;
;  Disassembly of Cromemco's RDOS 2.52 ROM for the 16FDC Disk Controller
;      it normally resides at C000H to CFFFH
;
        ORG     0C000H
;
CR	EQU	0DH
SPACE	EQU	20H
BS	EQU	08H
ESC	EQU	1BH
squote	equ	27h
msbon	EQU	80H
;
start:	DI
	JR	cldst
;
C003:	JP	C030
	JP	C504
	JP	C037
	JP	C03B
	JP	CB9E
	JP	CD37
	JP	C4D4
	JP	CD52
	JP	C5AB
	JP	seturt	; set up UART
	JP	inchr	; input
	JP	ckinst	; inp. status
	JP	CBEA
	JP	pt7ba	; output
	JP	crlf
;
C030:	LD	(77H),A
	LD	A,B
	JP	C387
;
C037:	LD	(75H),A
	RET
;
C03B:	LD	(76H),A
	RET
;
cldst:	XOR	A	;inhibit 5501 interrupts
	OUT	(3),A
	LD	B,A
	EXX
	CPL		;turn off PerSci and voice
	OUT	(4),A	;    coil options
	LD	A,0D0H
	OUT	(30H),A	;force interrupt on FDC
	LD	HL,2EH
	LD	SP,HL
clp1:	DEC	H
	JR	NZ,clp1
clp2:	LD	(HL),H
	INC	L
	JR	NZ,clp2
	INC	H
	LD	(62H),HL
	LD	(64H),HL
	CALL	seturt
	IN	A,(34H)	; sw 3 set for autoboot?
	AND	40H
	JP	NZ,gomon ; no
getsw:	IN	A,(04H)	;read sense switches
	CPL		;on = 1
	AND	3	;bits 7 & 8 (unused??)
boot:	LD	(77H),A
	CALL	ptfol
        DEFB    'Preparing to boot, ESC to abort'
        DEFB    CR+msbon
	CALL	setsel
	LD	D,A
	OUT	(34H),A
	LD	B,64H
esclp:	CALL	ckesc	; look for escape
	LD	HL,64H
	CALL	dela1
	DJNZ	esclp
	LD	(75H),A
	LD	(7DH),A
	LD	(78H),A
	INC	A
	LD	(76H),A
	CALL	C1F7
	LD	(7EH),A
	LD	HL,80H
	LD	(7BH),HL
	LD	(79H),HL
	LD	A,'B'
	LD	(70H),A
	LD	B,2
C0C8:	PUSH	BC
	CALL	CD37
	CALL	NC,CDCB
	CALL	NC,CD52
	POP	BC
	JR	NC,C0E8
	CALL	ckesc	; look for escape
	DJNZ	C0C8
	CALL	ptfol
	DEFB    CR,'Unable ','t'+msbon
	JR	C115
;
C0E8:	LD	A,(80H)
	CP	40H
	JR	Z,C0F3
	CP	0E5H
	JR	NZ,C0FA
C0F3:	CALL	ptfol
        DEFB    CR,'N'+msbon
    	JR      C115
;
C0FA:	CALL	ckesc	; look for escape
	CALL	setsel
	LD	D,A
	LD	A,(77H)
	EX	AF,AF'
	CALL	ptfol
	DEFB    CR,'Standby',CR+msbon
	SCF
	JP	80H
;
C115:	CALL	ptfol
	DEFB    'o boot',CR+msbon
	LD	A,(71H)
	OR	A
	CALL	NZ,C359
	JR	C131
;
ckesc:	CALL	ckinst
	CALL	NZ,inchr
	CP	esc
	RET	NZ
C131:	LD	A,0D0H	;force FDC interrupt
	OUT	(30H),A
	LD	A,7CH	;select side 1
	OUT	(4),A
gomon:	CALL	ptfol
	DEFB    CR,'Cromemco RDOS 02.52',CR+msbon
C151:	XOR     A
	LD	(6CH),A
