;****************************************************************
;*								*
;*			   BOOT					*
;*								*
;****************************************************************





;****************************************************************
;*								*
;*		MISCELLAENOUS EQUATES				*
;*								*
;****************************************************************


	ORG	0100H


;****************************************************************
;*								*
;*	BMOVE	BOOT MOVER.  MOVES PRIMARY LOADED IMAGE TO	*
;*		EXECUTION RESTING PLACE.			*
;*								*
;****************************************************************


BMOVE:
	MVI	A,0
	CALL	TRANS
	CALL	ADRCALC
	INX	H		; BUMP TO POINT TO KCBOTE ADDRESS
	MOV	E,M
	INX	H
	MOV	D,M
	XCHG			; BIOS EXECUTE ADDRESS TO [HL]
	MVI	L,0		; ALIGN ON PAGE BOUNDARY
	XCHG			; DESTINATION ADDRESS TO [DE]
	PUSH	D		; SAVE FOR EXCITING CLIMAX

	LXI	B,25		; 25 PHYSICAL BIOS SECTORS

BMOV1:	
	MOV	A,B		; PAGE NUMBER TO [A]
	CALL	TRANS		; GET CORRECT PAGE NUMBER
	CALL	ADRCALC		; CALCULATE ADDRESS
	CALL	MOV100		; MOVE PAGE ([DE] IS BUMPED CORRECTLY)
	INR	B		; BUMP PAGE NUMBER
	DCR	C		; COUNT DOWN
	JNZ	BMOV1		; LOOP TILL DONE
	RET			; BLAST OFF




;****************************************************************
;*								*
;*	ADRCALC	CALCULATE RAM ADDRESS FROM NUMBER IN [A]	*
;*		RETURNS MEMORY ADDRESS IN [HL]			*
;*								*
;****************************************************************


ADRCALC:
	MOV	H,A		; PAGE IN [H]
	MVI	L,0		; 
	RET			; 



	PAGE
;****************************************************************
;*								*
;*	MOV100	MOVES 100 HEX BYTES FROM [HL] TO [DE]		*
;*		PROTECTS AGAINST WRITE INTO MEMORY I/O		*
;*								*
;****************************************************************


MOV100:	PUSH	B
	LXI	B,100H		; 256 BYTES
	CALL	BMOVER
	POP	B
	RET



;****************************************************************
;*								*
;*	BMOVER	MOVES [BC] BYTES FROM [HL] TO [DE]		*
;*		PROTECTS AGAINST WRITE INTO MEMORY I/O		*
;*								*
;****************************************************************


BMOVER:	MOV	A,M		; GET A BYTE
	STAX	D		; STUFF IT
	INX	D		; BUMP POINTERS
	INX	H		; 
	DCX	B		; COUNTDOWN  TO DESTINY
	MOV	A,B		; TEST FOR [BC]=0
	ORA	C		; ANYMORE BYTES TO MOVE??
	JZ	BMV1		; NO, THEN WERE DONE.
	MOV	A,D		; SEE IF DESTINATION IS IN MEMORY MAPPED I/O
	CPI	0FCH		; THIS WOULD BE A BAD THING.
	JNZ	BMOVER		; NOT WRITING INTO I/O, THEN KEEP ON MOVING
BMV1:	RET			; VIOLA





;****************************************************************
;*								*
;*	TRANS	TRANSLATE FROM XLTB				*
;*								*
;****************************************************************


TRANS:	PUSH	H		; SAVE [HL]
	LXI	H,XLTD		; GET BASE ADDRESS
	CALL	OFFSET		; OFFSET INTO TABLE
	MOV	A,M
	POP	H		; RESTORE [HL]
	RET


;****************************************************************
;*								*
;*	OFFSET	OFFSET INTO TABLE				*
;*								*
;****************************************************************


OFFSET:	
	ADD	L		; OFFSET ADDITION
	MOV	L,A		; REPLACE
	RNC			; DONE IF NO CARRY
	INR	H		; BUMP PAGE IF CARRY
	RET


XLTB:
	DB	 1, 4, 7,10,13,16,19
	DB	22,25, 2, 5, 8,11,14
	DB	17,20,23,26, 3, 6, 9
	DB	12,15,18,21,24

XLTD:	DB	 10,19, 2,11,20, 3,12,21
	DB	 4,13,22, 5,14,23, 6,15,24
	DB	 7,16,25, 8,17,26, 9,18
	DB	 1
