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