TI-H: REVERSE ENGINEERED: EII


[Prev][Next][Index][Thread]

TI-H: REVERSE ENGINEERED: EII




;*****Old EII style code
TIPServer:
	rcall	read_ti			;Get byte from TI-Calc
	cp		temp, write		;Does it want to write data?
	breq	write_tip		;If it does, then do it!
	cp		temp, read		;Does it want to read data?
	breq	read_tip		;If it does, then do it!
	cp		temp, status	;Does it want to get the status?
	breq	status_tip		;If it does, then do it!
	cp		temp, version	;Does it want to get the version?
	breq	version_tip		;If it does, then do it!
	rjmp	TIPServer		;Opps.  :(  Something bad happened
write_tip:
	rcall	enable_spi		;Enable the memory
	mov		temp_spi, temp	;Put data in SPI temp register
	rcall	read_ti			;Get first address byte
	mov		temp_spi, temp	;Put data in SPI temp register
	rcall	write_spi		;Send address byte to memory
	rcall	read_ti			;Get second address byte
	mov		temp_spi, temp	;Put data in SPI temp register
	rcall	write_spi		;Send address byte to memory
	rcall	read_ti			;Get third address byte
	mov		temp_spi, temp	;Put data in SPI temp register
	rcall	write_spi		;Send address byte to memory
	rcall	read_ti			;Get number of bytes to write (low)
	mov		byteslow, temp	;Put number of bytes (low) into
byteslow
	rcall	read_ti			;Get number of bytes to write (high)
	mov		byteshighm temp	;Put number of bytes (high) into
byteshigh
	rjmp	write_page		;Write a page of data
read_tip:
	rcall	enable_spi		;Enable the memory
	mov		temp_spi, temp	;Put data in SPI temp register
	rcall	read_ti			;Get first address byte
	mov		temp_spi, temp	;Put data in SPI temp register
	rcall	write_spi		;Send address byte to memory
	rcall	read_ti			;Get second address byte
	mov		temp_spi, temp	;Put data in SPI temp register
	rcall	write_spi		;Send address byte to memory
	rcall	read_ti			;Get third address byte
	mov		temp_spi, temp	;Put data in SPI temp register
	rcall	write_spi		;Send address byte to memory
	ldi		temp_spi, null	;Load temp_spi with a null byte
	rcall	write_spi		;Send null byte #1 to memory
	rcall	write_spi		;Send null byte #2 to memory
	rcall	write_spi		;Send null byte #3 to memory
	rcall	write_spi		;Send null byte #4 to memory
	rcall	read_ti			;Get number of bytes to write (low)
	mov		byteslow, temp	;Put number of bytes (low) into
byteslow
	rcall	read_ti			;Get number of bytes to write (high)
	mov		byteshighm temp	;Put number of bytes (high) into
byteshigh
	rjmp	read_page		;Write a page of data
status_tip:
	rcall	enable_spi
	mov		temp_spi, temp
	rcall	write_spi
	rcall	disable_spi
	rcall	write_ti
	rjmp	TIPServer
version_tip:
	rcall	disable_spi
	ldi		temp, Eg
	rcall	write_ti
	rjmp	TIPServer
read_page:
	rcall	read_spi
	ldi		temp, delay		;Delay
A:	rjmp B					;Take up time
B:	dec		temp			;Take one away
	brne	A				;Is it nothing
	nop						;Do nothing
	mov		temp, temp_spi	;Put SPI data in temp register
	rcall	write_ti		;Send it to calculator
	dec		byteslow		;We've done one byte!
	brne	read_page		;Are we done? getting <=256 bytes?
	cpi		byteshigh, nmb	;Do we have more bytes to work with?
	breq	return			;nope
	mov		byteslow, byteshigh	;Yep
	clr		byteshigh		;We don't need bytes high
anymore
	cpi		byteshigh, 0x00	;Have we already messed with byteshigh?
	breq	return			;yep
	rjmp	read_page		;Get those extra bytes
write_page:
	rcall	read_ti
	ldi		temp, delay		;Delay
C:	rjmp D					;Take up time
D:	dec		temp			;Take one away
	brne	C				;Is it nothing
	nop						;Do nothing
	rcall	write_spi
	dec		byteslow		;We've done one byte!
	brne	write_page		;Are we done? getting <=256 bytes?
	cpi		byteshigh, nmb	;Do we have more bytes to work with?
	breq	return			;nope
	mov		byteslow, byteshigh	;Yep
	clr		byteshigh		;We don't need bytes high
anymore
	cpi		byteshigh, 0x00	;Have we already messed with byteshigh?
	breq	return			;yep
	rjmp	write_page		;Get those extra bytes
return:
	rcall	disable_spi		;Disable memory
	rjmp	TIPServer		;Go back