News: 11 March 2016 - Forum Rules, Mobile Version
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia

Author Topic: [65816]Store indirect problem  (Read 246 times)

yugisokubodai

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Assembly
[65816]Store indirect problem
« on: January 10, 2018, 10:09:01 pm »
I have this in my loop:

Code: [Select]
LDA $00
STA $1190,x

This works. Then I modified to

Code: [Select]
LDA #$1190
STA $54
...
LDA $00
STA ($54,x)

Then the result goes wrong. I looked the debugged file and found this:

X=00
STA ($54,x)[$80:1190] --> This is OK

X=02
STA ($54,x)[$80:2800] --> NG

Can anyone explain where I was wrong?

Thank you for reading

Disch

  • Hero Member
  • *****
  • Posts: 2559
  • NES Junkie
    • View Profile
Re: [65816]Store indirect problem
« Reply #1 on: January 10, 2018, 10:43:16 pm »
Indirect,X is not what you want -- and I'd argue is only useful is VERY LIMITED circumstances.  It does the +X BEFORE the pointer is dereferenced, not after.

Example:
When X=2, The pointer being read is from $56.  It's not reading the pointer from $54 at all.


What you are looking for is Indirect,Y mode... which is the same, but the indirection happens first, and the indexing afterward:

Code: [Select]
STA ($54),Y

Things to note:
- The comma denotes indexing (addition)
- The parenthesis denote dereferencing (pointer lookup)
- Indirect, X has the comma inside the parenthesis "($54,X)" because the addition is first
- Indirect, Y has the comma outside the parenthesis "($54),Y" because the indirection is first

yugisokubodai

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Assembly
Re: [65816]Store indirect problem
« Reply #2 on: January 10, 2018, 10:50:28 pm »
Danke, I corrected to STA ($54),y and it works.
I forgot that 65816 doesn't have thing like STA ($54),x.

I find that STA ($54,x) works exactly the same as STA $54,x  :o

Disch

  • Hero Member
  • *****
  • Posts: 2559
  • NES Junkie
    • View Profile
Re: [65816]Store indirect problem
« Reply #3 on: January 10, 2018, 10:53:39 pm »
Quote
I find that STA ($54,x) works exactly the same as STA $54,x

Not at all.

Assume you have the below memory:
Code: [Select]
0054=AA
0055=BB
0056=CC
0057=DD
X   =02
Y   =02
DP  =0000

Code: [Select]
STA $54,X    ; writes to $0056
STA ($54),Y  ; writes to $BBAC
STA ($54,X)  ; writes to $DDCC

yugisokubodai

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Assembly
Re: [65816]Store indirect problem
« Reply #4 on: January 10, 2018, 11:21:56 pm »
You deserve my likes  ;)