;term1.opt	Hand-optimized version of term1.mac	27 Mar 1988
;		Optimization code in small letters
	.Z80
	CSEG
P.39:
	DEFB	'Less than %dk for input buffer'
	DEFB	10
	DEFB	0
P.145:
	DEFB	'<%-2X>'
	DEFB	0
	EXTRN	?NFILE
	EXTRN	?IOB
	EXTRN	INPUT
	EXTRN	OUTPUT
	EXTRN	FORMAT
	EXTRN	MODE
	EXTRN	MASK
	EXTRN	CSET
	EXTRN	BUFCLR
	EXTRN	HSTPPD
	EXTRN	XONKEY
	EXTRN	PASSLF
	EXTRN	ECHO
	EXTRN	DSPCTL
	EXTRN	VTEMUL
	EXTRN	VTINIT
	EXTRN	PRTLOG
	EXTRN	RULER
	EXTRN	SIO?RE
	EXTRN	PIO?B0
	EXTRN	PAR
	EXTRN	SERVIC
	EXTRN	ALLOC
	EXTRN	PRINTF
	EXTRN	EXIT
	EXTRN	SWAPVE
	EXTRN	I?RS23
	EXTRN	INP
	EXTRN	STOPHO
	EXTRN	WAKEHO
	EXTRN	S?RS23
	EXTRN	@GC
	EXTRN	SETUP
	EXTRN	@GF
	EXTRN	CLOSEF
	EXTRN	SPRINT
	EXTRN	@VT
	EXTRN	@PF
	EXTRN	@PC
	EXTRN	@PT
	DSEG
P.24:
	DEFW	SERVIC+0
P.25:	DEFS	2,0
P.26:	DEFS	2,0
P.27:	DEFS	2,0
P.28:	DEFS	2,0
P.29:
	DEFW	0
	CSEG
INSTAL::
	ADD	HL,SP
	PUSH	HL
L.32:
	LD	HL,1024
	PUSH	HL
	LD	HL,4
	CALL	ALLOC
	LD	(P.26),HL
	LD	(P.25),HL
	LD	(P.27),HL
	LD	A,L
	OR	H
	JP	NZ,L.37
	LD	HL,P.39
	PUSH	HL
	LD	HL,1024
	PUSH	HL
	LD	HL,2
	ADD	HL,SP
	LD	A,(HL)
	INC	HL
	LD	H,(HL)
	LD	L,A
	PUSH	HL
	LD	HL,8
	CALL	PRINTF
	LD	HL,1
	PUSH	HL
	LD	HL,4
	CALL	EXIT
	JP	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	JP	$RTNS##
SEND::			;optimized
	ADD	HL,SP
	POP	BC
	EX	DE,HL
	LD	HL,-1
	ADD	HL,SP
	LD	SP,HL
	PUSH	BC
	PUSH	DE
	LD	HL,(INPUT)
;	CALL	$AOI##
	LD	A,L
	OR	H
;	JP	Z,L.93
	jp	nz,l.94
	LD	HL,2
	CALL	BEMPTY
;	CALL	$LNI##
;	CALL	$AOI##
L.93:
	LD	A,L
	OR	H
;	JP	Z,L.97
	jp	nz,l.97
l.94:
	LD	HL,4
	ADD	HL,SP
	LD	(HL),0 MOD 256
	JP	$RTNS##
L.97:
	LD	HL,5
	ADD	HL,SP
	LD	A,(HL)
	INC	HL
	LD	H,(HL)
	LD	L,A
	PUSH	HL
	LD	HL,4
	CALL	S?RS23
	EX	DE,HL
	LD	HL,4
	ADD	HL,SP
	LD	(HL),E
	JP	$RTNS##
R?KBD::			;optimized
	ADD	HL,SP
	POP	BC
	EX	DE,HL
	LD	HL,-1
	ADD	HL,SP
	LD	SP,HL
	PUSH	BC
	PUSH	DE
	DSEG
