Skip to content

Commit b76ddaa

Browse files
authored
Allow to turn off backlight on quick menu (#2316)
Also move the ds phat check to arm7, as on arm9 it was broken
1 parent fb01e69 commit b76ddaa

File tree

21 files changed

+167
-117
lines changed

21 files changed

+167
-117
lines changed

3dssplash/arm7/source/main.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
---------------------------------------------------------------------------------*/
3030
#include <nds.h>
3131
#include <maxmod7.h>
32+
#include "common/isPhatCheck.h"
3233
#include "common/arm7status.h"
3334

3435
void my_touchInit();
@@ -111,23 +112,24 @@ int main() {
111112

112113
setPowerButtonCB(powerButtonCB);
113114

114-
u8 readCommand = readPowerManagement(4);
115+
u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL);
115116

116117
// 01: Fade Out
117118
// 02: Return
118-
// 03: status (Bit 0: isDSLite, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT)
119-
119+
// 03: status (Bit 0: hasRegulableBacklight, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT, Bit 3: isDSPhat)
120+
120121

121122
// 03: Status: Init/Volume/Battery/SD
122123
// https://problemkaputt.de/gbatek.htm#dsii2cdevice4ahbptwlchip
123124
// Battery is 7 bits -- bits 0-7
124125
// Volume is 00h to 1Fh = 5 bits -- bits 8-12
125126
// SD status -- bits 13-14
126-
// Init status -- bits 15-17 (Bit 0 (15): isDSLite, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT)
127+
// Init status -- bits 15-18 (Bit 0 (15): hasRegulableBacklight, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT, Bit 3 (18): isDSPhat)
127128

128-
u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT)
129-
| BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)
130-
| BIT_SET(!!(readCommand & BIT(4) || readCommand & BIT(5) || readCommand & BIT(6) || readCommand & BIT(7)), DSLITE_BIT));
129+
u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT)
130+
| BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)
131+
| BIT_SET(!!(pmBacklight & BIT(4) || pmBacklight & BIT(5) || pmBacklight & BIT(6) || pmBacklight & BIT(7)), BACKLIGHT_BIT)
132+
| BIT_SET(isPhat(), DSPHAT_BIT));
131133

132134
status = (status & ~INIT_MASK) | ((initStatus << INIT_OFF) & INIT_MASK);
133135
fifoSendValue32(FIFO_USER_03, status);

imageview/arm7/source/main.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
---------------------------------------------------------------------------------*/
3030
#include <nds.h>
3131
#include <maxmod7.h>
32+
#include "common/isPhatCheck.h"
3233
#include "common/arm7status.h"
3334

3435
void my_touchInit();
@@ -114,22 +115,24 @@ int main() {
114115

115116
setPowerButtonCB(powerButtonCB);
116117

117-
u8 readCommand = readPowerManagement(4);
118+
u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL);
118119

119120
// 01: Fade Out
120121
// 02: Return
121-
// 03: status (Bit 0: isDSLite, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT)
122-
122+
// 03: status (Bit 0: hasRegulableBacklight, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT, Bit 3: isDSPhat)
123+
123124

124125
// 03: Status: Init/Volume/Battery/SD
125126
// https://problemkaputt.de/gbatek.htm#dsii2cdevice4ahbptwlchip
126127
// Battery is 7 bits -- bits 0-7
127128
// Volume is 00h to 1Fh = 5 bits -- bits 8-12
128129
// SD status -- bits 13-14
129-
// Init status -- bits 15-17 (Bit 0 (15): isDSLite, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT)
130+
// Init status -- bits 15-18 (Bit 0 (15): hasRegulableBacklight, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT, Bit 3 (18): isDSPhat)
130131

131-
u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT)
132-
| BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT));
132+
u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT)
133+
| BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)
134+
| BIT_SET(!!(pmBacklight & BIT(4) || pmBacklight & BIT(5) || pmBacklight & BIT(6) || pmBacklight & BIT(7)), BACKLIGHT_BIT)
135+
| BIT_SET(isPhat(), DSPHAT_BIT));
133136

134137
status = (status & ~INIT_MASK) | ((initStatus << INIT_OFF) & INIT_MASK);
135138
fifoSendValue32(FIFO_USER_03, status);

manual/arm7/source/main.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
---------------------------------------------------------------------------------*/
3030
#include <nds.h>
3131
#include <maxmod7.h>
32+
#include "common/isPhatCheck.h"
3233
#include "common/arm7status.h"
3334

