Thursday, April 21, 2016

Illusion of Gaia - "Press X To Run" Hack

I heard a couple people on Twitch request something like this a while back, so I thought I'd give it a go.  IoG has running, but you need to double-tap the direction to trigger it, which can get a little old after a few times.  The x button isn't used for anything in IoG, so it was free to assign to something new.

This one is a little more involved than some of my other recent hacks, since some new code had to be added.

https://dl.dropboxusercontent.com/u/19968993/iog_x_to_run_1_0.ips

To be used with Illusion of Gaia (U) [!].smc.  Not tested with other versions.

Details:

$82/80B6 AD 60 06    LDA $0660  [$81:0660]   A:0000 X:0000 Y:006C P:envmxdIZC
$82/80B9 29 00 0F    AND #$0F00              A:0000 X:0000 Y:006C P:envmxdIZC
$82/80BC 8D 5E 06    STA $065E  [$81:065E]   A:0000 X:0000 Y:006C P:envmxdIZC

This code masks the directions off of the controller input value (which was earlier pulled from its mapped location of $4218) corresponding to the directional values and stores it off.  This isn't terribly relevant to this modification except I've chosen this point to inject a bit of new code since this is something that runs as part of the character control code.

That code has been replaced by a jump to a new subroutine:

22 00 00 E0  JSL E0:0000
EA EA        nothing

With the new subroutine added at the end of the ROM to handle X being pressed while direction keys are also held:

29 00 0F     AND 0F00  (replaced code)
8D 5E 06     STA 065E  (replaced code)
AD 18 42     LDA 4218  read controller inputs
29 40 00     AND #0040  and with X mask
F0 40        BEQ to [end]

AD 60 06     LDA 0660   .. 0100 for right held, 0200 for left, 0400 for down, 0800 for up
29 00 01     AND #0100  and with right mask
F0 08        BEQ to [leftcheck]
A9 03 00     LDA #0003
8D B2 09     STA 09B2
80 30        BRA to [end]

leftcheck:
AD 60 06     LDA 0660   .. 0100 for right held, 0200 for left, 0400 for down, 0800 for up
29 00 02     AND #0200  and with left mask
F0 08        BEQ to [downcheck]
A9 FD FF     LDA #FFFD
8D B2 09     STA 09B2
80 20        BRA to [end]

downcheck:
AD 60 06     LDA 0660   .. 0100 for right held, 0200 for left, 0400 for down, 0800 for up
29 00 04     AND #0400  and with down mask
F0 08        BEQ to [upcheck]
A9 03 00     LDA #0003
8D B4 09     STA 09B4
80 10        BRA to [end]

upcheck:
AD 60 06     LDA 0660   .. 0100 for right held, 0200 for left, 0400 for down, 0800 for up
29 00 08     AND #0800  and with up mask
F0 08        BEQ to [end]
A9 FD FF     LDA #FFFD
8D B4 09     STA 09B4
EA EA        BRA to [end] (this one is not really needed, we're already here.. keep these here for easy sizing)


end:
AD 60 06     LDA 0660
29 00 0C     AND #0C00  either vertical direction held? no? zero out the 09B4
D0 06        BNE [hcheck]
A9 00 00     LDA #0000
8D B4 09     STA 09B4

hcheck:
AD 60 06     LDA 0660
29 00 03     AND #0300  either horizontal direction held? no? zero out the 09B2
D0 06        BNE [end2]
A9 00 00     LDA #0000
8D B2 09     STA 09B2

end2:
6B           RTL

In short, what this bit of new code is doing is the following:

If "x" is held
   If "right" is held
      Set Will's horizontal running velocity to 3
   If "left" is held
      Set Will's horizontal running velocity to -3
   If "down" is held
      Set Will's vertical running velocity to 3
   If "up" is held
      Set Will's vertical running velocity to -3
If neither "up" nor "down" are held
   Set Will's vertical running velocity to 0
If neither "left" nor "right" are held
   Set Will's horizontal running velocity to 0
Return from subroutine

Note that setting the running velocity ($7E09B2, $7E09B4) to non-zero automatically triggers the game to use the running animation and move Will in whichever direction.  Setting it to zero stops Will's run.  All this code is doing is triggering that existing code in a different way.

This has not been tested with the full game yet!  There may be places where it breaks.  Particularly, spots where Will is forced in a certain direction still need to be tested.  Feel free to report issues here and they will be fixed.

No comments:

Post a Comment