Tape drive specs
reading speed:		6000 words/second
traveling speed:	12000 words/second
buffer:			32 words in, 32 words out

Tape specs:
size:			1024*256 words of data


GUI:

upper text field	displays the current tape
lower text field	for entering what new tape you want to insert
eject button		will eject the current tape from the tape drive
rename			will rename the current tape to the text in the lower text field
save			will store the currently inserted tape
new			will insert an empty tape into the tape drive



Tape layout:

0:			Unused
1:			if not 4711, the tape drive will assume the tape is invalid and refuse to read/write to it
2:			if not zero the tape will be in a read-only state. The tape will have to be ejected and reinserted before the tape drive recognises that this flag has changed.
3:			the default bootloader uses this address as a pointer to the program to load from the tape. (note: the bootloader assumes the two first words where this is pointing to be the address to load the program at and the length of the program, respectively)
4-7:			reserved			
8+:			free space


Associated memory addresses
Address:	Label:				Verbose:

64		GLOBAL_TAPE_OUT			contents of this register are sent to the tape drive, the output buffer
65		GLOBAL_TAPE_IN			this register contains data sent from the tape drive, the input buffer
66		GLOBAL_TAPE_STATUS		This register contains the tape drive status. Only the IE, IOB and IIB bits are writable to
67		GLOBAL_TAPE_INTERRUPT		Error values. When written to, the 'writing' status is cancelled. as long as this register is non-zero, interrupts will be made while enabled.

Status Register:
Bit:		Meaning:			Shorthand:		Notes:
0		input buffer is full		IBF
1		output buffer is empty		OBE
2		interrupt enable bit		IE
3		tape drive busy			BUSY			set to true when the tape drive is reading from the tape, when the tape drive is winding to some position or the tape drive is writing to the tape and all words that are to be written has been received
4		write buffer full		WBF
5		read buffer full		RBF
6		writing data to tape		WRITING
7		interrupt on obe toggle		IOB
8		reading data from tape		READING
9		winding the tape		SEEKING
10		interrupt on ibf toggle		IIB


Interrupt Register:
Value:		Meaning:
0		nothing
1		unrecognised command sent to drive
2		end of tape reached during operation
3		attempted to interrupt the drive when it was busy
4		data buffer overflow
5		tape was ejected while an operatin was being performed


Communication protocol:
Low byte:	Meaning:			Verbose:

0		nop				do nothing
1		read				will read the ammount of words specified by the high 3 bytes of the word sent to tape
2		seek				will make the tape wind to the position specified by the high 3 bytes of the word sent to tape
3		write				will interpret the next <hight byte> words that are sent to the tape as data to write to the tape
4		stop				will stop the current task, unless that task is writing input to tape
5		tape inserted			will send back 1 if a tape is inserted, 0 if not
6		tape readable			will send back 1 if a tape is readable, 0 if not
7		tape writeable			will send back 1 if a tape is writeable,0 if not
8		purge data buffers		removes all buffered data from tape drive
9		disable data buffering		will make sure no data is stored on the data buffers
10		enable data buffering		will make sure 32 words of input/output can be buffered on the tape drive
11		relative seek			will move forwards/backwards relative to the current position
12		get tape pointer		returns the current position the tape is reading from

So, in order to read 10 words from the tape from address 16 onwards you must, in order:

1:	send 0x1002 to GLOBAL_TAPE_OUT
2:	wait for the tape to travel to position
3:	send 0x0a01 to GLOBAL_TAPE_OUT
4:	read the 10 words as they appear in GLOBAL_TAPE_IN register (signaled by IBF flag)



Example code:
This is the program that runs automatically when progCom is turned on.
It loads the stored program from a tape according to the specifications contained therein.
It is stored at address 128.
for other examples see libTape.txt

.meta
AUTLDR=FALSE
MAINJMP=FALSE
PIC=FALSE
AUTOSTACK=FALSE
.text

;print "please insert bootable media" message when possible

boot:
;******************************************************
;	Wait for tape to be inserted and readable
;******************************************************
	movi	r1, 6				;128
	call	sendToTape			;129
	call	tapeRead			;130
	beq	r1, r0, boot			;131
;******************************************************
;	Read bootloader pointer
;******************************************************
	;move tape to bootloader pointer
	movi	r1, 0x302			;132
	call	sendToTape			;133

	;read one word
	movi	r1, 0x101			;134
	call	sendToTape			;135
	call	tapeRead			;136

	;if bootloader location is 0, branch to start
	beq	r1, r0, boot			;137
;******************************************************
;	Read boot file information
;******************************************************
	;move tape to bootloader position
	sli	r1, r1, 8			;138
	ori	r1, r1, 2			;139
	call	sendToTape			;140
	
	;send command to read 2 words
	movi	r1, 0x201			;141
	call	sendToTape			;142
	;read load location
	call	tapeRead			;143
	mov	a0, r1				;144
	mov	r3, r1				;145

	;read program length
	call	tapeRead			;146
	mov	a1, r1				;147
	mov	r4, r1				;148
;******************************************************
;	Load program into proper position
;******************************************************
	;order tape to read entire program
	sli	r1, r1, 8			;149
	ori	r1, r1, 1			;150
	call	sendToTape			;151
	;read program data from tape
readLoop:
	call	tapeRead			;152
	wr	r1, r3, 0			;153
	addi	r3, r3, 1			;154
	subi	r4, r4, 1			;155
	bne	r4, r0, readLoop		;156
;******************************************************
;	Start program
;******************************************************
	;branch to program address
	jmpr	a0				;157


;******************************************************
;	Helper functions
;******************************************************
;waits for appropriate flags and then sends stuff to tape
sendToTape:
	;wait for busy flag false
	rd	r2, r0, GLOBAL_TAPE_STATUS	;158
	andi	r2, r2, 8			;159
	bne	r2, r0, sendToTape		;160

	;wait for OBE flag true
OBE_wait_loop:
	rd	r2, r0, GLOBAL_TAPE_STATUS	;161
	andi	r2, r2, 2			;162
	beq	r2, r0, OBE_wait_loop		;163

	wr	r1, r0, GLOBAL_TAPE_OUT		;164
	jmpr	ra				;165


;waits for IBF flag and returns stuff in r1
tapeRead:
	rd	r1, r0, GLOBAL_TAPE_STATUS	;166
	andi	r1, r1, 1			;167
	beq	r1, r0, tapeRead;wait loop	;168

	rd	r1, r0, GLOBAL_TAPE_IN		;169
	jmpr	ra				;170
