; CP/M CONSOLE & PRINTER INTERFACE
;
; Last update:
;
; 850511 - Saved BC' prior to CP/M calls
; 841010 - Saved IX & IY prior to CP/M calls
; 840909 - Converted all BIOS calls to BDOS calls for compatibility
;          with CP/M 3.0
;
;
;
lstout		equ	05h		; printer output
dconio		equ	06h		; direct console I/O
;
cacr		equ	12h		; cache control register
;
rubout		equ	7fh		
inpreq		equ	0ffh		; dconio input request
;
	;.z280					
	; PRE280 V1.11b 20-Nov-90  Copyright (c) 1990 by A.Zinser (fifi@veeble.north.de)
	.Z80
;
eprint:	defb	0			; printer flag
					; 0=disabled, 1=enabled
;
sysent:					
	push	bc				
	push	de				
	push	hl				
	push	ix				
	push	iy				
	exx					
	push	bc			; save ip (if used as such)
	exx				
	call	bdoss			; perform function (C)
	exx				
	pop	bc			; restore ip
	exx				
	pop	iy			
	pop	ix			
	pop	hl			
	pop	de			
	pop	bc			
	ret				
;
cstat:					
	push	bc			
	ld	c,dconio		; direct console I/O
	ld	e,inpreq		; input request
	call	sysent			; any chr typed?
	pop	bc			; if yes, a <-- char
	ret				; else    a <-- 00h (ignore chr)
;
;
cin:					
	push	bc			
	ld	c,dconio		; direct console i/o
	ld	e,inpreq		; request input
cinlp:					
	call	sysent			; a <-- chr (or 0 if nothing typed)
	or	a			
	jr	z,cinlp			; wait for CHR to be typed
	cp	rubout			
	jr	nz,cin1			
	ld	a,bsout			; convert RUB to ^H
cin1:					
	res	7,a			; msb <-- 0
	pop	bc			
	ret				
;
;
cout:					
	push	bc			
	push	de			; save e = chr
	ld	c,dconio		; direct console output
	call	sysent			; send e to con:
	pop	de			
	pop	bc			
	ret				
;
;
pout:					
	push	bc			
	ld	c,lstout		
	call	sysent			; send e to lst:
	pop	bc			
	ret				
;
;
cpout:					
	call	cout			; send e to console
	ld	a,(eprint)		
	or	a			; if eprint <> 0
	call	nz,pout			;send e to LST:
	ret				
;
;
;	FORTH TO CP/M SERIAL I/O INTERFACE
;
pqter:					
	call	cstat			
	ld	hl,0			
	or	a			; chr typed?
	jr	z,pqte1			; no
	inc	l			; yes, s1 <-- true
pqte1:					
	jhpush				
;
;
pkey:					
	call	cin			; read chr from console
	cp	dle			; ^P?
	ld	e,a			
	jr	nz,pkey1		; no
	ld	hl,eprint		
	ld	e,abl			; e <-- blank
	ld	a,(hl)			
	xor	01h			; toggle eprint lsb
	ld	(hl),a			
pkey1:					
	ld	l,e			
	ld	h,0			
	jhpush				; s1.lb <-- chr
;
;
pemit:					
	defw	$+2			; (EMIT) orphan
	pop	de			; e <-- s1.lb = chr
	ld	a,e			
	cp	bsout			
	jr	nz,pemit1		
	call	cout			; backspace
	ld	e,abl			; blank
	call	cout			; erase chr on con:
	ld	e,bsout			; backspace
pemit1:					
	call	cpout			; send chr to con:
	jnext				; and lst: if eprint = 01h
;
;
pcr:					
	ld	e,acr			
	call	cpout			; output cr
	ld	e,lf			
	call	cpout			; and lf
	jnext				
;
;
;
int = 01h
;
;
pcr:					
	ld	e,acr			
	call	cpout			; output cr
	