;TERM.ASM by Michael Conley -- version 1.0 PUBLIC DOMAIN JUNE 1985
;sends characters to your terminal (defined at end or patched with DDT, etc.)
;to clear the screen, or set any available attribute
;
PRCHR	EQU	2
BDOS	EQU	5
DMA	EQU	80H
DMABUF	EQU	DMA + 2
TPA	EQU	100H
;
LF	EQU	10
CR	EQU	13
ESC	EQU	27
;
;
	ORG	TPA		; Tpa starting address
	LD	HL,0		; First, clear hl
	ADD	HL,SP		; Then add in stack pointer
	LD	(OLDSP),HL	; Save it to oldsp
	LD	SP,STACK	; And aim pointer at internal stack
START:	
	PUSH	BC		; Save the regs
	PUSH	DE
	PUSH	HL
	LD	HL,DMA
	LD	A,(HL)		; Look at the ccp buffer
	CP	0		; More characters?
	JP	NZ,WHICH1	; Yes, process them
EXPLAIN:			; No, run help message
	LD	HL,HELP
	CALL	PRINT
	LD	HL,TERMTYP	; Include terminal type in message
	CALL	PRINT
	LD	HL,HELP1	; Then print the rest
	CALL	PRINT
	JP	EXIT
WHICH1:	
	LD	HL,ATTRIB	; First turn on term attribs if req
	CALL	PRINT
	LD	HL,DMABUF	; Then check the buffer
	LD	A,(HL)		; Got a character, check it
	CP	'C'
	JP	NZ,NEXT1
	LD	HL,CLS
	JP	OUTPUT
NEXT1:	
	CP	'R'
	JP	NZ,NEXT2
	LD	HL,INTOREV
	JP	OUTPUT
NEXT2:	
	CP	'N'
	JP	NZ,NEXT3
	LD	HL,OUTAREV
	JP	OUTPUT
NEXT3:	
	CP	'D'
	JP	NZ,NEXT4
	LD	HL,FLASH
	JP	OUTPUT
NEXT4:	
	CP	'E'
	JP	NZ,NEXT5
	LD	HL,NOFLASH
	JP	OUTPUT
NEXT5:	
	CP	'O'
	JP	NZ,NEXT6
	LD	HL,HALF
	JP	OUTPUT
NEXT6:	
	CP	'X'
	JP	NZ,NEXT7
	LD	HL,BRIGHT
	JP	OUTPUT
NEXT7:	
	CP	'S'
	JP	NZ,NEXT8
	LD	HL,TRANSP
	JP	OUTPUT
NEXT8:	
	CP	'Q'
	JP	NZ,EXPLAIN
	LD	HL,NOTRANS

OUTPUT:	
	CALL	PRINT
	JP	EXIT

PRINT:	
	LD	C,PRCHR		; Load print command in c
	LD	A,(HL)		; Get mem loc
	CP	80H		; Is it our terminator?
	RET	Z		; Yes, then let's return
	LD	E,A		; Otherwise stick it in E
	PUSH	HL		; Protect H reg
	CALL	BDOS		; And send it
	POP	HL		; Get H back
	INC	HL		; Increment it
	JP	PRINT		; And get ready for next char
EXIT:	
	POP	HL		; Reset regs
	POP	DE
	POP	BC
	LD	HL,(OLDSP)	; Pick up stored stack pointer
	LD	SP,HL		; Set pointer
	RET			; RET to cpm
;
;data storage
;
;configure these for your terminal, terminate all with 80h
;all except TERMTYP are 6 bytes long including the 80h
;don't disturb the POINT labels, they're for easy patching with DDT
;
	ORG	200H		; make it easy to find with DDT
;
POINT:	DEFB	'Terminal type>' ; don't touch
TERMTYP:DEFB	'Amstrad _VT52 emulation',80H ; your terminal type
POINT1:	DEFB	'Clear screen>'	; don't touch
CLS:	DEFB	ESC,'E',ESC,'H',80H;clear screen code
POINT2:	DEFB	'Enable Attributes>' ; don't touch
ATTRIB:	DEFB	0,0,0,0,0,80H ; if not needed, set all to nulls
POINT3:	DEFB	'Reverse Video>' ; don't touch
INTOREV:DEFB	ESC,'p',0,0,0,80H ; into reverse video
POINT4:	DEFB	'End Reverse>'	; don't touch
OUTAREV:DEFB	ESC,'q',0,0,0,80H ; end reverse video
POINT5:	DEFB	'24 x 80 mode>' ; don't touch
TRANSP:	DEFB	ESC,'x',0,0,0,80H ; enter transparent mode
POINT6:	DEFB	'Exit 24x80 mode>' ; don't touch
NOTRANS:DEFB	ESC,'y',0,0,0,80H ; exit transparent mode
POINT7:	DEFB	'Status line off>'	; don't touch
FLASH:	DEFB	ESC,'0',0,0,0,80H ; begin flashing video
POINT8:	DEFB	'Status line on>'	; don't touch
NOFLASH:DEFB	ESC,'1',0,0,0,80H ; end flashing video
POINT9:	DEFB	'Cursor on>' ; don't touch
HALF:	DEFB	ESC,'e',0,0,0,80H ; enter write protect/half intensity
POINTA:	DEFB	'Cursor off>' ; don't touch
BRIGHT:	DEFB	ESC,'f',0,0,0,80H ; end write protect/half intensity
POINTB:	DEFB	'<End of user alterable area'
;
;help message
;
HELP:	DEFB	CR,LF
	DEFB	'TERM version 1.0 by Michael Conley',CR,LF
	DEFB	'Configured for: ',80H
HELP1:	DEFB	CR,LF,LF
	DEFB	'Type:',CR,LF
	DEFB	'TERM C - Clear screen',CR,LF,LF
	DEFB	'TERM R - Reverse video',CR,LF
	DEFB	'TERM N - Normal  video',CR,LF,LF
	DEFB	'TERM D - Disable status line',CR,LF
	DEFB	'TERM E - Enable status line',CR,LF,LF
	DEFB	'TERM O - Cursor on     ',CR,LF
	DEFB	'TERM X - Cursor off      ',CR,LF,LF
	DEFB	'TERM S - Set  24x80  mode',CR,LF
	DEFB	'TERM Q - Quit 24x80  mode',CR,LF,LF
	DEFB	'NOTE: May easily be patched using DDT -',CR,LF
	DEFB	'      User PATCH area begins at 200H',CR,LF,LF
	DEFB	80H		; List terminator
;
OLDSP:	DEFS	2		; Save stack pointer here
	DEFS	20		; Internal stack
STACK:	
	END  TPA