inlp:	LD	A,(7EH)
	LD	B,A
	CALL	C1E2
	LD	SP,2EH
	CALL	ptfol
        DEFB    ';'+msbon
	CALL	C7A3
	CALL	loctok
	AND	A
	JR	Z,C151
	CALL	C2C1
	JR	Z,inlp
	LD	A,B
	CP	17H
	JR	NC,inper
	ADD	A,A
	LD	HL,table
	CALL	C186
	LD	A,(HL)
	INC	HL
	LD	H,(HL)
	LD	L,A
	CALL	C1C7   ; go there
	JR	inlp
;
C186:	ADD	A,L
	LD	L,A
	RET	NC
	INC	H
	RET
;
table:  DEFW	CCFD	; Align
	DEFW	C1C8	; Boot
	DEFW	inper	; ?
	DEFW	C72B	; Display
	DEFW	C62A	; Examine
	DEFW	inper	; ?
	DEFW	C1C4	; Go
	DEFW	inper	; ?
	DEFW	C245	; Init
	DEFW	inper	; ?
	DEFW	inper	; ?
	DEFW	C439	; Logged disks
	DEFW	C645	; Move
	DEFW	inper	; ?
	DEFW	C636	; Output
	DEFW	inper	; ?
	DEFW	C6C2	; Query
	DEFW	C516	; Read disk
	DEFW	C67A	; Set
	DEFW	C941	; Test
	DEFW	inper	; ?
	DEFW	C652	; Verify
	DEFW	C51A	; Write disk
;
C1B9:	XOR	A
	LD	(6CH),A
inper:	CALL	ptfol
	DEFB    '?',CR+msbon
	JR	inlp
;
C1C4:	CALL	C853
C1C7:	JP	(HL)
;
C1C8:	CALL	loctok
	OR	A
	JP	Z,getsw
	CP	'E'
	JP	NC,C42A
	SUB	'A'
	JP	C,C42A
	PUSH	AF
	INC	DE
	CALL	fndeol
	POP	AF
	JP	boot
;
C1E2:	LD	A,(6CH)
	OR	A
	RET	Z
	CALL	pt7ba
	BIT	3,B
	RET	NZ
	BIT	7,B
	LD	A,';'
	CALL	NZ,pt7ba
	JP	pt7ba
;
C1F7:	LD	A,D
	OUT	(34H),A
	LD	A,0DFH
	OUT	(4),A
	LD	A,0D4H
	OUT	(30H),A
C202:	IN	A,(34H)
	RRCA
	JR	NC,C202
	IN	A,(30H)
	LD	BC,200H
	CALL	C23B
C20F:	LD	A,0D4H
	OUT	(30H),A
C213:	CALL	C234
	JR	Z,C1F7
	IN	A,(34H)
	RRCA
	JR	NC,C213
	IN	A,(30H)
	DJNZ	C20F
	XOR	A
	OUT	(3),A
	LD	A,C
	CP	'Z'
	JR	NC,C22C
	ADD	A,A
	ADD	A,A
	ADD	A,A
C22C:	CP	0B7H
	LD	A,80H
	RET	NC
	LD	A,4
	RET
;
C234:	IN	A,(3)
	CP	0C7H
	RET	NZ
	INC	C
	RET	Z
C23B:	LD	A,1
	OUT	(3),A
	LD	A,0FAH
	OUT	(5),A
	JR	C234
;
C245:	CALL	fndeol
	CALL	crlf
seturt:	IN	A,(4)	; aux. disk status
	AND	8
	JR	Z,C2AE	; baud rate preset
C251:	LD	A,0AH
	OUT	(2),A	; UART command register
	LD	HL,7D0H
	CALL	dela1
	LD	A,8
	OUT	(2),A
	LD	D,64H
C261:	DEC	D
	JR	Z,C251
C264:	LD	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	LD	HL,64H
	CALL	dela1
	JR	C320
;
C345:	CALL	ptfol
	DEFB    'Can',squote
	DEFB	't read Label',CR+msbon
C359:	LD	E,1
	CALL	C5F2
	CALL	C413
	XOR	A
	RET
