From 31f4419eec0705a131c98f74ebd23001d2275e1d Mon Sep 17 00:00:00 2001 From: Aurora Wright Date: Tue, 6 Jun 2017 02:12:18 +0200 Subject: [PATCH] Refactor screen functions, completely fix config not saving bug --- arm11/source/main.c | 27 +++++++++------------------ arm11/source/types.h | 3 +-- source/config.c | 11 +++++++---- source/config.h | 2 +- source/fs.c | 3 --- source/screen.c | 38 ++++++++++++++++---------------------- source/screen.h | 3 +-- 7 files changed, 35 insertions(+), 52 deletions(-) diff --git a/arm11/source/main.c b/arm11/source/main.c index 1a9c2c4..5740ae4 100644 --- a/arm11/source/main.c +++ b/arm11/source/main.c @@ -37,7 +37,7 @@ extern u32 prepareForFirmlaunchSize; extern volatile Arm11Operation operation; -static void initScreensSequence(u32 brightnessLevel) +static void initScreens(u32 brightnessLevel, struct fb *fbs) { *(vu32 *)0x10141200 = 0x1007F; *(vu32 *)0x10202014 = 0x00000001; @@ -70,10 +70,13 @@ static void initScreensSequence(u32 brightnessLevel) *(vu32 *)0x1040045C = 0x00f00190; *(vu32 *)0x10400460 = 0x01c100d1; *(vu32 *)0x10400464 = 0x01920002; - *(vu32 *)0x10400468 = 0x18300000; + *(vu32 *)0x10400468 = (u32)fbs[0].top_left; + *(vu32 *)0x1040046C = (u32)fbs[1].top_left; *(vu32 *)0x10400470 = 0x80341; *(vu32 *)0x10400474 = 0x00010501; *(vu32 *)0x10400478 = 0; + *(vu32 *)0x10400494 = (u32)fbs[0].top_right; + *(vu32 *)0x10400498 = (u32)fbs[1].top_right; *(vu32 *)0x10400490 = 0x000002D0; *(vu32 *)0x1040049C = 0x00000000; @@ -104,7 +107,8 @@ static void initScreensSequence(u32 brightnessLevel) *(vu32 *)0x1040055C = 0x00f00140; *(vu32 *)0x10400560 = 0x01c100d1; *(vu32 *)0x10400564 = 0x01920052; - *(vu32 *)0x10400568 = 0x18300000 + 0x46500; + *(vu32 *)0x10400568 = (u32)fbs[0].bottom; + *(vu32 *)0x1040056C = (u32)fbs[1].bottom; *(vu32 *)0x10400570 = 0x80301; *(vu32 *)0x10400574 = 0x00010501; *(vu32 *)0x10400578 = 0; @@ -116,16 +120,6 @@ static void initScreensSequence(u32 brightnessLevel) *(vu32 *)0x10400584 = 0x10101 * i; } -static void setupFramebuffers(struct fb *fbs) -{ - *(vu32 *)0x10400468 = (u32)fbs[0].top_left; - *(vu32 *)0x1040046c = (u32)fbs[1].top_left; - *(vu32 *)0x10400494 = (u32)fbs[0].top_right; - *(vu32 *)0x10400498 = (u32)fbs[1].top_right; - *(vu32 *)0x10400568 = (u32)fbs[0].bottom; - *(vu32 *)0x1040056c = (u32)fbs[1].bottom; -} - static void clearScreens(struct fb *fb) { //Setting up two simultaneous memory fills using the GPU @@ -178,11 +172,8 @@ void main(void) { case ARM11_READY: continue; - case INIT_SCREENS_SEQUENCE: - initScreensSequence(*(vu32 *)ARM11_PARAMETERS_ADDRESS); - break; - case SETUP_FRAMEBUFFERS: - setupFramebuffers((struct fb *)ARM11_PARAMETERS_ADDRESS); + case INIT_SCREENS: + initScreens(*(vu32 *)ARM11_PARAMETERS_ADDRESS, (struct fb *)(ARM11_PARAMETERS_ADDRESS + 4)); break; case CLEAR_SCREENS: clearScreens((struct fb *)ARM11_PARAMETERS_ADDRESS); diff --git a/arm11/source/types.h b/arm11/source/types.h index e8af14f..70efb1a 100644 --- a/arm11/source/types.h +++ b/arm11/source/types.h @@ -54,8 +54,7 @@ struct fb { typedef enum { - INIT_SCREENS_SEQUENCE = 0, - SETUP_FRAMEBUFFERS, + INIT_SCREENS = 0, CLEAR_SCREENS, SWAP_FRAMEBUFFERS, UPDATE_BRIGHTNESS, diff --git a/source/config.c b/source/config.c index 3019ee0..8db8a22 100644 --- a/source/config.c +++ b/source/config.c @@ -57,19 +57,20 @@ bool readConfig(void) return ret; } -void writeConfig(bool isPayloadLaunch) +void writeConfig(bool isConfigOptions) { - if(isPayloadLaunch) configData.config = (configData.config & 0xFFFFFF80) | (oldConfig & 0x7F); - /* If the configuration is different from previously, overwrite it. Just the no-forcing flag being set is not enough */ - if(needConfig != CREATE_CONFIGURATION && (configData.config & 0xFFFFFFBF) == oldConfig) return; + if(needConfig != CREATE_CONFIGURATION && ((isConfigOptions && (configData.config & 0xFFFFFF00) == (oldConfig & 0xFFFFFF00)) || + (!isConfigOptions && (configData.config & 0xBF) == (oldConfig & 0xFF)))) return; if(needConfig == CREATE_CONFIGURATION) { memcpy(configData.magic, "CONF", 4); configData.formatVersionMajor = CONFIG_VERSIONMAJOR; configData.formatVersionMinor = CONFIG_VERSIONMINOR; + + needConfig = MODIFY_CONFIGURATION; } if(!fileWrite(&configData, CONFIG_FILE, sizeof(CfgData))) @@ -387,6 +388,8 @@ void configMenu(bool oldPinStatus, u32 oldPinMode) if(newPinMode != 0) newPin(oldPinStatus && newPinMode == oldPinMode, newPinMode); else if(oldPinStatus) fileDelete(PIN_FILE); + writeConfig(true); + while(HID_PAD & PIN_BUTTONS); wait(2000ULL); } diff --git a/source/config.h b/source/config.h index 24de63d..7f82c63 100644 --- a/source/config.h +++ b/source/config.h @@ -69,5 +69,5 @@ typedef enum ConfigurationStatus } ConfigurationStatus; bool readConfig(void); -void writeConfig(bool isPayloadLaunch); +void writeConfig(bool isConfigOptions); void configMenu(bool oldPinStatus, u32 oldPinMode); diff --git a/source/fs.c b/source/fs.c index f35736c..658c75e 100644 --- a/source/fs.c +++ b/source/fs.c @@ -33,7 +33,6 @@ #include "screen.h" #include "draw.h" #include "utils.h" -#include "config.h" #include "fatfs/ff.h" #include "buttons.h" #include "firm.h" @@ -167,8 +166,6 @@ void loadPayload(u32 pressed, const char *payloadPath) if(payloadSize <= 0x200 || !checkFirmPayload(payloadSize)) return; - writeConfig(true); - if(isSdMode) sprintf(absPath, "sdmc:/luma/%s", path); else sprintf(absPath, "nand:/rw/luma/%s", path); diff --git a/source/screen.c b/source/screen.c index 743269b..969ad61 100644 --- a/source/screen.c +++ b/source/screen.c @@ -35,7 +35,19 @@ #include "i2c.h" #include "utils.h" -struct fb fbs[2]; +struct fb fbs[2] = +{ + { + .top_left = (u8 *)0x18300000, + .top_right = (u8 *)0x18300000, + .bottom = (u8 *)0x18346500, + }, + { + .top_left = (u8 *)0x18400000, + .top_right = (u8 *)0x18400000, + .bottom = (u8 *)0x18446500, + }, +}; static const u32 brightness[4] = {0x5F, 0x4C, 0x39, 0x26}; @@ -78,25 +90,6 @@ void clearScreens(bool isAlternate) invokeArm11Function(CLEAR_SCREENS); } -static void initScreensSequence(void) -{ - *(vu32 *)ARM11_PARAMETERS_ADDRESS = brightness[MULTICONFIG(BRIGHTNESS)]; - invokeArm11Function(INIT_SCREENS_SEQUENCE); -} - -static void setupFramebuffers(void) -{ - fbs[0].top_left = (u8 *)0x18300000; - fbs[1].top_left = (u8 *)0x18400000; - fbs[0].top_right = (u8 *)0x18300000; - fbs[1].top_right = (u8 *)0x18400000; - fbs[0].bottom = (u8 *)0x18346500; - fbs[1].bottom = (u8 *)0x18446500; - - memcpy((void *)ARM11_PARAMETERS_ADDRESS, fbs, sizeof(fbs)); - invokeArm11Function(SETUP_FRAMEBUFFERS); -} - void initScreens(void) { static bool needToSetup = true; @@ -105,14 +98,15 @@ void initScreens(void) { if(!ARESCREENSINITIALIZED) { - initScreensSequence(); + *(vu32 *)ARM11_PARAMETERS_ADDRESS = brightness[MULTICONFIG(BRIGHTNESS)]; + memcpy((void *)(ARM11_PARAMETERS_ADDRESS + 4), fbs, sizeof(fbs)); + invokeArm11Function(INIT_SCREENS); //Turn on backlight i2cWriteRegister(I2C_DEV_MCU, 0x22, 0x2A); } else updateBrightness(MULTICONFIG(BRIGHTNESS)); - setupFramebuffers(); needToSetup = false; } diff --git a/source/screen.h b/source/screen.h index 185e735..c697bf2 100644 --- a/source/screen.h +++ b/source/screen.h @@ -53,8 +53,7 @@ struct fb { typedef enum { - INIT_SCREENS_SEQUENCE = 0, - SETUP_FRAMEBUFFERS, + INIT_SCREENS = 0, CLEAR_SCREENS, SWAP_FRAMEBUFFERS, UPDATE_BRIGHTNESS,