;	INFOSOFT FILE TRANSFER PROGRAM
;
;	XFER[/optinßÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿnl()/77 EEH
;	REV 01.12 12/??/80 KRS - STACK FIXES AND OTHER GOODIES
;	REV 02.00 07/??/81 KRS - BLOCK I/O FOR NON-ASCII XFERS
;	REV 02.01 10/18/81 RLR - DIVIDE AND CPM CONVERT
;	REV 02.02 11/15/81 RLR - RE-DO AMB AND MAYBE LOGIC
;	REV 02.02a03/??/82 KRS - Version X.X7 and later
;	REV 02.10 05/26/82 SCJ - Merge 02.02 & 02.02a changes
;	REV 02.11 06/18/82 SCJ - Put /r option back in option table
;		  12/01/82 SCJ Change ICL to reference $:(DCOM)
;	REV 02.12 12/16/82 SCJ - Fix /d bug, misspellings in messages
;
;	######## NOTE THAT MAX FILE SIZE HANDLED IN BLOCK ###### 02.00
;	######## MODE IS 65535 RECORDS (8 MEGABYTE FILE)  ###### 02.00
;
	LST	NASC
;
cpmv	equ	0
	ICL	DF
;
	ifc	cpmv
	nam	CXM212
	elsec
	NAM	MXF212
	endc
;
	ENT	SBUFF,DOS
	ENT	IOSVER,BADFLG,PASS,
	ENT	SWPHX,SWEXIT,SWAMB,SWPRO,SWSTAT,SWASC
	ENT	SWIGNR,SWSTRP,SWTAB,SWFIL		;02.02
	ENT	CNTHI,CNTLO,CNTLN,TABCT			;02.02
	ENT	NECTCM,MORAMB,OFCB,IFCB
	ENT	IFCB,OFCB,IFCB2,OFCB2
;
	EXT	ZOPN,ZNEW,ZCLOS,MOVE,GCHAR,PCHAR,FNAME
	EXT	MEMORY,PFNAM,BINDB,NEGHL,CMPHL,MUL32	;02.00
	EXT	BINH2,BINH4,PRNT,DIV16			;02.00
;
	EXT	DOXOT9,NAXFER,DOXOT2			;02.01
	EXT	SKSPC,TSOPT,ABORT,PNAME,PNAM2,FIOER	;02.01
	EXT	RENAME,REN800,PSTAT,BADLEN		;02.01
	EXT	XOFREC,RECOUT				;02.01
	EXT	DOXFR					;02.02
;
	ifc	cpmv
	ext	namfb
	endc
;
SFCB:	EQU	5CH
EOF	EQU	'Z'-'@'
TAB	EQU	'I'-'@'
DLR	EQU	'$'
LF	EQU	0AH
CR	EQU	0DH
SPC	EQU	20H
;			;02.01 ONLY FOR CPM
CMDNUL	MAC	; TRUE LEN ADR	; FORCE A NUL AT THE END OF THE COMMAND LINE
[	IFC	CPMV
	LXI	H,&1
	MOV	E,M
	MVI	D,0
	DAD	D
	INX	H
	MVI	M,0	; FORCE NUL AT EOL
	ENDC
]
	ICL	$:COPYRT
IDENT:	DB	'InfoSoft '
	ifc	cpmv
	db	'CP/M '
	endc
	DB	'File Transfer (XFER 02.12)'
	DB	CR,LF,DLR
;
	ifc	cpmv
dos:	push	h
	push	d
	push	b
	call	5
	pop	b
	pop	d
	pop	h
	ret
	elsec
DOS:	EQU	5
	endc
;
START:	LHLD	6
	DCX	H
	SPHL		; SET STACK
	SHLD	USTK	; SAVE STACK FOR RESET  	 01.12
	LXI	D,IDENT	; IDENTIFY PROGRAM
	MVI	C,9
	CALL	DOS
;
	ifc	!cpmv
	MVI	C,8DH					;02.00
	CALL	DOS					;02.00
	MOV	A,B		; BLOCK MODE		 02.00
	CPI	2		; EARLIEST VERSION	;02.00
	JLT	OKMEM	; FORCE NO BLOCK		 02.00
	JEQ	YESBLK	; ALL V2'S OK			 02.00
	LXI	H,0421H	; MULTI'S BEFORE 4.21 - NO	 02.00
	MOV	E,C					;02.00
	MOV	D,B					;02.00
	CALL	CMPHL					;02.00
	JLT	OKMEM					;02.00
YESBLK:	LXI	H,MEMORY	; START OF BUFFERS		 02.00
	LXI	D,16384+80+130	; MIN BLOCK SPACE	 02.00
	DAD	D					;02.00
	XCHG						;02.00
	LHLD	6	; MEMORY TOP			 02.00
	CALL	CMPHL	; IF 6/7 < HL, NO		 02.00
	JGE	OKMEM	; SO FORCE OLD MODE		;02.00
	endc
;
	MVI	A,1					;02.00
	STA	IOSVER	; ELSE ALLOW NEW MODE		 02.00
;
; CALCULATE BUFFER SIZE
;
OKMEM:	LHLD	6					;02.00
	XCHG
	LXI	H,MEMORY
	CALL	NEGHL
	DAD	D	; HL:=SPACE LEFT FOR BUFFERS
	LXI	D,-80	; LEAVE ROOM FOR STACK		 01.08
	DAD	D
	MOV	A,H	; A:=PAGES LEFT
	STA	IFCBN	;	OR 2*128 BYTE BUFFERS
	STA	OFCBN
;
	MOV	A,H
	RAR
	PUSH	AF	;(SAVE CY)
	ANI	7FH	; TOP OF 1ST BUFFER IS IN 1ST 32K
	MOV	H,A
	POP	AF
	MVI	A,0
	RAR
	MOV	L,A	; HL:SIZE OF 1 BUFFER
	LXI	D,MEMORY
	DAD	D
	SHLD	OFCBB	; SET START OF OUTPUT BUFFER
	SHLD	TMPB
;
	CMDNUL	80H	;02.01 PUT NUL AT EOL
	LXI	D,81H	; COMMAND LINE-DATA PART	 02.01
	LXI	H,SBUFF					;02.00
	MVI	C,128					;02.00
	CALL	MOVE	; RELOCATED			 02.00
;
; 1ST FCB & DISK MUST BE BLANK
;
	MVI	A,-1
	STA	CONMODE	;02.01 NORMAL IS COMMAND MODE
	LXI	H,SFCB
	MOV	A,M
	ORA	A
	JNZ	DOCMD
	INX	H
	MOV	A,M
	CPI	SPC
	JNZ	DOCMD	; CMD LINE
	XRA	A
	STA	CONMODE	;02.01 FORCE CON MODE
	EJECT
;
;	READ CMD FROM CONSOLE
;
NECTCM: LHLD	USTK	; CRUCIAL TIME - RESET STACK	;01.12
	SPHL						;01.12
	LHLD	TMPB
	SHLD	OFCBB	; RESTORE OBUF
	XRA	A
	STA	PASS	; PASS:=XFER(0)
	LDA	CONMODE	;02.01
	ORA	A
	JNZ	0	; CMD LINE DONE
; READ NEW CMD
	MVI	C,2
	MVI	E,'!'
	CALL	DOS
;
	LXI	D,CBUFF	;02.01
	MVI	C,10
	CALL	DOS	; GET IT
	MVI	C,2
	MVI	E,LF	; FINISH THE JOB
	CALL	DOS
	CMDNUL	CBUFF1	;02.01
	LXI	H,SBUFF	;02.01
	MOV	A,M
	ORA	A
	JZ	0	; CON CMDS DONE(NUL LINE)
;
;	SET PTR PAST OPTIONS
;
; VERIFY/COMPARE IS HANDLED BY 2 PASSES
;   THRU HERE: 0-XFER, 1-COMPARE
;
; NORMALLY ONLY PASS 0 IS DONE
; /C - COMPARE FORCES ONLY PASS 1 TO BE DONE
; /V - DOES BOTH PASSES
;
DOCMD:	LXI	H,SBUFF	;02.01
	CALL	SKSPC
	MOV	A,M
	CPI	'/'
	JNE	DOCMD2
DOCMD1:	INX	H
	MOV	A,M
	CPI	SPC+1	; SKIP PAST OPTIONS
	JGE	DOCMD1
DOCMD2:	CALL	SKSPC
	SHLD	CPTR
;
	XRA	A
	STA	TABCT
	STA	SWAMB	; AMBIGIOUS XFER
;
; PROCESS OPTIONS
;
	LXI	H,OPTAB
NXTOPT:	MOV	B,M
	PUSH	H
	CALL	TSOPT
	POP	H
	INX	H
	MOV	E,M
	INX	H
	MOV	D,M
	INX	H
	STAX	D	; SAVE VALUE
	MOV	A,M
	ORA	A
	JNZ	NXTOPT
;
	LDA	SWFIL
	LXI	H,SWIGNR				;02.00
	ORA	M					;02.00
	LXI	H,SWSTRP
	ORA	M
	MOV	M,A	; STRIP:=STRIP OR FILTER
	LXI	H,SWTAB
	ORA	M
	LXI	H,SWASC	; ASC:=STRIP OR FILTER OR TAB
	ORA	M	; 	OR ASC
	MOV	M,A
	LDA	SWVRFY
	LXI	H,SWCOMP
	MOV	C,M
	ORA	C	; COMPARE:=COMPARE OR VERIFY
	MOV	M,A
;
	MOV	A,C
	ORA	A	; IF COMPARE ONLY (/C)
	JZ	OPTDONE
	MVI	A,1	; THEN PASS:=COMPARE(1)
	STA	PASS
;
	JMP	OPTDONE
	EJECT
;
; OPTION TABLE
;
OPT	MAC
[	DB	'&1'
	DW	&2
]
OPTAB:
	OPT	A,SWASC
	OPT	C,SWCOMP
	OPT	D,SWDEL		;02.00
	OPT	E,SWEXIT
	OPT	F,SWFIL
	OPT	I,SWIGNR
	OPT	M,SWCOND
	OPT	N,SWNEW		;02.00
	OPT	O,SWOLD		;02.00
	OPT	P,SWPRO		;02.00
	OPT	R,SWREAD	;02.11
	OPT	S,SWSTRP
	OPT	T,SWTAB
	OPT	V,SWVRFY
	OPT	X,SWPHX
	OPT	Z,SWSTAT
	DB	0
	EJECT
;
OPTDONE:
	MVI	C,25					;01.09
	CALL	DOS	;GET CURRENT DISK		 01.09
	STA	CURXXX					;01.09
	MVI	C,13					;01.09
	CALL	DOS	;UNLOG ALL			 01.09
	MVI	C,14					;01.09
	LDA	CURXXX	;RESELECT THIS ONE		 01.09
	MOV	E,A					;01.09
	CALL	DOS					;01.09
;
;	SETUP OUTPUT FILE
;
	LHLD	CPTR
	LXI	D,SFCB	; @HL:=VALID CHAR AFTER OPTION
	ifc	cpmv	;02.00
	call	namfb	;02.00
	elsec		;02.00
	MVI	C,86H	;
	CALL	DOS	; PROCESS NAME TO FCB
	endc		;02.00
	PUSH	H	;02.02 SAVE INPUT LINE PTR
    .IF
	LXI	H,SFCB+1;02.02 IF OUT NAME[1]=SPC
	MOV	A,M	;02.02
	CPI	SPC	;02.02 THEN IMPLIED AMBIGIOUS OUTPUT NAME
	CEQ	FILQUE	;02.02	(MATCHES INPUT NAME)
    .ENDIF
	LXI	D,SFCB	;02.02 COPY ORIGINAL INPUT TO SFCB1
	LXI	H,SFCB1	;02.02
	LXI	B,12	;02.02 FOR NON-AMB XFER
	CALL	MOVE	;02.02
;
	POP	H	;02.02 GET INPUT PTR
	CALL	SKSPC
	MOV	A,M
	CPI	'='
	LXI	D,FLERR
	JNZ	ABORT
;
	INX	H
	LXI	D,QFCB	; LEAVE SFCB WITH OUTPUT NAME
	ifc	cpmv	;02.00
	call	namfb	;02.00
	elsec		;02.00
	MVI	C,86H
	CALL	DOS
	endc		;02.00
	SHLD	CPTR	; SAVE CMD LINE PTR
;
	LXI	H,QFCB+1	; TREAT NULL		;01.12
	MOV	A,M		; INPUT FILE 		;01.12
	CPI	SPC		; SPEC THE SAME AS *.*	;01.12
	CEQ	FILQUE		; (ALL FILES)		;02.02
;
	LXI	H,QFCB1
	LXI	D,QFCB	; COPY ORIGINAL FCB TO FCB1
	LXI	B,12	; FOR NON-AMB XFER
	CALL	MOVE
;
; IF AMBIGIOUS FILE NAME THEN
;	THEN SEARCH & REPLACE IN FCB
;
	LXI	H,QFCB+1
	MVI	B,11
TSAMB:	MOV	A,M
	CPI	'?'
	JEQ	FNDAMB
	INX	H
	DCR	B
	JNZ	TSAMB
	JMP	NOAMB
;
FNDAMB:	MVI	A,1
	STA	SWAMB	; FLAG IT
	ifc	cpmv	;02.00
	xra	a	;02.00
	sta	cntamb  ;02.00
	endc		;02.00
;
;	PROCESS NEXT AMBIGIOUS FILE
;
NXTAMB:	SHLD	SAVHL		; STACK			;01.12
	LHLD	USTK		; RESET			;01.12
	SPHL						;01.12
	LHLD	SAVHL					;01.12
	PUSH	H
	LHLD	TMPB
	SHLD	OFCBB	; RESTORE OBUF
	POP	H
	LXI	D,ABUFF
	MVI	C,26
	CALL	DOS	; SET TO AMB SEARCH BUFF
;
      ifc	cpmv	;02.00 
	lxi	b,0ff11h;02.00 CPM MUST START FROM DIR ENTRY 1
lupamb:			;02.00 
	LXI	D,QFCB	;02.02
	CALL	DOS	;02.02
	CPI	-1	;02.02
	jeq	none01	;02.00 
	inr	b	;02.00 
	mov	h,a	;02.00 
	mvi	c,18	;02.00 
	lda	cntamb	;02.00 
	cmp	b	;02.00 
	jne	lupamb	;02.00 
	inr	a	;02.00 
	sta	cntamb	;02.00 
	mov	a,h	;02.00 
	add	a	;02.00 x2
	add	a	;02.00 x4
	add	a	;02.00 x8
	add	a	;02.00 x16
	add	a	;02.00 x32
	mov	c,a	;02.00 
	mvi	b,0	;02.00 
	lxi	h,abuff	;02.00 
	dad	b	;02.00 
	jmp	mvamb	;02.00 
;			;02.00 
cntamb:	db	0	;02.00 
;			;02.00 
none01:			;02.00 
;
      elsec		;02.00 
	LDA	SWAMB		;I/OS PICKS UP WHERE LEFT OFF
	ADI	16	; 17=1ST, 18=NEXT
	MOV	C,A	;
	LXI	D,QFCB
	CALL	DOS
	CPI	-1
	JNE	MVAMB
      endc		;02.00 
;
	LDA	SWAMB
	CPI	1
	JNE	NECTCM		; GO LOOK FOR MORE TO DO 01.12
; IF 1ST ATTEMPT THEN ERROR
	LXI	D,NONFND
	JMP	ABORT
;
NONFND:	DB	'No ambigious files matched',CR,LF,DLR
;
MVAMB:	XCHG
	INX	D	; DE:=FROM NAME
	LXI	H,QFCB1+1
	LXI	B,11
     .DO		;02.01
	LDAX	D	;02.01 MOVE AND CLEAR MSB
	ANI	7FH	;02.01
	MOV	M,A	;02.01
	INX	H	;02.01
	INX	D	;02.01
	DCR	C	;02.01
	JNZ	.DO	;02.01
     .UNTIL		;02.01
	LDA	QFCB
	STA	QFCB1	; USE DISK FROM ORIG
NOAMB:
;02.02 ---- CODE MOVED AND RE-DONE -----------
; SET-UP OUTPUT FILE NAME
; IF X-DISK THEN USE INPUT NAME
;02.02 IF OUTPUT NAME HAS AMB CHARS THEN GET FROM INPUT NAME
;
	LXI	D,SFCB1+1	;02.02 INITIALIZE OUTPUT NAME
	LXI	H,SFCB+1	;02.02 FROM ORIGINAL
	MVI	C,11		;02.02
	CALL	MOVE		;02.02
;
	LXI	H,SFCB+1
	MVI	B,11
	LXI	D,QFCB1+1	;02.02 ALLOW AMB OUTPUT NAME
     .DO
	MOV	A,M	; REPEAT
	CPI	'?'
	JNE	.NEXT	;02.02 IF OUTPUT FILE CHAR='?'
	LDAX	D	;02.02 THEN GET MATCHING INPUT CHAR
	MOV	M,A	;02.02      TO REPLACE '?'
     .NEXT
	INX	D	;02.02 ADV INPUT PTR
	INX	H	; ADV OUTPUT PTR
	DCR	B
	JNZ	.DO	; UNTIL WHOLE NAME
     .UNTIL
;
;  IF PASS =0 THEN CHECK FOR NEW OR OLD FILE ONLY
;
     .IF
	LDA	PASS
	ORA	A
	JNZ	.ENDIF
;			*** MEANINGLESS LOGIC IF A DEVICE
	LDA	SWNEW	; IF "NEW ONLY"
	LXI	H,SWOLD
	ORA	M	; OR "OLD ONLY"
	JZ	.ENDIF	; SEE IF EXISTS BY TRYING TO OPEN!!!
;
	LXI	D,SFCB	;OPEN OLD FILE
	MVI	C,15
	CALL	DOS
     .IF
	CPI	-1
	JNE	.ELSE	;-1==NOT THERE
     .THEN
	LDA	SWOLD	; DOESN'T EXIST - SKIP IF "OLD ONLY"
	LXI	H,OUTNOT
     .ELSE
	LDA	SWNEW	; EXISTS - SKIP OK IF "NEW ONLY"
	LXI	H,OUTISA
     .ENDIF		;A=PROPER FLAG TO CHECK/ HL=FAILS MSG
;
	ORA	A	;IF CASE WAS NOT SET
	JZ	.ENDIF	; 	THEN OK
	LXI	D,QFCB1-2
	CALL	PNAM2	; ELSE GIVE MSG AND SKIP FILE
	JMP	MORAMB
     .ENDIF
;02.02 			------------END OF ADDED CODE -----
;
; PRINT NAME OF FILE A,  BEFORE OPENING ON EVERY TRANSFER
;
	LDA	SWCOND	; LOOK FOR CONDITIONAL FLAG
	ORA	A	; -1 IF FOUND
	JZ	PRTNAM
; IF MAYBE FOUND THEN ASK QUESTION
	LXI	D,QFCB1-2
	LXI	H,TRANS 	; PRINT 'Transfer
	CALL	PNAME
	MVI	C,1
	CALL	DOS
	CPI	3
	JZ	NECTCM		; GO LOOK FOR MORE TO DO 01.12
	PUSH	PSW
	MVI	C,2
	MVI	E,CR
	CALL	DOS
	MVI	E,LF		; PUT OUT CR-LF
	CALL	DOS
	POP	PSW
	ANI	5FH
	CPI	'Y'
	JZ	PRTNAM
	CPI	'R'
	JNZ	MORAMB		; TRY NEXT ONE		 01.12
; OTHERWISE CLEAN THINGS UP AND PROCEED
;
	XRA	A	;02.02
	STA	SWCOND	;02.02 CLEAR COND REQ FLAG
;
PRTNAM:	LXI	D,QFCB1-2
	LDA	PASS
	ORA	A
	LXI	H,VERYMG				;02.00
	JNZ	PRTVER					;02.00
	LXI	H,COPYMG
PRTVER:	CALL	PNAM2					;02.00
	EJECT
;
;	*** OPEN FILES ***
;
	LXI	H,QFCB1
	LXI	D,IFCB
	XRA	A	; USE WHOLE NAME
	CALL	FNAME
	CALL	ZOPN
	JZ	FIOER	; OPEN ERROR
	IFC	!CPMV	;02.01
; IF READ PROTECTED FILE AND READ PROT OPTION:=OFF
	LXI	H,IFCB+2
	CALL	UNRDPT	;02.02a
	JZ	NORDP
	LDA	SWREAD	; AND NOT READ OPTION
	ORA	A
	JNZ	NORDP
		; THEN GIVE MSG & GOTO NEXT FILE
OPENF0:	LXI	D,IFCB
	LXI	H,RDPRTM
	CALL	PNAME
	JMP	MORAMB		; TRY FOR MORE	 	 01.12
NORDP:
	ENDC		;02.01
;
; HANDLE "DELETE BEFORE COPY" SWITCH
;			02.02 RE-WRITTEN
	LDA	PASS
	ORA	A	;PASS<>0 IS A VERIFY
	JNZ	OUTP1
;
	LDA	OFCB
	CPI	-1	; IF DEVICE THEN SKIP
	JEQ	OUTP0
;
	LDA	SWDEL	; IF DELETE THEN DO IT
	ORA	A
	JZ	OUTP0
;
	LXI	D,SFCB
	MVI	C,19
	CALL	DOS	; DELETE OLD FILE
	CPI	-1
	JNZ	OUTP0
;				COULD NOT DELETE
	LXI	D,SFCB	;SEE IF FILE IS STILL THERE
	MVI	C,15	;  BY OPENNING OLD FILE
	CALL	DOS
	CPI	-1
	JNE	REN800	; IT'S THERE - I CAN'T DELETE IT	;02,üÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ¿©©*r!z1z")B
r:*!iiiiiihhQØhRzª¢ÐJbÂHJAbš2IÙ¢B*q’*
¢)2z‘zª¢‚ª hPJbR MS,OFCB
	MVI	A,'$'	; USING TEMP NAME.$$$
	LXI	B,'$$'	
	CALL	FNAME	; SET-UP FILE XFCB
