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

Author Topic: Final Fantasy VI (SNES, v 1.0, NTSC): ASM question (Altering Sprint Shoes)  (Read 4453 times)

Edea

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Because my copy of the game has been patched with the 'Press B button to run' hack, the Sprint Shoes are no longer necessary.  I would like to change the Sprint Shoes into a Relic which, when equipped, changes the probably of a weapon's added spell activating during an attack, increasing it from 25% (1 in 4) to 100% (guaranteed).

Here is the relevant routine (C2 block) and what I want to do to it:

=========================================================================================
Weapon "addition magic" routine  (Source: TeriiSenshi)
=========================================================================================
Code: [Select]
C2/363E: A5 B5        LDA $B5
C2/3640: C9 16        CMP #$16       (is Command Jump?)
C2/3642: D0 05        BNE $3649      (if not, branch)
C2/3644: AD 70 3A     LDA $3A70      (are there more attacks to do from Offering /
                                      Quadra Slam / Dragon Horn / etc?)
C2/3647: D0 1C        BNE $3665      (if so, exit function)
C2/3649: AD 89 3A     LDA $3A89
C2/364C: 89 40        BIT #$40       (is "cast randomly with fight" bit set in the
                                      weapon spellcast byte?)
C2/364E: F0 15        BEQ $3665      (if not, Exit function)
----------------------------
   WHAT I WANT TO INSERT:
