]> cloudbase.mooo.com Git - z180-stamp.git/blame - z180/conbuf-a.180
Add polling driver for ASCI0/1
[z180-stamp.git] / z180 / conbuf-a.180
CommitLineData
6a4e9540
L
1 page 255\r
2 .z80\r
3 \r
4;\r
5; FIFO channels for communication with avr\r
6;\r
30d1329e 7 global ff.init,ff.in,ff.out,ff.i.st,ff.o.st\r
6a4e9540
L
8\r
9 extrn buf.init\r
10\r
11 include config.inc\r
12 include z180reg.inc\r
13\r
14\r
15;--------------------------------------------------------------\r
16\r
17 dseg\r
18 \r
19\r
20 mkbuf co.fifo,co.fifo_len\r
21 mkbuf ci.fifo,ci.fifo_len\r
22\r
23\r
24;--------------------------------------------------------------\r
25\r
26 cseg\r
27\r
28; Init Serial I/O for console input and output\r
29;\r
30\r
31ff.init:\r
32 ld ix,ci.fifo\r
33 ld a,ci.fifo.mask\r
34 call buf.init\r
35 ld ix,co.fifo\r
36 ld a,co.fifo.mask\r
37 jp buf.init\r
38\r
39\r
40ff.i.st:\r
41 push ix\r
42 ld ix,ci.fifo ;\r
43\r
44buf.empty:\r
45 ld a,(ix+o.in_idx) ;\r
46 sub (ix+o.out_idx) ;\r
47 pop ix\r
48 ret z\r
49 or 0ffh\r
50 ret\r
51 \r
52\r
53ff.in:\r
54 push ix\r
55 ld ix,ci.fifo ;\r
56\r
57buf.get:\r
58 ld a,(ix+o.out_idx) ;\r
59bg.wait:\r
60 cp (ix+o.in_idx) ;\r
61 jr z,bg.wait\r
62\r
63 push hl ;\r
64 push ix\r
65 pop hl\r
66 add a,l\r
67 ld l,a\r
68 jr nc,bg.nc\r
69 inc h\r
70bg.nc:\r
71 ld l,(hl)\r
72 \r
73 ld a,(ix+o.out_idx) ;\r
74 inc a\r
75 and (ix+o.mask)\r
76 ld (ix+o.out_idx),a\r
77 \r
78 ld a,l\r
79 pop hl\r
80 pop ix\r
81 ret\r
82\r
83\r
84ff.o.st:\r
85 push ix\r
86 ld ix,co.fifo ;\r
87\r
88buf.full:\r
89 ld a,(ix+o.in_idx) ;\r
90 inc a\r
91 and (ix+o.mask)\r
92 sub (ix+o.out_idx) ;\r
93 pop ix\r
94 ret z\r
95 or 0ffh\r
96 ret\r
97\r
98\r
99ff.out:\r
100 push ix\r
101 ld ix,co.fifo ;\r
102\r
103buf.put:\r
104 push hl ;\r
105 push bc\r
106 push ix\r
107 pop hl\r
30d1329e 108 ld a,c\r
6a4e9540
L
109 ld c,(ix+o.in_idx) ;\r
110 ld b,0\r
111 add hl,bc\r
112 ld b,a\r
113\r
114 ld a,c ;\r
115 inc a\r
116 and (ix+o.mask)\r
117bp.wait:\r
118 cp (ix+o.out_idx) ;\r
119 jr z,bp.wait\r
120 ld (hl),b\r
121 ld (ix+o.in_idx),a\r
122 \r
123 out (AVRINT6),a\r
124 ld a,b\r
125 pop bc\r
126 pop hl\r
127 pop ix\r
128 ret\r
129\r
130 end\r
131\r