diff --git a/3DS/include/drawing.h b/3DS/include/drawing.h index dd30618..78f94bb 100644 --- a/3DS/include/drawing.h +++ b/3DS/include/drawing.h @@ -1,5 +1,13 @@ #pragma once +#ifndef REG_LCDBACKLIGHTMAIN +#define REG_LCDBACKLIGHTMAIN (u32)(0x1ED02240 - 0x1EB00000) +#endif + +#ifndef REG_LCDBACKLIGHTSUB +#define REG_LCDBACKLIGHTSUB (u32)(0x1ED02A40 - 0x1EB00000) +#endif + inline void clearScreen(void); #define drawPixelRGB(x, y, r, g, b) drawPixelRGBFramebuffer(0, x, y, r, g, b) @@ -10,3 +18,6 @@ inline void drawBoxFramebuffer(u8 *fb, int x, int y, int width, int height, u8 r #define drawString(sx, sy, text, ...) drawStringFramebuffer(0, sx, sy, text, ##__VA_ARGS__) void drawStringFramebuffer(u8 *fb, int sx, int sy, char *text, ...); + +void disableBacklight(); +void enableBacklight(); diff --git a/3DS/source/drawing.c b/3DS/source/drawing.c index d17317b..653022d 100644 --- a/3DS/source/drawing.c +++ b/3DS/source/drawing.c @@ -155,3 +155,21 @@ void drawStringFramebuffer(u8 *fb, int sx, int sy, char *text, ...) { sx += 8; } } + +static u32 brightnessMain; +static u32 brightnessSub; + +void disableBacklight() { + u32 off = 0; + + GSPGPU_ReadHWRegs(NULL, REG_LCDBACKLIGHTMAIN, &brightnessMain, 4); + GSPGPU_ReadHWRegs(NULL, REG_LCDBACKLIGHTSUB, &brightnessSub, 4); + + GSPGPU_WriteHWRegs(NULL, REG_LCDBACKLIGHTMAIN, &off, 4); + GSPGPU_WriteHWRegs(NULL, REG_LCDBACKLIGHTSUB, &off, 4); +} + +void enableBacklight() { + GSPGPU_WriteHWRegs(NULL, REG_LCDBACKLIGHTMAIN, &brightnessMain, 4); + GSPGPU_WriteHWRegs(NULL, REG_LCDBACKLIGHTSUB, &brightnessSub, 4); +} diff --git a/3DS/source/main.c b/3DS/source/main.c index 11c235b..b76d011 100644 --- a/3DS/source/main.c +++ b/3DS/source/main.c @@ -34,7 +34,8 @@ int main(void) { acInit(); gfxInitDefault(); - //consoleInit(GFX_BOTTOM, NULL); + gfxSetDoubleBuffering(GFX_TOP, false); + gfxSetDoubleBuffering(GFX_BOTTOM, false); if(setjmp(exitJmp)) goto exit; @@ -81,20 +82,17 @@ int main(void) { gfxFlushBuffers(); gfxSwapBuffers(); - clearScreen(); - gfxFlushBuffers(); - gfxSwapBuffers(); + disableBacklight(); while(aptMainLoop()) { hidScanInput(); irrstScanInput(); u32 kHeld = hidKeysHeld(); - circlePosition circlePad; circlePosition cStick; + hidCstickRead(&cStick); hidCircleRead(&circlePad); - irrstCstickRead(&cStick); touchPosition touch; touchRead(&touch); @@ -104,6 +102,8 @@ int main(void) { if(keyboardToggle) { keyboardActive = !keyboardActive; keyboardToggle = false; + + if(keyboardActive) enableBacklight(); } } else keyboardToggle = true; @@ -137,15 +137,7 @@ int main(void) { sendKeys(kHeld, circlePad, touch, cStick); - receiveBuffer(sizeof(struct packet)); - - /*u8 *frame = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); - - switch(rcvBuf.command) { - case SCREENSHOT: - //drawStringFramebuffer(frame, 10, 10, "R"); - break; - }*/ + //receiveBuffer(sizeof(struct packet)); if((kHeld & KEY_START) && (kHeld & KEY_SELECT)) longjmp(exitJmp, 1); @@ -156,6 +148,8 @@ int main(void) { exit: + enableBacklight(); + SOC_Shutdown(); svcCloseHandle(fileHandle);