;
	CALL	ZNEW	; OPEN & CREATE OUT FILE
	JZ	FIOER
	JMP	OUTP2
;
OUTP1:	LXI	H,SFCB	; ELSE OUTPUT FOR INPUT
	LXI	D,OFCB
	LDA	SWVRFY	; USE '$$$' ONLY IF COPIED
	ORA	A
	JZ	OUTP3
;
	MVI	A,'$'	; USE TEMP NAME
	LXI	B,'$$'
OUTP3:	CALL	FNAME					;01.10
	CALL	ZOPN
	JZ	FIOER
	IFC	!CPMV	;02.02a
	LDA	SWREAD		; IF NOT /R		;01.12
	ORA	A		; HONOR READ PROT	;01.12
	JZ	OUTP2					;01.12
	LXI	H,OFCB+2				;01.08
	CALL	UNRDPT	;02.02a
	ENDC		;02.02a
	EJECT
;
;  CLEAR COUNTERS FOR XFER
;
OUTP2:
	LXI	H,0	;ZERO
	SHLD	CNTHI	; 32 BIT CHAR COUNT
	SHLD	CNTLO
	SHLD	CNTLN	; 16 BIT LINE COUNT
	SHLD	XOFREC	; BLOCK MODE REC NUMBER	 02.00
	SHLD	RECOUT	; BLOCK MODE REC CNT	 02.00
	XRA	A
	STA	BADFLG	; BAD COMPARE FLAG
