]> cloudbase.mooo.com Git - z180-stamp-cpm3.git/blob - cbios/time.180
time and date allways from server. 1.25ms interrupt
[z180-stamp-cpm3.git] / cbios / time.180
1 title 'Time module for the Modular CP/M 3 BIOS'
2
3 public ?time, gs_rtc
4 public prt0ini
5
6
7 extrn @date,@hour,@min,@sec
8 extrn f_cpu
9 extrn ioiniml,div32_16
10 extrn msg.sm,msg.recv
11 extrn _b0call
12
13 include config.inc
14 include z180reg.inc
15
16
17 ;----------------------------------------------------------------------
18 ; c == 00h: get time
19 ; c == ffh: set time
20
21 cseg ; time must be done from resident memory
22 ?time:
23 inc c ;zero if ff
24 ld c,3
25 jr z,time_set
26
27 ld a,(time_to)
28 or a
29 ret nz
30
31 dec c
32 time_set:
33 b0call gs_rtc
34 ld a,0ffh
35 ld (time_to),a
36 ret
37
38 ;----------------------------------------------------------------------
39 ; c = 2: get time
40 ; c = 3: set time
41
42 dseg
43 gs_rtc:
44
45 push hl
46 push de
47
48 ld hl,(@date)
49 ld a,(@hour)
50 ld d,a
51 ld a,(@min)
52 ld e,a
53 ld a,(@sec)
54 ld b,a ;b = sec, c = subcommand
55 push hl ;2
56 push de ;4
57 push bc ;6
58 ld hl,3 * 256 + 0 ;h = command, l = 0
59 push hl ;8
60
61 ld h,l ;hl = 0
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
73 pop hl ;len/command (discard)
74 pop bc ;subc/sec
75 pop de
76 pop hl
77 ld a,b
78 ld (@sec),a
79 ld a,e
80 ld (@min),a
81 ld a,d
82 ld (@hour),a
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)
114 ld bc,PRT_PRE * 800 ;1/800 s == 1,25 ms interrupt rate
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
126
127 ;----------------------------------------------------------------------
128 ; timer interrupt
129 ;
130 ; 1,25 ms clock tick
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
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
152 iprt_1:
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:
159 pop af
160 ei
161 ret
162
163 uptime:
164 dw 0,0
165 time_to:
166 db 0
167
168 end