;
;	INFOSOFT FILE TRANSFER PROGRAM
;
;	SUBROUTINES 
;
;	02.01 10/18/81 RLR - SPLIT XFER INTO PIECES
;
	NAM	SXF201
	LST	NASC
;
	ENT	DOXOT2,DOXOT5,DOXOT7,DOXOT9
	ENT	PNAME,PNAM2,FIOER,RENAME,REN800
	ENT	PSTAT,BADLEN,VRYFM
	ENT	ABORT,SKSPC,ABORT,TSOPT
;
	EXT	IOSVER					;02.01
	EXT	BADFLG,PASS,				;02.01
	EXT	SWPHX,SWEXIT,SWAMB,SWPRO,SWSTAT,SWASC	;02.01
	EXT	CNTHI,CNTLO,RECOUT,CNTLN		;02.01
	EXT	NECTCM,MORAMB				;02.01
	EXT	SBUFF,OFCB,IFCB,XOFREC			;02.01
;
	EXT	PFNAM,BINDB,CMPHL,MUL32			;02.01
	EXT	BINH2,BINH4,DIV16,MOVE,DOS		;02.01
;
;
SFCB:	EQU	5CH
EOF	EQU	'Z'-'@'
TAB	EQU	'I'-'@'
DLR	EQU	'$'
LF	EQU	0AH
CR	EQU	0DH
SPC	EQU	20H
;
;
	EJECT
;
; TEST OPTIONS IN COMMAND LINE
;
; ENTRY: B=OPTION
; EXIT:	IF FOUND THEN Z & A=-1
;		 ELSE NZ & A=0
;
TSOPT:	LXI	H,SBUFF		;02.01
	CALL	SKSPC
	CPI	'/'
	MVI	A,0
	RNE		; NO OPTIONS
;
TSOPT1:	INX	H	; REPEAT NEXT CHAR
	MOV	A,M
	CMP	B
	MVI	A,-1
	REQ		; UNTIL =OPT
	MOV	A,M
	SUI	20H
	CMP	B
	MVI	A,-1
	REQ		; OR =LOWER CASE OPT
	MOV	A,M
	CPI	SPC+1	; OR <=SPC
	JGE	TSOPT1
	XRA	A
	INR	B
	DCR	B	; (NZ)
	RET
	EJECT
;
;  REPORT ON COMPARE FAILURE
;
DOXOT9:	PUSH	B					;02.00
	LDA	SWPHX
	ORA	A
	JZ	DOXOT5	;DO NOT PRINT ADDRESSES
	LDA	BADFLG	;Q, HAS MESSAGE BEEN PRINTED
	ORA	A
	JNZ	DOXOT6	;YES
	MVI	A,1	;SET FLAG
	STA	BADFLG
	LXI	H,VRYFM
	CALL	PNAME	;PRINT NAME AND MSG
DOXOT6:	LDA	CNTHI	;GET ADDRESS
	LXI	H,HEX090
	CALL	BINH2
	LHLD	CNTLO	;GET ADDRESS
	MOV	B,H
	MOV	C,L
	LXI	H,HEX092
	CALL	BINH4
	POP	B	;GET BYTES
	PUSH	B
	MOV	A,B
	LXI	H,HEX094
	CALL	BINH2
	POP	B
	MOV	A,C
	LXI	H,HEX096
	CALL	BINH2
	LXI	D,HEX090
	MVI	C,9
	CALL	DOS
	RET
;
DOXOT5:	LXI	H,VRYFM	; EXIT ON VERIFY FAIL
DOXOT0:	CALL	PNAME
;
;   GENERAL LOCAL EXIT - ABORT OR ASK OPERATOR
;
DOXOT7:	LDA	SWEXIT
	ORA	A
	JNZ	NECTCM					;02.00
	LDA	SWAMB					;02.00
	ORA	A					;02.00
	JZ	NECTCM					;02.00
	LDA	SWPRO		; AUTO PROCEED?		 02.00
	ORA	A					;02.00
	JNZ	MORAMB					;02.00
