	NAM	BACKUP
*
* SIMPLE BACKUP FROM DRIVE 0 TO 1
*
	OPT	M		;RUN IN MEMORY
	OPT	NOG		;DON'T EXPAND STRINGS
*
* MONITOR PROM EQUATES
*
INTRPT	EQU	$FFEE		;MONITOR RE-ENTRY POINT
ECHO	EQU	$00F3		;ECHO FLAG
*
* BOOT PROM AND WORKSPACE PROM EQUATES
*
BTPROM	EQU	$FC00		;BOOT AND I/O PROM
WSPROM	EQU	$FD00		;WORKSPACE PROM
WSRAM	EQU	$7FE0		;SHARED PARAMETERS START HERE

INCH	EQU	BTPROM+3	;INPUT CHARACTER ROUTINE
OUTCH	EQU	BTPROM+6	;OUTPUT CHARACTER ROUTINE
XFERTRK	EQU	WSPROM+6 	;TRANSFER A TRACK
DSPMSG	EQU	WSPROM+15	;DISPLAY NULL TERMINATED MESSAGE
*
* 
	ORG 	WSRAM
DRVNUM	RMB	1		;REQUESTED DRIVE IN UPPER 2 BITS 
TRKNUM	RMB	1		;REQUESTED TRACK NUMBER
WRTFLAG	RMB	1		;NON-ZERO IF WRITING
*
* MISC EQUATES
*
NUMTRK	EQU	77		;NUMBER OF TRACKS ON THE DISK
CR	EQU	$0D
LF	EQU	$0A
*
* START OF CDOE
*
	ORG	$5000		;RUN ABOVE EDITOR/ASSEMBLER

	LDS	#STACK
	LDX	#MPROMPT	;PROMPT IF READY
	JSR	DSPMSG

	JSR	INCH		;GET RESPONSE
	JSR	OUTCH		;ECHO
	ANDA	#$DF		;CONVERT TO UPPER CASE
	CMPA	#'Y
	BNE	EXITMON

	CLR	TRKNUM		;START ON TRACK 0
*
* READ/WRITE TRACK LOOP
*
TRKLOOP	CLR	DRVNUM		;SOURCE DRIVE 0
	CLR	WRTFLAG		;READING
	LDX	#TRKBUF		
	JSR	XFERTRK		;READ A TRACK
	BNE	READERR

	LDAA	#$40		;DEST DRIVE 1
	STAA	DRVNUM
	STAA	WRTFLAG		;WRITING
	LDX	#TRKBUF
	JSR	XFERTRK		;WRITE A TRACK
	BNE	WRTERR

	LDAA	#'.		;DISPLAY PACIFIER
	JSR	OUTCH

	INC	TRKNUM		;MOVE TO NEXT TRACK
	LDAA	TRKNUM
	CMPA	#NUMTRK
	BNE	TRKLOOP

	LDX	#MDONE		"FINISHED"
	BRA	MSGEXIT
*
* DISPLAY MESSAGE AND EXIT TO MONITOR
*
READERR	LDX	#MRDERR		;"READ ERROR"
	BRA	MSGEXIT

WRTERR	LDX	#MWRTERR	;"WRITE ERROR"
MSGEXIT	JSR	DSPMSG		;DISPLAY ERROR MESSAGE->X

EXITMON	LDS	#ECHO		;DUPLICATE PROM MONITOR INITIALIZATION
	CLRB			;   OTHER THAN RESETTING THE ACIA
	PSHB
	PSHB
	JMP	INTRPT		;RE-ENTER MONITOR
*
* MESSAGES
*
MPROMPT	FCC	'PUT SOURCE IN DRIVE 0, DESTINATION IN DRIVE 1'
	FCB	CR,LF
	FCC	'READY? '
	FCB	0

MRDERR	FCC	'READ ERROR'
	FCB	0

MWRTERR	FCC	'WRITE ERROR'
	FCB	0

MDONE	FCC	'BACKUP COMPLETE'
	FCB	0
*
* DATA
*
	RMB	31		;32 BYTE STACK
STACK	RMB	1
TRKBUF	EQU	*		;TRACK BUFFER

	END
