]> cloudbase.mooo.com Git - z180-stamp-cpm3.git/blob - cbios/ascii.180
Add RTS/CTS flow control for asci0.
[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,ff_cnt
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_cnt
124 cp 32
125 jr c,a0i_1
126 di
127 in0 a,(cntla0)
128 res RTS0,a
129 out0 (cntla0),a
130 ei
131 a0i_1:
132 call ff_get
133 pop ix
134 ret
135
136 ;--------------------------------------------------------------
137 ; Get an input character
138
139 as1inp:
140 push ix
141 ld ix,s1.inbuf ;
142 call ff_get
143 pop ix
144 ret
145
146 ;--------------------------------------------------------------
147 ; Output status
148
149 as0osta:
150 push ix
151 ld ix,s0.outbuf ;
152 call ff_full
153 pop ix
154 ret
155
156 ;--------------------------------------------------------------
157 ; Output status
158
159 as1osta:
160 push ix
161 ld ix,s1.outbuf ;
162 call ff_full
163 pop ix
164 ret
165
166 ;--------------------------------------------------------------
167 ; put character in c in buffer
168 ; destroys hl, bc
169 ; returns output char in a
170
171 as0out:
172 push ix ;
173 ld ix,s0.outbuf ;
174 call ff_put
175 di ;
176 in0 c,(stat0) ;
177 set TIE,c ;
178 out0 (stat0),c ;
179 ei ;
180 pop ix ;
181 ret
182
183 ;--------------------------------------------------------------
184 ; put character in c in buffer
185 ; destroys hl, bc
186 ; returns output char in a
187
188 as1out:
189 push ix ;
190 ld ix,s1.outbuf ;
191 call ff_put
192 di ;
193 in0 c,(stat1) ;
194 set TIE,c ;
195 out0 (stat1),c ;
196 ei ;
197 pop ix ;
198 ret
199
200
201 ;------------------------------------------
202 ; ASCI 1 Transmit/Receive interupt routines
203
204 dseg
205 rxtxi0:
206 in0 e,(stat0) ;receive flag set? 5
207 jp p,txisv0 ;
208
209 in0 a,(rdr0) ;todo: break detection 9
210 in0 d,(cntla0) ; 1
211 res EFR,d ;
212 bit FE,e ;framing error?
213 jr nz,?0ri_1
214
215 push ix
216 ld ix,s0.inbuf ;
217 ld hl,s0.inbuf ;
218 ld c,(ix+o.in_idx) ;
219 ld b,0
220 add hl,bc
221 ld (hl),a
222
223 ld a,c ;
224 inc a
225 and (ix+o.mask)
226 ld c,a
227 sub (ix+o.out_idx) ;
228 jr z,$+5 ;skip if buffer is full
229 ld (ix+o.in_idx),c
230 jr nc,$+6
231 add (ix+o.mask)
232 inc a
233 cp 96
234 jr c,$+4
235 set RTS0,d ;RTS inactive
236 pop ix
237 ?0ri_1:
238 out0 (cntla0),d ; 1
239
240 txisv0:
241 bit TDRE,e
242 ret z
243
244 push ix
245 ld ix,s0.outbuf ;
246
247 ld a,(ix+o.out_idx) ;
248 cp (ix+o.in_idx) ;if index.in == index.out
249 jr z,?0ti_2 ; buffer empty
250
251 ld hl,s0.outbuf ;
252 ld c,a
253 ld b,0
254 add hl,bc
255 ld l,(hl)
256 out0 (tdr0),l ; 7
257
258 inc a
259 and (ix+o.mask)
260 ld (ix+o.out_idx),a
261 jr ?0ti_3
262 ?0ti_2:
263 res TIE,e ;disable tx-int
264 out0 (stat0),e ; 5
265 ?0ti_3:
266 pop ix
267 ret
268
269 ;------------------------------------------
270 ; ASCI 1 Transmit/Receive interupt routines
271
272 dseg
273 rxtxi1:
274 in0 e,(stat1) ;receive flag set? 5
275 jp p,txisv1 ;
276
277 in0 d,(rdr1) ;todo: break detection 9
278 bit FE,e ;framing error?
279 jr nz,??ri_1
280
281 push ix
282 ld ix,s1.inbuf ;
283 ld hl,s1.inbuf ;
284 ld c,(ix+o.in_idx) ;
285 ld b,0
286 add hl,bc
287 ld (hl),d
288
289 ld a,c ;
290 inc a
291 and (ix+o.mask)
292 cp (ix+o.out_idx) ;
293 jr z,$+5 ;skip if buffer is full
294 ld (ix+o.in_idx),a
295 pop ix
296 ??ri_1:
297 in0 a,(cntla1) ; 1
298 res EFR,a ;
299 out0 (cntla1),a ; 1
300 ret
301
302 txisv1:
303 push ix
304 ld ix,s1.outbuf ;
305
306 ld a,(ix+o.out_idx) ;
307 cp (ix+o.in_idx) ;if index.in == index.out
308 jr z,??ti_2 ; buffer empty
309
310 ld hl,s1.outbuf ;
311 ld c,a
312 ld b,0
313 add hl,bc
314 ld l,(hl)
315 out0 (tdr1),l ; 7
316
317 inc a
318 and (ix+o.mask)
319 ld (ix+o.out_idx),a
320 jr ??ti_3
321 ??ti_2:
322 res TIE,e ;disable tx-int
323 out0 (stat1),e ; 5
324 ??ti_3:
325 pop ix
326 ret
327
328
329
330 end