;
**********  SPINWRITER PROCESSOR *****************
;
;	 SPECIAL CODE FOR SPINWRITER (5510/5520)
;	  NON-DIABLO COMPATABLE
;	(C) RLR 1977 REV 00.00
;	(C) rlr 8/16/80 rev 00.05 (proper subscript/bold)
;	serarate module
;	    rev 01.00 rlr 10/30/80 
;
	NAM	SPWRTA
	ENT	SPINIT,SPRDY,SPOUT
;
	EXT	SPCINIT
	EXT	SPCSTAT,SPCIN
	EXT	SPCRDY,SPCOUT
;
	EXT	PROCHR,DELAY
;
ESC	EQU	27
ETX	EQU	3
ACK	EQU	6
BS	EQU	8
RS	EQU	30
US	EQU	31
CR	EQU	13
LF	EQU	10
SPC	EQU	20H
DLYF	EQU	3500
;
SPINIT:	JMP	SPCINIT
	EJECT
;
;
; ESC PROCESSOR
;
AX	MAC	; ACTION [LETTER,ADDRESS]
[DB	'&1'
	DW	&2]
S	MAC	; SET [LETTER,ADDRESS]
[DB	80H+'&1'
	DW	&2]
;
ESCTAB:	DW	OTCHR
	#AX	[A,SPINIT]
	#AX	[B,DOTHIN]
	#AX	[C,REVLF]
	#AX	[M,DOWID]
	#AX	[N,DOHGHT]
	#S	[O,THINWD]
	#AX	[F,HALFSP]
	#AX	[R,RIBBON]
	#S	[P,BOLDFG]
	DB	-1
	EJECT
;
;
; SPECIAL FUNCTIONS
;
DOTHIN:	LDA	THINWD
;
	CPI	8
	JLT	THIN2
;
	PUSH	AF	; SEND 7'S
	MVI	A,7
	CALL	SETWID	; SET TO THIN HORZ MOTION INDEX
	POP	AF
;
THIN1:	PUSH	AF	; SEND 7'S
	MVI	A,SPC
	CALL	LOUTX	; DO A SPACE
	POP	AF
	SUI	7
	CPI	8
	JGE	THIN1
;
THIN2:	CALL	SETWID	; RESIDUE
	MVI	A,SPC
	CALL	LOUTX
;
	LDA	NORMWD
	JMP	SETWID	; SET TO NORMAL WIDTH
;
DOWID:	MOV	A,L
	STA	NORMWD
	JMP	SETWID	; SET WIDTH
;
;	(ESC) ']' ('P'+X-1)
;
DOHGHT:	MOV	A,L
	STA	NORMHT
;
;
SETHGT:	MVI	B,']'	; SET CHAR HEIGHT
	CALL	ESCODE
	ADI	'P'-1
	JMP	LOUTX
;
; REVERSE LINE FEEDS
;
REVLF:	MOV	A,L	; REVERSE LINE FEEDS
	MVI	B,'9'
;
REVLF1:	CALL	ESCODE
	DCR	A
	JNZ	REVLF1
	RET
;
; SET WIDTH (1/60THS)
;	(ESC) ']' ('@'+N)
;
SETWID:	ADD	A	;*2
SET120:	MVI	B,']'
	ADI	'@'
;
SETPRM:	CALL	ESCODE	; (ESC) (B)
	JMP	LOUTX	;  (THEN A)
;
; HALF SPACING (OFFSET BY 127)  CODE =F
;
HALFSP:	MOV	A,L
	SBI	127
	RZ
;
	PUSH	AF
	LDA	NORMHT
	RRC
	ANI	15
	CALL	SETHGT	; SET HEIGHT TO HALF
	POP	AF
;
	MVI	B,'X'	; DOWN (MINUS)
	JGE	HALF1
;
	MVI	B,'Z'	; UP (PLUS)
	CMA
	INR	A
;
; 0..31 AS IS/ 32..63 THEN NEXT CHAR
;
HALF1:	CPI	31
	JLT	HALF2
;
	SUI	31	; 32..63
	INR	B	; NEXT CHAR
;
HALF2:	CALL	ESCODE
	ADI	'@'
	CALL	LOUTX
; RESET TO NORMAL HEIGHT
	LDA	NORMHT
	JMP	SETHGT	; SET HEIGHT TO HALF
;
; -R- RIBBON COLOR (0-BLACK,<>0-RED)
;
RIBBON:	MOV	A,L
	ORA	A
	MVI	B,'4'	; BLACK - CODE='4'
	JZ	RIBN1
	DCR	B	; RED - CODE='3'
RIBN1:	JMP	ESCODE
;
; SEND ESC CODE SEQUENCE (A=SAVED, B=CMD)
;   OUTPUT 3 CHARS (ESC),(B),IF NOT 0 THEN (A)
;
ESCODE:	PUSH	AF
	PUSH	B
     	MVI	A,ESC
	CALL	LOUTX
	POP	AF
	PUSH	AF
	CALL	LOUTX
	POP	B
	POP	AF
	RET
;
	EJECT
;
; LIST DEVICE READY
;
SPRDY:
	JMP	SPCRDY
;
; LIST DEVICE OUTPUTT
;
SPOUT:	LXI	H,ESCTAB
	CALL	PROCHR
	RET
;
; OUTPUT A CHAR, DO BOLD
;
OTCHR:
	CPI	SPC+1
	JLT	LOUTX
;ONLY TRY BOLD ON NORMAL CHARS
	PUSH	AF
	LDA	BOLDFG
	ORA	A
	JZ	OTCHR1	; 0-NORMAL
	DCR	A
	JZ	OTCHR2	; 1-OFFSET BOLD
;
; OTHERWISE: OVERSTRIKE BOLD
;
	POP	AF
	PUSH	AF
	CALL	LOUTX
	MVI	A,BS	; BACKUP
	CALL	LOUTX
; FINAL CHAR
OTCHR1:	POP	AF
	JMP	LOUTX
;
; OFFSET BOLD
;
OTCHR2:	MVI	A,1	; WIDTH = 1/120
	CALL	SET120
	POP	AF		; SEND CHAR
	PUSH	AF
	CALL	LOUTX
	POP	AF
	CALL	LOUTX		; TWICE
	LDA	NORMWD
	DCR	A	; WIDTH =(NORM WIDTH -1)
	CALL	SETWID
	MVI	A,SPC	; ADJUST ADVANCING GAP
	CALL	LOUTX
	LDA	NORMHT	; RESET TO NORMAL
	JMP	SETHGT
;
;  ACTUAL DEVICE OUTPUT
;
LOUTX:	JMP	SPCOUT
;
THINWD:	DW	6	; THIN SPACE WIDTH
BOLDFG:	DW	0	; BOLD FLAG
NORMWD:	DB	6	; NORMAL WIDTH
NORMHT:	DB	6	; NORMAL HEIGHT
;
;
*********** END OF SPINWRT  **************
;