;
;  *** XFER DATA ***
;
NXINF:	LDA	SWASC				;02.00
	ORA	A				;02.00
	JNZ	YESASC				;02.00
	LDA	OFCB				;02.00
	CPI	-1	; DEVICE?		 02.00
	JEQ	YESASC				;02.00
	LDA	IFCB				;02.00
	CPI	-1	; DEVICE?		 02.00
	JEQ	YESASC				;02.00
	LDA	IOSVER				;02.00
	ORA	A				;02.00
	JNZ	NONASC				;02.00
;
;  USE ASCII MODE IF NOT A DEVICE AND NOT ASCII
;
YESASC:	CALL	DOXFR				;02.00
	JMP	DOINF
;
; ELSE USE BLOCK MODE
;
NONASC:	CALL	NAXFER				;02.00
	EJECT
;
;	DO NEXT INPUT FILE SETUP
;
DOINF:	LHLD	CPTR
	MOV	A,M
	ORA	A
	JZ	DOCLOS
	INX	H	; SKIP DELIMITER
	CALL	SKSPC
	ORA	A
	JZ	DOCLOS	; NUL -> DONE
;
	LDA	SWAMB
	ORA	A
	LXI	D,ILLAMB	; IF AMB. & APEND
	JNZ	ABORT	; THEN ILLEGAL
