]> cloudbase.mooo.com Git - z180-stamp-cpm3.git/blob - cbios/msgbuf.180
Initial commit
[z180-stamp-cpm3.git] / cbios / msgbuf.180
1 page 255
2 .z80
3
4
5 global msginit
6 ; global msg.ist,msg.in,msg.ost,msg.out
7 ; global msg.sout
8 global msg.sm,msg.recv
9
10 extrn bufinit
11 extrn fifolst
12
13 include config.inc
14 include z180reg.inc
15
16
17 cseg
18
19
20 mkbuf 0,mtx.fifo,mtx.fifo_len
21 mkbuf 1,mrx.fifo,mrx.fifo_len
22
23 ;txfifo_addr equ fifolst + (0*3)
24 ;rxfifo_addr equ fifolst + (1*3)
25
26 itx equ 0*3
27 irx equ 1*3
28
29 ;--------------------------------------------------------------
30 ;
31 ; Init mssage fifos
32 ;
33 dseg
34
35 msginit:
36 ld a,(INIDONE)
37 cp INIDONEVAL
38 jr nz,msgi_1
39
40 ld hl,(040h)
41 ld a,l
42 or h
43 jr z,msgi_1
44
45 ld de,fifolst
46 ld bc,4*3
47 ldir
48 ret
49
50 msgi_1:
51 ld ix,mtx.fifo
52 ld a,mtx.fifo.mask
53 call bufinit
54 ld ix,mrx.fifo
55 ld a,mrx.fifo.mask
56 jp bufinit
57
58
59 ;--------------------------------------------------------------
60
61 cseg
62
63 msgi.st:
64 push ix
65 ld ix,(fifolst+irx) ;
66
67 buf.empty:
68 ld a,(ix+o.in_idx) ;
69 sub (ix+o.out_idx) ;
70 pop ix
71 ret z
72 or 0ffh
73 ret
74
75 ;--------------------------------------------------------------
76
77 msg.in:
78 push ix
79 ld ix,(fifolst+irx) ;
80
81 buf.get:
82 ld a,(ix+o.out_idx) ;
83 bg.wait:
84 cp (ix+o.in_idx) ;
85 jr z,bg.wait
86
87 push hl ;
88 push ix
89 pop hl
90 add a,l
91 ld l,a
92 jr nc,bg.nc
93 inc h
94 bg.nc:
95 ld l,(hl)
96
97 ld a,(ix+o.out_idx) ;
98 inc a
99 and (ix+o.mask)
100 ld (ix+o.out_idx),a
101
102 ld a,l
103 pop hl
104 pop ix
105 ret
106
107
108 ;----------------------------------------------------------------------
109 ; Receive message
110 ;
111 ; hl: pointer to receive buffer
112 ; b: receive buffer size
113 ; return:
114 ; data in buffer, buffer[0] has len
115 ; bc, a: destroyed
116
117 ; TODO: time out
118 ; TODO: return number of stored chars
119 ; TODO: result code
120
121 msg.recv:
122 push de
123
124 mr_wait_start:
125 call msg.in
126 cp 0AEh
127 jr nz,mr_wait_start
128
129 call msg.in ; get message length
130 ld c,a
131 inc c
132 jr mr_do
133
134 mr_next:
135 dec c
136 jr z,mr_exit ; while chars in input buffer
137 call msg.in ; get next
138 mr_do:
139 ld e,a
140 ld a,b
141 or a ; if room in output buffer
142 jr z,mr_skip
143 ld (hl),e ; store char
144 inc hl
145 dec b
146 mr_skip:
147 jr mr_next ;
148
149 mr_exit:
150 pop de
151 ret
152
153 ;--------------------------------------------------------------
154
155 msgo.st:
156 push ix
157 ld ix,(fifolst+itx) ;
158
159 buf.full:
160 ld a,(ix+o.in_idx) ;
161 inc a
162 and (ix+o.mask)
163 sub (ix+o.out_idx) ;
164 pop ix
165 ret z
166 or 0ffh
167 ret
168
169 ;--------------------------------------------------------------
170
171 if 0
172
173 msg.out:
174 push ix
175 ld ix,(fifolst+itx) ;
176
177 push hl ;
178 push bc
179 push ix
180 pop hl
181 ld c,(ix+o.in_idx) ;
182 ld b,0
183 add hl,bc
184 ld b,a
185
186 ld a,c ;
187 inc a
188 and (ix+o.mask)
189 bp.wait:
190 cp (ix+o.out_idx) ;
191 jr z,bp.wait
192 ld (hl),b
193 ld (ix+o.in_idx),a
194
195 ld a,b
196 out (AVRINT5),a
197 pop bc
198 pop hl
199 pop ix
200 ret
201
202 endif
203
204 ;--------------------------------------------------------------
205
206 if 0
207
208 msg.out:
209 push ix
210 ld ix,(fifolst+itx) ;
211
212 push bc
213 ld c,(ix+o.in_idx) ;
214 ld b,0
215 push ix ;14
216 add ix,bc ;10
217 ld (ix+0),a ;15
218 pop ix ;12=51
219 ld b,a ; 4
220 ld a,c ;
221 inc a ;
222 and (ix+o.mask) ;
223 bp.wait:
224 cp (ix+o.out_idx) ;
225 jr z,bp.wait ;
226 ld (ix+o.in_idx),a ;
227
228 ld a,b
229 out (AVRINT5),a
230 pop bc
231 pop ix
232 ret
233
234 endif
235 ;--------------------------------------------------------------
236
237 if 0
238 ; Works only, if buffer size < (128 - 3)
239 ; --> mask must be 03fh or less
240
241 msg.out:
242 push ix
243 ld ix,(fifolst+itx) ;
244
245 push bc
246 ld b,a ; 4
247 ld a,(ix+o.in_idx) ;14
248 ld ($ + 3 + 2),a ;15
249 ld (ix+0),b ;15
250 inc a ;
251 and (ix+o.mask) ;
252 bp.wait:
253 cp (ix+o.out_idx) ;
254 jr z,bp.wait ;
255 ld (ix+o.in_idx),a ;
256
257 ld a,b
258 out (AVRINT5),a
259 pop bc
260 pop ix
261 ret
262
263 endif
264
265 ;--------------------------------------------------------------
266 ;
267 ; (hl): data
268
269 if 0
270
271 msg.sout:
272 push ix ;14
273 ld ix,(fifolst+itx) ;12
274 push bc ;11
275 push de ;11
276 ld c,(hl) ; 6
277 ld b,0 ; 6
278 inc hl ; 7
279 ms.ol: ; \
280 TODO: ld a,low mtx.fifo ; 6 does not work with DR LINK-80
281 --> (fifolst+itx+0)
282 add a,(ix+o.in_idx) ;14
283 ld e,a ; 4
284 ld a,high mtx.fifo ; 6 does not work with DR LINK-80
285 --> (fifolst+itx+1)
286 adc a,b ; 4
287 ld d,a ; 4
288
289 ld a,(ix+o.in_idx) ;14
290 inc a ; 4
291 and (ix+o.mask) ;14
292 ms.wait:
293 cp (ix+o.out_idx) ;14
294 jr z,ms.wait ; 6/8
295
296 ldi ;12
297 ld (ix+o.in_idx),a ;15
298 jp pe,ms.ol ; 6/9 -- 126
299
300 out (AVRINT5),a ;10
301 pop de ; 9
302 pop bc ; 9
303 pop ix ;12
304 ret ; 9
305
306 endif
307
308 ;--------------------------------------------------------------
309 ;
310 ; (hl): data
311
312 if 1
313
314 msg.sout:
315 push ix ;14
316 ld ix,(fifolst+itx) ;12
317 push bc ;11
318 push de ;11
319 ld b,(hl) ; 6
320 inc hl ; 4
321 ex de,hl ; 3
322 ms.ol: ; \
323 push ix ;14
324 pop hl ; 9
325 ld c,(ix+o.in_idx) ;14
326 ld a,c ; 4
327 add l ; 4
328 ld l,a ; 4
329 jr nc,ms.on ; 6/8
330 inc h ; 4
331 ms.on:
332 ld a,c ; 4
333 inc a ; 4
334 and (ix+o.mask) ;14
335 ms.wait:
336 cp (ix+o.out_idx) ;14
337 jr z,ms.wait ; 6/8
338 ld c,a ; 4
339 ld a,(de) ; 6
340 inc de ; 4
341 ld (hl),a ; 7
342 ld (ix+o.in_idx),c ;15
343 djnz ms.ol ; 7/9 -- 130
344
345 out (AVRINT5),a ;10
346 ex de,hl ; 3
347 pop de ; 9
348 pop bc ; 9
349 pop ix ;12
350 ret ; 9
351
352 endif
353
354 ;----------------------------------------------------------------------
355
356
357
358 ; Send message
359 ; b: msg length
360 ; hl: pointer to message (netto)
361
362 msg.snd:
363 push ix
364 ld ix,(fifolst+itx)
365 ld c,0AEh
366 call buf.put
367 msnd_l:
368 ld c,(hl)
369 inc hl
370 call buf.put
371 djnz msnd_l
372 pop ix
373 ret
374
375
376 ;----------------------------------------------------------------------
377 ;
378 ; Put char in message buffer:
379 ; ix: buffer to put into
380 ; c: char
381
382 buf.put:
383 push ix ;15
384 push bc ;11
385 ld a,(ix+o.in_idx) ;19
386 ld c,a ;4
387 ld b,0 ;7
388 add ix,bc ;11
389 pop bc ;10
390 ld (ix),c ;7
391 pop ix ;14
392
393 inc a ;4
394 and (ix+o.mask) ;19 =121
395 bufp.wait:
396 cp (ix+o.out_idx) ;19
397 jr z,bufp.wait ;12/7
398 ld (ix+o.in_idx),a ;19
399
400 out (AVRINT5),a ;11
401 ld a,c ;4
402 ret ;10 =191
403
404
405 ;----------------------------------------------------------------------
406 ; Send message MEMORY
407 ;
408 ; hl: pointer to message (netto)
409 ; b: msg length
410
411 msg.sm:
412 push ix
413 ld ix,(fifolst+itx)
414 ld c,0AEh
415 call buf.put
416 ld c,b
417 call buf.put
418 msm_l:
419 ld c,(hl)
420 inc hl
421 call buf.put
422 djnz msm_l
423 pop ix
424 ret
425
426
427 ;----------------------------------------------------------------------
428 ; Send message INLINE
429 ;
430 ; h: function
431 ; l: subfunction
432 ; b: msg length
433
434 if 0
435
436 msg.sil:
437 ex (sp),hl
438 push ix
439 ld ix,(fifolst+itx)
440 ld c,0AEh
441 call buf.put
442 ld b,(hl)
443 msnd_pl:
444 ld c,(hl)
445 inc hl
446 call puf.put
447 djnz msnd_pl
448 ex (sp),hl
449 pop ix
450 ret
451
452 endif
453
454 ;--------------------------------------------------------------
455
456 if 0
457
458 msg.co:
459 push af
460 push hl
461 ld (buf_char),a
462 ld hl,buf
463 call msg.sout
464 pop hl
465 pop af
466 ret
467
468 buf:
469 db buf_end - $ - 1 ;output string length
470 db 0AEh ; message start token
471 db buf_end - $ - 1 ; message length
472 db 1 ; command
473 db 1 ; subcommand
474 buf_char:
475 db 0 ; pay load
476 buf_end:
477
478 endif
479
480 ;--------------------------------------------------------------
481
482
483
484 end