Mercurial > hg > Members > kono > nitros9-code
annotate level1/modules/clock.asm @ 641:767a608364b2
Some extra comments to the Makefile
author | roug |
---|---|
date | Sun, 08 Dec 2002 11:13:21 +0000 |
parents | 4f81e616d397 |
children | da4002e207e3 |
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 |
35 IFEQ RTCBB+RTCTC3 | |
36 SOFT set 1 | |
37 ENDC | |
38 | |
39 IFNE RTCBB | |
40 MPIFlag set 1 | |
41 SlotSlct set $22 | |
42 RTC.Base equ $FF5C | |
43 ENDC | |
44 IFNE RTCTC3 | |
45 RTC.Base equ $FF7C | |
46 ENDC | |
47 IFNE SOFT | |
48 RTC.Base equ size | |
49 ENDC | |
50 | |
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 | |
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 pshs u,y,cc | |
98 | |
99 ENDC | |
100 | |
101 IFNE RTCBB+RTCTC3 | |
102 | |
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 | |
0 | 192 ClockIRQ clra |
193 tfr a,dp set direct page to zero | |
506 | 194 lda PIA.U4+3 get hw byte |
0 | 195 bmi L0032 branch if sync flag on |
196 jmp [>D.SvcIRQ] | |
506 | 197 L0032 lda PIA.U4+2 clear interrupt? |
0 | 198 dec <D.Tick decrement tick counter |
199 bne L007F go around if not zero | |
200 ldd <D.Min get minutes/seconds | |
201 * Seconds increment | |
202 incb increment seconds | |
203 cmpb #60 full minute? | |
204 bcs L0079 nope... | |
506 | 205 |
206 IFNE RTCBB+RTCTC3 | |
207 | |
208 lbsr UpdTime | |
209 bra L007B | |
210 | |
211 ELSE | |
212 | |
0 | 213 * Minutes increment |
214 inca else increment minute | |
215 cmpa #60 full hour? | |
216 bcs L0078 nope... | |
506 | 217 ldd <D.Day else increment day |
0 | 218 * Hour increment |
219 incb increment hour | |
220 cmpb #24 past 23rd hour? | |
221 bcs L0075 branch if not | |
222 * Day increment | |
223 inca else increment day | |
224 leax >MonthChk,pcr | |
225 ldb <D.Month | |
226 * cmpb #3 is this February? | |
227 * bne L005F | |
228 * ldb <D.Year check year | |
229 * beq L005F if century, it's a leap year | |
230 * andb #$03 leap year? (divisible by 4) | |
231 * beq L0060 nope | |
232 *L005F inca | |
233 *L0060 ldb <D.Month get month | |
234 cmpa b,x compare days to max days | |
235 bls L0074 branch if ok | |
236 cmpb #2 is this February? | |
237 bne L006X if not, go on to year/month | |
238 * Leap year cases checked here | |
239 ldb <D.Year else check for leap year cases | |
240 beq L006X branch if year 1900 | |
241 cmpb #200 is it 1900+200 (2100)? | |
242 beq L006X if so, branch | |
243 andb #$03 see if 2^4 bit set (leap year) | |
244 cmpd #$1D00 29th on leap year? | |
245 beq L0074 it's a leap year... | |
246 L006X ldd <D.Year else get year and month | |
247 * Month increment | |
248 incb increment month | |
249 cmpb #13 past December? | |
250 bcs L0070 branch if not | |
251 * Year increment | |
252 inca else in year | |
253 ldb #1 and start month in January | |
254 L0070 std <D.Year update year/month | |
255 lda #1 new month, first day | |
256 L0074 clrb hour 0 | |
257 L0075 std <D.Day update day/hour | |
258 clra 0 minutes | |
259 L0078 clrb 0 seconds | |
506 | 260 |
261 ENDC | |
262 | |
0 | 263 L0079 std <D.Min update min/sec |
506 | 264 L007B lda <D.TSec |
0 | 265 sta <D.Tick |
266 L007F clra | |
267 pshs a | |
268 ldy <D.CLTB | |
269 bra L009E | |
270 L0087 ldd ,x | |
271 subd #$0001 | |
272 bne L009C | |
273 lda #$01 | |
274 sta ,s | |
275 lda $04,x | |
276 beq L00B8 | |
277 L0096 ora #$01 | |
278 sta $04,x | |
279 ldd $02,x | |
280 L009C std ,x | |
281 L009E ldx ,y++ | |
282 bne L0087 | |
283 lda ,s+ | |
284 beq L00B4 | |
285 ldx <D.Proc | |
286 beq L00AE | |
287 tst P$State,x | |
288 bpl L00BC branch if sysstate not set | |
289 L00AE jsr [>D.Poll] | |
290 bcc L00AE | |
291 L00B4 jmp [>D.AltIRQ] | |
292 L00B8 bsr L00DD | |
293 bra L0096 | |
294 L00BC leay >L00C4,pcr | |
295 jmp [>D.URtoSs] | |
296 L00C4 jsr [>D.Poll] | |
297 bcc L00C4 | |
298 ldx <D.Proc | |
299 ldb P$State,x | |
300 andb #^SysState turn off sysstate bit | |
301 stb P$State,x | |
302 ldd <P$SWI2,x | |
303 std <D.SWI2 | |
304 ldd <D.UsrIRQ | |
305 std <D.SvcIRQ | |
306 bra L00B4 | |
307 L00DD pshs y,x | |
308 L00DF ldx ,y++ | |
309 stx -$04,y | |
310 bne L00DF | |
311 puls y,x | |
312 leay -2,y | |
313 rts | |
314 | |
87 | 315 FVIRQ pshs cc |
0 | 316 orcc #FIRQMask+IRQMask |
317 ldy <D.CLTB | |
318 ldx <D.Init | |
319 ldb PollCnt,x | |
320 ldx R$X,u | |
321 beq L0118 | |
322 tst ,y | |
323 beq L010C | |
324 subb #$02 | |
325 lslb | |
326 leay b,y | |
327 tst ,y | |
328 bne L0128 | |
329 L0106 tst ,--y | |
330 beq L0106 | |
331 leay $02,y | |
332 L010C ldx R$Y,u | |
333 stx ,y | |
334 ldy R$D,u | |
335 sty ,x | |
336 bra L0124 | |
337 L0118 leax R$Y,u | |
338 L011A tst ,y | |
339 beq L0124 | |
340 cmpx ,y++ | |
341 bne L011A | |
342 bsr L00DD | |
343 L0124 puls cc | |
344 clrb | |
345 rts | |
346 L0128 puls cc | |
347 comb | |
348 ldb #E$Poll | |
349 rts | |
350 | |
351 ClkEnt equ * | |
352 pshs dp,cc | |
353 clra | |
354 tfr a,dp | |
355 | |
62
0817702b8a2e
clock.asm now references TPS, defsfile references systype
boisy
parents:
0
diff
changeset
|
356 lda #TPS |
0 | 357 |
358 sta <D.TSec | |
359 sta <D.Tick | |
360 | |
62
0817702b8a2e
clock.asm now references TPS, defsfile references systype
boisy
parents:
0
diff
changeset
|
361 lda #TPS/10 |
0 | 362 |
363 sta <D.TSlice | |
364 sta <D.Slice | |
365 orcc #FIRQMask+IRQMask mask ints | |
366 leax >ClockIRQ,pcr | |
367 stx <D.IRQ | |
368 * install system calls | |
369 leay >SysTbl,pcr | |
370 os9 F$SSvc | |
371 ldx #PIA.U4 | |
372 clra | |
373 sta 1,x change PIA.U4 side A to DDR | |
374 sta ,x clear PIA.U4 side A | |
375 sta 3,x change PIA.U4 side B to DDR | |
376 coma complement A side A | |
377 sta 2,x write all 1's to PIA.U4 side B | |
378 lda #$34 | |
379 sta 1,x PIA.U4 side A to I/O reg | |
380 lda #$3F | |
381 sta 3,x PIA.U4 side B to I/O reg | |
382 lda 2,x | |
506 | 383 |
384 IFEQ SOFT | |
385 | |
386 lbsr UpdTime Update time from RTC if one | |
387 | |
388 ENDC | |
389 | |
0 | 390 puls pc,dp,cc |
391 | |
392 * F$Time system call code | |
393 FTime ldx R$X,u | |
394 ldd <D.Year | |
395 std ,x | |
396 ldd <D.Day | |
397 std 2,x | |
398 ldd <D.Min | |
399 std 4,x | |
400 clrb | |
401 rts | |
402 | |
403 emod | |
404 eom equ * | |
405 end |