	org	0
;
; Cassette Loader for 4K BASIC Version 4.0
; 
;   ** Set sense switch A12 on (2SIO terminal) **
;   ** Set sense switch A9,A8 on (ACR load) **
;
; H = msb of load address
; L = lsb of load address = length of loader = leader byte

;	lxi	h,00faeh	;4K BASIC V3.2
	lxi	h,00fc2h	;4K BASIC V4.0
;	lxi	h,01fc2h	;8K BASIC v4.0
;	lxi	h,03fc2h	;Extended BASIC V4.0
;	lxi	h,07ec2h	;Extended Disk BASIC v5.0

loop	lxi	sp,stack	;init SP so a RET jumps to loop
	in	06h		;get sio status
	rrc			;new byte available?
	rc			;no (jumps back to loop)
	in	07h		;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

