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