fix up DSi direct boot

This commit is contained in:
Arisotura 2022-10-28 21:31:51 +02:00
parent 561781b954
commit 4ef2e1f4cc
2 changed files with 122 additions and 90 deletions

View File

@ -368,8 +368,6 @@ void SetupDirectBoot()
if (!(NDSCart::Header.UnitCode & 0x02)) if (!(NDSCart::Header.UnitCode & 0x02))
dsmode = true; dsmode = true;
// TODO: RAM size!!
if (dsmode) if (dsmode)
{ {
SCFG_BIOS = 0x0303; SCFG_BIOS = 0x0303;
@ -446,62 +444,35 @@ void SetupDirectBoot()
DSi_SPI_TSC::SetMode(0x00); DSi_SPI_TSC::SetMode(0x00);
} }
u32 arm9start = 0; // setup main RAM data
// TODO: verify what changes when loading a DS-mode ROM
// load the ARM9 secure area if (dsmode)
if (NDSCart::Header.ARM9ROMOffset >= 0x4000 && NDSCart::Header.ARM9ROMOffset < 0x8000)
{ {
u8 securearea[0x800]; for (u32 i = 0; i < 0x170; i+=4)
NDSCart::DecryptSecureArea(securearea);
for (u32 i = 0; i < 0x800; i+=4)
{ {
ARM9Write32(NDSCart::Header.ARM9RAMAddress+i, *(u32*)&securearea[i]); u32 tmp = *(u32*)&NDSCart::CartROM[i];
arm9start += 4; ARM9Write32(0x027FFE00+i, tmp);
}
} }
for (u32 i = arm9start; i < NDSCart::Header.ARM9Size; i+=4) ARM9Write32(0x027FF800, NDSCart::CartID);
{ ARM9Write32(0x027FF804, NDSCart::CartID);
u32 tmp = *(u32*)&NDSCart::CartROM[NDSCart::Header.ARM9ROMOffset+i]; ARM9Write16(0x027FF808, NDSCart::Header.HeaderCRC16);
ARM9Write32(NDSCart::Header.ARM9RAMAddress+i, tmp); ARM9Write16(0x027FF80A, NDSCart::Header.SecureAreaCRC16);
ARM9Write16(0x027FF850, 0x5835);
ARM9Write32(0x027FFC00, NDSCart::CartID);
ARM9Write32(0x027FFC04, NDSCart::CartID);
ARM9Write16(0x027FFC08, NDSCart::Header.HeaderCRC16);
ARM9Write16(0x027FFC0A, NDSCart::Header.SecureAreaCRC16);
ARM9Write16(0x027FFC10, 0x5835);
ARM9Write16(0x027FFC30, 0xFFFF);
ARM9Write16(0x027FFC40, 0x0001);
} }
else
for (u32 i = 0; i < NDSCart::Header.ARM7Size; i+=4)
{ {
u32 tmp = *(u32*)&NDSCart::CartROM[NDSCart::Header.ARM7ROMOffset+i];
ARM7Write32(NDSCart::Header.ARM7RAMAddress+i, tmp);
}
if ((!dsmode) && (NDSCart::Header.DSiCryptoFlags & (1<<0)))
{
// load DSi-specific regions
for (u32 i = 0; i < NDSCart::Header.DSiARM9iSize; i+=4)
{
u32 tmp = *(u32*)&NDSCart::CartROM[NDSCart::Header.DSiARM9iROMOffset+i];
ARM9Write32(NDSCart::Header.DSiARM9iRAMAddress+i, tmp);
}
for (u32 i = 0; i < NDSCart::Header.DSiARM7iSize; i+=4)
{
u32 tmp = *(u32*)&NDSCart::CartROM[NDSCart::Header.DSiARM7iROMOffset+i];
ARM7Write32(NDSCart::Header.DSiARM7iRAMAddress+i, tmp);
}
// decrypt any modcrypt areas
if (NDSCart::Header.DSiCryptoFlags & (1<<1))
{
DecryptModcryptArea(NDSCart::Header.DSiModcrypt1Offset,
NDSCart::Header.DSiModcrypt1Size,
NDSCart::Header.DSiARM9Hash);
DecryptModcryptArea(NDSCart::Header.DSiModcrypt2Offset,
NDSCart::Header.DSiModcrypt2Size,
NDSCart::Header.DSiARM7Hash);
}
}
// CHECKME: some of these are 'only for NDS ROM', presumably // CHECKME: some of these are 'only for NDS ROM', presumably
// only for when loading a cart? (as opposed to DSiWare) // only for when loading a cart? (as opposed to DSiWare)
@ -567,6 +538,65 @@ void SetupDirectBoot()
ARM9Write8(0x02FFFDFA, DSi_BPTWL::GetBootFlag() | 0x80); ARM9Write8(0x02FFFDFA, DSi_BPTWL::GetBootFlag() | 0x80);
ARM9Write8(0x02FFFDFB, 0x01); ARM9Write8(0x02FFFDFB, 0x01);
}
// TODO: for DS-mode ROMs, switch RAM size here
u32 arm9start = 0;
// load the ARM9 secure area
if (NDSCart::Header.ARM9ROMOffset >= 0x4000 && NDSCart::Header.ARM9ROMOffset < 0x8000)
{
u8 securearea[0x800];
NDSCart::DecryptSecureArea(securearea);
for (u32 i = 0; i < 0x800; i+=4)
{
ARM9Write32(NDSCart::Header.ARM9RAMAddress+i, *(u32*)&securearea[i]);
arm9start += 4;
}
}
for (u32 i = arm9start; i < NDSCart::Header.ARM9Size; i+=4)
{
u32 tmp = *(u32*)&NDSCart::CartROM[NDSCart::Header.ARM9ROMOffset+i];
ARM9Write32(NDSCart::Header.ARM9RAMAddress+i, tmp);
}
for (u32 i = 0; i < NDSCart::Header.ARM7Size; i+=4)
{
u32 tmp = *(u32*)&NDSCart::CartROM[NDSCart::Header.ARM7ROMOffset+i];
ARM7Write32(NDSCart::Header.ARM7RAMAddress+i, tmp);
}
if ((!dsmode) && (NDSCart::Header.DSiCryptoFlags & (1<<0)))
{
// load DSi-specific regions
for (u32 i = 0; i < NDSCart::Header.DSiARM9iSize; i+=4)
{
u32 tmp = *(u32*)&NDSCart::CartROM[NDSCart::Header.DSiARM9iROMOffset+i];
ARM9Write32(NDSCart::Header.DSiARM9iRAMAddress+i, tmp);
}
for (u32 i = 0; i < NDSCart::Header.DSiARM7iSize; i+=4)
{
u32 tmp = *(u32*)&NDSCart::CartROM[NDSCart::Header.DSiARM7iROMOffset+i];
ARM7Write32(NDSCart::Header.DSiARM7iRAMAddress+i, tmp);
}
// decrypt any modcrypt areas
if (NDSCart::Header.DSiCryptoFlags & (1<<1))
{
DecryptModcryptArea(NDSCart::Header.DSiModcrypt1Offset,
NDSCart::Header.DSiModcrypt1Size,
NDSCart::Header.DSiARM9Hash);
DecryptModcryptArea(NDSCart::Header.DSiModcrypt2Offset,
NDSCart::Header.DSiModcrypt2Size,
NDSCart::Header.DSiARM7Hash);
}
}
NDS::ARM7BIOSProt = 0x20; NDS::ARM7BIOSProt = 0x20;

