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