;
C363:	LD	BC,10H
	LD	DE,17AH
	CALL	C3EE
	LD	C,1
	CALL	C3EE
	LD	A,(178H)
	CP	'C'
	JR	NZ,C37A
	SET	1,B
C37A:	LD	A,(7EH)
	AND	0CCH
	OR	B
	LD	HL,(6AH)
	LD	(HL),A
C384:	CALL	C3F6
C387:	LD	(7EH),A
	BIT	0,A
	LD	DE,100AH
	LD	HL,200H
	JR	NZ,C3A1
	BIT	1,A
	LD	DE,805H
	JR	NZ,C3A1
C39B:	LD	DE,1A12H
	LD	HL,80H
C3A1:	LD	(79H),HL
	BIT	7,A
	LD	A,'L'
	LD	B,D
	JR	Z,C3AE
	LD	A,squote
	LD	B,E
C3AE:	LD	(6FH),A
	LD	A,B
	LD	(6EH),A
C3B5:	XOR	A
	RET
;
C3B7:	CALL	loctok
	OR	A
	RET	Z
	LD	BC,10H
	CALL	C3DE
	LD	C,1
	CALL	C3DE
	CALL	loctok
	CP	'C'
	JR	NZ,C3D4
	SET	1,B
	INC	DE
	CALL	loctok
C3D4:	OR	A
	JP	NZ,C1B9
	LD	A,B
	LD	(6DH),A
	SCF
	RET
;
C3DE:	CALL	loctok
	INC	DE
	CP	'S'
	RET	Z
	CP	'D'
	JP	NZ,C1B9
C3EA:	LD	A,B
	OR	C
	LD	B,A
	RET
;
C3EE:	LD	A,(DE)
	INC	DE
	INC	DE
	CP	'D'
	RET	NZ
	JR	C3EA
;
C3F6:	LD	A,(6CH)
	SUB	'A'
	LD	(77H),A
	LD	HL,66H
	CALL	C186
	LD	(6AH),HL
	LD	A,(HL)
	OR	A
	RET
;
C40A:	CALL	C5F2
C40D:	CALL	C413
	JP	inlp
;
C413:	CALL	ptfol
	DEFB    ' Err','-'+msbon
	LD	A,(70H)
	CALL	pt7ba
	LD	A,(71H)
	CALL	pspa
	JP	crlf
;
C42A:	CALL	ptfol
	DEFB    'A-D only',CR+msbon
	JP	inlp
;
C439:	CALL	fndeol
	LD	A,(77H)
	PUSH	AF
	LD	A,(6CH)
	PUSH	AF
	LD	A,'A'
C446:	PUSH	AF
	LD	(6CH),A
	CALL	C3F6
	LD	HL,(6AH)
	LD	B,(HL)
	CALL	NZ,C463
	POP	AF
	INC	A
	CP	'E'
	JR	C,C446
	POP	AF
	LD	(6CH),A
	POP	AF
	LD	(77H),A
	RET
;
C463:	CALL	ptfol
	DEFB	' ',SPACE+msbon
	CALL	C1E2
	CALL	ptfol
	DEFB	';',SPACE+msbon
	BIT	3,B
	CALL	NZ,ptspc
	BIT	7,B
	CALL	Z,ptspc
	BIT	4,B
	CALL	C498
	CALL	ptspc
	BIT	0,B
	CALL	C498
	BIT	1,B
	JR	Z,C495
	CALL	ptfol
	DEFB	' Cromi','x'+msbon
C495:	JP	crlf
;
C498:	LD	A,'D'
	JR	NZ,C49E
	LD	A,'S'
C49E:	JP	pt7ba
C4A1:	LD	B,A
	LD	A,(6CH)
	OR	A
	JP	Z,inper
	LD	A,B
	CP	'S'
	JR	Z,C4DA
	CALL	C8B0
C4B1:	JP	C,inper
	PUSH	HL
	CALL	C4E1
	LD	A,'S'
	LD	(70H),A
	POP	HL
	XOR	A
	OR	H
	JP	NZ,inper
	LD	A,(6FH)
	CP	L
	JR	C,C4B1
	LD	A,L
	LD	(75H),A
	CALL	C4D4
	RET	NC
	JP	C40D
