;************************************************************************
;    MICRO RESOURCES CP/M 2.2 COLD BOOT LOADER FOR TARBELL CONTROLLER
;************************************************************************
;
;	TRACK ZERO SECTOR 1 COLD BOOT LOADER PROGRAM. THIS PROGRAM IS
;	PLACED INTO RAM AT ADDRESS 0000H BY THE INITIAL MONITOR CP/M
;	LOAD COMMAND.
;
;	 LOAD AS FOLLOWS UTILIZING DDT:-
;
;		ISBOOT56.HEX
;		R900
;
;	COPYRIGHT 1982
;	MICHAEL J. KARAS
;	MICRO RESOURCES
;	These days Mike can be reached at mkaras@carousel-design.com” (March 23, 2009)
;
;
; THIS PROGRAM IS LOADED AT LOCATION ZERO
; BY THE BOOTSTRAP PROGRAM, AND EXECUTED.
; ITS PURPOSE IS TO LOAD AND EXECUTE THE
; CP/M DISK OPERATING SYSTEM AT THE TOP
; OF THE MEMORY IN USE.
;

MSIZE	EQU  60			;MEMORY SIZE IN DECIMAL KILO-BYTES	  

SPT	EQU  26			;NUMBER OF SECTORS PER TRACK.	  
DISK	EQU  0F8H		;DISK PORT BASE ADDRESS.	  
;							  
;
DCOM	EQU  DISK		;COMMAND PORT.
DSTAT	EQU  DISK		;STATUS PORT.
TRACK	EQU  DISK+1		;TRACK PORT.
SECT	EQU  DISK+2		;SECTOR PORT.
DATA	EQU  DISK+3		;DATA PORT.
WAIT	EQU  DISK+4		;WAIT PORT.
DCONT	EQU  DISK+4		;CONTROL PORT.

CBASE	EQU  MSIZE*1024-1C00H	;BIAS FOR LARGER THAN 20K BYTE MEMORY
CPMB	EQU  CBASE		;START OF CP/M.
BOOTE	EQU  CBASE+1600H	;COLD BOOT ENTRY POINT.
NSECTS	EQU  52			;TOTAL SECTORS OF CP/M.
RTCNT	EQU  10			;NUMBER OF RETRYS.

	ORG  00000H		;START OF LOADER.

BOOT:
	MVI  E,RTCNT		;GET RETRY COUNT.
BLOOP:
	LXI  SP,100H		;SET STACK POINTER.
	LXI  H,CPMB		;CP/M STARTS HERE.
	MVI  D,NSECTS		;NUMBER OF SECTORS TO READ.
	MVI  C,2		;SECTOR NUMBER.
RNTRK:
	MVI  B,4		;FOR HEAD LOAD.
	MOV  A,C		;SECTOR IN A.
RNSEC:
	CALL READ		;READ FIRST SECTOR.
	DCR  D			;IF DONE,
	JZ   BOOTE		;GO TO CP/M.
	MVI  B,0		;FOR NO HEAD LOAD.
	INR  C			;INCREMENT TRACK COUNT.
	MOV  A,C		;DONE WITH
	CPI  SPT+1		;THIS TRACK?
	JC   RNSEC		;IF NOT, READ NEXT SECTOR.

	MVI  A,52H		;STEP COMMAND AT 10 MSEC. RATE.
	OUT  DCOM		;ISSUE IT.
	IN   WAIT		;WAIT UNTIL DONE.
	MVI  C,1		;SECTOR NUMBER.
	JMP  RNTRK		;READ NEXT TRACK.

READ:
	OUT  SECT		;SET SECTOR REGISTER.
	CALL CHECK		;CHECK FOR ERROR.
	MVI  A,88H		;COMMAND FOR READ.
	ORA  B			;GET HEAD LOAD BIT.
	OUT  DCOM		;ISSUE COMMAND.
RLOOP:
	IN   WAIT		;WAIT FOR DRQ.
	ORA  A			;SET FLAGS.
	JP   CHECK		;JUMP IF DONE.
	IN   DATA		;READ DATA.
	MOV  M,A		;PUT IN MEMORY.
	INX  H			;INCREMENT POINTER.
	JMP  RLOOP		;LOOP UNTIL DONE.

CHECK:
	IN   DSTAT		;READ STATUS.
	ANI  9DH		;LOOK AT ERROR BITS.
	RZ			;OK IF ZERO.
	DCR  E			;DECREMENT RETRY COUNT.
	JNZ  BLOOP		;TRY AGAIN IF NOT ZERO.
	STA  EC			;SAVE ERROR CODE.
HERE:
	HLT			;ARGHHHH.....HALT
;
;
	ORG  0007DH		;PUT JUMP HERE.

	JMP  BOOT		;JUMP INTO BOOT.
EC:
	END			;END OF BOOT.
;
;
;
;+++...END OF FILE