;
	LXI	D,SHDWE
	MVI	C,9
	CALL	DOS
	MVI	C,1
	CALL	DOS	; GET CHAR
	CPI	3
	JZ	ABORT
	PUSH	PSW
	MVI	C,2
	MVI	E,CR
	CALL	DOS
	MVI	E,LF
	CALL	DOS
	POP	PSW
	ANI	5FH
	CPI	'Y'	; LOOK FOR NO
	JNZ	NECTCM		; GO LOOK FOR MORE TO DO 01.12
	XRA	A					;01.08
	STA	PASS					;01.08
	STA	BADFLG					;01.08
	JMP	MORAMB	; TRY NEXT			;01.12
;
SHDWE:	DB	'Continue copying ? $'
;
BADLEN:	LXI	H,LENGM	;BAD LENGTH
	JMP	DOXOT0
;
; COUNT CHARS
;
DOXOT2:	LHLD	CNTLO
	LXI	D,1
	DAD	D	; DO THIS TO SET CY
	SHLD	CNTLO
	RNC		; 32 BIT COUNT
	LHLD	CNTHI
	INX	H
	SHLD	CNTHI
;
	RET
	EJECT
;
;	RENAME THE FILE
;
RENAME:	LDA	OFCB
	CPI	-1	; IF DEVICE THEN SKIP
	RZ
;
	LXI	H,OFCB		;02.01
	LXI	D,11		;02.01
	DAD	D		;02.01
	LXI	D,SFCB+9	;FIX FILE TYPE
	MVI	C,3
	CALL	MOVE
;
	LXI	D,SFCB	;OPEN OLD FILE
	MVI	C,15
	CALL	DOS
	CPI	-1
	JZ	REN500	;NOT THERE
	LXI	D,SFCB
	MVI	C,19
	CALL	DOS	; DELETE OLD FILE
	CPI	-1					;01.08
	JZ	REN800	;COULD NOT DELETE
;
REN500:	LXI	D,SFCB
	LXI	H,SFCB+16
	MVI	C,16
	CALL	MOVE	; BUILD RENAME FCB
	LXI	H,SFCB+9
	MVI	M,DLR
	INX	H
	MVI	M,DLR	; NAME.EXT<-NAME.$$$
	INX	H
	MVI	M,DLR
;
	LXI	D,SFCB
	MVI	C,23
	CALL	DOS
	RET
;
REN800:	LXI	D,REN080
	JMP	ABORT
;
REN080:	DB	'Cannot erase old file',CR,LF,DLR
	EJECT
;
;PRINT STATUS FROM TRANSFER
;
PSTAT:	LDA	SWSTAT	; IF STATISTICS
	ORA	A
	JNZ	PST500
	LDA	SWASC					;02.00
	ORA	A					;02.00
	JNZ	PSTAT7					;02.00
	LDA	IOSVER					;02.00
	ORA	A					;02.00
	JZ	PSTAT7					;02.00
	LDA	IFCB					;02.00
	CPI	-1	; IF EITHER INPUT OR		 02.00
	JEQ	PSTAT7	; OUTPUT IS A DEVICE		 02.00
	LDA	OFCB	; THEN THE TRANSFER		 02.00
	CPI	-1	; WAS 'BYTE AT A TIME'		 02.00
	JEQ	PSTAT7	; MODE				 02.00
	LHLD	RECOUT					;02.00
	XCHG						;02.00
	LXI	B,128					;02.00
	CALL	MUL32					;02.00
	SHLD	CNTLO					;02.00
	XCHG						;02.00
	SHLD	CNTHI					;02.00
;
PSTAT7:	LHLD	CNTLO	; THEN PRINT 'K BYTES READ'	 02.00
	LXI	D,-1	; DEC COUNT BY 1
	DAD	D
	XCHG
	LHLD	CNTHI
	JC	PST300
;
	MOV	A,H	; IF COUNT IS ZERO SHOW THEM IT IS
	ORA	L
	JZ	PST450
;
	DCX	H
PST300:	MOV	H,L	; USE MID 2 BYTES
	MOV	L,D	;  ( MAX IS 16 MEG)
;
	MVI	B,2	; HL = # OF 256 BYTE BLOCKS
PST400:	XRA	A	; CLEAR CARRY
	MOV	A,H	; CONVERT TO 1K
	RAR
	MOV	H,A
	MOV	A,L
	RAR
	MOV	L,A
	DCR	B
	JNZ	PST400	; HL=#256'S / 4
;
	INX	H	; ROUND UP
