From 9fd16cf87224384783a7eef5d23477bf9de12143 Mon Sep 17 00:00:00 2001 From: RocketRobz Date: Sun, 22 Oct 2023 15:20:28 -0600 Subject: [PATCH] Improve DS Phat check --- README.md | 1 + imageview/arm7/source/main.c | 3 +-- manual/arm7/source/main.c | 5 +---- quickmenu/arm7/source/main.c | 7 +++---- romsel_aktheme/arm7/source/main.c | 5 +---- romsel_dsimenutheme/arm7/source/main.c | 3 +-- romsel_r4theme/arm7/source/main.c | 7 +++---- settings/arm7/source/main.c | 3 +-- title/arm7/source/main.c | 7 +++---- universal/include/common/systemdetails.h | 6 +++--- universal/source/common/systemdetails.cpp | 23 +++++++++++++++++++++-- 11 files changed, 39 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index b1136aa55c..a86af5e05c 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ You can help translate TWiLight Menu++ on the [Crowdin project](https://crowdin. - Another World & Yellow Wood Goblin: The original akMenu/Wood UI - [Arisotura](https://github.com/Arisotura): ROM list from melonDS, and BIOS dumper code from [dsibiosdumper](https://github.com/Arisotura/dsibiosdumper) - [devkitPro](https://github.com/devkitPro): Code used in nds-hb-menu, and the use of the bootloader, devkitARM, libnds, and libfat +- [edo9300](https://github.com/edo9300): DS Phat check code - [Gericom](https://github.com/Gericom), TrolleyDave, and FAST6191: GBA SRAM-patching code, used in gbapatcher ([SRAM patching thread at GBAtemp](https://gbatemp.net/threads/reverse-engineering-gba-patching.60168/)) - [Gericom](https://github.com/Gericom) & [profi200](https://github.com/profi200): GBA color correction code, used in [GBARunner3](https://github.com/Gericom/GBARunner3) - Nikokaro: Found no-tilt patches for *WarioWare: Twisted!*, and *Yoshi Topsy-Turvy*. ([GBAtemp thread](https://gbatemp.net/threads/gba-no-tilt-patches-for-ds-users.584128/)) diff --git a/imageview/arm7/source/main.c b/imageview/arm7/source/main.c index a1961ac497..b37c39f702 100644 --- a/imageview/arm7/source/main.c +++ b/imageview/arm7/source/main.c @@ -129,8 +129,7 @@ int main() { // Init status -- bits 15-17 (Bit 0 (15): isDSLite, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT) u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT) - | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT) - | BIT_SET(!!(readCommand & BIT(4) || readCommand & BIT(5) || readCommand & BIT(6) || readCommand & BIT(7)), DSLITE_BIT)); + | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)); status = (status & ~INIT_MASK) | ((initStatus << INIT_OFF) & INIT_MASK); fifoSendValue32(FIFO_USER_03, status); diff --git a/manual/arm7/source/main.c b/manual/arm7/source/main.c index ec667547b2..94e3be6d13 100644 --- a/manual/arm7/source/main.c +++ b/manual/arm7/source/main.c @@ -114,8 +114,6 @@ int main() { setPowerButtonCB(powerButtonCB); - u8 readCommand = readPowerManagement(4); - // 01: Fade Out // 02: Return // 03: status (Bit 0: isDSLite, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT) @@ -129,8 +127,7 @@ int main() { // Init status -- bits 15-17 (Bit 0 (15): isDSLite, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT) u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT) - | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT) - | BIT_SET(!!(readCommand & BIT(4) || readCommand & BIT(5) || readCommand & BIT(6) || readCommand & BIT(7)), DSLITE_BIT)); + | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)); status = (status & ~INIT_MASK) | ((initStatus << INIT_OFF) & INIT_MASK); fifoSendValue32(FIFO_USER_03, status); diff --git a/quickmenu/arm7/source/main.c b/quickmenu/arm7/source/main.c index 3fe75366de..f0b12e9f46 100644 --- a/quickmenu/arm7/source/main.c +++ b/quickmenu/arm7/source/main.c @@ -230,8 +230,6 @@ int main() { *(vu32*)0x037C0000 = wordBak; } - u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL); - // 01: Fade Out // 02: Return // 03: status (Bit 0: isDSLite, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT) @@ -245,13 +243,14 @@ int main() { // Init status -- bits 15-17 (Bit 0 (15): isDSLite, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT) u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT) - | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT) - | BIT_SET(!!(pmBacklight & BIT(4) || pmBacklight & BIT(5) || pmBacklight & BIT(6) || pmBacklight & BIT(7)), DSLITE_BIT)); + | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)); status = (status & ~INIT_MASK) | ((initStatus << INIT_OFF) & INIT_MASK); fifoSendValue32(FIFO_USER_03, status); if (REG_SNDEXTCNT == 0) { + u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL); + if (pmBacklight & 0xF0) // DS Lite backlightLevel = pmBacklight & 3; // Brightness } diff --git a/romsel_aktheme/arm7/source/main.c b/romsel_aktheme/arm7/source/main.c index 271c09cf1c..2dd45efcce 100755 --- a/romsel_aktheme/arm7/source/main.c +++ b/romsel_aktheme/arm7/source/main.c @@ -144,11 +144,8 @@ int main() { // Volume is 00h to 1Fh = 5 bits -- bits 8-12 // SD status -- bit 13 - u8 readCommand = readPowerManagement(4); - u32 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT) - | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT) - | BIT_SET(!!(readCommand & BIT(4) || readCommand & BIT(5) || readCommand & BIT(6) || readCommand & BIT(7)), DSLITE_BIT)); + | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)); status = (status & ~INIT_MASK) | ((initStatus << INIT_OFF) & INIT_MASK); fifoSendValue32(FIFO_USER_03, status); diff --git a/romsel_dsimenutheme/arm7/source/main.c b/romsel_dsimenutheme/arm7/source/main.c index 65a37277f6..d7c8af8afa 100644 --- a/romsel_dsimenutheme/arm7/source/main.c +++ b/romsel_dsimenutheme/arm7/source/main.c @@ -160,8 +160,7 @@ int main() { // Init status -- bits 15-17 (Bit 0 (15): isDSLite, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT) u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT) - | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT) - | BIT_SET(!!(pmBacklight & BIT(4) || pmBacklight & BIT(5) || pmBacklight & BIT(6) || pmBacklight & BIT(7)), DSLITE_BIT)); + | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)); status = (status & ~INIT_MASK) | ((initStatus << INIT_OFF) & INIT_MASK); fifoSendValue32(FIFO_USER_03, status); diff --git a/romsel_r4theme/arm7/source/main.c b/romsel_r4theme/arm7/source/main.c index 65a37277f6..d056c6f668 100644 --- a/romsel_r4theme/arm7/source/main.c +++ b/romsel_r4theme/arm7/source/main.c @@ -145,8 +145,6 @@ int main() { *(vu32*)0x037C0000 = wordBak; } - u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL); - // 01: Fade Out // 02: Return // 03: status (Bit 0: isDSLite, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT) @@ -160,13 +158,14 @@ int main() { // Init status -- bits 15-17 (Bit 0 (15): isDSLite, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT) u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT) - | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT) - | BIT_SET(!!(pmBacklight & BIT(4) || pmBacklight & BIT(5) || pmBacklight & BIT(6) || pmBacklight & BIT(7)), DSLITE_BIT)); + | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)); status = (status & ~INIT_MASK) | ((initStatus << INIT_OFF) & INIT_MASK); fifoSendValue32(FIFO_USER_03, status); if (REG_SNDEXTCNT == 0) { + u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL); + if (pmBacklight & 0xF0) { // DS Lite int backlightLevel = pmBacklight & 3; // Brightness *(int*)0x02003000 = backlightLevel; diff --git a/settings/arm7/source/main.c b/settings/arm7/source/main.c index 1024a8aff4..bed8eaf97c 100644 --- a/settings/arm7/source/main.c +++ b/settings/arm7/source/main.c @@ -231,8 +231,7 @@ int main() { // Init status -- bits 15-17 (Bit 0 (15): isDSLite, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT) u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT) - | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT) - | BIT_SET(!!(readCommand & BIT(4) || readCommand & BIT(5) || readCommand & BIT(6) || readCommand & BIT(7)), DSLITE_BIT)); + | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)); status = (status & ~INIT_MASK) | ((initStatus << INIT_OFF) & INIT_MASK); fifoSendValue32(FIFO_USER_03, status); diff --git a/title/arm7/source/main.c b/title/arm7/source/main.c index 95af4f6cda..3768d36557 100644 --- a/title/arm7/source/main.c +++ b/title/arm7/source/main.c @@ -235,8 +235,6 @@ int main() { biosDump((void*)0x02F80020, (const void*)0x00000020, 0x7FE0); } - u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL); - // 01: Fade Out // 02: Return // 03: status (Bit 0: isDSLite, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT) @@ -250,13 +248,14 @@ int main() { // Init status -- bits 15-17 (Bit 0 (15): isDSLite, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT) u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT) - | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT) - | BIT_SET(!!(pmBacklight & BIT(4) || pmBacklight & BIT(5) || pmBacklight & BIT(6) || pmBacklight & BIT(7)), DSLITE_BIT)); + | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)); status = (status & ~INIT_MASK) | ((initStatus << INIT_OFF) & INIT_MASK); fifoSendValue32(FIFO_USER_03, status); if (REG_SNDEXTCNT == 0) { + u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL); + if (pmBacklight & 0xF0) { // DS Lite int backlightLevel = pmBacklight & 3; // Brightness *(int*)0x02003000 = backlightLevel; diff --git a/universal/include/common/systemdetails.h b/universal/include/common/systemdetails.h index c3585ddbe5..2d0d7b0b07 100644 --- a/universal/include/common/systemdetails.h +++ b/universal/include/common/systemdetails.h @@ -25,8 +25,8 @@ class SystemDetails bool isRegularDS() { return _isRegularDS; } bool fatInitOk() { return _fatInitOk; } bool useNitroFS() { return _nitroFsInitOk; } - bool isDSPhat() { return (_isRegularDS && !_isDSLite); } - bool isDSLite() { return (_isRegularDS && _isDSLite); } + bool isDSPhat() { return (_isRegularDS && _isDSPhat); } + bool isDSLite() { return (_isRegularDS && !_isDSPhat); } bool dsDebugRam() { return (_dsDebugRam); } void initFilesystem(const char *runningPath); void initArm7RegStatuses(); @@ -39,7 +39,7 @@ class SystemDetails bool _arm7SCFGLocked; bool _isRunFromSD; bool _isRegularDS; - bool _isDSLite; + bool _isDSPhat; bool _dsDebugRam; bool _fatInitOk; bool _fifoOk; diff --git a/universal/source/common/systemdetails.cpp b/universal/source/common/systemdetails.cpp index 677752fc10..5bba157abc 100644 --- a/universal/source/common/systemdetails.cpp +++ b/universal/source/common/systemdetails.cpp @@ -7,6 +7,9 @@ #define CHECK_BIT(v, n) (((v) >> (n)) & 1) +#define FLASHM_BACKUPHEADER 0x3f680 +#define FLASHME_MAJOR_VER 0x17c + // Make this link C-like for volatility extern "C" { static volatile int _batteryLevel = 0; @@ -31,7 +34,7 @@ SystemDetails::SystemDetails() _dsiWramAccess = false; _arm7SCFGLocked = false; _isRegularDS = true; - _isDSLite = false; + _isDSPhat = false; _nitroFsInitOk = false; _fatInitOk = false; _fifoOk = false; @@ -56,7 +59,23 @@ SystemDetails::SystemDetails() _isRegularDS = false; // If sound frequency setting is found, then the console is not a DS Phat/Lite } - _isDSLite = CHECK_BIT(status, DSLITE_BIT); + if (_isRegularDS) { + u8 consoleType = 0; + readFirmware(0x1D, &consoleType, 1); + if(consoleType == 0xff) { + _isDSPhat = true; + } else { + u8 flashmeVersion = 0; + readFirmware(FLASHME_MAJOR_VER, &flashmeVersion, 1); + + if(flashmeVersion != 0xff){ + u8 contentsOnLite[6] = {0xff,0xff,0xff,0xff,0xff,0x00}; + u8 unusedShouldBeZeroFilledOnPhat[6]; + readFirmware(FLASHM_BACKUPHEADER+0x30, &unusedShouldBeZeroFilledOnPhat, 6); + _isDSPhat = memcmp(unusedShouldBeZeroFilledOnPhat, contentsOnLite, 6) != 0; + } + } + } if (!dsiFeatures()) { u32 wordBak = *(vu32*)0x02800000;