;-------------------------------------------------------------------------
;
;  Bootstrap loader for CUTER on cassette tape
;
;  This bootstrap loader loads a relocating loader from the cassette tape 
;  (CUTS) and then jumps to it. The relocating loader then loads CUTER 
;  from the tape into RAM starting at XX00 where XX is the value of the
;  front panel sense switches.
;
;  Set SER4TAP=1 to use the 3P+S serial port for loading instead of the
;  CUTS cassette interface.
;
;  Disassembled by Mike Douglas 9/10/24 from the data shown for the
;  bootstrap loader on page 24 of the SOLOS/CUTER User's Manual.
;
;-------------------------------------------------------------------------
SER4TAP	equ	0		;1=use serial port for the tape port

TAPECTL	set	0FAh		;tape control/status port
TAPEDAT	set	0FBh		;tape data register
TDR	equ	40h		;serial data ready bit mask
TAPE1ON	equ	80h		;bit mask to turn on tape #1

  if SER4TAP
TAPECTL	set	00h		;serial status port
TAPEDAT	set	01h		;serial data register
  endif

	org	0

; Execute this loader at address zero

	lxi	h,TDR		;H=0, L=40h=tape data ready mask
	sphl			;stack grows down from 40h
	mov	b,l		;B=40h
	mov	c,l		;C=40h

	mvi	a,TAPE1ON	;turn on tape #1
	out	TAPECTL

skip64	rst	4		;skip 64 bytes from tape
	dcr	b
	jnz	skip64

wtSync	rst	4		;wait for a 01h (start flag) byte
	dcr	a		
	jnz	wtSync

load	rst	4		;load bytes starting at 40h
	stax	b
	inx	b
	cpi	0DDh		;terminate when a 0DDh is read
	jnz	load

	pchl			;jump to relocating loader at 40h

; RST 4 - read byte from cassette and return in A

	org	4*8		;entry address for RST 4 instruction

tapeIn	in	TAPECTL		;wait for cassette byte
	ana	l		;L=40h which is data ready bit mask
	jz	tapeIn

	in	TAPEDAT		;A=byte from tape
	ret

	end