;
C4D4:	CALL	C5F8
	JP	CDCB
;
C4DA:	INC	DE
	CALL	C4E1
	JP	CDCB
;
C4E1:	LD	A,(75H)
	LD	(7DH),A
	CALL	C8AD
	RET	C
	XOR	A
	OR	H
C4ED:	JP	NZ,inper
	LD	A,L
	OR	A
	JR	NZ,C4F8
	LD	(78H),A
	RET
;
C4F8:	DEC	A
	JR	NZ,C4ED
	CALL	C3F6
	BIT	4,A
	JR	Z,C508
	LD	A,1
C504:	LD	(78H),A
	RET
;
C508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,(HL)
	CALL	hxpa
	INC	E
	INC	E
	INC	HL
	INC	C
	DJNZ	C76A
C77D:	CALL	C7A0
	LD	A,':'
	CP	E
	JR	NZ,C77D
	POP	DE
	POP	HL
	POP	BC
C788:	LD	A,(HL)
	INC	HL
	CALL	C792
	DJNZ	C788
	JP	crlf
;
C792:	AND	7FH
	CP	7FH
	JR	Z,C79C
	CP	' '
	JR	NC,pt7ba
C79C:	LD	A,'.'
	JR	pt7ba
C7A0:	INC	E
	JR	ptspc
C7A3:	LD	A,'1'
	LD	DE,2EH
	LD	(DE),A
	PUSH	DE
	CALL	CBEA
	EX	(SP),HL
	INC	HL
	LD	B,(HL)
	INC	B
	INC	HL
	PUSH	HL
C7B3:	DEC	B
	JR	Z,C7CD
	LD	A,(HL)
	CALL	lc2uc
	LD	(HL),A
	INC	HL
	CP	'"'
	JR	Z,C7C4
	CP	squote
	JR	NZ,C7B3
C7C4:	DEC	B
	JR	Z,C7CD
	CP	(HL)
	INC	HL
	JR	NZ,C7C4
	JR	C7B3
;
C7CD:	LD	(HL),0
	POP	DE
	POP	HL
	RET
;
lc2uc:	CP	'a'	;switch low. case to u.c.
	RET	C
	CP	'z'+1
	RET	NC
	SUB	' '
	RET
;
pspa:	PUSH	AF	;print space, c(A)
	CALL	ptspc
	POP	AF
	JR	hxpa
;
hxphl:	LD	A,H	;hex print c(HL)
	CALL	hxpa
	LD	A,L
hxpa:	PUSH	AF	;hex print c(A)
	RRA
	RRA
	RRA
	RRA
	CALL	ptchr
	POP	AF
ptchr:	AND	0FH
	CP	0AH
	JR	C,ptnum
	ADD	A,7
ptnum:	ADD	A,'0'
	JR	pt7ba

ptspc:	LD	A,' '
pt7ba:	PUSH	AF	; print 7-bit char.
	AND	7FH
	CALL	CC99
	POP	AF
	RET
;
ptfol:	EX	(SP),HL	; print string
ptchl:	LD	A,(HL)
	INC	HL
	OR	A
	JR	Z,endpts
	CALL	pt7ba
	JP	P,ptchl
endpts:	EX	(SP),HL
	RET
;
loctok:	LD	A,(DE)	; locate next non-blank (DE)
	CP	' '
	RET	NZ
	INC	DE
	JR	loctok
;
rmcom:	CALL	loctok	; remove comma & spaces (DE)
	CP	','
	RET	NZ
	INC	DE
	CALL	loctok
	XOR	A
	RET
;
fndeol:	CALL	loctok
	OR	A
	RET	Z
	JP	inper
;
C82F:	LD	HL,80H
	LD	B,H
	LD	C,L
	CALL	C868
	PUSH	HL
	PUSH	BC
	CALL	rmcom
	CALL	C8AD
	JP	C,inper
	CALL	fndeol
	EX	DE,HL
	POP	BC
	POP	HL
	RET
