]> cloudbase.mooo.com Git - z180-stamp-cpm3.git/blob - cbios/ascii.180
ascii.180 interrupt driver for ASCI 0/1
[z180-stamp-cpm3.git] / cbios / ascii.180
1 page 200
2
3 ; Interrupt drivers for ASCI0 and ASCI1
4
5 global as0init
6 global as0ista,as0inp
7 global as0osta,as0out
8 global as1init
9 global as1ista,as1inp
10 global as1osta,as1out
11
12 extrn as_init
13 extrn ff_empty,ff_get,ff_full,ff_put
14 extrn bufinit
15 extrn isv_sw
16
17
18
19 include config.inc
20 include z180reg.inc
21
22
23
24 ;-----------------------------------------------------
25
26 dseg
27
28 mkbuf s0.rx_id, s0.inbuf, s0.rx_len
29 mkbuf s0.tx_id, s0.outbuf,s0.tx_len
30 mkbuf s1.rx_id, s1.inbuf, s1.rx_len
31 mkbuf s1.tx_id, s1.outbuf, s1.tx_len
32
33
34
35 dseg
36
37 ;--------------------------------------------------------------
38 ; Init Serial I/O for input and output (ASCI 0/1)
39 ;
40 ; b: device number
41 ;
42
43
44 ;ser.init:
45 ; ld a,i
46 ; push af ;save IFF
47 ; di
48 ;---
49 ; pop af
50 ; ret po
51 ; ei
52 ; ret ;
53
54 as0init:
55 xor a ;
56 out0 (stat0),a ;Disable rx/tx interrupts
57 ld c,0 ;asci channel number
58 call as_init
59 ld hl,rtxisvjmp0 ;rx/tx int vector
60 ld (ivtab + IV$ASCI0),hl ;
61
62 ld ix,s0.inbuf
63 call bufinit
64 ld ix,s0.outbuf
65 call bufinit
66 ld a,M_RIE
67 out0 (stat0),a ;Enable rx interrupts
68 ret
69
70 as1init:
71 xor a ;
72 out0 (stat1),a ;Disable rx/tx interrupts
73 ld c,1 ;asci channel number
74 call as_init
75
76 ld hl,rtxisvjmp1 ;rx/tx int vector
77 ld (ivtab + IV$ASCI1),hl ;
78
79 push ix
80 ld ix,s1.inbuf
81 call bufinit
82 ld ix,s1.outbuf
83 call bufinit
84 pop ix
85 ld a,M_RIE
86 out0 (stat1),a ;Enable rx interrupts
87 ret
88
89
90 cseg
91 rtxisvjmp0:
92 call isv_sw
93 dw rxtxi0
94 rtxisvjmp1:
95 call isv_sw
96 dw rxtxi1
97
98 ;--------------------------------------------------------------
99
100 dseg
101 as0ista:
102 push ix
103 ld ix,s0.inbuf ;
104 call ff_empty
105 pop ix
106 ret
107
108 ;--------------------------------------------------------------
109
110 as1ista:
111 push ix
112 ld ix,s1.inbuf ;
113 call ff_empty
114 pop ix
115 ret
116
117 ;--------------------------------------------------------------
118 ; Get an input character
119
120 as0inp:
121 push ix
122 ld ix,s0.inbuf ;
123 call ff_get
124 pop ix
125 ret
126
127 ;--------------------------------------------------------------
128 ; Get an input character
129
130 as1inp:
131 push ix
132 ld ix,s1.inbuf ;
133 call ff_get
134 pop ix
135 ret
136
137 ;--------------------------------------------------------------
138 ; Output status
139
140 as0osta:
141 push ix
142 ld ix,s0.outbuf ;
143 call ff_full
144 pop ix
145 ret
146
147 ;--------------------------------------------------------------
148 ; Output status
149
150 as1osta:
151 push ix
152 ld ix,s1.outbuf ;
153 call ff_full
154 pop ix
155 ret
156
157 ;--------------------------------------------------------------
158 ; put character in c in buffer
159 ; destroys hl, bc
160 ; returns output char in a
161
162 as0out:
163 push ix ;
164 ld ix,s0.outbuf ;
165 call ff_put
166 di ;
167 in0 c,(stat0) ;
168 set TIE,c ;
169 out0 (stat0),c ;
170 ei ;
171 pop ix ;
172 ret
173
174 ;--------------------------------------------------------------
175 ; put character in c in buffer
176 ; destroys hl, bc
177 ; returns output char in a
178
179 as1out:
180 push ix ;
181 ld ix,s1.outbuf ;
182 call ff_put
183 di ;
184 in0 c,(stat1) ;
185 set TIE,c ;
186 out0 (stat1),c ;
187 ei ;
188 pop ix ;
189 ret
190
191
192 ;------------------------------------------
193 ; ASCI 1 Transmit/Receive interupt routines
194
195 dseg
196 rxtxi0:
197 in0 e,(stat0) ;receive flag set? 5
198 jp p,txisv0 ;
199
200 in0 d,(rdr0) ;todo: break detection 9
201 bit FE,e ;framing error?
202 jr nz,?0ri_1
203
204 push ix
205 ld ix,s0.inbuf ;
206 ld hl,s0.inbuf ;
207 ld c,(ix+o.in_idx) ;
208 ld b,0
209 add hl,bc
210 ld (hl),d
211
212 ld a,c ;
213 inc a
214 and (ix+o.mask)
215 cp (ix+o.out_idx) ;
216 jr z,$+5 ;skip if buffer is full
217 ld (ix+o.in_idx),a
218 pop ix
219 ?0ri_1:
220 in0 a,(cntla0) ; 1
221 res EFR,a ;
222 out0 (cntla0),a ; 1
223 ret
224
225 txisv0:
226 push ix
227 ld ix,s0.outbuf ;
228
229 ld a,(ix+o.out_idx) ;
230 cp (ix+o.in_idx) ;if index.in == index.out
231 jr z,?0ti_2 ; buffer empty
232
233 ld hl,s0.outbuf ;
234 ld c,a
235 ld b,0
236 add hl,bc
237 ld l,(hl)
238 out0 (tdr0),l ; 7
239
240 inc a
241 and (ix+o.mask)
242 ld (ix+o.out_idx),a
243 jr ?0ti_3
244 ?0ti_2:
245 res TIE,e ;disable tx-int
246 out0 (stat0),e ; 5
247 ?0ti_3:
248 pop ix
249 ret
250
251 ;------------------------------------------
252 ; ASCI 1 Transmit/Receive interupt routines
253
254 dseg
255 rxtxi1:
256 in0 e,(stat1) ;receive flag set? 5
257 jp p,txisv1 ;
258
259 in0 d,(rdr1) ;todo: break detection 9
260 bit FE,e ;framing error?
261 jr nz,??ri_1
262
263 push ix
264 ld ix,s1.inbuf ;
265 ld hl,s1.inbuf ;
266 ld c,(ix+o.in_idx) ;
267 ld b,0
268 add hl,bc
269 ld (hl),d
270
271 ld a,c ;
272 inc a
273 and (ix+o.mask)
274 cp (ix+o.out_idx) ;
275 jr z,$+5 ;skip if buffer is full
276 ld (ix+o.in_idx),a
277 pop ix
278 ??ri_1:
279 in0 a,(cntla1) ; 1
280 res EFR,a ;
281 out0 (cntla1),a ; 1
282 ret
283
284 txisv1:
285 push ix
286 ld ix,s1.outbuf ;
287
288 ld a,(ix+o.out_idx) ;
289 cp (ix+o.in_idx) ;if index.in == index.out
290 jr z,??ti_2 ; buffer empty
291
292 ld hl,s1.outbuf ;
293 ld c,a
294 ld b,0
295 add hl,bc
296 ld l,(hl)
297 out0 (tdr1),l ; 7
298
299 inc a
300 and (ix+o.mask)
301 ld (ix+o.out_idx),a
302 jr ??ti_3
303 ??ti_2:
304 res TIE,e ;disable tx-int
305 out0 (stat1),e ; 5
306 ??ti_3:
307 pop ix
308 ret
309
310
311
312 end