//
// simple toggle-in boot loader for TU-58 drv 0
//
// (c) 2012 Diane Neisius. License is GNU GPL, see http//fsf.org for details.
//
// NOTE: the code is somewhat crude and re-uses only few opcodes. This makes
// later toggling-in of the octal code less error-prone. That's my opinion
// about. Of course, the code is longer this way. Feel free to improve ;)
//


ser = 0176500	// serial port 0

init = 04	// RSP init command
boot = 010	// RSP boot command

. = 01000

start:				// register associations below seem to be kind
				// of standard for known bootloaders.
				// So just for the case...
	clr  r0			/ r0 = unit #
	mov  $ser, r1		/ r1 = reciever CSR
	mov  $ser+4, r2		/ r2 = transmitter CSR
				/ r3 = byte count 

// for better readability of the octal code, only r1 is used now...

	mov  $init, 6(r1)	/ send <init>
loop0:
	tst  4(r1)
	beq  loop0
	mov  $init, 6(r1) 	/ send <init> (reinitialize TU-58)
loop1:
	tst  4(r1)
	beq  loop1
	mov  $boot, 6(r1) 	/ send <boot> ...
loop2:
	tst  4(r1)
	beq  loop2
	mov  $0, 6(r1)		/ send ...from drive 0
loop3:
	tst  4(r1)
	beq  loop3

// throw away the <cont> sent by TU-58

cloop:
	tstb (r1)
	beq  cloop
	movb 2(r1), r5

// now wait for TU-58 to send the 512 raw bytes of block 0

	clr  r3			/ r3 = byte count 
rdloop:
	tstb (r1)
	beq  rdloop
	movb 2(r1), (r3)+
	cmp  $512, r3
	bne  rdloop

	clr  pc			/ final jump to the loaded boot block.
				/ at initial test, leave out (do "0G" in ODT)





	

