*---------------------------------------------------------
* Minimal OP-80 Binary Loader
*   Loads a binary image from an OP-80 paper tape reader
*   through port B of an MP-L(A) parallel interface board.
*   The program is loaded in descending order starting
*   at $7FFF and going down in memory. The start of data
*   that should be saved is marked by a $DD byte on the
*   tape. 
*---------------------------------------------------------
MPLSLOT	equ	7		;Set MP-L slot number here

PIABASE	equ	4*MPLSLOT
DATAA	equ	PIABASE+0
CSRA	equ	PIABASE+1
DATAB	equ	PIABASE+2
CSRB	equ	PIABASE+3

SYNC	equ	$DD

	org	0

	ldx	#$8000		;X->start of I/O space	
	ldaa	#$2C		;low going handshake pulse
	staa	CSRB,x		;  with write to PIA port B
	staa	DATAB,x		;reset OP80 RDA flip flop
	
restart	txs			;SP=$7FFF

getOP80	ldaa	CSRB,x		;wait for new byte
	bpl	getOP80

	ldaa	DATAB,x		;get new byte
	psha			;write byte to memory
	staa	DATAB,x		;clear OP80 read flip flop
	cmpa	#SYNC
	beq	restart
	bra	getOP80

	end
