]> cloudbase.mooo.com Git - z180-stamp-cpm3.git/blob - cbios/fifo.180
Update IXON flag from character device table (@ctbl)
[z180-stamp-cpm3.git] / cbios / fifo.180
1
2 public bufinit
3 public ff_empty,ff_get,ff_full,ff_put
4 public ff_puth,ff_cnt,ff_gech
5
6 public fifolst
7
8 extrn msg.sm,hwl2phy
9
10 maclib z180reg.inc
11 maclib config.inc
12
13
14 ;--------------------------------------------------------------------
15
16 dseg
17
18 fifolst:
19 rept 4
20 dw 0
21 endm
22
23 ;--------------------------------------------------------------------
24
25 dseg
26
27 bufinit:
28 ld (ix+o.in_idx),0 ;reset pointers (empty fifo)
29 ld (ix+o.out_idx),0
30 ld a,(ix+o.id)
31 ld hl,fifolst
32 ld e,a
33 ld d,0
34 add hl,de
35 add hl,de
36 push ix
37 pop de
38 cp 4
39 jr nc,bfi_skip
40
41 ld (hl),e
42 inc hl
43 ld (hl),d
44
45 bfi_skip:
46 ex de,hl
47 call hwl2phy ;get phys. address of fifo
48 ld c,a
49 ld a,(ix+o.id) ;fifo id
50 or a ;test if fifo 0
51 ret z
52
53 cp 4
54 ret nc
55
56 ; TODO: move to better place
57
58 ld b,a
59 push bc ;c: bank-addr, b: ignored
60 push hl ;address
61 ld c,0
62 push bc ;c: function, b:subf
63 ld b,5
64 ld h,c
65 ld l,c
66 add hl,sp
67 call msg.sm
68 pop hl
69 pop hl
70 pop hl
71 ret
72
73 ;--------------------------------------------------------------
74 ; Check if characters in fifo
75 ; Fifo is empty, if output index and input index are the same
76
77 ff_empty:
78 ld a,(ix+o.in_idx) ;
79 sub (ix+o.out_idx) ;
80 ret z
81 or 0ffh
82 ret
83
84 ;--------------------------------------------------------------
85 ; get character from fifo
86 ; destroys hl,b
87 ;
88 ; return:
89 ; c,a: next character
90
91 ff_get:
92 push ix
93 pop hl
94 ld c,(ix+o.out_idx) ;
95 ld b,0
96 add hl,bc
97 ld a,c
98 bg.wait:
99 cp (ix+o.in_idx) ;
100 jr z,bg.wait
101 inc a
102 and (ix+o.mask)
103 ld c,(hl)
104 ld (ix+o.out_idx),a
105 ld a,c
106 ret
107
108 ;--------------------------------------------------------------
109 ; get character and ramaining count from fifo
110 ; halt cpu, while buffer is empty
111 ; destroys hl
112 ;
113 ; return:
114 ; c,a: next character
115 ; b: number of charachters in fifo
116
117 ff_gech:
118 push ix
119 pop hl
120 ld c,(ix+o.out_idx) ;
121 ld b,0
122 add hl,bc
123 gech.wait:
124 ld a,(ix+o.in_idx) ;
125 sub c
126 jr nz,gech.cont
127 halt
128 jr gech.wait
129 gech.cont:
130 and (ix+o.mask) ;
131 dec a
132 ld b,a
133 ld a,c
134 inc a
135 and (ix+o.mask)
136 ld c,(hl)
137 ld (ix+o.out_idx),a
138 ld a,c
139 ret
140
141 ;--------------------------------------------------------------
142 ; Check if room in fifo
143 ; buffer is full, if output index is one behind input index
144 ;
145 ; return
146 ; a = 0 and z if buffer full
147 ; a = ff and nz if buffer not full
148
149 ff_full:
150 ld a,(ix+o.in_idx) ;
151 inc a ;
152 and (ix+o.mask) ;
153 sub (ix+o.out_idx) ;
154 ret z
155 or 0ffh
156 ret
157
158
159 ;--------------------------------------------------------------
160 ; put character in c in buffer
161 ; destroys bc
162
163 ff_put:
164 push ix ;
165 ex (sp),hl ; get buffer start address
166
167 ld a,c ;
168 ld c,(ix+o.in_idx) ; add input index
169 ld b,0 ;
170 add hl,bc ;
171 ld (hl),a ; one place is allways free
172 pop hl ; restore hl
173
174 ld a,c ; bump input index
175 inc a ;
176 and (ix+o.mask) ;
177 bp.wait: ; do
178 cp (ix+o.out_idx) ;
179 jr z,bp.wait ; while new input idx == ouput idx
180 ld (ix+o.in_idx),a ;
181 ret ;
182
183 ;--------------------------------------------------------------
184 ; put character in c in buffer
185 ; halt cpu, while buffer is is full
186 ; destroys bc
187
188 ff_puth:
189 push ix ;
190 ex (sp),hl ; get buffer start address
191
192 ld a,c ;
193 ld c,(ix+o.in_idx) ; add input index
194 ld b,0 ;
195 add hl,bc ;
196 ld (hl),a ; one place is allways free
197 pop hl ; restore hl
198
199 ld a,c ; bump input index
200 inc a ;
201 and (ix+o.mask) ;
202 jr $+3
203 bph.wait: ; do
204 halt ; halt cpu
205 cp (ix+o.out_idx) ;
206 jr z,bph.wait ; while new input idx == ouput idx
207 ld (ix+o.in_idx),a ;
208 ret ;
209
210 ;--------------------------------------------------------------
211 ; Return number of characters in fifo
212 ;
213
214 ff_cnt:
215 ld a,(ix+o.in_idx) ;
216 sub (ix+o.out_idx) ;
217 and (ix+o.mask) ;
218 ret
219
220 ;--------------------------------------------------------------
221
222 end