1313
|
1 ********************************************************************
|
|
2 * Clock2 - Real-Time Clock Subroutines
|
|
3 *
|
|
4 * $Id$
|
|
5 *
|
|
6 * Edt/Rev YYYY/MM/DD Modified by
|
|
7 * Comment
|
|
8 * ------------------------------------------------------------------
|
|
9 * 1 2003/08/18 Boisy G. Pitre
|
|
10 * Stripped from clock.asm in order to modularize clocks.
|
|
11
|
|
12 nam Clock2
|
|
13 ttl Real-Time Clock Subroutines
|
|
14
|
|
15 ifp1
|
|
16 use defsfile
|
|
17 endc
|
|
18
|
|
19 *
|
|
20 * Setup for specific RTC chip
|
|
21 *
|
|
22 IFNE RTCDriveWire
|
|
23 RTC.Base equ $0000
|
|
24 ENDC
|
|
25
|
|
26 IFNE RTCElim
|
|
27 RTC.Sped equ $20 32.768 KHz, rate=0
|
|
28 RTC.Strt equ $06 binary, 24 Hour, DST disabled
|
|
29 RTC.Stop equ $86 bit 7 set stops clock to allow setting time
|
|
30 RTC.Base equ $FF72 I don't know base for this chip.
|
|
31 ENDC
|
|
32
|
|
33 IFNE RTCDsto2+RTCDsto4
|
|
34 RTC.Base equ $FF50 Base address of clock
|
|
35 ENDC
|
|
36
|
|
37 IFNE RTCBB+RTCTc3
|
|
38 IFNE RTCBB
|
|
39 RTC.Base equ $FF5C In SCS* Decode
|
|
40 ELSE
|
|
41 RTC.Base equ $FF7C Fully decoded RTC
|
|
42 ENDC
|
|
43 RTC.Zero equ -4 Send zero bit by writing this offset
|
|
44 RTC.One equ -3 Send one bit by writing this offset
|
|
45 RTC.Read equ 0 Read data from this offset
|
|
46 ENDC
|
|
47
|
|
48 IFNE RTCSmart
|
|
49 RTC.Base equ $4004 We map the clock into this addr
|
|
50 RTC.Zero equ -4 Send zero bit by writing this offset
|
|
51 RTC.One equ -3 Send one bit by writing this offset
|
|
52 RTC.Read equ 0 Read data from this offset
|
|
53 ENDC
|
|
54
|
|
55 IFNE RTCHarrs
|
|
56 RTC.Base equ $FF60 Base address for clock
|
|
57 ENDC
|
|
58
|
|
59 IFNE RTCSoft
|
|
60 RTC.Base equ 0 Have to have one defined.
|
|
61 ENDC
|
|
62
|
|
63 *------------------------------------------------------------
|
|
64 *
|
|
65 * Start of module
|
|
66 *
|
|
67 mod len,name,Systm+Objct,ReEnt+0,JmpTable,RTC.Base
|
|
68
|
|
69 name fcs "Clock2"
|
|
70 fcb 1
|
|
71
|
|
72 IFNE MPIFlag
|
|
73 SlotSlct fcb MPI.Slot-1 Slot constant for MPI select code
|
|
74 ENDC
|
|
75
|
|
76 * Jump table for RTC
|
|
77 *
|
|
78 * Entry points:
|
|
79 * - Init
|
|
80 * - SetTime
|
|
81 * - GetTime
|
|
82 JmpTable
|
|
83 lbra Init
|
|
84 bra GetTime
|
|
85 nop
|
|
86 lbra SetTime
|
|
87
|
|
88 *
|
|
89 * GetTime Subroutine
|
|
90 *
|
|
91 * This subroutine is called by the main clock module.
|
|
92 *
|
|
93
|
|
94 *
|
|
95 * Eliminator time update (lacks MPI slot select ability)
|
|
96 *
|
|
97 GetTime equ *
|
|
98 IFNE RTCElim
|
|
99 ldx M$Mem,pcr get RTC base address from fake memory requirement
|
|
100 ldb #$0A UIP status register address
|
|
101 stb ,x generate address strobe
|
|
102 lda 1,x get UIP status
|
|
103 bpl NoUIP Update In Progress, go shift next RTC read
|
|
104 lda #TkPerSec/2 set up next RTC read attempt in 1/2 second
|
|
105 sta <D.Tick save tick
|
|
106 bra UpdTExit and return
|
|
107
|
|
108 NoUIP decb year register address
|
|
109 stb ,x generate address strobe
|
|
110 lda 1,x get year
|
|
111 sta <D.Year
|
|
112 decb month register address
|
|
113 stb ,x
|
|
114 lda 1,x
|
|
115 sta <D.Month
|
|
116 decb day of month register address
|
|
117 stb ,x
|
|
118 lda 1,x
|
|
119 sta <D.Day
|
|
120 ldb #4 hour register address
|
|
121 stb ,x
|
|
122 lda 1,x
|
|
123 sta <D.Hour
|
|
124 ldb #2 minute register address
|
|
125 stb ,x
|
|
126 lda 1,x
|
|
127 sta <D.Min
|
|
128 clrb second register address
|
|
129 stb ,x
|
|
130 lda 1,x
|
|
131 SaveSec sta <D.Sec
|
|
132 UpdTExit rts
|
|
133 ENDC
|
|
134
|
|
135 *
|
|
136 * Disto 2-in-1 RTC time update
|
|
137 *
|
|
138 IFNE RTCDsto2
|
|
139 pshs a,cc Save old interrupt status and mask IRQs
|
|
140 bsr RTCPre
|
|
141
|
|
142 bsr GetVal Get Year
|
|
143 bsr GetVal Get Month
|
|
144 bsr GetVal Get Day
|
|
145 decb ldb #5
|
|
146 stb 2,x
|
|
147 decb
|
|
148 lda ,x
|
|
149 anda #3
|
|
150 bsr GetVal1 Get Hour
|
|
151 bsr GetVal Get Minute
|
|
152 bsr GetVal Get Second
|
|
153
|
|
154 RTCPost clr >$FFD9 2 MHz (Really should check $A0 first)
|
|
155 puls cc,b
|
|
156
|
|
157 IFNE MPIFlag
|
|
158 stb >MPI.Slct Restore saved "currently" selected MPak slot
|
|
159 ENDC
|
|
160
|
|
161 clrb
|
|
162 rts
|
|
163
|
|
164 RTCPre orcc #IntMasks
|
|
165
|
|
166 IFNE MPIFlag
|
|
167 ldb >MPI.Slct Save currently selected MPak slot on stack
|
|
168 stb 3,s
|
|
169 andb #$F0
|
|
170 orb >SlotSlct,pcr Get slot to select
|
|
171 stb >MPI.Slct Select MPak slot for clock
|
|
172 ENDC
|
|
173
|
|
174 ldy #D.Time
|
|
175 ldx M$Mem,pcr
|
|
176 clr 1,x
|
|
177 ldb #12
|
|
178 clr >$FFD8 1 MHz
|
|
179 rts
|
|
180
|
|
181 GetVal stb 2,x
|
|
182 decb
|
|
183 lda ,x read tens digit from clock
|
|
184 anda #$0f
|
|
185 GetVal1 pshs b save b
|
|
186 ldb #10
|
|
187 mul multiply by 10 to get value
|
|
188 stb ,y save 10s value
|
|
189 puls b set up clock for ones digit
|
|
190 stb 2,x
|
|
191 decb
|
|
192 lda ,x read ones digit from clock
|
|
193 anda #$0f
|
|
194 adda ,y add ones + tens
|
|
195 sta ,y+ store clock value into time packet
|
|
196 rts
|
|
197
|
|
198 ENDC
|
|
199
|
|
200 *
|
|
201 * Disto 4-in-1 RTC time update
|
|
202 *
|
|
203 IFNE RTCDsto4
|
|
204 IFNE MPIFlag
|
|
205 pshs cc Save old interrupt status and mask IRQs
|
|
206 orcc #IntMasks
|
|
207 ldb >MPI.Slct Save currently selected MPak slot on stack
|
|
208 pshs b
|
|
209 andb #$F0
|
|
210 orb >SlotSlct,pcr Select MPak slot for clock
|
|
211 stb >MPI.Slct
|
|
212 ENDC
|
|
213
|
|
214 ldx M$Mem,pcr
|
|
215 ldy #D.Time Start with seconds
|
|
216
|
|
217 ldb #11
|
|
218 bsr GetVal Get Year
|
|
219 bsr GetVal Get Month
|
|
220 bsr GetVal Get Day
|
|
221 lda #3 Mask tens digit of hour to remove AM/PM bit
|
|
222 bsr GetVal1 Get Hour
|
|
223 bsr GetVal Get Minute
|
|
224 bsr GetVal Get Second
|
|
225
|
|
226 IFNE MPIFlag
|
|
227 puls b Restore saved "currently" selected MPak slot
|
|
228 stb >MPI.Slct
|
|
229 puls cc,pc Restore previous IRQ status
|
|
230 ELSE
|
|
231 rts No MPI, don't need to mess with slot, CC
|
|
232 ENDC
|
|
233
|
|
234 GetVal lda #$0f Mask to apply to tens digit
|
|
235 GetVal1 stb 1,x
|
|
236 decb
|
|
237 anda ,x read ones digit from clock
|
|
238 pshs b save b
|
|
239 ldb #10
|
|
240 mul multiply by 10 to get value
|
|
241 stb ,y Add to ones digit
|
|
242 puls b
|
|
243 stb 1,x
|
|
244 decb
|
|
245 lda ,x read tens digit from clock and mask it
|
|
246 anda #$0f
|
|
247 adda ,y
|
|
248 sta ,y+
|
|
249 rts
|
|
250
|
|
251 ENDC
|
|
252
|
|
253
|
|
254 *
|
|
255 * Update time from DriveWire
|
|
256 *
|
|
257 IFNE RTCDriveWire
|
|
258
|
|
259 lbra DoDW
|
|
260
|
|
261 use bbwrite.asm
|
|
262
|
|
263 DoDW pshs y,x,cc
|
|
264 lda #'# Time packet
|
|
265 orcc #IntMasks Disable interrupts
|
|
266 lbsr SerWrite
|
|
267 bsr SerRead Read year byte
|
|
268 bcs UpdLeave
|
|
269 sta <D.Year
|
|
270 bsr SerRead Read month byte
|
|
271 bcs UpdLeave
|
|
272 sta <D.Month
|
|
273 bsr SerRead Read day byte
|
|
274 bcs UpdLeave
|
|
275 sta <D.Day
|
|
276 bsr SerRead Read hour byte
|
|
277 bcs UpdLeave
|
|
278 sta <D.Hour
|
|
279 bsr SerRead Read minute byte
|
|
280 bcs UpdLeave
|
|
281 sta <D.Min
|
|
282 bsr SerRead Read second byte
|
|
283 bcs UpdLeave
|
|
284 sta <D.Sec
|
|
285 bsr SerRead Read day of week (0-6) byte
|
|
286 UpdLeave puls cc,x,y,pc
|
|
287
|
|
288 use bbread.asm
|
|
289
|
|
290 ENDC
|
|
291
|
|
292 *
|
|
293 * Update time from B&B RTC
|
|
294 *
|
|
295 IFNE RTCBB+RTCTc3
|
|
296 pshs u,y,cc
|
|
297 leay ReadBCD,pcr Read bytes of clock
|
|
298
|
|
299 TfrTime orcc #IntMasks turn off interrupts
|
|
300 ldu M$Mem,pcr Get base address
|
|
301
|
|
302 IFNE MPIFlag
|
|
303 ldb >MPI.Slct Select slot
|
|
304 pshs b
|
|
305 andb #$F0
|
|
306 orb SlotSlct,pcr
|
|
307 stb >MPI.Slct
|
|
308 ENDC
|
|
309
|
|
310 lbsr SendMsg Initialize clock
|
|
311 ldx #D.Sec
|
|
312 ldb #8 Tfr 8 bytes
|
|
313
|
|
314 tfrloop jsr ,y Tfr 1 byte
|
|
315
|
|
316 bitb #$03
|
|
317 beq skipstuf Skip over day-of-week, etc.
|
|
318 leax -1,x
|
|
319 skipstuf decb
|
|
320 bne tfrloop
|
|
321
|
|
322 IFNE MPIFlag
|
|
323 puls b
|
|
324 stb >MPI.Slct restore MPAK slot
|
|
325 ENDC
|
|
326
|
|
327 puls u,y,cc,pc
|
|
328
|
|
329 ClkMsg fcb $C5,$3A,$A3,$5C,$C5,$3A,$A3,$5C
|
|
330 * Enable clock with message $C53AA35CC53AA35C
|
|
331 SendMsg lda RTC.Read,u Send Initialization message to clock
|
|
332 leax <ClkMsg,pcr
|
|
333 ldb #8
|
|
334 msgloop lda ,x+
|
|
335 bsr SendByte
|
|
336 decb
|
|
337 bne msgloop
|
|
338 rts
|
|
339
|
|
340 SendBCD pshs b Send byte to clock, first converting to BCD
|
|
341 bitb #$03
|
|
342 bne BCDskip Send zero for day-of-week, etc.
|
|
343 lda #0
|
|
344 bra SndBCDGo
|
|
345 BCDskip lda ,x
|
|
346 SndBCDGo tfr a,b
|
|
347 bra binenter
|
|
348 binloop adda #6
|
|
349 binenter subb #10
|
|
350 bhs binloop
|
|
351 puls b
|
|
352 SendByte coma Send one byte to clock
|
|
353 rora
|
|
354 bcc sendone
|
|
355 sendzero tst RTC.Zero,u
|
|
356 lsra
|
|
357 bcc sendone
|
|
358 bne sendzero
|
|
359 rts
|
|
360 sendone tst RTC.One,u
|
|
361 lsra
|
|
362 bcc sendone
|
|
363 bne sendzero
|
|
364 rts
|
|
365
|
|
366
|
|
367 ReadBCD pshs b
|
|
368 ldb #$80 High bit will rotate out after we read 8 bits
|
|
369 readbit lda RTC.Read,u Read a bit
|
|
370 lsra
|
|
371 rorb Shift it into B
|
|
372 bcc readbit Stop when marker bit appears
|
|
373 tfr b,a
|
|
374 bra BCDEnter Convert BCD number to Binary
|
|
375 BCDLoop subb #6 by subtracting 6 for each $10
|
|
376 BCDEnter suba #$10
|
|
377 bhs BCDLoop
|
|
378 stb ,x
|
|
379 puls b,pc
|
|
380
|
|
381 ENDC
|
|
382
|
|
383
|
|
384 *
|
|
385 * Update time from Smartwatch RTC
|
|
386 *
|
|
387 IFNE RTCSmart
|
|
388 pshs cc
|
|
389 orcc #IntMasks Disable interrupts
|
|
390 lda >MPI.Slct Get MPI slot
|
|
391 ldb <$90 Get GIME shadow of $FF90
|
|
392 pshs b,a
|
|
393 anda #$F0
|
|
394 ora >SlotSlct,pcr Get new slot to select
|
|
395 anda #$03 *** TEST ***
|
|
396 sta >MPI.Slct And select it
|
|
397 andb #$FC
|
|
398 stb >$FF90 ROM mapping = 16k internal, 16k external
|
|
399 ldb >$FFA2 Read GIME for $4000-$5fff
|
|
400 pshs b
|
|
401 lda #$3E
|
|
402 sta >$FFA2 Put block $3E at $4000-$5fff
|
|
403 clr >$FFDE Map RAM/ROM, to map in external ROM
|
|
404 lbsr SendMsg Initialize clock
|
|
405 ldx #D.Sec Start with seconds
|
|
406 lda #$08
|
|
407 sta ,-s Set up loop counter = 8
|
|
408 L021E ldb #$08
|
|
409 L0220 lda >RTC.Read+RTC.Base Read one bit
|
|
410 lsra
|
|
411 ror ,x Put bit into time
|
|
412 decb End of bit loop
|
|
413 bne L0220
|
|
414 lda ,s Check loop counter
|
|
415 cmpa #$08
|
|
416 beq L023D Fill "seconds" twice (ignore 1st value)
|
|
417 cmpa #$04
|
|
418 bne L0239
|
|
419 ldb ,x Save 4th value read at $34 (day of week?)
|
|
420 stb $0A,x
|
|
421 bra L023D And overwrite "day" with day
|
|
422 L0239 leax -$01,x Go to next time to read
|
|
423 bsr BCD2Dec Convert 1,x from BCD to decimal
|
|
424 L023D dec ,s
|
|
425 bne L021E End of loop for reading time
|
|
426 leas $01,s Done with loop counter
|
|
427 clr >$FFDF Map all RAM
|
|
428 puls b
|
|
429 stb >$FFA2 Put back original memory block
|
|
430 puls b,a
|
|
431 sta >MPI.Slct
|
|
432 stb >$FF90 Restore original ROM mapping
|
|
433 puls cc,pc Re-enable interrupts
|
|
434
|
|
435 * Convert BCD to a normal number
|
|
436
|
|
437 BCD2Dec lda $01,x
|
|
438 clrb
|
|
439 B2DLoop cmpa #$10
|
|
440 bcs B2DDone
|
|
441 suba #$10
|
|
442 addb #$0A
|
|
443 bra B2DLoop
|
|
444 B2DDone pshs a
|
|
445 addb ,s+
|
|
446 stb $01,x
|
|
447 rts
|
|
448
|
|
449 ClkMsg fcb $C5,$3A,$A3,$5C,$C5,$3A,$A3,$5C
|
|
450
|
|
451 * Send above "string" to smartwatch, one bit at a time
|
|
452
|
|
453 SendMsg leax <ClkMsg,pcr
|
|
454 lda >RTC.Read+RTC.Base Tell clock we're going to start???
|
|
455 lda #$08
|
|
456 sta ,-s Store counter = 8
|
|
457 L006B ldb #$08 Start of outer loop, 8 bytes to send
|
|
458 lda ,x+ Get byte to send
|
|
459 L006F lsra Start of inner loop, 8 bits to send
|
|
460 bcs L0077
|
|
461 tst >RTC.Zero+RTC.Base Send a "zero" bit
|
|
462 bra L007A
|
|
463 L0077 tst >RTC.One+RTC.Base Send a "one" bit
|
|
464 L007A decb
|
|
465 bne L006F End of inner loop
|
|
466 dec ,s End of outer loop
|
|
467 bne L006B
|
|
468 puls pc,a
|
|
469
|
|
470 ENDC
|
|
471
|
|
472 *
|
|
473 * Update time from Harris RTC
|
|
474 *
|
|
475 IFNE RTCHarrs
|
|
476 pshs cc
|
|
477 orcc #IntMasks Disable interrupts
|
|
478
|
|
479 ldu M$Mem,pcr Get base address
|
|
480 ldy #D.Time Pointer to time in system map
|
|
481
|
|
482 lda #%00001100 Init command register (Normal,Int. Disabled,
|
|
483 sta $11,u Run,24-hour mode, 32kHz)
|
|
484
|
|
485 lda ,u Read base address to set-up clock regs for read
|
|
486 lda 6,u Get year
|
|
487 sta ,y+
|
|
488 lda 4,u Get month
|
|
489 sta ,y+
|
|
490 lda 5,u Get day
|
|
491 sta ,y+
|
|
492 lda 1,u Get hour
|
|
493 sta ,y+
|
|
494 lda 2,u Get minute
|
|
495 sta ,y+
|
|
496 lda 3,u Get second
|
|
497 sta ,y+
|
|
498
|
|
499 puls cc,pc Re-enable interrupts
|
|
500 ENDC
|
|
501 *
|
|
502 *
|
|
503 * Software time update
|
|
504 *
|
|
505 *
|
|
506
|
|
507 IFNE RTCSoft
|
|
508 lda <D.Min grab current minute
|
|
509 inca minute+1
|
|
510 cmpa #60 End of hour?
|
|
511 blo UpdMin no, Set start of minute
|
|
512 ldd <D.Day get day, hour
|
|
513 incb hour+1
|
|
514 cmpb #24 End of Day?
|
|
515 blo UpdHour ..no
|
|
516 inca day+1
|
|
517 leax months-1,pcr point to months table with offset-1: Jan = +1
|
|
518 ldb <D.Month this month
|
|
519 cmpa b,x end of month?
|
|
520 bls UpdDay ..no, update the day
|
|
521 cmpb #2 yes, is it Feb?
|
|
522 bne NoLeap ..no, ok
|
|
523 ldb <D.Year else get year
|
|
524 andb #$03 check for leap year: good until 2099
|
|
525 cmpd #$1D00 29th on leap year?
|
|
526 beq UpdDay ..yes, skip it
|
|
527 NoLeap ldd <D.Year else month+1
|
|
528 incb month+1
|
|
529 cmpb #13 end of year?
|
|
530 blo UpdMonth ..no
|
|
531 inca year+1
|
|
532 ldb #$01 set month to jan
|
|
533 UpdMonth std <D.Year save year, month
|
|
534 lda #$01 day=1st
|
|
535 UpdDay clrb hour=midnite
|
|
536 UpdHour std <D.Day save day,hour
|
|
537 clra minute=00
|
|
538 UpdMin clrb seconds=00
|
|
539 std <D.Min save min,secs
|
|
540 UpdTExit rts
|
|
541 ENDC
|
|
542
|
|
543 months fcb 31,28,31,30,31,30,31,31,30,31,30,31 Days in each month
|
|
544
|
|
545
|
|
546 SetTime equ *
|
|
547 *
|
|
548 * Set Eliminator RTC from D.Time
|
|
549 *
|
|
550 IFNE RTCElim
|
|
551 pshs cc save interrupt status
|
|
552 orcc #IntMasks disable IRQs
|
|
553 ldx M$Mem,pcr get RTC base address from fake memory requirement
|
|
554 ldy #D.Time point [Y] to time variables in DP
|
|
555 ldd #$0B*256+RTC.Stop
|
|
556 bsr UpdatCk0 stop clock before setting it
|
|
557 ldb #RTC.Sped
|
|
558 bsr UpdatCk0 set crystal speed, output rate
|
|
559 bsr UpdatClk go set year
|
|
560 bsr UpdatClk go set month
|
|
561 bsr UpdatClk go set day of month
|
|
562 bsr UpdatCk0 go set day of week (value doesn't matter)
|
|
563 bsr UpdatCk0 go set hours alarm (value doesn't matter)
|
|
564 bsr UpdatClk go set hour
|
|
565 bsr UpdatCk0 go set minutes alarm (value doesn't matter)
|
|
566 bsr UpdatClk go set minute
|
|
567 bsr UpdatCk0 go set seconds alarm (value doesn't matter)
|
|
568 bsr UpdatClk go set second
|
|
569 ldd #$0B*256+RTC.Strt
|
|
570 bsr UpdatCk0 go start clock
|
|
571 puls cc Recover IRQ status
|
|
572 clrb
|
|
573 rts
|
|
574
|
|
575 UpdatClk ldb ,y+ get data from D.Time variables in DP
|
|
576 UpdatCk0 std ,x generate address strobe, save data
|
|
577 deca set [A] to next register down
|
|
578 rts
|
|
579
|
|
580 IFGT Level-1
|
|
581 * OS-9 Level Two code only (for now)
|
|
582 NewSvc fcb F$NVRAM Eliminator adds one new service call
|
|
583 fdb F.NVRAM-*-2
|
|
584 fcb $80 end of service call installation table
|
|
585
|
|
586 *------------------------------------------------------------
|
|
587 * read/write RTC Non Volatile RAM (NVRAM)
|
|
588 *
|
|
589 * INPUT: [U] = pointer to caller's register stack
|
|
590 * R$A = access mode (1 = read, 2 = write, other = error)
|
|
591 * R$B = byte count (1 through 50 here, but in other implementations
|
|
592 * may be 1 through 256 where 0 implies 256)
|
|
593 * R$X = address of buffer in user map
|
|
594 * R$Y = start address in NVRAM
|
|
595 *
|
|
596 * OUTPUT: RTC NVRAM read/written
|
|
597 *
|
|
598 * ERROR OUTPUT: [CC] = Carry set
|
|
599 * [B] = error code
|
|
600 F.NVRAM tfr u,y copy caller's register stack pointer
|
|
601 ldd #$0100 ask for one page
|
|
602 os9 F$SRqMem
|
|
603 bcs NVR.Exit go report error...
|
|
604 pshs y,u save caller's stack and data buffer pointers
|
|
605 ldx R$Y,y get NVRAM start address
|
|
606 cmpx #50 too high?
|
|
607 bhs Arg.Err yes, go return error...
|
|
608 ldb R$B,y get NVRAM byte count
|
|
609 beq Arg.Err
|
|
610 abx check end address
|
|
611 cmpx #50 too high?
|
|
612 bhi Arg.Err yes, go return error...
|
|
613 lda R$A,y get direction flag
|
|
614 cmpa #WRITE. put caller's data into NVRAM?
|
|
615 bne ChkRead no, go check if read...
|
|
616 clra [D]=byte count
|
|
617 pshs d save it...
|
|
618 ldx <D.Proc get caller's process descriptor address
|
|
619 lda P$Task,x caller is source task
|
|
620 ldb <D.SysTsk system is destination task
|
|
621 ldx R$X,y get caller's source pointer
|
|
622 puls y recover byte count
|
|
623 os9 F$Move go MOVE data
|
|
624 bcs NVR.Err
|
|
625 ldy ,s get caller's register stack pointer from stack
|
|
626 lda R$Y+1,y get NVRAM start address
|
|
627 adda #$0E add offset to first RTC NVRAM address
|
|
628 ldb R$B,y get byte count
|
|
629 ldx M$Mem,pcr get clock base address from fake memory requirement
|
|
630 pshs cc,b save IRQ enable status and byte counter
|
|
631 orcc #IntMasks disable IRQs
|
|
632 WrNVR.Lp ldb ,u+ get caller's data
|
|
633 std ,x generate RTC address strobe and save data to NVRAM
|
|
634 inca next NVRAM address
|
|
635 dec 1,s done yet?
|
|
636 bne WrNVR.Lp no, go save another byte
|
|
637 puls cc,b recover IRQ enable status and clean up stack
|
|
638 NVR.RtM puls y,u recover register stack & data buffer pointers
|
|
639 ldd #$0100 return one page
|
|
640 os9 F$SRtMem
|
|
641 NVR.Exit rts
|
|
642
|
|
643 Arg.Err ldb #E$IllArg Illegal Argument error
|
|
644 bra NVR.Err
|
|
645
|
|
646 ChkRead cmpa #READ. return NVRAM data to caller?
|
|
647 bne Arg.Err illegal access mode, go return error...
|
|
648 lda R$Y+1,y get NVRAM start address
|
|
649 adda #$0E add offset to first RTC NVRAM address
|
|
650 ldx M$Mem,pcr get clock base address from fake memory requirement
|
|
651 pshs cc,b save IRQ enable status and byte counter
|
|
652 orcc #IntMasks disable IRQs
|
|
653 RdNVR.Lp sta ,x generate RTC address strobe
|
|
654 ldb 1,x get NVRAM data
|
|
655 stb ,u+ save it to buffer
|
|
656 inca next NVRAM address
|
|
657 dec 1,s done yet?
|
|
658 bne RdNVR.Lp no, go get another byte
|
|
659 puls cc,a recover IRQ enable status, clean up stack ([A]=0)
|
|
660 ldb R$B,y [D]=byte count
|
|
661 pshs d save it...
|
|
662 ldx <D.Proc get caller's process descriptor address
|
|
663 ldb P$Task,x caller is source task
|
|
664 lda <D.SysTsk system is destination task
|
|
665 ldu R$X,y get caller's source pointer
|
|
666 puls y recover byte count
|
|
667 ldx 2,s get data buffer (source) pointer
|
|
668 os9 F$Move go MOVE data
|
|
669 bcc NVR.RtM
|
|
670 NVR.Err puls y,u recover caller's stack and data pointers
|
|
671 pshs b save error code
|
|
672 ldd #$0100 return one page
|
|
673 os9 F$SRtMem
|
|
674 comb set Carry for error
|
|
675 puls b,pc recover error code, return...
|
|
676
|
|
677 ENDC
|
|
678 ENDC
|
|
679
|
|
680 *
|
|
681 * Set Disto 2-in-1 RTC from Time variables
|
|
682 *
|
|
683 IFNE RTCDsto2
|
|
684 pshs a,cc
|
|
685 lbsr RTCPre Initialize
|
|
686
|
|
687 bsr SetVal Set Year
|
|
688 bsr SetVal Set Month
|
|
689 bsr SetVal Set Day
|
|
690 ldd #$0805 $08 in A, $05 in B
|
|
691 bsr SetVal1 Set Hour (OR value in A ($08) with hour)
|
|
692 bsr SetVal Set Minute
|
|
693 bsr SetVal Set Second
|
|
694
|
|
695 lbra RTCPost Clean up + return
|
|
696
|
|
697 SetVal clra
|
|
698 SetVal1 stb 2,x Set Clock address
|
|
699 decb
|
|
700 pshs b
|
|
701 ldb ,y+ Get current value
|
|
702 DvLoop subb #10 Get Tens digit in A, ones digit in B
|
|
703 bcs DvDone
|
|
704 inca
|
|
705 bra DvLoop
|
|
706 DvDone addb #10
|
|
707 sta ,x Store tens digit
|
|
708 tfr b,a
|
|
709 puls b Get back original clock address
|
|
710 stb 2,x
|
|
711 decb
|
|
712 sta ,x Store ones digit
|
|
713 rts
|
|
714 ENDC
|
|
715
|
|
716 *
|
|
717 * Set Disto 4-in-1 RTC from Time variables
|
|
718 *
|
|
719 IFNE RTCDsto4
|
|
720 pshs cc
|
|
721 orcc #IntMasks
|
|
722
|
|
723 IFNE MPIFlag
|
|
724 ldb >MPI.Slct Save currently selected MPak slot
|
|
725 pshs b
|
|
726 andb #$F0
|
|
727 orb >SlotSlct,pcr Get slot to select
|
|
728 stb >MPI.Slct Select MPak slot for clock
|
|
729 ENDC
|
|
730
|
|
731 ldy #D.Time+6
|
|
732 ldx M$Mem,pcr
|
|
733 clrb
|
|
734 bsr SetVal Set Second
|
|
735 bsr SetVal Set Minute
|
|
736 bsr SetVal Set Hour
|
|
737 bsr SetVal Set Day
|
|
738 bsr SetVal Set Month
|
|
739 bsr SetVal Set Year
|
|
740
|
|
741 IFNE MPIFlag
|
|
742 puls b Restore old MPAK slot
|
|
743 stb >MPI.Slct
|
|
744 ENDC
|
|
745
|
|
746 puls cc
|
|
747 clrb No error
|
|
748 rts
|
|
749
|
|
750 SetVal clr ,-s Create variable for tens digit
|
|
751 lda ,-y Get current value
|
|
752 DvLoop suba #10 Get Tens digit on stack, ones digit in A
|
|
753 bcs DvDone
|
|
754 inc ,s
|
|
755 bra DvLoop
|
|
756 DvDone adda #10
|
|
757 stb 1,x Set Clock address
|
|
758 incb
|
|
759 sta ,x Store ones digit
|
|
760 stb 1,x
|
|
761 incb
|
|
762 puls a
|
|
763 sta ,x Store tens digit
|
|
764 rts
|
|
765 ENDC
|
|
766
|
|
767 *
|
|
768 * Set B&B RTC from Time variables
|
|
769 *
|
|
770 IFNE RTCBB+RTCTc3
|
|
771 pshs u,y,cc
|
|
772 leay SendBCD,pcr Send bytes of clock
|
|
773 lbra TfrTime
|
|
774 ENDC
|
|
775
|
|
776 *
|
|
777 * Set Harris 1770 RTC from Time variables
|
|
778 *
|
|
779 IFNE RTCHarrs
|
|
780 pshs cc
|
|
781 orcc #IntMasks Disable interrupts
|
|
782
|
|
783 ldu M$Mem,pcr Get base address
|
|
784 ldy #D.Time Pointer to time in system map
|
|
785
|
|
786 lda #%00000100 Init command register (Normal,Int. Disabled,
|
|
787 sta $11,u STOP clock,24-hour mode, 32kHz)
|
|
788
|
|
789 lda ,y+ Get year
|
|
790 sta 6,u
|
|
791 lda ,y+ Get month
|
|
792 sta 4,u
|
|
793 lda ,y+ Get day
|
|
794 sta 5,u
|
|
795 lda ,y+ Get hour
|
|
796 sta 1,u
|
|
797 lda ,y+ Get minute
|
|
798 sta 2,u
|
|
799 lda ,y Get second
|
|
800 sta 3,u
|
|
801
|
|
802 lda #%00001100 Init command register (Normal,Int. Disabled,
|
|
803 sta $11,u START clock,24-hour mode, 32kHz)
|
|
804
|
|
805 puls cc,pc Re-enable interrupts
|
|
806 ENDC
|
|
807
|
|
808
|
|
809 *
|
|
810 * RTC-specific initializations here
|
|
811 *
|
|
812 Init equ *
|
|
813 IFNE RTCDsto4
|
|
814 * Disto 4-N-1 RTC specific initialization
|
|
815 ldx M$Mem,pcr
|
|
816 ldd #$010F Set mode for RTC chip
|
|
817 stb 1,x
|
|
818 sta ,x
|
|
819 ldd #$0504
|
|
820 sta ,x
|
|
821 stb ,x
|
|
822 ENDC
|
|
823
|
|
824 IFNE RTCElim
|
|
825 IFGT Level-1
|
|
826 * Eliminator will install specific system calls
|
|
827 leay NewSvc,pcr insert syscalls
|
|
828 os9 F$SSvc
|
|
829 ENDC
|
|
830 ENDC
|
|
831
|
|
832 rts
|
|
833
|
|
834 emod
|
|
835 len equ *
|
|
836 end
|