	TITLE	'8 INCH TO 5 INCH COPY PROGRAM'
NSBOOT	EQU	0E800H
BDOS5	EQU	5H
	ORG	100H
	JMP	START
	ORG	500H
START	LXI	SP,STACK+50
SIGNON1	LXI	D,SIGNON
SIGNON2	CALL	PRINT
	LXI	D,BOOTMSG	;BOOT NORTH STAR DOS?
	CALL	PRINT
	CALL	INPUT
	CPI	'Y'
	JZ	BOOTNS		;BOOT NS DOS
MESS1	LXI	D,DEST		;DESTINATION SYSTEM?
	CALL	PRINT
	CALL	INPUT
	STA	TODOS
	CPI	'5'		;TO NORTH STAR
	JZ	TONS
	CPI	'8'		;TO CP/M
	JZ	TOCPM
	JMP	MESS1
TONS	LXI	D,SRCCPM	;CONFIRM SOURCE ON CPM
	CALL	PRINT
	JMP	MESS4
TOCPM	LXI	D,SRCNS		;CONFIRM SOURCE ON NS
	CALL	PRINT
MESS4	XRA	A		;RESET EOF INDICATOR
	STA	EOF
MESS6	LXI	D,MOUNT		;TYPE MOUNT MESSAGE
	CALL	PRINT		;DONE NOW SO THAT DISKS ARE LOADED
	CALL	INPUT		;WHEN FILE NAMES ARE ENTERED
MESS7	LXI	D,CPMFILE	;GET CPM FILE NAME
	CALL	PRINT
	CALL	INPUT
	CALL	GETFCB		;CREATE FCB
	CALL	OPENCPM
	LXI	D,NSFILE	;GET 5 INCH CPM NAME
	CALL	PRINT
	CALL	INPUT
	CALL	GETFCB5
	CALL 	OPENCPM5
	LDA	TODOS
	CPI	'5'
	JZ	TO5INCH
	JMP	TO8INCH
NSERR	LXI	D,ERRM3
	CALL	PRINT
	JMP	FINISHED
PRINT	PUSH	D
	LXI	D,CRLF
	MVI	C,9
	CALL	BDOS8
	POP	D
PRINT2	MVI	C,9
	CALL	BDOS8
	RET
INPUT	LXI	D,IBUF
	MVI	C,0AH
	CALL	BDOS8
	LDA	IBUF+2
	RET
BDOS8	JMP	05H
BOOTNS	LHLD	06H
	SHLD	BDOS8+1
	JMP	NSBOOT

* COPY FILES FROM 5 INCH TO 8 INCH CPM
TO8INCH	EQU	$
COPY1	LXI	D,CPMBUFF
	MVI	C,1AH		;SET DMA ADDR
	CALL	BDOS5
	LXI	D,FCB5
	MVI	C,14H
	CALL 	BDOS5	;SEQUENTIAL READ FROM 5"
	ORA	A
	JNZ	EOFON8
	LXI	D,CPMBUFF
	MVI	C,1AH
	CALL	BDOS8
	LXI	D,FCB
	MVI	C,15H
	CALL	BDOS8
	ORA	A
	JNZ	EOFON8
	JMP	COPY1
EOFON8	CALL	CLOSECPM
	CALL	CLOSECPM5
	JMP	MESS7

* COPY 8 INCH TO 5 INCH NORTH STAR CPM
TO5INCH	EQU	$
COPY6	LXI	D,CPMBUFF
	MVI	C,1AH
	CALL	BDOS8
	LXI	D,FCB
	MVI	C,14H
	CALL	BDOS8		;READ 8"
	ORA	A
	JNZ	EOFON8
	LXI	D,CPMBUFF
	MVI	C,1AH
	CALL	BDOS5
	LXI	D,FCB5
	MVI	C,15H
	CALL	BDOS5		;WRITE 8"
	ORA	A
	JNZ	EOFON8
	JMP 	COPY6


FINISHED	MVI	C,0	;GO TO CPM
	JMP	BDOS8


CLOSECPM	EQU	$
	LXI	D,FCB
	MVI	C,10H
	CALL	BDOS8		;CLOSE THE FILE
	RET


OPENCPM	LXI	D,FCB
	MVI	C,0FH
	CALL	BDOS8		;OPEN THE FILE
	INR	A
	JNZ	EXISTS		;FILE ALREADY EXISTS
	LDA	TODOS		;FILE DOES NOT EXIST
	CPI	'8'		;THATS OK, IT IS TO CPM
	JZ	MAKEIT		;CREATE A FILE
