	.Z80
	TITLE	COLEX-880 series console driver
	SUBTTL	Copyright (C) 1984, Colex Electronic Co. Ltd.
	NAME	('CONDRV')
	INCLUDE	COPYRIGH
;****************************************************************
;*								*
;*		COLEX-880 series console driver 		*
;*								*
;*	This module maps requests for the console to either	*
;*	the STD-CRT card or to the SCC on the STD-PSIO card	*
;*	(via the SCCDRV module). If DEFCON is non-zero, the 	*
;*	console assignment table is modified for either a crt	*
;*	or a scc based console depending upon the boot prom	*
;*	detecting the presence of the STD-CRT at coldstart.	*
;*								*
;****************************************************************
;  Date		   Author		Modification
;13-Jul-84	R.J. Wellsted
;10-Oct-84	R.J. Wellsted	added bit 7 suppression on input
	PAGE

	PUBLIC	CONIN@,CONDR@	;entry points
	PUBLIC	BERMSG,EERMSG	;error message handlers
	PUBLIC	USRSOM,USRREL	;signon message, release no.
	PUBLIC	DEFCON		;default console patch point

	EXTRN	CRTINI,CRTDRV	;crt driver entry points
	EXTRN	CONAST,SCCDRV	;console assignment, scc driver
	EXTRN	C1FLGS		;scc channel 1 flags
	EXTRN	DMSHL		;print string function

IOBYTE	EQU	0003H		;boot prom crt flag byte
CR	EQU	0DH
LF	EQU	0AH

	COMMON	/?INIT?/
CONIN@:	LD	A,(DEFCON)	;get default console flag
	INC	A		;test if auto select
	JR	NZ,NOTAUT	;skip if not
	LD	HL,CONAST	;point to console assignment table
	LD	(HL),2		;assume std-crt for now
	LD	A,(IOBYTE)	;get crt flag
	OR	A		;test for crt
	JR	Z,NOTCRT	;skip if not
	CALL	CRTINI		;go do init if so
	JR	NOTAUT		;do rest of init

NOTCRT:	LD	(HL),1		;mark as scc console
	LD	A,(C1FLGS)	;get channel 1 flags
	AND	0FH		;get baud rate
	OR	11010000B	;set att'n detect & cts handshake (+in use)
	LD	(C1FLGS),A	;save flags
NOTAUT:	LD	HL,BERMSG	;point to begin error message
	CALL	SETEND		;set end point
	LD	HL,EERMSG	;point to end error message
SETEND:	LD	A,(HL)		;get length
	OR	A		;test for 0 length
	RET	Z		;done if so
	LD	E,A		;make 16 bit length
	LD	D,0
	ADD	HL,DE		;point to end
	SET	7,(HL)		;set msb of char
	RET			;done

USRSOM:	DB	CR,LF
	DB	'COLEX-880 series, Release '
USRREL:	DB	'2.4$$$$$$$$$$$$$$'

DEFCON:	DB	0FFH		;default console patch point

	CSEG
CONDR@:	LD	A,E		;get function code
	CP	8		;test for error message start
	JR	Z,BEGMSG	;skip if so
	CP	9		;test for error message end
	JR	Z,ENDMSG	;skip if so
	CP	2		;test for input
	JR	NC,GODRVR	;skip if not
	OR	A		;test for status test
	JR	NZ,GETINP	;skip if not
	CALL	GODRVR		;get input status
	RES	7,C		;clear parity bit
	RET			;done

GETINP:	CALL	GODRVR		;get character
	RES	7,A		;clear parity bit
	RET			;done

GODRVR:	LD	A,B		;get channel no.
	CP	2		;test if crt
	JP	Z,CRTDRV	;if so go to crt driver
	JP	SCCDRV		;else go to scc driver

BEGMSG:	LD	HL,BERMSG	;point to error message lead-in
	JR	SHWMSG		;go to show it

ENDMSG:	LD	HL,EERMSG	;point to error message lead-out
SHWMSG:	LD	A,(HL)		;get length
	INC	HL		;adjust pointer
	OR	A		;test for 0
	JP	NZ,DMSHL	;go show it
	RET			;done

	DSEG
BERMSG:	DB	2		;start of error message (length)
	DB	CR,LF
	DS	14

EERMSG:	DB	2		;error message finished (length)
	DB	CR,LF
	DS	14

	END
