#44600 - Darkain - Fri Jun 03, 2005 9:37 am
dispite the topic mentioning GBA, this is indeed specific to, and only to, the Nintendo DS.
DONT DIRECTLY WRITE TO GBA SAVERAM IN YOUR NDS CODE WITHOUT FIRST CHECKING TO MAKE SURE IT IS OK
here is the basic hypothetical situation that was brought up in #dsdev the other night... lets say you have a commercial GBA cart inside of your DS, and you WMB (wireless multi-boot) a NDS demo using WifiMe to the DS. This demo supports saving high scores to the GBA cart... WOOPSIES!! there goes your commercial game's save data!!!
DesktopMan and I discussed this for a bit, and agreed upon a common sollution to fix this problem. You should read from the data area on the cart first and make a simple check. At byte offset 0x080000AC, there is a 4 byte non-null terminating string containing the value "PASS". this, from here on forward, will be considered as STANDARD PRACTICE for ALL .NDS loader bootstraps from gba cart. Here is a basic example of a check to see if it is indeed a flashcart sporting a homebrew nds loader:
This value should be checked EVERY SINGLE TIME you try to write data to the saveram, just in case the user swapped carts during usage.
By default in DevKitARM/PRO r12 (i'm not sure about latest CVS tho), the CRT0 was accidently setup incorrectly for the ARM9 CPU. It provented you from writing to saveram all together. I now personally see this as a somewhat GOOD thing just to make sure bad things dont happen. This is very easy to fix. In the file DevKitArm/arm-elf/lib/ds_arm9_crt0.s, line 132 contains the "DAccess" restrictions (big ass PDF explaining in detail what it means). This value should be changed to 0x36033333 to allow read/write access to the GBA Saveram in both usr and svc mode. This also allows for writing to gba data cart addresses, which is helpful for access cart registers for page flipping and flashing from the unit itself. here is what the crt0 section should look like:
Once this modification has been made, you will need to recompile the CRT file. This can be done by opening a console window and going to devkitarm/arm-elf/lib, and then typing in make CRT=ds_arm9. from here, you should get an output like this:
_________________
-=- Darkain Dragoon -=-
http://www.darkain.com
DarkStar for Nintendo DS
DONT DIRECTLY WRITE TO GBA SAVERAM IN YOUR NDS CODE WITHOUT FIRST CHECKING TO MAKE SURE IT IS OK
here is the basic hypothetical situation that was brought up in #dsdev the other night... lets say you have a commercial GBA cart inside of your DS, and you WMB (wireless multi-boot) a NDS demo using WifiMe to the DS. This demo supports saving high scores to the GBA cart... WOOPSIES!! there goes your commercial game's save data!!!
DesktopMan and I discussed this for a bit, and agreed upon a common sollution to fix this problem. You should read from the data area on the cart first and make a simple check. At byte offset 0x080000AC, there is a 4 byte non-null terminating string containing the value "PASS". this, from here on forward, will be considered as STANDARD PRACTICE for ALL .NDS loader bootstraps from gba cart. Here is a basic example of a check to see if it is indeed a flashcart sporting a homebrew nds loader:
Code: |
if (memcmp((void*)0x080000AC, "PASS", 4) == 0) {
SaveMyGame(); } |
This value should be checked EVERY SINGLE TIME you try to write data to the saveram, just in case the user swapped carts during usage.
By default in DevKitARM/PRO r12 (i'm not sure about latest CVS tho), the CRT0 was accidently setup incorrectly for the ARM9 CPU. It provented you from writing to saveram all together. I now personally see this as a somewhat GOOD thing just to make sure bad things dont happen. This is very easy to fix. In the file DevKitArm/arm-elf/lib/ds_arm9_crt0.s, line 132 contains the "DAccess" restrictions (big ass PDF explaining in detail what it means). This value should be changed to 0x36033333 to allow read/write access to the GBA Saveram in both usr and svc mode. This also allows for writing to gba data cart addresses, which is helpful for access cart registers for page flipping and flashing from the unit itself. here is what the crt0 section should look like:
Code: |
@-------------------------------------------------------------------------
@ IAccess @------------------------------------------------------------------------- ldr r0,=0x06606333 mcr p15, 0, r0, c5, c0, 3 @------------------------------------------------------------------------- @ DAccess @------------------------------------------------------------------------- ldr r0,=0x36033333 mcr p15, 0, r0, c5, c0, 2 |
Once this modification has been made, you will need to recompile the CRT file. This can be done by opening a console window and going to devkitarm/arm-elf/lib, and then typing in make CRT=ds_arm9. from here, you should get an output like this:
Quote: |
C:\devkitarm\arm-elf\lib>make CRT=ds_arm9
arm-elf-gcc -x assembler-with-cpp -marm -c ds_arm9_crt0.s -ods_arm9_crt0.o arm-elf-gcc -x assembler-with-cpp -marm -mthumb-interwork -c ds_arm9_crt0.s -o interwork/ds_arm9_crt0.o arm-elf-gcc -x assembler-with-cpp -mthumb -c ds_arm9_crt0.s -o thumb/ds_arm9_cr t0.o arm-elf-gcc -x assembler-with-cpp -mthumb -mthumb-interwork -c ds_arm9_crt0.s - o thumb/interwork/ds_arm9_crt0.o C:\devkitarm\arm-elf\lib> |
_________________
-=- Darkain Dragoon -=-
http://www.darkain.com
DarkStar for Nintendo DS