From e708b51d6d80ce5c273817c5a0aa8df3b7f7eda7 Mon Sep 17 00:00:00 2001 From: RocketRobz Date: Thu, 20 Aug 2020 08:07:00 -0600 Subject: [PATCH] DS(i): Improve emulator check DS header is now grabbed from GBA slot by ARM7, to avoid crashes. Also mount NitroFS in order of how fast data is accessible. --- nds/arm7/source/main.c | 6 ++++- nds/arm9/source/gfx.cpp | 2 +- nds/arm9/source/nitrofs.c | 55 +++++++++++++++++++++------------------ 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/nds/arm7/source/main.c b/nds/arm7/source/main.c index 38c996a..5e0e6f6 100644 --- a/nds/arm7/source/main.c +++ b/nds/arm7/source/main.c @@ -55,7 +55,11 @@ void powerButtonCB() { int main() { //--------------------------------------------------------------------------------- // nocashMessage("ARM7 main.c main"); - + + // Grab from DS header in GBA slot + *(u16*)0x02FFFC36 = *(u16*)0x0800015E; // Header CRC16 + *(u32*)0x02FFFC38 = *(u32*)0x0800000C; // Game Code + // clear sound registers dmaFillWords(0, (void*)0x04000400, 0x100); diff --git a/nds/arm9/source/gfx.cpp b/nds/arm9/source/gfx.cpp index bff52d4..bda38d0 100644 --- a/nds/arm9/source/gfx.cpp +++ b/nds/arm9/source/gfx.cpp @@ -63,7 +63,7 @@ extern int characterLimit; void GFX::loadSheets() { if (!isDSiMode()) { - sysSetCartOwner (BUS_OWNER_ARM9); // Allow arm9 to access GBA ROM (or in this case, the DS Memory Expansion Pak) + //sysSetCartOwner (BUS_OWNER_ARM9); // Allow arm9 to access GBA ROM (or in this case, the DS Memory Expansion Pak) *(vu32*)(0x08240000) = 1; if (*(vu32*)(0x08240000) == 1) { charSpriteMem3 = (u16*)0x09000000; diff --git a/nds/arm9/source/nitrofs.c b/nds/arm9/source/nitrofs.c index 920c81f..b52a0c8 100644 --- a/nds/arm9/source/nitrofs.c +++ b/nds/arm9/source/nitrofs.c @@ -137,6 +137,35 @@ nitroFSInit(const char *ndsfile) chdirpathid = NITROROOT; ndsFileLastpos = 0; ndsFile = NULL; + bool noLoader = ((strncmp((const char *)0x02FFFC38, __NDSHeader->gameCode, 4) == 0) + && (*(u16*)0x02FFFC36 == __NDSHeader->headerCRC16)); + if (!isDSiMode() || noLoader) + { + sysSetCartOwner (BUS_OWNER_ARM9); //give us gba slot ownership + if ((strncmp(((const char *)GBAROM) + LOADERSTROFFSET, LOADERSTR, strlen(LOADERSTR)) == 0) || noLoader) + { // We has gba rahm + //printf("yes i think this is GBA?!\n"); + if ((strncmp(((const char *)GBAROM) + 0x20C, __NDSHeader->gameCode, 4) == 0) + && (*(u16*)0x0800035E == __NDSHeader->headerCRC16)) + { //Look for second magic string, if found its a sc.nds or nds.gba + //printf("sc/gba\n"); + fntOffset = ((u32) * (u32 *)(((const char *)GBAROM) + FNTOFFSET + LOADEROFFSET)) + LOADEROFFSET; + fatOffset = ((u32) * (u32 *)(((const char *)GBAROM) + FATOFFSET + LOADEROFFSET)) + LOADEROFFSET; + hasLoader = true; + AddDevice(&nitroFSdevoptab); + return (1); + } + else + { //Ok, its not a .gba build, so must be emulator + //printf("gba, must be emu\n"); + fntOffset = ((u32) * (u32 *)(((const char *)GBAROM) + FNTOFFSET)); + fatOffset = ((u32) * (u32 *)(((const char *)GBAROM) + FATOFFSET)); + hasLoader = false; + AddDevice(&nitroFSdevoptab); + return (1); + } + } + } if (ndsfile != NULL) { if ((ndsFile = fopen(ndsfile, "rb"))) @@ -165,32 +194,6 @@ nitroFSInit(const char *ndsfile) return (1); } } - if (!isDSiMode() || PersonalData->name[0]==0 /* Regular NO$GBA */ || strncmp((const char*)0x4FFFA00, "no$gba", 6) == 0) { - sysSetCartOwner (BUS_OWNER_ARM9); //give us gba slot ownership - if ((strncmp(((const char *)GBAROM) + LOADERSTROFFSET, LOADERSTR, strlen(LOADERSTR)) == 0) - || (strncmp(((const char *)GBAROM) + 0xC, __NDSHeader->gameCode, 4) == 0)) - { // We has gba rahm - //printf("yes i think this is GBA?!\n"); - if (strncmp(((const char *)GBAROM) + LOADERSTROFFSET + LOADEROFFSET, LOADERSTR, strlen(LOADERSTR)) == 0) - { //Look for second magic string, if found its a sc.nds or nds.gba - //printf("sc/gba\n"); - fntOffset = ((u32) * (u32 *)(((const char *)GBAROM) + FNTOFFSET + LOADEROFFSET)) + LOADEROFFSET; - fatOffset = ((u32) * (u32 *)(((const char *)GBAROM) + FATOFFSET + LOADEROFFSET)) + LOADEROFFSET; - hasLoader = true; - AddDevice(&nitroFSdevoptab); - return (1); - } - else - { //Ok, its not a .gba build, so must be emulator - //printf("gba, must be emu\n"); - fntOffset = ((u32) * (u32 *)(((const char *)GBAROM) + FNTOFFSET)); - fatOffset = ((u32) * (u32 *)(((const char *)GBAROM) + FATOFFSET)); - hasLoader = false; - AddDevice(&nitroFSdevoptab); - return (1); - } - } - } return (0); }