	.title	M9312 'CT' BOOT prom for TA11/TU60 controller

	; This source code is an exact copy of the DEC M9312 23-761A9 boot PROM.
	;
	; This boot PROM is for the TA11 controller with TU60 drives.
	;
	; Multiple units and/or CSR addresses are supported via different entry points.
	;
	; Standard devices are 82S131, Am27S13, 74S571 or other compatible bipolar
	; PROMs with a 512x4 TriState 16pin DIP architecture. This code resides in
	; the low half of the device; the top half is blank and unused.
	;
	; Alternatively, 82S129 compatible 256x4 TriState 16pin DIP devices can be
	; used, as the uppermost address line (hardwired low) is an active low chip
	; select (and will be correctly asserted low).

tacsr	=177500				; std TA11 csrbase

tacs	=+0				; control/status
tadb	=+2				; data buffer

diags	=165564				; console diags phase2 entry

	.asect
	.=173000

	; --------------------------------------------------

start:	.ascii	"TC"			; device code (reversed)

	.word	last-.			; offset to next boot header

dl0n:	sec				; boot std csr, unit zero, no diags
dl0d:	mov	#0,r0			; boot std csr, unit zero, with diags
dlNr:	mov	#tacsr,r1		; boot std csr, unit <R0>
dlNb:	mov	pc,r4			; boot csr <R1>, unit <R0>
	bcc	diag			; br if diags requested
	br	go			; return to (R4)+2 from diags
					; then skip over pseudo reboot vector

	; --------------------------------------------------

	.word	173000			; prom start addess @ 24
	.word	340			; and priority level @ 26

	; --------------------------------------------------

go:	mov	r0,r3			; copy unit number
	bic	#^c1,r3			; mask to 0/1
	swab	r3			; to high byte
	mov	r3,(r1)			; to controller<8>

	mov	r4,r5			; r4=r5=173x20
	bic	#177,r5			; r5=173x00
	add	#table-start,r5		; offset to table start
	mov	#375,r2			; -2 as a byte
	movb	(r5)+,r3		; R3=240

2$:	movb	(r5)+,(r1)		; send 037,015,005,024,224
	bmi	4$			; exit if last command

3$:	bitb	r3,(r1)			; check trreq<7> or ready<5>
	beq	3$			; loop if neither

	incb	r2			; count from -2,-1,0,...,177
	bmi	2$			; loop twice

	movb	tadb(r1),(r2)		; write data byte in buffer
	br	3$			; loop

4$:	tst	(r1)			; check error<15>
	bmi	5$			; br if error

	clr	r2			; point at address zero
	cmpb	r3,(r2)			; check for NOP=240 there
	bne	5$			; br if not, not a boot block

	clr	pc			; jump to bootstrap start

5$:	reset				; reset controller
	jmp	2(r4)			; and retry the boot

	; --------------------------------------------------

diag:	jmp	@#diags			; jump to console diags

	; --------------------------------------------------

table:	.byte	240			; trreq<7>+ready<5> AND NOP
	.byte	037			; ilbs+rewind+go command
	.byte	015			; spaceforwardblock+go command
	.byte	005			; read+go command
	.byte	024			; ilbs+read command
	.byte	224			; ilbs+read command + 200

	.word	0,0,0,0,0,0,0,0		; unused
	.word	0,0,0,0,0,0,0		;

	; --------------------------------------------------

	.=start+176
crc16:	.word	<022763>		; CRC-16 will go here

last:	; next boot prom starts here

	.end