3435
void my_touchInit();
@@ -112,22 +113,24 @@ int main() {
112113

113114
irqEnable(IRQ_VBLANK | IRQ_VCOUNT);
114115

115-
setPowerButtonCB(powerButtonCB);
116+
u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL);
116117

117118
// 01: Fade Out
118119
// 02: Return
119-
// 03: status (Bit 0: isDSLite, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT)
120-
120+
// 03: status (Bit 0: hasRegulableBacklight, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT, Bit 3: isDSPhat)
121+
121122

122123
// 03: Status: Init/Volume/Battery/SD
123124
// https://problemkaputt.de/gbatek.htm#dsii2cdevice4ahbptwlchip
124125
// Battery is 7 bits -- bits 0-7
125126
// Volume is 00h to 1Fh = 5 bits -- bits 8-12
126127
// SD status -- bits 13-14
127-
// Init status -- bits 15-17 (Bit 0 (15): isDSLite, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT)
128+
// Init status -- bits 15-18 (Bit 0 (15): hasRegulableBacklight, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT, Bit 3 (18): isDSPhat)
128129

129-
u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT)
130-
| BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT));
130+
u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT)
131+
| BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)
132+
| BIT_SET(!!(pmBacklight & BIT(4) || pmBacklight & BIT(5) || pmBacklight & BIT(6) || pmBacklight & BIT(7)), BACKLIGHT_BIT)
133+
| BIT_SET(isPhat(), DSPHAT_BIT));
131134

132135
status = (status & ~INIT_MASK) | ((initStatus << INIT_OFF) & INIT_MASK);
133136
fifoSendValue32(FIFO_USER_03, status);

quickmenu/arm7/source/main.c

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <nds.h>
3131
#include <string.h>
3232
#include <maxmod7.h>
33+
#include "common/isPhatCheck.h"
3334
#include "common/arm7status.h"
3435

3536
#define REG_SCFG_WL *(vu16*)0x4004020
@@ -49,12 +50,14 @@ static int soundVolume = 127;
4950
volatile int rebootTimer = 0;
5051
volatile int status = 0;
5152
static int backlightLevel = 0;
53+
static bool isDSPhat = false;
54+
static bool hasRegulableBacklight = false;
5255

5356
//static bool gotCartHeader = false;
5457

5558

