summaryrefslogtreecommitdiff
path: root/z180/bioscio.180
blob: 5ec55c69b07e44d1eefe8392e2df6e5fe998f6e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
	.z80

;		  Copyright (C), 1982
;		 Digital Research, Inc
;		     P.O. Box 579
;		Pacific Grove, CA  93950

;   This is the invariant portion of the modular BIOS and is
;	distributed as source for informational purposes only.
;	All desired modifications should be performed by
;	adding or changing externally defined modules.
;	This allows producing "standard" I/O modules that
;	can be combined to support a particular system
;	configuration.
;
;   Modified for faster character I/O by Udo Munk

cr	equ	13
lf	equ	10
bell	equ	7
ctlQ	equ	'Q'-'@'
ctlS	equ	'S'-'@'

	cseg			; GENCPM puts CSEG stuff in common memory

	; variables in system data page

;;	extrn	@covec,@civec,@aovec,@aivec,@lovec ; I/O redirection vectors
				
	; user defined character I/O routines

	extrn	?ci,?co,?cist,?cost	; each take device in <B>
	extrn	?cinit			; (re)initialize device in <C>
	extrn	@ctbl			; physical character device table


	include	modebaud.inc	; define mode bits


	public	@covec,@civec,@aovec,@aivec,@lovec ; I/O redirection vectors
	public	?const,?conin,?cono,?list,?auxo,?auxi
	public	?lists,?conos,?auxis,?auxos,?dvtbl,charini


@CIVEC:	dw	0		; Console Input Redirection
				; Vector (word, r/w)
@COVEC:	dw	0		; Console Output Redirection
				; Vector (word, r/w)
@AIVEC:	dw	0		; Auxiliary Input Redirection
				; Vector (word, r/w)
@AOVEC:	dw	0		; Auxiliary Output Redirection
				; Vector (word, r/w)
@LOVEC:	dw	0		; List Output Redirection
				; Vector (word, r/w)


charini:

	ld	c,15		; initialize all 16 character devices
c$init$loop:
	push	bc
	call	?cinit
	pop	bc
	dec	c
	jp	p,c$init$loop

	ld	hl,1000000000000000b	; assign console to HOST
	ld	(@civec),hl
	ld	(@covec),hl
	ld	hl,0000000000000000b	; assign auxiliary to nothing
	ld	(@aivec),hl
	ld	(@aovec),hl
	ld	hl,0000000000000000b	; assign printer to nothing
	ld	(@lovec),hl
	ret


	; DEVTBL
	;	Return address of character device table

?dvtbl:
devtbl:
	ld	hl,@ctbl
	ret


	; CONOUT
	;	Console Output. Send character in <C>
	;			to all selected devices

?cono:
conout:
	ld	hl,(@covec)	; fetch console output bit vector
	jr	out$scan


	; AUXOUT
	;	Auxiliary Output. Send character in <C>
	;			to all selected devices

?auxo:
auxout:
	ld	hl,(@aovec)	; fetch aux output bit vector
	jr	out$scan


	; LIST
	;	List Output. Send character in <C>
	;			to all selected devices.

?list:
list:
	ld	hl,(@lovec)	; fetch list output bit vector

out$scan:
	ld	b,0		; start with device 0
co$next:
	add	hl,hl		; shift out next bit
	jr	nc,not$out$device
	push	hl		; save the vector
	push	bc		; save the count and character
	call	?co		; if device selected, print it
	pop	bc		; recover count and character
	pop	hl		; recover the rest of the vector
not$out$device:
	inc	b		; next device number
	ld	a,h
	or	l		; see if any devices left
	jr	nz,co$next	; and go find them...
	ret


	; CONOST
	;	Console Output Status. Return true if
	;		all selected console output devices
	;		are ready.

?conos:
conost:
	ld	hl,(@covec)	; get console output bit vector
	jr	ost$scan


	; AUXOST
	;	Auxiliary Output Status. Return true if
	;		all selected auxiliary output devices
	;		are ready.

?auxos:
auxost:
	ld	hl,(@aovec)	; get aux output bit vector
	jr	ost$scan


	; LISTST
	;	List Output Status. Return true if
	;		all selected list output devices
	;		are ready.

?lists:
listst:
	ld	hl,(@lovec)	; get list output bit vector

