Created
September 3, 2022 15:39
-
-
Save SKGleba/1b033c75494c5c4679983e4e8dcadc29 to your computer and use it in GitHub Desktop.
toggle use_qaf in syscon scratchpad, persists until power loss
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 <stdio.h> | |
#include <string.h> | |
#include <psp2kern/kernel/modulemgr.h> | |
#include <vitasdkkern.h> | |
void hexdump(uint8_t* data, int size) { | |
for (int i = 0; i < size; i -= -1) { | |
if (!(i % 0x10)) | |
ksceDebugPrintf("\n %04X: ", i); | |
ksceDebugPrintf("%02X ", data[i]); | |
} | |
ksceDebugPrintf("\n"); | |
} | |
int check_dipsw(int no, uint8_t* buf) { | |
return (*(uint32_t*)(buf + (no >> 5) * 4) >> (no & 31)) & 1; | |
} | |
int set_dipsw(int no, uint8_t* buf) { | |
*(uint32_t*)(buf + (no >> 5) * 4) = *(uint32_t*)(buf + (no >> 5) * 4) | 1 << (no & 0x1f); | |
return check_dipsw(no, buf); | |
} | |
int clear_dipsw(int no, uint8_t* buf) { | |
*(uint32_t*)(buf + (no >> 5) * 4) = *(uint32_t*)(buf + (no >> 5) * 4) & ~(1 << (no & 0x1f)); | |
return check_dipsw(no, buf); | |
} | |
void _start() __attribute__((weak, alias("module_start"))); | |
int module_start(SceSize argc, const void *args) | |
{ | |
uint8_t cp_dipsw[0x20]; | |
memset(cp_dipsw, 0, 0x20); | |
int ret = ksceSysconReadCommand(0xE0, cp_dipsw, 0x10); // sc_cmd_0x90(off, data, size) | |
ksceDebugPrintf("read_sc_scratch_E0 ret 0x%X\n", ret); | |
if (ret < 0) | |
return SCE_KERNEL_START_SUCCESS; | |
ret = ksceSysconReadCommand(0xF0, cp_dipsw + 0x10, 0x10); // sc_cmd_0x90(off, data, size) | |
ksceDebugPrintf("read_sc_scratch_F0 ret 0x%X\n", ret); | |
if (ret < 0) | |
return SCE_KERNEL_START_SUCCESS; | |
hexdump(cp_dipsw, 0x20); | |
ret = check_dipsw(0xF0, cp_dipsw); | |
ksceDebugPrintf("check_sc_dipsw ret 0x%X\n", ret); | |
if (ret) { | |
ksceDebugPrintf("clearing sc_dipsw 0xf0\n"); | |
ret = clear_dipsw(0xF0, cp_dipsw); | |
ksceDebugPrintf("clear_sc_dipsw ret 0x%X\n", ret); | |
} else { | |
ksceDebugPrintf("setting sc_dipsw 0xf0\n"); | |
ret = set_dipsw(0xF0, cp_dipsw); | |
ksceDebugPrintf("set_sc_dipsw ret 0x%X\n", ret); | |
} | |
hexdump(cp_dipsw, 0x20); | |
ret = ksceSysconSendCommand(0xE0, cp_dipsw, 0x10); // sc_cmd_0x91(off, data, size) | |
ksceDebugPrintf("write_sc_scratch_E0 ret 0x%X\n", ret); | |
ret = ksceSysconSendCommand(0xF0, cp_dipsw + 0x10, 0x10); // sc_cmd_0x91(off, data, size) | |
ksceDebugPrintf("write_sc_scratch_F0 ret 0x%X\n", ret); | |
return SCE_KERNEL_START_SUCCESS; | |
} | |
int module_stop(SceSize argc, const void *args) | |
{ | |
return SCE_KERNEL_STOP_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CMakeLists.txt :