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

Author Topic: GBA hacking: How to modify branch jumps?  (Read 613 times)

SleepyFist

  • Hero Member
  • *****
  • Posts: 835
    • View Profile
GBA hacking: How to modify branch jumps?
« on: June 25, 2019, 06:00:01 am »
There's a block of code in the ROM I'm working with right now, that I want to move backwards a few bytes to utilize some empty space nearby, the problem is that I don't know how to change the addresses that branches in the code jump to, leaving the thing unusable the moment I change the location of the code at all, does anyone have any idea how i could go about fixing this?

Sorry if this is a stupid question but I'm still unused to working with GBA ASM code.
Sleepy's tune of the week|| Lost Lullabies (Unreleased Samurai Champloo tracks)|| https://youtu.be/BK6PR8DPNOw

Bregalad

  • Hero Member
  • *****
  • Posts: 2636
    • View Profile
Re: GBA hacking: How to modify branch jumps?
« Reply #1 on: June 25, 2019, 07:31:18 am »
Is this block of code a subroutine ?
Typically it'd be called using the
Code: [Select]
blinstruction. You should search for pointers pointing to your subroutine, stored in little-endian, and ending with 0x08 (the most significant byte is 0x08 because it's the offset of cartridge ROM). You'll probably find several references, and if you modify them all you'd be able to easily relocate your subroutine.

If that doesn't work, some further analysis with a step-by-step debugger is needed, but there's no general answer and it changes from case to case. I hope this was helpful - but I don't know what I can say for help.

SleepyFist

  • Hero Member
  • *****
  • Posts: 835
    • View Profile
Re: GBA hacking: How to modify branch jumps?
« Reply #2 on: June 25, 2019, 08:17:14 am »
Yeah, it is a subroutine, I've got it mapped out, as well as the cluster of bl commands that link to it and a bunch of other subroutines, I just wasn't sure how to go about finding the pointers,thanks for the advice.  :thumbsup:

The game in question is Final Fight One for the GBA, I'm doing some work on it for SCD, it also doubles as much needed practice for GBA ASM hacking as well.
Sleepy's tune of the week|| Lost Lullabies (Unreleased Samurai Champloo tracks)|| https://youtu.be/BK6PR8DPNOw

FAST6191

  • Hero Member
  • *****
  • Posts: 2560
    • View Profile
Re: GBA hacking: How to modify branch jumps?
« Reply #3 on: June 25, 2019, 11:03:09 am »
Why this approach? It is a 32 Mbit title so you could trivially expand it 8 times its current size if you wanted to, or 4 times if you wanted to be nicer to certain flash cart users. That is still megabytes of space though.
There are times when it makes sense to shuffle something so that you gain a bit of space but the thought of having to do it for something that the game branches to and having to hunt down all the potential jumps to it in ARM and THUMB modes... there had better be a really good reason for this one. As you are unlikely to be out of space that leaves "having to work with existing mods" or "having to work with future mods" as the main viable options for that, and I don't think I missed Final Fight GBA being the latest game to receive a dedicated hacking community of the "blink and you will miss it" variety (for the GBA then Fire Pro Wrestling is usually the main example of such a thing).

Can you not put jumps around the code block? The GBA does blind jumping reasonably well if you wanted to start your new stuff before it, jump in the middle and land after it. Or even a single solitary jump where the original routine would have landed to go to its new location.

http://problemkaputt.de/gbatek.htm#armopcodesbranchandbranchwithlinkbblbxblxswibkpt
http://www.coranac.com/tonc/text/asm.htm

SleepyFist

  • Hero Member
  • *****
  • Posts: 835
    • View Profile
Re: GBA hacking: How to modify branch jumps?
« Reply #4 on: June 25, 2019, 07:29:28 pm »
Tbh, I've pretty much been winging it, starting in on hacking Final Fight, I only really had cursory knowledge of 6502 and MIPS ASM, I hadn't even considered that I could just expand the ROM and jump to the new code that way.  :P

I've probably gotten much further half-assing this than I did with my other projects at the very least anyways, I'm finally learning!
Sleepy's tune of the week|| Lost Lullabies (Unreleased Samurai Champloo tracks)|| https://youtu.be/BK6PR8DPNOw

Bregalad

  • Hero Member
  • *****
  • Posts: 2636
    • View Profile
Re: GBA hacking: How to modify branch jumps?
« Reply #5 on: June 26, 2019, 02:43:45 am »
Why this approach? It is a 32 Mbit title so you could trivially expand it 8 times its current size if you wanted to, or 4 times if you wanted to be nicer to certain flash cart users.[...]
Can you not put jumps around the code block? The GBA does blind jumping reasonably well if you wanted to start your new stuff before it, jump in the middle and land after it. Or even a single solitary jump where the original routine would have landed to go to its new location.

http://problemkaputt.de/gbatek.htm#armopcodesbranchandbranchwithlinkbblbxblxswibkpt
http://www.coranac.com/tonc/text/asm.htm
Not expanding the ROM makes it more likely to work well together with other hacks and translations which expand the ROM. So I'd recommand expanding the ROM only if not doing so is complicated. FAST has a point though, that with GBA if you need to epxand the ROM it's usually straightforward and there's no point of doing major effort without expanding the ROM.

Also keep in mind IPS patches can only adress 16MB (or 256MBit) so you expanding it to 8 times would be a bad idea even if you didn't care about certain flash cart users.

SleepyFist

  • Hero Member
  • *****
  • Posts: 835
    • View Profile
Re: GBA hacking: How to modify branch jumps?
« Reply #6 on: June 27, 2019, 10:29:10 am »
It's probably for the best if I go ahead and expand the rom, there's quite a few modifications SCD has requested that are going to require a bit of room to work, in addition to some stuff I'm considering adding myself after SCD's restoration project is done.
Sleepy's tune of the week|| Lost Lullabies (Unreleased Samurai Champloo tracks)|| https://youtu.be/BK6PR8DPNOw