[stella] Trouble with AtariVox code - please help!

Subject: [stella] Trouble with AtariVox code - please help!
From: "Bob Montgomery" <BobM@xxxxxxxxxxx>
Date: Tue, 31 May 2005 16:16:15 -0400
I'm having trouble getting my code to work that is supposed to read/write high scores to the AtariVox. Would someone take a look at this routine and see if they can see what I am doing wrong?

I am having no trouble making the AVox speak, and when I read from the AVox I get something back, but I can't seem to write anything to it.

A few notes about the routine:
I don't get any errors from the AVox, at least none that would trigger the branch to "eeprom_error"  I have played around with sticking that check after almost all of the reads/writes to the AVox and it never takes that branch.
The CompareHighScoreSubroutine has been tested and it works.  So I don't think that is the problem.
I have played around with bypassing the Checksum check and nothing.

What happens when I run this is:
It reads something, I think every byte it reads is $FF, though it could be any combination of the nibbles $D through $F (i.e., $DF, $FE, etc.) - sorry, I haven't been able to narrow it down further yet.
No matter what I tell it to write to the AVox, when I read from the AVox's eeprom, I always get the same values.

Anyway, here's the code.  The subroutines whose names begin "i2c" are from the AVox driver pack
(download here: http://www.atariage.com/store/product_info.php?cPath=31&products_id=295) 
from the file: i2c.inc
As far as I know, they should work; Aaron (Fall Down) wrote me that they are the subroutines he used 
and that they worked fine.

Oh, one last thing: I have been testing this with a Cuttle Cart.

-bob

;--code follows


AVoxMemAccessKernel		;VBLANK is not turned off during this kernel.
	lda #228
	sta TIM64T

	;--clear AVoxMemAccessFlag:
	lda Flags2
	and #%01111111
	sta Flags2


	;---AVox EEPROM Access code follows

	jsr i2c_startwrite
	bcs eeprom_error

	lda #$00		;high byte &
	jsr i2c_txbyte
	lda #$C0		;low byte of address: $00C0
	jsr i2c_txbyte

	jsr i2c_stopwrite

	jsr i2c_startread

	ldx #6
ReadHighScoresFromAVoxLoop
	jsr i2c_rxbyte		;--read byte from EEPROM
	sta DataFromAVox,X
	dex
	bpl ReadHighScoresFromAVoxLoop

	jsr i2c_stopread

	;Note:
	;	DataFromAVox	==	HighScore	hundreds and thousands	-$C6
	;	DataFromAVox+1	==	HighScore+1	ones and tens		-$C5
	;	DataFromAVox+2	==	HighScore2					-$C4
	;	DataFromAVox+3	==	HighScore2+1				-$C3
	;	DataFromAVox+4	==	HighScore3					-$C2
	;	DataFromAVox+5	==	HighScore3+1				-$C1
	;	DataFromAVox+6	==	Checksum					-$C0
	;where HighScore is the lowest score

	;--now check the checksum by adding all high score bytes,
	;	in order.  Result is checksum.
	;--Note: addition is NOT bcd, though high scores are bcd.


	lda #0
	ldx #5
	clc
ChecksumCheckLoop
	adc DataFromAVox,X
	dex
	bpl ChecksumCheckLoop

	cmp DataFromAVox+6		;Checksum correct?
	bne CheckSumIncorrect

	;--Checksum correct, now we merge high scores from current
	;	session with high scores in AVox
	;	by calling CompareHighScoreSubroutine for each high score.
	;	CompareHighScoreSubroutine needs the high score to be compared in
	;	Temp+1 and Temp+2
	
	ldx #5
MergeHighScoresLoop
	lda DataFromAVox-1,X
	sta Temp+1
	lda DataFromAVox,X
	sta Temp+2
	stx Temp+3
	jsr CompareHighScoreSubroutine
	ldx Temp+3
	dex
	dex
	bpl MergeHighScoresLoop

	;--now the current-session high score table should be the merged, correct
	;	high score table and can be written directly back to the AVox.

CheckSumIncorrect	;--if checksum was incorrect, then write current-session
			;	high score table to AVox

	;--first figure new checksum

	lda #0
	ldx #5
	clc
FigureNewChecksumLoop
	adc HighScore,X
	dex
	bpl FigureNewChecksumLoop

	sta DataFromAVox+6		;save new checksum over old checksum

	jsr i2c_startwrite
	bcs eeprom_error
	
	lda #$00
	jsr i2c_txbyte
	lda #$C0
	jsr i2c_txbyte

	lda DataFromAVox+6	;write checksum to $C0
	jsr i2c_txbyte

	ldx #5
WriteHighScoreTableToAVoxLoop
	lda HighScore,X
	jsr i2c_txbyte
	dex
	bpl WriteHighScoreTableToAVoxLoop
eeprom_error	
	jsr i2c_stopwrite

	;---End AVox EEPROM access code

WaitForEndOfAVMemAccessKernel
	lda INTIM
	bne WaitForEndOfAVMemAccessKernel
	sta WSYNC

	rts
Archives (includes files) at http://www.biglist.com/lists/stella/archives/
Unsub & more at http://stella.biglist.com

Current Thread