From f718297591976b01d3530769d12da68636a689f6 Mon Sep 17 00:00:00 2001 From: TuxSH Date: Tue, 26 Feb 2019 20:19:52 +0100 Subject: [PATCH] Fix screens not working on firmlaunch - LCD fill was not unset - Still needs to do screeninit on firmlaunch even though PDN_GPU_CNT is 0x1007F --- arm11/source/main.c | 21 +++++++++++++++++++++ exceptions/arm9/source/types.h | 4 ++-- source/screen.c | 10 +++++----- source/screen.h | 6 ++++-- source/utils.c | 17 ++++++----------- 5 files changed, 38 insertions(+), 20 deletions(-) diff --git a/arm11/source/main.c b/arm11/source/main.c index 3d4ce67..5be2c5e 100644 --- a/arm11/source/main.c +++ b/arm11/source/main.c @@ -40,6 +40,10 @@ extern volatile Arm11Operation operation; static void initScreens(u32 brightnessLevel, struct fb *fbs) { *(vu32 *)0x10141200 = 0x1007F; + + *(vu32 *)0x10202204 = 0x01000000; //set LCD fill black to hide potential garbage -- NFIRM does it before firmlaunching + *(vu32 *)0x10202A04 = 0x01000000; + *(vu32 *)0x10202014 = 0x00000001; *(vu32 *)0x1020200C &= 0xFFFEFFFE; *(vu32 *)0x10202240 = brightnessLevel; @@ -118,16 +122,33 @@ static void initScreens(u32 brightnessLevel, struct fb *fbs) //Disco register for(u32 i = 0; i < 256; i++) *(vu32 *)0x10400584 = 0x10101 * i; + + *(vu32 *)0x10202204 = 0x00000000; //unset LCD fill + *(vu32 *)0x10202A04 = 0x00000000; } static void setupFramebuffers(struct fb *fbs) { + *(vu32 *)0x10202204 = 0x01000000; //set LCD fill black to hide potential garbage -- NFIRM does it before firmlaunching + *(vu32 *)0x10202A04 = 0x01000000; + *(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; + + //Set framebuffer format, framebuffer select and stride + *(vu32 *)0x10400470 = 0x80341; + *(vu32 *)0x10400478 = 0; + *(vu32 *)0x10400490 = 0x2D0; + *(vu32 *)0x10400570 = 0x80301; + *(vu32 *)0x10400578 = 0; + *(vu32 *)0x10400590 = 0x2D0; + + *(vu32 *)0x10202204 = 0x00000000; //unset LCD fill + *(vu32 *)0x10202A04 = 0x00000000; } static void clearScreens(struct fb *fb) diff --git a/exceptions/arm9/source/types.h b/exceptions/arm9/source/types.h index 484a03b..23d5e7a 100644 --- a/exceptions/arm9/source/types.h +++ b/exceptions/arm9/source/types.h @@ -40,6 +40,6 @@ typedef volatile u16 vu16; typedef volatile u32 vu32; typedef volatile u64 vu64; -#define PDN_GPU_CNT (*(vu8 *)0x10141200) +#define PDN_GPU_CNT (*(vu32 *)0x10141200) -#define ARESCREENSINITIALIZED (PDN_GPU_CNT != 1) +#define ARESCREENSINITIALIZED ((PDN_GPU_CNT & 0xFF) != 1) diff --git a/source/screen.c b/source/screen.c index 7e0e772..3793944 100644 --- a/source/screen.c +++ b/source/screen.c @@ -35,6 +35,8 @@ #include "i2c.h" #include "utils.h" +bool needToSetupScreens = true; + struct fb fbs[2] = { { @@ -92,11 +94,9 @@ void clearScreens(bool isAlternate) void initScreens(void) { - static bool needToSetup = true; - - if(needToSetup) + if(needToSetupScreens) { - if(!ARESCREENSINITIALIZED) + if(!ARESCREENSINITIALIZED || bootType == FIRMLAUNCH) { *(vu32 *)ARM11_PARAMETERS_ADDRESS = brightness[MULTICONFIG(BRIGHTNESS)]; memcpy((void *)(ARM11_PARAMETERS_ADDRESS + 4), fbs, sizeof(fbs)); @@ -111,7 +111,7 @@ void initScreens(void) invokeArm11Function(SETUP_FRAMEBUFFERS); clearScreens(true); - needToSetup = false; + needToSetupScreens = false; } clearScreens(false); diff --git a/source/screen.h b/source/screen.h index a5eb733..79ae987 100644 --- a/source/screen.h +++ b/source/screen.h @@ -33,9 +33,9 @@ #include "types.h" -#define PDN_GPU_CNT (*(vu8 *)0x10141200) +#define PDN_GPU_CNT (*(vu32 *)0x10141200) -#define ARESCREENSINITIALIZED (PDN_GPU_CNT != 1) +#define ARESCREENSINITIALIZED ((PDN_GPU_CNT & 0xFF) != 1) #define ARM11_PARAMETERS_ADDRESS 0x1FFFF000 @@ -65,6 +65,8 @@ typedef enum extern struct fb fbs[2]; +extern bool needToSetupScreens; + void prepareArm11ForFirmlaunch(void); void deinitScreens(void); void swapFramebuffers(bool isAlternate); diff --git a/source/utils.c b/source/utils.c index c31ec49..5846400 100644 --- a/source/utils.c +++ b/source/utils.c @@ -106,7 +106,7 @@ u32 waitInput(bool isMenu) void mcuPowerOff(void) { - if(bootType != FIRMLAUNCH && ARESCREENSINITIALIZED) clearScreens(false); + if(!needToSetupScreens) clearScreens(false); //Shutdown LCD if(ARESCREENSINITIALIZED) i2cWriteRegister(I2C_DEV_MCU, 0x22, 1 << 0); @@ -136,17 +136,12 @@ void error(const char *fmt, ...) vsprintf(buf, fmt, args); va_end(args); - if(bootType != FIRMLAUNCH) - { - initScreens(); + initScreens(); + drawString(true, 10, 10, COLOR_RED, "An error has occurred:"); + u32 posY = drawString(true, 10, 30, COLOR_WHITE, buf); + drawString(true, 10, posY + 2 * SPACING_Y, COLOR_WHITE, "Press any button to shutdown"); - drawString(true, 10, 10, COLOR_RED, "An error has occurred:"); - u32 posY = drawString(true, 10, 30, COLOR_WHITE, buf); - drawString(true, 10, posY + 2 * SPACING_Y, COLOR_WHITE, "Press any button to shutdown"); - - waitInput(false); - } - else fileWrite(buf, "firmlauncherror.txt", strlen(buf)); + waitInput(false); mcuPowerOff(); }