;
	CALL	C865
	JR	fndeol
;
C84E:	CALL	C868
	JR	fndeol
;
C853:	CALL	C8AD
	JP	C,inper
	JR	fndeol
;
C85B:	PUSH	HL
	CALL	C8AD
	JR	C,C862
	EX	(SP),HL
C862:	POP	HL
	JR	fndeol
;
C865:	SCF
	JR	C869
C868:	OR	A
C869:	EX	AF,AF'
	PUSH	BC
	PUSH	HL
	CALL	C8AD
	JR	NC,C879
	EX	AF,AF'
	JP	C,inper
	EX	AF,AF'
	POP	HL
	JR	C87A
;
C879:	POP	AF
C87A:	CALL	C887
	JR	NC,C885
	EX	AF,AF'
	POP	BC
	RET	NC
	JP	inper
;
C885:	POP	AF
	RET
;
C887:	CALL	rmcom
	LD	A,(DE)
	CP	'S'
	JR	NZ,C890
	INC	DE
C890:	PUSH	HL
	PUSH	AF
	CALL	C8AD
	JR	C,C8A6
	LD	B,H
	LD	C,L
	POP	AF
	POP	HL
	JR	Z,C8A4
	LD	A,C
	SUB	L
	LD	C,A
	LD	A,B
	SBC	A,H
	LD	B,A
	INC	BC
C8A4:	OR	A
	RET
;
C8A6:	POP	AF
	POP	HL
	JP	Z,inper
	SCF
	RET
;
C8AD:	CALL	loctok
C8B0:	CALL	C8E0
	RET	C
	PUSH	DE
C8B5:	INC	DE
	CALL	C8E0
	JR	NC,C8B5
	POP	DE
	CP	'.'
	JR	Z,C8C5
	CALL	C8CA
	AND	A
	RET
;
C8C5:	CALL	C8F4
	AND	A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)
	LD	A,'U'
	LD	(HL),A
	CP	(HL)
	JR	NZ,C996
	CPL
	LD	(HL),A
	CP	(HL)
	JR	Z,C99B
C996:	LD	(HL),B
	LD	A,'X'
	JR	C9A4
;
C99B:	LD	(HL),B
C99C:	INC	HL
	DEC	DE
	LD	A,D
	OR	E
	JR	NZ,C97C
	LD	A,'^'
C9A4:	CALL	pt7ba
	POP	HL
	LD	A,10H
	ADD	A,H
	LD	H,A
	JR	NZ,C975
	CALL	ptfol
	DEFB	CR,'Specify disk (eg, A; or A;; or A;;;)',SPACE+msbon
	CALL	C7A3
	CALL	loctok
	OR	A
	JP	Z,crlf
	CALL	C2C1
	JP	NZ,C1B9
	CALL	ptfol
	DEFB	'Seek tests:',CR+msbon
	LD	B,15H
	LD	HL,sektab
seklp:	IN	A,(31H)
	LD	(7DH),A
	LD	A,(HL)
	PUSH	BC
	PUSH	HL
	CP	0FFH
	JR	NZ,CA35
	CALL	ptfol
	DEFB	SPACE,'Restore',':'+msbon
	CALL	C604
	CALL	CD37
	EX	AF,AF'
	CALL	C61E
	EX	AF,AF'
	JR	CA4C
;
; seek test targets
;
sektab:	DEFB	1,2,3,4,5,0feh
	DEFB	6,7,8,9,0,0feh
	DEFB	27h,0,15h,0,1,0feh
	DEFB	0ffh,0feh
	DEFB	27h
;
CA35:	CP	0FEH
	JR	NZ,CA3F
	CALL	crlf
	OR	A
	JR	CA51
;
CA3F:	LD	(75H),A
	CALL	pspa
	CALL	ptfol
	DEFB	':'+msbon
	CALL	C4D4
CA4C:	PUSH	AF
	CALL	ckcry
	POP	AF
