       1                                	.title	M9312 'DD' BOOT prom for TU58 DECtapeII serial tape controller (REVISED)
       2                                	
       3                                	; This source code is an M9312 boot PROM for the TU58 version 23-765B9.
       4                                	;
       5                                	; This boot PROM is for the TU58 DECtapeII serial tape controller.
       6                                	;
       7                                	; Multiple units and/or CSR addresses are supported via different entry points.
       8                                	;
       9                                	; Standard devices are 82S131, Am27S13, 74S571 or other compatible bipolar
      10                                	; PROMs with a 512x4 TriState 16pin DIP architecture. This code resides in
      11                                	; the low half of the device; the top half is blank and unused.
      12                                	;
      13                                	; Alternatively, 82S129 compatible 256x4 TriState 16pin DIP devices can be
      14                                	; used, as the uppermost address line (hardwired low) is an active low chip
      15                                	; select (and will be correctly asserted low).
      16                                
      17                                
      18                                	;VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
      19                                	;
      20                                	; The original code in 23-765A9 is REALLY BROKEN when it comes to
      21                                	; supporting a non-std CSR other than 776500 in R1 on entry
      22                                	;
      23                                	; All the hard references to:  ddrbuf, ddxcsr, ddxbuf
      24                                	; have been changed to:         2(R1),  4(R1),  6(R1)
      25                                	;
      26                                	; The one reference where 'ddrcsr' might have been used is '(R1)' instead
      27                                	; which is actually correct (but totally inconsistent with other usage).
      28                                	;
      29                                	;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      30                                
      31                                
      32 176500                         ddcsr	=176500				; std TU58 csrbase
      33                                
      34 000000                         ddrcsr	=+0				; receive control
      35 000002                         ddrbuf	=+2				; receive data
      36 000004                         ddxcsr	=+4				; transmit control
      37 000006                         ddxbuf	=+6				; transmit data
      38                                
      39 165564                         diags	=165564				; console diags phase2 entry
      40                                
      41                                	.asect
      42 173000                         	.=173000
      43                                
      44                                	; --------------------------------------------------
      45                                
      46 173000    104     104          start:	.ascii	"DD"			; device code (reversed)
      47                                
      48 173002 000176                  	.word	last-.			; offset to next boot header
      49                                
      50 173004 000261                  dd0n:	sec				; boot std csr, unit zero, no diags
      51 173006 012700  000000          dd0d:	mov	#0,r0			; boot std csr, unit zero, with diags
      52 173012 012701  176500          ddNr:	mov	#ddcsr,r1		; boot std csr, unit <R0>
      53 173016 010704                  ddNb:	mov	pc,r4			; boot csr <R1>, unit <R0>
      54 173020 103055                  	bcc	diag			; br if diags requested
      55 173022 000402                  	br	go			; return to (R4)+2 from diags
      56                                					; then skip over pseudo reboot vector
      57                                
      58                                	; --------------------------------------------------
      59                                
      60 173024 173000                  	.word	173000			; prom start addess @ 24
      61 173026 000340                  	.word	340			; and priority level @ 26
      62                                
      63                                	; --------------------------------------------------
      64                                
      65 173030 012706  002000          go:	mov	#2000,sp		; setup a stack
      66 173034 005004                  	clr	r4			; zap old return address
      67 173036 005261  000004          	inc	ddxcsr(r1)		; set break bit
      68 173042 005003                  	clr	r3			; data 000,000
      69 173044 004767  173120'         	jsr	pc,10$			; transmit a bunch of zero chars
      70 173050 005061  000004          	clr	ddxcsr(r1)		; clear break bit
      71 173054 005761  000002          	tst	ddrbuf(r1)		; read/flush any stale rx char
      72 173060 012703  004004          	mov	#<010*400>+004,r3	; data 010,004
      73 173064 004767  173124'         	jsr	pc,12$			; transmit 004 (init) and 010 (boot)
      74 173070 010003                  	mov	r0,r3			; get unit number
      75 173072 004767  173126'         	jsr	pc,13$			; transmit unit number
      76                                
      77 173076 005003                  	clr	r3			; clear rx buffer ptr
      78 173100 105711                  2$:	tstb	(r1)			; wait for rcv'd char available
      79 173102 100376                  	bpl	2$			; br if not yet
      80 173104 116123  000002          	movb	ddrbuf(r1),(r3)+	; store the char in buffer, bump ptr
      81 173110 022703  001000          	cmp	#1000,r3		; hit end of buffer (512. bytes)?
      82 173114 101371                  	bhi	2$			; br if not yet
      83                                
      84 173116 005007                  	clr	pc			; jump to bootstrap at zero
      85                                
      86 173120 004717                  10$:	jsr	pc,(pc)			; recursive call for char replication
      87 173122 004717                  11$:	jsr	pc,(pc)			; recursive call for char replication
      88 173124 004717                  12$:	jsr	pc,(pc)			; recursive call for char replication
      89 173126 105761  000004          13$:	tstb	ddxcsr(r1)		; wait for xmit buffer available
      90 173132 100375                  	bpl	13$			; br if not yet
      91 173134 110361  000006          	movb	r3,ddxbuf(r1)		; send the char
      92 173140 000303                  	swab	r3			; swap to other char
      93 173142 000207                  	rts	pc			; now recurse or return
      94                                
      95                                	; --------------------------------------------------
      96                                
      97 173144 000261                  dd1n:	sec				; boot std csr, unit one, no diags
      98 173146 012700  000001          dd1d:	mov	#1,r0			; boot std csr, unit one, with diags
      99 173152 000717                  	br	ddNr			; continue
     100                                
     101                                	; --------------------------------------------------
     102                                
     103 173154 000137  165564          diag:	jmp	@#diags			; jump to console diags
     104                                
     105                                	; --------------------------------------------------
     106                                
     107 173160 000000  000000  000000  	.word	0,0,0,0,0,0,0		; unused
         173166 000000  000000  000000  
         173174 000000                  
     108                                
     109                                	; --------------------------------------------------
     110                                
     111 173176                         	.=start+176
     112 173176 046154                  crc16:	.word	<046154>		; CRC-16 will go here
     113                                
     114                                last:	; next boot prom starts here
     115                                
     116                                	.end
     116                                