ost$scan:
	ld	b,0		; start with device 0
cos$next:
	add	hl,hl		; check next bit
	push	hl		; save the vector
	push	bc		; save the count
	ld	a,0FFh		; assume device ready
	call	c,coster	; check status for this device
	pop	bc		; recover count
	pop	hl		; recover bit vector
	or	a		; see if device ready
	ret	z		; if any not ready, return false
	inc	b		; drop device number
	ld	a,h
	or	l		; see if any more selected devices
	jr	nz,cos$next
	or	0FFh		; all selected were ready, return true
	ret

coster:		; check for output device ready, including optional
		;	xon/xoff support
		;
		;TODO: interrupt driven devices should xon/xoff handle
		;	in isv

	ld	l,b
	ld	h,0		; make device code 16 bits
	push	hl		; save it in stack
	add	hl,hl
	add	hl,hl
	add	hl,hl		; create offset into device characteristics tbl
	ld	de,@ctbl+6
	add	hl,de		; make address of mode byte
	ld	a,(hl)
	and	mb$xon$xoff
	pop	hl		; recover console number in <HL>
	jp	z,?cost		; not a xon device, go get output status direct
	ld	de,xofflist
	add	hl,de		; make pointer to proper xon/xoff flag
	call	cist1		; see if this keyboard has character
	ld	a,(hl)
	call	nz,ci1		; get flag or read key if any
	cp	ctlq
	jr	nz,not$q	; if its a ctl-Q,
	ld	a,0FFh		;	set the flag ready
not$q:
	cp	ctls
	jr	nz,not$s	; if its a ctl-S,
	ld	a,00h		;	clear the flag
not$s:
	ld	(hl),a		; save the flag
	call	cost1		; get the actual output status,
	and	(hl)		; and mask with ctl-Q/ctl-S flag
	ret			; return this as the status

cist1:		; get input status with <BC> and <HL> saved
	push	bc
	push	hl
	call	?cist
	pop	hl
	pop	bc
	or	a
	ret

cost1:		; get output status, saving <BC> & <HL>
	push	bc
	push	hl
	call	?cost
	pop	hl
	pop	bc
	or	a
	ret

ci1:		; get input, saving <BC> & <HL>
	push	bc
	push	hl
	call	?ci
	pop	hl
	pop	bc
	ret


	; AUXIST
	;	Auxiliary Input Status. Return true if
	;		any selected auxiliary input device
	;		has an available character.
?auxis:
auxist:
	ld	hl,(@aivec)	; get aux input bit vector
	jr	ist$scan


	; CONST
	;	Console Input Status. Return true if
	;		any selected console input device
	;		has an available character.
?const:
const:
	ld	hl,(@civec)	; get console input bit vector


ist$scan:
	ld	b,0		; start with device 0
cis$next:
	add	hl,hl		; check next bit
	ld	a,0		; assume device not ready
	call	c,cist1		; check status for this device
	or	a
	ret	nz		; if any ready, return true
	inc	b		; next device number
	ld	a,h
	or	l		; see if any more selected devices
	jr	nz,cis$next
	xor	a		; all selected were not ready, return false
	ret


	; AUXIN
	;	Auxiliary Input. Return character from first
	;		ready auxiliary input device.
?auxi:
auxin:
	ld	hl,(@aivec)
	jr	in$scan


	; CONIN
	;	Console Input. Return character from first
	;		ready console input device.
?conin:
conin:
	ld	hl,(@civec)

in$scan:
	push	hl		; save bit vector
	ld	b,0
ci$next:
	add	hl,hl		; shift out next bit
	ld	a,0		; insure zero a (nonexistant device not ready).
	call	c,cist1		; see if the device has a character
	or	a
	jr	nz,ci$rdy	; this device has a character
	inc	b		; else, next device
	ld	a,h
	or	l		; see if any more devices
	jr	nz,ci$next	; go look at them
	pop	hl		; recover bit vector
	jr	in$scan		; loop til we find a character
ci$rdy:
	pop	hl		; discard extra stack
	jp	?ci



xofflist:
	db 	-1,-1,-1,-1,-1,-1,-1,-1	; ctl-s clears to zero
	db	-1,-1,-1,-1,-1,-1,-1,-1


	end