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