----------------------------
*(Does the attacker have Item #230 equipped in either Relic slot?)
                *(If so, branch to what is currently C2/3658)

This insertion would bypass the '1 in 4 check' portion of the code
                when that Relic was equipped, making the game always isolate/save
                the spell instead.
        ----------------------------
C2/3650: EB           XBA
C2/3651: 20 5A 4B     JSR $4B5A      (random #, 0 to 255)
C2/3654: C9 40        CMP #$40
C2/3656: B0 0D        BCS $3665      (if that # is 64 or greater, exit function.  iow, exit
                                      3/4 of time.)
C2/3658: EB           XBA
C2/3659: 29 3F        AND #$3F       (isolate spell # of weapon in bottom 6 bits)
C2/365B: 8D 00 34     STA $3400      (save it)
C2/365E: A9 10        LDA #$10
C2/3660: 14 B2        TRB $B2        (this bit distinguishes traditional "addition magic"
                                      spellcasts from Tempest's Wind Slash in a few ways in
                                      C2/37EB.)
                                     (one is that it'll cause the targeting byte to be set to
                                      only "Cursor start on enemy" for the followup spell.
                                      maybe the goal is to prevent the spell from targeting
                                      multiple enemies..?  but i'm not sure when the spellcast
                                      would even try to target anything other than the target
                                      whacked by the weapon, unless the spell randomizes
                                      targets, which no normal "addition magic" does.)
C2/3662: EE 70 3A     INC $3A70      (increment # of attacks remaining.  since the calling
                                      code will soon decrement this, the addition magic
                                      should be cast with the same # of attacks remaining
                                      as the weapon strike preceding it was.)
C2/3665: 60           RTS
=========================================================================================

However, there's serious space issues, here.  I don't know where to insert this additional code; it will not 'fit.'  Would anyone with some experience altering the game's code be willing to help me figure out how to either reoptimize or relocate portions of this subroutine so that I'm able to alter Item 230's behavior the way I want, without disrupting other portions of the ROM which are sensitive?

Lenophis

  • IRC Staff
  • Hero Member
  • *****
  • Posts: 960
  • The return of the sombrero!
    • View Profile
    • Slick Productions
Hooray, I'm helping! </Zoidberg!>

I would highly recommend you do not make this hard-coded to a specific item. There's enough hard-coded crap already in this game, and it would pretty bad to add to it. My personal recommendation is to claim an unused bit in one of the item property bytes (check boxes with "?" in FF3usME) and use that instead. Here's some handy code for you to help:

Code: [Select]
(Weapon "addition magic")

C2/363E: A5 B5        LDA $B5
C2/3640: C9 16        CMP #$16   (is Command Jump?)
C2/3642: D0 05        BNE $3649  (if not, branch)
C2/3644: AD 70 3A     LDA $3A70  (are there more attacks to do from Offering /
                                  Quadra Slam / Dragon Horn / etc?)
C2/3647: D0 1C        BNE $3665  (if so, exit function)
C2/3649: AD 89 3A     LDA $3A89
C2/364C: 89 40        BIT #$40   (is "cast randomly with fight" bit set in the
                                  weapon spellcast byte?)
C2/364E: F0 15        BEQ $3665  (if not, Exit function)
C2/3650: EB           XBA
C2/3651: 20 xx xx     JSR $xxxx  (JSR to new routine elsewhere with free space in C2)
C2/3654: EA           NOP
C2/3655: EA           NOP
C2/3656: B0 0D        BCS $3665  (branch if spell proc is unsuccessful, either due to no buff or no good RNG roll)
C2/3658: EB           XBA
C2/3659: 29 3F        AND #$3F   (isolate spell # of weapon in bottom 6 bits)
C2/365B: 8D 00 34     STA $3400  (save it)
C2/365E: A9 10        LDA #$10
C2/3660: 14 B2        TRB $B2    (prevent followup spell from hitting random target;
                                  it can only hit the one whacked by the weapon.)
C2/3662: EE 70 3A     INC $3A70  (increment # of attacks remaining.  since the calling
                                  code will soon decrement this, the addition magic
                                  should be cast with the same # of attacks remaining
                                  as the weapon strike preceding it was)
C2/3665: 60           RTS

Some new location in bank C2!

First you should determine which free bit you wish to use. There's technically 4 free bits, but one of them, $11D7:1 is used as scratch for the Earrings. You could use this if you wanted, but you would also get a damage boost for magical attacks. Otherwise you can use $11D8:7, $11D9:5, or $11D9:6.
You could also use the party-wide bit the Sprint Shoes currently use, but then the effect would apply to everyone in the party.

Code: [Select]
If you use $11D8:7...
CLC  (this is our indicator that it is equipped, but if it's not equipped then carry will be changed with the RNG call)
LDA $11D8
BMI equipped (the highest bit holds our effect, and this branch will take if it's equipped)
JSR $4B5A  (our RNG, rolls 0-255)
CMP #$40
equipped:
RTS

If you use $11D9:5 or 6
CLC
LDA $11D9
BIT #$20 or BIT #$40 (depending on above)
BNE equipped
JSR $4B5A  (our RNG, rolls 0-255)
CMP #$40
equipped:
RTS

I didn't test it, but this should work unless I got my branch logic mixed up.


https://ff6randomizer.codeplex.com/ - Randomize your FF6 experience!

Edea

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Oh, thank heavens, I was hoping you'd see this.

I'll do my best implementing those and report back in a few days, hopefully.  This is definitely what I needed; mostly I need to make sure I don't mess up one of the '?' entries I've already used for something else (I think it was for allowing Atlas Armlet's effect to stack?  Ugh, need to review my item changes first).

THANK you, again.

EDIT: It works!  Here's the completed code, if anyone cares to try it.  Works with Genji Glove, turned off by Offering, just like normal 'weapon spell' activation.  Tested it a lot with a Fire Rod; relic on, it always cast Fire 2, relic off, did it about 25% of the time.  In the FF3usME item editor, this is the upper '?' in the lower right box to the far right of the screen.

Code: [Select]
(2383e)
C2/363E: A5 B5        LDA $B5
C2/3640: C9 16        CMP #$16   (is Command Jump?)
C2/3642: D0 05        BNE $3649  (if not, branch)
C2/3644: AD 70 3A     LDA $3A70  (are there more attacks to do from Offering /
                                  Quadra Slam / Dragon Horn / etc?)
C2/3647: D0 1C        BNE $3665  (if so, exit function)
C2/3649: AD 89 3A     LDA $3A89
C2/364C: 89 40        BIT #$40   (is "cast randomly with fight" bit set in the
                                  weapon spellcast byte?)
C2/364E: F0 15        BEQ $3665  (if not, Exit function)
C2/3650: EB           XBA
C2/3651: 20 5A A6     JSR $A65A (JSR to new routine elsewhere with free space in C2)
C2/3654: EA           NOP
C2/3655: EA           NOP
C2/3656: B0 0D        BCS $3665  (branch if spell proc is unsuccessful, either due to no buff or no good RNG roll)
C2/3658: EB           XBA
C2/3659: 29 3F        AND #$3F   (isolate spell # of weapon in bottom 6 bits)
C2/365B: 8D 00 34     STA $3400  (save it)
C2/365E: A9 10        LDA #$10
C2/3660: 14 B2        TRB $B2    (prevent followup spell from hitting random target;
                                  it can only hit the one whacked by the weapon.)
C2/3662: EE 70 3A     INC $3A70  (increment # of attacks remaining.  since the calling
                                  code will soon decrement this, the addition magic
                                  should be cast with the same # of attacks remaining
                                  as the weapon strike preceding it was)
C2/3665: 60           RTS


(2a85a)
C2/A65A: 18       CLC
C2/A65B: AD D9 11     LDA $11D9 (used this one because I'm also using the Atlas Armlet stack mod)
C2/A65E: 89 20        BIT #$20
C2/A660: D0 05        BNE (in other words, if it's equipped, go here)
C2/A662: 20 5A 4B     JSR $4B5A  (the RNG, rolls 0-255)
C2/A664: C9 40        CMP #$40
C2/A666: 60           RTS
« Last Edit: March 17, 2014, 06:20:01 pm by Edea »

Lenophis

  • IRC Staff
  • Hero Member
  • *****
  • Posts: 960
  • The return of the sombrero!
    • View Profile
    • Slick Productions
You know, when I was posting this, I was completely neglecting which free bit corresponds with which check box in the editor. I'm glad you figured that out quickly. :-[

$11D7:1 looks at the "?" check box with "Raise steal rate" and "Raise sketch rate" et al.
$11D8:7 looks at the "?" check box with "Randomly retort" and "Randomly evade" et al.
$11D9:5 and 6 looks at the "?" check boxes with "Shell on low HP" and "Safe on low HP" et al.

I'll just hide now. :laugh:


https://ff6randomizer.codeplex.com/ - Randomize your FF6 experience!

assassin

  • Full Member
  • ***
  • Posts: 142
    • View Profile
    • My Barren Webpage
[post had no new info, so feel free to delete it entirely.]
« Last Edit: March 18, 2014, 04:20:23 pm by assassin »

Edea

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
I'll just ask this in here as it's another ASM question...

Would anyone know what code I need to look at to prevent the White Dragon battle in the Fanatic's Tower from spitting a Holy Lance at you after you've returned to the dungeon screen?

I'm reorganizing the Veldt encounters, and White Dragon (being a Boss) is being moved to the post-255 range, so there's no longer a need for this; I just want it to drop its stuff normally like the other seven dragons, during the 'finished battle' screen sequence. 

THAT part I can do just fine, but preventing the "Got Pearl Lance!" event from occuring, afterward, that I'm unsure about (as it still needs to tell you how many dragons are left, and it needs to send you into the correct encounter when you speak to the sprite).  Is it possible to do this using just the Map Editor?

Madsiur

  • RHDN Patreon Supporter!
  • Full Member
  • *****
  • Posts: 174
  • FF6 hacker
    • View Profile
You need to modify the White Dragon event. You can remove the dialogue "Got pearl lance" (4B DD 06) and the item adding to inventory (80 21). Subroutine $CC1F9F is responsible of displaying the number of dragons left.

Edit: You'll need to modify the first parameter byte of the 4D command, which is: formation number - 256 (meaning your boss formation must be between #256 and #512 if my memory is good...). What I find odd is that here the formation is $8B while the actual formation is 523... It doesn't match 523 - 256...

Code: [Select]
CC/558B: 4D    Invoke battle, enemy set $8B, background $3F (Default for this area), (mosaic effect enabled), (swoosh sound enabled)
CC/558E: B2    Call subroutine $CA5EA9
CC/5592: 42    Hide object $10
CC/5594: DD    Clear event bit $1E80($694) [$1F52, bit 4]
CC/5596: 96    Restore screen from fade
CC/5597: 5C    Pause execution until fade in or fade out is complete
CC/5598: 4B    Display dialogue message $06DD, wait for button press
               
               Got “Pearl Lance”!
CC/559B: 80    Add item $21 (<DA>Pearl Lance ) to inventory
CC/559D: B2    Call subroutine $CC1F9F
CC/55A1: 3A    Enable player to move while event commands execute
CC/55A2: FE    Return
« Last Edit: March 22, 2014, 10:30:21 pm by Madsiur »

Edea

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Alright, looks like it can just be NOP'd...I'll give it a shot once I've got a good save for testing it.  Thank you!

Madsiur

  • RHDN Patreon Supporter!
  • Full Member
  • *****
  • Posts: 174
  • FF6 hacker
    • View Profile
Alright, looks like it can just be NOP'd...I'll give it a shot once I've got a good save for testing it.  Thank you!

You can replace those bytes by an unused event commands such as FD which simply returns to a RTS and will act as "Do nothing" in the event.

Lenophis

  • IRC Staff
  • Hero Member
  • *****
  • Posts: 960
  • The return of the sombrero!
    • View Profile
    • Slick Productions
Edit: You'll need to modify the first parameter byte of the 4D command, which is: formation number - 256 (meaning your boss formation must be between #256 and #512 if my memory is good...). What I find odd is that here the formation is $8B while the actual formation is 523... It doesn't match 523 - 256...
It loads the 2-pack formation, which for FF3usME is 512-256. $8B is 2-pack 139, which is number 395 in the "Packs" tab of the formations editor.


https://ff6randomizer.codeplex.com/ - Randomize your FF6 experience!