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