;
	LXI	D,QFCB1	; LEAVE SFCB WITH OUTPUT NAME
	ifc	cpmv	;02.00
	call	namfb	;02.00
	elsec		;02.00
	MVI	C,86H
	CALL	DOS
	endc		;02.00
	SHLD	CPTR
	XCHG
	LXI	D,IFCB
	XRA	A	; USE WHOLE NAME
	CALL	FNAME
	CALL	ZOPN
	JZ	FIOER	; OPEN ERROR
	LDA	IFCB
	CPI	-1
	JZ	NXINF	;DEVICE
;
	LXI	D,IFCB
	LDA	PASS					;02.00
	ORA	A					;02.00
	LXI	H,VERYMG				;02.00
	JNZ	PVER01					;02.00
	LXI	H,COPYMG ; TELL WHAT FILES ARE BEING APPENDED
PVER01:	CALL	PNAM2					;02.00
;
	IFC	CPMV	;02.01
	JMP	NXINF	;02.01 CONTINUE
	ELSEC		;02.01
	LXI	H,IFCB+2
	CALL	UNRDPT	;02.02a
	JZ	NXINF	;NOT READ PROTECTED
	LDA	SWREAD
	ORA	A
	JNZ	NXINF	;IGNORE READ PROTECT
	JMP	OPENF0
	ENDC		;02.01
	EJECT
