;
; CRT OUTPUT
;
LINLEN	EQU	80		;LINE LENGTH
LPP	EQU	24		;LINES PER PAGE
PGLEN	EQU	1920		;CHARACTERS PER PAGE
;
VIO	EQU	0F000H		;REFRESH MEMORY ADDRESS
;
	ORG	5000H
;
CRTOUT:	LHLD	ROWCOL		;ROW, COLUMN
	XCHG
	LHLD	CURSR		;ABSOLUTE CURSOR ADDRESS
	MOV	A,M		;GET CHAR UNDER CURSOR
	ANI	7FH		;TURN CURSOR OFF
	MOV	M,A		;AND PUT CHAR BACK
	MOV	A,C		;GET CHAR
	CPI	0AH		;AND BEGIN TESTING FOR SPECIALS
	JZ	VLF
	CPI	0DH
	JZ	VCR
	CPI	5FH
	JZ	CHRDEL
	CPI	08H
	JNZ	VWRITE
	DCR	E		;DECREMENT COLUMN
	JMP	STRCR		;TURN CURSOR BACK ON & RET
CHRDEL:	MOV	A,E		;MAKE SURE WE'RE NOT IN 1ST SCRN POS
	ORA	D		;
	JNZ	CHDEL1		;O.K.
	LXI	D,((LPP-1)*256)+(LINLEN-1)
	LXI	H,VIO+PGLEN-1
	JMP	CHDEL2
CHDEL1:	DCR	E		;DECREMENT COLUMN
	DCX	H		;DECREMENT MEMORY POINTER
CHDEL2:	MVI	M,' '
	JMP	STRCR
VLF:	INR	D		;INCREMENT ROW
	JMP	STRCR
SCROL:	LXI	H,VIO+LINLEN
	LXI	D,VIO
SWAP:	MOV	A,M
	INX	H
	STAX	D
	INX	D
	MVI	A,(VIO+PGLEN) SHR 8
	CMP	H
	JNZ	SWAP
	MVI	A,(VIO+PGLEN) AND 0FFH
	CMP	L		;NOW TEST LOW ORDER BYTE
	JNZ	SWAP		;AND CONTINUE IF NOT DONE
	XCHG
LSTLN:	MVI	M,' '
	INX	H
	MOV	A,L
	CPI	(VIO+PGLEN) AND 0FFH
	JNZ	LSTLN
	MVI	D,LPP-1		;BUT PUT CURSOR ON LAST LINE
	RET
VCR:	MVI	E,0
	JMP	STRCR
VWRITE:	MOV	M,C
	INR	E
STRCR:	MOV	A,E
	ORA	A
	JP	STRCR2
	MVI	E,LINLEN-1
	MOV	A,E
	DCR	D
STRCR2:	CPI	LINLEN
	JC	CKLINE
	MVI	E,0
	INR	D
CKLINE:	MOV	A,D		;GET LINE NO.
	ORA	A		;SET FLAGS
	JP	CKLIN2		;AT LEAST IT'S >= 0
	MVI	D,LPP-1		;WRAP AROUND BACKWARDS IF NEG
	MOV	A,D
CKLIN2:	CPI	LPP		;SEE IF OFF END
	JC	CALCAD
	MOV	C,E		;SAVE COL. NO.
	CALL	SCROL		;WE DID, NEED TO SCROLL UP
	MOV	E,C		;RESTORE COLUMN NO.
CALCAD:	XCHG			;PUT ROW, COL IN H,L
	SHLD	ROWCOL
	XCHG
	LXI	B,LINLEN	;NOW MULT LINE LENGTH BY ROW NO
	LXI	H,VIO-LINLEN
CALC1:	DAD	B		;
	DCR	D
	JP	CALC1
	INR	D		;NOW ADD IN COLUMN NO.
	DAD	D		;
CALCDN:	SHLD	CURSR
	MOV	A,M
	ORI	80H
	MOV	M,A
	RET
;
CURSR	DW	VIO
ROWCOL	DW	0
