1706
|
1 *
|
|
2 * View_wait.a -- End-of-picture pause... handles color cycling, screen
|
|
3 * flipping, and timeout.
|
|
4 *
|
|
5 * Global labels:
|
|
6 * keywait: Subroutine to handle end-of-picture pause.
|
|
7 * SetSig: Sets trivial signal trap which stores signal in SigCode
|
|
8 *
|
|
9 check macro
|
|
10 pshs b,cc
|
|
11 ldb #\1
|
|
12 os9 F$PErr
|
|
13 puls b,cc
|
|
14 endm
|
|
15
|
|
16 ifp1
|
1777
|
17 use os9defs.a
|
1706
|
18 endc
|
|
19
|
|
20 StdOut equ 1
|
|
21 StdErr equ 2
|
|
22
|
|
23 psect View_wait_a,0,0,0,0,0
|
|
24
|
|
25 *******************************************************
|
|
26 *
|
|
27 * Keywait- wait for keypress or mouse click
|
|
28 * Also, handle palette cycling.
|
|
29 *
|
|
30 *******************************************************
|
|
31 vsect dp
|
|
32 cycleleft rmb 2
|
|
33 extraleft rmb 2
|
|
34 endsect
|
|
35
|
|
36 keywait:
|
|
37 pshs a,b,x,y,u
|
|
38 clr <abort
|
|
39
|
|
40 ldd <cyclerate Initialize cycle and extra count-down timers.
|
|
41 std <cycleleft
|
|
42 ldd <extrarate
|
|
43 std <extraleft
|
|
44
|
|
45 kwloop
|
|
46 lbsr conscheck Check for consistency, to make sure we don't waste time.
|
|
47 clr <SigCode Set up our signals.
|
|
48 lbsr setmouse
|
|
49 lbsr setkeysig
|
|
50
|
|
51 kwchkey
|
|
52 lbsr getkey Is there a key waiting?
|
|
53 bcs kwnokey
|
|
54 clr <SigCode
|
|
55 lbsr kwdokey If so, handle it
|
|
56 bra kwchkey . and then check again.
|
|
57 kwnokey
|
|
58
|
|
59 tst <flipping If flipping is on, do that.
|
|
60 beq kwnoflip
|
|
61 lbsr kwflip
|
|
62 bra kwsig
|
|
63 kwnoflip
|
|
64
|
|
65 tst <cycle If animation is on, do that.
|
|
66 beq kwnocycle
|
|
67 lbsr kwanimate
|
|
68 bra kwsig
|
|
69 kwnocycle
|
|
70
|
|
71 ldx <MaxTime If none of the above, just sleep for MaxTime
|
|
72 cmpx #0
|
|
73 beq kwsig
|
|
74 tst <SigCode
|
|
75 bne nosleep1
|
|
76 os9 F$Sleep
|
|
77 nosleep1
|
|
78 stx <MaxTime
|
|
79
|
|
80
|
|
81 *
|
|
82 * Handle a signal.
|
|
83 kwsig
|
|
84 ldd <MaxTime If we timed out, end now.
|
|
85 beq kwend
|
|
86 lda <SigCode
|
|
87
|
|
88 cmpa #KButton Was it a keypress that woke us up?
|
|
89 bne kwnokey1
|
|
90 clr <SigCode If so, clear sigcode,
|
|
91 lbsr getkey . get the key
|
|
92 bsr kwdokey . process it
|
|
93 bcc kwloop . and keep going.
|
|
94 bra kwend
|
|
95 kwnokey1
|
|
96
|
|
97 cmpa #MButton Was it a mouse click?
|
|
98 bne kwnomouse None of the above, we just exit.
|
|
99 bsr kwdomouse
|
|
100 lbcc kwloop
|
|
101 bra kwend
|
|
102 kwnomouse
|
|
103
|
|
104 kwend
|
|
105 puls a,b,x,y,u,pc
|
|
106
|
|
107
|
|
108 *
|
|
109 * Process a mouse click.
|
|
110 *
|
|
111 kwdomouse
|
|
112 clr <SigCode
|
|
113 orcc #Carry Set carry, since any mouse click should end.
|
|
114 rts
|
|
115
|
|
116 *
|
|
117 * process a key press.
|
|
118 * Expects: key in A.
|
|
119 kwdokey
|
|
120 pshs a,b,x
|
|
121 cmpa #'Z Convert key to lower case
|
|
122 bhi kwlower
|
|
123 cmpa #'A
|
|
124 blo kwlower
|
|
125 suba #'A-'a
|
|
126 kwlower
|
|
127
|
|
128 cmpa #$20 Was it a space?
|
|
129 bne kwkey1
|
|
130 com <cycle Yes, turn cycling on/off
|
|
131 lbne kwdonekey
|
|
132 lbsr setpals Restore original palettes, if we just turned cycling off.
|
|
133 lbra kwdonekey
|
|
134 kwkey1
|
|
135
|
|
136 cmpa #', Was it a "<"?
|
|
137 beq kwkey21
|
|
138 cmpa #'<
|
|
139 beq kwkey21
|
|
140 cmpa #'s Was it an "S" (slower)
|
|
141 bne kwkey2
|
|
142 kwkey21
|
|
143 ldx <cyclerate
|
|
144 leax 1,x Increase the cycle delay
|
|
145 beq kwkey22
|
|
146 stx <cyclerate
|
|
147 kwkey22
|
|
148 tst <flipping
|
|
149 beq kwkey23 If not flipping, don't do this...
|
|
150 ldd <fliprate
|
|
151 addd #1
|
|
152 cmpd #6000
|
|
153 bhs kwkey23
|
|
154 std <fliprate
|
|
155 kwkey23
|
|
156 lbra kwdonekey
|
|
157 kwkey2
|
|
158
|
|
159 cmpa #'.
|
|
160 beq kwkey31
|
|
161 cmpa #'>
|
|
162 beq kwkey31
|
|
163 cmpa #'f "F" (faster)
|
|
164 bne kwkey3
|
|
165 kwkey31
|
|
166 ldx <cyclerate
|
|
167 leax -1,x Decrease the cycle delay
|
|
168 beq kwkey32
|
|
169 stx <cyclerate Don't make it zero!
|
|
170 kwkey32
|
|
171 tst <flipping
|
|
172 beq kwkey33 If not flipping, don't do this...
|
|
173 ldd <fliprate
|
|
174 subd #1
|
|
175 cmpd #2
|
|
176 bls kwkey33
|
|
177 std <fliprate
|
|
178 kwkey33
|
|
179 lbra kwdonekey
|
|
180 kwkey3
|
|
181
|
|
182 cmpa #$B2 F2 key
|
|
183 beq kwkey41
|
|
184 cmpa #$0a Down-arrow
|
|
185 bne kwkey4
|
|
186 kwkey41
|
|
187 lbsr flipscreen
|
|
188 lbra kwdonekey
|
|
189 kwkey4
|
|
190
|
|
191 cmpa #$0c Up-arrow
|
|
192 bne kwkey5
|
|
193 lbsr flipback
|
|
194 lbra kwdonekey
|
|
195 kwkey5
|
|
196
|
|
197 cmpa #$B1
|
|
198 bne kwkey6
|
|
199 lda <flipping
|
|
200 beq kwkey61
|
|
201 lda #$ff
|
|
202 kwkey61
|
|
203 coma
|
|
204 sta <flipping
|
|
205 lbra kwdonekey
|
|
206 kwkey6
|
|
207
|
|
208 lbsr docycle Any other key? Single step.
|
|
209 lbsr dorotate
|
|
210 lbra kwdonekey
|
|
211 kwdonekey
|
|
212 andcc #^Carry Clear carry flag, since no key forces an exit.
|
|
213 puls a,b,x,pc
|
|
214
|
|
215 *
|
|
216 * Check cycle, extra, and flipping variables for consistency,
|
|
217 * since naive routines may end up with inconsistent or inefficient
|
|
218 * combinations of settings (for example, we might end up with
|
|
219 * flipping enabled, but only one screen allocated).
|
|
220 *
|
|
221 conscheck
|
|
222 pshs a,b
|
|
223 * Check "cycle" values for consistency.
|
|
224 lda <cyclestart Do a consistency check on the cycle values.
|
|
225 cmpa <cycleend
|
|
226 blo cons0
|
|
227 ldd #$ffff if cyclestart >= cycleend, then
|
|
228 std <cyclerate set cyclerate to $ffff.
|
|
229 bra cons1
|
|
230 cons0
|
|
231 ldd <cyclerate otherwise, make sure cyclerate is not 0
|
|
232 bne cons1
|
|
233 ldd #10 Just a random value.
|
|
234 std <cyclerate
|
|
235 cons1
|
|
236
|
|
237 * Check "extra" palette values for consistency.
|
|
238 lda <extranum Do a consistency check on extra palette values.
|
|
239 bne cons2
|
|
240 ldd #$ffff if extranum is zero,
|
|
241 std <extrarate set extrarate to $ffff.
|
|
242 bra cons3
|
|
243 cons2
|
|
244 ldd <extrarate otherwise, make sure extrarate is not 0
|
|
245 bne cons3
|
|
246 ldd #10 Just a random value.
|
|
247 std <extrarate
|
|
248 cons3
|
|
249
|
|
250 * Check flipping vars for consistency
|
|
251 lda <numscreens Do a consistency check on flipping var.
|
|
252 cmpa #2
|
|
253 bhs cons4
|
|
254 clr <flipping If <2 screens, then ensure flipping is off.
|
|
255 cons4
|
|
256
|
|
257 * Check "cycle" variable for consistency.
|
|
258 lda <cyclestart A consistency check: If all animation effects
|
|
259 cmpa <cycleend are disabled, then turn off "cycle"
|
|
260 blo cons5
|
|
261 lda <extranum
|
|
262 bne cons5
|
|
263 clr <cycle And turn off cycle flag.
|
|
264 cons5
|
|
265
|
|
266 puls a,b,pc
|
|
267
|
|
268 *
|
|
269 * Do screen flipping
|
|
270 * Return when MaxTime goes to zero, or when a signal is received.
|
|
271 *
|
|
272 kwflip
|
|
273 pshs a,b,x
|
|
274 kwfliploop
|
|
275 ldd <MaxTime Count down one extra tick each time through
|
|
276 lbeq kwflipend
|
|
277 lbsr flipscreen Do one flip
|
|
278 ldd <fliprate interval between flips
|
|
279 cmpd <MaxTime
|
|
280 lbls kwflip0 If MaxTime is shorter than this, use MaxTime instead.
|
|
281 ldd <MaxTime
|
|
282 kwflip0
|
|
283 tfr d,x
|
|
284 pshs x
|
|
285 tst <SigCode
|
|
286 bne nosleep2
|
|
287 os9 F$Sleep
|
|
288 nosleep2
|
|
289 pshs x
|
|
290 ldd <MaxTime Count down MaxTime
|
|
291 addd ,s++
|
|
292 subd ,s++
|
|
293 std <MaxTime
|
|
294 tst <SigCode Did we end due to a signal?
|
|
295 beq kwfliploop No, keep flipping.
|
|
296 kwflipend
|
|
297 puls a,b,x,pc
|
|
298
|
|
299 *
|
|
300 * Do animation
|
|
301 * Return when MaxTime goes to zero, or a signal is received.
|
|
302 *
|
|
303 kwanimate
|
|
304 pshs a,b,x
|
|
305 kwanimloop
|
|
306 ldd <MaxTime
|
|
307 lbeq kwanimend If MaxTime is zero, quit now.
|
|
308
|
|
309 ldd <cycleleft Have we timed out for cycle?
|
|
310 bne kwanim0
|
|
311 lbsr docycle Roll the palettes.
|
|
312 ldd <cyclerate Restore the countdown.
|
|
313 std <cycleleft
|
|
314 kwanim0
|
|
315
|
|
316 ldd <extraleft Have we timed out for extra?
|
|
317 bne kwanim1
|
|
318 lbsr dorotate Rotate extra palettes.
|
|
319 ldd <extrarate Restore the countdown.
|
|
320 std <extraleft
|
|
321 kwanim1
|
|
322
|
|
323 ldd <cycleleft Sleep for the appropriate delay
|
|
324 cmpd <extraleft
|
|
325 blo kwanim20 The appropriate delay is the least of
|
|
326 ldd <extraleft cycleleft, extraleft, and MaxTime.
|
|
327 kwanim20
|
|
328 cmpd <MaxTime
|
|
329 blo kwanim2
|
|
330 ldd <MaxTime
|
|
331 kwanim2
|
|
332
|
|
333 tfr d,x Save original delay in D.
|
|
334 tst <SigCode
|
|
335 bne nosleep3
|
|
336 os9 F$Sleep This returns the amount of time that we didn't sleep.
|
|
337 nosleep3
|
|
338 pshs x
|
|
339 subd ,s subtract time left
|
|
340 std ,s This gives total time slept
|
|
341 ldd <MaxTime Count down maximum time left
|
|
342 subd ,s
|
|
343 std <MaxTime
|
|
344 ldd <cycleleft Count down cycle time left
|
|
345 subd ,s
|
|
346 std <cycleleft
|
|
347 ldd <extraleft count down extra time left
|
|
348 subd ,s++ Clean up the stack while we're at it.
|
|
349 std <extraleft
|
|
350
|
|
351 tst <SigCode Were we woken up by a signal?
|
|
352 beq kwanimloop No, keep going.
|
|
353 kwanimend
|
|
354 puls a,b,x,pc
|
|
355
|
|
356 *
|
|
357 * Trivial signal handler... store signal value and exit
|
|
358 *
|
|
359 SigInter
|
|
360 stb SigCode,u Store the signal code.
|
|
361 tfr u,y Set up y as it should be.
|
|
362 tfr u,d
|
|
363 tfr a,dp Set up DP too.
|
|
364 tst <abort Should we abort now?
|
|
365 lbne _abort
|
|
366 rti
|
|
367
|
|
368 SetSig:
|
|
369 pshs x,y,u
|
|
370 leax SigInter,pcr Set the signal intercept
|
|
371 leau ,y
|
|
372 os9 F$Icpt
|
|
373 lbcs _error
|
|
374 puls x,y,u,pc
|
|
375
|
|
376 endsect
|