;
;	FINISH OFF WRITING
;
;	DELETE OLD FILE, RENAME NEW:=TEMP FILE
;
DOCLOS:	LDA	PASS
	ORA	A
	JNZ	DOCL0	; IF PASS=0
	LXI	D,OFCB
	CALL	ZCLOS
	JZ	FIOER
;
	LDA	SWCOMP
	ORA	A	; IF VERIFY
	JZ	DOCL4
	MVI	A,1	; THEN DO PASS 1
	STA	PASS	;	(COMPARE)
;
	LDA	SWAMB	; IF NOT AMBIGIOUS FILE
	ORA	A
	JZ	DOCMD	; THEN RE-BUILD CMD LINE
	JMP	PRTNAM	; ELSE JUST RE-OPEN FILE	 02.00
;			SO DON'T FOUL-UP DIR PTR
;
;	NEW FILE FULLY CREATED
;
DOCL0:	LDA	BADFLG	;Q, BAD FLAG
	ORA	A
	JNZ	0	;YES, ABORT
	LDA	IOSVER					;02.00
	ORA	A					;02.00
	JZ	DOCL01	; NOT BLOCK			 02.00
	LDA	SWASC					;02.00
	ORA	A					;02.00
	JZ	DOCL6	; YES BLOCK			 02.00