5659
//---------------------------------------------------------------------------------
57-
void soundFadeOut() {
60+
void soundFadeOut(void) {
5861
//---------------------------------------------------------------------------------
5962
soundVolume -= 3;
6063
if (soundVolume < 0) {
@@ -63,7 +66,7 @@ void soundFadeOut() {
6366
}
6467

6568
//---------------------------------------------------------------------------------
66-
void ReturntoDSiMenu() {
69+
void ReturntoDSiMenu(void) {
6770
//---------------------------------------------------------------------------------
6871
nocashMessage("ARM7 ReturnToDSiMenu");
6972
if (isDSiMode()) {
@@ -77,17 +80,26 @@ void ReturntoDSiMenu() {
7780
}
7881

7982
//---------------------------------------------------------------------------------
80-
void changeBacklightLevel() {
83+
void changeBacklightLevel(void) {
8184
//---------------------------------------------------------------------------------
8285
if (REG_SNDEXTCNT == 0) {
83-
backlightLevel++;
84-
if (backlightLevel > 3) {
86+
// if the backlight is regulable the range will be 0 - 3
87+
// if the backlight is regulable and the console is a phat the range will be 0 - 4 (with 4 being backlight off)
88+
// if the backlight is not regulable the only possible values will be 0 and 4 (with 4 being backlight off)
89+
backlightLevel += 1 + (3 * !hasRegulableBacklight);
90+
91+
if (backlightLevel > (3 + isDSPhat)) {
8592
backlightLevel = 0;
8693
}
87-
u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL);
88-
if (pmBacklight & 0xF0) // DS Lite
89-
writePowerManagement(PM_BACKLIGHT_LEVEL, (pmBacklight & ~3) | backlightLevel);
90-
writePowerManagement(PM_CONTROL_REG, readPowerManagement(PM_CONTROL_REG) | 0xC);
94+
if (hasRegulableBacklight) {
95+
u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL);
96+
writePowerManagement(PM_BACKLIGHT_LEVEL, (pmBacklight & ~3) | (backlightLevel & 0x3));
97+
}
98+
99+
if(backlightLevel == 4)
100+
writePowerManagement(PM_CONTROL_REG, readPowerManagement(PM_CONTROL_REG) & ~0xC);
101+
else
102+
writePowerManagement(PM_CONTROL_REG, readPowerManagement(PM_CONTROL_REG) | 0xC);
91103
return;
92104
}
93105

@@ -113,7 +125,7 @@ void VblankHandler(void) {
113125
}
114126

115127
//---------------------------------------------------------------------------------
116-
void VcountHandler() {
128+
void VcountHandler(void) {
117129
//---------------------------------------------------------------------------------
118130
void my_inputGetAndSend(void);
119131
my_inputGetAndSend();
@@ -122,7 +134,7 @@ void VcountHandler() {
122134
volatile bool exitflag = false;
123135

124136
//---------------------------------------------------------------------------------
125-
void powerButtonCB() {
137+
void powerButtonCB(void) {
126138
//---------------------------------------------------------------------------------
127139
exitflag = true;
128140
}
@@ -230,20 +242,27 @@ int main() {
230242
*(vu32*)0x037C0000 = wordBak;
231243
}
232244

245+
u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL);
246+
247+
hasRegulableBacklight = !!(pmBacklight & BIT(4) || pmBacklight & BIT(5) || pmBacklight & BIT(6) || pmBacklight & BIT(7));
248+
isDSPhat = isPhat();
249+
233250
// 01: Fade Out
234251
// 02: Return
235-
// 03: status (Bit 0: isDSLite, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT)
252+
// 03: status (Bit 0: hasRegulableBacklight, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT, Bit 3: isDSPhat)
236253

237254

238255
// 03: Status: Init/Volume/Battery/SD
239256
// https://problemkaputt.de/gbatek.htm#dsii2cdevice4ahbptwlchip
240257
// Battery is 7 bits -- bits 0-7
241258
// Volume is 00h to 1Fh = 5 bits -- bits 8-12
242259
// SD status -- bits 13-14
243-
// Init status -- bits 15-17 (Bit 0 (15): isDSLite, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT)
260+
// Init status -- bits 15-18 (Bit 0 (15): hasRegulableBacklight, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT, Bit 3 (18): isDSPhat)
244261

245262
u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT)
246-
| BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT));
263+
| BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)
264+
| BIT_SET(hasRegulableBacklight, BACKLIGHT_BIT)
265+
| BIT_SET(isDSPhat, DSPHAT_BIT));
247266

248267
status = (status & ~INIT_MASK) | ((initStatus << INIT_OFF) & INIT_MASK);
249268
fifoSendValue32(FIFO_USER_03, status);
@@ -253,6 +272,9 @@ int main() {
253272

254273
if (pmBacklight & 0xF0) // DS Lite
255274
backlightLevel = pmBacklight & 3; // Brightness
275+
276+
if((readPowerManagement(PM_CONTROL_REG) & 0xC) == 0) // DS Phat backlight off
277+
backlightLevel = 4;
256278
}
257279

258280
if (isDSiMode()) {

quickmenu/arm9/source/graphics/graphics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ void vBlankHandler()
373373
glSprite(33, iconYpos[3], GL_FLIP_NONE, sdFound() ? &iconboxImage[0] : &iconboxImage[sys().isRegularDS() ? (((u8*)GBAROM)[0xB2] != 0x96) : 1]);
374374
int num = (io_dldi_data->ioInterface.features & FEATURE_SLOT_GBA) ? 1 : 0;
375375
drawIcon(num, 40, iconYpos[3]+6);
376-
if (sys().isDSLite() || (dsiFeatures() && ms().consoleModel < 2)) {
376+
if (sys().isRegularDS() || (dsiFeatures() && ms().consoleModel < 2)) {
377377
glSprite(10, iconYpos[4], GL_FLIP_NONE, &cornerIcons[0]);
378378
}
379379
if (bnrWirelessIcon[num] > 0) glSprite(207, iconYpos[3]+30, GL_FLIP_NONE, &wirelessIcons[(bnrWirelessIcon[1]-1) & 31]);

quickmenu/arm9/source/main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ void loadGameOnFlashcard(const char* ndsPath, bool dsGame) {
769769
|| (memcmp(io_dldi_data->friendlyName, "R4iTT", 5) == 0)
770770
|| (memcmp(io_dldi_data->friendlyName, "Acekard AK2", 0xB) == 0)
771771
|| (memcmp(io_dldi_data->friendlyName, "Ace3DS+", 7) == 0)) {
772-
if (sys().isDSLite()) {
772+
if (sys().hasRegulableBacklight()) {
773773
CIniFile backlightini("fat:/_wfwd/backlight.ini");
774774
backlightini.SetInt("brightness", "brightness", *(int*)0x02003000);
775775
backlightini.SaveIniFile("fat:/_wfwd/backlight.ini");
@@ -1733,7 +1733,7 @@ int dsClassicMenu(void) {
17331733
}
17341734

17351735
if (pressed & KEY_LEFT) {
1736-
if (cursorPosition == 2 || (cursorPosition == 5 && (sys().isDSLite() || (dsiFeatures() && ms().consoleModel < 2)))
1736+
if (cursorPosition == 2 || (cursorPosition == 5 && (sys().isRegularDS() || (dsiFeatures() && ms().consoleModel < 2)))
17371737
|| cursorPosition == 6) {
17381738
cursorPosition--;
17391739
if (cursorPosition == 5 && ms().kioskMode) {
@@ -1767,7 +1767,7 @@ int dsClassicMenu(void) {
17671767
cursorPosition = 3;
17681768
menuButtonPressed = true;
17691769
} else if (touch.px >= 10 && touch.px <= 20 && touch.py >= 175 && touch.py <= 185
1770-
&& (sys().isDSLite() || (dsiFeatures() && ms().consoleModel < 2))) {
1770+
&& (sys().isRegularDS() || (dsiFeatures() && ms().consoleModel < 2))) {
17711771
cursorPosition = 4;
17721772
menuButtonPressed = true;
17731773
} else if (touch.px >= 117 && touch.px <= 137 && touch.py >= 170 && touch.py <= 190 && !ms().kioskMode) {
@@ -2100,8 +2100,8 @@ int dsClassicMenu(void) {
21002100
break;
21012101
case 4:
21022102
// Adjust backlight level
2103-
if (sys().isDSLite() || (dsiFeatures() && ms().consoleModel < 2)) {
2104-
fifoSendValue32(FIFO_USER_04, 1);
2103+
if (sys().isRegularDS() || (dsiFeatures() && ms().consoleModel < 2)) {
2104+
fifoSendValue32(FIFO_USER_04, 1 | (sys().isDSPhat() << 1) | (sys().hasRegulableBacklight() << 2));
21052105
mmEffectEx(&snd_backlight);
21062106
}
21072107
break;

romsel_aktheme/arm7/source/arm7status.h

Lines changed: 0 additions & 20 deletions
This file was deleted.

romsel_aktheme/arm7/source/main.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
#include <nds.h>
3131
#include <string.h>
3232
#include <maxmod7.h>
33-
#include "arm7status.h"
33+
#include "common/isPhatCheck.h"
34+
#include "common/arm7status.h"
3435

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

@@ -132,20 +133,25 @@ int main() {
132133
irqEnable( IRQ_VBLANK | IRQ_VCOUNT );
133134

134135
setPowerButtonCB(powerButtonCB);
135-
136+
137+
u8 pmBacklight = readPowerManagement(PM_BACKLIGHT_LEVEL);
138+
136139
// 01: Fade Out
137140
// 02: Return
138-
// 03: status (Bit 0: isDSLite, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT)
139-
141+
// 03: status (Bit 0: hasRegulableBacklight, Bit 1: scfgEnabled, Bit 2: REG_SNDEXTCNT, Bit 3: isDSPhat)
142+
140143

141-
// 05: Volume/Battery/SD
144+
// 03: Status: Init/Volume/Battery/SD
142145
// https://problemkaputt.de/gbatek.htm#dsii2cdevice4ahbptwlchip
143146
// Battery is 7 bits -- bits 0-7
144147
// Volume is 00h to 1Fh = 5 bits -- bits 8-12
145-
// SD status -- bit 13
148+
// SD status -- bits 13-14
149+
// Init status -- bits 15-18 (Bit 0 (15): hasRegulableBacklight, Bit 1 (16): scfgEnabled, Bit 2 (17): REG_SNDEXTCNT, Bit 3 (18): isDSPhat)
146150

147-
u32 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT)
148-
| BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT));
151+
u8 initStatus = (BIT_SET(!!(REG_SNDEXTCNT), SNDEXTCNT_BIT)
152+
| BIT_SET(!!(REG_SCFG_EXT), REGSCFG_BIT)
153+
| BIT_SET(!!(pmBacklight & BIT(4) || pmBacklight & BIT(5) || pmBacklight & BIT(6) || pmBacklight & BIT(7)), BACKLIGHT_BIT)
154+
| BIT_SET(isPhat(), DSPHAT_BIT));
149155

150156
status = (status & ~INIT_MASK) | ((initStatus << INIT_OFF) & INIT_MASK);
151157
fifoSendValue32(FIFO_USER_03, status);

0 commit comments

Comments
 (0)