PAGE	58
	TITLE	'Boot Loader for Cromemco 4FDC/16FDC in 8080 code'
;
LARGESW:	EQU	1		;ONE IF MAXI (8") DRIVE; ZERO FOR 5"
;
MEMSIZE:	EQU	48
BEGINADR	EQU	MEMSIZE*1024-56*128	;START OF CPM
;
CBOOT		EQU	BEGINADR+44*128	;THIS IS THE COLD BOOT
;
		ORG	80H		;Cromemco nFDC boards load boot to 80H not 00H
;
;CROMEMCO 4FDC I/O ASSIGNMENTS
;
CSTATPORT:	EQU	00H
CDATAPORT:	EQU	01H
IMODEPORT:	EQU	02H
IMASKPORT:	EQU	03H
PARLPORT:	EQU	04H
STATPORT:	EQU	30H
TRAKPORT:	EQU	31H
SECTPORT:	EQU	32H
DATAPORT:	EQU	33H
FLAGPORT:	EQU	34H
BANKPORT:	EQU	40H
;
START:	MVI	A,01H
	OUT	BANKPORT
	LXI	H,BEGINADR		;START OF CP/M
	LXI	D,51*256+2		;SECTOR COUNT, FIRST SECTOR
;
;RESTORE TO TRACK ZERO
;
	MVI	A,21H+LARGESW*10H
	OUT	FLAGPORT
	MVI	A,0FH-LARGESW*2
RST0:	OUT	STATPORT
RST1:	IN	FLAGPORT
	RAR
	JNC	RST1
	IN	STATPORT
	ANI	98H
	JNZ	START
;
;READ ONE SECTOR
;
RDI0:	MOV	A,E
	OUT	SECTPORT
	LXI	B,8000H+DATAPORT
	MVI	A,0A1H+LARGESW*10H
	OUT	FLAGPORT
	MVI	A,88H
	OUT	STATPORT
RDI1:	IN	FLAGPORT
	RAR
	JC	RDI3
;	INI
	IN	DATAPORT
	MOV	M,A
	INX	H
	DCR	B
;
	JNZ	RDI1
RDI2:	IN	FLAGPORT
	RAR
	JNC	RDI2
;
;CHECK STATUS AND READY FOR NEXT SECTOR AND TRACK
;
RDI3:	IN	STATPORT
	ANI	9CH
	JNZ	START		;RETRY BOOT IF ERROR
	DCR	D
	JZ	CBOOT		;SEE IF ALL DONE
	INR	E
	MOV	A,E		;INCREMENT SECTOR NUMBER
	CPI	19+LARGESW*8
	JC	RDI0		;JUMP IF NOT END OF TRACK
	MVI	E,1
	MVI	A,5FH-LARGESW*2	;GO TO NEXT TRACK
	JMP	RST0
;
	END