;
DOCL01:	LXI	D,OFCB	;READ FROM THE OUTPUT AGAIN
	CALL	GCHAR
	JZ	DOCL6	;END OF FILE - GOOD
	MOV	C,A	;SAVE CHARACTER
	LDA	SWASC	;Q, ASCII
	ORA	A
	JZ	BADLEN	;NO, ERROR
	MOV	A,C	;GET CHARACTER
	CPI	1AH	;Q, ASCII END OF FILE
	JNZ	BADLEN	;NO, ERROR
DOCL6:	LDA	SWVRFY	; IF THERE WAS A COPY BEFORE
	ORA	A	;  THE COMPARE, RENAME FILE
	JZ	DOCL5
	CALL	RENAME	;## RENAME FILE
DOCL5:	LXI	H,VERFYM ; ELSE SAY VERIFIED
	Kü?ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿR MSO PRINT STATS
;
DOCL4:	CALL	RENAME	;RENAME FILE
DOCL1:	CALL	PSTAT	;PRINT STATS
;
;
MORAMB:	LXI	H,SWAMB					;01.12
	MOV	A,M	; IF NON-AMBIGIOUS
	ORA	A
	JZ	NECTCM	; THEN NEXT CMD			 01.12
	MVI	M,2		(SEARCH NEXT)
	XRA	A	; ELSE NEXT AMB FILE
	STA	PASS	;   (PASS:=0)
    .IF
	MVI	C,11	;02.02  PROPER PLACE FOR AMBIG ABORT
	CALL	DOS	;02.02
	ORA	A	;02.02		IF A KEY PRESS
	JZ	.ENDIF	;02.02
	MVI	C,1	;02.02	THEN GET IT
	CALL	DOS	;02.02
	CPI	CR	;02.02		CR ==> ABORT
	JEQ	NECTCM	;02.02
    .ENDIF
	LDA	SWCOMP	; IF COMPARE AND NOT VERIFY
	ORA	A
	JZ	NXTAMB	
	LDA	SWVRFY
	ORA	A		; (I.E. NO XFER)
	JNZ	NXTAMB
	MVI	A,1	; THEN PASS 1 ONLY (NOT 0)
	STA	PASS
	JMP	NXTAMB
