How to find ROM offsets - pret/pokecrystal GitHub Wiki
Introduction
When building external tools, you may need to know where the relevant data is stored in the rom. This need is irrelevant for tools that work directly with the source files of this project, but it is relevant for tools that interface with rom files directly. So, in those cases, you may want to find the relevant rom file offsets.
Luckily, you can use this projects' data to help you find these offsets for the vanilla Crystal roms. This guide can also apply for rom hacks based on this project if you apply the steps below on their respective git repos.
Guide
The first step is to browse the directories of this project and check files that look related to what you're looking for.
Once you've found what you need there, you'll likely end up finding a name/label in one of the .asm
files. (example: BaseData
or PokemonPicPointers
)
Now it's time to look at the pokecrystal.sym
file. You can find this file here or by building the project with make
. Search the name/label you found earlier in this file to find a line that looks like this:
14:5424 BaseData
In this line, 14 refers to the bankNumber and 5424 is an offset value. Both are hexadecimal. But hold on, you're not done yet!
To get the absolute ROM offset, you need to do this calculation:
romOffset = (bankNumber * $4000) + (offset - $4000)
Let me explain: the offset you found earlier is the memory address the data you searched for AFTER it has been mapped to the bank 1 address space in the gameboys' memory. Bank 1 is always mapped to $4000-$8000 on the gameboy. So to calculate the actual offset inside the rom file, you need to subtract with $4000 and add the bank offset to get the absolute rom file offset.
If we apply this calculation to the BaseData
example earlier, it looks like this:
($14 * $4000) + ($5424 - $4000) = $51424
So 0x51424 would be the absolute ROM offset you'd be looking for.
Happy hacking!