;
; SPOOLER LOGIC FOR I/OS
;
; TAKES OUTPUT FILE AND SENDS TO
;  PRINTER USING DELAY TIME FOR KEY IN
;
;	02.25 10/80   KRS CORRECT UFCB USE
;	02.32 11/13/80 RLR ADD ENT SPLFG
;	02.36 12/30/81 RLR - REMOVE UNUSED 'RDUCB,ADUCB'
;	02.38 4/82  KRS REMOVE CRPIM
;
	NAM	SPLCTL
	ENT	SPLCTL	; SYSTEM CALL
	ENT	SPLLST	; SPOOL LOGIC
	ENT	SPLBUF,SPLFCB	; FOR DEB
	ENT	SPLFG	; FLAG FOR SPOOLER
;
	EXT	URREG,SAVAF
	EXT	RDFIL,ZMOVE,MOVE,LRDY,LOUT
;
	icl	pdef		;02.39
	icl	df		;02.39
	df.dos			;02.39
	df.cpu			;02.39
	df.sys			;02.39
;
FCBLEN	EQU	33	; 33 BYTE IN FCB
;
CR	EQU	13
LF	EQU	10
FF	EQU	12
SPC	EQU	20H
TAB	EQU	9	; TAB EXPANSION
EOF	EQU	'Z'-'@'	; EOF CHAR
;
; SPOOL CONTROL
;  FCB IS PASSED TO CALL 85H
;  ALREADY OPENED WITH RECORD CNT=0
;
;  DE=FCB -> TO INITIALIZE SPOOLER
;  DE=0   -> TO DISABLE
;  DE=1   -> GET SPOOLER STATUS
;  DE=2   -> TO PAUSE   * NOT ACTIVE
;  DE=3   ->'TO RESTART	*
;
SPLCTL:	MOV	A,D
	ORA	A
	JNZ	SPLC0
	MOV	A,E
	CPI	40H
	JLT	SPLC1
;	  			INITIALIZE SPOOL
SPLC0:	LXI	H,SPLFCB ; MOVE IN SPOOL FCB
	LXI	B,FCBLEN ; FCB LENGTH
	CALL	MOVE	 ; DE=ORG FCB
;
	XRA	A
	STA	SPLTAB	; ZERO TAB COUNT
	CMA
	STA	SPLFG	; FLAG ACTIVE (-1)
	MVI	A,128
	STA	SPLCNT	; FORCE READ OF BUFFER
	RET
;
; 0 - DISABLE ONLY ACTIVE
;
SPLC1:	ORA	A
	JNZ	SPLC2
; 0- DISABLE
	XRA	A
	STA	SPLFG
	RET
; 1- STATUS
SPLC2:	LDA	SPLFG
	JMP	SAVAF
;
; SPOOL ACTIVE MODULE
;
SPLLST:	LDA	SPLFG
	ORA	A
	RZ		; NOT ACTIVE
;
	CALL	LRDY
	ORA	A
	RZ		 PRINTER NOT READY
;
	PUSH	H
	LDA	SPLCNT
	CPI	128
	JLT	SPLL1
; 
; FILL DATA BUFFER
;
	XRA	A
	STA	SPLCNT	; NEXT READ AT BUFFER CHAR 0
;
	LHLD	URREG
	LXI	B,URDBF	; SAVE USER BUFFER-> DE
	DAD	B
	LXI	B,SPLBUF
	MOV	E,M
	MOV	M,C
	INX	H
	MOV	D,M
	MOV	M,B	; USE SPOOLER BUFFER-> BC
	PUSH	H
	PUSH	D
;
	LHLD	URREG			; 02.25
	LXI	D,URFCB			; 02.25
	DAD	D			; 02.25
	LXI	D,SAVUFB		; 02.25
	LXI	B,FCBLEN	; SAVE	  02.25
	CALL	ZMOVE	; THE USER FCB	  02.25
;
	LXI	D,SPLFCB
	CALL	RDFIL
;
	PUSH	PSW			; 02.29
	LHLD	URREG			; 02.25
	LXI	D,URFCB			; 02.25
	DAD	D			; 02.25
	LXI	D,SAVUFB		; 02.25
	LXI	B,FCBLEN	; RESTORE 02.25
	CALL	MOVE	; THE USER FCB	  02.25
	POP	PSW			; 02.29
;
	POP	D
	POP	H	; RESTORE USER BUFFER
	MOV	M,D
	DCX	H
	MOV	M,E
;
	ORA	A
	JZ	SPLL1
; END OF SPOOLER FILE
SPLEOF:	MVI	A,CR
	CALL	LOUT
	MVI	A,LF
	CALL	LOUT
	MVI	A,FF
	CALL	LOUT
	XRA	A
	STA	SPLFG
	POP	H
	RET
; NOW OUTPUT CHAR
SPLL1:	LXI	H,SPLCNT
	MOV	C,M
	INR	M
	MVI	B,0
	LXI	H,SPLBUF
	DAD	B	; HL:=(SPLCNT)+SPLBUF
	MOV	A,M
	CPI	EOF	; EOF CHAR
	JEQ	SPLEOF
	LXI	H,SPLTAB
;
	CPI	CR
	JNE	SPLL2	; IF RETURN
	MVI	M,0	; ZERO TAB COUNT
;
SPLL2:	CPI	TAB
	JNE	SPLL4
; IF TAB THEN EXPAND
;
SPLL3:	MVI	A,SPC
	CALL	LOUT	; DO SPACE
	INR	M
	MOV	A,M	; UNTIL (SPLTAB MOD 8)=0
	ANI	7
	JNZ	SPLL3
	JMP	SPLL5
;
SPLL4:	PUSH	PSW
	CALL	LOUT
	POP	PSW
	CPI	SPC
	JLT	SPLL5	; IF PRINTING
	INR	M	; THEN COUNT LOCATION
; DID IT...
SPLL5:	POP	H
	RET
;
; SPOOL DATA AREA
;
SPLFG:	DB	0	; SPOOLER STATUS FLAG
;
	RAM
;
SPLCNT:	DS	1	; DATA BUFFER COUNT
SPLTAB:	DS	1	; SPOOL TAB COUNT
SPLFCB:	DS	FCBLEN	; SPOOL FCB 
SPLBUF:	DS	128	; SINGLE DATA BUFFER
SAVUFB:	DS	FCBLEN	; USERS FCB
;
;	END
