]> cloudbase.mooo.com Git - z180-stamp.git/blob - z180/msgbuf-a.180
Add unique id to fifos
[z180-stamp.git] / z180 / msgbuf-a.180
1 page 255
2 .z80
3
4 global mrx.fifo,mtx.fifo
5
6 global msginit,msgi.st,msg.in,msgo.st,msg.out
7 global msg.sout
8
9 extrn buf.init
10
11 include config.inc
12 if CPU_Z180
13 include z180reg.inc
14 endif
15
16 ;--------------------------------------------------------------
17
18 dseg
19
20 mkbuf mtx.fifo_id, mtx.fifo, mtx.fifo_len
21 mkbuf mrx.fifo_id, mrx.fifo, mrx.fifo_len
22
23 ;--------------------------------------------------------------
24
25 cseg
26
27 ;
28 ; Init buffer
29 ;
30
31 msginit:
32 ld ix,mrx.fifo
33 ld a,mrx.fifo.mask
34 call buf.init
35 ld ix,mtx.fifo
36 ld a,mtx.fifo.mask
37 jp buf.init
38
39 ;--------------------------------------------------------------
40
41 msgi.st:
42 push ix
43 ld ix,mrx.fifo ;
44
45 buf.empty:
46 ld a,(ix+o.in_idx) ;
47 sub (ix+o.out_idx) ;
48 pop ix
49 ret z
50 or 0ffh
51 ret
52
53 ;--------------------------------------------------------------
54
55 msg.in:
56 push ix
57 ld ix,mrx.fifo ;
58
59 buf.get:
60 ld a,(ix+o.out_idx) ;
61 bg.wait:
62 cp (ix+o.in_idx) ;
63 jr z,bg.wait
64
65 push hl ;
66 push ix
67 pop hl
68 add a,l
69 ld l,a
70 jr nc,bg.nc
71 inc h
72 bg.nc:
73 ld l,(hl)
74
75 ld a,(ix+o.out_idx) ;
76 inc a
77 and (ix+o.mask)
78 ld (ix+o.out_idx),a
79
80 ld a,l
81 pop hl
82 pop ix
83 ret
84
85 ;--------------------------------------------------------------
86
87 msgo.st:
88 push ix
89 ld ix,mtx.fifo ;
90
91 buf.full:
92 ld a,(ix+o.in_idx) ;
93 inc a
94 and (ix+o.mask)
95 sub (ix+o.out_idx) ;
96 pop ix
97 ret z
98 or 0ffh
99 ret
100
101 ;--------------------------------------------------------------
102
103 if 0
104
105 msg.out:
106 push ix
107 ld ix,mtx.fifo ;
108
109 buf.put:
110 push hl ;
111 push bc
112 push ix
113 pop hl
114 ld c,(ix+o.in_idx) ;
115 ld b,0
116 add hl,bc
117 ld b,a
118
119 ld a,c ;
120 inc a
121 and (ix+o.mask)
122 bp.wait:
123 cp (ix+o.out_idx) ;
124 jr z,bp.wait
125 ld (hl),b
126 ld (ix+o.in_idx),a
127
128 ld a,b
129 out (AVRINT5),a
130 pop bc
131 pop hl
132 pop ix
133 ret
134
135 endif
136
137 ;--------------------------------------------------------------
138
139
140
141 msg.out:
142 push ix
143 ld ix,mtx.fifo ;
144
145 buf.put:
146 push bc
147 ld c,(ix+o.in_idx) ;
148 ld b,0
149 push ix ;14
150 add ix,bc ;10
151 ld (ix+0),a ;15
152 pop ix ;12 / 51
153 ld b,a ; 4
154 ld a,c ;
155 inc a ;
156 and (ix+o.mask) ;
157 bp.wait:
158 cp (ix+o.out_idx) ;
159 jr z,bp.wait ;
160 ld (ix+o.in_idx),a ;
161
162 ld a,b
163 out (AVRINT5),a
164 pop bc
165 pop ix
166 ret
167
168
169 ;--------------------------------------------------------------
170
171 if 0
172 ; Works only, if buffer size < (128 - 3)
173 ; --> mask must be 03fh or less
174
175 msg.out:
176 push ix
177 ld ix,mtx.fifo ;
178
179 buf.put:
180 push bc
181 ld b,a ; 4
182 ld a,(ix+o.in_idx) ;14
183 ld ($ + 3 + 2),a ;15
184 ld (ix+0),b ;15
185 inc a ;
186 and (ix+o.mask) ;
187 bp.wait:
188 cp (ix+o.out_idx) ;
189 jr z,bp.wait ;
190 ld (ix+o.in_idx),a ;
191
192 ld a,b
193 out (AVRINT5),a
194 pop bc
195 pop ix
196 ret
197
198 endif
199
200 ;--------------------------------------------------------------
201 ;
202 ; (hl): data
203
204 msg.sout:
205 push ix ;14
206 ld ix,mtx.fifo ;12
207 push bc ;11
208 push de ;11
209 ld c,(hl) ; 6
210 ld b,0 ; 6
211 inc hl ; 7
212 ms.ol: ; \
213 ld a,low mtx.fifo ; 6
214 add a,(ix+o.in_idx) ;14
215 ld e,a ; 4
216 ld a,high mtx.fifo ; 6
217 adc a,b ; 4
218 ld d,a ; 4
219
220 ld a,(ix+o.in_idx) ;14
221 inc a ; 4
222 and (ix+o.mask) ;14
223 ms.wait:
224 cp (ix+o.out_idx) ;14
225 jr z,ms.wait ; 6/8
226
227 ldi ;12
228 ld (ix+o.in_idx),a ;15
229 jp pe,ms.ol ; 6/9 -- 126
230
231 out (AVRINT5),a ;10
232 pop de ; 9
233 pop bc ; 9
234 pop ix ;12
235 ret ; 9
236
237 ;--------------------------------------------------------------
238 ;
239 ; (hl): data
240
241 if 0
242
243 msg.sout:
244 push ix ;14
245 ld ix,mtx.fifo ;12
246 push bc ;11
247 push de ;11
248 ld b,(hl) ; 6
249 inc hl ; 4
250 ex de,hl ; 3
251 ms.ol: ; \
252 push ix ;14
253 pop hl ; 9
254 ld c,(ix+o.in_idx) ;14
255 ld a,c ; 4
256 add l ; 4
257 ld l,a ; 4
258 jr nc,ms.on ; 6/8
259 inc h ; 4
260 ms.on:
261 ld a,c ; 4
262 inc a ; 4
263 and (ix+o.mask) ;14
264 ms.wait:
265 cp (ix+o.out_idx) ;14
266 jr z,ms.wait ; 6/8
267 ld c,a ; 4
268 ld a,(de) ; 6
269 inc de ; 4
270 ld (hl),a ; 7
271 ld (ix+o.in_idx),c ;15
272 djnz ms.ol ; 7/9 -- 130
273
274 out (AVRINT5),a ;10
275 ex de,hl ; 3
276 pop de ; 9
277 pop bc ; 9
278 pop ix ;12
279 ret ; 9
280
281 endif
282
283 ;--------------------------------------------------------------
284
285 msg.co:
286 push af
287 push hl
288 ld (buf_char),a
289 ld hl,buf
290 call msg.sout
291 pop hl
292 pop af
293 ret
294
295
296 buf:
297 db buf_end - $ - 1 ;output string length
298 db 0AEh ; message start token
299 db buf_end - $ - 1 ; message length
300 db 1 ; command
301 db 1 ; subcommand
302 buf_char:
303 db 0 ; pay load
304 buf_end:
305
306 ;----------------------------------------------------------------------
307
308 end