CA51:	POP	HL
	POP	BC
	JP	C,crlf
	INC	HL
	DJNZ	seklp
	CALL	ptfol
	DEFB	CR,'Read/Write tests',CR+msbon
	CALL	CB94
	CALL	CBB0
	JP	C,crlf
	CALL	ptfol
	DEFB	'Write test MAY DESTROY data'
	DEFB	CR,'ESC=abort RETURN=proceed',SPACE+msbon
	CALL	C7A3
	LD	HL,900H
	CALL	setpat
	LD	BC,200H
CABB:	LD	(HL),L
	INC	HL
	DEC	BC
	LD	A,B
	OR	C
	JR	NZ,CABB
	CALL	CBC1
	JR	NC,CB35
CAC7:	CALL	ptfol
	DEFB	'Test failed!',CR
	DEFB    'Disk data a','t'+msbon
	LD	E,1
	CALL	C5DE
	CALL	ptfol
	DEFB	' may have been destroyed'
	DEFB	CR,'Original is located at 0D00','s'+msbon
	LD	HL,(79H)
	CALL	hxphl
	CALL	ptfol
	DEFB	' in memory',CR+msbon
	RET
;
CB35:	LD	HL,0B00H
	CALL	setpat
	CALL	CBB0
	JR	C,CAC7
	CALL	ptfol
	DEFB	'Pattern compare',SPACE+msbon
	LD	BC,(79H)
	LD	DE,900H
	LD	HL,0B00H
CB5D:	LD	A,(DE)
	CP	(HL)
	JR	NZ,CB6A
	INC	DE
	INC	HL
	DEC	BC
	LD	A,B
	OR	C
	JR	NZ,CB5D
	JR	CB6B
;
CB6A:	SCF
CB6B:	CALL	CBD1
	CALL	CB94
	CALL	CBC1
	JP	C,CAC7
	JP	crlf
;
ckcry:	JR	C,ng
	CALL	ptfol
	DEFB	'O','K'+msbon
	RET
;
ng:	CALL	ptfol
	DEFB	'error',SPACE+msbon
	LD	A,(71H)
	CALL	hxpa
	JP	crlf
;
CB94:	CALL	ptfol
	DEFB	'Dat','a'+msbon
	LD	HL,0D00H
CB9E:	LD	(7BH),HL
	RET
;
setpat:	LD	(7BH),HL
	CALL	ptfol
	DEFB	'Patter','n'+msbon
	RET
;
CBB0:	CALL	CBDA
	CALL	ptfol
	DEFB	' read',SPACE+msbon
	CALL	CD52
	JR	CBD1
;
CBC1:	CALL	CBDA
	CALL	ptfol
	DEFB	' write',SPACE+msbon
	CALL	C5AB
CBD1:	PUSH	AF
	CALL	ckcry
	CALL	crlf
	POP	AF
	RET
;
CBDA:	LD	A,squote
	LD	(75H),A
	LD	(7DH),A
	LD	A,1
	LD	(76H),A
	JP	CDCB
CBEA:	PUSH	BC
	PUSH	HL
CBEC:	LD	B,0
	LD	HL,2
	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(75H),A	; seek tests
	LD	(78H),A
	CALL	CF55
	OUT	(34H),A
	CALL	CE25
	JR	C,CD8F
	OUT	(30H),A
CD83:	IN	A,(34H)
	BIT	2,A	; motor timeout
	JR	NZ,CDC4
	RRA		; EOJ?
	JR	NC,CD83	; no
	JP	CE3E	; yes
;
CD8F:	LD	A,0C4H	; read address
	OUT	(30H),A
	CALL	CFD6	; side select
	AND	'W'
	OUT	(4),A
	CALL	dela	; delay??
CD9D:	IN	A,(4)
	AND	'@'	; seek in progress?
	JR	NZ,CDB9
	CALL	CFCF
CDA6:	IN	A,(34H)
	BIT	2,A
	JR	NZ,CDC4
	RRA
	JR	NC,CDA6
	LD	A,0D0H	; force interrupt
	OUT	(30H),A
	SUB	A
	OUT	(31H),A	; track reg.
	JP	CE50
