From c5e14074c3b999d09b8a8612cfa7f011423e83ab Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 3 Jul 2019 12:37:34 +0200 Subject: [PATCH] * add SCFG_EXT * quick hack to detect cartridges --- src/DSi.cpp | 24 +++++++++++++++++++++--- src/DSi.h | 2 ++ src/DSi_I2C.cpp | 8 ++++---- src/NDSCart.cpp | 8 +++++--- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/DSi.cpp b/src/DSi.cpp index e601da97..26a67f4e 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -46,6 +46,7 @@ u32 BootAddr[2]; u16 SCFG_Clock9; u16 SCFG_Clock7; +u32 SCFG_EXT[2]; u32 SCFG_MC; u32 MBK[2][9]; @@ -127,7 +128,9 @@ void Reset() SCFG_Clock9 = 0x0187; // CHECKME SCFG_Clock7 = 0x0187; - SCFG_MC = 0x0011; + SCFG_EXT[0] = 0x8307F100; + SCFG_EXT[1] = 0x93FFFB06; + SCFG_MC = 0x0010;//0x0011; // LCD init flag GPU::DispStat[0] |= (1<<6); @@ -1038,7 +1041,7 @@ u32 ARM9IORead32(u32 addr) { switch (addr) { - case 0x04004008: return 0x8307F100; + case 0x04004008: return SCFG_EXT[0]; case 0x04004010: return SCFG_MC & 0xFFFF; case 0x04004040: return MBK[0][0]; @@ -1183,6 +1186,14 @@ void ARM9IOWrite32(u32 addr, u32 val) { switch (addr) { + case 0x04004008: + SCFG_EXT[0] &= ~0x8007F19F; + SCFG_EXT[0] |= (val & 0x8007F19F); + SCFG_EXT[1] &= ~0x0000F080; + SCFG_EXT[1] |= (val & 0x0000F080); + printf("SCFG_EXT = %08X / %08X (val9 %08X)\n", SCFG_EXT[0], SCFG_EXT[1], val); + return; + case 0x04004040: MapNWRAM_A(0, val & 0xFF); MapNWRAM_A(1, (val >> 8) & 0xFF); @@ -1333,7 +1344,7 @@ u32 ARM7IORead32(u32 addr) case 0x04000218: return NDS::IE2; case 0x0400021C: return NDS::IF2; - case 0x04004008: return 0x80000000; // HAX + case 0x04004008: return SCFG_EXT[1]; case 0x04004010: return SCFG_MC; case 0x04004040: return MBK[1][0]; @@ -1449,6 +1460,13 @@ void ARM7IOWrite32(u32 addr, u32 val) case 0x04000218: NDS::IE2 = (val & 0x7FF7); NDS::UpdateIRQ(1); return; case 0x0400021C: NDS::IF2 &= ~(val & 0x7FF7); NDS::UpdateIRQ(1); return; + case 0x04004008: + SCFG_EXT[0] &= ~0x03000000; + SCFG_EXT[0] |= (val & 0x03000000); + SCFG_EXT[1] &= ~0x93FF0F07; + SCFG_EXT[1] |= (val & 0x93FF0F07); + printf("SCFG_EXT = %08X / %08X (val7 %08X)\n", SCFG_EXT[0], SCFG_EXT[1], val); + return; case 0x04004010: val &= 0xFFFF800C; if ((val & 0xC) == 0xC) val &= ~0xC; // hax diff --git a/src/DSi.h b/src/DSi.h index 642a56a7..db585b48 100644 --- a/src/DSi.h +++ b/src/DSi.h @@ -31,6 +31,8 @@ extern u64 ConsoleID; extern DSi_SDHost* SDMMC; extern DSi_SDHost* SDIO; +extern u8 ITCMInit[0x8000]; + bool Init(); void DeInit(); diff --git a/src/DSi_I2C.cpp b/src/DSi_I2C.cpp index 845dd9db..e88858b2 100644 --- a/src/DSi_I2C.cpp +++ b/src/DSi_I2C.cpp @@ -72,7 +72,7 @@ void Reset() void Start() { - printf("BPTWL: start\n"); + //printf("BPTWL: start\n"); } u8 Read(bool last) @@ -83,7 +83,7 @@ u8 Read(bool last) return 0; } - printf("BPTWL: read %02X -> %02X\n", CurPos, Registers[CurPos]); + //printf("BPTWL: read %02X -> %02X\n", CurPos, Registers[CurPos]); return Registers[CurPos++]; } @@ -98,7 +98,7 @@ void Write(u8 val, bool last) if (CurPos == -1) { CurPos = val; - printf("BPTWL: reg=%02X\n", val); + //printf("BPTWL: reg=%02X\n", val); return; } @@ -113,7 +113,7 @@ void Write(u8 val, bool last) Registers[CurPos] = val; } - printf("BPTWL: write %02X -> %02X\n", CurPos, val); + //printf("BPTWL: write %02X -> %02X\n", CurPos, val); CurPos++; // CHECKME } diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index 0ecd304a..0bb8b5ce 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -19,6 +19,7 @@ #include #include #include "NDS.h" +#include "DSi.h" #include "NDSCart.h" #include "ARM.h" #include "CRC32.h" @@ -558,7 +559,8 @@ void Key1_ApplyKeycode(u32* keycode, u32 mod) void Key1_InitKeycode(u32 idcode, u32 level, u32 mod) { - memcpy(Key1_KeyBuf, &NDS::ARM7BIOS[0x30], 0x1048); // hax + //memcpy(Key1_KeyBuf, &NDS::ARM7BIOS[0x30], 0x1048); // hax + memcpy(Key1_KeyBuf, &DSi::ITCMInit[0x4894], 0x1048); // hax u32 keycode[3] = {idcode, idcode>>1, idcode<<1}; if (level >= 1) Key1_ApplyKeycode(keycode, mod); @@ -1185,11 +1187,11 @@ void WriteROMCnt(u32 val) *(u32*)&cmd[4] = *(u32*)&ROMCommand[4]; } - /*printf("ROM COMMAND %04X %08X %02X%02X%02X%02X%02X%02X%02X%02X SIZE %04X\n", + printf("ROM COMMAND %04X %08X %02X%02X%02X%02X%02X%02X%02X%02X SIZE %04X\n", SPICnt, ROMCnt, cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6], cmd[7], - datasize);*/ + datasize); switch (cmd[0]) {