;
;02.02 FILL FCB (@HL) WITH '?' FOR NAME
;
FILQUE:	MVI	A,'?'		; (ALL FILES)=*.*
	MVI	B,11
     .DO
	MOV	M,A
	INX	H
	DCR	B
	JNZ	.DO
     .UNTIL
	RET
	EJECT
;
	IFC	!CPMV
;		NEW READ PROTECT LOGIC AT VERSION 02.02a
UNRDPT:
	PUSH	B
	MOV	A,M		; GET FIRST BYTE (OLD I/OS)
	ANI	40H		; NON-0 IF RD PROT
	MOV	B,A		; SAVE RESULT
	MOV	A,M
	ANI	3FH		; CLEAR FOR OLD I/OS
	MOV	M,A
	MOV	A,B		; SAVE FIRST RESULT
	LXI	B,8		; INCREMENT TO NEW RD PROT FLAG
	DAD	B
	MOV	B,A		; SAVE OLD RESULT
	MOV	A,M
	ANI	80H		; TEST NEW ONE
	ORA	B		; SET A TO COMPOSITE RESULT
	MOV	B,A		; AND BACK TO B
	MOV	A,M
	ANI	7FH		; CLEAR NEW ONE
	MOV	M,A
	MOV	A,B
	ORA	A		; PASS ORIG STATUS BACK
	POP	B
	RET
	ENDC
