From 575adcbb9d20b22239a1eddf46175a8798269b1e Mon Sep 17 00:00:00 2001 From: TuxSH Date: Sun, 3 Jul 2016 20:53:13 +0200 Subject: [PATCH] Revert part of 136e0d89 (due to cache issues) --- source/draw.h | 2 -- source/screen.c | 56 ++++++++++++++++++++++++++----------------------- source/screen.h | 10 ++++----- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/source/draw.h b/source/draw.h index f64b245..c93f424 100644 --- a/source/draw.h +++ b/source/draw.h @@ -19,8 +19,6 @@ #define COLOR_RED 0x0000FF #define COLOR_BLACK 0x000000 -extern volatile struct fb *const fb; - bool loadSplash(void); void drawCharacter(char character, int posX, int posY, u32 color); int drawString(const char *string, int posX, int posY, u32 color); \ No newline at end of file diff --git a/source/screen.c b/source/screen.c index 106ddcd..d0aa0d8 100644 --- a/source/screen.c +++ b/source/screen.c @@ -12,17 +12,18 @@ #include "draw.h" #include "i2c.h" +#define ARM11_STUB_ADDRESS (0x25000000 - 0x40) //It's currently only 0x28 bytes large. We're putting 0x40 just to be sure here +#define WAIT_FOR_ARM9() *arm11Entry = 0; while(!*arm11Entry); ((void (*)())*arm11Entry)(); vu32 *arm11Entry = (vu32 *)0x1FFFFFF8; -volatile struct fb *const fb = (volatile struct fb *)0x23FFFE00; void __attribute__((naked)) arm11Stub(void) { //Disable interrupts __asm(".word 0xF10C01C0"); - + //Wait for the entry to be set while(*arm11Entry == ARM11_STUB_ADDRESS); - + //Jump to it ((void (*)())*arm11Entry)(); } @@ -30,14 +31,13 @@ void __attribute__((naked)) arm11Stub(void) static inline void invokeArm11Function(void (*func)()) { static bool hasCopiedStub = false; - if(!hasCopiedStub) { memcpy((void *)ARM11_STUB_ADDRESS, arm11Stub, 0x40); flushDCacheRange((void *)ARM11_STUB_ADDRESS, 0x40); hasCopiedStub = true; } - + *arm11Entry = (u32)func; while(*arm11Entry); *arm11Entry = ARM11_STUB_ADDRESS; @@ -63,23 +63,25 @@ void deinitScreens(void) if(PDN_GPU_CNT != 1) invokeArm11Function(ARM11); } -void updateBrightness(u32 brightnessIndex) +void updateBrightness(u32 brightnessLevel) { - u32 brightnessLevel = brightness[brightnessIndex]; - + static int brightnessValue; + + brightnessValue = brightness[brightnessLevel]; + void __attribute__((naked)) ARM11(void) { //Disable interrupts - __asm(".word 0xF10C01C0"); - + __asm(".word 0xF10C01C0"); + //Change brightness - *(vu32 *)0x10202240 = brightnessLevel; - *(vu32 *)0x10202A40 = brightnessLevel; + *(vu32 *)0x10202240 = brightnessValue; + *(vu32 *)0x10202A40 = brightnessValue; WAIT_FOR_ARM9(); } - flushDCacheRange(&brightnessLevel, 4); + flushDCacheRange(&brightnessValue, 4); invokeArm11Function(ARM11); } @@ -89,8 +91,9 @@ void clearScreens(void) { //Disable interrupts __asm(".word 0xF10C01C0"); - + //Setting up two simultaneous memory fills using the GPU + vu32 *REGs_PSC0 = (vu32 *)0x10400010; REGs_PSC0[0] = (u32)fb->top_left >> 3; //Start address REGs_PSC0[1] = (u32)(fb->top_left + 0x46500) >> 3; //End address @@ -102,7 +105,7 @@ void clearScreens(void) REGs_PSC1[1] = (u32)(fb->bottom + 0x38400) >> 3; //End address REGs_PSC1[2] = 0; //Fill value REGs_PSC1[3] = (2 << 8) | 1; //32-bit pattern; start - + while(!((REGs_PSC0[3] & 2) && (REGs_PSC1[3] & 2))); if(fb->top_right != fb->top_left) @@ -111,33 +114,33 @@ void clearScreens(void) REGs_PSC0[1] = (u32)(fb->top_right + 0x46500) >> 3; //End address REGs_PSC0[2] = 0; //Fill value REGs_PSC0[3] = (2 << 8) | 1; //32-bit pattern; start - + while(!(REGs_PSC0[3] & 2)); } - + WAIT_FOR_ARM9(); } - + flushDCacheRange((void *)fb, sizeof(struct fb)); invokeArm11Function(ARM11); } -bool initScreens(void) +u32 initScreens(void) { - bool needToInit = PDN_GPU_CNT == 1; + u32 needToInit = PDN_GPU_CNT == 1; void __attribute__((naked)) ARM11(void) { //Disable interrupts __asm(".word 0xF10C01C0"); - u32 brightnessLevel = brightness[MULTICONFIG(0)]; + u32 brightnessLevel = MULTICONFIG(0); *(vu32 *)0x10141200 = 0x1007F; *(vu32 *)0x10202014 = 0x00000001; *(vu32 *)0x1020200C &= 0xFFFEFFFE; - *(vu32 *)0x10202240 = brightnessLevel; - *(vu32 *)0x10202A40 = brightnessLevel; + *(vu32 *)0x10202240 = brightness[brightnessLevel]; + *(vu32 *)0x10202A40 = brightness[brightnessLevel]; *(vu32 *)0x10202244 = 0x1023E; *(vu32 *)0x10202A44 = 0x1023E; @@ -223,7 +226,7 @@ bool initScreens(void) WAIT_FOR_ARM9(); } - + if(needToInit) { flushDCacheRange(&config, 4); @@ -233,8 +236,9 @@ bool initScreens(void) //Turn on backlight i2cWriteRegister(I2C_DEV_MCU, 0x22, 0x2A); } - else updateBrightness(MULTICONFIG(0)); - + else + updateBrightness(MULTICONFIG(0)); + clearScreens(); return needToInit; diff --git a/source/screen.h b/source/screen.h index 34cc7be..5f2bf1d 100644 --- a/source/screen.h +++ b/source/screen.h @@ -10,16 +10,14 @@ #include "types.h" #define PDN_GPU_CNT (*(vu8 *)0x10141200) -#define ARM11_STUB_ADDRESS (0x25000000 - 0x40) //It's currently only 0x28 bytes large. We're putting 0x40 just to be sure here -#define WAIT_FOR_ARM9() *arm11Entry = 0; while(!*arm11Entry); ((void (*)())*arm11Entry)(); -struct fb { +static volatile struct fb { u8 *top_left; u8 *top_right; u8 *bottom; -}; +} *const fb = (volatile struct fb *)0x23FFFE00; void deinitScreens(void); -void updateBrightness(u32 brightnessIndex); +void updateBrightness(u32 brightnessLevel); void clearScreens(void); -bool initScreens(void); \ No newline at end of file +u32 initScreens(void); \ No newline at end of file