;----------------------------------------------------------------------- 
;
; Bootstrap loader for Altair BASIC 1.0
;
;     BASIC 1.0 assumes an 88-SIO serial port at I/O address 0/1.
;     The SIO board is expected to be rev 0. This loader, however,
;     is for the more common Rev 1 version of the SIO. Of course,
;     the patched version of BASIC 1.0 for the rev 1 SIO board
;     should be the tape that is loaded.
;
;	1) Enter this bootstrap loader at 1800h (014000 octal).
;
;	2) Examine 1800h (014000 octal) on the front panel.
;
;	3) Position the paper tape in the NULL leader and start
;	   the tape reader.
;
;	4) Immediately depress RUN on the front panel.
;
;	5) After the tape finishes reading, STOP-RESET the machine
;	   and then depress RUN. The BASIC initialization dialog is
;	   then displayed on the console.
;
;  Version      Date   		Description
;    1.0    14-Aug-2016	    M. Douglas, Original
;
;    1.1    20-Nov-2017     M. Douglas, Move loader origin to 1800h
;			    to allow more room for trailing tape nulls
;			    before the loader gets over-written.
;
;----------------------------------------------------------------------- 

; Equates

SIOST	equ	00h		;SIO status register
SIODR	equ	01h		;SIO data register

	org	1800h		;location of this loader

; Store bytes in sequentially increasing memory pointed to by HL.
;    If the SYNC byte is detected (6Ah, ends the leader, marks the
;    start of data), HL is reset to zero. This code assumes the
;    leader is less than 255 bytes long.

	mvi	h,0		;HL->where to load binary (L set later)

loop	lxi	sp,stack	;init SP so a RET jumps to loop
	in	SIOST		;get sio status
	rrc			;new byte available?
	rc			;no (jumps back to loop)

	in	SIODR		;get the byte and store in memory
	mov	m,a
	inx	h

	sui	6Ah		;sync byte?
	rnz			;no (jumps back to loop)

	mov	l,a		;restart hl at zero (sync in 1st 256 bytes)
	ret			;jump back to loop

stack	dw	loop		;stack content jumps to loop when RET executed

	end

