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