-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathclock.inc.asm
More file actions
278 lines (246 loc) · 5.83 KB
/
Copy pathclock.inc.asm
File metadata and controls
278 lines (246 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
;
;=======================================================================
;
; Modular Z80 DarkStar (NE Z80) Monitor
;
;=======================================================================
;
; RT Clock DS1302
; ---------------------------------------------------------------------
;;
;; RTCWMOD
;; - set DS1302 I/O line as output
rtcwmod:
ld a,$cf ; 11-00-1111 mode ctrl word
; Mode 3 (bit mode port B)
out (crtservcnt),a ; load mode 3 ctrl word
ld a,00011101b ; bit mask 00011101
; |------- b6 out (ds1320 i/o line)
out (crtservcnt),a ; send to PIO2
ret
;;
;; RTCWMOD
;; - set DS1302 I/O line as output
rtcrmod:
ld a,$cf ; 11-00-1111 mode ctrl word
; Mode 3 (bit mode port B)
out (crtservcnt),a ; load mode 3 ctrl word
ld a,01011101b ; bit mask 01011101
; |------- b6 in (ds1320 i/o line)
out (crtservcnt),a ; send to PIO2
ret
clupsclk:
in a,(crtservdat) ; read data port PIO2
set clksclk,a
out (crtservdat),a ; send to PIO2
ret
cllosclk:
in a,(crtservdat) ; read data port PIO2
res clksclk,a
out (crtservdat),a ; send to PIO2
ret
cluprst:
in a,(crtservdat) ; read data port PIO2
set clkrst,a
out (crtservdat),a ; send to PIO2
ret
cllorst:
in a,(crtservdat) ; read data port PIO2
res clkrst,a
out (crtservdat),a ; send to PIO2
ret
;.....
; Set up DS-1302 interface
; Entry: None
; Uses : AF
copen: call rtcrmod ; Data Line to Input
call cllosclk ; Clk LO to Start
call cluprst ; Clear Reset to HI
ret
;.....
; Write the Byte in A to the chip (used for Command)
; Exit : None
; Uses : AF,E
wr1302: push hl ; Save Regs
ld l,a ; Store byte
ld e,8 ; set bit count
call rtcwmod ; data line to output
wr130l: call cllosclk
rrc l ; Data Byte LSB to Carry
jr nc,wr13b0 ; is zero ?
in a,(crtservdat) ; no set to 1
set clkio,a
out (crtservdat),a
jr wr13nx ; next
wr13b0: in a,(crtservdat) ; yes set to 0
res clkio,a
out (crtservdat),a
wr13nx: call clupsclk
dec e ; Eight Bits Sent?
jr nz,wr130l ; ..loop if Not
;
call rtcrmod ; Set Port to Data IN
pop hl ; Restore Regs
ret
;.....
; Deselect the Clock for Exit
; Uses : AF
cclosw: call rtcrmod
cclose: call clupsclk ; HI CLK
call cllorst ; LOW RST
ret
;-------------------------------------------------------------------------
; Dallas DS-1302 Clock Interface
;
; Read the Clock to a buffer area in Memory. Seven bytes are read
; in burst mode from the clock chip, one bit at a time. The Clock is accessed
; serially (LSB first) one byte at a time with a command byte being written to
; begin the Read/Write. Burst Mode is used with a 0BFH byte for Reading,
; 0BEH for Writing as the Command. Clock Setting clears the Write Protect
; bit before setting, and resets the chip to Read-Only when finished.
; The Entire Date/Time String is eight bytes read as:
;
; Sec Min Hour Day Mon DOW Year WProt
; (12/24) (MSB)
;
; In this implementation, the 12/24 hour bit is always set to 24-hour
; mode by clearing the MSB.
rdtime:
call copen ; Set Clock to Read, returning BC->DRA Port
ld d,7 ; 7 Bytes to Read
; Command the DS-1302 for Burst Read of Clock
ld a,10111111b ; Load the Burst Clock Read Command
call wr1302 ; and Send it
; Read the Clock Data.
rddsre:
push hl ; Save Ptr
ld e,8 ; Gather 8 bit for a byte
rdtim1:
call cllosclk ; Clock LO
nop ; (settle)
in a,(crtservdat) ; Read Bit to LSB
rlca ; shift left to
rlca ; move bit 6 to carry
rr l ; to MSB of L
call clupsclk ; Clock HI
dec e ; Byte Done?
jr nz,rdtim1 ; ..jump if Not
ld e,l ; Else Get Byte
pop hl ; Restore Ptr to Dest
ld (hl),e ; Save value in output string
inc hl ; back down to previous byte in output
dec d ; decrement counter
jr nz,rddsre ; ..get another byte if not done
call cclose ; Else Deselect Clock
ld a,$01 ; Set Good Exit
ret
;.....
; Activate the Clock chip and set Date/Time from the parsed string
wrtime:
call copen ; Open the Clock
ld a,10001110b ; select write to control register (8E)
call wr1302
ld a,0 ; Write-Protect Off
call wr1302
call cclosw
call copen
ld a,10111110b ; Burst Write (BE)
ld b,8 ; 8 bytes
call wr1302
stti0:
ld a,(hl)
call wr1302
inc hl
djnz stti0
call cclosw
ret
;;
;; Activate trickle charger
;;
; STTCK: CALL COPEN ; Open the Clock
; LD A,10010000B ; select write to trickle charger reg.
; CALL WR1302
; LD A,10100101B ; prog as 1 diode + 2kohm res. (2.2mA)
; CALL WR1302
; CALL CCLOSW
; RET
;-------------------------------------------------------------------------
; Dallas DS-1302 RAM Interface
;
; Read or write the RAM (31 bytes)
;
;;
;; bios read interface
;;
;; D = data (output), E = index (0-30)
;;
getdsr:
push af
push de
push hl
ld a,e ; check range
cp 31
jr nc,wrrame ; over, jump to WRITE exit
sla e ; adj ptr
ld a,e
or 11000000b ; mask bits to ram
ld e,a
set 0,e ; impose read
call copen ; open device
ld a,e ; ptr to ram
call wr1302 ; send it
ld e,8 ; gather 8 bit for a byte
rdram1:
call cllosclk ; clock lo
nop ; (settle)
in a,(crtservdat) ; read bit to LSB
rlca ; shift left to
rlca ; move bit 6 to carry
rr d ; to MSB of d
call clupsclk ; clock hi
dec e ; byte done?
jr nz,rdram1 ; ..jump if not
call cclose
pop hl
ld a,d
pop de
ld d,a
pop af
ret
;;
;; bios write interface
;;
;; D = data, E = index (0-30)
;;
setdsr:
push af
push de
push hl
ld a,e ; check range
cp 31
jr nc,wrrame ; over
sla e ; adj ptr
ld a,e
or 11000000b ; mask bits
ld e,a
res 0,e ; impose write
exx
call copen ; Open the chip
ld a,10001110b ; select write to control register (8E)
call wr1302
ld a,0 ; Write-Protect Off
call wr1302
call cclosw
call copen
exx
ld a,e ; point to ram loc.
call wr1302
ld a,d
call wr1302 ; write
call cclosw
wrrame:
pop hl
pop de
pop af
ret
; --- EOF ---