Skip to content

Commit

Permalink
Semi-working
Browse files Browse the repository at this point in the history
Attempted to directly set the hardware registers but that doesn't work
  • Loading branch information
devnoname120 committed Apr 11, 2017
1 parent 82f83ac commit e3bdc35
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ endif()
project(vitabright)
include("${VITASDK}/share/vita.cmake" REQUIRED)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-q -Wall -O3 -std=gnu99")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-q -Wall -O0 -std=gnu99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fno-exceptions")

include_directories(
Expand All @@ -28,6 +28,7 @@ add_executable(vitabright


target_link_libraries(vitabright
${CMAKE_SOURCE_DIR}/extra/libSceDisplayForDriver_stub.a
taihenForKernel_stub
SceIofilemgrForDriver_stub
#k
Expand Down
9 changes: 9 additions & 0 deletions extra/extra.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
modules:
SceDisplay:
nid: 0x3F05296F
libraries:
SceDisplayForDriver:
functions:
SceDisplayForDriver_0x9E3C6DC6: 0x9E3C6DC6
kernel: true
nid: 0x9FED47AC
Binary file added extra/libSceDisplayForDriver_stub.a
Binary file not shown.
85 changes: 77 additions & 8 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,53 @@ void _start() __attribute__ ((weak, alias ("module_start")));
static tai_hook_ref_t hook_get_max_brightness;
static tai_hook_ref_t hook_set_brightness;

#define DEVICE_BASE (0xE0000000)
#define IFTU0_BASE (DEVICE_BASE + 0x5020000)


uint *iftu0_base = NULL;

static inline void turnon_oled(int a2, int a3)
{
if (a2 == 128)
{
*(iftu0_base + 0x2000 + 32) = 0;
*(iftu0_base + 0x2000 + 4) &= ~1;
}
else
{
*(iftu0_base + 0x2000 + 32) = a2;
*(iftu0_base + 0x2000 + 4) |= 1;
}

if (a3 == 256)
{
*(iftu0_base + 0x1000 + 160) = 1;
}
else
{
*(iftu0_base + 0x1000 + 140) = a3;
*(iftu0_base + 0x1000 + 160) = 0;
}
}

int brightness_adjust(void)
{
for (int j = 0; j < 256; j += 2)
{
turnon_oled(4, j);
for (int k = 0; k < 0x1000000; k++);
}
turnon_oled(128, 0);
for (int j = 254; j >= 0; j -= 2)
{
turnon_oled(4, j);
for (int k = 0; k < 0x1000000; k++);
}
}



int get_max_brightness(uint *brightness)
{
int ret = TAI_CONTINUE(int, hook_get_max_brightness, brightness);
Expand All @@ -23,22 +70,44 @@ int get_max_brightness(uint *brightness)

int set_brightness(uint brightness)
{
// Min: 21, Max: 65536
uint mod_brightness = (brightness-15)*(65536)/(65536-15);
//uint mod_brightness = (brightness + 10000);
int ret = TAI_CONTINUE(uint, hook_set_brightness, mod_brightness);
LOG("set_brightness(%u) = %d, corrected to %u\n", brightness, ret, mod_brightness);
return ret;
uint mod_brightness;

if (brightness < 100)
mod_brightness = 1;
else
mod_brightness = (brightness-19)*(65536)/(65536-19);
//int ret = TAI_CONTINUE(uint, hook_set_brightness, mod_brightness);

//int intensity = (char)((brightness-20)*256/(65536-20));
LOG("set_brightness(%u), corrected to %u\n", brightness, mod_brightness);

SceDisplayForDriver_0x9E3C6DC6(0, mod_brightness);

//brightness_adjust();
//turnon_oled(4, intensity);

return 0;
}


int module_start(SceSize argc, const void *args)
{
log_reset();
SceKernelAllocMemBlockKernelOpt opt = {0};
opt.size = sizeof(opt);
opt.attr = 2;
opt.paddr = IFTU0_BASE;
int payload_block = ksceKernelAllocMemBlock("hw_regs", 0x20100206, 0x3000, &opt); // Need 0x2032 but it has to be page-aligned so 0x3000
if (payload_block < 0)
LOG("AllocMemBlock ret=0x%08X", payload_block);
int ret = ksceKernelGetMemBlockBase(payload_block, (void**)&iftu0_base);

if (ret < 0)
LOG("GetMemBlock ret=0x%08X", ret);


LOG("vitabright started...\n");

int ret = taiHookFunctionExportForKernel(KERNEL_PID, &hook_get_max_brightness,
ret = taiHookFunctionExportForKernel(KERNEL_PID, &hook_get_max_brightness,
"SceAVConfig",
TAI_ANY_LIBRARY,
0x6ABA67F4,
Expand Down

2 comments on commit e3bdc35

@CelesteBlue-dev
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use VitaSDK libraries ?
Couldn't we add SceDisplayForDriver_0x9E3C6DC6 to nids.yml if it isn't there yet ?

@devnoname120
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.