0
|
1 ********************************************************************
|
|
2 * Clock2 - Motorola 146818 clock driver
|
|
3 *
|
|
4 * $Id$
|
|
5 *
|
|
6 * Ed. Comments Who YY/MM/DD
|
|
7 * ------------------------------------------------------------------
|
|
8 * 1 Created BRI 88/10/06
|
|
9 * 2 Shift D.Tick & exit if UIP (not wait up to
|
|
10 * 2228 uS for completion), general clean up BRI 88/11/17
|
|
11 * 3 Re-wrote clock access to eliminate repeated
|
|
12 * subroutine calls to increase speed BRI 88/11/26
|
|
13 * 4 Changed clock access to once per minute BRI 89/03/25
|
|
14 * 5 More changes BRI 90/04/15
|
|
15
|
|
16 nam Clock2
|
|
17 ttl Motorola 146818 clock driver
|
|
18
|
|
19 edition equ 5
|
|
20 MPISlot equ $33 (MPI Slot $00-$33)
|
|
21
|
|
22 ifp1
|
|
23 use defsfile
|
|
24 endc
|
|
25
|
|
26 ClkAddr equ $FF72 clock base address
|
|
27 Vrsn equ 1
|
|
28 SpeedClk equ $20 32.768 KHz, rate=0
|
|
29 StartClk equ $06 binary, 24 Hour, DST disabled
|
|
30 StopClk equ $86 bit 7 set stops clock to allow setting t
|
|
31
|
|
32 * MC146818/DS1287 clock register map:
|
|
33 org $00
|
|
34 CRegSec rmb $01 seconds register
|
|
35 CRegSAl rmb $01 seconds alarm register
|
|
36 CRegMin rmb $01 minutes register
|
|
37 CRegMAl rmb $01 minutes alarm register
|
|
38 CRegHour rmb $01 hours register
|
|
39 CRegHAl rmb $01 hours alarm register
|
|
40 CRegDayW rmb $01 day of week register
|
|
41 CRegDayM rmb $01 day of month register
|
|
42 CRegMnth rmb $01 months register
|
|
43 CRegYear rmb $01 years register
|
|
44 CRegA rmb $01 bits 7-0: UIP (read only); DV2-DV0; RS3-
|
|
45 CRegB rmb $01 bits 7-0: SET; PIE; AIE; UIE; SQWE; DM;
|
|
46 CRegC rmb $01 bits 7-0: IRQF; PF; AF; UF; Unused3-Unus
|
|
47 CRegD rmb $01 bits 7-0: VRT; Unused6-Unused0
|
|
48 CSRAM rmb $40-. CMOS static RAM
|
|
49
|
|
50 mod CSize,CNam,Systm+Objct,ReEnt+Vrsn,Entry,ClkAddr
|
|
51
|
|
52 CNam fcs "Clock2"
|
|
53 fcb edition
|
|
54 *RTCSlot fcb MPISlot
|
|
55
|
|
56 Entry bra Init clock hardware initialization gets time
|
|
57 nop maintain 3 byte entry table spacing
|
|
58 bra GetTime get hardware time
|
|
59 nop save a couple cycles with short branch a
|
|
60 SetTime clrb no error for return...
|
|
61 pshs cc,d,x,y,u save regs which will be altered
|
|
62 ldx <M$Mem,pcr get clock base addr
|
|
63 leay <SetTable,pcr point [Y] to RTC register set table
|
|
64 ldu #D.Time point [U] to time variables in DP
|
|
65 ldb #(SetEnd-SetTable)/2 get loop count
|
|
66 stb R$B,s save counter to B reg on stack
|
|
67 orcc #IntMasks disable IRQs while setting clock
|
|
68 CSetLoop ldd ,y++ get clock set data
|
|
69 bmi CRegSet [A] Sign bit set, go save [B] to clock requirement
|
|
70 ldb b,u get system time from D.Time variables
|
|
71 CRegSet anda #^Sign clear sign bit
|
|
72 std ,x generate clock address strobe, store dat
|
|
73 dec R$B,s done all clock regs?
|
|
74 bne CSetLoop no, go do next...
|
|
75 L003A ldb #$01
|
|
76 stb <$002E
|
|
77 puls cc,d,x,y,u,pc restore altered regs, return to caller
|
|
78
|
|
79 SetTable equ *
|
|
80 fcb Sign+CRegB,StopClk
|
|
81 fcb Sign+CRegA,SpeedClk
|
|
82 GetTable equ *
|
|
83 fcb CRegYear,D.Year-D.Time
|
|
84 fcb CRegMnth,D.Month-D.Time
|
|
85 fcb CRegDayM,D.Day-D.Time
|
|
86 fcb CRegHour,D.Hour-D.Time
|
|
87 fcb CRegMin,D.Min-D.Time
|
|
88 fcb CRegSec,D.Sec-D.Time
|
|
89 GetEnd equ *
|
|
90 fcb Sign+CRegDayW,$01
|
|
91 fcb Sign+CRegHAl,$00
|
|
92 fcb Sign+CRegMAl,$00
|
|
93 fcb Sign+CRegSAl,$00
|
|
94 fcb Sign+CRegB,StartClk
|
|
95 SetEnd equ *
|
|
96
|
|
97 Init ldb #59 last second in minute
|
|
98 stb <D.Sec force RTC read
|
|
99
|
|
100 GetTime clrb no error for return...
|
|
101 pshs cc,d,x,y,u save regs which will be altered
|
|
102 ldb <D.Sec get current second
|
|
103 incb next...
|
|
104 cmpb #60 done minute?
|
|
105 bhs CGetT00 yes, go read RTC...
|
|
106 stb <D.Sec set new second
|
|
107 bra CGExit go clean up & return
|
|
108 CGetT00 ldx <M$Mem,pcr get clock base addr
|
|
109 lda #CRegA RTC Update In Progress status register
|
|
110 sta ,x generate address strobe
|
|
111 lda 1,x get UIP status
|
|
112 bmi L003A RTC Update In Progress (1:449 chance), go shft D.Ticki
|
|
113 leay <GetTable,pcr point [Y] to RTC "get" register info table
|
|
114 ldu #D.Time point [U] to time variables in DP
|
|
115 ldb #$06
|
|
116 stb R$B,s save counter to B reg on stack
|
|
117 CGetLoop ldd ,y++ get clock register info from table
|
|
118 sta ,x generate clock address strobe
|
|
119 lda 1,x get clock data
|
|
120 sta b,u save data to D.Time variables
|
|
121 dec R$B,s done all D.Time vars?
|
|
122 bne CGetLoop no, go do next...
|
|
123 CGExit puls cc,d,x,y,u,pc recover regs, return to caller
|
|
124
|
|
125 emod
|
|
126 CSize equ *
|
|
127 end
|