;
CDB9:	IN	A,(34H)
	BIT	2,A
	JR	NZ,CDC4
	RRA
	JR	NC,CD9D
	JR	CD8F
;
CDC4:	LD	A,80H
	LD	(71H),A
	SCF
	RET
;
CDCB:	SUB	A	; seek?
	CALL	CF55
	OUT	(34H),A
	LD	A,(75H)
	OUT	(33H),A
	LD	C,A
	LD	A,(76H)
	OUT	(32H),A
	LD	A,(7DH)
	OUT	(31H),A
	SUB	C
	JP	Z,CFCF
	CALL	CE25
	JR	C,CDF9
	OR	10H
	OUT	(30H),A
CDEE:	IN	A,(34H)
	BIT	2,A
	JR	NZ,CDC4
	RRA
	JR	NC,CDEE
	JR	CE3E
;
CDF9:	CALL	CFD6	;side???
	AND	'O'	;4fh?
	OUT	(4),A
	LD	A,18H	;FDC seek command
	OUT	(30H),A
CE04:	IN	A,(34H)
	BIT	2,A	;motor timeout?
	JR	NZ,CDC4
	RRA
	JR	NC,CE04
	IN	A,(30H)	;read disk status
	LD	L,'2'
CE11:	IN	A,(4)	;read aux disk status
	AND	40h	;seek in progress? PerSci only
	JR	NZ,CE11
	DEC	L
	JR	NZ,CE11
CE1A:	IN	A,(4)
	AND	40h
	JR	NZ,CE1A
	CALL	CFCF
	JR	CE50
;
CE25:	LD	A,(7EH)
	BIT	2,A
	JR	NZ,CE36
	BIT	3,A
	LD	A,0EH
	JR	Z,CE34
	LD	A,0CH
CE34:	AND	A
	RET
;
CE36:	BIT	3,A
	LD	A,0FH
	JR	Z,CE34
	SCF
	RET
;
CE3E:	CALL	CFCF
	LD	HL,64H
	CALL	dela1
	IN	A,(30H)
	LD	(71H),A
	AND	98H
	SCF
	RET	NZ
CE50:	LD	A,(75H)
	LD	(7DH),A
	AND	A
	RET
;
CE58:	CALL	CE8F	; READ
	OUT	(30H),A
CE5D:	IN	A,(34H)	; disk flags
	RRA
	JR	C,CE78	; finished
	INI
	INC	B
	IN	A,(34H)	; disk flags
	RRA
	JR	C,CE78	; finished
	INI
	JP	NZ,CE5D
CE6F:	IN	A,(34H)	; disk flags
	BIT	1,A
	JR	NZ,CE85	; autowait timed out
	RRA
	JR	NC,CE6F
CE78:	CALL	CFCF
	IN	A,(30H)	; disk status
	LD	(71H),A
	AND	9CH	; errors
	RET	Z
	JR	CE8D
;
CE85:	CALL	CFCF	; chg. side if (78)#0
	LD	A,80H
	LD	(71H),A
CE8D:	SCF
	RET
;
CE8F:	CALL	CF40
	LD	D,A
	DI
	CALL	CFC6
	ADD	A,88H
	LD	E,A
	LD	A,D
	OUT	(34H),A	; disk control
	LD	A,E
	RET
;
CE9F:	CALL	dela	; WRITE
	CALL	CF40
	LD	D,A
	DI
	CALL	CFC6
	ADD	A,0A8H
	LD	E,A
	LD	A,D
	OUT	(34H),A
	LD	A,E
	OUT	(30H),A
CEB3:	IN	A,(34H)
	RRA
	JR	C,CECA
	OUTI
	INC	B
	IN	A,(34H)
	RRA
	JR	C,CECA
	OUTI
	JP	NZ,CEB3
CEC5:	IN	A,(34H)
	RRA
	JR	NC,CEC5
CECA:	CALL	CFCF
	CALL	dela
	IN	A,(30H)
	LD	(71H),A
	AND	0FCH
	SCF
	RET	NZ
	AND	A
	LD	A,(7EH)
	BIT	1,A
	RET	Z
	CALL	CF00
	JR	C,CEEF
