]> cloudbase.mooo.com Git - z180-stamp.git/blob - z180/bioscio.180
CP/M 3 compatible character i/o handling
[z180-stamp.git] / z180 / bioscio.180
1
2 .z80
3
4 ; Copyright (C), 1982
5 ; Digital Research, Inc
6 ; P.O. Box 579
7 ; Pacific Grove, CA 93950
8
9 ; This is the invariant portion of the modular BIOS and is
10 ; distributed as source for informational purposes only.
11 ; All desired modifications should be performed by
12 ; adding or changing externally defined modules.
13 ; This allows producing "standard" I/O modules that
14 ; can be combined to support a particular system
15 ; configuration.
16 ;
17 ; Modified for faster character I/O by Udo Munk
18
19 cr equ 13
20 lf equ 10
21 bell equ 7
22 ctlQ equ 'Q'-'@'
23 ctlS equ 'S'-'@'
24
25 cseg ; GENCPM puts CSEG stuff in common memory
26
27 ; variables in system data page
28
29 ;; extrn @covec,@civec,@aovec,@aivec,@lovec ; I/O redirection vectors
30
31 ; user defined character I/O routines
32
33 extrn ?ci,?co,?cist,?cost ; each take device in <B>
34 extrn ?cinit ; (re)initialize device in <C>
35 extrn @ctbl ; physical character device table
36
37
38 include modebaud.inc ; define mode bits
39
40
41 public @covec,@civec,@aovec,@aivec,@lovec ; I/O redirection vectors
42 public ?const,?conin,?cono,?list,?auxo,?auxi
43 public ?lists,?conos,?auxis,?auxos,?dvtbl,charini
44
45
46 @CIVEC: dw 0 ; Console Input Redirection
47 ; Vector (word, r/w)
48 @COVEC: dw 0 ; Console Output Redirection
49 ; Vector (word, r/w)
50 @AIVEC: dw 0 ; Auxiliary Input Redirection
51 ; Vector (word, r/w)
52 @AOVEC: dw 0 ; Auxiliary Output Redirection
53 ; Vector (word, r/w)
54 @LOVEC: dw 0 ; List Output Redirection
55 ; Vector (word, r/w)
56
57
58 charini:
59
60 ld c,15 ; initialize all 16 character devices
61 c$init$loop:
62 push bc
63 call ?cinit
64 pop bc
65 dec c
66 jp p,c$init$loop
67
68 ld hl,1100000000000000b ; assign console to HOST and ASCI1
69 ld (@civec),hl
70 ld (@covec),hl
71 ld hl,0000000000000000b ; assign auxiliary to nothing
72 ld (@aivec),hl
73 ld (@aovec),hl
74 ld hl,0000000000000000b ; assign printer to nothing
75 ld (@lovec),hl
76 ret
77
78
79 ; DEVTBL
80 ; Return address of character device table
81
82 ?dvtbl:
83 devtbl:
84 ld hl,@ctbl
85 ret
86
87
88 ; CONOUT
89 ; Console Output. Send character in <C>
90 ; to all selected devices
91
92 ?cono:
93 conout:
94 ld hl,(@covec) ; fetch console output bit vector
95 jr out$scan
96
97
98 ; AUXOUT
99 ; Auxiliary Output. Send character in <C>
100 ; to all selected devices
101
102 ?auxo:
103 auxout:
104 ld hl,(@aovec) ; fetch aux output bit vector
105 jr out$scan
106
107
108 ; LIST
109 ; List Output. Send character in <C>
110 ; to all selected devices.
111
112 ?list:
113 list:
114 ld hl,(@lovec) ; fetch list output bit vector
115
116 out$scan:
117 ld b,0 ; start with device 0
118 co$next:
119 add hl,hl ; shift out next bit
120 jr nc,not$out$device
121 push hl ; save the vector
122 push bc ; save the count and character
123 call ?co ; if device selected, print it
124 pop bc ; recover count and character
125 pop hl ; recover the rest of the vector
126 not$out$device:
127 inc b ; next device number
128 ld a,h
129 or l ; see if any devices left
130 jr nz,co$next ; and go find them...
131 ret
132
133
134 ; CONOST
135 ; Console Output Status. Return true if
136 ; all selected console output devices
137 ; are ready.
138
139 ?conos:
140 conost:
141 ld hl,(@covec) ; get console output bit vector
142 jr ost$scan
143
144
145 ; AUXOST
146 ; Auxiliary Output Status. Return true if
147 ; all selected auxiliary output devices
148 ; are ready.
149
150 ?auxos:
151 auxost:
152 ld hl,(@aovec) ; get aux output bit vector
153 jr ost$scan
154
155
156 ; LISTST
157 ; List Output Status. Return true if
158 ; all selected list output devices
159 ; are ready.
160
161 ?lists:
162 listst:
163 ld hl,(@lovec) ; get list output bit vector
164
165 ost$scan:
166 ld b,0 ; start with device 0
167 cos$next:
168 add hl,hl ; check next bit
169 push hl ; save the vector
170 push bc ; save the count
171 ld a,0FFh ; assume device ready
172 call c,coster ; check status for this device
173 pop bc ; recover count
174 pop hl ; recover bit vector
175 or a ; see if device ready
176 ret z ; if any not ready, return false
177 inc b ; drop device number
178 ld a,h
179 or l ; see if any more selected devices
180 jr nz,cos$next
181 or 0FFh ; all selected were ready, return true
182 ret
183
184 coster: ; check for output device ready, including optional
185 ; xon/xoff support
186 ;
187 ;TODO: interrupt driven devices should xon/xoff handle
188 ; in isv
189
190 ld l,b
191 ld h,0 ; make device code 16 bits
192 push hl ; save it in stack
193 add hl,hl
194 add hl,hl
195 add hl,hl ; create offset into device characteristics tbl
196 ld de,@ctbl+6
197 add hl,de ; make address of mode byte
198 ld a,(hl)
199 and mb$xon$xoff
200 pop hl ; recover console number in <HL>
201 jp z,?cost ; not a xon device, go get output status direct
202 ld de,xofflist
203 add hl,de ; make pointer to proper xon/xoff flag
204 call cist1 ; see if this keyboard has character
205 ld a,(hl)
206 call nz,ci1 ; get flag or read key if any
207 cp ctlq
208 jr nz,not$q ; if its a ctl-Q,
209 ld a,0FFh ; set the flag ready
210 not$q:
211 cp ctls
212 jr nz,not$s ; if its a ctl-S,
213 ld a,00h ; clear the flag
214 not$s:
215 ld (hl),a ; save the flag
216 call cost1 ; get the actual output status,
217 and (hl) ; and mask with ctl-Q/ctl-S flag
218 ret ; return this as the status
219
220 cist1: ; get input status with <BC> and <HL> saved
221 push bc
222 push hl
223 call ?cist
224 pop hl
225 pop bc
226 or a
227 ret
228
229 cost1: ; get output status, saving <BC> & <HL>
230 push bc
231 push hl
232 call ?cost
233 pop hl
234 pop bc
235 or a
236 ret
237
238 ci1: ; get input, saving <BC> & <HL>
239 push bc
240 push hl
241 call ?ci
242 pop hl
243 pop bc
244 ret
245
246
247 ; AUXIST
248 ; Auxiliary Input Status. Return true if
249 ; any selected auxiliary input device
250 ; has an available character.
251 ?auxis:
252 auxist:
253 ld hl,(@aivec) ; get aux input bit vector
254 jr ist$scan
255
256
257 ; CONST
258 ; Console Input Status. Return true if
259 ; any selected console input device
260 ; has an available character.
261 ?const:
262 const:
263 ld hl,(@civec) ; get console input bit vector
264
265
266 ist$scan:
267 ld b,0 ; start with device 0
268 cis$next:
269 add hl,hl ; check next bit
270 ld a,0 ; assume device not ready
271 call c,cist1 ; check status for this device
272 or a
273 ret nz ; if any ready, return true
274 inc b ; next device number
275 ld a,h
276 or l ; see if any more selected devices
277 jr nz,cis$next
278 xor a ; all selected were not ready, return false
279 ret
280
281
282 ; AUXIN
283 ; Auxiliary Input. Return character from first
284 ; ready auxiliary input device.
285 ?auxi:
286 auxin:
287 ld hl,(@aivec)
288 jr in$scan
289
290
291 ; CONIN
292 ; Console Input. Return character from first
293 ; ready console input device.
294 ?conin:
295 conin:
296 ld hl,(@civec)
297
298 in$scan:
299 push hl ; save bit vector
300 ld b,0
301 ci$next:
302 add hl,hl ; shift out next bit
303 ld a,0 ; insure zero a (nonexistant device not ready).
304 call c,cist1 ; see if the device has a character
305 or a
306 jr nz,ci$rdy ; this device has a character
307 inc b ; else, next device
308 ld a,h
309 or l ; see if any more devices
310 jr nz,ci$next ; go look at them
311 pop hl ; recover bit vector
312 jr in$scan ; loop til we find a character
313 ci$rdy:
314 pop hl ; discard extra stack
315 jp ?ci
316
317
318
319 xofflist:
320 db -1,-1,-1,-1,-1,-1,-1,-1 ; ctl-s clears to zero
321 db -1,-1,-1,-1,-1,-1,-1,-1
322
323
324 end
325