NOTFND	LXI	D,NOFILE	;NO FILE ERR
	CALL	PRINT
	JMP	FINISHED
MAKEIT	LXI	D,FCB		;CREATE A FILE
	MVI	C,16H		;ON CPM
	CALL	BDOS8
	INR	A
	JZ	CPMERR		;NO ROOM TO CREATE ONE
	RET
EXISTS	LDA	TODOS		;FILE ALREADY EXISTS
	CPI	'5'		;THATS OK BECAUSE COPY IT TO NS
	RZ
	LXI	D,FCB		;COPYING IT TO CPM SO DELETE
	MVI	C,13H		;THE EXISTING FILE AND MAKE
	CALL	BDOS8		;A NEW ONE
	JMP	MAKEIT
GETFCB	LXI	H,IBUF+2	;GET ADDRESS OF INPUT LINE
	LDA	IBUF+1		;GET CHAR CNT FROM INPUT BUFFER
	ORA	A
	JZ	FINISHED	;QUIT IF NO NAME ENTERED
	MOV	B,A
	MVI	C,33
	XRA	A
	LXI	D,FCB		;CLEAR THE FCB
CLEARFCB	STAX	D
	INX	D
	DCR	C
	JNZ	CLEARFCB
	PUSH	H		;SAVE THE POSITION OF THE DRIVE NUMBER
	INX	H		;CHECK FOR A COLON
	MOV	A,M
	CPI	':'
	JNZ	NOCOLON
	POP	H
	MOV	A,M
	ANI	1FH		;CONVERT A=1...P=16
	STA	FCB
	INX	H
	INX	H		;PASS THE COLON
	DCR	B
	DCR	B
	JMP	GETNAME
NOCOLON	POP	H
GETNAME	LXI	D,FCB+1
	MVI	C,11
	MVI	A,20H		;BLANK OUT THE NAME
CLEARNAME	STAX	D
	INX	D
	DCR	C
	JNZ	CLEARNAME
	LXI	D,FCB+1
	MVI	C,8
MOVENAME	MOV	A,M	;MOVE THE NAME TO THE FCB
	CPI	'.'		;LOOK FOR THE PERIOD THAT SEPARATES
	JZ	PERIOD		;THE NAME  FROM THE TYPE
	CALL 	UPPERCASE
	STAX	D
	INX	D
	INX	H
	DCR	B		;DECREASE BYTE CNT IN INPUT BUFFER
	RZ
	DCR	C
	JNZ	MOVENAME
	MOV	A,M
	CPI	'.'
	JZ	PERIOD
	DCR	B
	RZ
	JMP	CPMFILENAME
PERIOD	LXI	D,TYPE
	INX	H
	MVI	C,3
MOVETYPE	MOV	A,M
	CALL	UPPERCASE
	STAX	D
	INX	D
	INX	H
	DCR	B
	RZ
	DCR	C
	JNZ	MOVETYPE
	RET
CPMFILENAME	LXI	D,ERRM4
	CALL	PRINT
	JMP	FINISHED
UPPERCASE	CPI	60H	;CONVERT LOWER TO UPPER CASE
	RC
	SBI	20H
	RET

CLOSECPM5	EQU	$
	LXI	D,FCB5
	MVI	C,10H
	CALL	BDOS5		;CLOSE THE FILE
	RET


OPENCPM5	LXI	D,FCB5
	MVI	C,0FH
	CALL	BDOS5		;OPEN THE FILE
	INR	A
	JNZ	EXISTS5		;FILE ALREADY EXISTS5
	LDA	TODOS		;FILE DOES NOT EXIST
	CPI	'5'		;THATS OK, IT IS TO CPM5
	JZ	MAKEIT5		;CREATE A FILE
NOTFND5	LXI	D,NOFILE	;NO FILE ERR
	CALL	PRINT
	JMP	FINISHED
MAKEIT5	LXI	D,FCB5		;CREATE A FILE
	MVI	C,16H		;ON CPM5
	CALL	BDOS5
	INR	A
	JZ	CPM5ERR		;NO ROOM TO CREATE ONE
	RET
EXISTS5	LDA	TODOS		;FILE ALREADY EXISTS
	CPI	'8'		;THATS OK BECAUSE COPY IT TO NS
	RZ
	LXI	D,FCB5		;COPYING IT TO CPM5 SO DELETE
	MVI	C,13H		;THE EXISTING FILE AND MAKE
	CALL	BDOS5		;A NEW ONE
	JMP	MAKEIT5