View File

@ -385,6 +385,30 @@ void SetupDirectBoot(std::string romname)
{ {
MapSharedWRAM(3); MapSharedWRAM(3);
// setup main RAM data
for (u32 i = 0; i < 0x170; i+=4)
{
u32 tmp = *(u32*)&NDSCart::CartROM[i];
ARM9Write32(0x027FFE00+i, tmp);
}
ARM9Write32(0x027FF800, NDSCart::CartID);
ARM9Write32(0x027FF804, NDSCart::CartID);
ARM9Write16(0x027FF808, NDSCart::Header.HeaderCRC16);
ARM9Write16(0x027FF80A, NDSCart::Header.SecureAreaCRC16);
ARM9Write16(0x027FF850, 0x5835);
ARM9Write32(0x027FFC00, NDSCart::CartID);
ARM9Write32(0x027FFC04, NDSCart::CartID);
ARM9Write16(0x027FFC08, NDSCart::Header.HeaderCRC16);
ARM9Write16(0x027FFC0A, NDSCart::Header.SecureAreaCRC16);
ARM9Write16(0x027FFC10, 0x5835);
ARM9Write16(0x027FFC30, 0xFFFF);
ARM9Write16(0x027FFC40, 0x0001);
u32 arm9start = 0; u32 arm9start = 0;
// load the ARM9 secure area // load the ARM9 secure area
@ -414,28 +438,6 @@ void SetupDirectBoot(std::string romname)
ARM7Write32(NDSCart::Header.ARM7RAMAddress+i, tmp); ARM7Write32(NDSCart::Header.ARM7RAMAddress+i, tmp);
} }
for (u32 i = 0; i < 0x170; i+=4)
{
u32 tmp = *(u32*)&NDSCart::CartROM[i];
ARM9Write32(0x027FFE00+i, tmp);
}
ARM9Write32(0x027FF800, NDSCart::CartID);
ARM9Write32(0x027FF804, NDSCart::CartID);
ARM9Write16(0x027FF808, NDSCart::Header.HeaderCRC16);
ARM9Write16(0x027FF80A, NDSCart::Header.SecureAreaCRC16);
ARM9Write16(0x027FF850, 0x5835);
ARM9Write32(0x027FFC00, NDSCart::CartID);
ARM9Write32(0x027FFC04, NDSCart::CartID);
ARM9Write16(0x027FFC08, NDSCart::Header.HeaderCRC16);
ARM9Write16(0x027FFC0A, NDSCart::Header.SecureAreaCRC16);
ARM9Write16(0x027FFC10, 0x5835);
ARM9Write16(0x027FFC30, 0xFFFF);
ARM9Write16(0x027FFC40, 0x0001);
ARM7BIOSProt = 0x1204; ARM7BIOSProt = 0x1204;
SPI_Firmware::SetupDirectBoot(false); SPI_Firmware::SetupDirectBoot(false);