Skip to content

Commit

Permalink
Allow to turn off backlight on quick menu (#2316)
Browse files Browse the repository at this point in the history
Also move the ds phat check to arm7, as on arm9 it was broken
  • Loading branch information
edo9300 authored Oct 23, 2023
1 parent fb01e69 commit b76ddaa
Show file tree
Hide file tree
Showing 21 changed files with 167 additions and 117 deletions.
16 changes: 9 additions & 7 deletions 3dssplash/arm7/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
---------------------------------------------------------------------------------*/
#include <nds.h>
#include <maxmod7.h>
#include "common/isPhatCheck.h"
#include "common/arm7status.h"

void my_touchInit();
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 9 additions & 6 deletions imageview/arm7/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
---------------------------------------------------------------------------------*/
#include <nds.h>
#include <maxmod7.h>
#include "common/isPhatCheck.h"
#include "common/arm7status.h"

void my_touchInit();
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 9 additions & 6 deletions manual/arm7/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
---------------------------------------------------------------------------------*/
#include <nds.h>
#include <maxmod7.h>
#include "common/isPhatCheck.h"
#include "common/arm7status.h"

void my_touchInit();
Expand Down Expand Up @@ -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);
Expand Down
50 changes: 36 additions & 14 deletions quickmenu/arm7/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <nds.h>
#include <string.h>
#include <maxmod7.h>
#include "common/isPhatCheck.h"
#include "common/arm7status.h"

#define REG_SCFG_WL *(vu16*)0x4004020
Expand All @@ -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) {
Expand All @@ -63,7 +66,7 @@ void soundFadeOut() {
}

//---------------------------------------------------------------------------------
void ReturntoDSiMenu() {
void ReturntoDSiMenu(void) {
//---------------------------------------------------------------------------------
nocashMessage("ARM7 ReturnToDSiMenu");
if (isDSiMode()) {
Expand All @@ -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;
}

Expand All @@ -113,7 +125,7 @@ void VblankHandler(void) {
}

//---------------------------------------------------------------------------------
void VcountHandler() {
void VcountHandler(void) {
//---------------------------------------------------------------------------------
void my_inputGetAndSend(void);
my_inputGetAndSend();
Expand All @@ -122,7 +134,7 @@ void VcountHandler() {
volatile bool exitflag = false;

//---------------------------------------------------------------------------------
void powerButtonCB() {
void powerButtonCB(void) {
//---------------------------------------------------------------------------------
exitflag = true;
}
Expand Down Expand Up @@ -230,20 +242,27 @@ 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
// 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(!!(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);
Expand All @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion quickmenu/arm9/source/graphics/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
10 changes: 5 additions & 5 deletions quickmenu/arm9/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 0 additions & 20 deletions romsel_aktheme/arm7/source/arm7status.h

This file was deleted.

22 changes: 14 additions & 8 deletions romsel_aktheme/arm7/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
#include <nds.h>
#include <string.h>
#include <maxmod7.h>
#include "arm7status.h"
#include "common/isPhatCheck.h"
#include "common/arm7status.h"

#define BIT_SET(c, n) ((c) << (n))

Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit b76ddaa

Please sign in to comment.