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.
This commit is contained in:
RocketRobz 2020-08-20 08:07:00 -06:00
parent e14ba20cbe
commit e708b51d6d
3 changed files with 35 additions and 28 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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);
}