Mercurial > hg > Members > kono > nitros9-code
annotate level1/modules/clock.asm @ 1417:b7b173926ea1
Changes and fixes by Robert Gault
author | boisy |
---|---|
date | Sun, 30 Nov 2003 22:25:56 +0000 |
parents | 7fdef42e19a0 |
children | 67a173d497d5 |
rev | line source |
---|---|
0 | 1 ******************************************************************** |
1313 | 2 * Clock - OS-9 System Clock |
3 * | |
4 * CoCo 3 notes: | |
5 * Includes support for several different RTC chips, GIME Toggle | |
6 * IRQ fix, numerous minor changes. | |
0 | 7 * |
8 * $Id$ | |
9 * | |
1287 | 10 * Edt/Rev YYYY/MM/DD Modified by |
11 * Comment | |
0 | 12 * ------------------------------------------------------------------ |
1313 | 13 * ????/??/?? |
14 * NitrOS-9 2.00 distribution. | |
1287 | 15 * |
1313 | 16 * 9r4 2003/01/01 Boisy G. Pitre |
17 * Back-ported to OS-9 Level Two. | |
1287 | 18 * |
1313 | 19 * 9r5 2003/08/18 Boisy G. Pitre |
20 * Separated clock into Clock and Clock2 for modularity. | |
21 * | |
22 * 9r6 2003/09/04 Boisy G. Pitre | |
23 * Combined Level One and Level Two sources | |
0 | 24 |
1313 | 25 nam Clock |
26 ttl OS-9 System Clock | |
0 | 27 |
1313 | 28 IFP1 |
29 use defsfile | |
30 ENDC | |
0 | 31 |
1313 | 32 Edtn equ 9 |
33 rev equ 6 | |
34 | |
0 | 35 |
1313 | 36 *------------------------------------------------------------ |
37 * | |
38 * Start of module | |
39 * | |
40 mod len,name,Systm+Objct,ReEnt+rev,Init,0 | |
506 | 41 |
1313 | 42 name fcs "Clock" |
43 fcb Edtn | |
44 | |
45 IFEQ Level-1 | |
506 | 46 |
1313 | 47 *TkPerTS equ 2 ticks per time slice |
48 TkPerTS equ TkPerSec/10 ticks per time slice | |
506 | 49 |
1313 | 50 NewSvc fcb F$Time |
0 | 51 fdb FTime-*-2 |
87 | 52 fcb F$VIRQ |
53 fdb FVIRQ-*-2 | |
506 | 54 fcb F$STime |
55 fdb FSTime-*-2 | |
0 | 56 fcb $80 |
57 | |
506 | 58 FSTime ldx R$X,u |
59 ldd ,x | |
60 std <D.Year | |
61 ldd 2,x | |
62 std <D.Day | |
63 ldd 4,x | |
64 std <D.Min | |
65 andcc #^Carry | |
66 | |
67 * | |
1313 | 68 * Call SetTime entry point in Clock2 |
506 | 69 * |
1313 | 70 ldx <D.Clock2 get entry point to Clock2 |
71 jsr $06,x else call GetTime entry point | |
506 | 72 |
73 rts | |
1000 | 74 |
75 * | |
76 * Clock IRQ Entry Point | |
77 * | |
0 | 78 ClockIRQ clra |
79 tfr a,dp set direct page to zero | |
1213
4e235f213651
Lots of changes: bootscripts and bootlists added, sources massaged...
boisy
parents:
1000
diff
changeset
|
80 lda PIA0Base+3 get hw byte |
0 | 81 bmi L0032 branch if sync flag on |
82 jmp [>D.SvcIRQ] | |
1213
4e235f213651
Lots of changes: bootscripts and bootlists added, sources massaged...
boisy
parents:
1000
diff
changeset
|
83 L0032 lda PIA0Base+2 clear interrupt? |
0 | 84 dec <D.Tick decrement tick counter |
85 bne L007F go around if not zero | |
1313 | 86 ldb <D.Sec get minutes/seconds |
0 | 87 * Seconds increment |
88 incb increment seconds | |
89 cmpb #60 full minute? | |
90 bcs L0079 nope... | |
506 | 91 |
1000 | 92 * |
1313 | 93 * Call GetTime entry point in Clock2 |
1000 | 94 * |
1313 | 95 ldx <D.Clock2 get entry point to Clock2 |
96 jsr $03,x call GetTime entry point | |
97 fcb $8C skip next 2 bytes | |
506 | 98 |
1313 | 99 L0079 stb <D.Sec update sec |
506 | 100 L007B lda <D.TSec |
0 | 101 sta <D.Tick |
102 L007F clra | |
103 pshs a | |
1313 | 104 ldy <D.CLTb |
0 | 105 bra L009E |
106 L0087 ldd ,x | |
107 subd #$0001 | |
108 bne L009C | |
109 lda #$01 | |
110 sta ,s | |
111 lda $04,x | |
112 beq L00B8 | |
113 L0096 ora #$01 | |
114 sta $04,x | |
115 ldd $02,x | |
116 L009C std ,x | |
117 L009E ldx ,y++ | |
118 bne L0087 | |
119 lda ,s+ | |
120 beq L00B4 | |
121 ldx <D.Proc | |
122 beq L00AE | |
123 tst P$State,x | |
124 bpl L00BC branch if sysstate not set | |
125 L00AE jsr [>D.Poll] | |
126 bcc L00AE | |
127 L00B4 jmp [>D.AltIRQ] | |
128 L00B8 bsr L00DD | |
129 bra L0096 | |
130 L00BC leay >L00C4,pcr | |
131 jmp [>D.URtoSs] | |
132 L00C4 jsr [>D.Poll] | |
133 bcc L00C4 | |
134 ldx <D.Proc | |
135 ldb P$State,x | |
136 andb #^SysState turn off sysstate bit | |
137 stb P$State,x | |
138 ldd <P$SWI2,x | |
139 std <D.SWI2 | |
140 ldd <D.UsrIRQ | |
141 std <D.SvcIRQ | |
142 bra L00B4 | |
143 L00DD pshs y,x | |
144 L00DF ldx ,y++ | |
145 stx -$04,y | |
146 bne L00DF | |
147 puls y,x | |
148 leay -2,y | |
149 rts | |
150 | |
87 | 151 FVIRQ pshs cc |
0 | 152 orcc #FIRQMask+IRQMask |
1313 | 153 ldy <D.CLTb |
0 | 154 ldx <D.Init |
155 ldb PollCnt,x | |
156 ldx R$X,u | |
157 beq L0118 | |
158 tst ,y | |
159 beq L010C | |
160 subb #$02 | |
161 lslb | |
162 leay b,y | |
163 tst ,y | |
164 bne L0128 | |
165 L0106 tst ,--y | |
166 beq L0106 | |
167 leay $02,y | |
168 L010C ldx R$Y,u | |
169 stx ,y | |
170 ldy R$D,u | |
171 sty ,x | |
172 bra L0124 | |
173 L0118 leax R$Y,u | |
174 L011A tst ,y | |
175 beq L0124 | |
176 cmpx ,y++ | |
177 bne L011A | |
178 bsr L00DD | |
179 L0124 puls cc | |
180 clrb | |
181 rts | |
182 L0128 puls cc | |
183 comb | |
184 ldb #E$Poll | |
185 rts | |
186 | |
1313 | 187 Init pshs dp,cc |
0 | 188 clra |
189 tfr a,dp | |
190 | |
1313 | 191 leax <Clock2,pcr |
192 lda #Systm+Objct | |
193 os9 F$Link | |
194 bcc LinkOk | |
195 jmp >$FFFE reset | |
196 LinkOk sty <D.Clock2 save entry point | |
197 * Call Clock2 init routine | |
198 jsr ,y call init entry point of Clock2 | |
199 | |
200 | |
201 lda #TkPerSec | |
0 | 202 |
203 sta <D.TSec | |
204 sta <D.Tick | |
205 | |
1313 | 206 * Don't need to explicitly read RTC during initialization |
207 ldd #59*256+TkPerTS last second and time slice in minute | |
208 std <D.Sec Will prompt RTC read at next time slice | |
0 | 209 |
1313 | 210 stb <D.TSlice |
211 stb <D.Slice | |
0 | 212 orcc #FIRQMask+IRQMask mask ints |
213 leax >ClockIRQ,pcr | |
214 stx <D.IRQ | |
215 * install system calls | |
1313 | 216 leay >NewSvc,pcr |
0 | 217 os9 F$SSvc |
1213
4e235f213651
Lots of changes: bootscripts and bootlists added, sources massaged...
boisy
parents:
1000
diff
changeset
|
218 ldx #PIA0Base |
0 | 219 clra |
1213
4e235f213651
Lots of changes: bootscripts and bootlists added, sources massaged...
boisy
parents:
1000
diff
changeset
|
220 sta 1,x change PIA0Base side A to DDR |
4e235f213651
Lots of changes: bootscripts and bootlists added, sources massaged...
boisy
parents:
1000
diff
changeset
|
221 sta ,x clear PIA0Base side A |
4e235f213651
Lots of changes: bootscripts and bootlists added, sources massaged...
boisy
parents:
1000
diff
changeset
|
222 sta 3,x change PIA0Base side B to DDR |
0 | 223 coma complement A side A |
1213
4e235f213651
Lots of changes: bootscripts and bootlists added, sources massaged...
boisy
parents:
1000
diff
changeset
|
224 sta 2,x write all 1's to PIA0Base side B |
0 | 225 lda #$34 |
1213
4e235f213651
Lots of changes: bootscripts and bootlists added, sources massaged...
boisy
parents:
1000
diff
changeset
|
226 sta 1,x PIA0Base side A to I/O reg |
0 | 227 lda #$3F |
1213
4e235f213651
Lots of changes: bootscripts and bootlists added, sources massaged...
boisy
parents:
1000
diff
changeset
|
228 sta 3,x PIA0Base side B to I/O reg |
0 | 229 lda 2,x |
506 | 230 |
1313 | 231 puls pc,dp,cc |
506 | 232 |
0 | 233 |
234 * F$Time system call code | |
235 FTime ldx R$X,u | |
236 ldd <D.Year | |
237 std ,x | |
238 ldd <D.Day | |
239 std 2,x | |
240 ldd <D.Min | |
241 std 4,x | |
242 clrb | |
243 rts | |
244 | |
1313 | 245 |
246 | |
247 | |
248 ELSE | |
249 | |
250 | |
251 | |
252 | |
253 * OS-9 Level Two Clock | |
254 | |
255 TkPerTS equ 2 ticks per time slice | |
256 GI.Toggl equ %00000001 GIME CART* IRQ enable bit, for CC3 | |
257 | |
258 * TC9 needs to reset more interrupt sources | |
259 *GI.Toggl equ %00000111 GIME SERINT*, KEYINT*, CART* IRQ enable bits | |
260 | |
261 | |
262 * Table to set up Service Calls: | |
263 * | |
264 NewSvc fcb F$Time | |
265 fdb F.Time-*-2 | |
266 fcb F$VIRQ | |
267 fdb F.VIRQ-*-2 | |
268 fcb F$Alarm | |
269 fdb F.ALARM-*-2 | |
270 fcb F$STime | |
271 fdb F.STime-*-2 | |
272 fcb $80 end of service call installation table | |
273 | |
274 *--------------------------------------------------------- | |
275 * IRQ Handling starts here. | |
276 * | |
277 * Caveat: There may not be a stack at this point, so avoid using one. | |
278 * Stack is set up by the kernel between here and SvcVIRQ. | |
279 * | |
280 SvcIRQ lda >IRQEnR Get GIME IRQ Status and save it. | |
281 ora <D.IRQS | |
282 sta <D.IRQS | |
283 bita #$08 Check for clock interrupt | |
284 beq NoClock | |
285 anda #^$08 Drop clock interrupt | |
286 sta <D.IRQS | |
287 ldx <D.VIRQ Set VIRQ routine to be executed | |
288 clr <D.QIRQ ---x IS clock IRQ | |
289 bra ContIRQ | |
290 | |
291 NoClock leax DoPoll,pcr If not clock IRQ, just poll IRQ source | |
292 IFNE H6309 | |
293 oim #$FF,<D.QIRQ ---x set flag to NOT clock IRQ | |
294 ELSE | |
295 lda #$FF | |
296 sta <D.QIRQ | |
297 ENDC | |
298 ContIRQ stx <D.SvcIRQ | |
299 jmp [D.XIRQ] Chain through Kernel to continue IRQ handling | |
300 | |
301 *------------------------------------------------------------ | |
302 * | |
303 * IRQ handling re-enters here on VSYNC IRQ. | |
304 * | |
305 * - Count down VIRQ timers, mark ones that are done | |
306 * - Call DoPoll/DoToggle to service VIRQs and IRQs and reset GIME | |
307 * - Call Keyboard scan | |
308 * - Update time variables | |
309 * - At end of minute, check alarm | |
310 * | |
311 SvcVIRQ clra Flag if we find any VIRQs to service | |
312 pshs a | |
313 ldy <D.CLTb Get address of VIRQ table | |
314 bra virqent | |
315 | |
316 virqloop equ * | |
317 IFGT Level-2 | |
318 ldd 2,y Get Level 3 extended map type | |
319 orcc #IntMasks | |
320 sta >$0643 | |
321 stb >$0645 | |
322 std >$FFA1 | |
323 andcc #^IntMasks | |
324 ENDC | |
325 | |
326 ldd Vi.Cnt,x Decrement tick count | |
327 IFNE H6309 | |
328 decd --- subd #1 | |
329 ELSE | |
330 subd #$0001 | |
331 ENDC | |
332 bne notzero Is this one done? | |
333 lda Vi.Stat,x Should we reset? | |
334 bmi doreset | |
335 lbsr DelVIRQ No, delete this entry | |
336 doreset ora #$01 Mark this VIRQ as triggered. | |
337 sta Vi.Stat,x | |
338 lda #$80 Add VIRQ as interrupt source | |
339 sta ,s | |
340 ldd Vi.Rst,x Reset from Reset count. | |
341 notzero std Vi.Cnt,x | |
342 virqent ldx ,y++ | |
343 bne virqloop | |
344 | |
345 IFGT Level-2 | |
346 puls d | |
347 orcc #Carry | |
348 stb >$0643 | |
349 stb >$FFA1 | |
350 incb | |
351 stb >$0645 | |
352 stb >$FFA1 | |
353 andcc #^IntMasks | |
354 ELSE | |
355 puls a Get VIRQ status flag: high bit set if VIRQ | |
356 ENDC | |
357 | |
358 ora <D.IRQS Check to see if other hardware IRQ pending. | |
359 bita #%10110111 Any V/IRQ interrupts pending? | |
360 beq toggle | |
361 IFGT Level-2 | |
362 lbsr DoPoll Yes, go service them. | |
363 ELSE | |
364 bsr DoPoll Yes, go service them. | |
365 ENDC | |
366 bra KbdCheck | |
367 toggle equ * | |
368 IFGT Level-2 | |
369 lbsr DoToggle No, toggle GIME anyway | |
370 ELSE | |
371 bsr DoToggle No, toggle GIME anyway | |
372 ENDC | |
373 | |
374 KbdCheck equ * | |
375 IFGT Level-2 | |
376 lda >$0643 grab current map type | |
377 ldb >$0645 | |
378 pshs d save it | |
379 orcc #IntMasks IRQs off | |
380 lda >$0660 SCF local memory ---x | |
381 sta >$0643 into DAT image ---x | |
382 sta >$FFA1 and into RAM ---x | |
383 inca | |
384 sta >$0645 | |
385 sta >$FFA2 map in SCF, CC3IO, WindInt, etc. | |
386 ENDC | |
387 | |
388 jsr [>D.AltIRQ] go update mouse, gfx cursor, keyboard, etc. | |
389 | |
390 IFGT Level-2 | |
391 puls d restore original map type ---x | |
392 orcc #IntMasks | |
393 sta >$0643 into system DAT image ---x | |
394 stb >$0645 | |
395 std >$FFA1 and into RAM ---x | |
396 andcc #$AF | |
397 ENDC | |
398 | |
399 dec <D.Tick End of second? | |
400 bne VIRQend No, skip time update and alarm check | |
401 lda #TkPerSec Reset tick count | |
402 sta <D.Tick | |
403 | |
404 * ATD: Modified to call real time clocks on every minute ONLY. | |
405 inc <D.Sec go up one second | |
406 lda <D.Sec grab current second | |
407 cmpa #60 End of minute? | |
408 blo VIRQend No, skip time update and alarm check | |
409 clr <D.Sec Reset second count to zero | |
410 | |
411 * | |
412 * Call GetTime entry point in Clock2 | |
413 * | |
414 ldx <D.Clock2 get entry point to Clock2 | |
415 jsr $03,x call GetTime entry point | |
416 | |
417 NoGet ldd >WGlobal+G.AlPID | |
418 ble VIRQend Quit if no Alarm set | |
419 ldd >WGlobal+G.AlPckt+3 Does Hour/Minute agree? | |
420 cmpd <D.Hour | |
421 bne VIRQend | |
422 ldd >WGlobal+G.AlPckt+1 Does Month/Day agree? | |
423 cmpd <D.Month | |
424 bne VIRQend | |
425 ldb >WGlobal+G.AlPckt+0 Does Year agree? | |
426 cmpb <D.Year | |
427 bne VIRQend | |
428 ldd >WGlobal+G.AlPID | |
429 cmpd #1 | |
430 beq checkbel | |
431 os9 F$Send | |
432 bra endalarm | |
433 checkbel ldb <D.Sec Sound bell for 15 seconds | |
434 andb #$F0 | |
435 beq dobell | |
436 endalarm ldd #$FFFF | |
437 std >WGlobal+G.AlPID | |
438 bra VIRQend | |
439 dobell ldx >WGlobal+G.BelVec | |
440 beq VIRQend | |
441 jsr ,x | |
442 VIRQend jmp [>D.Clock] Jump to kernel's timeslice routine | |
443 | |
444 *------------------------------------------------------------ | |
445 * Interrupt polling and GIME reset code | |
446 * | |
447 | |
448 * | |
449 * Call [D.Poll] until all interrupts have been handled | |
450 * | |
451 Dopoll | |
452 IFGT Level-2 | |
453 lda >$0643 Level 3: get map type | |
454 ldb >$0645 | |
455 pshs d save for later | |
456 ENDC | |
457 Dopoll.i | |
458 jsr [>D.Poll] Call poll routine | |
459 bcc DoPoll.i Until error (error -> no interrupt found) | |
460 | |
461 IFGT Level-2 | |
462 puls d | |
463 orcc #IntMasks | |
464 sta >$0643 | |
465 stb >$0645 | |
466 std >$FFA1 | |
467 andcc #^IntMasks | |
468 ENDC | |
469 | |
470 * | |
471 * Reset GIME to avoid missed IRQs | |
472 * | |
473 DoToggle lda #^GI.Toggl Mask off CART* bit | |
474 anda <D.IRQS | |
475 sta <D.IRQS | |
476 lda <D.IRQER Get current enable register status | |
477 tfr a,b | |
478 anda #^GI.Toggl Mask off CART* bit | |
479 orb #GI.Toggl --- ensure that 60Hz IRQ's are always enabled | |
480 sta >IRQEnR Disable CART | |
481 stb >IRQEnR Enable CART | |
482 clrb | |
483 rts | |
484 | |
485 | |
486 *------------------------------------------------------------ | |
487 * | |
488 * Handle F$VIRQ system call | |
489 * | |
490 F.VIRQ pshs cc | |
491 orcc #IntMasks Disable interrupts | |
492 ldy <D.CLTb Address of VIRQ table | |
493 ldx <D.Init Address of INIT | |
494 ldb PollCnt,x Number of polling table entries from INIT | |
495 ldx R$X,u Zero means delete entry | |
496 beq RemVIRQ | |
497 IFGT Level-2 | |
498 bra FindVIRQ ---x | |
499 | |
500 v.loop leay 4,y ---x | |
501 ENDC | |
502 FindVIRQ ldx ,y++ Is VIRQ entry null? | |
503 beq AddVIRQ If yes, add entry here | |
504 decb | |
505 bne FindVIRQ | |
506 puls cc | |
507 comb | |
508 ldb #E$Poll | |
509 rts | |
510 | |
511 AddVIRQ | |
512 IFGT Level-2 | |
513 ldx R$Y,u | |
514 stx ,y | |
515 lda >$0643 | |
516 ldb >$0645 | |
517 std 2,y | |
518 ELSE | |
519 leay -2,y point to first null VIRQ entry | |
520 ldx R$Y,u | |
521 stx ,y | |
522 ENDC | |
523 ldy R$D,u | |
524 sty ,x | |
525 bra virqexit | |
526 | |
527 IFGT Level-2 | |
528 v.chk leay 4,y | |
529 RemVIRQ ldx ,y | |
530 ELSE | |
531 RemVIRQ ldx ,y++ | |
532 ENDC | |
533 beq virqexit | |
534 cmpx R$Y,u | |
535 bne RemVIRQ | |
536 bsr DelVIRQ | |
537 virqexit puls cc | |
538 clrb | |
539 rts | |
540 | |
541 DelVIRQ pshs x,y | |
542 DelVLup | |
543 IFGT Level-2 | |
544 ldq ,y++ move entries up in table | |
545 leay 2,y | |
546 stq -8,y | |
547 bne DelVLup | |
548 puls x,y,pc | |
549 ELSE | |
550 ldx ,y++ move entries up in table | |
551 stx -4,y | |
552 bne DelVLup | |
553 puls x,y | |
554 leay -2,y | |
555 rts | |
556 ENDC | |
557 | |
558 IFGT Level-1 | |
559 *------------------------------------------------------------ | |
560 * | |
561 * Handle F$Alarm call | |
562 * | |
563 F.Alarm ldx #WGlobal+G.AlPckt | |
564 ldd R$D,u | |
565 bne DoAlarm | |
566 std G.AlPID-G.AlPckt,x Erase F$Alarm PID, Signal. | |
567 rts | |
568 | |
569 DoAlarm tsta If PID != 0, set alarm for this process | |
570 bne SetAlarm | |
571 cmpd #1 1 -> Set system-wide alarm | |
572 bne GetAlarm | |
573 SetAlarm std G.AlPID-G.AlPckt,x | |
574 ldy <D.Proc | |
575 lda P$Task,y Move from process task | |
576 ldb <D.SysTsk To system task | |
577 ldx R$X,u From address given in X | |
578 ldu #WGlobal+G.AlPckt | |
579 ldy #5 Move 5 bytes | |
580 bra FMove | |
581 | |
582 GetAlarm cmpd #2 | |
583 bne AlarmErr | |
584 ldd G.AlPID-G.AlPckt,x | |
585 std R$D,u | |
586 bra RetTime | |
587 AlarmErr comb | |
588 ldb #E$IllArg | |
589 rts | |
590 ENDC | |
591 | |
592 *------------------------------------------------------------ | |
593 * | |
594 * Handle F$Time System call | |
595 * | |
596 F.Time equ * | |
597 IFGT Level-1 | |
598 ldx #D.Time Address of system time packet | |
599 RetTime ldy <D.Proc Get pointer to current proc descriptor | |
600 ldb P$Task,y Process Task number | |
601 lda <D.SysTsk From System Task | |
602 ldu R$X,u | |
603 STime.Mv ldy #6 Move 6 bytes | |
604 FMove os9 F$Move | |
605 ELSE | |
606 ldx R$X,u get pointer to caller's space | |
607 ldd <D.Year get year and month | |
608 std ,x | |
609 ldd <D.Day get day and hour | |
610 std 2,x | |
611 ldd <D.Min get minute and second | |
612 std 4,x | |
613 clrb | |
614 ENDC | |
615 rts | |
616 | |
617 *------------------------------------------------------------ | |
618 * | |
619 * Handle F$STime system call | |
620 * | |
621 * First, copy time packet from user address space to system time | |
622 * variables, then fall through to code to update RTC. | |
623 * | |
624 F.STime equ * | |
625 IFGT Level-1 | |
626 ldx <D.Proc Caller's process descriptor | |
627 lda P$Task,x Source is in user map | |
628 ldx R$X,u Address of caller's time packet | |
629 ldu #D.Time Destination address | |
630 ldb <D.SysTsk Destination is in system map | |
631 bsr STime.Mv Get time packet (ignore errors) | |
632 ELSE | |
633 ldx R$X,u | |
634 ldd ,x | |
635 std <D.Year | |
636 ldd 2,x | |
637 std <D.Day | |
638 ldd 4,x | |
639 std <D.Min | |
640 ENDC | |
641 lda #TkPerSec Reset to start of second | |
642 sta <D.Tick | |
643 | |
644 * | |
645 * Call SetTime entry point in Clock2 | |
646 * | |
647 ldx <D.Clock2 get entry point to Clock2 | |
648 jsr $06,x else call GetTime entry point | |
649 | |
650 NoSet rts | |
651 | |
652 *-------------------------------------------------- | |
653 * | |
654 * Clock Initialization | |
655 * | |
656 * This vector is called by the kernel to service the first F$STime | |
657 * call. F$STime is usually called by CC3Go (with a dummy argument) | |
658 * in order to initialize the clock. F$STime is re-vectored to the | |
659 * service code above to handle future F$STime calls. | |
660 * | |
661 * | |
662 Init ldx <D.Proc save user proc | |
663 pshs x | |
664 ldx <D.SysPrc make sys for link | |
665 stx <D.Proc | |
666 | |
667 leax <Clock2,pcr | |
668 lda #Systm+Objct | |
669 os9 F$Link | |
670 | |
671 * And here, we restore the original D.Proc value | |
672 puls x | |
673 stx <D.Proc restore user proc | |
674 | |
675 bcc LinkOk | |
676 lda #E$MNF | |
677 jmp <D.Crash | |
678 LinkOk sty <D.Clock2 save entry point | |
679 InitCont ldx #PIA0Base point to PIA0 | |
680 clra no error for return... | |
681 pshs cc save IRQ enable status (and Carry clear) | |
682 orcc #IntMasks stop interrupts | |
683 | |
684 IFGT Level-1 | |
685 * Note: this code can go away once we have a rel_50hz | |
686 IFEQ TkPerSec-50 | |
687 ldb <D.VIDMD get video mode register copy | |
688 orb #$08 set 50 Hz VSYNC bit | |
689 stb <D.VIDMD save video mode register copy | |
690 stb >$FF98 set 50 Hz VSYNC | |
691 ENDC | |
692 ENDC | |
693 | |
694 sta 1,x enable DDRA | |
695 sta ,x set port A all inputs | |
696 sta 3,x enable DDRB | |
697 coma | |
698 sta 2,x set port B all outputs | |
699 ldd #$343C [A]=PIA0 CRA contents, [B]=PIA0 CRB contents | |
700 sta 1,x CA2 (MUX0) out low, port A, disable HBORD high-to-low IRQs | |
701 stb 3,x CB2 (MUX1) out low, port B, disable VBORD low-to-high IRQs | |
702 lda ,x clear possible pending PIA0 HBORD IRQ | |
703 lda 2,x clear possible pending PIA0 VBORD IRQ | |
704 | |
705 * Don't need to explicitly read RTC during initialization | |
706 ldd #59*256+TkPerTS last second and time slice in minute | |
707 std <D.Sec Will prompt RTC read at next time slice | |
708 | |
709 stb <D.TSlice set ticks per time slice | |
710 stb <D.Slice set first time slice | |
711 leax SvcIRQ,pcr set IRQ handler | |
712 stx <D.IRQ | |
713 leax SvcVIRQ,pcr set VIRQ handler | |
714 stx <D.VIRQ | |
715 leay NewSvc,pcr insert syscalls | |
716 os9 F$SSvc | |
717 IFGT Level-1 | |
718 * H6309 optimization opportunity here using oim | |
719 lda <D.IRQER get shadow GIME IRQ enable register | |
720 ora #$08 set VBORD bit | |
721 sta <D.IRQER save shadow register | |
722 sta >IRQEnR enable GIME VBORD IRQs | |
723 ENDC | |
724 | |
725 * Call Clock2 init routine | |
726 ldy <D.Clock2 get entry point to Clock2 | |
727 jsr ,y call init entry point of Clock2 | |
728 InitRts puls cc,pc recover IRQ enable status and return | |
729 | |
730 ENDC | |
731 | |
732 | |
733 Clock2 fcs "Clock2" | |
734 | |
735 emod | |
736 len equ * | |
737 end |