	TITLE	"BIOS.TIO   HT68K BIOS: TERMINAL I/O"
	PAGE
********************** TERMINAL I/O **********************
;------------  GET CHAR FROM CONSOLE --- NO EDITING --- NO ECHO
GETCON

;=====	LEA	SRAREG,A1	;==
;GCON00	BTST.B	#0,(A1)		;==
;=====	BEQ.S	GCON00		;==
;=====	MOVE.B	RBAREG,D7	;==
;=====	MOVE.L	D7,-(A4)	;==
;=====	RTS			;==

	LEA	CONIN+VARS,A1
GCON10	TST.W	SIZE(A1)	;WAIT FOR CHARACTER
	BEQ.S	GCON10
	MOVEQ	#0,D1		;GET CHAR
	MOVE.B	TAIL(A1),D1
	MOVE.B	QUEUE(A1,D1),D7
	SUBQ.W	#1,SIZE(A1)	;UPDATE QUEUE
	ADDQ.B	#1,TAIL(A1)
	MOVE.L	D7,-(A4)	;RETURN CHAR ON HTPL STACK
	RTS
;-----------  PUT CHAR TO CONSOLE
PUTCON

;=====	LEA	SRAREG,A1	;==
;PCON00	BTST.B	#2,(A1)		;==
;=====	BEQ.S	PCON00		;==
;=====	MOVE.L	(A4)+,D0	;==
;=====	MOVE.B	D0,TBAREG	;==
;=====	RTS			;==

	LEA	VARS,A2
	LEA	CONOUT(A2),A1
PCON10	CMPI.W	#256,SIZE(A1)	;WAIT FOR ROOM IN QUEUE
	BHS.S	PCON10
	MOVE.L	(A4)+,D0	;GET CHAR FROM HTPL STACK
	MOVEQ	#0,D1		;PUT CHAR IN QUEUE
	MOVE.B	HEAD(A1),D1
	MOVE.B	D0,QUEUE(A1,D1)
	ADDQ.W	#1,SIZE(A1)	;UPDATE QUEUE
	ADDQ.B	#1,HEAD(A1)
	ORI.B	#TXABIT,MASK681(A2)	;ENABLE TXRDY INTERRUPT
	MOVE.B	MASK681(A2),IMRREG
	RTS
;-----------  INITIALIZE CONSOLE
INITCON
	BSR	ICHANA
	RTS
;-----------  STATUS OF CONSOLE
STATCON
	MOVEQ	#0,D0
	LEA	VARS,A2
	MOVE.B	SRAREG,D1	;GET STATUS OF CHANNEL A
	BTST	#0,D1		;IF STATUS BITS VALID THEN
	BEQ.S	SCON20
	BTST	#7,D1		;  IF BREAK DETECT
	BEQ.S	SCON10
	BSET.L	#2,D0		;    THEN SET BREAK
SCON10	ANDI.B	#70H,D1		;  IF RECEIVER ERRORS
	BEQ.S	SCON20
	BSET.L	#14,D0		;    THEN SET ERROR
SCON20	LEA	CONIN(A2),A0
	TST.W	SIZE(A0)	;IF INPUT QUEUE NOT EMPTY
	BEQ.S	SCON30
	BSET.L	#0,D0		;  THEN SET CHARACTER_AVAILABLE
SCON30	LEA	CONOUT(A2),A0
	CMPI.W	#256,SIZE(A0)
	BHS.S	SCON40		;IF OUTPUT QUEUE NOT FULL
	BSET.L	#1,D0		;  THEN SET TRANSMIT_READY
SCON40	BSET.L	#15,D0		;SET COMMAND_PROCESSED
	MOVE.L	D0,-(A4)	;RETURN STATUS
	RTS 
;-----------  CONTROL CONSOLE
CNTRLCON
	LEA	VARS,A2
	MOVE.L	(A4)+,D0	;GET CONTROL STRING LENGTH
	MOVEA.L	(A4)+,A0	;GET CONTROL STRING POINTER
	MOVE.L	#8000H,-(A4)	;CLEAN STATUS
CCON20	TST.L	D0		;WHILE NOT END OF STRING
	BNE.S	CCON30
	RTS
CCON30	MOVE.B	(A0)+,D1	;  GET CONTROL_CODE
	SUBQ.L	#1,D0		;  CASE CONTROL_CODE OF
	CMPI.B	#1,D1		;  01: (SCSI REZERO CODE)
	BNE.S	CCON40
	MOVEM.L	#0101H,-(A4)
	BSR	ICHANA		;      RE-INITIALIZE CHANNEL A
	MOVEM.L	(A4)+,#8080H
	BRA.S	CCON20
CCON40	ORI.B	#17H,3(A4)	;  OTHER: REQUEST DENIED
	BRA.S	CCON20		;ENDCASE ENDWHILE

;------------  GET CHAR FROM PRINTER --- NO EDITING --- NO ECHO
GETPRN
	CLR.L	-(A4)		;RETURN NULL CHAR
	RTS
;-----------  PUT CHAR TO PRINTER
PUTPRN
	LEA	VARS,A2
	LEA	PRNOUT(A2),A1
PPRN10	CMPI.W	#256,SIZE(A1)	;WAIT FOR ROOM IN QUEUE
	BHS.S	PPRN10
	MOVE.L	(A4)+,D0	;GET CHAR FROM HTPL STACK
	MOVEQ	#0,D1		;PUT CHAR IN QUEUE
	MOVE.B	HEAD(A1),D1
	MOVE.B	D0,QUEUE(A1,D1)
	ADDQ.W	#1,SIZE(A1)	;UPDATE QUEUE
	ADDQ.B	#1,HEAD(A1)
	TST.B	PRNACK(A2)	;IF LAST CHAR ACKNOWLEDGED
	BEQ.S	PPRN90
	BSR	PRNCHAR		;  THEN SEND CHARACTER