GETFCB5	LXI	H,IBUF+2	;GET ADDRESS OF INPUT LINE
	LDA	IBUF+1		;GET CHAR CNT FROM INPUT BUFFER
	ORA	A
	JZ	FINISHED	;QUIT IF NO NAME ENTERED
	MOV	B,A
	MVI	C,33
	XRA	A
	LXI	D,FCB5		;CLEAR THE FCB5
CLEARFCB5	STAX	D
	INX	D
	DCR	C
	JNZ	CLEARFCB5
	PUSH	H		;SAVE THE POSITION OF THE DRIVE NUMBER
	INX	H		;CHECK FOR A COLON
	MOV	A,M
	CPI	':'
	JNZ	NOCOLON5
	POP	H
	MOV	A,M
	ANI	1FH		;CONVERT A=1...P=16
	STA	FCB5
	INX	H
	INX	H		;PASS THE COLON
	DCR	B
	DCR	B
	JMP	GETNAME5
NOCOLON5	POP	H
GETNAME5	LXI	D,FCB5+1
	MVI	C,11
	MVI	A,20H		;BLANK OUT THE NAME
CLEARNAME5	STAX	D
	INX	D
	DCR	C
	JNZ	CLEARNAME5
	LXI	D,FCB5+1
	MVI	C,8
MOVENAME5	MOV	A,M	;MOVE THE NAME TO THE FCB5
	CPI	'.'		;LOOK FOR THE PERIOD5 THAT SEPARATES
	JZ	PERIOD5		;THE NAME  FROM THE TYPE
	CALL 	UPPERCASE
	STAX	D
	INX	D
	INX	H
	DCR	B		;DECREASE BYTE CNT IN INPUT BUFFER
	RZ
	DCR	C
	JNZ	MOVENAME5
	MOV	A,M
	CPI	'.'
	JZ	PERIOD5
	DCR	B
	RZ
	JMP	CPM5FILENAME
PERIOD5	LXI	D,TYPE5
	INX	H
	MVI	C,3
MOVETYPE5	MOV	A,M
	CALL	UPPERCASE
	STAX	D
	INX	D
	INX	H
	DCR	B
	RZ
	DCR	C
	JNZ	MOVETYPE5
	RET
CPM5FILENAME LXI D,ERRM5
	JMP	CPMERR0
CPMERR	LXI	D,ERRM38
	JMP	CPMERR0
CPM5ERR LXI	D,ERRM35
CPMERR0	CALL	PRINT
	JMP	FINISHED
ERRM38	DB	'CPM ERR ON 8 INCH SYSTEM$'
ERRM35	DB	'CPM ERR ON 5 INCH NS SYSTEM$'

CRLF	DB	0DH,0AH,'$'
DEST	DB	'DESTINATION SYSTEM (5/8)? $'
SRCCPM	DB	'COPY FROM 8 INCH (HD) TO 5 INCH NORTH STAR$'
SRCNS	DB	'COPY FROM 5 INCH NORTH STAR TO 8 INCH (OR HARD DISK)$'
ERRM2	DB	'CPM IO ERROR$'
ERRM4	DB	'CPM FILE NAME ERROR$'
ERRM5	DB	'NORTH STAR FILE NAME ERROR$'
ERRM3	DB	'NORTH STAR IO ERROR$'
NOFILE	DB	'FILE NOT FOUND$'
SIGNON	DB	0CH,'INTERCPM REL 1.0 5 INCH TO 8 INCH COPY$'
BOOTMSG	DB	'REBOOT 5 INCH CPM (Y/N)? $'
CPMFILE	DB	'8 INCH FILE NAME? $'
NSFILE	DB	'5 INCH (NS) FILE NAME? $'
MOUNT	DB	'MOUNT DISKETTES AND ENTER RETURN$'
TODOS	DS	1
EOF	DS	1
IBUF	DB	20
	DS	22
FCB	DS	9
TYPE	DS	3
	DS	25
CPMCNT	DS	1
FCB5	DS	9
TYPE5	DS	3
	DS	25
TEMP5	DS	1
CPMADDR	DS	2
TEMP	DS	1
CPMBUFF	EQU	80H
CPM5ADDR	DS	2
CPM5CNT	DS	1
STACK	DS	50
	END	100H
