Created
February 24, 2017 08:35
-
-
Save SonoSooS/a1e339d67ef30b8394e572a2df6dcd27 to your computer and use it in GitHub Desktop.
LCD Tweaker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <3ds.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
//#include "testimage_bin.h" | |
void PrettyScroll(char* txt, u32 val) | |
{ | |
static char drawbuf[41]; | |
u32 eh = val; | |
eh += 4; | |
eh >>= 3; | |
if(val >> 8) | |
{ | |
memset(drawbuf, '?', 32); | |
drawbuf[32] = '\0'; | |
} | |
else | |
{ | |
memset(drawbuf, '#', eh); | |
drawbuf[eh] = '\0'; | |
} | |
printf("%s: %03i (0x%02X)\e[K\n<- [%-32.32s] ->\n", txt, val, val, drawbuf); | |
} | |
typedef struct | |
{ | |
u32 sy; | |
u32 ey; | |
u8* ptr; | |
} sli_t; | |
int which(sli_t* ptr, u32 y) | |
{ | |
int i = 0; | |
while(1) | |
{ | |
if(!ptr->sy) return -1; | |
if(ptr->sy <= y && ptr->ey > y) return i; | |
i++; | |
ptr++; | |
} | |
} | |
int main() | |
{ | |
gfxInit(GSP_RGBA8_OES, GSP_RGBA8_OES, false); | |
gfxSetDoubleBuffering(GFX_TOP, 0); | |
gfxSet3D(1); | |
PrintConsole console; | |
consoleInit(GFX_BOTTOM, &console); | |
gfxSwapBuffers(); | |
gfxSwapBuffers(); | |
int redraw = 1; | |
u32 kDown = 0; | |
u32 kHeld = 0; | |
u32 kUp = 0; | |
touchPosition touch; | |
int i = 0; | |
u32 britop = 0xFaaF; | |
u32 bribot = 0xFaaF; | |
struct | |
{ | |
u8 r; | |
u8 g; | |
u8 b; | |
u8 a; | |
} scrtop, scrbot; | |
sli_t sli[] = | |
{ | |
{ 3 * 8, 6 * 8, &britop}, | |
{ 6 * 8, 9 * 8, &scrtop.r}, | |
{ 9 * 8, 12 * 8, &scrtop.g}, | |
{12 * 8, 15 * 8, &scrtop.b}, | |
{17 * 8, 20 * 8, &bribot}, | |
{20 * 8, 23 * 8, &scrbot.r}, | |
{23 * 8, 26 * 8, &scrbot.g}, | |
{26 * 8, 29 * 8, &scrbot.b}, | |
{0, 0, 0} | |
}; | |
int slisel = -1; | |
u32 regtop = 0x202200; | |
u32 regbot = 0x202A00; | |
/* | |
do | |
{ | |
u32* src = testimage_bin; | |
u32* ptr = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, 0, 0); | |
for(i = 0; i != 400 * 240; i++) *(ptr++) = __builtin_bswap32(*(src++)); | |
src = testimage_bin; | |
ptr = gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, 0, 0); | |
for(i = 0; i != 400 * 240; i++) *(ptr++) = __builtin_bswap32(*(src++)); | |
} | |
while(0); | |
*/ | |
while(aptMainLoop()) | |
{ | |
hidScanInput(); | |
kDown = hidKeysDown(); | |
kHeld = hidKeysHeld(); | |
kUp = hidKeysUp(); | |
if(kHeld & KEY_SELECT) break; | |
if(kHeld & KEY_TOUCH) hidTouchRead(&touch); | |
if((kDown | kUp) || (kHeld & KEY_TOUCH)) redraw = 1; | |
if(kDown & KEY_TOUCH) | |
{ | |
slisel = which(sli, touch.py); | |
if(slisel >= 0) | |
{ | |
if(touch.px >= (4 * 8) && touch.px < (36 * 8)) | |
{ | |
*sli[slisel].ptr = (touch.px - (4 * 8)) & 0xFF; | |
} | |
} | |
} | |
else if((kHeld & KEY_TOUCH) && slisel >= 0) | |
{ | |
if(touch.px < (4 * 8)) | |
{ | |
if(slisel & 3) | |
{ | |
u8* ptr = sli[slisel].ptr; | |
if(--(*ptr) == 1) kUp |= KEY_TOUCH; | |
} | |
else | |
{ | |
u32* ptr = sli[slisel].ptr; | |
if(--(*ptr) == 1) kUp |= KEY_TOUCH; | |
} | |
} | |
else if(touch.px >= (36 * 8)) | |
{ | |
if(slisel & 3) | |
{ | |
u8* ptr = sli[slisel].ptr; | |
if(++(*ptr) == 0xFF) kUp |= KEY_TOUCH; | |
} | |
else | |
{ | |
u32* ptr = sli[slisel].ptr; | |
if(++(*ptr) == 0xFF) kUp |= KEY_TOUCH; | |
} | |
} | |
} | |
if(kUp & KEY_TOUCH) | |
{ | |
switch(slisel) | |
{ | |
case 0: | |
GSPGPU_WriteHWRegs(regtop + 0x40, &britop, 4); | |
break; | |
case 1: | |
case 2: | |
case 3: | |
for(i = 0; i != 0x100; i += 4) | |
GSPGPU_WriteHWRegs(regtop + 0x100 + i, &scrtop, 4); | |
break; | |
case 4: | |
GSPGPU_WriteHWRegs(regbot + 0x40, &bribot, 4); | |
break; | |
case 5: | |
case 6: | |
case 7: | |
for(i = 0; i != 0x100; i += 4) | |
GSPGPU_WriteHWRegs(regbot + 0x100 + i, &scrbot, 4); | |
break; | |
default: | |
break; | |
} | |
slisel = -1; | |
} | |
if(redraw) | |
{ | |
console.cursorX = 0; | |
console.cursorY = 0; | |
puts("LCD Tweaker v0.0_dev1 by Sono-kun\n\n"); | |
if(!(kHeld & KEY_TOUCH)) | |
{ | |
GSPGPU_ReadHWRegs(regtop + 0x40, &britop, 4); | |
GSPGPU_ReadHWRegs(regbot + 0x40, &bribot, 4); | |
GSPGPU_ReadHWRegs(regtop + 0x100, &scrtop, 4); | |
GSPGPU_ReadHWRegs(regbot + 0x100, &scrbot, 4); | |
} | |
PrettyScroll("Top screen brightness", britop); | |
PrettyScroll("Red", scrtop.r); | |
PrettyScroll("Green", scrtop.g); | |
PrettyScroll("Blue", scrtop.b); | |
puts("========================================"); | |
PrettyScroll("Bottom screen brightness", bribot); | |
PrettyScroll("Red", scrbot.r); | |
PrettyScroll("Green", scrbot.g); | |
PrettyScroll("Blue", scrbot.b); | |
redraw = 0; | |
} | |
gspWaitForVBlank(); | |
} | |
ded: | |
gfxExit(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment