]>
Commit | Line | Data |
---|---|---|
1 | page 255\r | |
2 | .z80\r | |
3 | \r | |
4 | ;\r | |
5 | ; FIFO channels for communication with avr\r | |
6 | ;\r | |
7 | global ff.init,ff.in,ff.ist,ff.out,ff.ost\r | |
8 | \r | |
9 | extrn bufinit,fifolst\r | |
10 | \r | |
11 | include config.inc\r | |
12 | if CPU_Z180\r | |
13 | include z180reg.inc\r | |
14 | endif\r | |
15 | \r | |
16 | dseg\r | |
17 | mkbuf ci.fifo_id, ci.fifo, ci.fifo_len\r | |
18 | mkbuf co.fifo_id, co.fifo, co.fifo_len\r | |
19 | \r | |
20 | ici equ ci.fifo_id * 2\r | |
21 | ico equ co.fifo_id * 2\r | |
22 | \r | |
23 | \r | |
24 | ;--------------------------------------------------------------\r | |
25 | \r | |
26 | ; Init Serial I/O for console input and output\r | |
27 | ;\r | |
28 | dseg\r | |
29 | ff.init:\r | |
30 | ld a,(INIDONE)\r | |
31 | cp INIDONEVAL\r | |
32 | ret z\r | |
33 | \r | |
34 | ld ix,ci.fifo\r | |
35 | call bufinit\r | |
36 | ld ix,co.fifo\r | |
37 | jp bufinit\r | |
38 | \r | |
39 | ;--------------------------------------------------------------\r | |
40 | ; Input status\r | |
41 | ; buffer is empty, if output index and input index are the same\r | |
42 | \r | |
43 | dseg\r | |
44 | ff.ist:\r | |
45 | push ix\r | |
46 | ld ix,(fifolst+ici) ;\r | |
47 | \r | |
48 | buf.empty:\r | |
49 | ld a,(ix+o.in_idx) ;\r | |
50 | sub (ix+o.out_idx) ;\r | |
51 | pop ix\r | |
52 | ret z\r | |
53 | or 0ffh\r | |
54 | ret\r | |
55 | \r | |
56 | \r | |
57 | ;--------------------------------------------------------------\r | |
58 | ; Output status\r | |
59 | ; buffer is full, if output index is one behind input index\r | |
60 | \r | |
61 | ff.in:\r | |
62 | push ix\r | |
63 | ld ix,(fifolst+ici) ;\r | |
64 | \r | |
65 | buf.get:\r | |
66 | push ix\r | |
67 | pop hl\r | |
68 | ld c,(ix+o.out_idx) ;\r | |
69 | ld b,0\r | |
70 | add hl,bc\r | |
71 | ld a,c\r | |
72 | bg.wait:\r | |
73 | cp (ix+o.in_idx) ;\r | |
74 | jr z,bg.wait\r | |
75 | ld b,(hl)\r | |
76 | ld a,c ;\r | |
77 | inc a\r | |
78 | and (ix+o.mask)\r | |
79 | ld (ix+o.out_idx),a\r | |
80 | ld a,b\r | |
81 | pop ix\r | |
82 | ret\r | |
83 | \r | |
84 | ;--------------------------------------------------------------\r | |
85 | ; Output status\r | |
86 | ; buffer is full, if output index is one behind input index\r | |
87 | \r | |
88 | ff.ost:\r | |
89 | push ix\r | |
90 | ld ix,(fifolst+ico) ;\r | |
91 | \r | |
92 | buf.full:\r | |
93 | ld a,(ix+o.in_idx) ;\r | |
94 | inc a\r | |
95 | and (ix+o.mask)\r | |
96 | sub (ix+o.out_idx) ;\r | |
97 | pop ix\r | |
98 | ret z\r | |
99 | or 0ffh\r | |
100 | ret\r | |
101 | \r | |
102 | \r | |
103 | ;--------------------------------------------------------------\r | |
104 | ; put character in c in buffer\r | |
105 | ; destroys hl, bc\r | |
106 | ; returns output char in a\r | |
107 | \r | |
108 | ff.out:\r | |
109 | push ix ;\r | |
110 | ld ix,(fifolst+ico) ;\r | |
111 | buf.put:\r | |
112 | push ix ;\r | |
113 | pop hl ; get buffer start address\r | |
114 | \r | |
115 | ld a,c ;\r | |
116 | ld c,(ix+o.in_idx) ; add input index\r | |
117 | ld b,0 ;\r | |
118 | add hl,bc ;\r | |
119 | ld (hl),a ; one place is allways free\r | |
120 | ld b,a ;\r | |
121 | \r | |
122 | ld a,c ; bump input index\r | |
123 | inc a ;\r | |
124 | and (ix+o.mask) ;\r | |
125 | bp.wait: ; do\r | |
126 | cp (ix+o.out_idx) ;\r | |
127 | jr z,bp.wait ; while new input idx == ouput idx\r | |
128 | ld (ix+o.in_idx),a ;\r | |
129 | \r | |
130 | out (AVRINT6),a ; tell monitor\r | |
131 | ld a,b ;\r | |
132 | pop ix ;\r | |
133 | ret ;\r | |
134 | \r | |
135 | end\r |