gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Question about the gba rom file format

#1301 - isildur - Thu Jan 16, 2003 4:28 pm

Hello,

I have made myself a dumb cable to load gba roms in a real GBA. It works fine. For roms to be loaded by the link port, the start address of code must be 0x02000000 instead of 0x08000000. How can I change that with roms that are already compiled? Where can I find info on the gba rom file format, so I could just patch the rom with the 0x02000000 value.
First of all, is this possible, will it work? Or does it only work with roms compiled for multiboot...

#1302 - Splam - Thu Jan 16, 2003 4:36 pm

It will probably only work for roms compiled for multiboot ie roms that are less than 256k. Not entirely sure on what you've done but if a rom is compiled normally it will expect to be located at 0x8000000 (as you know), if you try to load it to 0x2000000 then a) thats where ram is so the file would have to be less than 256k b) thats where variables etc are put (ok, not ALWAYS before anyone says :P ) so if it's not expecting to be there it will overtwrite itseld with those variables and crash.

Also (someone correct me if I'm missing something obvious here) there isn't a "load" address in the rom format (check your cart header file, may be called rom_header) because it presumes the cart is located at 0x8000000, multiboot "games" are sent from 1 cart to another gba without the cart and it's the communication software in the bios that loads it to ram. Multiboot transfer stuff for gba (for homebrew) just takes advantage of the same functionality.

#1303 - isildur - Thu Jan 16, 2003 4:53 pm

Thanks for the reply.

There must be a way to just change the rom file header to tell gba to load the code at 0x02000000 instead of 0x08000000.

Any information on the gba file format?

isildur

#1319 - Splam - Thu Jan 16, 2003 6:25 pm

Sorry but why MUST there be a way? As I said , if you put a cart in the gba it will boot from 0x8000000 (the bios does this) if there is no cart it listens to the link cable port for a signal saying another gba is sending to it, if it finds this signal it will transfer the file being sent from the other gba to 0x2000000 because that's the only place it has to put it.

The rom header contains the following

32bit branch instruction (to skip the rest of the rom info)
The nintendo logo
12 byte rom name (the games name)
32bit Code (region stuff I think)
16bit maker code (given to companies by Nintendo)
byte 0x96 (not totally sure what thats for)
byte Main unit code (hmm)
byte Device type
7bytes of 0x00 Reserved
byte software version number (eg version or revision number)
byte checksum
2bytes 0x00 reserved

No load address in there.

#1322 - isildur - Thu Jan 16, 2003 6:55 pm

Ok, I understand that part. But how come rom files compiled with code start at 0x08000000 do not work when sent to the link port? The same rom compiled with code start at 0x02000000 will work. The fact that a rom is compiled with different start addresses makes a difference. So there must be something different in the file.

#1324 - Splam - Thu Jan 16, 2003 7:08 pm

There are lots of reasons for code compiled for rom not to work at 0x200000

There are variables or even instructions that will hold addresses that aren't relative to the program counter, therefore a game will try to read something from somewhere in rom, if it's loaded somewhere else that data won't be there. That's whats different in the file. If you had the map file from the compiler then you could probably write a relocater, but you don't so you can't ;)

I explained a few more reasons in my 1st post such as the ram allocation, if the code is compiled for rom execution it knows all of ram is free (also you have iwram free) if you then just try to execute the same code from ram the 1st thing it will do is try to put its variables in ram which hasn't been reserved for such use.

#1325 - isildur - Thu Jan 16, 2003 7:11 pm

Ok, I see... well thanks for the info!

#1331 - Splam - Thu Jan 16, 2003 8:41 pm

hehe you don't sound too sure ;) If you're still unsure then please say so, sometimes my explanations are based on what I think is a reasonable level of knowledge and if you've not come across things such relocating code b4 then you may have no idea what I'm talking about. If thats the case I'll do an example for you.

#1334 - Splam - Thu Jan 16, 2003 8:44 pm

ignore. double post.

#1347 - isildur - Thu Jan 16, 2003 10:32 pm

Splam wrote:
and if you've not come across things such relocating code b4 then you may have no idea what I'm talking about. If thats the case I'll do an example for you.


Never done that for the ARM, but played with such stuff in win32 PE format.

What I wanted to do was to be able to load roms (<256k) that were not compiled for multiboot, in the GBA. I thought maybe that by modifying the rom file, I could make them load in the GBA through the link port. There are some nice demos out there (for which I don't have the source) that I would like to try on the GBA instead of an emulator.

If you have ideas... ;-)

isildur

#1354 - tepples - Thu Jan 16, 2003 11:48 pm

Some of the demos, even though they may use only 256 KB of ROM (such as the Farbrausch fr018 demo), still probably use all of EWRAM as temporary storage for e.g. compressed data or lookup tables calculated during less-complex parts of the demo (a common technique in Farbrausch demos). Simply changing all the addresses in such a program to point at 0x02000000 rather than 0x08000000 will cause the program to overwrite itself.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.