CEE5:	IN	A,(34H)
	RRA
	JR	C,CEEE
	IN	A,(33H)
	JR	CEE5
CEEE:	INC	E
CEEF:	CALL	CFCF
	IN	A,(30H)
	LD	(71H),A
	AND	9CH
	SCF
	RET	NZ
	LD	A,E
	AND	A
	RET	Z
	SCF
	RET
;
CF00:	CALL	CE8F
	LD	BC,(79H)
	SRL	B
	RR	C
	SRL	B
	RR	C
	LD	B,C
	LD	E,0
	OUT	(30H),A
CF14:	IN	A,(34H)
	RRA
	RET	C
	IN	A,(33H)
	XOR	(HL)
	RET	NZ
	INC	HL
	IN	A,(34H)
	RRA
	RET	C
	IN	A,(33H)
	XOR	(HL)
	RET	NZ
	INC	HL
	IN	A,(34H)
	RRA
	RET	C
	IN	A,(33H)
	XOR	(HL)
	RET	NZ
	INC	HL
	IN	A,(34H)
	RRA
	RET	C
	IN	A,(33H)
	XOR	(HL)
	RET	NZ
	INC	HL
	DJNZ	CF14
CF3A:	IN	A,(34H)
	RRA
	JR	NC,CF3A
	RET
;
CF40:	IN	A,(33H)
	LD	A,80H
	CALL	CF55
	LD	HL,(79H)
	RR	H
	RR	L
	LD	B,L
	LD	C,'3'
	LD	HL,(7BH)
	RET
;
CF55:	LD	C,A
	IN	A,(34H)
	AND	4	; motor timeout
	JR	Z,CF60	; motor on
	SUB	A	; motor off
	LD	(72H),A
CF60:	CALL	setsel
	OUT	(34H),A
	PUSH	AF
	PUSH	HL
	CALL	CFD6
	AND	5FH
	OUT	(4),A
	LD	A,(72H)
	AND	A
	JR	Z,CF95
	LD	HL,190H
	LD	A,(73H)
	CP	B
	JR	NZ,CF98
	LD	A,(74H)
	LD	H,A
	LD	A,(78H)
	LD	(74H),A
	CP	H
	JR	NZ,CF90
	IN	A,(34H)
	AND	' '
	JR	NZ,CF9B
CF90:	CALL	dela
	JR	CF9B
;
CF95:	LD	HL,4E20H
CF98:	CALL	dela1
CF9B:	POP	HL
	LD	A,B
	LD	(73H),A
	LD	A,1
	LD	(72H),A
	POP	AF
	OR	C
	RET
;
setsel:	LD	A,(77H)
	LD	B,A
	INC	B
	SUB	A
	SCF
rotlp:	RLA
	DJNZ	rotlp
	LD	B,A
	LD	A,(7EH)
	BIT	2,A
	JR	Z,notmx
	SET	4,B	;set 'maxi'
notmx:	BIT	0,A
	JR	Z,notdd
	SET	6,B	;set 'double density'
notdd:	LD	A,B
	OR	20H	;set 'motor on'
	RET
;
CFC6:	IN	A,(34H)
	CPL
	AND	' '
	RET	Z
	LD	A,4
	RET
;
CFCF:	CALL	CFD6
	OUT	(4),A	; aux. disk cmd.
	XOR	A
	RET
;
CFD6:	PUSH	BC
	LD	B,7FH	; no action
	LD	A,(78H)
	AND	A
	JR	Z,CFE1
	LD	B,7DH	; opposite side
CFE1:	LD	A,B
	POP	BC
	RET
;
dela:	LD	HL,8
	LD	A,(7EH)
	BIT	2,A
	JR	NZ,dela1
	LD	HL,0CH
dela1:	PUSH	BC
dela2:	DEC	HL
	LD	B,1CH
dela3:	DJNZ	dela3
	NOP
	NOP
	LD	A,L
	OR	H
	JR	NZ,dela2
	POP	BC
	RET
;
	DEFB	0FFH
	END
