SilentLink:
	;Silent linking routine
	call Link_Receive		;get the first byte
	cp 0C9h			;signals a transmission from a computer/calculator
	jp nz,CLI_Input_Loop			;not the OS, if we ever want TI-OS support do something here
	;Now we need to see what the command byte in the packet is
	ld hl,CLI_Input_Loop
	ld (errorHandler),hl			;Set up error handler
	call SilentLink_GetByte
	or a
	jr z,SilentLink_ReceiveProgram		;00h command
	jp CLI_Input_Loop
SilentLink_ReceiveProgram:
	call SilentLink_GetByte
	ld c,a
	call SilentLink_GetByte
	ld b,a		;Now BC is the size of the program
	;We must check if we have enough RAM
	cp 70h
	jp z,SilentLink_NoMemory		;This means that the program is larger than 28KB.
	ld a,(nextRAMpage)
	cp 85h
	jr c,SilentLink_ReceiveProgram_Step1
	;We need to check the difference
	ld hl,0C000h
	ld de,(nextRAMoffset)
	or a
	sbc hl,de
	;HL now is the space left on the current page...must calculate future ones
	ld a,(nextRAMpage)
	cp 87h
	jr z,SilentLink_ReceiveProgram_Compare
	ld d,a
	ld a,87h
	sub d
	push bc
	ld b,a
	ld de,4000h
SilentLink_ReceiveProgram_Add:
	add hl,de
	djnz SilentLink_ReceiveProgram_Add
	pop bc
SilentLink_ReceiveProgram_Compare:
	;HL now is the space we have left; compare
	or a
	sbc hl,bc
	jp c,SilentLink_NoMemory
SilentLink_ReceiveProgram_Step1:
	;Size check passed...on to next step
	;Send accept packet
	ld a,01h
	call Link_Send
	;Now we must receive the name...11 bytes
	;Let's build a VAT entry whilst we go
	ld hl,fileOP1
	ld b,11
SilentLink_ReceiveProgram_Step2:
	push bc
	call SilentLink_GetByte
	ld (hl),a
	inc hl
	pop bc
	djnz SilentLink_ReceiveProgram_Step2
	;Now get the size
	call SilentLink_GetByte
	ld c,a
	call SilentLink_GetByte
	ld b,a
	ld a,1
	push bc
	call Create_File			;Make the file
	ld a,01h
	call Link_Send
	pop bc
	;Ready to receive data now
	ld de,SilentLink_ReceiveProgram_DeleteOnError
	ld (errorHandler),de			;If we time out in the midst of a transfer, delete our file
SilentLink_ReceiveProgram_Step3:
	push bc
	call SilentLink_GetByte
	ld (hl),a
	inc hl
	bit 6,h
	jr z,SilentLink_ReceiveProgram_Step3_NoPageBoundary
	;We are at C000h, we must go back to 8000h and increment a page
	in a,(7)
	inc a
	out (7),a
	ld h,80h
SilentLink_ReceiveProgram_Step3_NoPageBoundary:
	pop bc
	dec bc
	ld a,b
	or c
	jr nz,SilentLink_ReceiveProgram_Step3
	;Yay we received a program!
	ld a,81h
	out (7),a		;Back to normal
	jp CLI_Input_Loop
SilentLink_ReceiveProgram_DeleteOnError:
	;Delete the program if an error
	ld a,81h
	out (7),a
SilentLink_NoMemory:
	ld a,02h
	call Link_Send
	jp CLI_Input_Loop
SilentLink_GetByte:
	;This routine gets a byte, but the difference is that it has timeout and waits
SilentLink_GetByte_Loop:
	ld b,0		;move this out of the loop for a timeout
	ei
	halt
	in a,(9)
	and 00011000b
	jp nz,Link_Receive
	djnz SilentLink_GetByte_Loop
	ld sp,stackStart
	;Receiving timed out, go to error place
	ld hl,(errorHandler)
	jp (hl)
