chiark / gitweb /
JPEG support and other fixes from Nick Clark
[ssr] / StraySrc / Libraries / Sapphire / s / screen
1 ;
2 ; screen.s
3 ;
4 ; Screen mode information caching (TMA)
5 ;
6 ; © 1994-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Sapphire library.
12 ;
13 ; Sapphire is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
16 ; any later version.
17 ;
18 ; Sapphire is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ; GNU General Public License for more details.
22 ;
23 ; You should have received a copy of the GNU General Public License
24 ; along with Sapphire.  If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Standard header ------------------------------------------------------
28
29                 GET     libs:header
30                 GET     libs:swis
31
32 ;----- External dependencies ------------------------------------------------
33
34                 GET     sapphire:sapphire
35                 GET     sapphire:event
36
37 ;----- Main code ------------------------------------------------------------
38
39                 AREA    |Sapphire$$Code|,CODE,READONLY
40
41 ; --- screen_getInfo ---
42 ;
43 ; On entry:     --
44 ;
45 ; On exit:      R0 == pointer to screen information block
46 ;
47 ; Use:          This call returns a pointer to a block of information
48 ;               about the current screen modes.  The format of this block
49 ;               is defined above.
50
51                 EXPORT  screen_getInfo
52 screen_getInfo  ROUT
53
54                 STMFD   R13!,{R14}              ;Save a register
55                 LDR     R0,screen__wSpace       ;Get my workspace offset
56                 LDR     R14,sapph_workspace     ;Load workspace base address
57                 ADD     R0,R14,R0               ;Find workspace address
58                 ADD     R0,R0,#4                ;Point to the data block
59                 LDMFD   R13!,{PC}^              ;Return to caller
60
61                 LTORG
62
63 ; --- screen_cache ---
64 ;
65 ; On entry:     R12 points to workspace
66 ;
67 ; On exit:      --
68 ;
69 ; Use:          Caches screen information for the current mode.
70
71                 EXPORT  screen_cache
72 screen_cache    ROUT
73
74                 STMFD   R13!,{R0-R10,R14}       ;Stack some registers
75
76                 ; --- Now read relevent mode variables ---
77
78                 MOV     R3,#1                   ;A useful value
79                 MOV     R0,#-1                  ;Get info on current mode
80
81                 MOV     R1,#4                   ;XEigFactor
82                 SWI     OS_ReadModeVariable     ;Read its value
83                 MOV     R4,R2                   ;Look after xEig
84                 MOV     R9,R3,LSL R4            ;Get dx correctly
85
86                 MOV     R1,#5                   ;YEigFactor
87                 SWI     OS_ReadModeVariable     ;Read its value
88                 MOV     R5,R2                   ;Look after yEig
89                 MOV     R10,R3,LSL R5           ;Get dy correctly
90
91                 MOV     R1,#9                   ;Log2BPP
92                 SWI     OS_ReadModeVariable     ;Read its value
93                 MOV     R6,R3,LSL R2            ;Calculate bpp
94
95                 MOV     R1,#11                  ;XWindLimit
96                 SWI     OS_ReadModeVariable     ;Read its value
97                 ADD     R2,R2,#1                ;Calculate screen width
98                 MOV     R7,R2,LSL R4            ;width=(XwindLimit+1)<<xEig
99
100                 MOV     R1,#12                  ;XWindLimit
101                 SWI     OS_ReadModeVariable     ;Read its value
102                 ADD     R2,R2,#1                ;Calculate screen width
103                 MOV     R8,R2,LSL R5            ;height=(YwindLimit+1)<<yEig
104
105                 ; --- Now store the cached information ---
106
107                 STMIB   R12,{R4-R10}            ;Store in my workspace
108
109                 ; --- And return to caller ---
110
111                 LDMFD   R13!,{R0-R10,PC}^       ;Return
112
113                 LTORG
114
115 ; --- screen__postFilter ---
116 ;
117 ; On entry:     R0 == wimp event type
118 ;               R1 == pointer to returned block
119 ;               R12 == pointer to my workspace
120 ;
121 ; On exit:      --
122 ;
123 ; Use:          Called as a post filter to cache screen information on
124 ;               a mode change.
125
126 screen__postFilter
127                 ROUT
128
129                 ; --- Do we want this event ---
130
131                 CMP     R0,#2                   ;Open window request?
132                 MOVEQS  PC,R14                  ;Yes -- return PDQ
133
134                 STMFD   R13!,{R0,R2,R14}        ;Save registers
135                 LDR     R2,screen__flags        ;Get the flags word
136                 CMP     R0,#17                  ;Is event a message?
137                 CMPNE   R0,#18
138                 BICNE   R2,R2,#sFlag__newMode   ;No -- clear 'changed mode'
139                 STRNE   R2,screen__flags        ;...store back flags
140                 LDMNEFD R13!,{R0,R2,PC}^        ;...and return
141
142                 ; --- Is it the right message ---
143
144                 LDR     R14,[R1,#16]            ;Get the message type
145                 LDR     R0,=&400C1              ;Is it a mode change?
146                 CMP     R14,R0                  ;Compare the values
147                 BICNE   R2,R2,#sFlag__newMode   ;No -- clear 'changed mode'
148                 STRNE   R2,screen__flags        ;...store back flags
149                 LDMNEFD R13!,{R0,R2,PC}^        ;...and return
150
151                 ; --- Cache the mode information ---
152
153                 ORR     R2,R2,#sFlag__newMode   ;Set 'changed mode' bit
154                 STR     R2,screen__flags        ;Store back flags
155                 BL      screen_cache            ;Cache screen info
156
157                 ; --- And return ---
158
159                 LDMFD   R13!,{R0,R2,PC}^        ;Return to caller
160
161                 LTORG
162
163 ; --- screen_justChangedMode ---
164 ;
165 ; On entry:     --
166 ;
167 ; On exit:      CS if last event was a mode change, CC otherwise
168 ;
169 ; Use:          Informs the caller if the last event was a mode change.
170 ;               The system ignores open window requests when making it's
171 ;               decision.
172
173                 EXPORT  screen_justChangedMode
174 screen_justChangedMode ROUT
175
176                 STMFD   R13!,{R12,R14}          ;Stack some registers
177                 WSPACE  screen__wSpace          ;Locate my workspace
178
179                 LDR     R14,screen__flags       ;Get the flags word
180                 TST     R14,#sFlag__newMode     ;Test relevant bit
181                 LDMFD   R13!,{R12,R14}          ;Restore my registers
182                 BICEQS  PC,R14,#C_flag          ;It wasn't -- clear carry
183                 ORRNES  PC,R14,#C_flag          ;It was -- set carry
184
185                 LTORG
186
187 ; --- screen_init ---
188 ;
189 ; On entry:     --
190 ;
191 ; On exit:      --
192 ;
193 ; Use:          Initialises the screen unit.
194
195                 EXPORT  screen_init
196 screen_init     ROUT
197
198                 STMFD   R13!,{R0,R1,R12,R14}    ;Stack some registers
199                 WSPACE  screen__wSpace          ;Get my workspace
200
201                 ; --- Are we already initialised? ---
202
203                 LDR     R0,screen__flags        ;Get my flags
204                 TST     R0,#sFlag__inited       ;Are we initialised?
205                 LDMNEFD R13!,{R0,R1,R12,PC}^    ;Yes -- return
206
207                 ORR     R0,R0,#sFlag__inited    ;Set flags
208                 STR     R0,screen__flags        ;And store them back
209
210                 ; --- Now cache the current mode info ---
211
212                 BL      screen_cache
213
214                 ; --- Ensure that the event system is initialised ---
215
216                 BL      event_init
217
218                 ; --- Finally, set up a post filter to catch mode changes ---
219
220                 ADR     R0,screen__postFilter   ;Routine to call
221                 MOV     R1,R12                  ;Put my workspace in R12
222                 BL      event_postFilter        ;Add the post filter
223
224                 ; --- That's it now ---
225
226                 LDMFD   R13!,{R0,R1,R12,PC}^    ;Return
227
228                 LTORG
229
230 screen__wSpace  DCD     0                       ;My workspace pointer
231
232 ;----- Workspace ------------------------------------------------------------
233
234                 ^       0,R12
235 screen__wStart  #       0
236
237 screen__flags   #       4                       ;Flags
238
239 screen__xEig    #       4                       ;X Eig Factor
240 screen__yEig    #       4                       ;Y Eig Factor
241 screen__bpp     #       4                       ;Bits per pixel
242 screen__width   #       4                       ;Current screen width
243 screen__height  #       4                       ;Current screen height
244 screen__dx      #       4                       ;x pixel size
245 screen__dy      #       4                       ;y pixel size
246
247 screen__wSize   EQU     {VAR}-screen__wStart
248
249 sFlag__inited   EQU     (1<<0)                  ;I've been initialised
250 sFlag__newMode  EQU     (1<<1)                  ;Mode change just happened
251
252                 AREA    |Sapphire$$LibData|,CODE,READONLY
253
254                 DCD     screen__wSize           ;Workspace size
255                 DCD     screen__wSpace          ;Workspace pointer
256                 DCD     0                       ;Scratchpad size
257                 DCD     screen_init             ;Initialisation code
258
259 ;----- That's all, folks ----------------------------------------------------
260
261                 END