; DISK COPY FROM DRIVE 0 TO DRIVE 1

; PROM INTERFACE EQUATES

	ORG	0F809H
DRVINI:	DS	3
SETDRV:	DS	3
SETTRK:	DS	3
SETSEC:	DS	3
SETDMA:	DS	3
READ:	DS	3
WRITE:	DS	3

GETCHR:	DS	3
DSPCHR:	DS	3
DSPMSG:	DS	3
	
; MISC EQUATES

;MON	EQU	40H
NUMTRK	EQU	77
SECTRK1	EQU	27		;SECTORS+1
CR	EQU	0DH
LF	EQU	0AH
LFMSB	EQU	8AH		;LF WITH MSB SET
SPMSB	EQU	0A0H		;SPACE WITH MSB SET

; START OF CODE

	ORG	6000H

START:	CALL	DSPMSG
	DB	"Put source in drive 0, destination in drive 1",CR,LF
	DB	"Ready?",SPMSB
	CALL	GETCHR
	CALL	DSPCHR		
	ORI	20H		;TO LOWER CASE
	CPI	"y"

	PUSH	PSW		;PRESERVE RESULT, SEND CR/LF
	CALL	DSPMSG
	DB	CR,LFMSB
	POP	PSW
	JNZ	MON		;EXIT
	XRA	A		;START ON TRACK 0

; OUTER TRACK LOOP

TRKLP:	CALL	SETTRK
	PUSH	PSW		;SAVE TRACK

	XRA	A		;SOURCE DRIVE 0
	LXI	H,READ		;READ SOURCE
	CALL	XFRTRK
	
	MVI	A,1		;DEST DRIVE 1
	LXI	H,WRITE		;WRITE DEST
	CALL	XFRTRK

	MVI	A,"."		;PACIFIER
	CALL	DSPCHR
	
	POP	PSW		;NEXT TRACK
	INR	A
	CPI	NUMTRK
	JNZ	TRKLP
	
	CALL	DSPMSG
	DB	CR,LF,LF,"Backup Complete",CR,LFMSB
	JMP	MON

; XFRTRK - TRANSFER A TRACK OF SECTORS
	
XFRTRK:	SHLD	DVADDR		;READ OR WRITE
	CALL	SETDRV
	LXI	H,TRKBUF	;TRANSFER BUFFER
	MVI	A,1		;START AT SECTOR 1

XTLOOP:	PUSH	PSW		;SAVE SECTOR
	CALL	SETSEC
	CALL	SETDMA
	CALL	DSKVEC		;READ OR WRITE
	JNZ	ERROR

	POP	PSW		;A=SECTOR	
	ADI	2
	CPI	SECTRK1
	JC	XTLOOP
	RNZ			;EVEN SECTORS DONE, TRACK COMPLETE
	MVI	A,2		;READ EVEN SECTORS
	JMP	XTLOOP

ERROR:	CALL	DSPMSG
	DB	"Disk Error",CR,LFMSB
	JMP	MON
	
; DATA AREA

DSKVEC:	DB	0C3H		;JUMP OPCODE
DVADDR:	DS	2		;ADDRESS TO JUMP TO
TRKBUF:	DS	1		;TRACK BUFFER STARTS HERE

	END
	BEG	START
	RUN	BACK
