]>
Commit | Line | Data |
---|---|---|
ea5293bb L |
1 | title 'Time module for the Modular CP/M 3 BIOS' |
2 | ||
f4471ef9 L |
3 | public ?time, gs_rtc |
4 | public prt0ini | |
ea5293bb | 5 | |
ea5293bb L |
6 | |
7 | extrn @date,@hour,@min,@sec | |
f4471ef9 L |
8 | extrn f_cpu |
9 | extrn ioiniml,div32_16 | |
10 | extrn msg.sm,msg.recv | |
ea5293bb L |
11 | |
12 | include config.inc | |
13 | include z180reg.inc | |
14 | ||
15 | ||
f4471ef9 L |
16 | ;---------------------------------------------------------------------- |
17 | ; c == 00h: get time | |
18 | ; c == ffh: set time | |
ea5293bb L |
19 | |
20 | cseg ; time must be done from resident memory | |
ea5293bb | 21 | ?time: |
f4471ef9 L |
22 | inc c ;zero if ff |
23 | ret nz ;nothing to do | |
24 | ||
25 | ld c,3 | |
26 | ||
27 | ; fall thru | |
28 | ||
29 | ;---------------------------------------------------------------------- | |
30 | ; c = 2: get time | |
31 | ; c = 3: set time | |
32 | ||
33 | gs_rtc: | |
34 | ||
35 | push hl | |
36 | push de | |
37 | ||
38 | ld hl,(@date) | |
39 | push hl ;2 | |
40 | ld a,(@hour) | |
41 | ld h,a | |
42 | ld a,(@min) | |
43 | ld l,a | |
44 | push hl ;4 | |
45 | ld a,(@sec) | |
46 | ld b,a ;b = sec, c = subcommand | |
47 | push bc ;6 | |
48 | ld hl,3 * 256 + 0 ;h = command, l = 0 | |
49 | push hl ;8 | |
50 | ||
51 | ld h,l | |
52 | add hl,sp | |
53 | push hl | |
54 | inc hl ;7 | |
55 | ||
56 | ld b,7 | |
57 | call msg.sm | |
58 | ||
59 | pop hl ;8 | |
60 | ld b,8 ; max receive message len | |
61 | call msg.recv | |
62 | ||
63 | pop hl ;len/command | |
64 | pop hl ;subc/sec | |
65 | ld a,h | |
66 | ld (@sec),a | |
67 | pop hl | |
68 | ld a,l | |
69 | ld (@min),a | |
70 | ld a,h | |
71 | ld (@hour),a | |
72 | pop hl | |
73 | ld (@date),hl | |
74 | ||
75 | pop de | |
76 | pop hl | |
77 | ret | |
78 | ||
79 | ||
80 | ;---------------------------------------------------------------------- | |
81 | ; intit timer interrupt | |
82 | ||
83 | dseg | |
84 | ||
85 | prt0ini: | |
86 | in0 a,(tcr) | |
87 | push af | |
88 | and ~(M_TIE0+M_TDE0) ;stop timer 0 | |
89 | out0 (tcr),a | |
90 | ||
91 | ld a,i | |
92 | ld h,a | |
93 | in0 a,(il) | |
94 | and 0E0h | |
95 | or IV$PRT0 | |
96 | ld l,a | |
97 | ld de,isvprt0 | |
98 | ld (hl),e | |
99 | inc hl | |
100 | ld (hl),d | |
101 | ||
102 | ld hl,(f_cpu) | |
103 | ld de,(f_cpu+2) | |
104 | ld bc,PRT_PRE * 100 ;1/100 s == 10 ms interrupt rate | |
105 | call div32_16 | |
106 | ||
107 | out0 (tmdr0l),l | |
108 | out0 (tmdr0h),h | |
109 | out0 (rldr0l),l | |
110 | out0 (rldr0h),h | |
111 | pop af | |
112 | or (M_TIE0+M_TDE0) | |
113 | out0 (tcr),a | |
114 | ret | |
115 | ||
116 | ;---------------------------------------------------------------------- | |
117 | ; timer interrupt | |
118 | ; | |
119 | ; 10 ms clock tick | |
120 | ||
121 | ||
122 | cseg ;common! | |
123 | isvprt0: | |
124 | push af | |
125 | in0 a,(tcr) ;reset TIF0 flag | |
126 | in0 a,(tmdr0l) | |
127 | in0 a,(tmdr0h) | |
128 | ||
129 | ld a,(tim_ms) ; | |
130 | inc a | |
131 | cp 100 ;100 * 10ms ? | |
132 | jr nz,iprt_1 | |
133 | ||
134 | ld a,(@sec) | |
135 | inc a | |
136 | daa | |
137 | cp 60h | |
138 | jr nz,iprt_2 | |
139 | ||
140 | ld a,(@min) | |
141 | inc a | |
142 | daa | |
143 | cp 60h | |
144 | jr nz,iprt_3 | |
145 | ||
146 | ld a,(@hour) | |
147 | inc a | |
148 | daa | |
149 | cp 24h | |
150 | jr nz,iprt_4 | |
151 | ||
152 | push hl | |
153 | ld hl,(@date) | |
154 | inc hl | |
155 | ld (@date),hl | |
156 | pop hl | |
157 | ||
158 | xor a | |
159 | iprt_4: | |
160 | ld (@hour),a | |
161 | xor a | |
162 | iprt_3: | |
163 | ld (@min),a | |
164 | xor a | |
165 | iprt_2: | |
166 | ld (@sec),a | |
167 | xor a | |
168 | iprt_1: | |
169 | ld (tim_ms),a | |
170 | pop af | |
171 | ei | |
172 | ret | |
173 | ||
174 | tim_ms: | |
175 | db 0 | |
ea5293bb L |
176 | |
177 | end |