chiark / gitweb /
Initial revision
[ssr] / StraySrc / Dynamite / dynamite / s / dynTask
1 ;
2 ; dynTask.s
3 ;
4 ; The background compacting WIMP task
5 ;
6 ; © 1994-1998 Straylight
7 ;
8 ;----- Licensing note -------------------------------------------------------
9 ;
10 ; This file is part of Straylight's Dynamite
11 ;
12 ; Dynamite is free software; you can redistribute it and/or modify
13 ; it under the terms of the GNU General Public License as published by
14 ; the Free Software Foundation; either version 2, or (at your option)
15 ; any later version.
16 ;
17 ; Dynamite is distributed in the hope that it will be useful,
18 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ; GNU General Public License for more details.
21 ;
22 ; You should have received a copy of the GNU General Public License
23 ; along with Dynamite.  If not, write to the Free Software Foundation,
24 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26
27 ;----- Standard header ------------------------------------------------------
28
29                 GET     libs:header
30                 GET     libs:swis
31
32                 GET     libs:stream
33
34 ;----- External dependencies ------------------------------------------------
35
36                 GET     sh.dynHeap
37                 GET     sh.wSpace
38
39                 GET     sh.messages
40
41                 IMPORT  dyn_base
42
43 ;----- Main code ------------------------------------------------------------
44
45                 AREA    |Dynamite$$Code|,CODE,READONLY
46
47 ; --- dt_service ---
48 ;
49 ; On entry:     R1 == service call number
50 ;               Other registers depend on R1
51 ;
52 ; On exit:      Depends on service call
53 ;
54 ; Use:          Handles service calls for Dynamite
55
56                 EXPORT  dt_service
57 dt_service      ROUT
58
59                 ; --- Get rid of unwanted services quickly ---
60
61                 CMP     R1,#&4A
62                 CMPNE   R1,#&27
63                 CMPNE   R1,#&49
64                 MOVNES  PC,R14
65
66                 ; --- Now dispatch wanted services ---
67
68                 LDR     R12,[R12,#0]            ;Get my workspace pointer
69                 STMFD   R13!,{R14}              ;Save some useful registers
70
71                 CMP     R1,#&27                 ;Service_Reset...
72                 BEQ     %20dt_service
73
74                 CMP     R1,#&4A                 ;Service_StartedWimp
75                 BEQ     %10dt_service
76
77                 ; --- Service_StartWimp ---
78
79                 LDR     R14,dyn_taskHandle      ;Get my task handle
80                 CMP     R14,#0                  ;Am I already running?
81                 MOVEQ   R14,#-1                 ;I'm trying to start up
82                 STREQ   R14,dyn_taskHandle      ;Store as my task handle
83                 ADREQL  R0,dt__commands         ;Point to the command string
84                 MOVEQ   R1,#0                   ;Claim the service call
85                 LDMFD   R13!,{PC}^              ;Return to RISC OS
86
87                 ; --- Service_StartedWimp ---
88
89 10dt_service    LDR     R14,dyn_taskHandle      ;Get my task handle
90                 CMP     R14,#-1                 ;Am I already running?
91                 MOVEQ   R14,#0                  ;No -- blank out task handle
92                 STREQ   R14,dyn_taskHandle      ;Store it over the old one
93                 LDMFD   R13!,{PC}^              ;Return happily
94
95                 ; --- Service_Reset ---
96
97 20dt_service    MOV     R14,#0                  ;Blank out my task handle
98                 STR     R14,dyn_taskHandle      ;Store it over the old one
99                 LDMFD   R13!,{PC}^              ;Return to RISC OS now
100
101                 LTORG
102
103 ; --- dt__startTask ---
104 ;
105 ; On entry:     --
106 ;
107 ; On exit:      --
108 ;
109 ; Use:          Starts up the Dynamite application from a *Command.
110
111 dt__startTask   ROUT
112
113                 LDR     R12,[R12]               ;Load my workspace address
114                 LDR     R0,dyn_taskHandle       ;Get my task handle variable
115                 CMP     R0,#-1                  ;Am I waiting to start?
116                 ADRNEL  R0,msg_errDesk          ;No -- moan at stupid user
117                 ORRNES  PC,R14,#V_flag          ;And return the error
118                 MOV     R0,#1                   ;We're launching the app
119                 STR     R0,dyn_launch           ;So set the launch flag
120                 STMFD   R13!,{R14}              ;Save a register nicely
121                 MOV     R0,#2                   ;Start my module up
122                 ADR     R1,dt__myName           ;Point to the module name
123                 SWI     XOS_Module              ;Start up the task proper
124                 LDMFD   R13!,{PC}               ;And return to caller
125
126 dt__myName      DCB     "Dynamite",0
127
128                 LTORG
129
130 ; --- dt_quit ---
131 ;
132 ; On entry:     --
133 ;
134 ; On exit:      --
135 ;
136 ; Use:          Closes down Dynamite's WIMP task (used for background
137 ;               compaction of the heap).
138
139                 EXPORT  dt_quit
140 dt_quit         ROUT
141
142                 STMFD   R13!,{R0,R1,R14}        ;Save some registers
143                 LDR     R0,dyn_taskHandle       ;Find my task handle
144                 LDR     R1,=&4B534154           ;The magic number thing
145                 SWI     XWimp_CloseDown         ;Close down the application
146                 MOV     R14,#0                  ;Now we don't have a task
147                 STR     R14,dyn_taskHandle      ;So zap my task handle
148                 LDMFD   R13!,{R0,R1,PC}^        ;And return to caller
149
150                 LTORG
151
152 ; --- dt_run ---
153 ;
154 ; On entry:     R12 == address of module private word
155 ;
156 ; On exit:      Via OS_Exit
157 ;
158 ; Use:          Runs the Dynamite WIMP task.
159
160                 EXPORT  dt_run
161 dt_run          ROUT
162
163                 LDR     R12,[R12]               ;Find my workspace address
164                 ADR     R13,dyn_pollBlk+256     ;Make a microstack
165
166                 ; --- Is it worth doing anything? ---
167
168                 MOV     R0,#0                   ;How many Wimp tasks?
169                 SWI     Wimp_ReadSysInfo        ;Read the number back
170                 CMP     R0,#0                   ;Are there any running?
171                 SWIEQ   OS_Exit                 ;Nope: then don't bother
172
173                 ; --- Handle the ultra-weird launch sequence ---
174
175                 LDR     R14,dyn_launch          ;Load the launch flag
176                 CMP     R14,#0                  ;Are we launching?
177                 BEQ     %50dt_run               ;No -- launch then
178
179                 ; --- Start up the WIMP thing ---
180
181                 MOV     R0,#200                 ;Make it run under RISC OS 2
182                 LDR     R1,=&4B534154           ;Get the magic number thing
183                 ADR     R2,dt__taskName         ;Point to the task name
184                 SWI     Wimp_Initialise         ;Start up the WindowManager
185                 STR     R1,dyn_taskHandle       ;Save the task handle
186
187                 ; --- Remove my name from the Switcher's list ---
188
189                 ADR     R1,dyn_pollBlk          ;Point to the poll block
190                 MOV     R0,#20                  ;Minimum message size
191                 STR     R0,[R1,#0]              ;Save in position 0
192                 MOV     R2,#0                   ;This is not a reply
193                 MOV     R3,#&40000              ;The TaskCloseDown message
194                 ORR     R3,R3,#&000C3           ;It comes in two episodes
195                 ADD     R0,R1,#12               ;Point to bit of message blk
196                 STMIA   R0,{R2,R3}              ;Build the message in there
197                 MOV     R0,#17                  ;Don't get a reply
198                 MOV     R2,#0                   ;Give everyone a shot at it
199                 SWI     XWimp_SendMessage       ;Send it the message
200
201                 ; --- Now do the main loop ---
202
203 00dt_run        LDR     R14,dyn_hpFlags         ;Load the heap's flags
204                 TST     R14,#hpFlag_tidy        ;Is the heap tidy?
205                 LDREQ   R14,dyn_lockCount       ;No -- then load lock count
206                 CMPEQ   R14,#0                  ;Is the heap locked?
207                 MOVNE   R0,#1                   ;Tidy or locked, so be nice
208                 MOVEQ   R0,#0                   ;Otherwise use idles
209                 ADR     R1,dyn_pollBlk          ;Point to my pollblock
210                 ADD     R13,R1,#256             ;Make a bogus stack
211                 SWI     Wimp_Poll               ;Do the poll thing
212                 CMP     R0,#0                   ;Is it an idle event?
213                 SWIEQ   Dynamite_Reduce         ;Yes -- then reduce the heap
214                 CMP     R0,#17                  ;Is it a message
215                 CMPNE   R0,#18                  ;Of either type
216                 LDREQ   R0,[R1,#16]             ;Get the message type
217                 CMPEQ   R0,#0                   ;Is it a Message_Quit
218                 LDRNE   R14,dyn_hpFlags         ;No -- load the flags
219                 BICNE   R14,R14,#hpFlag_mSent   ;...clear the message sent
220                 STRNE   R14,dyn_hpFlags         ;...save the flags back
221                 BNE     %00dt_run               ;...loop round again
222
223                 ; --- I've been told to quit ---
224                 ;
225                 ; Seeing as I've viciously and nastily removed myself from
226                 ; the TaskManager's task table, I know this must have been
227                 ; a broadcast quit, so I hari-kiri with wanton abandon.
228
229                 SWI     Wimp_CloseDown          ;Close down the task
230                 MOV     R0,#0                   ;No task handle any more
231                 STR     R0,dyn_taskHandle       ;So zero it then
232                 SWI     OS_Exit                 ;Farewell, cruel world
233
234 dt__taskName    DCB     "DynamiteCompactor",0
235
236                 ; --- Launch the Compactor task ---
237
238 50dt_run        MOV     R0,#200                 ;Make it run under RISC OS 2
239                 LDR     R1,=&4B534154           ;Get the magic number thing
240                 ADR     R2,dt__launchName       ;Point to the task name
241                 SWI     Wimp_Initialise         ;Start up the WindowManager
242
243                 MOV     R0,#-1                  ;Fake a startup sequence
244                 STR     R0,dyn_taskHandle       ;Save this as my task handle
245                 LDR     R0,=dt__commands        ;Point to my main command
246                 BL      dyn_base                ;Find the module base
247                 ADD     R0,R14,R0               ;Relocate the address
248                 SWI     Wimp_StartTask          ;Start it up nicely
249
250                 SWI     Wimp_CloseDown          ;Tell WIMP to get knotted
251                 SWI     OS_Exit                 ;And kill self evilly
252
253 dt__launchName  DCB     "DynamiteLauncher",0
254
255                 LTORG
256
257 ; --- dt_message ---
258 ;
259 ; On entry:     --
260 ;
261 ; On exit:      --
262 ;
263 ; Use:          Sends a silly message to the Compactor task so that it gets
264 ;               control again if it disabled idle events.
265
266                 EXPORT  dt_message
267 dt_message      ROUT
268
269                 STMFD   R13!,{R0-R3,R14}        ;Save some registers
270                 LDR     R14,dyn_taskHandle      ;Load my task handle
271                 CMP     R14,#0                  ;Is it vaguely sensible?
272                 LDMLEFD R13!,{R0-R3,PC}^        ;No -- don't bother then
273                 LDR     R14,dyn_hpFlags         ;Load the flags
274                 TST     R14,#hpFlag_mSent       ;Has a message been sent?
275                 LDMNEFD R13!,{R0-R3,PC}^        ;Yes -- then return
276                 ORR     R14,R14,#hpFlag_mSent   ;Set the flag
277                 STR     R14,dyn_hpFlags         ;And save the flags back
278                 ADR     R1,dyn_pollBlk          ;Point to the poll block
279                 MOV     R0,#20                  ;Minimum message size
280                 STR     R0,[R1,#0]              ;Save in position 0
281                 MOV     R2,#0                   ;This is not a reply
282                 MOV     R3,#&4A000              ;A bogus message number
283                 ORR     R3,R3,#&003C0           ;(My SWI chunk base)
284                 ADD     R0,R1,#12               ;Point to bit of message blk
285                 STMIA   R0,{R2,R3}              ;Build the message in there
286                 MOV     R0,#17                  ;Don't get a reply
287                 MOV     R2,R14                  ;Get my task handle
288                 SWI     XWimp_SendMessage       ;Send it the message
289                 LDMFD   R13!,{R0-R3,PC}^        ;And return to caller
290
291                 LTORG
292
293                 ; --- *Commands ---
294
295                 AREA    |Dynamite$$Commands|,CODE,READONLY
296
297 dt__commands    DCB     "Desktop_DynamiteCompactor",0
298                 DCD     dt__startTask
299                 DCD     0
300                 DCD     synt_compactor
301                 DCD     help_compactor
302
303 ;----- That's all, folks ----------------------------------------------------
304
305                 END