]> cloudbase.mooo.com Git - z180-stamp.git/blob - z180/msgbuf-a.180
36e08715db1304e3443110a131d61ffd1aa93d03
[z180-stamp.git] / z180 / msgbuf-a.180
1 page 255
2 .z80
3
4 global mrx.fifo,mtx.fifo
5
6 global msginit,msgi.st,msg.in,msgo.st,msg.out
7 global msg.sout
8
9 extrn buf.init
10
11 include config.inc
12 include z180reg.inc
13
14 ;--------------------------------------------------------------
15
16 dseg
17
18 mkbuf mrx.fifo,mrx.fifo_len
19 mkbuf mtx.fifo,mtx.fifo_len
20
21 ;--------------------------------------------------------------
22
23 cseg
24
25 ;
26 ; Init buffer
27 ;
28
29 msginit:
30 ld ix,mrx.fifo
31 ld a,mrx.fifo.mask
32 call buf.init
33 ld ix,mtx.fifo
34 ld a,mtx.fifo.mask
35 jp buf.init
36
37 ;--------------------------------------------------------------
38
39 msgi.st:
40 push ix
41 ld ix,mrx.fifo ;
42
43 buf.empty:
44 ld a,(ix+o.in_idx) ;
45 sub (ix+o.out_idx) ;
46 pop ix
47 ret z
48 or 0ffh
49 ret
50
51 ;--------------------------------------------------------------
52
53 msg.in:
54 push ix
55 ld ix,mrx.fifo ;
56
57 buf.get:
58 ld a,(ix+o.out_idx) ;
59 bg.wait:
60 cp (ix+o.in_idx) ;
61 jr z,bg.wait
62
63 push hl ;
64 push ix
65 pop hl
66 add a,l
67 ld l,a
68 jr nc,bg.nc
69 inc h
70 bg.nc:
71 ld l,(hl)
72
73 ld a,(ix+o.out_idx) ;
74 inc a
75 and (ix+o.mask)
76 ld (ix+o.out_idx),a
77
78 ld a,l
79 pop hl
80 pop ix
81 ret
82
83 ;--------------------------------------------------------------
84
85 msgo.st:
86 push ix
87 ld ix,mtx.fifo ;
88
89 buf.full:
90 ld a,(ix+o.in_idx) ;
91 inc a
92 and (ix+o.mask)
93 sub (ix+o.out_idx) ;
94 pop ix
95 ret z
96 or 0ffh
97 ret
98
99 ;--------------------------------------------------------------
100
101 msg.out:
102 push ix
103 ld ix,mtx.fifo ;
104
105 buf.put:
106 push hl ;
107 push bc
108 push ix
109 pop hl
110 ld c,(ix+o.in_idx) ;
111 ld b,0
112 add hl,bc
113 ld b,a
114
115 ld a,c ;
116 inc a
117 and (ix+o.mask)
118 bp.wait:
119 cp (ix+o.out_idx) ;
120 jr z,bp.wait
121 ld (hl),b
122 ld (ix+o.in_idx),a
123
124 ld a,b
125 out0 (AVRINT5),a
126 pop bc
127 pop hl
128 pop ix
129 ret
130
131
132 ;--------------------------------------------------------------
133 ;
134 ; (hl): data
135
136 msg.sout:
137 push ix
138 ld ix,mtx.fifo ;
139
140 push bc
141 push de
142 ld b,(hl) ;
143 inc hl
144 ex de,hl
145
146 ms.ol:
147 push ix
148 pop hl
149 ld c,(ix+o.in_idx) ;
150 ld a,c
151 add l
152 ld l,a
153 jr nc,ms.on
154 inc h
155 ms.on:
156 ld a,c ;
157 inc a
158 and (ix+o.mask)
159 ms.wait:
160 cp (ix+o.out_idx) ;
161 jr z,ms.wait
162 ld c,a
163 ld a,(de)
164 inc de
165 ld (hl),a
166 ld (ix+o.in_idx),c
167 djnz ms.ol
168 out0 (AVRINT5),a
169 ex de,hl
170 pop de
171 pop bc
172 pop ix
173 ret
174
175 ;--------------------------------------------------------------
176
177 msg.co:
178 push af
179 push hl
180 ld (buf_char),a
181 ld hl,buf
182 call msg.sout
183 pop hl
184 pop af
185 ret
186
187
188 buf:
189 db buf_end - $ - 1 ;output string length
190 db 0AEh ; message start token
191 db buf_end - $ - 1 ; message length
192 db 1 ; command
193 db 1 ; subcommand
194 buf_char:
195 db 0 ; pay load
196 buf_end:
197
198 ;----------------------------------------------------------------------
199
200 end
201