0
|
1 ********************************************************************
|
|
2 * Clock2 - Dallas Semiconductor 1216E SmartWatch clock driver
|
|
3 *
|
|
4 * $Id$
|
|
5 *
|
|
6 * Ed. Comments Who YY/MM/DD
|
|
7 * ------------------------------------------------------------------
|
|
8 * 1 Created BGP 98/10/04
|
|
9
|
|
10 nam Clock2
|
|
11 ttl Dallas Semiconductor 1216E SmartWatch clock driver
|
|
12
|
|
13 ifp1
|
|
14 use defsfile
|
|
15 endc
|
|
16
|
|
17 rev set 1
|
|
18 edition set 1
|
|
19
|
|
20 RTC.Base equ $2000 We map the clock into this addr
|
|
21 RTC.Blok equ $FFA1 Address corresponding to map RTC ROM block into
|
|
22 RTCMPSlt equ $33 MPI Slot ($00-$33) where RTC is
|
|
23
|
|
24 mod CSize,CNam,Systm+Objct,ReEnt+rev,Entry,RTC.Base
|
|
25
|
|
26 CNam fcs "Clock2"
|
|
27 fcb edition edition byte
|
|
28 SlotSlct fcb RTCMPSlt slot constant for MPI select code
|
|
29
|
|
30 Entry bra Init clock hardware initialization
|
|
31 nop maintain 3 byte entry table spacing
|
|
32 * bra GetTime get hardware time
|
|
33 bra ReadSW get hardware time
|
|
34 nop save a couple cycles with short branch a
|
|
35 bra SetTime set hardware time
|
|
36
|
|
37 * SetTime is not implemented yet
|
|
38 SetTime clrb
|
|
39 rts
|
|
40
|
|
41 GetTime ldb <D.Sec get seconds
|
|
42 incb
|
|
43 cmpb #60
|
|
44 beq ReadSW if zero, get SmartWatch time
|
|
45 stb <D.Sec else update second
|
|
46 rts
|
|
47
|
|
48 Init
|
|
49 ReadSW pshs d,x,y,u save regs which will be altered
|
|
50
|
|
51 ldx #$003E
|
|
52 ldb #1
|
|
53 os9 F$MapBlk
|
|
54 * lbcs exx
|
|
55
|
|
56 pshs cc
|
|
57
|
|
58 * orcc #IntMasks disable interrupts
|
|
59 lda MPI.Slct get MPI slot
|
|
60 ldb <D.HINIT get GIME shadow of $FF90
|
|
61 pshs d
|
|
62 lda SlotSlct,pcr
|
|
63 sta MPI.Slct and select it
|
|
64 andb #$FC
|
|
65 stb $FF90 ROM mapping = 16k internal, 16k external
|
|
66 leay SWKey,pcr
|
|
67 *ROMRAM sta >$FFDE put CC3 in ROM mode
|
|
68 * Loop to write 64 bit key to SmartWatch
|
|
69 MapSW lda $04,u read ROM block (trigger SW)
|
|
70 LoopTop ldb #8 B = bit counter (8)
|
|
71 lda ,y+ get byte in key
|
|
72 beq ReadTime if zero, exit
|
|
73 BitLoop lsra move bit 0 to Carry
|
|
74 bcs Write1 if Carry set, write a 1 to SmartWatch
|
|
75 tst ,u else write 0 to SmartWatch
|
|
76 bra LoopCntl
|
|
77 Write1 tst 1,u
|
|
78 LoopCntl decb dec bit counter
|
|
79 beq LoopTop if more bits, continue
|
|
80 bra BitLoop else move to top of loop and get next byte in key
|
|
81
|
|
82 * Read Time from SmartWatch
|
|
83 ReadTime lda #8
|
|
84 L00CF ldb #8
|
|
85 pshs d
|
|
86 L00D3 ldb 4,u
|
|
87 lsrb
|
|
88 rora
|
|
89 dec 1,s dec count (B) on stack
|
|
90 bne L00D3
|
|
91
|
|
92 * Convert BCD to a normal number
|
|
93 BCD2Dec clrb
|
|
94 B2DLoop cmpa #$10
|
|
95 bcs B2DDone
|
|
96 suba #$10
|
|
97 addb #$0A
|
|
98 bra B2DLoop
|
|
99 B2DDone pshs a
|
|
100 addb ,s+
|
|
101
|
|
102 stb 1,s
|
|
103 puls a
|
|
104 deca
|
|
105 bne L00CF
|
|
106 * sta >$FFDF
|
|
107 * Restore original values and unmask interrupts ASAP
|
|
108 ldx #D.Time
|
|
109 ldd ,s get year/Month
|
|
110 std ,x save year/month
|
|
111 lda 2,s get day
|
|
112 sta 2,x save day
|
|
113 ldd 4,s get hour/min
|
|
114 std 3,x save hour/min
|
|
115 lda 6,s get seconds
|
|
116 sta 5,x save seconds
|
|
117 leas 8,s clean stack
|
|
118 puls d get DINIT/MPI slot
|
|
119 sta >MPI.Slct restore org MPI slot
|
|
120 stb >$FF90 restore org GIME INT0
|
|
121
|
|
122 puls cc
|
|
123
|
|
124 ldb #1
|
|
125 os9 F$ClrBlk
|
|
126
|
|
127 exx
|
|
128 puls pc,d,x,y,u
|
|
129
|
|
130 SWKey fcb %11000101,%00111010,%10100011,%01011100
|
|
131 fcb %11000101,%00111010,%10100011,%01011100
|
|
132 fcb $00
|
|
133
|
|
134 ifeq 1
|
|
135
|
|
136
|
|
137 * Read SmartWatch time
|
|
138 * Entry: Y=copy of stack pointer
|
|
139 ReadSW pshs cc Save interrupt status
|
|
140 orcc #IntMasks Disable interupts
|
|
141
|
|
142 lda >MPI.Slct Get current MPak slot
|
|
143 ldb <D.HINIT Get current GIME init register
|
|
144 pshs d Save current MPak slot & GIME init register
|
|
145 lda #RTCMPSlt Set MPak to slot 4 (both ROM & IRQ select)
|
|
146 sta >MPI.Slct
|
|
147 andb #$FC Set GIME to use 16K Internal/16K External ROM
|
|
148 stb $FF90
|
|
149 lda <D.TINIT Get task side
|
|
150 bita #$01 We in task 1? (either GRFDRV or user task)
|
|
151 bne L0207 Yes, adjust myself for it
|
|
152 * If we are in system state, map ROM block into block 2 of Task 0
|
|
153 ldb RTC.Blok Get current memory block to swap out
|
|
154 pshs d Save it
|
|
155 lda #$3E Get Disk ROM block #
|
|
156 sta RTC.Blok Swap it in
|
|
157 bra ROMRAM Go find Smart watch
|
|
158 * If we are in user state, map ROM block into block 2 of Task 1
|
|
159 L0207 ldb RTC.Blok+8 Get block # to save
|
|
160 pshs d Preserve Init1 register & block # currently mapped
|
|
161 lda #$3E Get Disk ROM block #
|
|
162 sta RTC.Blok+8 Swap it in
|
|
163
|
|
164 * Now, switch to ROM mode and swap Smartwatch in
|
|
165 ROMRAM clr $FFDE Switch to all ROM mode
|
|
166 * pshs dp Preserve DP
|
|
167 * lda #$20 Point DP to ROM/Smartwatch block
|
|
168 * tfr a,dp
|
|
169 lbsr MapSW Swap Smarwatch into beginning of ROM block
|
|
170 ldx #D.Sec Point to system seconds
|
|
171 lda #8 Get # registers to read
|
|
172 sta ,-s Save it on stack
|
|
173 * Read bits from SmartWatch
|
|
174 ReadSW ldb #8 Get # of bits
|
|
175 GetBit lda >RTC.Base+4 Get a bit off the smartwatch
|
|
176 lsra Shift it to carry
|
|
177 ror ,x Move it location
|
|
178 decb Done?
|
|
179 bne GetBit No, keep going
|
|
180 lda ,s Get register #
|
|
181 cmpa #$08 Was it the 1/10th second register?
|
|
182 beq L023D Yes skip it and do it again
|
|
183 cmpa #$04 Was it day of week register?
|
|
184 bne L0239 No, go on to next register
|
|
185 ldb ,x Get the day of week
|
|
186 stb <D.Daywk Save it
|
|
187 bra L023D Move to next register
|
|
188
|
|
189 L0239 leax -1,x Move time packet pointer back
|
|
190 bsr BCD2Dec Convert BCD to hex for current register
|
|
191 L023D dec ,s Done all registers?
|
|
192 bne ReadSW No, go back
|
|
193 leas 1,s Purge stack
|
|
194 * puls dp Get back real DP
|
|
195 clr $FFDF Swap back to all RAM mode
|
|
196 puls d Restore block #
|
|
197 bita #$01 In task 1?
|
|
198 bne L0251 Yes, save block to task 1
|
|
199 stb RTC.Blok Save block to task 0
|
|
200 bra L0254 Continue on
|
|
201 L0251 stb RTC.Blok+8 Save block to task 1
|
|
202 L0254 puls d Restore MPak slot # & GIME init register
|
|
203 sta >MPI.Slct Switch MPak back
|
|
204 stb $FF90 Restore GIME
|
|
205 puls cc,pc Restore interupts & return
|
|
206
|
|
207 * Convert BCD to Hex
|
|
208 BCD2Dec lda 1,x Get BCD byte
|
|
209 clrb Clear out destination byte
|
|
210 L0261 cmpa #16 0-15?
|
|
211 blo L026B Yes, it's fine
|
|
212 suba #16 Subtract 16 from BCD byte
|
|
213 addb #10 Add 10 to destination byte
|
|
214 bra L0261 keep doing until we are done
|
|
215 L026B pshs a Push leftover onto stack
|
|
216 addb ,s+ Add to current destination byte
|
|
217 stb 1,x Store it back
|
|
218 rts return
|
|
219
|
|
220
|
|
221
|
|
222
|
|
223
|
|
224
|
|
225
|
|
226
|
|
227
|
|
228
|
|
229
|
|
230
|
|
231
|
|
232
|
|
233
|
|
234
|
|
235 * Enable SmartWatch
|
|
236 * Entry: S is a new stack ptr for temporary use. ROM has been mapped into
|
|
237 * block 2, which will have the Smartwatch mapped into the beginning of
|
|
238 * it after we send out the 'map in Smartwatch' 64 bit sequence
|
|
239 * Y=original stack pointer, DO NOT MODIFY!
|
|
240 * DP must be $20, for direct page addressing
|
|
241 *
|
|
242 * 6809 optomization: Preserve DP on the stack, and then set it for $20
|
|
243 * Use for $2000/$2001 ops in direct page mode, saving 50+ cycles
|
|
244 * (especially considering interrupts are disabled this whole time!)
|
|
245 * NOTE: all accesses to smartwatch except the init pattern have to be
|
|
246 * READS ONLY, not writes
|
|
247 * 6309: do above, and use LDE instead of TST, as well as F as the counter
|
|
248 * instead of the stack
|
|
249 *
|
|
250
|
|
251 SWBits fcb %11000101,%00111010,%10100011,%01011100
|
|
252 fcb %11000101,%00111010,%10100011,%01011100
|
|
253
|
|
254 MapSW leax SWBits,pc point to coding table
|
|
255 lda >RTC.Base+4 Reset Smarwatch to expect the map in sequence
|
|
256 lda #8 byte counter
|
|
257 sta ,-s onto stack
|
|
258
|
|
259 ByteLoop ldb #8 bit counter
|
|
260 lda ,x+ get code byte
|
|
261 BitLoop lsra shift LSBit out
|
|
262 bcs Write1 if a 1 bit, skip ahead
|
|
263 tst >RTC.Base if 0, test 1st byte of ROM we mapped in
|
|
264 bra DecLoop
|
|
265 Write1 tst >RTC.Base+1 if 1 bit, test 2nd byte of ROM we mapped in
|
|
266 DecLoop decb dec bit counter
|
|
267 bne BitLoop keep reading alternate signals until byte is done
|
|
268 dec ,s dec byte counter
|
|
269 bne ByteLoop keep going until entire 64 bit read pattern done
|
|
270 puls a,pc restore regs & return
|
|
271
|
|
272
|
|
273
|
|
274 endc
|
|
275
|
|
276 emod
|
|
277 CSize equ *
|
|
278 end
|
|
279
|
|
280
|