]> cloudbase.mooo.com Git - z180-stamp-cpm3.git/blob - cbios/ascip.180
4bb2f0961479446ee72a67034be32103804b508b
[z180-stamp-cpm3.git] / cbios / ascip.180
1 page 200
2
3 ; Simple polling drivers for ASCI0 and ASCI1
4
5 extrn ioiniml
6
7 global as0init
8 global as0ista,as0inp
9 global as0osta,as0out
10 global as1init
11 global as1ista,as1inp
12 global as1osta,as1out
13
14
15 extrn f_cpu,add_hla,div32_r
16 extrn @ctbl
17
18 include config.inc
19 include z180reg.inc
20
21
22 ;--------------------------------------------------------------
23 ; TC = (f PHI /(2*baudrate*Clock_mode)) - 2
24 ;
25 ; Clock_mode == 16
26 ; TC = (f PHI / (32 * baudrate)) - 2
27 ;
28 ; br150 = baudrate/150
29 ; TC = (f PHI / (32 * 150 * br150)) - 2
30 ; TC = (f PHI / (32 * 150 * br150)) - 2
31
32
33 ;
34 ; Init Serial I/O for console input and output (ASCI1)
35 ;
36
37 dseg
38
39 as0init:
40 ld hl,initab0
41 jr as_init
42 as1init:
43 ld hl,initab1
44 as_init:
45 push hl
46
47 ld c,8 ;
48 mlt bc ;
49 ld hl,@ctbl+7 ;get baudrate index
50 add hl,bc ;
51 ld a,(hl)
52 and 0fh
53 add a,a ;get factor
54 ld hl,bd150_tab
55 call add_hla
56 ld c,(hl)
57 inc hl
58 ld b,(hl)
59 ld hl,(f_cpu)
60 ld de,(f_cpu+2)
61 call div32_r
62 ld bc,32*150
63 call div32_r
64 ld de,2
65 or a
66 sbc hl,de
67 jr nc,as_ini_1
68 ld hl,0
69 as_ini_1:
70 ld b,h
71 ld c,l
72 pop de
73 ld hl,init_br_off
74 add hl,de
75 ld (hl),c
76 inc hl
77 ld (hl),b
78 ex de,hl
79 jp ioiniml
80
81
82 bd150_tab:
83 ; factor index baudrate orig. cp/m
84 dw 19200/150 ; 0 19200 -
85 dw 28800/150 ; 1 28800 50
86 dw 38400/150 ; 2 38400 75
87 dw 57600/150 ; 3 57600 110
88 dw 11520/15 ; 4 115200 134.5
89 dw 150/150 ; 5 150
90 dw 300/150 ; 6 300
91 dw 600/150 ; 7 600
92 dw 1200/150 ; 8 1200
93 dw 1800/150 ; 9 1800
94 dw 2400/150 ;10 2400
95 dw 3600/150 ;11 3600
96 dw 4800/150 ;12 4800
97 dw 7200/150 ;13 7200
98 dw 9600/150 ;14 9600
99 dw 19200/150 ;15 19200
100
101
102
103
104 initab0:
105 db 1,stat0,0 ;Disable rx/tx interrupts
106 ;Enable baud rate generator
107 db 1,asext0,M_BRGMOD+M_DCD0DIS+M_CTS0DIS
108 db 2,astc0l
109 init_br_off equ $ - initab0
110 dw 28
111 db 1,cntlb0,M_MPBT ;No MP Mode, X16
112 db 1,cntla0,M_RE+M_TE+M_MOD2 ;Rx/Tx enable, 8N1
113 db 0
114
115 initab1:
116 db 1,stat1,0 ;Disable rx/tx ints, disable CTS1
117 db 1,asext1,M_BRGMOD ;Enable baud rate generator
118 db 2,astc1l,low 3, high 3
119 db 1,cntlb1,M_MPBT ;No MP Mode, X16
120 db 1,cntla1,M_RE+M_TE+M_MOD2 ;Rx/Tx enable, 8N1
121 db 0
122
123
124 ;--------------------------------------------------------------
125
126 cseg
127
128 as0ista:
129 in0 a,(stat0)
130 and M_RDRF
131 ret z
132 or 0ffh
133 ret
134
135 as1ista:
136 in0 a,(stat1)
137 and M_RDRF
138 ret z
139 or 0ffh
140 ret
141
142
143 as0inp:
144 in0 a,(stat0)
145 bit RDRF,a
146 jr z,as0inp
147
148 in0 c,(rdr0)
149 and a,M_OVRN+M_PERR+M_FE
150 jr z,as0in_ex
151
152 in0 a,(cntla0)
153 res EFR,a
154 out0 (cntla0),a
155 as0in_ex:
156 ld a,c
157 ret
158
159 as1inp:
160 in0 a,(stat1)
161 bit RDRF,a
162 jr z,as1inp
163
164 in0 c,(rdr1)
165 and a,M_OVRN+M_PERR+M_FE
166 jr z,as1in_ex
167
168 in0 a,(cntla1)
169 res EFR,a
170 out0 (cntla1),a
171 as1in_ex:
172 ld a,c
173 ret
174
175 if 0
176 in0 a,(stat1)
177 rlca
178 jr nc,as1inp
179 in0 a,rdr1
180 ret
181 endif
182
183
184 as0osta:
185 in0 a,(stat0)
186 and M_TDRE
187 ret z
188 or 0ffh
189 ret
190
191 as1osta:
192 in0 a,(stat1)
193 and M_TDRE
194 ret z
195 or 0ffh
196 ret
197
198
199 as0out:
200 in0 a,(stat0)
201 and M_TDRE
202 jr z,as0out
203 out0 (tdr0),c
204 ld a,c
205 ret
206
207 as1out:
208 in0 a,(stat1)
209 and M_TDRE
210 jr z,as1out
211 out0 (tdr1),c
212 ld a,c
213 ret
214
215 end