ROMSEL	EQU	11H
STACK	EQU	0F700H
BDOS	EQU	0005H
STROUT	EQU	09H
KEYIN	EQU	01H
CINP	EQU	06H

BELL	EQU	07H
KEYCOM	EQU	41H

IFSEL	EQU	30H
PORTA	EQU	30H
PORTB	EQU	31H
PORTC	EQU	32H
STATUS	EQU	33H

INI	EQU	8BH
MOTORON	EQU	00000001B
MOTOROFF EQU	00000000B
SIDEA	EQU	00000010B
SIDEB	EQU	00000000B
DIRIN	EQU	00000100B
DIROUT	EQU	00000000B
STEP1ON EQU	08H
STEP1OF EQU	00H
STEP2ON EQU	10H
STEP2OF EQU	00H
WRGONB	EQU	80H
WRGOFF  EQU	00H

INDEX1	EQU	00000001B
INDEX2  EQU	00000010B
TR0A	EQU	00000100B
TR0B	EQU	00001000B
READYA  EQU	00010000B
READYB	EQU	00100000B
READYAB EQU     READYA+READYB
WRPROT  EQU	01000000B

ORG	100H

ENTRY:
	DI
	LXI	SP,STACK
	MVI	A,INI
	OUT	STATUS
	MVI	A,MOTOROFF+SIDEA+DIRIN+STEP1OF+STEP2OF+WRGOFF
	OUT	PORTA

	MVI	C,STROUT
	LXI	D,M1
	CALL	BDOS
D0:
	MVI	C,KEYIN
	CALL	BDOS
	ANI	07FH
	MOV	B,A
	CPI	30H
	MVI	A,44
	JZ	D1
	MOV	A,B
	CPI	31H
	MVI	A,88
	JNZ	D0

D1:
	STA	TPI

	MVI	A,INI
	OUT	STATUS



	MVI	A,MOTORON+SIDEA+DIROUT+STEP1OF+STEP2OF+WRGOFF
	OUT	PORTA
D2:
	LXI	H,0FFFFH
	CALL	WAIT
	IN	PORTB
	ANI	READYAB
	JNZ	D2



D3:
	IN	PORTB
	ANI	TR0A
	JZ	D4
	MVI	A,MOTORON+SIDEA+DIROUT+STEP1ON+STEP2OF+WRGOFF
	OUT	PORTA
	NOP
	NOP
	MVI	A,MOTORON+SIDEA+DIROUT+STEP1OF+STEP2OF+WRGOFF
	OUT	PORTA
	LXI	H,1500
	CALL	WAIT
	JMP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DEX:
	IN	PORTB
	ANI	INDEX1
	JNZ	INDEX
	MVI	B,100
IND1:
	IN	PORTB
	ANI	INDEX1+INDEX2
	RZ
	DCR	B
	JNZ	IND1
	MVI	C,STROUT
	LXI	D,M3
	CALL	BDOS
	LXI	H,1000
	CALL	WAIT
	JMP	INDEX

TPI:	DB	00H

M1:	DB	26
	DB	'PHYSICAL COPY',13,10
	DB	'SOURCE DISK IN DRIVE A',13,10
	DB	'DESTINATION DISK IN DRIVE B',13,10,13,10
	DB	'0 = 48 TPI DISK',13,10
	DB	'1 = 96 TPI DISK',13,10
	DB	'$'

M2:	DB	26
	DB	'COPY COMPLETE',13,10,13,10
	DB	'0 = EXIT COPY PROGRAM',13,10
	DB	'1 = COPY ANOTHER DISK',13,10
	DB	'$'

M3:	DB	'*'
	DB	'$'

END
