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