make things work, sorta kinda (I lost track)
This commit is contained in:
parent
18c7629451
commit
cdff61c209
131
src/DSi.cpp
131
src/DSi.cpp
|
@ -47,8 +47,6 @@
|
||||||
namespace DSi
|
namespace DSi
|
||||||
{
|
{
|
||||||
|
|
||||||
u32 BootAddr[2];
|
|
||||||
|
|
||||||
u16 SCFG_BIOS;
|
u16 SCFG_BIOS;
|
||||||
u16 SCFG_Clock9;
|
u16 SCFG_Clock9;
|
||||||
u16 SCFG_Clock7;
|
u16 SCFG_Clock7;
|
||||||
|
@ -79,14 +77,9 @@ DSi_NDMA* NDMAs[8];
|
||||||
DSi_SDHost* SDMMC;
|
DSi_SDHost* SDMMC;
|
||||||
DSi_SDHost* SDIO;
|
DSi_SDHost* SDIO;
|
||||||
|
|
||||||
FILE* SDMMCFile = nullptr;
|
|
||||||
|
|
||||||
u64 ConsoleID;
|
u64 ConsoleID;
|
||||||
u8 eMMC_CID[16];
|
u8 eMMC_CID[16];
|
||||||
|
|
||||||
u8 ITCMInit[0x8000];
|
|
||||||
u8 ARM7Init[0x3C00];
|
|
||||||
|
|
||||||
|
|
||||||
void Set_SCFG_Clock9(u16 val);
|
void Set_SCFG_Clock9(u16 val);
|
||||||
|
|
||||||
|
@ -134,8 +127,6 @@ void DeInit()
|
||||||
|
|
||||||
delete SDMMC;
|
delete SDMMC;
|
||||||
delete SDIO;
|
delete SDIO;
|
||||||
|
|
||||||
CloseDSiNAND();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Reset()
|
void Reset()
|
||||||
|
@ -144,21 +135,24 @@ void Reset()
|
||||||
//NDS::ARM9->CP15Write(0x911, 0x00000020);
|
//NDS::ARM9->CP15Write(0x911, 0x00000020);
|
||||||
//NDS::ARM9->CP15Write(0x100, NDS::ARM9->CP15Read(0x100) | 0x00050000);
|
//NDS::ARM9->CP15Write(0x100, NDS::ARM9->CP15Read(0x100) | 0x00050000);
|
||||||
|
|
||||||
NDS::ARM9->JumpTo(BootAddr[0]);
|
NDS::MapSharedWRAM(3);
|
||||||
NDS::ARM7->JumpTo(BootAddr[1]);
|
|
||||||
|
|
||||||
NDMACnt[0] = 0; NDMACnt[1] = 0;
|
NDMACnt[0] = 0; NDMACnt[1] = 0;
|
||||||
for (int i = 0; i < 8; i++) NDMAs[i]->Reset();
|
for (int i = 0; i < 8; i++) NDMAs[i]->Reset();
|
||||||
|
|
||||||
memcpy(NDS::ARM9->ITCM, ITCMInit, 0x8000);
|
|
||||||
|
|
||||||
DSi_I2C::Reset();
|
DSi_I2C::Reset();
|
||||||
DSi_AES::Reset();
|
|
||||||
DSi_DSP::Reset();
|
DSi_DSP::Reset();
|
||||||
|
|
||||||
|
SDMMC->CloseHandles();
|
||||||
|
SDIO->CloseHandles();
|
||||||
|
|
||||||
|
LoadNAND();
|
||||||
|
|
||||||
SDMMC->Reset();
|
SDMMC->Reset();
|
||||||
SDIO->Reset();
|
SDIO->Reset();
|
||||||
|
|
||||||
|
DSi_AES::Reset();
|
||||||
|
|
||||||
SCFG_BIOS = 0x0101; // TODO: should be zero when booting from BIOS
|
SCFG_BIOS = 0x0101; // TODO: should be zero when booting from BIOS
|
||||||
SCFG_Clock9 = 0x0187; // CHECKME
|
SCFG_Clock9 = 0x0187; // CHECKME
|
||||||
SCFG_Clock7 = 0x0187;
|
SCFG_Clock7 = 0x0187;
|
||||||
|
@ -172,22 +166,6 @@ void Reset()
|
||||||
// LCD init flag
|
// LCD init flag
|
||||||
GPU::DispStat[0] |= (1<<6);
|
GPU::DispStat[0] |= (1<<6);
|
||||||
GPU::DispStat[1] |= (1<<6);
|
GPU::DispStat[1] |= (1<<6);
|
||||||
|
|
||||||
NDS::MapSharedWRAM(3);
|
|
||||||
|
|
||||||
for (u32 i = 0; i < 0x3C00; i+=4)
|
|
||||||
ARM7Write32(0x03FFC400+i, *(u32*)&ARM7Init[i]);
|
|
||||||
|
|
||||||
u32 eaddr = 0x03FFE6E4;
|
|
||||||
ARM7Write32(eaddr+0x00, *(u32*)&eMMC_CID[0]);
|
|
||||||
ARM7Write32(eaddr+0x04, *(u32*)&eMMC_CID[4]);
|
|
||||||
ARM7Write32(eaddr+0x08, *(u32*)&eMMC_CID[8]);
|
|
||||||
ARM7Write32(eaddr+0x0C, *(u32*)&eMMC_CID[12]);
|
|
||||||
ARM7Write16(eaddr+0x2C, 0x0001);
|
|
||||||
ARM7Write16(eaddr+0x2E, 0x0001);
|
|
||||||
ARM7Write16(eaddr+0x3C, 0x0100);
|
|
||||||
ARM7Write16(eaddr+0x3E, 0x40E0);
|
|
||||||
ARM7Write16(eaddr+0x42, 0x0001);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DecryptModcryptArea(u32 offset, u32 size, u8* iv)
|
void DecryptModcryptArea(u32 offset, u32 size, u8* iv)
|
||||||
|
@ -445,7 +423,10 @@ void SetupDirectBoot()
|
||||||
ARM9Write32(0x02FFE000+i, tmp);
|
ARM9Write32(0x02FFE000+i, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DSi_NAND::Init(SDMMCFile, &DSi::ARM7iBIOS[0x8308]))
|
FILE* nand = Platform::OpenLocalFile(Platform::GetConfigString(Platform::DSi_NANDPath), "r+b");
|
||||||
|
if (nand)
|
||||||
|
{
|
||||||
|
if (DSi_NAND::Init(nand, &DSi::ARM7iBIOS[0x8308]))
|
||||||
{
|
{
|
||||||
u8 userdata[0x1B0];
|
u8 userdata[0x1B0];
|
||||||
DSi_NAND::ReadUserData(userdata);
|
DSi_NAND::ReadUserData(userdata);
|
||||||
|
@ -465,6 +446,9 @@ void SetupDirectBoot()
|
||||||
DSi_NAND::DeInit();
|
DSi_NAND::DeInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fclose(nand);
|
||||||
|
}
|
||||||
|
|
||||||
u8 nwifiver = SPI_Firmware::GetNWifiVersion();
|
u8 nwifiver = SPI_Firmware::GetNWifiVersion();
|
||||||
ARM9Write8(0x020005E0, nwifiver);
|
ARM9Write8(0x020005E0, nwifiver);
|
||||||
|
|
||||||
|
@ -544,21 +528,28 @@ void SoftReset()
|
||||||
|
|
||||||
NDS::ARM9->CP15Reset();
|
NDS::ARM9->CP15Reset();
|
||||||
|
|
||||||
memcpy(NDS::ARM9->ITCM, ITCMInit, 0x8000);
|
NDS::MapSharedWRAM(3);
|
||||||
|
|
||||||
|
// FIXME!!!!!
|
||||||
|
//memcpy(NDS::ARM9->ITCM, ITCMInit, 0x8000);
|
||||||
|
|
||||||
DSi_AES::Reset();
|
|
||||||
// TODO: does the DSP get reset? NWRAM doesn't, so I'm assuming no
|
// TODO: does the DSP get reset? NWRAM doesn't, so I'm assuming no
|
||||||
// *HOWEVER*, the bootrom (which does get rerun) does remap NWRAM, and thus
|
// *HOWEVER*, the bootrom (which does get rerun) does remap NWRAM, and thus
|
||||||
// the DSP most likely gets reset
|
// the DSP most likely gets reset
|
||||||
DSi_DSP::Reset();
|
DSi_DSP::Reset();
|
||||||
|
|
||||||
|
SDMMC->CloseHandles();
|
||||||
|
SDIO->CloseHandles();
|
||||||
|
|
||||||
LoadNAND();
|
LoadNAND();
|
||||||
|
|
||||||
SDMMC->Reset();
|
SDMMC->Reset();
|
||||||
SDIO->Reset();
|
SDIO->Reset();
|
||||||
|
|
||||||
NDS::ARM9->JumpTo(BootAddr[0]);
|
DSi_AES::Reset();
|
||||||
NDS::ARM7->JumpTo(BootAddr[1]);
|
|
||||||
|
//NDS::ARM9->JumpTo(BootAddr[0]);
|
||||||
|
//NDS::ARM7->JumpTo(BootAddr[1]);
|
||||||
|
|
||||||
SCFG_BIOS = 0x0101; // TODO: should be zero when booting from BIOS
|
SCFG_BIOS = 0x0101; // TODO: should be zero when booting from BIOS
|
||||||
SCFG_Clock9 = 0x0187; // CHECKME
|
SCFG_Clock9 = 0x0187; // CHECKME
|
||||||
|
@ -575,10 +566,8 @@ void SoftReset()
|
||||||
GPU::DispStat[0] |= (1<<6);
|
GPU::DispStat[0] |= (1<<6);
|
||||||
GPU::DispStat[1] |= (1<<6);
|
GPU::DispStat[1] |= (1<<6);
|
||||||
|
|
||||||
NDS::MapSharedWRAM(3);
|
//for (u32 i = 0; i < 0x3C00; i+=4)
|
||||||
|
// ARM7Write32(0x03FFC400+i, *(u32*)&ARM7Init[i]);
|
||||||
for (u32 i = 0; i < 0x3C00; i+=4)
|
|
||||||
ARM7Write32(0x03FFC400+i, *(u32*)&ARM7Init[i]);
|
|
||||||
|
|
||||||
u32 eaddr = 0x03FFE6E4;
|
u32 eaddr = 0x03FFE6E4;
|
||||||
ARM7Write32(eaddr+0x00, *(u32*)&eMMC_CID[0]);
|
ARM7Write32(eaddr+0x00, *(u32*)&eMMC_CID[0]);
|
||||||
|
@ -650,7 +639,14 @@ bool LoadNAND()
|
||||||
{
|
{
|
||||||
printf("Loading DSi NAND\n");
|
printf("Loading DSi NAND\n");
|
||||||
|
|
||||||
if (!DSi_NAND::Init(SDMMCFile, &DSi::ARM7iBIOS[0x8308]))
|
FILE* nand = Platform::OpenLocalFile(Platform::GetConfigString(Platform::DSi_NANDPath), "r+b");
|
||||||
|
if (!nand)
|
||||||
|
{
|
||||||
|
printf("Failed to open DSi NAND\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!DSi_NAND::Init(nand, &DSi::ARM7iBIOS[0x8308]))
|
||||||
{
|
{
|
||||||
printf("Failed to load DSi NAND\n");
|
printf("Failed to load DSi NAND\n");
|
||||||
return false;
|
return false;
|
||||||
|
@ -676,8 +672,8 @@ bool LoadNAND()
|
||||||
memset(NWRAMMask, 0, sizeof(NWRAMMask));
|
memset(NWRAMMask, 0, sizeof(NWRAMMask));
|
||||||
|
|
||||||
u32 bootparams[8];
|
u32 bootparams[8];
|
||||||
fseek(SDMMCFile, 0x220, SEEK_SET);
|
fseek(nand, 0x220, SEEK_SET);
|
||||||
fread(bootparams, 4, 8, SDMMCFile);
|
fread(bootparams, 4, 8, nand);
|
||||||
|
|
||||||
printf("ARM9: offset=%08X size=%08X RAM=%08X size_aligned=%08X\n",
|
printf("ARM9: offset=%08X size=%08X RAM=%08X size_aligned=%08X\n",
|
||||||
bootparams[0], bootparams[1], bootparams[2], bootparams[3]);
|
bootparams[0], bootparams[1], bootparams[2], bootparams[3]);
|
||||||
|
@ -690,8 +686,8 @@ bool LoadNAND()
|
||||||
MBK[1][8] = 0;
|
MBK[1][8] = 0;
|
||||||
|
|
||||||
u32 mbk[12];
|
u32 mbk[12];
|
||||||
fseek(SDMMCFile, 0x380, SEEK_SET);
|
fseek(nand, 0x380, SEEK_SET);
|
||||||
fread(mbk, 4, 12, SDMMCFile);
|
fread(mbk, 4, 12, nand);
|
||||||
|
|
||||||
MapNWRAM_A(0, mbk[0] & 0xFF);
|
MapNWRAM_A(0, mbk[0] & 0xFF);
|
||||||
MapNWRAM_A(1, (mbk[0] >> 8) & 0xFF);
|
MapNWRAM_A(1, (mbk[0] >> 8) & 0xFF);
|
||||||
|
@ -745,12 +741,12 @@ bool LoadNAND()
|
||||||
|
|
||||||
AES_init_ctx_iv(&ctx, boot2key, boot2iv);
|
AES_init_ctx_iv(&ctx, boot2key, boot2iv);
|
||||||
|
|
||||||
fseek(SDMMCFile, bootparams[0], SEEK_SET);
|
fseek(nand, bootparams[0], SEEK_SET);
|
||||||
dstaddr = bootparams[2];
|
dstaddr = bootparams[2];
|
||||||
for (u32 i = 0; i < bootparams[3]; i += 16)
|
for (u32 i = 0; i < bootparams[3]; i += 16)
|
||||||
{
|
{
|
||||||
u8 data[16];
|
u8 data[16];
|
||||||
fread(data, 16, 1, SDMMCFile);
|
fread(data, 16, 1, nand);
|
||||||
|
|
||||||
for (int j = 0; j < 16; j++) tmp[j] = data[15-j];
|
for (int j = 0; j < 16; j++) tmp[j] = data[15-j];
|
||||||
AES_CTR_xcrypt_buffer(&ctx, tmp, 16);
|
AES_CTR_xcrypt_buffer(&ctx, tmp, 16);
|
||||||
|
@ -770,12 +766,12 @@ bool LoadNAND()
|
||||||
|
|
||||||
AES_init_ctx_iv(&ctx, boot2key, boot2iv);
|
AES_init_ctx_iv(&ctx, boot2key, boot2iv);
|
||||||
|
|
||||||
fseek(SDMMCFile, bootparams[4], SEEK_SET);
|
fseek(nand, bootparams[4], SEEK_SET);
|
||||||
dstaddr = bootparams[6];
|
dstaddr = bootparams[6];
|
||||||
for (u32 i = 0; i < bootparams[7]; i += 16)
|
for (u32 i = 0; i < bootparams[7]; i += 16)
|
||||||
{
|
{
|
||||||
u8 data[16];
|
u8 data[16];
|
||||||
fread(data, 16, 1, SDMMCFile);
|
fread(data, 16, 1, nand);
|
||||||
|
|
||||||
for (int j = 0; j < 16; j++) tmp[j] = data[15-j];
|
for (int j = 0; j < 16; j++) tmp[j] = data[15-j];
|
||||||
AES_CTR_xcrypt_buffer(&ctx, tmp, 16);
|
AES_CTR_xcrypt_buffer(&ctx, tmp, 16);
|
||||||
|
@ -787,11 +783,6 @@ bool LoadNAND()
|
||||||
ARM7Write32(dstaddr, *(u32*)&data[12]); dstaddr += 4;
|
ARM7Write32(dstaddr, *(u32*)&data[12]); dstaddr += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
// repoint the CPUs to the boot2 binaries
|
|
||||||
|
|
||||||
BootAddr[0] = bootparams[2];
|
|
||||||
BootAddr[1] = bootparams[6];
|
|
||||||
|
|
||||||
#define printhex(str, size) { for (int z = 0; z < (size); z++) printf("%02X", (str)[z]); printf("\n"); }
|
#define printhex(str, size) { for (int z = 0; z < (size); z++) printf("%02X", (str)[z]); printf("\n"); }
|
||||||
#define printhex_rev(str, size) { for (int z = (size)-1; z >= 0; z--) printf("%02X", (str)[z]); printf("\n"); }
|
#define printhex_rev(str, size) { for (int z = (size)-1; z >= 0; z--) printf("%02X", (str)[z]); printf("\n"); }
|
||||||
|
|
||||||
|
@ -800,18 +791,36 @@ bool LoadNAND()
|
||||||
printf("eMMC CID: "); printhex(eMMC_CID, 16);
|
printf("eMMC CID: "); printhex(eMMC_CID, 16);
|
||||||
printf("Console ID: %" PRIx64 "\n", ConsoleID);
|
printf("Console ID: %" PRIx64 "\n", ConsoleID);
|
||||||
|
|
||||||
memset(ITCMInit, 0, 0x8000);
|
u32 eaddr = 0x03FFE6E4;
|
||||||
memcpy(&ITCMInit[0x4400], &ARM9iBIOS[0x87F4], 0x400);
|
ARM7Write32(eaddr+0x00, *(u32*)&eMMC_CID[0]);
|
||||||
memcpy(&ITCMInit[0x4800], &ARM9iBIOS[0x9920], 0x80);
|
ARM7Write32(eaddr+0x04, *(u32*)&eMMC_CID[4]);
|
||||||
memcpy(&ITCMInit[0x4894], &ARM9iBIOS[0x99A0], 0x1048);
|
ARM7Write32(eaddr+0x08, *(u32*)&eMMC_CID[8]);
|
||||||
memcpy(&ITCMInit[0x58DC], &ARM9iBIOS[0xA9E8], 0x1048);
|
ARM7Write32(eaddr+0x0C, *(u32*)&eMMC_CID[12]);
|
||||||
|
ARM7Write16(eaddr+0x2C, 0x0001);
|
||||||
|
ARM7Write16(eaddr+0x2E, 0x0001);
|
||||||
|
ARM7Write16(eaddr+0x3C, 0x0100);
|
||||||
|
ARM7Write16(eaddr+0x3E, 0x40E0);
|
||||||
|
ARM7Write16(eaddr+0x42, 0x0001);
|
||||||
|
|
||||||
|
memcpy(&NDS::ARM9->ITCM[0x4400], &ARM9iBIOS[0x87F4], 0x400);
|
||||||
|
memcpy(&NDS::ARM9->ITCM[0x4800], &ARM9iBIOS[0x9920], 0x80);
|
||||||
|
memcpy(&NDS::ARM9->ITCM[0x4894], &ARM9iBIOS[0x99A0], 0x1048);
|
||||||
|
memcpy(&NDS::ARM9->ITCM[0x58DC], &ARM9iBIOS[0xA9E8], 0x1048);
|
||||||
|
|
||||||
|
u8 ARM7Init[0x3C00];
|
||||||
memset(ARM7Init, 0, 0x3C00);
|
memset(ARM7Init, 0, 0x3C00);
|
||||||
memcpy(&ARM7Init[0x0000], &ARM7iBIOS[0x8188], 0x200);
|
memcpy(&ARM7Init[0x0000], &ARM7iBIOS[0x8188], 0x200);
|
||||||
memcpy(&ARM7Init[0x0200], &ARM7iBIOS[0xB5D8], 0x40);
|
memcpy(&ARM7Init[0x0200], &ARM7iBIOS[0xB5D8], 0x40);
|
||||||
memcpy(&ARM7Init[0x0254], &ARM7iBIOS[0xC6D0], 0x1048);
|
memcpy(&ARM7Init[0x0254], &ARM7iBIOS[0xC6D0], 0x1048);
|
||||||
memcpy(&ARM7Init[0x129C], &ARM7iBIOS[0xD718], 0x1048);
|
memcpy(&ARM7Init[0x129C], &ARM7iBIOS[0xD718], 0x1048);
|
||||||
|
|
||||||
|
for (u32 i = 0; i < 0x3C00; i+=4)
|
||||||
|
ARM7Write32(0x03FFC400+i, *(u32*)&ARM7Init[i]);
|
||||||
|
|
||||||
|
// repoint the CPUs to the boot2 binaries
|
||||||
|
NDS::ARM9->JumpTo(bootparams[2]);
|
||||||
|
NDS::ARM7->JumpTo(bootparams[6]);
|
||||||
|
|
||||||
DSi_NAND::PatchUserData();
|
DSi_NAND::PatchUserData();
|
||||||
|
|
||||||
DSi_NAND::DeInit();
|
DSi_NAND::DeInit();
|
||||||
|
@ -819,12 +828,6 @@ bool LoadNAND()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CloseDSiNAND()
|
|
||||||
{
|
|
||||||
if (DSi::SDMMCFile)
|
|
||||||
fclose(DSi::SDMMCFile);
|
|
||||||
DSi::SDMMCFile = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RunNDMAs(u32 cpu)
|
void RunNDMAs(u32 cpu)
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,8 +39,6 @@ extern u64 ConsoleID;
|
||||||
extern DSi_SDHost* SDMMC;
|
extern DSi_SDHost* SDMMC;
|
||||||
extern DSi_SDHost* SDIO;
|
extern DSi_SDHost* SDIO;
|
||||||
|
|
||||||
extern FILE* SDMMCFile;
|
|
||||||
|
|
||||||
const u32 NWRAMSize = 0x40000;
|
const u32 NWRAMSize = 0x40000;
|
||||||
|
|
||||||
extern u8* NWRAM_A;
|
extern u8* NWRAM_A;
|
||||||
|
@ -65,8 +63,6 @@ void SoftReset();
|
||||||
bool LoadBIOS();
|
bool LoadBIOS();
|
||||||
bool LoadNAND();
|
bool LoadNAND();
|
||||||
|
|
||||||
void CloseDSiNAND();
|
|
||||||
|
|
||||||
void RunNDMAs(u32 cpu);
|
void RunNDMAs(u32 cpu);
|
||||||
void StallNDMAs();
|
void StallNDMAs();
|
||||||
bool NDMAsInMode(u32 cpu, u32 mode);
|
bool NDMAsInMode(u32 cpu, u32 mode);
|
||||||
|
|
|
@ -61,6 +61,14 @@ DSi_SDHost::~DSi_SDHost()
|
||||||
if (Ports[1]) delete Ports[1];
|
if (Ports[1]) delete Ports[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DSi_SDHost::CloseHandles()
|
||||||
|
{
|
||||||
|
if (Ports[0]) delete Ports[0];
|
||||||
|
if (Ports[1]) delete Ports[1];
|
||||||
|
Ports[0] = nullptr;
|
||||||
|
Ports[1] = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void DSi_SDHost::Reset()
|
void DSi_SDHost::Reset()
|
||||||
{
|
{
|
||||||
if (Num == 0)
|
if (Num == 0)
|
||||||
|
@ -101,10 +109,7 @@ void DSi_SDHost::Reset()
|
||||||
|
|
||||||
TXReq = false;
|
TXReq = false;
|
||||||
|
|
||||||
if (Ports[0]) delete Ports[0];
|
CloseHandles();
|
||||||
if (Ports[1]) delete Ports[1];
|
|
||||||
Ports[0] = nullptr;
|
|
||||||
Ports[1] = nullptr;
|
|
||||||
|
|
||||||
if (Num == 0)
|
if (Num == 0)
|
||||||
{
|
{
|
||||||
|
@ -131,7 +136,7 @@ void DSi_SDHost::Reset()
|
||||||
else
|
else
|
||||||
sd = nullptr;
|
sd = nullptr;
|
||||||
|
|
||||||
mmc = new DSi_MMCStorage(this, true, DSi::SDMMCFile);
|
mmc = new DSi_MMCStorage(this, true, Platform::GetConfigString(Platform::DSi_NANDPath));
|
||||||
mmc->SetCID(DSi::eMMC_CID);
|
mmc->SetCID(DSi::eMMC_CID);
|
||||||
|
|
||||||
Ports[0] = sd;
|
Ports[0] = sd;
|
||||||
|
@ -727,12 +732,15 @@ void DSi_SDHost::CheckSwapFIFO()
|
||||||
|
|
||||||
#define MMC_DESC (Internal?"NAND":"SDcard")
|
#define MMC_DESC (Internal?"NAND":"SDcard")
|
||||||
|
|
||||||
DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, FILE* file)
|
DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, std::string filename)
|
||||||
: DSi_SDDevice(host)
|
: DSi_SDDevice(host)
|
||||||
{
|
{
|
||||||
Internal = internal;
|
Internal = internal;
|
||||||
File = file;
|
File = Platform::OpenLocalFile(filename, "r+b");
|
||||||
|
printf("BLAGFARTED: %s -> %p\n", filename.c_str(), File);
|
||||||
SD = nullptr;
|
SD = nullptr;
|
||||||
|
|
||||||
|
ReadOnly = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, std::string filename, u64 size, bool readonly, std::string sourcedir)
|
DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, std::string filename, u64 size, bool readonly, std::string sourcedir)
|
||||||
|
@ -754,6 +762,10 @@ DSi_MMCStorage::~DSi_MMCStorage()
|
||||||
SD->Close();
|
SD->Close();
|
||||||
delete SD;
|
delete SD;
|
||||||
}
|
}
|
||||||
|
if (File)
|
||||||
|
{
|
||||||
|
fclose(File);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DSi_MMCStorage::Reset()
|
void DSi_MMCStorage::Reset()
|
||||||
|
|
|
@ -33,6 +33,7 @@ public:
|
||||||
DSi_SDHost(u32 num);
|
DSi_SDHost(u32 num);
|
||||||
~DSi_SDHost();
|
~DSi_SDHost();
|
||||||
|
|
||||||
|
void CloseHandles();
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
void DoSavestate(Savestate* file);
|
void DoSavestate(Savestate* file);
|
||||||
|
@ -122,7 +123,7 @@ protected:
|
||||||
class DSi_MMCStorage : public DSi_SDDevice
|
class DSi_MMCStorage : public DSi_SDDevice
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DSi_MMCStorage(DSi_SDHost* host, bool internal, FILE* file);
|
DSi_MMCStorage(DSi_SDHost* host, bool internal, std::string filename);
|
||||||
DSi_MMCStorage(DSi_SDHost* host, bool internal, std::string filename, u64 size, bool readonly, std::string sourcedir);
|
DSi_MMCStorage(DSi_SDHost* host, bool internal, std::string filename, u64 size, bool readonly, std::string sourcedir);
|
||||||
~DSi_MMCStorage();
|
~DSi_MMCStorage();
|
||||||
|
|
||||||
|
|
|
@ -565,7 +565,6 @@ void Reset()
|
||||||
if (ConsoleType == 1)
|
if (ConsoleType == 1)
|
||||||
{
|
{
|
||||||
DSi::LoadBIOS();
|
DSi::LoadBIOS();
|
||||||
DSi::LoadNAND();
|
|
||||||
|
|
||||||
ARM9ClockShift = 2;
|
ARM9ClockShift = 2;
|
||||||
MainRAMMask = 0xFFFFFF;
|
MainRAMMask = 0xFFFFFF;
|
||||||
|
@ -932,6 +931,11 @@ void EjectCart()
|
||||||
NDSCart::EjectCart();
|
NDSCart::EjectCart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CartInserted()
|
||||||
|
{
|
||||||
|
return NDSCart::CartInserted;
|
||||||
|
}
|
||||||
|
|
||||||
bool LoadGBACart(const u8* romdata, u32 romlen, const u8* savedata, u32 savelen)
|
bool LoadGBACart(const u8* romdata, u32 romlen, const u8* savedata, u32 savelen)
|
||||||
{
|
{
|
||||||
if (!GBACart::LoadROM(romdata, romlen))
|
if (!GBACart::LoadROM(romdata, romlen))
|
||||||
|
|
|
@ -240,6 +240,7 @@ void LoadBIOS();
|
||||||
|
|
||||||
bool LoadCart(const u8* romdata, u32 romlen, const u8* savedata, u32 savelen);
|
bool LoadCart(const u8* romdata, u32 romlen, const u8* savedata, u32 savelen);
|
||||||
void EjectCart();
|
void EjectCart();
|
||||||
|
bool CartInserted();
|
||||||
|
|
||||||
bool NeedsDirectBoot();
|
bool NeedsDirectBoot();
|
||||||
void SetupDirectBoot(std::string romname);
|
void SetupDirectBoot(std::string romname);
|
||||||
|
|
|
@ -1489,6 +1489,7 @@ void CartHomebrew::ReadROM_B7(u32 addr, u32 len, u8* data, u32 offset)
|
||||||
|
|
||||||
bool Init()
|
bool Init()
|
||||||
{
|
{
|
||||||
|
CartInserted = false;
|
||||||
CartROM = nullptr;
|
CartROM = nullptr;
|
||||||
Cart = nullptr;
|
Cart = nullptr;
|
||||||
|
|
||||||
|
@ -1503,14 +1504,14 @@ void DeInit()
|
||||||
|
|
||||||
void Reset()
|
void Reset()
|
||||||
{
|
{
|
||||||
if (Cart) delete Cart;
|
/*if (Cart) delete Cart;
|
||||||
Cart = nullptr;
|
Cart = nullptr;
|
||||||
|
|
||||||
CartInserted = false;
|
CartInserted = false;
|
||||||
if (CartROM) delete[] CartROM;
|
if (CartROM) delete[] CartROM;
|
||||||
CartROM = nullptr;
|
CartROM = nullptr;
|
||||||
CartROMSize = 0;
|
CartROMSize = 0;
|
||||||
CartID = 0;
|
CartID = 0;*/
|
||||||
|
|
||||||
ResetCart();
|
ResetCart();
|
||||||
}
|
}
|
||||||
|
@ -1716,7 +1717,7 @@ bool LoadROM(const u8* romdata, u32 romlen)
|
||||||
Key1_Encrypt((u32*)&CartROM[arm9base]);
|
Key1_Encrypt((u32*)&CartROM[arm9base]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("FAZIL");
|
|
||||||
CartInserted = true;
|
CartInserted = true;
|
||||||
|
|
||||||
u32 irversion = 0;
|
u32 irversion = 0;
|
||||||
|
@ -1738,7 +1739,7 @@ printf("FAZIL");
|
||||||
Cart = new CartRetailBT(CartROM, CartROMSize, CartID);
|
Cart = new CartRetailBT(CartROM, CartROMSize, CartID);
|
||||||
else
|
else
|
||||||
Cart = new CartRetail(CartROM, CartROMSize, CartID);
|
Cart = new CartRetail(CartROM, CartROMSize, CartID);
|
||||||
printf("PFART\n");
|
|
||||||
if (Cart)
|
if (Cart)
|
||||||
Cart->Reset();
|
Cart->Reset();
|
||||||
/*{
|
/*{
|
||||||
|
@ -1759,14 +1760,14 @@ printf("PFART\n");
|
||||||
//if (Cart) Cart->LoadSave(sram, romparams.SaveMemType);
|
//if (Cart) Cart->LoadSave(sram, romparams.SaveMemType);
|
||||||
if (Cart && romparams.SaveMemType > 0)
|
if (Cart && romparams.SaveMemType > 0)
|
||||||
Cart->SetupSave(romparams.SaveMemType);
|
Cart->SetupSave(romparams.SaveMemType);
|
||||||
printf("PROEUPRAOUTTE\n");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadSave(const u8* savedata, u32 savelen)
|
void LoadSave(const u8* savedata, u32 savelen)
|
||||||
{printf("CARTSAVE\n");
|
{
|
||||||
if (Cart)
|
if (Cart)
|
||||||
Cart->LoadSave(savedata, savelen);printf("SAVE FARTED\n");
|
Cart->LoadSave(savedata, savelen);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*bool LoadROM(const char* path, const char* sram, bool direct)
|
/*bool LoadROM(const char* path, const char* sram, bool direct)
|
||||||
|
|
|
@ -196,6 +196,7 @@ extern u32 ROMCnt;
|
||||||
|
|
||||||
extern u8 ROMCommand[8];
|
extern u8 ROMCommand[8];
|
||||||
|
|
||||||
|
extern bool CartInserted;
|
||||||
extern u8* CartROM;
|
extern u8* CartROM;
|
||||||
extern u32 CartROMSize;
|
extern u32 CartROMSize;
|
||||||
|
|
||||||
|
|
|
@ -220,7 +220,7 @@ int SetupDSiNAND()
|
||||||
// TODO: some basic checks
|
// TODO: some basic checks
|
||||||
// check that it has the nocash footer, and all
|
// check that it has the nocash footer, and all
|
||||||
|
|
||||||
DSi::SDMMCFile = f;
|
//DSi::SDMMCFile = f;
|
||||||
|
|
||||||
return Load_OK;
|
return Load_OK;
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@ void LoadCheats()
|
||||||
|
|
||||||
int LoadBIOS()
|
int LoadBIOS()
|
||||||
{
|
{
|
||||||
DSi::CloseDSiNAND();
|
//DSi::CloseDSiNAND();
|
||||||
|
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
|
@ -373,7 +373,7 @@ int LoadROM(const u8 *romdata, u32 romlength, const char *archivefilename, const
|
||||||
|
|
||||||
int LoadROM(const char* file, int slot)
|
int LoadROM(const char* file, int slot)
|
||||||
{
|
{
|
||||||
DSi::CloseDSiNAND();
|
//DSi::CloseDSiNAND();
|
||||||
|
|
||||||
int res;
|
int res;
|
||||||
bool directboot = Config::DirectBoot != 0;
|
bool directboot = Config::DirectBoot != 0;
|
||||||
|
@ -530,12 +530,12 @@ void UnloadROM(int slot)
|
||||||
|
|
||||||
ROMPath[slot] = "";
|
ROMPath[slot] = "";
|
||||||
|
|
||||||
DSi::CloseDSiNAND();
|
// DSi::CloseDSiNAND();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Reset()
|
int Reset()
|
||||||
{
|
{
|
||||||
DSi::CloseDSiNAND();
|
// DSi::CloseDSiNAND();
|
||||||
|
|
||||||
int res;
|
int res;
|
||||||
bool directboot = Config::DirectBoot != 0;
|
bool directboot = Config::DirectBoot != 0;
|
||||||
|
|
|
@ -42,6 +42,7 @@ namespace ROMLoader
|
||||||
std::string FullROMPath;
|
std::string FullROMPath;
|
||||||
std::string BaseROMDir;
|
std::string BaseROMDir;
|
||||||
std::string BaseROMName;
|
std::string BaseROMName;
|
||||||
|
std::string BaseAssetName;
|
||||||
|
|
||||||
|
|
||||||
int LastSep(std::string path)
|
int LastSep(std::string path)
|
||||||
|
@ -75,7 +76,7 @@ std::string GetAssetPath(std::string configpath, std::string ext)
|
||||||
if (!configpath.empty())
|
if (!configpath.empty())
|
||||||
configpath += "/";
|
configpath += "/";
|
||||||
|
|
||||||
return configpath + BaseROMName + ext;
|
return configpath + BaseAssetName + ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -257,12 +258,15 @@ QString VerifySetup()
|
||||||
|
|
||||||
bool LoadBIOS()
|
bool LoadBIOS()
|
||||||
{
|
{
|
||||||
|
NDS::SetConsoleType(Config::ConsoleType);
|
||||||
|
|
||||||
if (NDS::NeedsDirectBoot())
|
if (NDS::NeedsDirectBoot())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
FullROMPath = "";
|
FullROMPath = "";
|
||||||
BaseROMDir = "";
|
BaseROMDir = "";
|
||||||
BaseROMName = "";
|
BaseROMName = "";
|
||||||
|
BaseAssetName = "";
|
||||||
|
|
||||||
NDS::Reset();
|
NDS::Reset();
|
||||||
return true;
|
return true;
|
||||||
|
@ -343,10 +347,12 @@ bool LoadROM(QStringList filepath, bool reset)
|
||||||
|
|
||||||
FullROMPath = fullpath;
|
FullROMPath = fullpath;
|
||||||
BaseROMDir = basepath;
|
BaseROMDir = basepath;
|
||||||
BaseROMName = romname.substr(0, romname.rfind('.'));
|
BaseROMName = romname;
|
||||||
|
BaseAssetName = romname.substr(0, romname.rfind('.'));
|
||||||
|
|
||||||
if (reset)
|
if (reset)
|
||||||
{
|
{
|
||||||
|
NDS::SetConsoleType(Config::ConsoleType);
|
||||||
NDS::Reset();
|
NDS::Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,7 +373,7 @@ bool LoadROM(QStringList filepath, bool reset)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool res = NDS::LoadCart(filedata, filelen, savedata, savelen);
|
bool res = NDS::LoadCart(filedata, filelen, savedata, savelen);
|
||||||
if (res)
|
if (res && reset)
|
||||||
{
|
{
|
||||||
if (Config::DirectBoot || NDS::NeedsDirectBoot())
|
if (Config::DirectBoot || NDS::NeedsDirectBoot())
|
||||||
{
|
{
|
||||||
|
@ -387,6 +393,30 @@ void EjectCart()
|
||||||
FullROMPath = "";
|
FullROMPath = "";
|
||||||
BaseROMDir = "";
|
BaseROMDir = "";
|
||||||
BaseROMName = "";
|
BaseROMName = "";
|
||||||
|
BaseAssetName = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CartLabel()
|
||||||
|
{
|
||||||
|
if (BaseROMName.empty())
|
||||||
|
return "(none)";
|
||||||
|
|
||||||
|
QString ret = QString::fromStdString(BaseROMName);
|
||||||
|
|
||||||
|
int maxlen = 32;
|
||||||
|
if (ret.length() > maxlen)
|
||||||
|
ret = ret.left(maxlen-6) + "..." + ret.right(3);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// PLACEHOLDER
|
||||||
|
QString GBACartLabel()
|
||||||
|
{
|
||||||
|
return "(none)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,11 @@ QString VerifySetup();
|
||||||
bool LoadBIOS();
|
bool LoadBIOS();
|
||||||
bool LoadROM(QStringList filepath, bool reset);
|
bool LoadROM(QStringList filepath, bool reset);
|
||||||
void EjectCart();
|
void EjectCart();
|
||||||
|
QString CartLabel();
|
||||||
|
|
||||||
|
bool LoadGBAROM(QStringList filepath, bool reset);
|
||||||
|
void EjectGBACart();
|
||||||
|
QString GBACartLabel();
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
|
|
@ -1308,7 +1308,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
||||||
|
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
|
||||||
actCurrentCart = menu->addAction("Slot 1: princessbourf.nds");
|
actCurrentCart = menu->addAction("DS slot: " + ROMLoader::CartLabel());
|
||||||
actCurrentCart->setEnabled(false);
|
actCurrentCart->setEnabled(false);
|
||||||
|
|
||||||
actInsertCart = menu->addAction("Insert cart...");
|
actInsertCart = menu->addAction("Insert cart...");
|
||||||
|
@ -1319,7 +1319,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
||||||
|
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
|
||||||
actCurrentGBACart = menu->addAction("Slot 2: Fartslapper Mk. II");
|
actCurrentGBACart = menu->addAction("GBA slot: " + ROMLoader::GBACartLabel());
|
||||||
actCurrentGBACart->setEnabled(false);
|
actCurrentGBACart->setEnabled(false);
|
||||||
|
|
||||||
actInsertGBACart = menu->addAction("Insert ROM cart...");
|
actInsertGBACart = menu->addAction("Insert ROM cart...");
|
||||||
|
@ -1614,6 +1614,9 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
||||||
|
|
||||||
createScreenPanel();
|
createScreenPanel();
|
||||||
|
|
||||||
|
actEjectCart->setEnabled(false);
|
||||||
|
actEjectGBACart->setEnabled(false);
|
||||||
|
|
||||||
for (int i = 0; i < 9; i++)
|
for (int i = 0; i < 9; i++)
|
||||||
{
|
{
|
||||||
actSaveState[i]->setEnabled(false);
|
actSaveState[i]->setEnabled(false);
|
||||||
|
@ -2149,6 +2152,9 @@ void MainWindow::onOpenFile()
|
||||||
|
|
||||||
NDS::Start();
|
NDS::Start();
|
||||||
emuThread->emuRun();
|
emuThread->emuRun();
|
||||||
|
|
||||||
|
actCurrentCart->setText("DS slot: " + ROMLoader::CartLabel());
|
||||||
|
actEjectCart->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*QString MainWindow::pickAndExtractFileFromArchive(QString archiveFileName, QByteArray *romBuffer)
|
/*QString MainWindow::pickAndExtractFileFromArchive(QString archiveFileName, QByteArray *romBuffer)
|
||||||
|
@ -2333,6 +2339,9 @@ void MainWindow::onInsertCart()
|
||||||
}
|
}
|
||||||
|
|
||||||
emuThread->emuUnpause();
|
emuThread->emuUnpause();
|
||||||
|
|
||||||
|
actCurrentCart->setText("DS slot: " + ROMLoader::CartLabel());
|
||||||
|
actEjectCart->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onEjectCart()
|
void MainWindow::onEjectCart()
|
||||||
|
@ -2342,6 +2351,9 @@ void MainWindow::onEjectCart()
|
||||||
ROMLoader::EjectCart();
|
ROMLoader::EjectCart();
|
||||||
|
|
||||||
emuThread->emuUnpause();
|
emuThread->emuUnpause();
|
||||||
|
|
||||||
|
actCurrentCart->setText("DS slot: " + ROMLoader::CartLabel());
|
||||||
|
actEjectCart->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onSaveState()
|
void MainWindow::onSaveState()
|
||||||
|
|
Loading…
Reference in New Issue