]> cloudbase.mooo.com Git - z180-stamp-cpm3.git/blob - cbios/fifo.180
ascii.180 interrupt driver for ASCI 0/1
[z180-stamp-cpm3.git] / cbios / fifo.180
1
2 public bufinit
3 public ff_empty,ff_get,ff_full,ff_put
4
5 public fifolst
6
7 extrn msg.sm,hwl2phy
8
9 include config.inc
10 include z180reg.inc
11
12
13 ;--------------------------------------------------------------------
14
15 dseg
16
17 fifolst:
18 rept 4
19 dw 0
20 endm
21
22 ;--------------------------------------------------------------------
23
24 dseg
25
26 bufinit:
27 ld (ix+o.in_idx),0 ;reset pointers (empty fifo)
28 ld (ix+o.out_idx),0
29 ld a,(ix+o.id)
30 ld hl,fifolst
31 ld e,a
32 ld d,0
33 add hl,de
34 add hl,de
35 push ix
36 pop de
37 cp 4
38 jr nc,bfi_skip
39
40 ld (hl),e
41 inc hl
42 ld (hl),d
43
44 bfi_skip:
45 ex de,hl
46 call hwl2phy ;get phys. address of fifo
47 ld c,a
48 ld a,(ix+o.id) ;fifo id
49 or a ;test if fifo 0
50 ret z
51
52 cp 4
53 ret nc
54
55 ; TODO: move to better place
56
57 ld b,a
58 push bc ;c: bank-addr, b: ignored
59 push hl ;address
60 ld c,0
61 push bc ;c: function, b:subf
62 ld b,5
63 ld h,c
64 ld l,c
65 add hl,sp
66 call msg.sm
67 pop hl
68 pop hl
69 pop hl
70 ret
71
72 ;--------------------------------------------------------------
73 ; Check if characters in fifo
74 ; Fifo is empty, if output index and input index are the same
75
76 ff_empty:
77 ld a,(ix+o.in_idx) ;
78 sub (ix+o.out_idx) ;
79 ret z
80 or 0ffh
81 ret
82
83 ;--------------------------------------------------------------
84
85 ff_get:
86 push ix
87 pop hl
88 ld c,(ix+o.out_idx) ;
89 ld b,0
90 add hl,bc
91 ld a,c
92 bg.wait:
93 cp (ix+o.in_idx) ;
94 jr z,bg.wait
95 ld b,(hl)
96 ld a,c ;
97 inc a
98 and (ix+o.mask)
99 ld (ix+o.out_idx),a
100 ld a,b
101 ret
102
103 ;--------------------------------------------------------------
104 ; Check if room in fifo
105 ; buffer is full, if output index is one behind input index
106
107 ff_full:
108 ld a,(ix+o.in_idx) ;
109 inc a
110 and (ix+o.mask)
111 sub (ix+o.out_idx) ;
112 ret z
113 or 0ffh
114 ret
115
116
117 ;--------------------------------------------------------------
118 ; put character in c in buffer
119 ; destroys hl, bc
120 ; returns output char in a
121
122 ff_put:
123 push ix ;
124 pop hl ; get buffer start address
125
126 ld a,c ;
127 ld c,(ix+o.in_idx) ; add input index
128 ld b,0 ;
129 add hl,bc ;
130 ld (hl),a ; one place is allways free
131 ld b,a ;
132
133 ld a,c ; bump input index
134 inc a ;
135 and (ix+o.mask) ;
136 bp.wait: ; do
137 cp (ix+o.out_idx) ;
138 jr z,bp.wait ; while new input idx == ouput idx
139 ld (ix+o.in_idx),a ;
140 ld a,b ;
141 ret ;
142
143 end