Skip to content

Commit

Permalink
Improve DS Phat check
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketRobz committed Oct 22, 2023
1 parent caeebfa commit 9fd16cf
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 31 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/))
Expand Down
3 changes: 1 addition & 2 deletions imageview/arm7/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions manual/arm7/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions quickmenu/arm7/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down
5 changes: 1 addition & 4 deletions romsel_aktheme/arm7/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions romsel_dsimenutheme/arm7/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions romsel_r4theme/arm7/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions settings/arm7/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions title/arm7/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions universal/include/common/systemdetails.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -39,7 +39,7 @@ class SystemDetails
bool _arm7SCFGLocked;
bool _isRunFromSD;
bool _isRegularDS;
bool _isDSLite;
bool _isDSPhat;
bool _dsDebugRam;
bool _fatInitOk;
bool _fifoOk;
Expand Down
23 changes: 21 additions & 2 deletions universal/source/common/systemdetails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +34,7 @@ SystemDetails::SystemDetails()
_dsiWramAccess = false;
_arm7SCFGLocked = false;
_isRegularDS = true;
_isDSLite = false;
_isDSPhat = false;
_nitroFsInitOk = false;
_fatInitOk = false;
_fifoOk = false;
Expand All @@ -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;
Expand Down

0 comments on commit 9fd16cf

Please sign in to comment.