Re: [stella] My code is broked!

Subject: Re: [stella] My code is broked!
From: Jason Rein <jjrein@xxxxxxxxxxxxx>
Date: Tue, 7 Oct 2003 20:07:10 -0700
Hi,

I'm still learning Indirect Y addressing (and writing a "how to" as I go along in case I forget later) but I think you may need to initialize both the hi and lo byte of the address (since Indirect Y expects a 16-bit address).

For example, you're stuffing the value #$B0 (least significant byte of the address) in tmpVar3 but when you go to dereference it later (with "lda (tmpVar3),y"), it's reading the address as "$xxB0" where "$xx" is garbage.

Try this...

lda #PlayerHand
sta tmpVar3
lda #0
sta tmpVar3+1

lda #Player3
sta tmpVar4
lda #0
sta tmpVar4+1

We're simply putting "$00" as the most significant byte of the address so the tmpVar3 pointer will look like "$00B0" and the tmpVar4 pointer will hold "$00A0". Oh, and be sure both tmpVars are 2 bytes in size!

I hope that helps. If not, we'll both learn something! :)

Jason


On Tuesday, October 7, 2003, at 07:33 PM, Chris Larkin wrote:

It could just be that I still don't fully understand indirect addressing... But this should work?
?
I know this loop does not replace the first byte in either location, but it should "swap" the others... However
my results are not very good :-)?What am I doing wrong?
?
?
PlayerHand = $B0 ; -> $B6
Player3 = $A0 ; -> $A6
?
TradeHands
??? ?LDY #7
??? ?LDA #PlayerHand
??? ?STA tmpVar3
??? ?LDA #Player3
??? ?STA tmpVar4


TradeLoop
??? ?LDA (tmpVar3),y
??? ?STA tmpVar2
??? ?LDA (tmpVar4),y
?????STA (tmpVar3),y
?????LDA tmpVar2
??? ?STA (tmpVar4),y
??? ?DEY
??? ?BNE TradeLoop
??? ?RTS

?
Current Thread