;--------------------------------------------------------------------------
;
;	Boot loader for CP/M 2.2b for the North Star Single Density 
;	Controller. This loader is read from sector 4, track 0 into
;	RAM at 2000h, then jumped to at 2004h by the boot ROM. 
;
;	Version History
;
;	Ver	  Date		     Description
;	---	----------	---------------------
;	1.0 	11/15/2015	Original, Mike Douglas
;
;--------------------------------------------------------------------------
;  CPM location equates

	 maclib	cpmsize		;bring in memory and bios size
BIOSBASE equ	(CCPBASE+CCPLEN+BDOSLEN) ;base address of this BIOS

DISKIO	equ	0e91eh		;disk I/O in FDC ROM
UNTRACK	equ	59h		;undefined track number

	org	02000h		;boot ROM puts boot sector here

; Track table as used by ROM. When the boot sector is loaded, 
;   the boot drive track number gets set to zero by the 1st
;   byte here. The current drive in RAM is 1, so we load that
;   same value here.

trktbl	db	0,UNTRACK,UNTRACK
curDrv	db	1		;drive 1 is selected when this loads
	
loadCpm	mvi	a,4		;load four sectors
	lxi	b,0001h		;track 0, drive 1
	lxi	d,0001h		;sector 0, read command
	lxi	h,CCPBASE	;start of CP/M
	call	DISKIO
	jnz	loadCpm	

	mvi	a,5		;load five sectors
	lxi	b,0001h		;track 0, drive 1
	lxi	d,0501h		;sector 5, read command
	lxi	h,CCPBASE+0400h
	call	DISKIO
	jnz	loadCpm

	mvi	a,10		;load ten sectors
	lxi	b,0101h		;track 1, drive 1
	lxi	d,0001h		;sector 0, read command
	lxi	h,CCPBASE+0900h
	call	DISKIO
	jnz	loadCpm

	mvi	a,10		;load ten sectors
	lxi	b,0201h		;track 2, drive 1
	lxi	d,0001h		;sector 0, read command
	lxi	h,CCPBASE+1300h
	call	DISKIO
	jnz	loadCpm
	
	jmp	BIOSBASE	;jump to BIOS cold start entry

	end
