;--------------------------------------------------------------------------
;
; BINLOAD.ASM (for Polymorphic computers)
;
;    Loads a ready to execute binary file through the printer serial
;    port into RAM at 3200h.
;
;    Press CTRL-Z to enter the front panel mode and type the bytes of
;    this program in at 8000h (L8000<CR> then type in each byte in hex
;    with a space between each byte). Execute the loader by jumping to it
;    (SPJ8000<CR>G). Send the file in 8 bit binary mode from the PC. Reset
;    the computer and then re-enter front panel mode by pressing CTRL-Z.
;    Jump to the loaded program at 3200h (SPJ3200<CR>G).
;
;    Version History
;
;    1.0  12/15/17   M. Douglas
;
;--------------------------------------------------------------------------

RUNADDR	equ	8000h		;where this program loads
LOADADR	equ	3200h		;where payload is placed

SIODR	equ	00h		;8251 data register
SIOCR	equ	01h		;8251 control register
SIORDA	equ	02h		;receive data available mask

SETUP	equ	02ADh		;setup 8251 from table (in Poly ROM)
	
	org	RUNADDR

	call	SETUP		;setup 8251 from following table 
	db	01Fh		;device 1 (printer port), 9600 baud
	db	0AAh		;fake sync character
	db	040h		;reset gets us to mode level
	db	04Eh		;mode async, 8N1, 16x
	db	000h		;command: idle, also end of table

	di			;disable interrupts

	mvi	a,26h		;A=enable UART receive
	out	SIOCR

	lxi	h,LOADADR	;HL->where to put received program

loop	in	SIOCR		;A=serial status register
	ani	SIORDA		;byte received?
	jz	loop		;no, keep waiting

	in	SIODR		;A=byte received
	mov	m,a		;store in memory
	inx	h		;bump address
	jmp	loop		;repeat

	end
