]> cloudbase.mooo.com Git - z180-stamp.git/blob - z180/conbuf-a.180
Version 0.6.8.2
[z180-stamp.git] / z180 / conbuf-a.180
1 page 255
2 .z80
3
4 ;
5 ; FIFO channels for communication with avr
6 ;
7 global ff.init,ff.in,ff.out,ff.i.st,ff.o.st
8
9 extrn bufinit
10
11 include config.inc
12 if CPU_Z180
13 include z180reg.inc
14 endif
15
16
17 ;--------------------------------------------------------------
18
19 dseg
20
21
22 mkbuf ci.fifo_id, ci.fifo, ci.fifo_len
23 mkbuf co.fifo_id, co.fifo, co.fifo_len
24
25
26 ;--------------------------------------------------------------
27
28 cseg
29
30 ; Init Serial I/O for console input and output
31 ;
32
33 ff.init:
34 ld ix,ci.fifo
35 call bufinit
36 ld ix,co.fifo
37 jp bufinit
38
39
40 ff.i.st:
41 push ix
42 ld ix,ci.fifo ;
43
44 buf.empty:
45 ld a,(ix+o.in_idx) ;
46 sub (ix+o.out_idx) ;
47 pop ix
48 ret z
49 or 0ffh
50 ret
51
52
53 ff.in:
54 push ix
55 ld ix,ci.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 ff.o.st:
85 push ix
86 ld ix,co.fifo ;
87
88 buf.full:
89 ld a,(ix+o.in_idx) ;
90 inc a
91 and (ix+o.mask)
92 sub (ix+o.out_idx) ;
93 pop ix
94 ret z
95 or 0ffh
96 ret
97
98
99 if 1
100 ff.out:
101 push ix ;15
102 ld ix,co.fifo ;14
103
104 buf.put:
105 push hl ;11
106 push bc ;11
107 push ix ;15
108 pop hl ;10
109 ld a,c ;4
110 ld c,(ix+o.in_idx) ;19
111 ld b,0 ;7
112 add hl,bc ;11
113 ld (hl),a ;7
114 ld b,a ;4
115
116 ld a,c ;4
117 inc a ;4
118 and (ix+o.mask) ;19
119 bp.wait:
120 cp (ix+o.out_idx) ;19
121 jr z,bp.wait ;12/7
122 ld (ix+o.in_idx),a ;19
123
124 out (AVRINT6),a ;11
125 ld a,b ;4
126 pop bc ;10
127 pop hl ;10
128 pop ix ;14
129 ret ;10
130
131 else
132
133 ff.out:
134 push ix ;15
135 ld ix,co.fifo ;14
136
137 buf.put:
138 push hl ;11
139 push ix ;15
140 pop hl ;10
141 ld a,(ix+o.in_idx) ;19
142 add a,l ;4
143 ld l,a ;4
144 jr nc,bp.1 ;12/7
145 inc l ;4
146 ld (hl),c ;7
147 ld a,(ix+o.in_idx) ;19
148 inc a ;4
149 and (ix+o.mask) ;19
150 bp.wait:
151 cp (ix+o.out_idx) ;19
152 jr z,bp.wait ;12/7
153 ld (ix+o.in_idx),a ;19
154
155 out (AVRINT6),a ;11
156 ld a,c ;4
157 pop hl ;10
158 pop ix ;14
159 ret ;10 |
160
161 endif
162
163 end