Initial revision
[ssr] / StraySrc / MiscToys / CheckSD / s / CheckSD
1 ;
2 ; checksd.s
3 ;
4 ; Ask for confirmation on shutdowns
5 ;
6 ; © 1995 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; CheckSD is free software; you can redistribute it and/or modify
12 ; it under the terms of the GNU General Public License as published by
13 ; the Free Software Foundation; either version 2, or (at your option)
14 ; any later version.
15 ;
16 ; CheckSD is distributed in the hope that it will be useful,
17 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ; GNU General Public License for more details.
20 ;
21 ; You should have received a copy of the GNU General Public License
22 ; along with CheckSD. If not, write to the Free Software Foundation,
23 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25 ;----- Standard header ------------------------------------------------------
26
27 GET libs:header
28 GET libs:swis
29
30 GET libs:stream
31
32 ;----- External dependencies ------------------------------------------------
33
34 GET libs:embTemp.sh.embTemp
35
36 IMPORT tpl_warning
37
38 IMPORT |Image$$RW$$Limit|
39
40 ;----- Main code ------------------------------------------------------------
41
42 AREA |Asm$$Code|,CODE,READONLY
43 ENTRY
44
45 ; --- main ---
46 ;
47 ; On entry: --
48 ;
49 ; On exit: Via OS_Exit
50 ;
51 ; Use: Initialise the application.
52
53 main ROUT
54
55 BL cs_init ;Initialise low-level things
56 BL cs_initWimp ;Initialise WIMPy things
57 BL cs_poll ;Enter the poll loop
58 SWI OS_Exit ;And return when done
59
60 LTORG
61
62 ; --- cs_init ---
63 ;
64 ; On entry: --
65 ;
66 ; On exit: R12 == pointer to workspace
67 ; R13 == stack pointer
68 ; Other registers corrupted
69 ;
70 ; Use: Initialises workspace etc.
71
72 cs_init ROUT
73
74 MOV R0,#4096 ;Only need a 4K wimpslot
75 MOV R1,#-1 ;Don't change next slot
76 SWI Wimp_SlotSize ;Change my slot, please
77
78 SWI OS_GetEnv ;Find the memory limit
79 MOV R13,R1 ;Put stack at the top
80 LDR R12,=|Image$$RW$$Limit| ;Put workspace at end
81 ADD R0,R12,#cs_wSize ;Add on the workspace size
82 CMP R0,R13 ;Do we have enough space?
83 MOVCCS PC,R14 ;Yes -- then return to caller
84
85 ADR R0,cs_noMem ;Point to error message
86 SWI OS_GenerateError ;Raise the error
87
88 cs_noMem DCD 1
89 DCB "Not enough memory for CheckSD to start up",0
90
91 ; --- cs_initWimp ---
92 ;
93 ; On entry: --
94 ;
95 ; On exit: R0-R11 corrupted
96 ;
97 ; Use: Initialises various WIMPy things.
98
99 cs_initWimp ROUT
100
101 STMFD R13!,{R14} ;Save return address
102
103 MOV R0,#200 ;RISC OS 2 will do for me
104 LDR R1,=&4B534154 ;Get magic WIMP number
105 ADR R2,cs_appName ;Point to application name
106 SWI Wimp_Initialise ;Initialise the WIMP then
107
108 ADRL R0,tpl_warning ;Find the template
109 ADR R1,cs_pollBlock ;Write window to poll block
110 ADR R2,cs_indBase ;Point to indirect buffer
111 ADR R3,cs_indLimit ;Point to limit of this
112 MOV R4,#1 ;Use the Wimp sprite area
113 MOV R5,#1 ;For everything, please
114 BL embTemp_extract ;Extract the file
115 SWI Wimp_CreateWindow ;Create the window
116 STR R0,cs_warning ;Save the window handle
117
118 LDMFD R13!,{PC}^ ;Now return to caller
119
120 cs_appName DCB "CheckShutdowns",0
121
122 LTORG
123
124 ; --- cs_poll ---
125 ;
126 ; On entry: --
127 ;
128 ; On exit: R0-R11 corrupted
129 ;
130 ; Use: Does the main polling job.
131
132 cs_poll ROUT
133
134 STMFD R13!,{R14} ;Save return address
135 00 MOV R0,#1 ;Don't give me null events
136 ADR R1,cs_pollBlock ;Point to my poll block
137 SWI Wimp_Poll ;Get an event, please
138 ADR R14,%b00 ;Set up a return address
139 CMP R0,#1 ;Is it a redraw event?
140 BEQ cs_redraw ;Yes (weird)
141 CMP R0,#17 ;Is this a message?
142 CMPNE R0,#18 ;Check both types
143 BEQ cs_message ;Yes -- handle that then
144 MOVS PC,R14 ;And loop back round again
145
146 LTORG
147
148 ; --- cs_redraw ---
149 ;
150 ; On entry: R1 == pointer to window handle
151 ;
152 ; On exit: --
153 ;
154 ; Use: Redraws a window the only way we can.
155
156 cs_redraw ROUT
157
158 STMFD R13!,{R0,R14} ;Save some registers
159 SWI Wimp_RedrawWindow ;Start a redraw job
160 CMP R0,#0 ;Have we finished yet?
161 00 SWINE XSculptrix_RedrawWindow ;No -- do 3D bits then
162 SWINE Wimp_GetRectangle ;And get another rectangle
163 CMPNE R0,#0 ;Finished now?
164 BNE %b00 ;No -- keep looping
165 LDMFD R13!,{R0,PC}^ ;And return to caller
166
167 LTORG
168
169 ; --- cs_message ---
170 ;
171 ; On entry: R1 == pointer to message block
172 ;
173 ; On exit: R0-R11 corrupted
174 ;
175 ; Use: Handles messages
176
177 cs_message ROUT
178
179 LDR R0,[R1,#16] ;Load the message type
180 CMP R0,#0 ;Is this a quit?
181 LDMEQFD R13!,{PC}^ ;Yes -- then stop right now
182 CMP R0,#8 ;Is this a pre-quit?
183 MOVNES PC,R14 ;No -- ignore it then
184 LDR R0,[R1,#0] ;Load the message size
185 CMP R0,#20 ;Is this the old size?
186 LDRNE R0,[R1,#20] ;No -- load the flags word
187 TSTNE R0,#1 ;Test the flag bit
188 MOVNES PC,R14 ;And return if not shutdown
189
190 STMFD R13!,{R14} ;Save a register
191 SUB R13,R13,#48 ;Drop stack pointer further
192 LDR R0,cs_warning ;Load the window handle
193 STR R0,[R13,#0] ;Store it away
194 MOV R1,R13 ;Point to it there
195 SWI Wimp_GetWindowState ;Find the window size
196 LDMIB R1,{R2-R5} ;Load them out
197 SUB R13,R13,#16 ;Make space on the stack
198 ADR R0,cs_vduvars ;Point to VDU variables
199 MOV R1,R13 ;Output on the stack
200 SWI OS_ReadVduVariables ;Read them then
201 LDMIA R13!,{R6-R9} ;Load them
202 ADD R8,R8,#1 ;Find the screen width
203 ADD R9,R9,#1 ;And its height
204 MOV R8,R8,LSL R6 ;Work out widht in OS units
205 MOV R9,R9,LSL R7 ;And the height too
206 SUB R4,R4,R2 ;Find the window width
207 SUB R5,R5,R3 ;And its height
208 SUB R2,R8,R4 ;Find centre position
209 SUB R3,R9,R5 ;Vertically too
210 MOV R2,R2,LSR #1 ;And work out the positions
211 MOV R3,R3,LSR #1 ;To centre on the screen
212 ADD R4,R2,R4 ;Get the limit coords too now
213 ADD R5,R3,R5 ;So we can store them back
214 MOV R1,R13 ;Point to the poll block
215 STMIB R1,{R2-R5} ;Save all of them away
216 SWI Wimp_OpenWindow ;Display it on the screen
217
218 ; --- Constrain the mouse pointer ---
219
220 MOV R14,#1 ;A word to shift about
221 SUB R2,R2,R14,LSL R6 ;Knock pixel of left side
222 SUB R3,R3,R14,LSL R7 ;And off the top
223 BL cs_constrain ;Constrain mouse here
224
225 BL cs_beep ;Maybe make a noise
226 BL cs_redraw ;Force it to redraw
227
228 ; --- Work out position of buttons ---
229
230 ADD R14,R1,#20 ;Point to scroll offsets
231 LDMIA R14,{R10,R11} ;Load them
232 SUB R10,R2,R10 ;Find the x origin position
233 SUB R11,R5,R11 ;And the y origin position
234
235 MOV R14,#3 ;Find default button
236 STR R14,[R1,#4] ;Store that in the block
237 SWI Wimp_GetIconState ;Read the icon block
238 ADD R14,R1,#8 ;Point to the sizes
239 LDMIA R14,{R4-R7} ;Load them out
240 ADD R4,R4,R10 ;Transform these
241 ADD R5,R5,R11
242 ADD R6,R6,R10
243 ADD R7,R7,R11
244
245 MOV R14,#4 ;Find cancel button
246 STR R14,[R1,#4] ;Store that in the block
247 SWI Wimp_GetIconState ;Read the icon block
248 ADD R14,R1,#8 ;Point to the sizes
249 LDMIA R14,{R0-R3} ;Load them out
250 ADD R8,R0,R10 ;Transform these
251 ADD R9,R1,R11
252 ADD R10,R2,R10
253 ADD R11,R3,R11
254
255 ; --- Now enter a loop thing ---
256
257 SWI OS_Mouse ;Read the mouse state
258 MOV R14,R2 ;Look after current state
259
260 05 SWI OS_Mouse ;Read the mouse state
261 BIC R3,R2,R14 ;Clear bits already set
262 ANDS R3,R3,#5 ;Only look at sel and adj
263 BEQ %f00 ;If no buttons, skip
264
265 CMP R0,R4 ;Check for default button
266 CMPCS R1,R5
267 CMPCS R6,R0
268 CMPHI R7,R1
269 MOVHI R0,#3 ;If so, get default
270 BHI %10cs_message ;And handle that
271
272 CMP R0,R8 ;Check for cancel button
273 CMPCS R1,R9
274 CMPCS R10,R0
275 CMPHI R11,R1
276 MOVHI R0,#4 ;If so, get cancel
277 BHI %10cs_message ;And handle that
278
279 ; --- Check for key presses ---
280
281 00 MOV R14,R2 ;Remember new current state
282 MOV R0,#129 ;Read a keypress
283 MOV R1,#0 ;Don't wait for it
284 MOV R2,#0 ;Really don't
285 SWI OS_Byte ;Read that
286 MOV R0,#0 ;Clear a word
287 CMP R1,#&0D ;Return pressed?
288 EOREQ R0,R0,#3 :EOR: 4 ;Yes -- choose default
289 CMPNE R1,#&1B ;Or escape?
290 EOREQ R0,R0,#4 ;Yes -- choose cancel
291 BNE %b05 ;Otherwise loop
292
293 ; --- Choose a button ---
294
295 10cs_message MOV R11,R0 ;Look after the icon
296 SUB R13,R13,#16 ;Make a slab block
297 MOV R1,R0 ;Get the icon handle
298 LDR R0,cs_warning ;Get the warning box
299 MOV R2,R13 ;Point to slab block
300 SWI XSculptrix_SlabIcon ;Slab the icon
301 ADR R1,cs_warning ;Point to window handle
302 SWI Wimp_CloseWindow ;Take the window down
303 SWI XSculptrix_UnslabIcon ;And unslab the icon
304 ADD R13,R13,#16 ;Reclaim the block
305
306 ; --- Unconstrain the mouse ---
307
308 SUB R13,R13,#16 ;Make space on the stack
309 ADR R0,cs_vduvars ;Point to VDU variables
310 MOV R1,R13 ;Output on the stack
311 SWI OS_ReadVduVariables ;Read them then
312 LDMIA R13!,{R2-R5} ;Load them
313 MOV R4,R4,LSL R2 ;Work out widht in OS units
314 MOV R5,R5,LSL R3 ;And the height too
315 MOV R2,#0 ;Start at bottom left
316 MOV R3,#0 ;Set both up
317 BL cs_constrain ;Set the rectangle
318
319 ; --- Now sort out what to do now ---
320
321 CMP R11,#4 ;Cancel shutdown?
322 BNE %f00 ;No -- skip onwards
323 ADR R1,cs_pollBlock ;Point to the poll block
324 LDR R14,[R1,#8] ;Load his ref
325 STR R14,[R1,#12] ;This is my ref
326 LDR R2,[R1,#4] ;Load his task handle
327 MOV R0,#19 ;Ack the message
328 SWI Wimp_SendMessage ;Abort the shutdown
329
330 ; --- Now tidy up and return ---
331
332 00 ADD R13,R13,#48 ;Restore the stack
333 LDMFD R13!,{PC}^ ;And return to caller
334
335 cs_vduvars DCD 4,5,11,12,-1
336
337 LTORG
338
339 ; --- cs_constrain ---
340 ;
341 ; On entry: R2-R5 == coordinates to constrain to
342 ;
343 ; On exit: --
344 ;
345 ; Use: Constrain the mouse to a rectangle.
346
347 cs_constrain ROUT
348
349 STMFD R13!,{R0-R2,R14} ;Save some registers
350 MOV R0,#1 ;Subreason code
351 ORR R0,R0,R2,LSL #8
352 ORR R0,R0,R3,LSL #24
353 MOV R1,R3,LSR #8
354 ORR R1,R1,R4,LSL #8
355 ORR R1,R1,R5,LSL #24
356 MOV R2,R5,LSR #8
357 STMFD R13!,{R0-R2} ;Save them on the stack
358 MOV R0,#21 ;Do mouse things
359 MOV R1,R13 ;Point to the block
360 SWI OS_Word ;Do the job
361 ADD R13,R13,#12 ;Restore stack pointer
362 LDMFD R13!,{R0-R2,PC}^ ;And return to caller
363
364 LTORG
365
366
367 ; --- cs_beep ---
368 ;
369 ; On entry: --
370 ;
371 ; On exit: --
372 ;
373 ; Use: Sounds the bell (VDU 7) if the CMOS settings dictate that
374 ; error boxes should cause a beep.
375
376 cs_beep ROUT
377
378 STMFD R13!,{R0-R2,R14} ;Save some registers
379 MOV R0,#161 ;Read CMOS locations nicely
380 MOV R1,#197 ;Read WimpFlags location
381 SWI OS_Byte ;Do the read operation
382 TST R2,#1<<4 ;Do we make noises then?
383 SWIEQ OS_WriteI+7 ;Yes -- bleep
384 LDMFD R13!,{R0-R2,PC}^ ;Return to caller
385
386 LTORG
387
388 ;----- Workspace ------------------------------------------------------------
389
390 ^ 0,R12
391 cs_wStart # 0
392
393 cs_warning # 4
394 cs_pollBlock # 256
395 cs_indBase # 256
396 cs_indLimit # 0
397 cs_stack # 256
398
399 cs_wSize EQU {VAR}-cs_wStart
400
401 ;----- That's all, folks ----------------------------------------------------
402
403 END