	NAME	DBSLDR
	TITLE	- JADE DOUBLE D - CP/M 2.2
;*****************************************************
;						     *
;	PROGRAM ID:	DDBIOS LOADER         	     *
;						     *
;	VERSION:	2.2	    RELEASE 2	     *
;						     *
;*****************************************************
;						     *
;	PROPERTY OF:	JADE COMPUTER PRODUCTS	     *
;			4901 W. ROSECRANS BLVD.	     *
;			HAWTHORNE, CALIFORNIA	     *
;			90250,   U.S.A.              *
;						     *
;*****************************************************
; THE BIOS LOADER IS READ INTO THE DCM SECTOR BUFFER *
; AFTER DCM HAS INITIALIZED. THE BIOS LOADER PROGRAM *
; IS THEN  EXECUTED  WHICH READS THE  DDBIOS  MODULE *
; INTO BANK 1.  THE COMMAND BLOCK (IN DCM) IS SET TO *
; INDICATE  DDBIOS  MODULE SIZE AND THE  SYSTEM LOAD *
; ADDRESS.  THE  BIOS LOADER PROGRAM IS GENERATED BY *
; MOVCPM.COM AS THE COLD START LOADER (900-97F HEX). *
; THIS MODULE IS PROVIDED FOR REFERENCE PURPOSES.    *
;*****************************************************
; THE  DDBIOS LOADER IS COMPATABLE WITH  REV B AND C *
; DOUBLE D CONTROLLER BOARDS.  IT IS COMPATABLE WITH *
; FD1791-01 / FD1793-01.  IT WILL ALSO FUNCTION WITH *
; THE CURRENT FD179X-02 SERIES.			     *
;*****************************************************
	EJECT
;*****************************************************
; CONTROLLER PORT ASSIGNMENTS			     *
;*****************************************************

BL$STS	EQU	000H	;BOARD STATUS
BL$CTL	EQU	000H	;BOARD CONTROLS
WD$CMD	EQU	004H	;179X-02 COMMAND REGISTER
WD$STS	EQU	004H	;179X-02 STATUS REGISTER
WD$SEC	EQU	006H	;179X-02 SECTOR REGISTOR
WD$DTA	EQU	007H	;179X-02 DATA REGISTER
XP$MTO	EQU	010H	;MOTOR TIME OUT
XP$MTX	EQU	040H	;MOTOR TIME EXTEND
XP$DSH	EQU	080H	;DATA SYNC HOLD

;*****************************************************
; 179X-02 COMMAND AND MASK.			     *
;*****************************************************

DC$RDS	EQU  10001000B	;READ SECTOR.
DM$RER	EQU  10011100B	;READ ERROR MASK.

;*****************************************************
; SYSTEM ASSIGNMENTS				     *
;*****************************************************

NMBR$K	EQU	20		;SYSTEM SIZE IN K.
LNG$1K	EQU	1024		;TOTAL BYTES IN 1K.
CPM$SZ	EQU	NMBR$K*LNG$1K	;TOTAL SYSTEM BYTES.
BIOS$S	EQU	LNG$1K*3/2	;BIOS ALLOCATED SIZE.
BIOS$A	EQU	CPM$SZ-BIOS$S	;BIOS LOAD ADDRESS.

;*****************************************************
; INTERNAL MEMORY ASSIGNMENTS			     *
;*****************************************************

BANK$0	EQU	1000H		;LOWER BANK ADDRESS.
BANK$L	EQU	0400H		;1K BANK LENGTH.
BANK$1	EQU	BANK$0+BANK$L	;UPPER BANK ADDRESS.
IO$BLK	EQU	BANK$0+0370H	;I/O BLOCK ADDRESS.
CB$STS	EQU	IO$BLK+0007H	;COMMAND STATUS BYTE.
CW$LAD	EQU	IO$BLK+0008H	;BIOS LOAD ADDR LOC.
CW$LNG	EQU	IO$BLK+000AH	;BIOS LOAD LENGTH LOC.
SEC$BF	EQU	BANK$0+0380H	;SECTOR BUFFER AREA.

;*****************************************************
; BIOS PROGRAM LINKAGE.				     *
;*****************************************************

SEC$BG	EQU	4		;FIRST BIOS SECTOR.
SEC$NM	EQU	8		;NUMBER OF SECTORS.
SEC$EX	EQU	SEC$BG+SEC$NM-1	;LAST BIOS SECTOR.

;*****************************************************
	EJECT
;*****************************************************
; ASSEMBLER DIRECTIVES				     *
;*****************************************************

	PSECT	ABS		;ABSOLUTE ADDRESSING.
	ORG	SEC$BF		;PROGRAM START POINT.

;*****************************************************
; INITIALIZE BIOS READ OPERATION		     *
;*****************************************************

BEGIN:	LD	HL,LNG$1K	;BIOS LOAD LENGTH.
	LD	(CW$LNG),HL	;LOAD LENGTH SET.
	LD	HL,BIOS$A	;BIOS SYSTEM ADDR.
	LD	(CW$LAD),HL	;LOAD ADDRESS SET.
	LD	HL,BANK$1	;BIOS LOAD POINT.

;*****************************************************
; SET-UP FOR EACH READ SECTOR COMMAND		     *
;*****************************************************

RD$SEC:	LD	IY,RD$TST	;SET NMI VECTOR.
	LD	A,(SECTOR)	;FIRST BIOS SECTOR.
	XOR	C		;INVERT (1791-01).
	OUT	(WD$SEC),A	;SET 179X-02 SEC REG.
	LD	A,DC$RDS	;READ SECTOR CMND.
	XOR	C		;INVERT (1791-01).
	OUT	(WD$CMD),A	;ISSUE 179X-02 COMMAND.

;*****************************************************
; READ SECTOR OPERATION				     *
;*****************************************************

RD$BYT:	IN	A,(XP$DSH)	;WAIT FOR DATA.
	IN	A,(WD$DTA)	;INPUT INV DATA.
	XOR	C		;INVERT (1791-01).
	LD	(HL),A		;STORE DCM BYTE.
	INC	HL		;INCREMENT POINTER.
	JP	RD$BYT		;REPEAT OPERATION.

;*****************************************************
	EJECT
;*****************************************************
; CHECK READ SECTOR STATUS, REPEAT UNTIL BIOS LOADED *
;*****************************************************

RD$TST:	AND	DM$RER		;TEST FOR ERRORS.
	JR	NZ,ERRORS	;ERROR DETECTED.
	LD	A,(SECTOR)	;GET SECTOR NMBR.
	CP	SEC$EX		;CHECK IF LAST SEC.
	JR	Z,FINISH	;GO IF FINISHED.
	INC	A		;INCREMENT.
	LD	(SECTOR),A	;STORE SECTOR NUMBER.
	JR	RD$SEC		;READ NEXT SECTOR.

;*****************************************************
; READ ERROR HAS BEEN DETECTED			     *
;*****************************************************

ERRORS:	LD	(CB$STS),A	;DISPLAY ERROR STATUS.
	XOR	A		;ZERO  A REGISTER.
	OUT	(BL$CTL),A	;DESELECT DRIVE.
	IN	A,(XP$MTO)	;MOTOR OFF!
	HALT			;TERMINATE.

;*****************************************************
; BIOS SECTOR HAVE BEEN LOADED			     *
;*****************************************************

FINISH:	EI			;ENABLE INTERRUPTS.
	HALT			;SHUTDOWN BOARD.

;*****************************************************
; SECTOR NUMBER STORAGE				     *
;*****************************************************

SECTOR:	DEFB	SEC$BG		;SECTOR COUNTER.

;*****************************************************
	END
    