Mercurial > hg > Members > kono > nitros9-code
annotate level1/modules/clock.asm @ 1071:853a796a1bcd
Removed logbook
author | boisy |
---|---|
date | Mon, 31 Mar 2003 14:10:56 +0000 |
parents | da4002e207e3 |
children | 4e235f213651 |
rev | line source |
---|---|
0 | 1 ******************************************************************** |
2 * Clock - OS-9 Level One V2 Clock module | |
3 * | |
4 * $Id$ | |
5 * | |
6 * NOTE: This clock is TOTALLY VALID for ALL DATES between 1900-2155 | |
7 * | |
8 * Ed. Comments Who YY/MM/DD | |
9 * ------------------------------------------------------------------ | |
506 | 10 * 5 Tandy/Microware original version |
11 * 6 Modified to handle leap years properly for BGP 99/05/03 | |
0 | 12 * 1900 and 2100 A.D. |
506 | 13 * Added TC^3 SCSI/B&B RTC Clock Support BGP 02/05/14 |
0 | 14 |
15 nam Clock | |
16 ttl OS-9 Level One V2 Clock module | |
17 | |
506 | 18 IFP1 |
0 | 19 use defsfile |
506 | 20 ENDC |
0 | 21 |
22 tylg set Systm+Objct | |
23 atrv set ReEnt+rev | |
506 | 24 rev set $1 |
201 | 25 edition set 6 |
0 | 26 |
506 | 27 mod eom,name,tylg,atrv,ClkEnt,RTC.Base |
0 | 28 |
29 size equ . | |
30 | |
31 name fcs /Clock/ | |
32 fcb edition | |
33 | |
506 | 34 * If no RTC defines are set, then this is a software clock |
1000 | 35 IFEQ RTCBB+RTCTC3 |
36 SOFT set 1 | |
506 | 37 ENDC |
38 | |
1000 | 39 IFNE RTCBB |
40 MPIFlag set 1 | |
41 SlotSlct set $22 | |
42 RTC.Base equ $FF5C | |
506 | 43 ENDC |
1000 | 44 IFNE RTCTC3 |
45 RTC.Base equ $FF7C | |
506 | 46 ENDC |
1000 | 47 IFNE SOFT |
48 RTC.Base equ size | |
506 | 49 ENDC |
50 | |
1000 | 51 IFNE RTCBB+RTCTC3 |
52 RTC.Zero equ -4 Send zero bit by writing this offset | |
53 RTC.One equ -3 Send one bit by writing this offset | |
54 RTC.Read equ 0 Read data from this offset | |
506 | 55 ENDC |
56 | |
0 | 57 SysTbl fcb F$Time |
58 fdb FTime-*-2 | |
87 | 59 fcb F$VIRQ |
60 fdb FVIRQ-*-2 | |
506 | 61 |
62 IFEQ SOFT | |
63 | |
64 fcb F$STime | |
65 fdb FSTime-*-2 | |
66 | |
67 ENDC | |
68 | |
0 | 69 fcb $80 |
70 | |
506 | 71 IFNE SOFT |
0 | 72 * table of days of the month |
73 MonthChk fcb 00 | |
74 fcb 31 January | |
75 fcb 28 February | |
76 fcb 31 March | |
77 fcb 30 April | |
78 fcb 31 May | |
79 fcb 30 June | |
80 fcb 31 July | |
81 fcb 31 August | |
82 fcb 30 September | |
83 fcb 31 October | |
84 fcb 30 November | |
85 fcb 31 December | |
86 | |
506 | 87 ELSE |
88 | |
89 FSTime ldx R$X,u | |
90 ldd ,x | |
91 std <D.Year | |
92 ldd 2,x | |
93 std <D.Day | |
94 ldd 4,x | |
95 std <D.Min | |
96 andcc #^Carry | |
97 | |
98 ENDC | |
99 | |
100 IFNE RTCBB+RTCTC3 | |
101 | |
1000 | 102 pshs u,y,cc |
506 | 103 leay SendBCD,pcr Send bytes of clock |
104 lbra TfrTime | |
105 * | |
106 * Update time from B&B/TC3 RTC | |
107 * | |
108 UpdTime pshs u,y,cc | |
109 leay ReadBCD,pcr Read bytes of clock | |
110 | |
111 TfrTime orcc #IntMasks turn off interrupts | |
112 ldu M$Mem,pcr Get base address | |
113 | |
114 IFNE MPIFlag | |
115 ldb >MPI.Slct Select slot | |
116 pshs b | |
117 andb #$F0 | |
118 orb SlotSlct,pcr | |
119 stb >MPI.Slct | |
120 ENDC | |
121 | |
122 lbsr SendMsg Initialize clock | |
123 ldx #D.Sec | |
124 ldb #8 Tfr 8 bytes | |
125 | |
126 tfrloop jsr ,y Tfr 1 byte | |
127 bitb #$03 | |
128 beq skipstuf Skip over day-of-week, etc. | |
129 leax -1,x | |
130 skipstuf decb | |
131 bne tfrloop | |
132 | |
133 IFNE MPIFlag | |
134 puls b | |
135 stb >MPI.Slct restore MPAK slot | |
136 ENDC | |
137 | |
138 puls u,y,cc,pc | |
139 | |
140 ClkMsg fcb $C5,$3A,$A3,$5C,$C5,$3A,$A3,$5C | |
141 * Enable clock with message $C53AA35CC53AA35C | |
142 SendMsg lda RTC.Read,u Send Initialization message to clock | |
143 leax <ClkMsg,pcr | |
144 ldb #8 | |
145 msgloop lda ,x+ | |
146 bsr SendByte | |
147 decb | |
148 bne msgloop | |
149 rts | |
150 | |
151 SendBCD pshs b Send byte to clock, first converting to BCD | |
152 bitb #$03 | |
153 bne BCDskip Send zero for day-of-week, etc. | |
154 lda #0 | |
155 bra SndBCDGo | |
156 BCDskip lda ,x | |
157 SndBCDGo tfr a,b | |
158 bra binenter | |
159 binloop adda #6 | |
160 binenter subb #10 | |
161 bhs binloop | |
162 puls b | |
163 SendByte coma Send one byte to clock | |
164 rora | |
165 bcc sendone | |
166 sendzero tst RTC.Zero,u | |
167 lsra | |
168 bcc sendone | |
169 bne sendzero | |
170 rts | |
171 sendone tst RTC.One,u | |
172 lsra | |
173 bcc sendone | |
174 bne sendzero | |
175 rts | |
176 | |
177 ReadBCD pshs b | |
178 ldb #$80 High bit will rotate out after we read 8 bits | |
179 readbit lda RTC.Read,u Read a bit | |
180 lsra | |
181 rorb Shift it into B | |
182 bcc readbit Stop when marker bit appears | |
183 tfr b,a | |
184 bra BCDEnter Convert BCD number to Binary | |
185 BCDLoop subb #6 by subtracting 6 for each $10 | |
186 BCDEnter suba #$10 | |
187 bhs BCDLoop | |
188 stb ,x | |
189 puls b,pc | |
190 ENDC | |
191 | |
1000 | 192 IFNE RTCDriveWire |
193 rts | |
194 | |
195 use bbwrite.asm | |
196 | |
197 UpdTime pshs y,x,cc | |
198 lda #'# Time packet | |
199 orcc #IntMasks Disable interrupts | |
200 lbsr SerWrite | |
201 bsr SerRead Read year byte | |
202 bcs UpdLeave | |
203 sta <D.Year | |
204 bsr SerRead Read month byte | |
205 bcs UpdLeave | |
206 sta <D.Month | |
207 bsr SerRead Read day byte | |
208 bcs UpdLeave | |
209 sta <D.Day | |
210 bsr SerRead Read hour byte | |
211 bcs UpdLeave | |
212 sta <D.Hour | |
213 bsr SerRead Read minute byte | |
214 bcs UpdLeave | |
215 sta <D.Min | |
216 bsr SerRead Read second byte | |
217 bcs UpdLeave | |
218 sta <D.Sec | |
219 bsr SerRead Read day of week (0-6) byte | |
220 UpdLeave puls cc,x,y,pc | |
221 | |
222 use bbread.asm | |
223 | |
224 ENDC | |
225 | |
226 | |
227 * | |
228 * Clock IRQ Entry Point | |
229 * | |
0 | 230 ClockIRQ clra |
231 tfr a,dp set direct page to zero | |
506 | 232 lda PIA.U4+3 get hw byte |
0 | 233 bmi L0032 branch if sync flag on |
234 jmp [>D.SvcIRQ] | |
506 | 235 L0032 lda PIA.U4+2 clear interrupt? |
0 | 236 dec <D.Tick decrement tick counter |
237 bne L007F go around if not zero | |
238 ldd <D.Min get minutes/seconds | |
239 * Seconds increment | |
240 incb increment seconds | |
241 cmpb #60 full minute? | |
242 bcs L0079 nope... | |
506 | 243 |
1000 | 244 IFNE RTCBB+RTCTC3+RTCDriveWire |
245 * | |
246 * Hardware clock code | |
247 * | |
506 | 248 |
249 lbsr UpdTime | |
250 bra L007B | |
251 | |
1000 | 252 ELSE |
253 * | |
254 * Software clock code | |
255 * | |
0 | 256 * Minutes increment |
257 inca else increment minute | |
258 cmpa #60 full hour? | |
259 bcs L0078 nope... | |
506 | 260 ldd <D.Day else increment day |
0 | 261 * Hour increment |
262 incb increment hour | |
263 cmpb #24 past 23rd hour? | |
264 bcs L0075 branch if not | |
265 * Day increment | |
266 inca else increment day | |
267 leax >MonthChk,pcr | |
268 ldb <D.Month | |
269 * cmpb #3 is this February? | |
270 * bne L005F | |
271 * ldb <D.Year check year | |
272 * beq L005F if century, it's a leap year | |
273 * andb #$03 leap year? (divisible by 4) | |
274 * beq L0060 nope | |
275 *L005F inca | |
276 *L0060 ldb <D.Month get month | |
277 cmpa b,x compare days to max days | |
278 bls L0074 branch if ok | |
279 cmpb #2 is this February? | |
280 bne L006X if not, go on to year/month | |
281 * Leap year cases checked here | |
282 ldb <D.Year else check for leap year cases | |
283 beq L006X branch if year 1900 | |
284 cmpb #200 is it 1900+200 (2100)? | |
285 beq L006X if so, branch | |
286 andb #$03 see if 2^4 bit set (leap year) | |
287 cmpd #$1D00 29th on leap year? | |
288 beq L0074 it's a leap year... | |
289 L006X ldd <D.Year else get year and month | |
290 * Month increment | |
291 incb increment month | |
292 cmpb #13 past December? | |
293 bcs L0070 branch if not | |
294 * Year increment | |
295 inca else in year | |
296 ldb #1 and start month in January | |
297 L0070 std <D.Year update year/month | |
298 lda #1 new month, first day | |
299 L0074 clrb hour 0 | |
300 L0075 std <D.Day update day/hour | |
301 clra 0 minutes | |
302 L0078 clrb 0 seconds | |
506 | 303 |
304 ENDC | |
305 | |
0 | 306 L0079 std <D.Min update min/sec |
506 | 307 L007B lda <D.TSec |
0 | 308 sta <D.Tick |
309 L007F clra | |
310 pshs a | |
311 ldy <D.CLTB | |
312 bra L009E | |
313 L0087 ldd ,x | |
314 subd #$0001 | |
315 bne L009C | |
316 lda #$01 | |
317 sta ,s | |
318 lda $04,x | |
319 beq L00B8 | |
320 L0096 ora #$01 | |
321 sta $04,x | |
322 ldd $02,x | |
323 L009C std ,x | |
324 L009E ldx ,y++ | |
325 bne L0087 | |
326 lda ,s+ | |
327 beq L00B4 | |
328 ldx <D.Proc | |
329 beq L00AE | |
330 tst P$State,x | |
331 bpl L00BC branch if sysstate not set | |
332 L00AE jsr [>D.Poll] | |
333 bcc L00AE | |
334 L00B4 jmp [>D.AltIRQ] | |
335 L00B8 bsr L00DD | |
336 bra L0096 | |
337 L00BC leay >L00C4,pcr | |
338 jmp [>D.URtoSs] | |
339 L00C4 jsr [>D.Poll] | |
340 bcc L00C4 | |
341 ldx <D.Proc | |
342 ldb P$State,x | |
343 andb #^SysState turn off sysstate bit | |
344 stb P$State,x | |
345 ldd <P$SWI2,x | |
346 std <D.SWI2 | |
347 ldd <D.UsrIRQ | |
348 std <D.SvcIRQ | |
349 bra L00B4 | |
350 L00DD pshs y,x | |
351 L00DF ldx ,y++ | |
352 stx -$04,y | |
353 bne L00DF | |
354 puls y,x | |
355 leay -2,y | |
356 rts | |
357 | |
87 | 358 FVIRQ pshs cc |
0 | 359 orcc #FIRQMask+IRQMask |
360 ldy <D.CLTB | |
361 ldx <D.Init | |
362 ldb PollCnt,x | |
363 ldx R$X,u | |
364 beq L0118 | |
365 tst ,y | |
366 beq L010C | |
367 subb #$02 | |
368 lslb | |
369 leay b,y | |
370 tst ,y | |
371 bne L0128 | |
372 L0106 tst ,--y | |
373 beq L0106 | |
374 leay $02,y | |
375 L010C ldx R$Y,u | |
376 stx ,y | |
377 ldy R$D,u | |
378 sty ,x | |
379 bra L0124 | |
380 L0118 leax R$Y,u | |
381 L011A tst ,y | |
382 beq L0124 | |
383 cmpx ,y++ | |
384 bne L011A | |
385 bsr L00DD | |
386 L0124 puls cc | |
387 clrb | |
388 rts | |
389 L0128 puls cc | |
390 comb | |
391 ldb #E$Poll | |
392 rts | |
393 | |
394 ClkEnt equ * | |
395 pshs dp,cc | |
396 clra | |
397 tfr a,dp | |
398 | |
62
0817702b8a2e
clock.asm now references TPS, defsfile references systype
boisy
parents:
0
diff
changeset
|
399 lda #TPS |
0 | 400 |
401 sta <D.TSec | |
402 sta <D.Tick | |
403 | |
62
0817702b8a2e
clock.asm now references TPS, defsfile references systype
boisy
parents:
0
diff
changeset
|
404 lda #TPS/10 |
0 | 405 |
406 sta <D.TSlice | |
407 sta <D.Slice | |
408 orcc #FIRQMask+IRQMask mask ints | |
409 leax >ClockIRQ,pcr | |
410 stx <D.IRQ | |
411 * install system calls | |
412 leay >SysTbl,pcr | |
413 os9 F$SSvc | |
414 ldx #PIA.U4 | |
415 clra | |
416 sta 1,x change PIA.U4 side A to DDR | |
417 sta ,x clear PIA.U4 side A | |
418 sta 3,x change PIA.U4 side B to DDR | |
419 coma complement A side A | |
420 sta 2,x write all 1's to PIA.U4 side B | |
421 lda #$34 | |
422 sta 1,x PIA.U4 side A to I/O reg | |
423 lda #$3F | |
424 sta 3,x PIA.U4 side B to I/O reg | |
425 lda 2,x | |
506 | 426 |
427 IFEQ SOFT | |
428 | |
429 lbsr UpdTime Update time from RTC if one | |
430 | |
431 ENDC | |
432 | |
0 | 433 puls pc,dp,cc |
434 | |
435 * F$Time system call code | |
436 FTime ldx R$X,u | |
437 ldd <D.Year | |
438 std ,x | |
439 ldd <D.Day | |
440 std 2,x | |
441 ldd <D.Min | |
442 std 4,x | |
443 clrb | |
444 rts | |
445 | |
446 emod | |
447 eom equ * | |
448 end |