4 ; Ask for confirmation on shutdowns
9 ;----- Licensing note -------------------------------------------------------
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)
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.
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.
25 ;----- Standard header ------------------------------------------------------
32 ;----- External dependencies ------------------------------------------------
34 GET libs:embTemp.sh.embTemp
38 IMPORT |Image$$RW$$Limit|
40 ;----- Main code ------------------------------------------------------------
42 AREA |Asm$$Code|,CODE,READONLY
49 ; On exit: Via OS_Exit
51 ; Use: Initialise the application.
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
66 ; On exit: R12 == pointer to workspace
67 ; R13 == stack pointer
68 ; Other registers corrupted
70 ; Use: Initialises workspace etc.
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
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
85 ADR R0,cs_noMem ;Point to error message
86 SWI OS_GenerateError ;Raise the error
89 DCB "Not enough memory for CheckSD to start up",0
95 ; On exit: R0-R11 corrupted
97 ; Use: Initialises various WIMPy things.
101 STMFD R13!,{R14} ;Save return address
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
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
118 LDMFD R13!,{PC}^ ;Now return to caller
120 cs_appName DCB "CheckShutdowns",0
128 ; On exit: R0-R11 corrupted
130 ; Use: Does the main polling job.
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
150 ; On entry: R1 == pointer to window handle
154 ; Use: Redraws a window the only way we can.
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
171 ; On entry: R1 == pointer to message block
173 ; On exit: R0-R11 corrupted
175 ; Use: Handles messages
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
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
218 ; --- Constrain the mouse pointer ---
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
225 BL cs_beep ;Maybe make a noise
226 BL cs_redraw ;Force it to redraw
228 ; --- Work out position of buttons ---
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
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
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
255 ; --- Now enter a loop thing ---
257 SWI OS_Mouse ;Read the mouse state
258 MOV R14,R2 ;Look after current state
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
265 CMP R0,R4 ;Check for default button
269 MOVHI R0,#3 ;If so, get default
270 BHI %10cs_message ;And handle that
272 CMP R0,R8 ;Check for cancel button
276 MOVHI R0,#4 ;If so, get cancel
277 BHI %10cs_message ;And handle that
279 ; --- Check for key presses ---
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
293 ; --- Choose a button ---
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
306 ; --- Unconstrain the mouse ---
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
319 ; --- Now sort out what to do now ---
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
330 ; --- Now tidy up and return ---
332 00 ADD R13,R13,#48 ;Restore the stack
333 LDMFD R13!,{PC}^ ;And return to caller
335 cs_vduvars DCD 4,5,11,12,-1
339 ; --- cs_constrain ---
341 ; On entry: R2-R5 == coordinates to constrain to
345 ; Use: Constrain the mouse to a rectangle.
349 STMFD R13!,{R0-R2,R14} ;Save some registers
350 MOV R0,#1 ;Subreason code
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
373 ; Use: Sounds the bell (VDU 7) if the CMOS settings dictate that
374 ; error boxes should cause a beep.
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
388 ;----- Workspace ------------------------------------------------------------
399 cs_wSize EQU {VAR}-cs_wStart
401 ;----- That's all, folks ----------------------------------------------------