diff --git a/3dssplash/arm7/source/main.c b/3dssplash/arm7/source/main.c index 6f47c56f20..a4132e5b5b 100644 --- a/3dssplash/arm7/source/main.c +++ b/3dssplash/arm7/source/main.c @@ -29,6 +29,7 @@ ---------------------------------------------------------------------------------*/ #include #include +#include "common/isPhatCheck.h" #include "common/arm7status.h" void my_touchInit(); @@ -111,23 +112,24 @@ int main() { setPowerButtonCB(powerButtonCB); - u8 readCommand = readPowerManagement(4); + u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL); // 01: Fade Out // 02: Return - // 03: status (Bit 0: isDSLite, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT) - + // 03: status (Bit 0: hasRegulableBacklight, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT, Bit 3: isDSPhat) + // 03: Status: Init/Volume/Battery/SD // https://problemkaputt.de/gbatek.htm#dsii2cdevice4ahbptwlchip // Battery is 7 bits -- bits 0-7 // Volume is 00h to 1Fh = 5 bits -- bits 8-12 // SD status -- bits 13-14 - // Init status -- bits 15-17 (Bit 0 (15): isDSLite, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT) + // Init status -- bits 15-18 (Bit 0 (15): hasRegulableBacklight, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT, Bit 3 (18): isDSPhat) - 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)); + 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)), BACKLIGHT_BIT) + | BIT_SET(isPhat(), DSPHAT_BIT)); status = (status & ~INIT_MASK) | ((initStatus << INIT_OFF) & INIT_MASK); fifoSendValue32(FIFO_USER_03, status); diff --git a/imageview/arm7/source/main.c b/imageview/arm7/source/main.c index b37c39f702..af1bb51c4f 100644 --- a/imageview/arm7/source/main.c +++ b/imageview/arm7/source/main.c @@ -29,6 +29,7 @@ ---------------------------------------------------------------------------------*/ #include #include +#include "common/isPhatCheck.h" #include "common/arm7status.h" void my_touchInit(); @@ -114,22 +115,24 @@ int main() { setPowerButtonCB(powerButtonCB); - u8 readCommand = readPowerManagement(4); + u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL); // 01: Fade Out // 02: Return - // 03: status (Bit 0: isDSLite, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT) - + // 03: status (Bit 0: hasRegulableBacklight, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT, Bit 3: isDSPhat) + // 03: Status: Init/Volume/Battery/SD // https://problemkaputt.de/gbatek.htm#dsii2cdevice4ahbptwlchip // Battery is 7 bits -- bits 0-7 // Volume is 00h to 1Fh = 5 bits -- bits 8-12 // SD status -- bits 13-14 - // Init status -- bits 15-17 (Bit 0 (15): isDSLite, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT) + // Init status -- bits 15-18 (Bit 0 (15): hasRegulableBacklight, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT, Bit 3 (18): isDSPhat) - u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT) - | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)); + 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)), BACKLIGHT_BIT) + | BIT_SET(isPhat(), DSPHAT_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 94e3be6d13..62dfcdf6bf 100644 --- a/manual/arm7/source/main.c +++ b/manual/arm7/source/main.c @@ -29,6 +29,7 @@ ---------------------------------------------------------------------------------*/ #include #include +#include "common/isPhatCheck.h" #include "common/arm7status.h" void my_touchInit(); @@ -112,22 +113,24 @@ int main() { irqEnable(IRQ_VBLANK | IRQ_VCOUNT); - setPowerButtonCB(powerButtonCB); + u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL); // 01: Fade Out // 02: Return - // 03: status (Bit 0: isDSLite, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT) - + // 03: status (Bit 0: hasRegulableBacklight, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT, Bit 3: isDSPhat) + // 03: Status: Init/Volume/Battery/SD // https://problemkaputt.de/gbatek.htm#dsii2cdevice4ahbptwlchip // Battery is 7 bits -- bits 0-7 // Volume is 00h to 1Fh = 5 bits -- bits 8-12 // SD status -- bits 13-14 - // Init status -- bits 15-17 (Bit 0 (15): isDSLite, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT) + // Init status -- bits 15-18 (Bit 0 (15): hasRegulableBacklight, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT, Bit 3 (18): isDSPhat) - u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT) - | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)); + 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)), BACKLIGHT_BIT) + | BIT_SET(isPhat(), DSPHAT_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 f0b12e9f46..968966c76a 100644 --- a/quickmenu/arm7/source/main.c +++ b/quickmenu/arm7/source/main.c @@ -30,6 +30,7 @@ #include #include #include +#include "common/isPhatCheck.h" #include "common/arm7status.h" #define REG_SCFG_WL *(vu16*)0x4004020 @@ -49,12 +50,14 @@ static int soundVolume = 127; volatile int rebootTimer = 0; volatile int status = 0; static int backlightLevel = 0; +static bool isDSPhat = false; +static bool hasRegulableBacklight = false; //static bool gotCartHeader = false; //--------------------------------------------------------------------------------- -void soundFadeOut() { +void soundFadeOut(void) { //--------------------------------------------------------------------------------- soundVolume -= 3; if (soundVolume < 0) { @@ -63,7 +66,7 @@ void soundFadeOut() { } //--------------------------------------------------------------------------------- -void ReturntoDSiMenu() { +void ReturntoDSiMenu(void) { //--------------------------------------------------------------------------------- nocashMessage("ARM7 ReturnToDSiMenu"); if (isDSiMode()) { @@ -77,17 +80,26 @@ void ReturntoDSiMenu() { } //--------------------------------------------------------------------------------- -void changeBacklightLevel() { +void changeBacklightLevel(void) { //--------------------------------------------------------------------------------- if (REG_SNDEXTCNT == 0) { - backlightLevel++; - if (backlightLevel > 3) { + // if the backlight is regulable the range will be 0 - 3 + // if the backlight is regulable and the console is a phat the range will be 0 - 4 (with 4 being backlight off) + // if the backlight is not regulable the only possible values will be 0 and 4 (with 4 being backlight off) + backlightLevel += 1 + (3 * !hasRegulableBacklight); + + if (backlightLevel > (3 + isDSPhat)) { backlightLevel = 0; } - u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL); - if (pmBacklight & 0xF0) // DS Lite - writePowerManagement(PM_BACKLIGHT_LEVEL, (pmBacklight & ~3) | backlightLevel); - writePowerManagement(PM_CONTROL_REG, readPowerManagement(PM_CONTROL_REG) | 0xC); + if (hasRegulableBacklight) { + u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL); + writePowerManagement(PM_BACKLIGHT_LEVEL, (pmBacklight & ~3) | (backlightLevel & 0x3)); + } + + if(backlightLevel == 4) + writePowerManagement(PM_CONTROL_REG, readPowerManagement(PM_CONTROL_REG) & ~0xC); + else + writePowerManagement(PM_CONTROL_REG, readPowerManagement(PM_CONTROL_REG) | 0xC); return; } @@ -113,7 +125,7 @@ void VblankHandler(void) { } //--------------------------------------------------------------------------------- -void VcountHandler() { +void VcountHandler(void) { //--------------------------------------------------------------------------------- void my_inputGetAndSend(void); my_inputGetAndSend(); @@ -122,7 +134,7 @@ void VcountHandler() { volatile bool exitflag = false; //--------------------------------------------------------------------------------- -void powerButtonCB() { +void powerButtonCB(void) { //--------------------------------------------------------------------------------- exitflag = true; } @@ -230,9 +242,14 @@ int main() { *(vu32*)0x037C0000 = wordBak; } + u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL); + + hasRegulableBacklight = !!(pmBacklight & BIT(4) || pmBacklight & BIT(5) || pmBacklight & BIT(6) || pmBacklight & BIT(7)); + isDSPhat = isPhat(); + // 01: Fade Out // 02: Return - // 03: status (Bit 0: isDSLite, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT) + // 03: status (Bit 0: hasRegulableBacklight, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT, Bit 3: isDSPhat) // 03: Status: Init/Volume/Battery/SD @@ -240,10 +257,12 @@ int main() { // Battery is 7 bits -- bits 0-7 // Volume is 00h to 1Fh = 5 bits -- bits 8-12 // SD status -- bits 13-14 - // Init status -- bits 15-17 (Bit 0 (15): isDSLite, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT) + // Init status -- bits 15-18 (Bit 0 (15): hasRegulableBacklight, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT, Bit 3 (18): isDSPhat) u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT) - | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)); + | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT) + | BIT_SET(hasRegulableBacklight, BACKLIGHT_BIT) + | BIT_SET(isDSPhat, DSPHAT_BIT)); status = (status & ~INIT_MASK) | ((initStatus << INIT_OFF) & INIT_MASK); fifoSendValue32(FIFO_USER_03, status); @@ -253,6 +272,9 @@ int main() { if (pmBacklight & 0xF0) // DS Lite backlightLevel = pmBacklight & 3; // Brightness + + if((readPowerManagement(PM_CONTROL_REG) & 0xC) == 0) // DS Phat backlight off + backlightLevel = 4; } if (isDSiMode()) { diff --git a/quickmenu/arm9/source/graphics/graphics.cpp b/quickmenu/arm9/source/graphics/graphics.cpp index 2b54a886f6..4527d67fba 100644 --- a/quickmenu/arm9/source/graphics/graphics.cpp +++ b/quickmenu/arm9/source/graphics/graphics.cpp @@ -373,7 +373,7 @@ void vBlankHandler() glSprite(33, iconYpos[3], GL_FLIP_NONE, sdFound() ? &iconboxImage[0] : &iconboxImage[sys().isRegularDS() ? (((u8*)GBAROM)[0xB2] != 0x96) : 1]); int num = (io_dldi_data->ioInterface.features & FEATURE_SLOT_GBA) ? 1 : 0; drawIcon(num, 40, iconYpos[3]+6); - if (sys().isDSLite() || (dsiFeatures() && ms().consoleModel < 2)) { + if (sys().isRegularDS() || (dsiFeatures() && ms().consoleModel < 2)) { glSprite(10, iconYpos[4], GL_FLIP_NONE, &cornerIcons[0]); } if (bnrWirelessIcon[num] > 0) glSprite(207, iconYpos[3]+30, GL_FLIP_NONE, &wirelessIcons[(bnrWirelessIcon[1]-1) & 31]); diff --git a/quickmenu/arm9/source/main.cpp b/quickmenu/arm9/source/main.cpp index 0d7b80636a..3a8a9f96e2 100644 --- a/quickmenu/arm9/source/main.cpp +++ b/quickmenu/arm9/source/main.cpp @@ -769,7 +769,7 @@ void loadGameOnFlashcard(const char* ndsPath, bool dsGame) { || (memcmp(io_dldi_data->friendlyName, "R4iTT", 5) == 0) || (memcmp(io_dldi_data->friendlyName, "Acekard AK2", 0xB) == 0) || (memcmp(io_dldi_data->friendlyName, "Ace3DS+", 7) == 0)) { - if (sys().isDSLite()) { + if (sys().hasRegulableBacklight()) { CIniFile backlightini("fat:/_wfwd/backlight.ini"); backlightini.SetInt("brightness", "brightness", *(int*)0x02003000); backlightini.SaveIniFile("fat:/_wfwd/backlight.ini"); @@ -1733,7 +1733,7 @@ int dsClassicMenu(void) { } if (pressed & KEY_LEFT) { - if (cursorPosition == 2 || (cursorPosition == 5 && (sys().isDSLite() || (dsiFeatures() && ms().consoleModel < 2))) + if (cursorPosition == 2 || (cursorPosition == 5 && (sys().isRegularDS() || (dsiFeatures() && ms().consoleModel < 2))) || cursorPosition == 6) { cursorPosition--; if (cursorPosition == 5 && ms().kioskMode) { @@ -1767,7 +1767,7 @@ int dsClassicMenu(void) { cursorPosition = 3; menuButtonPressed = true; } else if (touch.px >= 10 && touch.px <= 20 && touch.py >= 175 && touch.py <= 185 - && (sys().isDSLite() || (dsiFeatures() && ms().consoleModel < 2))) { + && (sys().isRegularDS() || (dsiFeatures() && ms().consoleModel < 2))) { cursorPosition = 4; menuButtonPressed = true; } else if (touch.px >= 117 && touch.px <= 137 && touch.py >= 170 && touch.py <= 190 && !ms().kioskMode) { @@ -2100,8 +2100,8 @@ int dsClassicMenu(void) { break; case 4: // Adjust backlight level - if (sys().isDSLite() || (dsiFeatures() && ms().consoleModel < 2)) { - fifoSendValue32(FIFO_USER_04, 1); + if (sys().isRegularDS() || (dsiFeatures() && ms().consoleModel < 2)) { + fifoSendValue32(FIFO_USER_04, 1 | (sys().isDSPhat() << 1) | (sys().hasRegulableBacklight() << 2)); mmEffectEx(&snd_backlight); } break; diff --git a/romsel_aktheme/arm7/source/arm7status.h b/romsel_aktheme/arm7/source/arm7status.h deleted file mode 100644 index d36e28e0f3..0000000000 --- a/romsel_aktheme/arm7/source/arm7status.h +++ /dev/null @@ -1,20 +0,0 @@ - -#ifndef A7STAT_H -#define A7STAT_H - -#define SNDEXTCNT_BIT 2 -#define REGSCFG_BIT 1 -#define DSLITE_BIT 0 - -#define BAT_MASK 0b00000000000011111111 -#define BAT_OFF 0 - -#define VOL_MASK 0b00000001111100000000 -#define VOL_OFF 8 - -#define SD_MASK 0b00000110000000000000 -#define SD_OFF 13 - -#define INIT_MASK 0b00111000000000000000 -#define INIT_OFF 15 -#endif \ No newline at end of file diff --git a/romsel_aktheme/arm7/source/main.c b/romsel_aktheme/arm7/source/main.c index 2dd45efcce..517884bf90 100755 --- a/romsel_aktheme/arm7/source/main.c +++ b/romsel_aktheme/arm7/source/main.c @@ -30,7 +30,8 @@ #include #include #include -#include "arm7status.h" +#include "common/isPhatCheck.h" +#include "common/arm7status.h" #define BIT_SET(c, n) ((c) << (n)) @@ -132,20 +133,25 @@ int main() { irqEnable( IRQ_VBLANK | IRQ_VCOUNT ); setPowerButtonCB(powerButtonCB); - + + u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL); + // 01: Fade Out // 02: Return - // 03: status (Bit 0: isDSLite, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT) - + // 03: status (Bit 0: hasRegulableBacklight, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT, Bit 3: isDSPhat) + - // 05: Volume/Battery/SD + // 03: Status: Init/Volume/Battery/SD // https://problemkaputt.de/gbatek.htm#dsii2cdevice4ahbptwlchip // Battery is 7 bits -- bits 0-7 // Volume is 00h to 1Fh = 5 bits -- bits 8-12 - // SD status -- bit 13 + // SD status -- bits 13-14 + // Init status -- bits 15-18 (Bit 0 (15): hasRegulableBacklight, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT, Bit 3 (18): isDSPhat) - u32 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT) - | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)); + 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)), BACKLIGHT_BIT) + | BIT_SET(isPhat(), DSPHAT_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 d056c6f668..ffa68bbaab 100644 --- a/romsel_dsimenutheme/arm7/source/main.c +++ b/romsel_dsimenutheme/arm7/source/main.c @@ -30,6 +30,7 @@ #include #include #include +#include "common/isPhatCheck.h" #include "common/arm7status.h" void my_touchInit(); @@ -145,27 +146,29 @@ 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) - + // 03: status (Bit 0: hasRegulableBacklight, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT, Bit 3: isDSPhat) + // 03: Status: Init/Volume/Battery/SD // https://problemkaputt.de/gbatek.htm#dsii2cdevice4ahbptwlchip // Battery is 7 bits -- bits 0-7 // Volume is 00h to 1Fh = 5 bits -- bits 8-12 // SD status -- bits 13-14 - // Init status -- bits 15-17 (Bit 0 (15): isDSLite, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT) + // Init status -- bits 15-18 (Bit 0 (15): hasRegulableBacklight, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT, Bit 3 (18): isDSPhat) - u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT) - | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)); + 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)), BACKLIGHT_BIT) + | BIT_SET(isPhat(), DSPHAT_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/romsel_dsimenutheme/arm9/source/graphics/ThemeTextures.cpp b/romsel_dsimenutheme/arm9/source/graphics/ThemeTextures.cpp index 4ff3989b77..49ae8e54e0 100644 --- a/romsel_dsimenutheme/arm9/source/graphics/ThemeTextures.cpp +++ b/romsel_dsimenutheme/arm9/source/graphics/ThemeTextures.cpp @@ -508,7 +508,7 @@ void ThemeTextures::loadBatteryTextures() { _battery4Texture = std::make_unique(TFN_BATTERY4, TFN_FALLBACK_BATTERY4); } } else { - if (!sys().isDSPhat()) { + if (sys().hasRegulableBacklight()) { _batterychargeTexture = std::make_unique(TFN_BATTERY_CHARGE, TFN_FALLBACK_BATTERY_CHARGE); _batterychargeblinkTexture = std::make_unique(TFN_BATTERY_CHARGE_BLINK, TFN_FALLBACK_BATTERY_CHARGE_BLINK); } diff --git a/romsel_dsimenutheme/arm9/source/main.cpp b/romsel_dsimenutheme/arm9/source/main.cpp index 99eaec3a5c..8b6f8e4867 100644 --- a/romsel_dsimenutheme/arm9/source/main.cpp +++ b/romsel_dsimenutheme/arm9/source/main.cpp @@ -678,7 +678,7 @@ void loadGameOnFlashcard(const char *ndsPath, bool dsGame) { || (memcmp(io_dldi_data->friendlyName, "R4iTT", 5) == 0) || (memcmp(io_dldi_data->friendlyName, "Acekard AK2", 0xB) == 0) || (memcmp(io_dldi_data->friendlyName, "Ace3DS+", 7) == 0)) { - if (sys().isDSLite()) { + if (sys().hasRegulableBacklight()) { CIniFile backlightini("fat:/_wfwd/backlight.ini"); backlightini.SetInt("brightness", "brightness", *(int*)0x02003000); backlightini.SaveIniFile("fat:/_wfwd/backlight.ini"); diff --git a/romsel_r4theme/arm7/source/main.c b/romsel_r4theme/arm7/source/main.c index d056c6f668..ffa68bbaab 100644 --- a/romsel_r4theme/arm7/source/main.c +++ b/romsel_r4theme/arm7/source/main.c @@ -30,6 +30,7 @@ #include #include #include +#include "common/isPhatCheck.h" #include "common/arm7status.h" void my_touchInit(); @@ -145,27 +146,29 @@ 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) - + // 03: status (Bit 0: hasRegulableBacklight, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT, Bit 3: isDSPhat) + // 03: Status: Init/Volume/Battery/SD // https://problemkaputt.de/gbatek.htm#dsii2cdevice4ahbptwlchip // Battery is 7 bits -- bits 0-7 // Volume is 00h to 1Fh = 5 bits -- bits 8-12 // SD status -- bits 13-14 - // Init status -- bits 15-17 (Bit 0 (15): isDSLite, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT) + // Init status -- bits 15-18 (Bit 0 (15): hasRegulableBacklight, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT, Bit 3 (18): isDSPhat) - u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT) - | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)); + 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)), BACKLIGHT_BIT) + | BIT_SET(isPhat(), DSPHAT_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/romsel_r4theme/arm9/source/main.cpp b/romsel_r4theme/arm9/source/main.cpp index 42f868c2b2..f63bc06637 100644 --- a/romsel_r4theme/arm9/source/main.cpp +++ b/romsel_r4theme/arm9/source/main.cpp @@ -765,7 +765,7 @@ void loadGameOnFlashcard(const char* ndsPath, bool dsGame) { || (memcmp(io_dldi_data->friendlyName, "R4iTT", 5) == 0) || (memcmp(io_dldi_data->friendlyName, "Acekard AK2", 0xB) == 0) || (memcmp(io_dldi_data->friendlyName, "Ace3DS+", 7) == 0)) { - if (sys().isDSLite()) { + if (sys().hasRegulableBacklight()) { CIniFile backlightini("fat:/_wfwd/backlight.ini"); backlightini.SetInt("brightness", "brightness", *(int*)0x02003000); backlightini.SaveIniFile("fat:/_wfwd/backlight.ini"); diff --git a/settings/arm7/source/main.c b/settings/arm7/source/main.c index bed8eaf97c..2354d02b34 100644 --- a/settings/arm7/source/main.c +++ b/settings/arm7/source/main.c @@ -30,6 +30,7 @@ #include #include #include +#include "common/isPhatCheck.h" #include "common/arm7status.h" #define REG_SCFG_WL *(vu16*)0x4004020 @@ -216,11 +217,11 @@ int main() { *(vu32*)0x037C0000 = wordBak; } - u8 readCommand = readPowerManagement(4); + u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL); // 01: Fade Out // 02: Return - // 03: status (Bit 0: isDSLite, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT) + // 03: status (Bit 0: hasRegulableBacklight, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT, Bit 3: isDSPhat) // 03: Status: Init/Volume/Battery/SD @@ -228,10 +229,12 @@ int main() { // Battery is 7 bits -- bits 0-7 // Volume is 00h to 1Fh = 5 bits -- bits 8-12 // SD status -- bits 13-14 - // Init status -- bits 15-17 (Bit 0 (15): isDSLite, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT) + // Init status -- bits 15-18 (Bit 0 (15): hasRegulableBacklight, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT, Bit 3 (18): isDSPhat) u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT) - | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)); + | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT) + | BIT_SET(!!(pmBacklight & BIT(4) || pmBacklight & BIT(5) || pmBacklight & BIT(6) || pmBacklight & BIT(7)), BACKLIGHT_BIT) + | BIT_SET(isPhat(), DSPHAT_BIT)); status = (status & ~INIT_MASK) | ((initStatus << INIT_OFF) & INIT_MASK); fifoSendValue32(FIFO_USER_03, status); diff --git a/settings/arm9/source/main.cpp b/settings/arm9/source/main.cpp index 6e60f52548..cfae2f474c 100644 --- a/settings/arm9/source/main.cpp +++ b/settings/arm9/source/main.cpp @@ -49,6 +49,7 @@ int currentTheme = 0; bool currentMacroMode = false; +bool wasBacklightOff = false; static TWLSettings::TExploit previousDSiWareExploit = TWLSettings::EExploitNone; static int previousSysRegion = 0; @@ -778,7 +779,7 @@ void defaultExitHandler() } if (ms().macroMode) { powerOff(PM_BACKLIGHT_TOP); - } else { + } else if(!wasBacklightOff) { powerOn(PM_BACKLIGHT_TOP); } if (ms().showMainMenu) { @@ -844,10 +845,12 @@ void customSleep() { swiWaitForVBlank(); } irqEnable(IRQ_VBLANK & IRQ_VCOUNT); - if (!currentMacroMode) { - powerOn(PM_BACKLIGHT_TOP); + if(!wasBacklightOff) { + if (!currentMacroMode) { + powerOn(PM_BACKLIGHT_TOP); + } + powerOn(PM_BACKLIGHT_BOTTOM); } - powerOn(PM_BACKLIGHT_BOTTOM); mmResume(); fadeType = true; *(int*)0x02003004 = 2; // Fade in sound @@ -876,6 +879,8 @@ int settingsMode(void) snd().init(); keysSetRepeat(25, 5); + + wasBacklightOff = sys().isRegularDS() && (REG_POWERCNT & 0xC) == 0; bool widescreenFound = false; // bool lumaFound = false; diff --git a/title/arm7/source/main.c b/title/arm7/source/main.c index 3768d36557..417f4f3b7b 100644 --- a/title/arm7/source/main.c +++ b/title/arm7/source/main.c @@ -30,6 +30,7 @@ #include #include #include +#include "common/isPhatCheck.h" #include "common/arm7status.h" #define REG_SCFG_WL *(vu16*)0x4004020 @@ -235,9 +236,11 @@ 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) + // 03: status (Bit 0: hasRegulableBacklight, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT, Bit 3: isDSPhat) // 03: Status: Init/Volume/Battery/SD @@ -245,17 +248,17 @@ int main() { // Battery is 7 bits -- bits 0-7 // Volume is 00h to 1Fh = 5 bits -- bits 8-12 // SD status -- bits 13-14 - // Init status -- bits 15-17 (Bit 0 (15): isDSLite, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT) + // Init status -- bits 15-18 (Bit 0 (15): hasRegulableBacklight, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT, Bit 3 (18): isDSPhat) u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT) - | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)); + | BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT) + | BIT_SET(!!(pmBacklight & BIT(4) || pmBacklight & BIT(5) || pmBacklight & BIT(6) || pmBacklight & BIT(7)), BACKLIGHT_BIT) + | BIT_SET(isPhat(), DSPHAT_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/title/arm9/source/main.cpp b/title/arm9/source/main.cpp index f4b213f916..8e91288b14 100644 --- a/title/arm9/source/main.cpp +++ b/title/arm9/source/main.cpp @@ -655,7 +655,7 @@ void lastRunROM() || (memcmp(io_dldi_data->friendlyName, "R4iTT", 5) == 0) || (memcmp(io_dldi_data->friendlyName, "Acekard AK2", 0xB) == 0) || (memcmp(io_dldi_data->friendlyName, "Ace3DS+", 7) == 0)) { - if (sys().isDSLite()) { + if (sys().hasRegulableBacklight()) { CIniFile backlightini("fat:/_wfwd/backlight.ini"); backlightini.SetInt("brightness", "brightness", *(int*)0x02003000); backlightini.SaveIniFile("fat:/_wfwd/backlight.ini"); diff --git a/universal/include/common/arm7status.h b/universal/include/common/arm7status.h index d36e28e0f3..abcc6b5315 100644 --- a/universal/include/common/arm7status.h +++ b/universal/include/common/arm7status.h @@ -2,9 +2,10 @@ #ifndef A7STAT_H #define A7STAT_H +#define DSPHAT_BIT 3 #define SNDEXTCNT_BIT 2 #define REGSCFG_BIT 1 -#define DSLITE_BIT 0 +#define BACKLIGHT_BIT 0 #define BAT_MASK 0b00000000000011111111 #define BAT_OFF 0 @@ -15,6 +16,6 @@ #define SD_MASK 0b00000110000000000000 #define SD_OFF 13 -#define INIT_MASK 0b00111000000000000000 +#define INIT_MASK 0b01111000000000000000 #define INIT_OFF 15 #endif \ No newline at end of file diff --git a/universal/include/common/isPhatCheck.h b/universal/include/common/isPhatCheck.h new file mode 100644 index 0000000000..e9f1218d97 --- /dev/null +++ b/universal/include/common/isPhatCheck.h @@ -0,0 +1,27 @@ +#ifndef IS_PHAT_CHECK_H +#define IS_PHAT_CHECK_H + +#include + +#define FLASHM_BACKUPHEADER 0x3f680 +#define FLASHME_MAJOR_VER 0x17c + +static inline bool isPhat() { + if(!!(REG_SNDEXTCNT)) return false; + u8 consoleType = 0; + readFirmware(0x1D, &consoleType, 1); + if(consoleType == 0xff) return true; + + 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); + return memcmp(unusedShouldBeZeroFilledOnPhat, contentsOnLite,6) != 0; + } + return false; +} + +#endif //IS_PHAT_CHECK_H \ No newline at end of file diff --git a/universal/include/common/systemdetails.h b/universal/include/common/systemdetails.h index 2d0d7b0b07..2bd16c5439 100644 --- a/universal/include/common/systemdetails.h +++ b/universal/include/common/systemdetails.h @@ -27,6 +27,7 @@ class SystemDetails bool useNitroFS() { return _nitroFsInitOk; } bool isDSPhat() { return (_isRegularDS && _isDSPhat); } bool isDSLite() { return (_isRegularDS && !_isDSPhat); } + bool hasRegulableBacklight() { return _hasRegulableBacklight; } bool dsDebugRam() { return (_dsDebugRam); } void initFilesystem(const char *runningPath); void initArm7RegStatuses(); @@ -40,6 +41,7 @@ class SystemDetails bool _isRunFromSD; bool _isRegularDS; bool _isDSPhat; + bool _hasRegulableBacklight; bool _dsDebugRam; bool _fatInitOk; bool _fifoOk; diff --git a/universal/source/common/systemdetails.cpp b/universal/source/common/systemdetails.cpp index 5bba157abc..8904400c05 100644 --- a/universal/source/common/systemdetails.cpp +++ b/universal/source/common/systemdetails.cpp @@ -35,6 +35,7 @@ SystemDetails::SystemDetails() _arm7SCFGLocked = false; _isRegularDS = true; _isDSPhat = false; + _hasRegulableBacklight = true; _nitroFsInitOk = false; _fatInitOk = false; _fifoOk = false; @@ -59,23 +60,9 @@ SystemDetails::SystemDetails() _isRegularDS = false; // If sound frequency setting is found, then the console is not a DS Phat/Lite } - 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; - } - } - } + _isDSPhat = CHECK_BIT(status, DSPHAT_BIT) != 0; + + _hasRegulableBacklight = CHECK_BIT(status, BACKLIGHT_BIT) != 0; if (!dsiFeatures()) { u32 wordBak = *(vu32*)0x02800000;