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.

DS development > [help] How to write a program to load a rom then execute it?

#62662 - robot - Sun Dec 04, 2005 3:31 am

Can anyone show me the steps that a program sould do to load a rom from SuperCard (CF or SD) then execute it just like the SC shell does.

I already know how to use SuperCard I/O routines to read and write data from SC card.

Thank you in advance.

#62666 - Dwedit - Sun Dec 04, 2005 5:23 am

I'm guessing you would read 256k off the card, disable the CF interface and enable the RAM, write 256k, then repeat. To run it, jump to the ram. Not sure if you need to set the stack pointer first or not. Maybe instead of jumping, use the SWI reset call.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#62668 - tepples - Sun Dec 04, 2005 5:27 am

You may need to set up the virtual memory registers in the way that the program expects. Failure to do this is part of why the GBAMP can't run WMB demos.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#62773 - robot - Mon Dec 05, 2005 5:27 pm

It's me again, after take two days trial and error, I still can't make it.

I have load a rom into memory from SC SD, but I can't make it run.

Does a NDS rom (execution file) has some kind of relocation table, just like DOS or Windows execution file? Or I need to put the rom to specific address?

Can anyone give me some example with full or part of source code? Even the example not designed for SC SD is also appreciated.

Many thanks in advance.

#62775 - natrium42 - Mon Dec 05, 2005 5:41 pm

robot wrote:

Can anyone give me some example with full or part of source code? Even the example not designed for SC SD is also appreciated.

There is Darkain's Multi-NDS source in ndslib (note: not in libnds). Also, you could look at ndsmall loader source (in assembly) in the libnds CVS.

The steps involved in loading a NDS:
1. Clear memory
2. Copy ARM7 and ARM9 binaries into memory
3. Reset all registers to "initial" values (the hard part)
4. Direct ARM9 to the entry point in ARM9 binary
5. Direct ARM7 to the entry point in ARM7 binary

There could be some problems with parts 4 and 5 because some homebrews might rely on a certain timing there. So you need a way to synchronize CPU cores somehow so that they jump to entry points at about the same time.
_________________
www.natrium42.com

#62783 - robot - Mon Dec 05, 2005 6:57 pm

natrium42 wrote:

There is Darkain's Multi-NDS source in ndslib (note: not in libnds). Also, you could look at ndsmall loader source (in assembly) in the libnds CVS.

The steps involved in loading a NDS:
1. Clear memory
2. Copy ARM7 and ARM9 binaries into memory
3. Reset all registers to "initial" values (the hard part)
4. Direct ARM9 to the entry point in ARM9 binary
5. Direct ARM7 to the entry point in ARM7 binary

There could be some problems with parts 4 and 5 because some homebrews might rely on a certain timing there. So you need a way to synchronize CPU cores somehow so that they jump to entry points at about the same time.


Thanks, this information helps alot.

#62805 - chishm - Tue Dec 06, 2005 12:00 am

You may want to check out my GBAMP firmware replacement.

It is based on Darkain's loader, but I have fixed a few things with it. It also uses CF cards, so that is closer to what you want. In fact, all that is really needed to make it compatible is to change the CRT0 to remove the GBAMP stuff and then change the CF routines to SD routines
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com


Last edited by chishm on Mon Mar 20, 2006 3:23 am; edited 1 time in total

#62866 - robot - Tue Dec 06, 2005 4:26 pm

chishm wrote:
You may want to check out my GBAMP firmware replacement.

It is based on Darkain's loader, but I have fixed a few things with it. It also uses CF cards, so that is closer to what you want. In fact, all that is really needed to make it compatible is to change the CRT0 to remove the GBAMP stuff and then change the CF routines to SD routines


Thanks, this information is very useful. I have downloaded latest NDSLIB and devkitPro from sourceforge CVS.