221
|
1 ********************************************************************
|
|
2 * SWRead - Read SmartWatch clock
|
|
3 *
|
|
4 * $Id$
|
|
5 *
|
|
6 * Copyright May, 1990 by Robert Gault
|
|
7
|
|
8 * SWREAD will read smartwatch compensating for 12hr mode if active
|
|
9 * time will be sent to OS-9 in 24hr mode for compatability
|
|
10 *
|
|
11 * The routine does grab a large uninterruptible block of time from
|
|
12 * the system, but no other way seems possible.
|
|
13 *
|
|
14 * syntax swread [n&] n=1-60 minutes
|
|
15 * D.Daywk stored for possible use
|
|
16 *
|
|
17 * Ed. Comments Who YY/MM/DD
|
|
18 * ------------------------------------------------------------------
|
|
19 * 1 Created RG 91/03/01
|
|
20 * 1 Changed irq handling; MPI handling; RG 91/10/29
|
|
21 * error handling
|
|
22 * 1 Removed relocation routine. Removal could be RG 92/12/26
|
|
23 * dangerous if OS-9 did not grab block from the
|
|
24 * low addresses first. Code must not be in a
|
|
25 * RAM/ROM block when ROMs activated.
|
|
26 * 2 Relocated part of clock read routine to RG 94/12/19
|
|
27 * shorten the time spent with irqs off.
|
|
28
|
|
29 nam SWRead
|
|
30 ttl Read SmartWatch clock
|
|
31
|
|
32 ifp1
|
|
33 use defsfile
|
255
|
34 use systype
|
221
|
35 endc
|
|
36
|
|
37 cartI equ $FF22 cartridge IRQ report
|
|
38 rom equ $FFDE
|
|
39 ram equ $FFDF
|
|
40 IEN equ %00100000
|
|
41 FEN equ %00010000
|
|
42 SCS equ %00000100
|
|
43 ROM1 equ %00000010
|
|
44 ROM0 equ %00000001
|
|
45 *D.Cntury set $6A century byte
|
|
46
|
|
47 type set prgrm+objct
|
|
48 revs set reent+1
|
|
49 edition set 2
|
|
50
|
|
51 mod pgrmend,name,type,revs,start,size
|
|
52
|
|
53 name fcs /SWRead/
|
|
54 fcb edition
|
|
55
|
|
56 locblk0 rmb 2 pointer to block 0
|
|
57 locblk3E rmb 2 pointer to block $3E ie. disk ROM
|
|
58 dpsave rmb 1
|
|
59 sleep rmb 1 sleep interval time in minutes
|
|
60 byte1 rmb 1 temp storage of clock read data; if never changes - no clock
|
|
61 clkflag rmb 1 set when clock is found
|
|
62 mpiimage rmb 1
|
|
63 sleepflg rmb 1 indicates multiple reads requested
|
|
64 timer rmb 1 count down for sleep interval; per minute
|
|
65 century rmb 1 century flag
|
|
66 rawdata rmb 8 direct readout from clock chip
|
|
67
|
|
68 stack rmb 200
|
|
69 size equ .
|
|
70
|
|
71 message1 fcc /no clock found/
|
255
|
72 fcb C$CR
|
221
|
73 setime fcc /setime/ forced chain to setime routine
|
255
|
74 fcb C$CR
|
221
|
75
|
255
|
76 errmes fcb C$LF
|
221
|
77 fcc /Swread syntax:/
|
255
|
78 fcb C$LF,C$LF
|
221
|
79 fcc /swread [n&]/
|
255
|
80 fcb C$LF
|
221
|
81 fcc / The parameter string is optional; n = 1 to 60 min/
|
255
|
82 fcb C$LF
|
221
|
83 fcc / permitting the watch to be poled in background every/
|
255
|
84 fcb C$LF
|
221
|
85 fcc / n minutes. Use decimal time values./
|
255
|
86 fcb C$CR
|
221
|
87 allert fcb $C5,$3A,$A3,$5C,$C5,$3A,$A3,$5C,0
|
|
88
|
|
89 start clr <sleepflg
|
|
90 cmpd #2
|
|
91 blo noparams
|
|
92 ldd ,x
|
|
93 cmpa #'?
|
|
94 lbeq syntax
|
|
95 cmpa #'-
|
|
96 lbeq syntax
|
|
97
|
|
98 cmpb #'0 if second byte is CR then only one number
|
|
99 blo onebyte
|
|
100 subd #$3030 convert from ascii to bcd
|
|
101
|
|
102 cmpd #$600 one hour skip is max
|
|
103 lbhi syntax
|
|
104 cmpb #9 must be a number from 0-9
|
|
105 lbhi syntax
|
|
106
|
|
107 pshs b convert reg.D to hexidecimal
|
|
108 ldb #10
|
|
109 mul
|
|
110 addb ,s+
|
|
111 bra storeit
|
|
112
|
|
113 onebyte suba #'0
|
|
114 cmpa #9
|
|
115 lbhi syntax
|
|
116
|
|
117 storeit stb <timer
|
|
118 stb <sleep used to reset timer on count down
|
|
119 com <sleepflg
|
|
120
|
|
121 noparams equ *
|
255
|
122 lda MPI.Slct
|
221
|
123 anda #3 retain IRQ settings
|
|
124 ora #$30 start at slot 4; ROM setting
|
|
125 sta <mpiimage
|
|
126
|
|
127 doit pshs u
|
|
128 ldb #1 single block
|
|
129 ldx #$3E disk rom; $07C000-$07DFFF
|
255
|
130 os9 F$MapBlk map into user space clock ROM
|
221
|
131 bcs exit2
|
|
132 stu locblk3E save pointer
|
|
133 ldx #0 system direct page
|
255
|
134 os9 F$MapBlk system direct page
|
221
|
135 bcs exit2
|
|
136 leax ,u faster but = to TFR; get pointer for system DP
|
|
137 stu locblk0 save pointer
|
|
138 tfr dp,b get our own DP
|
|
139 stb dpsave
|
|
140
|
|
141 bsr readclk
|
|
142
|
|
143 ldb #1 unmap blocks from user space
|
|
144 ldu locblk3E get pointer
|
255
|
145 os9 F$ClrBlk
|
221
|
146 ldb #1
|
|
147 ldu locblk0 get pointer
|
255
|
148 os9 F$ClrBlk
|
221
|
149 puls u
|
|
150
|
|
151 tst <clkflag was clock found?
|
|
152 beq error2
|
|
153 tst <sleepflg are we in repeat mode?
|
|
154 beq exit
|
|
155
|
|
156 snooze ldx #3540 = one minute of ticks minus one second for overhead
|
255
|
157 os9 F$Sleep
|
221
|
158 cmpx #0
|
|
159 bne exit received signal so quit
|
|
160
|
|
161 dec timer
|
|
162 bne snooze
|
|
163
|
|
164 lda sleep reset timer
|
|
165 sta timer
|
|
166 bra doit go and read the clock
|
|
167
|
|
168 exit2 leas 2,s puls u
|
|
169 coma set cc
|
255
|
170 os9 F$Exit
|
|
171 error ldb #E$IllArg
|
|
172 os9 F$Exit
|
221
|
173
|
|
174 error2 lda #2 error path
|
|
175 leax message1,pcr
|
|
176 ldy #40
|
|
177 os9 I$WritLn
|
|
178 * force a normal Setime as SmartWatch was not detected
|
255
|
179 lda #Prgrm+Objct modul type
|
221
|
180 ldb #2 size of data area
|
|
181 leax setime,pcr
|
|
182 ldy #0 parameter size
|
|
183 leas stack,u
|
|
184 leau size,u
|
|
185 os9 F$Chain
|
|
186 exit clrb
|
|
187 os9 F$exit
|
|
188
|
|
189 * this is the heart of the clock reading routine
|
|
190 * regX regU point to system direct page
|
|
191 readclk pshs cc
|
|
192 lda d.hinit,x get $FF90 image
|
255
|
193 ldb MPI.Slct get current setting
|
221
|
194 pshs d save them
|
|
195 anda #^(IEN+FEN+ROM1+ROM0) no GIME IRQ/FIRQ; external access
|
255
|
196 orcc #IntMasks stop interrupts
|
221
|
197 sta $FF90
|
|
198 sta rom go to ROM mode
|
|
199 ldx <locblk3E point to clock ROM
|
|
200 ldb <mpiimage get new value for MPI
|
|
201 clr <clkflag start with clock not found
|
|
202 lda locblk3E
|
|
203 tfr a,dp point to clock
|
|
204
|
255
|
205 findclk stb MPI.Slct set new slot
|
221
|
206 leay allert,pcr point to clock wakeup code
|
|
207 lda <4 clear clock at $C004
|
|
208 clrb
|
|
209 bita #1 1bit serial I/O port; if no clock, all bits should be 0 or 1
|
|
210 beq low
|
|
211 comb
|
|
212 low stb >byte1 save as flag for found clock
|
|
213
|
|
214 nxtbyte ldb #8 bits/byte
|
|
215 lda ,y+
|
|
216 beq gettime
|
|
217 nxtbit lsra do a serial generation
|
|
218 bcs high
|
|
219 cmpa <0 talk to clock at $C000; cmp faster than tst
|
|
220 bra high2
|
|
221 high cmpa <1 talk to clock at $C001
|
|
222 high2 decb
|
|
223 bne nxtbit
|
|
224 bra nxtbyte
|
|
225
|
|
226 gettime lda #8 8 bytes to read from clock
|
|
227 pshs a
|
|
228 ldy #rawdata
|
|
229 * read serial bit stream from clock
|
|
230 timebyte lsr <4
|
|
231 rora
|
|
232 lsr <4
|
|
233 rora
|
|
234 lsr <4
|
|
235 rora
|
|
236 lsr <4
|
|
237 rora
|
|
238 lsr <4
|
|
239 rora
|
|
240 lsr <4
|
|
241 rora
|
|
242 lsr <4
|
|
243 rora
|
|
244 lsr <4
|
|
245 rora
|
|
246 sta ,y+ store in raw data
|
|
247 cmpa >byte1 if reg.A never changes then no clock
|
|
248 beq maybe always possible that a clock byte might look like ROM
|
|
249 inc >clkflag indicate a found clock
|
|
250 maybe dec ,s
|
|
251 bne timebyte
|
|
252 leas 1,s yank counter
|
|
253 tst >clkflag did we find the clock?
|
|
254 bne found
|
|
255 ldb >mpiimage try another MPI slot
|
|
256 bitb #$30 did we get to slot 0?
|
|
257 beq found
|
|
258 subb #$10 next slot
|
|
259 stb >mpiimage save image so that we don't hunt the next time.
|
|
260 bra findclk
|
|
261
|
|
262 found lda >dpsave
|
|
263 tfr a,dp back to program DP
|
|
264 sta ram go back to RAM mode
|
|
265 puls d
|
255
|
266 stb MPI.Slct restore to original setting
|
221
|
267 tst cartI clear CART flag incase autostart ROM pack was present in MPI
|
|
268 sta $FF90 restore GIME mode
|
|
269 puls cc restore IRQs
|
|
270 tst <clkflag
|
|
271 beq noclk
|
|
272 ldx #rawdata
|
|
273 leay D.Slice,u
|
|
274 ldb #8
|
|
275 pshs b
|
|
276 trans lda ,x+ translate serial data into OS-9 format
|
|
277 ldb ,s
|
|
278 cmpb #1 year
|
|
279 bne notyr
|
|
280 cmpa #$80 binary coded decimal number
|
|
281 bhi nintn
|
|
282 * ldb #20
|
|
283 * stb D.Cntury,u
|
|
284 sta <century
|
|
285 bra notyr
|
|
286 nintn
|
|
287 * ldb #19
|
|
288 * stb D.Cntury,u
|
|
289 clr <century
|
|
290 *notyr ldb ,s
|
|
291 notyr cmpb #4 day of the week
|
|
292 bne notdywk
|
|
293 anda #7
|
|
294 sta D.Daywk,u
|
|
295 bra nxtdata
|
|
296 notdywk cmpb #5 special 12/24, AM/PM indicator
|
|
297 bne cnvrt convert any number
|
|
298 bita #%10000000 12/24 hour bit
|
|
299 beq cnvrt 24 hour time
|
|
300 bita #%00100000 AM/PM bit since 12 hour time, check AM/PM
|
|
301 pshs cc
|
|
302 anda #%00011111 keep only time
|
|
303 puls cc
|
|
304 bne PMhr
|
|
305 cmpa #$12 bcd value
|
|
306 bne cnvrt
|
|
307 clra 12 AM = 0 hrs 24hr time
|
|
308 bra cnvrt
|
|
309 Pmhr cmpa #$12 bcd value
|
|
310 beq cnvrt 12PM = 1200 24 hr time
|
|
311 adda #$12 all other times (1-11) add 12; ie. 1300-2300
|
|
312 cnvrt tfr a,b return result in reg.B
|
|
313 anda #%11110000 get MSN
|
|
314 lsra
|
|
315 lsra
|
|
316 sta ,-s save #4a
|
|
317 lsra
|
|
318 sta ,-s save #2a
|
|
319 subb ,s+ 16a+b-4a
|
|
320 subb ,s+ 12a+b-2a=10a+b
|
|
321 stb ,-y decrease pointer and then store
|
|
322 nxtdata dec ,s
|
|
323 bne trans
|
|
324 tst <century
|
|
325 beq not20
|
|
326 lda #100
|
|
327 adda 1,y
|
|
328 sta 1,y
|
|
329 not20 puls b,pc
|
|
330
|
|
331 noclk clr D.Daywk,u clear garbage as new date routine reads D.Daywk
|
|
332 leay D.Time,u
|
|
333 ldd #7
|
|
334 noclklp sta ,y+ clear clock packet; faster than a clr ,y+
|
|
335 decb
|
|
336 bne noclklp
|
|
337 * clr D.Cntury,u
|
|
338 clr <century
|
|
339 clr <clkflag
|
|
340 rts
|
|
341
|
|
342 syntax lda #2
|
|
343 leax errmes,pcr
|
|
344 ldy #300
|
|
345 os9 I$Writln
|
|
346 clrb
|
|
347 os9 F$Exit
|
|
348
|
|
349 emod
|
|
350 pgrmend equ *
|
|
351 end
|
|
352
|