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