PPRN90	RTS			;  ELSE WAIT FOR ACK
;-----------  INITIALIZE PRINTER
INITPRN
	BSR	INIPRN		;USE RESET INIT ROUTINE
	RTS
;-----------  STATUS OF PRINTER
STATPRN
	MOVEQ	#0,D0
	LEA	VARS,A2
	TST.B	PRNACK(A2)
	BNE.S	SPRN10		;IF NO ACKNOWLEDGE FROM LAST CHAR
	BSET.L	#8,D0		;  THEN SET BUSY
SPRN10	LEA	PRNOUT(A2),A0
	CMPI.W	#256,SIZE(A0)
	BHS.S	SPRN20		;IF QUEUE NOT FULL
	BSET.L	#1,D0		;  THEN SET TRANSMIT_READY
SPRN20	BSET.L	#15,D0		;SET COMMAND_PROCESSED
	MOVE.L	D0,-(A4)	;RETURN STATUS
	RTS
;-----------  CONTROL PRINTER
CNTRLPRN
	RTS

;------------  GET CHAR FROM AUXILIARY DEVICE (TERM2)
GETAUX
	LEA	AUXIN+VARS,A1
GAUX10	TST.W	SIZE(A1)	;WAIT FOR CHARACTER
	BEQ.S	GAUX10
	MOVEQ	#0,D1		;GET CHAR
	MOVE.B	TAIL(A1),D1
	MOVE.B	QUEUE(A1,D1),D7
	SUBQ.W	#1,SIZE(A1)	;UPDATE QUEUE
	ADDQ.B	#1,TAIL(A1)
	MOVE.L	D7,-(A4)	;RETURN CHAR ON HTPL STACK
	RTS
;-----------  PUT CHAR TO AUXILIARY DEVICE (TERM2)
PUTAUX
	LEA	VARS,A2
	LEA	AUXOUT(A2),A1
PAUX10	CMPI.W	#256,SIZE(A1)	;WAIT FOR ROOM IN QUEUE
	BHS.S	PAUX10
	MOVE.L	(A4)+,D0	;GET CHAR FROM HTPL STACK
	MOVEQ	#0,D1		;PUT CHAR IN QUEUE
	MOVE.B	HEAD(A1),D1
	MOVE.B	D0,QUEUE(A1,D1)
	ADDQ.W	#1,SIZE(A1)	;UPDATE QUEUE
	ADDQ.B	#1,HEAD(A1)
	ORI.B	#TXBBIT,MASK681(A2)	;ENABLE TXRDY INTERRUPT
	MOVE.B	MASK681(A2),IMRREG
	RTS
;-----------  INITIALIZE AUXILIARY
INITAUX
	BSR	ICHANB
	RTS
;-----------  STATUS OF AUXILIARY
STATAUX
	MOVEQ	#0,D0
	LEA	VARS,A2
	MOVE.B	SRBREG,D1	;GET STATUS OF CHANNEL B
	BTST	#0,D1		;IF STATUS BITS VALID THEN
	BEQ.S	SAUX20
	BTST	#7,D1		;  IF BREAK DETECT
	BEQ.S	SAUX10
	BSET.L	#2,D0		;    THEN SET BREAK
SAUX10	ANDI.B	#70H,D1		;  IF RECEIVER ERRORS
	BEQ.S	SAUX20
	BSET.L	#14,D0		;    THEN SET ERROR
SAUX20	LEA	AUXIN(A2),A0
	TST.W	SIZE(A0)	;IF INPUT QUEUE NOT EMPTY
	BEQ.S	SAUX30
	BSET.L	#0,D0		;  THEN SET CHARACTER_AVAILABLE
SAUX30	LEA	AUXOUT(A2),A0
	CMPI.W	#256,SIZE(A0)
	BHS.S	SAUX40		;IF OUTPUT QUEUE NOT FULL
	BSET.L	#1,D0		;  THEN SET TRANSMIT_READY
SAUX40	BSET.L	#15,D0		;SET COMMAND_PROCESSED
	MOVE.L	D0,-(A4)	;RETURN STATUS
	RTS 

;-----------  CONTROL AUXILIARY
CNTRLAUX
	LEA	VARS,A2
	MOVE.L	(A4)+,D0	;GET CONTROL STRING LENGTH
	MOVEA.L	(A4)+,A0	;GET CONTROL STRING POINTER
	MOVE.L	#8000H,-(A4)	;CLEAN STATUS
CAUX20	TST.L	D0		;WHILE NOT END OF STRING
	BNE.S	CAUX30
	RTS
CAUX30	MOVE.B	(A0)+,D1	;  GET CONTROL_CODE
	SUBQ.L	#1,D0		;  CASE CONTROL_CODE OF
	CMPI.B	#1,D1		;  01: (SCSI REZERO CODE)
	BNE.S	CAUX40
	MOVEM.L	#0101H,-(A4)
	BSR	ICHANB		;      RE-INITIALIZE CHANNEL B
	MOVEM.L	(A4)+,#8080H
	BRA.S	CAUX20
CAUX40	ORI.B	#17H,3(A4)	;  OTHER: REQUEST DENIED
	BRA.S	CAUX20		;ENDCASE ENDWHILE


	END	;BIOS.TIO