PST450:	LXI	D,CNTCRM
	CALL	PRTVAL
	LDA	SWASC
	ORA	A	; IF ASC
	JNZ	PST451
	LDA	IOSVER				;02.00
	ORA	A				;02.00
	JZ	PST500	; NO MESSAGE!!!		 02.00
;
	LHLD	RECOUT				;02.00
	XCHG					;02.00
	LHLD	XOFREC	; OUTPUT FILE SIZE	 02.00
	CALL	CMPHL				;02.00
	JEQ	PST500				;02.00
	LXI	D,RRECS0			;02.00
	MVI	C,9				;02.00
	CALL	DOS				;02.00
	DCX	H				;02.00
	DCX	H				;02.00
	LXI	D,8				;02.00
	DAD	D				;02.00
	CALL	DIV16				;02.00
	LXI	D,RRECS2			;02.00
	CALL	PRTVAL				;02.00
	JMP	PST500				;02.00
;
PST451:	LXI	D,CNTLNM			;02.00
	LHLD	CNTLN	; THEN PRINT 'LINES READ'
	CALL	PRTVAL
;
PST500:	MVI	C,2
	MVI	E,CR
	CALL	DOS
	MVI	E,LF
	CALL	DOS
	MVI	C,11	; ABORT IF CR PRESSED
	CALL	DOS
	ORA	A
	RZ
	MVI	C,1
	CALL	DOS
	CPI	CR
	JEQ	NECTCM		; GO LOOK FOR MORE TO DO 01.12
	RET
	EJECT
;
;	MISC:
;
VRYFM:	DB	' failed compare',CR,LF,DLR
LENGM:	DB	' had a length compare error',CR,LF,DLR
CNTLNM:	DB	'  lines read',CR,LF,DLR
RRECS0:	DB	'Output file nominal size is ',DLR
RRECS2:	DB	'K bytes',CR,LF,DLR
CNTCRM:	DB	'K bytes read',CR,LF,DLR
;
HEX090:	DB	'xx'
HEX092:	DB	'xxxx  '
HEX094:	DB	'xx '
HEX096:	DB	'xx'
CRLF:	DB	CR,LF,DLR
;
; ABORT ON FATAL ERROR
;
ABORT1:	XCHG
;
ABORT:	MVI	C,9
	CALL	DOS	; TELL UM WHY
	JMP	NECTCM		; GO LOOK FOR MORE TO DO 01.12
	EJECT
;
; PRINT DECIMAL VALUE
;	@DE=MSG, HL=VALUE
;
PRTVAL:	PUSH	D
	MOV	B,H
	MOV	C,L
	LXI	H,NAMBUF
	PUSH	H
	CALL	BINDB
	MVI	M,'$'
	POP	D
	MVI	C,9
	CALL	DOS
	POP	D
	CALL	DOS
	RET
;
;  FATAL I/O ERROR
;
FIOER:	PUSH	H					;01.12
	CALL	PRNAM					;01.12
	POP	H					;01.12
	CALL	PRNAM1					;01.12
	LXI	D,CRLF					;01.12
	MVI	C,9					;01.12
	CALL	DOS					;01.12
	JMP	DOXOT7	;02.01 ASK OPER FOR ACTION
;
;	PRINT FILE NAME & MSG
;		@DE=XFCB,@HL=MSG
;
PNAME:	PUSH	H
	CALL	PRNAM					;01.12
	POP	D					;01.12
	MVI	C,9					;01.12
	JMP	DOS					;01.12
;
PNAM2:	PUSH	D					;02.00
	XCHG						;02.00
	MVI	C,9					;02.00
	CALL	DOS					;02.00
	POP	D					;02.00
	CALL	PRNAM					;02.00
	LXI	D,CRLF					;02.00
	MVI	C,9					;02.00
	JMP	DOS					;02.00
;
PRNAM:	LXI	H,NAMBUF
	CALL	PFNAM
PRNAM1:	MOV	E,M
	MVI	C,2
	CALL	DOS
	INX	H
	MOV	A,M
	CPI	CR					;01.12
	RZ						;01.12
	ORA	A
	JNZ	PRNAM1
	RET
;
;	SKIP TO NEXT NON-SPACE
;
SKSPC:	MOV	A,M
	CPI	SPC
	RNZ		; NON-SPACE/DONE
	INX	H
	JMP	SKSPC
;
NAMBUF:	DS	15	;PRINT NAME BUFFER
;
