;
;==================================================================================================
; S100 PROPELLER CONSOLE DRIVER
;==================================================================================================
;
; TODO:
;
SCON_IOBASE	.EQU	$0000			; NOTE: 16-BIT I/O
;
SCON_STATUS	.EQU	SCON_IOBASE
SCON_DATA	.EQU	SCON_IOBASE + 1
;
SCON_KBDRDY	.EQU	%00000010
SCON_DSPRDY	.EQU	%00000100
;
SCON_COLS	.EQU	80
SCON_ROWS	.EQU	40
;
		DEVECHO	"SCON: IO="
		DEVECHO	SCON_IOBASE
		DEVECHO	"\n"
;
;
;
SCON_INIT:
	CALL	NEWLINE
	PRTS("SCON:$")
	PRTS(" IO=0x$")			; FORMATTING
	LD	A,SCON_IOBASE
	CALL	PRTHEXBYTE
;
	; DISPLAY CONSOLE DIMENSIONS
	CALL	PC_SPACE
	LD	A,SCON_COLS
	CALL	PRTDECB
	LD	A,'X'
	CALL	COUT
	LD	A,SCON_ROWS
	CALL	PRTDECB
	CALL	PRTSTRD
	.TEXT	" TEXT (ANSI)$"
;
; ADD OURSELVES TO CIO DISPATCH TABLE
;
	LD	D,0			; PHYSICAL UNIT IS ZERO
	LD	E,CIODEV_SCON		; DEVICE TYPE
	LD	BC,SCON_FNTBL		; BC := FUNCTION TABLE ADDRESS
	CALL	CIO_ADDENT		; ADD ENTRY, A := UNIT ASSIGNED
	;;;LD	(HCB + HCB_CRTDEV),A	; SET OURSELVES AS THE CRT DEVICE
	CALL	CIO_SETCRT		; SET OURSELVES AS THE CRT DEVICE
;
	XOR	A			; SIGNAL SUCCESS
	RET
;
; DRIVER FUNCTION TABLE
;
SCON_FNTBL:
	.DW	SCON_IN
	.DW	SCON_OUT
	.DW	SCON_IST
	.DW	SCON_OST
	.DW	SCON_INITDEV
	.DW	SCON_QUERY
	.DW	SCON_DEVICE
#IF (($ - SCON_FNTBL) != (CIO_FNCNT * 2))
	.ECHO	"*** INVALID SCON FUNCTION TABLE ***\n"
#ENDIF
;
;
;
SCON_IN:
	CALL	SCON_IST		; CHECK FOR CHAR PENDING
	JR	Z,SCON_IN		; WAIT FOR IT IF NECESSARY
	;IN0	A,(SCON_DATA)		; READ THE CHAR FROM PROPIO
	LD	BC,SCON_DATA		; DATA PORT (16 BIT I/O)
	IN	A,(C)			; READ THE CHAR FROM PROPIO
	LD	E,A
	RET
;
;
;
SCON_IST:
	;IN0	A,(SCON_STATUS)		; READ LINE STATUS REGISTER
	LD	BC,SCON_STATUS		; STATUS PORT (16-BIT I/O)
	IN	A,(C)			; READ LINE STATUS REGISTER
	AND	SCON_KBDRDY		; ISOLATE KBDRDY
	JP	Z,CIO_IDLE		; RETURN VIA IDLE PROCESSING
	OR	$FF			; SET A=$FF TO SIGNAL READY
	RET				; RETURN
;
;
;
SCON_OUT:
	CALL	SCON_OST		; CHECK FOR OUTPUT READY
	JR	Z,SCON_OUT		; WAIT IF NECESSARY
	LD	A,E			; RECOVER THE CHAR TO WRITE
	;OUT0	(SCON_DATA),A		; WRITE THE CHAR TO PROPIO
	LD	BC,SCON_DATA		; DATA PORT (16 BIT I/O)
	OUT	(C),A			; WRITE THE CHAR TO PROPIO
	RET
;
;
;
SCON_OST:
	;IN0	A,(SCON_STATUS)		; READ LINE STATUS REGISTER
	LD	BC,SCON_STATUS		; STATUS PORT (16-BIT I/O)
	IN	A,(C)			; READ LINE STATUS REGISTER
	AND	SCON_DSPRDY 		; ISOLATE DSPRDY
	JP	Z,CIO_IDLE		; RETURN VIA IDLE PROCESSING
	OR	$FF			; SET A=$FF TO SIGNAL READY
	RET				; RETURN
;
;
;
SCON_INITDEV:
	SYSCHKERR(ERR_NOTIMPL)
	RET
;
;
;
SCON_QUERY:
	LD	DE,0
	LD	HL,0
	XOR	A
	RET
;
;
;
SCON_DEVICE:
	LD	D,CIODEV_SCON		; D := DEVICE TYPE
	LD	E,0			; E := DEVICE NUM, ALWAYS 0
	LD	C,$BF			; C := DEVICE TYPE, 0xBF IS PROP TERM
	LD	H,0			; H := 0, DRIVER HAS NO MODES
	LD	L,SCON_IOBASE		; L := BASE I/O ADDRESS
	XOR	A			; SIGNAL SUCCESS
	RET
