From 6f8a9421ef96b40c3a6cf7dd728187aa589a6c5e Mon Sep 17 00:00:00 2001 From: Aurora Date: Tue, 5 Apr 2016 02:20:05 +0200 Subject: [PATCH] Added basic support for configuring the brightness level for the built-in screen init --- Makefile | 2 +- patches/reboot.s | 8 ++++---- screeninit/source/main.c | 6 ++++-- source/firm.c | 4 ++-- source/screeninit.c | 3 +++ source/screeninit.h | 2 ++ source/utils.c | 18 ++++++++++++++---- 7 files changed, 30 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index da77732..be82e58 100644 --- a/Makefile +++ b/Makefile @@ -59,7 +59,7 @@ $(dir_out)/$(name).dat: $(dir_build)/main.bin $(dir_out) @dd if=$(dir_build)/main.bin of=$@ bs=512 seek=144 $(dir_out)/arm9loaderhax.bin: $(dir_build)/main.bin $(dir_out) - @cp -av $(dir_build)/main.bin $@ + @cp -a $(dir_build)/main.bin $@ $(dir_out)/3ds/$(name): $(dir_out) @mkdir -p "$(dir_out)/3ds/$(name)" diff --git a/patches/reboot.s b/patches/reboot.s index 45ec099..bae45ff 100644 --- a/patches/reboot.s +++ b/patches/reboot.s @@ -129,14 +129,14 @@ memcpy32: ; memcpy32(void *src, void *dst, unsigned int size) bytes_read: .word 0 fopen: .ascii "OPEN" .pool -firm_fname: .dcw "sdmc:/aurei/patched_firmware_sys.bin" - .word 0x0 +firm_fname: .dcw "sdmc:/aurei/patched_firmware_sys.bin" + .word 0x0 .pool twlfirm_fname: .dcw "sdmc:/aurei/patched_firmware_twl.bin" - .word 0x0 + .word 0x0 .pool agbfirm_fname: .dcw "sdmc:/aurei/patched_firmware_agb.bin" - .word 0x0 + .word 0x0 .align 4 kernelcode_start: diff --git a/screeninit/source/main.c b/screeninit/source/main.c index 01bce2c..9485ec0 100755 --- a/screeninit/source/main.c +++ b/screeninit/source/main.c @@ -2,13 +2,15 @@ void main(void) { + const u32 brightness[4] = {0x5F, 0x4C, 0x39, 0x26}; + u32 brightnessLevel = *(vu32 *)0x24F04000; vu32 *const arm11 = (u32 *)0x1FFFFFF8; *(vu32 *)0x10141200 = 0x1007F; *(vu32 *)0x10202014 = 0x00000001; *(vu32 *)0x1020200C &= 0xFFFEFFFE; - *(vu32 *)0x10202240 = 0x45; - *(vu32 *)0x10202A40 = 0x45; + *(vu32 *)0x10202240 = brightness[brightnessLevel]; + *(vu32 *)0x10202A40 = brightness[brightnessLevel]; *(vu32 *)0x10202244 = 0x1023E; *(vu32 *)0x10202A44 = 0x1023E; diff --git a/source/firm.c b/source/firm.c index 385b208..dbdae45 100755 --- a/source/firm.c +++ b/source/firm.c @@ -38,8 +38,8 @@ static u32 firmSize, selectedFirm, usePatchedFirm, emuOffset, - emuHeader, - config; + emuHeader; +u32 config; void setupCFW(void) { diff --git a/source/screeninit.c b/source/screeninit.c index 81143f2..7702196 100644 --- a/source/screeninit.c +++ b/source/screeninit.c @@ -50,6 +50,9 @@ void initScreens(void) { if(PDN_GPU_CNT == 1) { + //Write brightness level for the stub to pick up + *(vu32 *)0x24F04000 = (config >> 10) & 3; + memcpy((void *)SCREENINIT_ADDRESS, screeninit, screeninit_size); *arm11 = SCREENINIT_ADDRESS; diff --git a/source/screeninit.h b/source/screeninit.h index 3bf4c1e..cbad6c9 100644 --- a/source/screeninit.h +++ b/source/screeninit.h @@ -13,5 +13,7 @@ #define PDN_GPU_CNT (*(vu8 *)0x10141200) +u32 config; + void deinitScreens(void); void initScreens(void); \ No newline at end of file diff --git a/source/utils.c b/source/utils.c index 0e40c3a..2a62a96 100644 --- a/source/utils.c +++ b/source/utils.c @@ -72,6 +72,8 @@ void configureCFW(const char *configPath, const char *patchedFirms[]) for(u32 i = 0; i < optionsAmount; i++) options[i].enabled = (tempConfig >> i) & 1; + options[optionsAmount].enabled = (tempConfig >> 10) & 3; + //Pre-select the first configuration option u32 selectedOption = 0; @@ -81,12 +83,17 @@ void configureCFW(const char *configPath, const char *patchedFirms[]) u16 pressed = 0; do { + options[optionsAmount].posY = drawString("Screen-init brightness: 4( ) 3( ) 2( ) 1( )", 10, 53, selectedOption == optionsAmount ? COLOR_RED : COLOR_WHITE); + for(u32 i = 0; i < optionsAmount; i++) { - options[i].posY = drawString(optionsText[i], 10, !i ? 60 : options[i - 1].posY + SPACING_Y, selectedOption == i ? COLOR_RED : COLOR_WHITE); + options[i].posY = drawString(optionsText[i], 10, !i ? options[optionsAmount].posY + 2 * SPACING_Y : options[i - 1].posY + SPACING_Y, selectedOption == i ? COLOR_RED : COLOR_WHITE); drawCharacter('x', 10 + SPACING_X, options[i].posY, options[i].enabled ? (selectedOption == i ? COLOR_RED : COLOR_WHITE) : COLOR_BLACK); } + for(u32 i = 0; i < 4; i++) + drawCharacter('x', 10 + (26 + 5 * i) * SPACING_X, options[optionsAmount].posY, options[optionsAmount].enabled == i ? (selectedOption == optionsAmount ? COLOR_RED : COLOR_WHITE) : COLOR_BLACK); + pressed = waitInput(); } while(!(pressed & MENU_BUTTONS)); @@ -94,10 +101,10 @@ void configureCFW(const char *configPath, const char *patchedFirms[]) switch(pressed) { case BUTTON_UP: - selectedOption = !selectedOption ? optionsAmount - 1 : selectedOption - 1; + selectedOption = !selectedOption ? optionsAmount : selectedOption - 1; break; case BUTTON_DOWN: - selectedOption = selectedOption == optionsAmount - 1 ? 0 : selectedOption + 1; + selectedOption = selectedOption >= optionsAmount - 1 ? 0 : selectedOption + 1; break; case BUTTON_LEFT: selectedOption = 0; @@ -106,7 +113,8 @@ void configureCFW(const char *configPath, const char *patchedFirms[]) selectedOption = optionsAmount - 1; break; case BUTTON_A: - options[selectedOption].enabled = !options[selectedOption].enabled; + if(selectedOption != optionsAmount) options[selectedOption].enabled = !options[selectedOption].enabled; + else options[optionsAmount].enabled = options[optionsAmount].enabled == 3 ? 0 : options[optionsAmount].enabled + 1; break; } @@ -126,6 +134,8 @@ void configureCFW(const char *configPath, const char *patchedFirms[]) for(u32 i = 0; i < optionsAmount; i++) tempConfig |= options[i].enabled << i; + tempConfig |= options[optionsAmount].enabled << 10; + fileWrite(&tempConfig, configPath, 3); //Zero the last booted FIRM flag