;
	EJECT
;
;	MISC:
;
VERFYM:	DB	' compared OK',CR,LF,DLR
BADOTM:	DB	'Illegal output filename',CR,LF,DLR
RDPRTM:	DB	' is read protected',CR,LF,DLR
VERYMG:	DB	'      Verifying $'			;02.00
COPYMG:	DB	'           Copying $'			;02.00
TRANS:	DB	' to be transferred ? $'		;02.12
OUTISA:	DB	'Already exists on output disk: $'	;02.02
OUTNOT:	DB	'Does not exist on output disk: $'	;02.02
FLERR:	DB	'File specification error',CR,LF,DLR
ILLAMB:	DB	'Cannot append to an ambiguous file',CR,LF,DLR	;02.12
;
;
;	BUFFER SIZE IS CALCULATED
;
	RAM
CPTR:	DW	0
TABCT:	DB	0
CNTHI:	DW	0	; CHAR COUNT
CNTLO:	DW	0	; CHAR COUNT
CNTLN:	DW	0	; LINE COUNT
BADFLG:	DB	0	; BAD COMPARE FLAG
CURXXX:	DB	0	; CURRENT DISK ON ENTRY		 01.09
;
;		CBUFF/CBUFF1/SBUFF MUST BE IN SEQUENCE
CBUFF:	DB	127	;CONSOLE INPUT BUFFER		 02.01
CBUFF1:	DB	0	;CONSOLE TRUE LENGTH		 02.01
SBUFF:	DS	127	;COMMAND BUFFER			 02.00
CONMODE:DB	-1	;CONSOLE MODE: 0=YES,NZ=CMD LINE 02.01
;
;  SWITCHES
;
SWASC:	DB	0	;/A@	- ASCII
SWTAB:	DB	0	;/T@	- TAB EXPAND
SWSTRP:	DB	0	;/S@	- STRIP NUL RUBOUTS
SWFIL:	DB	0	;/F@	- FILTER BAD ASCII CHARS
SWIGNR:	DB	0	;/I@	- IGNORE ASCII EOF (^Z)
SWCOMP:	DB	0	;/C	- COMPARE
SWVRFY:	DB	0	;/V	- VERIFY AFTER COPY
SWPHX:	DB	0	:/X	- HEX ADR OF COMPARE FAILURES
SWREAD:	DB	0	;/R	- READ PROTECTED FILES
SWSTAT:	DB	0	;/Z	- DON'T PRINT STATISTICS
SWCOND:	DB	0	;/M	- CONDITIONAL XFER
SWEXIT:	DB	0	;/E	- EXIT ON FAILURE
SWDEL:	DB	0	:/D	- DELETE OLD FILE FIRST
SWNEW:	DB	0	;/N	- COPY ONLY NEW FILES TO DISK
SWOLD:	DB	0	;/O	- COPY ONLY IF ALREADY ON DISK
SWUSR:	DB	0	;/U	- DO NOT COPY 'S' FILES
SWPRO:	DB	0	;/P	- PROCEED ON ERROR
;
;	@ ---> ANY OF THESE FORCE BYTE-BY-BYTE TRANSFER,	 02.00
;	       OTHERWISE DO BLOCK-BY-BLOCK			 02.00
;
SWAMB:	DB	0	; AMBIGIOUS FILES
;
PASS:	DB	0	; PASS: 0=XFER, 1=COMPARE
REST:	DB	0	; AS TO WHETHER TO DO REST OF CONDITIONAL
USTK:	DW	0	; STACK RESET ADDRESS			 01.12
SAVHL:	DW	0	; SAVE HL WORD				 01.12
TMPB:	DW	0	; OUTPUT BUFF ADDR			 01.08
IOSVER:	DB	0	; I/OS - MULTI/OS VERSION		 02.00
;
;	XTENDED FCB'S
;
IFCB:	DB	0,0
IFCB2:	DS	33		;02.01 SYS FCB
	DW	MEMORY,0
IFCBN:	DW	0	; BUFFER SIZE				 01.08
;
OFCB:	DB	0,0
OFCB2:	DS	33		;02.01 SYS FCB
OFCBB:	DW	MEMORY,0
OFCBN:	DW	0	; BUFFER SIZ				 01.08
;
;
QFCB:	DS	33	; FOR NAME BUILDING
QFCB1:	DS	33	; 2ND BUILDER
SFCB1:	DS	33	; ORIGINAL FILENAME
;
ABUFF:	DS	128	; AMBIGIOUS SEARCH BUFFER
;
	END	START
;