P.102:	DEFS	2,0
	CSEG
L.103:
	LD	HL,2
	CALL	@GC
	LD	(P.102),HL
	LD	DE,30
	CALL	$SCPI##
	JP	NZ,L.107
	LD	HL,2
	CALL	SETUP
	JP	L.103
L.107:
	LD	HL,(XONKEY)
	LD	A,L
	OR	H
	JP	Z,L.109
	LD	HL,(P.29)
	LD	A,L
	OR	H
	JP	Z,L.110
	LD	HL,(P.102)
	LD	DE,19
	CALL	$SCPI##
	CALL	$NEQU##

	CALL	$AOI##
	LD	A,L
	OR	H
	JP	Z,L.112
	LD	HL,(P.102)
	LD	DE,17
	CALL	$SCPI##
	CALL	$NEQU##

	CALL	$AOI##
L.112:
	LD	(P.29),HL
	LD	HL,4
	ADD	HL,SP
	LD	(HL),0 MOD 256
	JP	$RTNS##
L.110:
	LD	HL,(P.102)
	LD	DE,19
	CALL	$SCPI##
	JP	NZ,L.118
	LD	HL,1
	LD	(P.29),HL
	LD	HL,4
	ADD	HL,SP
	LD	(HL),0 MOD 256
	JP	$RTNS##
L.118:
L.109:
	LD	HL,(INPUT)
;	CALL	$AOI##
	LD	A,L
	OR	H
;	JP	Z,L.121
	jp	z,l.128
	LD	HL,(INPUT)
	PUSH	HL
	LD	HL,4
	CALL	@GF
	LD	(P.102),HL
	LD	DE,26
	CALL	$SCPI##
	CALL	$EQU##

	CALL	$AOI##
	LD	A,L
	OR	H
	JP	NZ,L.124
	LD	HL,(P.102)
	LD	DE,-1
	CALL	$SCPI##
	CALL	$EQU##

	CALL	$AOI##
;L.124:
;	CALL	$AOI##
L.121:
	LD	A,L
	OR	H
	JP	Z,L.128
l.124:
	LD	HL,INPUT
	PUSH	HL
	LD	HL,1
	PUSH	HL
	LD	HL,2
	ADD	HL,SP
	LD	A,(HL)
	INC	HL
	LD	H,(HL)
	LD	L,A
	PUSH	HL
	LD	HL,8
	CALL	CLOSEF
L.128:
	LD	HL,(P.102)
	CALL	$AOI##
	LD	A,L
	OR	H
;	JP	Z,L.131
	jp	z,l.132
	LD	HL,(ECHO)
	CALL	$AOI##
L.131:
	LD	A,L
	OR	H
	JP	Z,L.132
	LD	HL,(P.102)
	PUSH	HL
	LD	HL,4
	CALL	DISPLA
L.132:
	LD	DE,(P.102)
	LD	HL,4
	ADD	HL,SP
	LD	(HL),E
	JP	$RTNS##
DISPLA::		;optimized
	ADD	HL,SP
	PUSH	HL
	DSEG
P.137:	DEFS	5,0
P.138:	DEFS	2,0
	CSEG
	LD	HL,(DSPCTL)
	CALL	$AOI##
	LD	A,L
	OR	H
;	JP	Z,L.139
	jp	z,l.143
	LD	HL,4
	ADD	HL,SP
	LD	A,(HL)
	INC	HL
	LD	H,(HL)
	LD	L,A
	LD	DE,32
	CALL	$SCPI##
	CALL	$LT##

	CALL	$AOI##
L.139:
	LD	A,L
	OR	H
	JP	Z,L.143
	LD	HL,P.137
	PUSH	HL
	LD	HL,P.145
	PUSH	HL
	LD	HL,8
	ADD	HL,SP
	LD	A,(HL)
	INC	H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