FF6 Hacking
How Do We Index Address - Printable Version

+- FF6 Hacking (https://www.ff6hacking.com/forums)
+-- Forum: Discussion Forums (https://www.ff6hacking.com/forums/forum-5.html)
+--- Forum: Magitek Research Facility (https://www.ff6hacking.com/forums/forum-9.html)
+--- Thread: How Do We Index Address (/thread-3122.html)



How Do We Index Address - ReturnerScum - 02-07-2016

So I ran up against a wall trying to edit esper level-up bonuses because index addressing seems so simple, but does not compute.  This thread is for the posterity of figuring it out.  From my readings, index addressing is simple.  Instead of going to a static location, you go to a pointed location that is instead increased (or decreased?) by one of the other registers (X, Y, etc.).  So (LDA, X) JSR ($CA24,X) means you jump to the address but if 2 is the current value in the X register, then you go to that address +2.

This is how index addressing works, isn't it?  When I try to modify things in FF6 based on this it doesn't work out.  Also, I often can't follow the C2 notes that are based on index addressing, as they look to be using it differently than I imagine.

Thanks All,
RS

Edit: I did mean JSR for that example.  (LDA, X) is loading to the accumulator like you all said


RE: How Do We Index Address - Catone - 02-07-2016

The 8 bit and 16 bit modes always get me on the multiplication part while adjusting for how many bytes to skip to reach the desired entry. Course, saving that loaded value for use was always a hassle too.

In theory that seems like the correct method, but I'm certainly not good enough to check it without knowing whats going on around it and what its trying to load/read.


RE: How Do We Index Address - ReturnerScum - 02-07-2016

You know what's cool? The Socrates quote in your sig


RE: How Do We Index Address - Catone - 02-07-2016

Yeah, I used to always say "The closest you'll ever get to knowing everything is knowing, you don't know chit."

Then one day watching Bill & Ted's Excellent Adventure I realized just how smart ol' Socrates really was. Since his quote was alot prettier than mine, I figured I'd go with his. Although I still think he said it the same way I did, they just translated it wrong.

But yeah, if you "know" nothing, then you can learn anything. Least it always made since to me.


RE: How Do We Index Address - m06 - 02-07-2016

(02-07-2016, 12:33 PM)ReturnerScum Wrote: So (LDA, X) means you jump to the address but if 2 is the current value in the X register, then you go to that address +2.

You're on the right track.
Maybe I'm taking you to literally but LDA does not jump. LDA (load accumulator) loads the A register with a value.
So LDA $0000,X loads the binary value at address $0000+X (as you said) but puts the value into the A register and does not jump.


RE: How Do We Index Address - madsiur - 02-08-2016

You're right on the basic. There's a resume but with little explanation on the snesdevelopment site. There's also about 20 different addressing combination described here covering 20 pages: http://wiki.nesdev.com/w/images/7/76/Programmanual.pdf

Maybe it would worth you read them. Read! (I haven't Tongue)


RE: How Do We Index Address - Synchysi - 02-08-2016

What you're likely thinking of is indexed jumping - i.e., JSR $8C4A,X

In this case, $8C4A is generally the start of the jump table. The table itself is simply a list of addresses in little Endian (essentially meaning that you read them backwards) that redirect the jump. So, using the esper bonus jump table for example:

Code:
C2/614E: 70 61  (~10% HP bonus)
C2/6150: 74 61  (~30% HP bonus)
C2/6152: 78 61  (50% HP bonus)
C2/6154: 70 61  (~10% MP bonus)
C2/6156: 74 61  (~30% MP bonus)
C2/6158: 78 61  (50% MP bonus)
C2/615A: B0 61  (Double natural HP gain for level)
C2/615C: 97 61  (No bonus)
C2/615E: 97 61  (No bonus)
C2/6160: 9B 61  (Vigor bonus)
C2/6162: 9B 61  (Vigor bonus)
C2/6164: 9A 61  (Speed bonus)
C2/6166: 9A 61  (Speed bonus)
C2/6168: 99 61  (Stamina bonus)
C2/616A: 99 61  (Stamina bonus)
C2/616C: 98 61  (MagPwr bonus)
C2/616E: 98 61  (MagPwr bonus)

If you look at these backwards, you can see where each one will redirect the jump to. For instance, the HP +50% boost would redirect the jump to C2/6178.

It's important to remember that X needs to be an even number for a jump table to work properly. Since all addresses in a jump table are two bytes, you need to push the index forward by two bytes to get the next proper address in the table. That's why you will see things like ASL, TAX before the jump (like at C2/60EF).