Users browsing this thread: 1 Guest(s)
Good Lord Send Us An Esper Level Up Bonus Patch

#8
Posts: 290
Threads: 3
Thanks Received: 40
Thanks Given: 1
Joined: Apr 2012
Reputation: 9
Status
None
(02-11-2016, 06:09 PM)ReturnerScum Wrote: I think what's really confusing to me is that I can't follow everything from the beginning.  I understand that it's using Y then transferring to X, but why not just increment X?  My biggest roadblock was not being able to track what happens to X throughout the whole code.

There's typically a reason they use X instead of Y or vice versa, generally related to common functions - in this case the JSR $6293. This subroutine Multiplies A * 11 and stores the result in X. It's used in multiple places, which forces the calling functions to use X as the resulting index.

So X starts out as the pointer to the equipped esper of the character in question, then has its value transferred to Y. X then becomes the esper bonus index of the esper in question.

(02-11-2016, 06:09 PM)ReturnerScum Wrote: The TDC is what signals to me that the A register is cleared so the new esper function is probably starting.  However, note that the new function starts by loading data at $D86E0A,X which is some esper information that most likely has our esper bonus.  What is in X already, and how did it get there?  I surely don't know.

The commentary two lines before that (JSR $6293) tells you what's in X, as I mentioned above.

Esper data in the ROM starts at D8/6E00, and is eleven bytes. That's eleven bytes of data per esper sorted thusly:

Code:
$0000                               Spell 1 learn rate
$0001                               Spell 1
$0002                               Spell 2 learn rate
$0003                               Spell 2
$0004                               Spell 3 learn rate
$0005                               Spell 3
$0006                               Spell 4 learn rate
$0007                               Spell 4
$0008                               Spell 5 learn rate
$0009                               Spell 5
$000A                               Bonus at level up

So that's why we get the esper ID and multiply it by eleven - because every eleventh byte starting at D8/6E0A will be the bonus for whatever esper we're looking at.

(02-11-2016, 06:09 PM)ReturnerScum Wrote: These are pointers, but I'm not sure how the computer knows they're pointers.

Because of the way we access them. This block never gets executed directly - it's only access via indexed jump, which will always treat whatever it jumps to as a pointer.

(02-11-2016, 06:09 PM)ReturnerScum Wrote: These are percentages and branches and some maneuvering which I haven't fully cared to figure out.  It's easy enough to change the percentages by changing the LDA values.

The maneuvering here is simply for the sake of efficiency. We can go over this later if you want.

(02-11-2016, 06:09 PM)ReturnerScum Wrote: We're going to load $161A,X into A.  Apparently $161A = Vigor, $161B = Speed, $161C = Stamina, and $161D = Magic Power, because we load these indexed by X which will be from 0 to 3.

This is... almost true. This is another case of an info block, just like the eleven-byte block for espers we discussed above. Take a look at the RAM map here: https://www.ff6hacking.com/forums/showth...p?tid=1408

Character data starts at $1600 and is 37 bytes long per character. The first 37 bytes are for Terra, then the next 37 are for Locke, then Cyan, then Shadow, etc. So we can assume that some time ago, X was loaded with (character ID * 37) for the sake of accessing this character info block. It's true that $161A = vigor, but only for Terra. The easier way to read it would be:

$161A + (character ID * 37) = vigor

(02-11-2016, 06:09 PM)ReturnerScum Wrote: We copy X to A then shift A to the right twice, which, I believe, pushes the entire value out of the accumulator.  This puts the value of bit 1 of X into the Carry (which I don't know anything about), or at least sets the carry flag.  Then we copy Y to X, so we now have that 0 to 3 value finally in X.  C2/619F is where we load $161A,X to get our vigor, speed, stamina, or magic power statistic.  The INC increases A by 1, so we're increasing the stat.  Then we branch if the carry flag was set, which hops over another increase of the stat.

The accumulator and index registers carry with them several flags that change depending on multiple factors. One of those flags is the carry flag. It has a multitude of uses, from overflow identification to conditional branching (such as here).

It may be easiest to consider the carry flag as an extra bit that sets off to the right of your working register (typically the accumulator). LSR will discard the carry and move the lowest bit of A into the carry, while ASL will move the carry into the lowest bit of A and discards the highest bit of A (more information on these instructions and others here. In this case, two LSRs actually move bit 1 of A into the carry (note the TXA at C2/619B), and then branches depending on whether or not the carry was set.

(02-11-2016, 06:09 PM)ReturnerScum Wrote: So the carry flag is set by a double logical shift right (LSR) of whatever was in bit 1 of X (which I still don't know what it is) and that is what determines if you get +1 or +2 to the stat.

I'm not too sure what you're confused about here, since you went over it in one of the tutorial threads you made. Note the commentary at C2/60F1:

Code:
C2/60F1: FC 4E 61     JSR ($614E,X)  (calculate bonus.  note that [Stat]+1 jumps to the
                                     same place as [Stat]+2.  what distinguishes them?
                                     Bit 1 of X.  if X is 20, 24, 28, 32, you'll get +1
                                     to a stat.. if it's 18, 22, 26, 30, you get +2.

                                     for HP/MP boosts, X of 0/2/4 means HP, and
                                     6/8/10 means MP)

Just translate X into binary, then shift all the bits to the right twice (two LSRs). X at this point contains the esper bonus index * 2, and the values work out this way due to the way they're laid out in the jump table.

(02-11-2016, 06:09 PM)ReturnerScum Wrote: But first! We change the pointers to point to our new code:

There's no sense in having two speed and stamina pointers here with the same bonus, so you can free up two of those for future expansion if you really wanted to.

(02-11-2016, 06:09 PM)ReturnerScum Wrote: So this is our new code, where we have the same process but instead of worrying about the carry flag, we just increase A six times.  Because Speed has problems around 231 and more (I believe it's actually 236), we've changed the ceilings for the stamina and speed stats to be 230.

It would be more efficient to clear the carry, then add 6 rather than using INC six times:

Code:
C2/6164: BD 1A 16     LDA $161A,X  (at $161A,X we have Vigor, Speed, Stamina, and MagPwr,
                                   respectively)
C2/6167: 18           CLC
C2/6168: 69 06        ADC #$06
C2/616A: C9 81        CMP #$E7     (is stat >= 231?)
C2/616C: 90 02        BCC $6172
C2/616E: A9 80        LDA #$E6     (if so, make it 230)
C2/6170: 9D 1A 16     STA $161A,X  (save updated stat)
C2/6173: 60           RTS

CLC = clear carry
ADC = add with carry

The reason we CLC before the ADC is because if the carry is set, it'll add an additional 1 to your value. So we clear it beforehand to prevent that from happening.


GET A SILK BAG FROM THE GRAVEYARD DUCK TO LIVE LONGER.

Brave New World
  Find
Quote  
[-] The following 1 user says Thank You to Synchysi for this post:
  • ReturnerScum (02-12-2016)



Messages In This Thread
RE: Good Lord Send Us An Esper Level Up Bonus Patch - by Synchysi - 02-12-2016, 06:28 PM

Forum Jump:

Users browsing this thread: 1 Guest(s)


Theme by Madsiur2017Custom Graphics by JamesWhite