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 > Loading Attached ROMs

#25452 - Krakken - Mon Aug 23, 2004 8:37 am

I have a question regarding execution of a GBA game. Say for example, I have a ROM with a list of other roms that are attached to the main ROM (like a flash cart menu), how would I execute one of those attached ROMs from the main ROM and then later get back to the main ROM without reset?

Thanks.

#25453 - DKL - Mon Aug 23, 2004 9:24 am

You mean other GBA roms ? Then the "simplest" way would be to link your
overlay roms with a modified linker script, where rom base would be
0x8000000+(size_of_previous_roms) and stacks starting a little lower in memory to
keep values for your main menu. To call them it would be basically just jumps at
the right address, keeping sp at the right place. To come back, you need to jump
to a part of the base rom code that will rebuild the menu, rebuild gfx, reset
interrupt handler address, etc. based on values in the stack. You need the roms
sources to relink them.

Flash carts are using memory mapping techniques, to make the roms think they are
at 0x8000000. So they don't need to relink the roms. But if you intend to use
these techniques, you'll have the same problems as Pogoshell, incompatibilities
between carts. Good luck ! :)

Why do you want to do this ?

DKL

#25457 - Krakken - Mon Aug 23, 2004 11:33 am

I want to know for a number of reasons. Mainly so I can generally understand how it's done. It sparked my interest when tepples mentioned it for the new compo as a way of arranging the games.

#25468 - tepples - Mon Aug 23, 2004 7:00 pm

DKL wrote:
You need the roms sources to relink them.

Technically not; you need their object code.

This distinction matters because a proprietary program's object code may in a few cases be available to the owner of a Game Pak. See LGPL subsection 6c.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#25469 - DKL - Mon Aug 23, 2004 7:16 pm

tepples wrote:
DKL wrote:
You need the roms sources to relink them.

Technically not; you need their object code.

This distinction matters because a proprietary program's object code may in a few cases be available to the owner of a Game Pak. See LGPL subsection 6c.


Well, since anybody with a minimum programming experience know that, I didn't feel the need to make the distinction.

See BPFD subsection 3.9b, third paragraph... ;)

I'll choose my words next time... Thanks for your help.

Regards,
DKL

#67158 - Abscissa - Sun Jan 15, 2006 10:24 pm

I realize I'm bringing this back from the dead, but I'm just starting to do this, and I'm looking for some more clarification and details.

Does that approach DKL explained above involve:

A. A separate call to the linker for each ROM (obviously adjusting the start address in the linker script each time), and then some way to combine the resulting ROMs into one? (Possibly with another call to the linker? Or maybe something with objcopy?)

-or-

B. Taking the *.o files from each compiled-but-not-linked project and linking them all together (involving fancier adjustments to the linker script)?

-or-

C. Something altogether different from A or B.
_________________
Useless Rants a.k.a. My futile attempts at rationalizing my unreasonable reluctance to call my site a 'blog'.

#67211 - tepples - Mon Jan 16, 2006 6:40 am

Abscissa wrote:
I realize I'm bringing this back from the dead

"It is always better to post in an existing topic than to start a new one" (Posting and You (SWF)). Full point for Abscissa.

Quote:
Does that approach DKL explained above involve:

A. A separate call to the linker for each ROM (obviously adjusting the start address in the linker script each time)

This would be the simplest solution.

Quote:
and then some way to combine the resulting ROMs into one?

'padbin' (from GBFS) followed by either 'cat' or 'copy /b' should work nicely.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#67230 - Abscissa - Mon Jan 16, 2006 9:05 am

tepples wrote:
Quote:
and then some way to combine the resulting ROMs into one?

'padbin' (from GBFS) followed by either 'cat' or 'copy /b' should work nicely.


So you're saying basically just append the *.gba files back-to-back with each other, header and all as-is? And when the menu does a "jump" it should jump to the address just past the end of the desired appended ROM's GBA header?

Also, with "padbin" am I trying to allow the individual ROMS room to grow, or am I ensuring each ROM starts on a 32-bit boundary (or some other boundary)?
_________________
Useless Rants a.k.a. My futile attempts at rationalizing my unreasonable reluctance to call my site a 'blog'.

#67279 - tepples - Mon Jan 16, 2006 6:22 pm

Abscissa wrote:
So you're saying basically just append the *.gba files back-to-back with each other, header and all as-is?

That will work if each .gba file has been properly relocated by its link script.

Quote:
Also, with "padbin" am I trying to allow the individual ROMS room to grow

Yes, so that you don't have to rewrite your link scripts every time you get a new build from the developers. Remember that physical ROM chips come in power-of-2 sizes, and if you're trying to make a multicart, then you don't have to worry much about wasting space until you're brushing up against a power-of-2 size.

Quote:
or am I ensuring each ROM starts on a 32-bit boundary (or some other boundary)?

Some programs need to be aligned to specific boundaries. For instance, a program that uses appended GBFS needs its first GBFS file to be aligned to a 256-byte boundary because of a tradeoff in the linear search algorithm of find_first_gbfs_file().
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#67294 - Abscissa - Mon Jan 16, 2006 7:41 pm

I see, thanks :)

tepples wrote:
Some programs need to be aligned to specific boundaries. For instance, a program that uses appended GBFS needs its first GBFS file to be aligned to a 256-byte boundary because of a tradeoff in the linear search algorithm of find_first_gbfs_file().
I'm not working with a ROM that uses GBFS, but out of curiosity: Ignoring the multi-rom menu stuff, does GBFS automatically ensure the start of the first GBFS file is on an appropriate boundary?
_________________
Useless Rants a.k.a. My futile attempts at rationalizing my unreasonable reluctance to call my site a 'blog'.

#67296 - tepples - Mon Jan 16, 2006 8:00 pm

Abscissa wrote:
out of curiosity: Ignoring the multi-rom menu stuff, does GBFS automatically ensure the start of the first GBFS file is on an appropriate boundary?

If you include a 'padbin' line like in the GBFS example program's batch file, yes.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#67306 - Abscissa - Mon Jan 16, 2006 10:10 pm

Yay, it's working for me :) ! Thanks again.
_________________
Useless Rants a.k.a. My futile attempts at rationalizing my unreasonable reluctance to call my site a 'blog'.