
	org	0
;
; 2SIO Loader for MITS Programming System II using the 2nd port
;    on an 88-2SIO (12h/13h)
;
;  ** Set sense switches A15, A11, A10, A9 ON **
;
	mvi	a,3		;reset then init ACIA
	out	12h
	mvi	a,015h		;015h for 8N1, 011h for 8N2
	out	12h

; H = msb of load address
; L = lsb of load address = length of loader = leader byte

	lxi	h,0FAEh		;PS2 same as 4K BASIC V3.2

loop	lxi	sp,stack	;init SP so a RET jumps to loop
	in	12h		;get 2sio status
	rrc			;new byte available?
	rnc			;no (jumps back to loop)
	in	13h		;get the byte
	cmp	l		;new byte = leader byte?
	rz			;yes (jumps back to loop)
	dcr	l		;not leader, decrement address
	mov	m,a		;store the byte (reverse order)
	rnz			;loop until L = 0
	pchl			;jump to code just downloaded

stack	dw	loop
	end

