Skip to content

Commit

Permalink
Added support for native resolution patches
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOfficialFloW committed Mar 10, 2019
1 parent 05a00b7 commit 7938368
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 17 deletions.
3 changes: 3 additions & 0 deletions adrenaline_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ typedef struct {
#define ADRENALINE_SIZE 0x2000
#define ADRENALINE_ADDRESS 0xABCDE000

#define DRAW_NATIVE 0xABCDEF00
#define NATIVE_FRAMEBUFFER 0x0A000000

#define CONVERT_ADDRESS(addr) (0x68000000 + (addr & 0x0FFFFFFF))

#endif
2 changes: 2 additions & 0 deletions cef/systemctrl/adrenaline.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,5 +323,7 @@ int initAdrenaline() {

sceKernelStartThread(thid, 0, NULL);

*(u32 *)DRAW_NATIVE = 0;

return 0;
}
20 changes: 10 additions & 10 deletions cef/systemctrl/rebootex.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ static unsigned char rebootex[] __attribute__((aligned(16))) = {
0xf8, 0x08, 0x42, 0x8c, 0xf8, 0xff, 0xbd, 0x27, 0x04, 0x00, 0xbf, 0xaf, 0x00, 0x00, 0xb0, 0xaf,
0x09, 0xf8, 0x40, 0x00, 0x21, 0x80, 0xa0, 0x00, 0x04, 0x00, 0xbf, 0x8f, 0x40, 0x01, 0x02, 0x3c,
0x50, 0x00, 0x02, 0xae, 0x00, 0x8a, 0x02, 0x3c, 0x4c, 0x00, 0x02, 0xae, 0x00, 0x00, 0xb0, 0x8f,
0x08, 0x00, 0xe0, 0x03, 0x08, 0x00, 0xbd, 0x27, 0xfc, 0x88, 0x03, 0x3c, 0xcc, 0x01, 0x63, 0x24,
0xff, 0x03, 0x02, 0x3c, 0xff, 0xff, 0x42, 0x34, 0x82, 0x18, 0x03, 0x00, 0x24, 0x18, 0x62, 0x00,
0x00, 0x0c, 0x02, 0x3c, 0x25, 0x18, 0x62, 0x00, 0x60, 0x14, 0x02, 0x3c, 0x03, 0x00, 0x49, 0x34,
0xff, 0xf3, 0x02, 0x3c, 0xf0, 0xff, 0xbd, 0x27, 0xff, 0xff, 0x48, 0x34, 0x01, 0x88, 0x02, 0x3c,
0x08, 0x00, 0xb1, 0xaf, 0x04, 0x00, 0xb0, 0xaf, 0x28, 0x00, 0x91, 0x8c, 0x21, 0x80, 0xa0, 0x00,
0x0c, 0x00, 0xbf, 0xaf, 0x00, 0x40, 0x47, 0x34, 0x00, 0x88, 0x04, 0x3c, 0xfc, 0x88, 0x06, 0x3c,
0x00, 0x80, 0x05, 0x3c, 0x00, 0x00, 0x82, 0x8c, 0x08, 0x00, 0x49, 0x54, 0x04, 0x00, 0x84, 0x24,
0xe4, 0xff, 0x82, 0x8c, 0xe4, 0xff, 0x83, 0xac, 0x24, 0x10, 0x48, 0x00, 0x80, 0x10, 0x02, 0x00,
0x25, 0x10, 0x45, 0x00, 0xf8, 0x08, 0xc2, 0xac, 0x04, 0x00, 0x84, 0x24, 0xf5, 0xff, 0x87, 0x14,
0x00, 0x00, 0x00, 0x00, 0x68, 0x00, 0x3f, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x21, 0x28, 0x00, 0x02,
0x08, 0x00, 0xe0, 0x03, 0x08, 0x00, 0xbd, 0x27, 0xfc, 0x88, 0x02, 0x3c, 0xfc, 0x88, 0x03, 0x3c,
0xcc, 0x01, 0x63, 0x24, 0xf8, 0x08, 0x46, 0x8c, 0xff, 0x03, 0x02, 0x3c, 0xff, 0xff, 0x42, 0x34,
0x82, 0x18, 0x03, 0x00, 0x24, 0x18, 0x62, 0x00, 0x00, 0x0c, 0x02, 0x3c, 0x25, 0x18, 0x62, 0x00,
0x60, 0x14, 0x02, 0x3c, 0x03, 0x00, 0x49, 0x34, 0xff, 0xf3, 0x02, 0x3c, 0xf0, 0xff, 0xbd, 0x27,
0xff, 0xff, 0x48, 0x34, 0x01, 0x88, 0x02, 0x3c, 0x08, 0x00, 0xb1, 0xaf, 0x04, 0x00, 0xb0, 0xaf,
0x28, 0x00, 0x91, 0x8c, 0x21, 0x80, 0xa0, 0x00, 0x0c, 0x00, 0xbf, 0xaf, 0x00, 0x40, 0x47, 0x34,
0x00, 0x88, 0x04, 0x3c, 0x00, 0x80, 0x05, 0x3c, 0x00, 0x00, 0x82, 0x8c, 0x07, 0x00, 0x49, 0x54,
0x04, 0x00, 0x84, 0x24, 0xe4, 0xff, 0x82, 0x8c, 0xe4, 0xff, 0x83, 0xac, 0x24, 0x10, 0x48, 0x00,
0x80, 0x10, 0x02, 0x00, 0x25, 0x30, 0x45, 0x00, 0x04, 0x00, 0x84, 0x24, 0xf6, 0xff, 0x87, 0x14,
0xfc, 0x88, 0x02, 0x3c, 0x68, 0x00, 0x3f, 0x0e, 0xf8, 0x08, 0x46, 0xac, 0x21, 0x28, 0x00, 0x02,
0x21, 0xc8, 0x20, 0x02, 0x0c, 0x00, 0xbf, 0x8f, 0x08, 0x00, 0xb1, 0x8f, 0x04, 0x00, 0xb0, 0x8f,
0x04, 0x00, 0x04, 0x24, 0x08, 0x00, 0x20, 0x03, 0x10, 0x00, 0xbd, 0x27, 0xf0, 0xff, 0xbd, 0x27,
0x04, 0x00, 0xb0, 0xaf, 0x2d, 0xae, 0x02, 0x3c, 0x21, 0x80, 0x80, 0x00, 0x08, 0x00, 0xb1, 0xaf,
Expand Down
5 changes: 3 additions & 2 deletions cef/systemctrl/sysmodpatches.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,10 @@ void PatchImposeDriver(u32 text_addr) {
if (sceKernelInitKeyConfig() == PSP_INIT_KEYCONFIG_POPS) {
SetupCallbacks();
MAKE_DUMMY_FUNCTION(text_addr + 0x91C8, PSP_INIT_KEYCONFIG_GAME);
REDIRECT_FUNCTION(text_addr + 0x92B0, sceKernelWaitEventFlagPatched);
}

REDIRECT_FUNCTION(text_addr + 0x92B0, sceKernelWaitEventFlagPatched);

ClearCaches();
}

Expand All @@ -354,7 +355,7 @@ void PatchMediaSync(u32 text_addr) {
}

void SetSpeed(int cpu, int bus) {
if (cpu == 20 || cpu == 75 || cpu == 100 || cpu == 133 || cpu == 333 || cpu == 300 || cpu == 266 || cpu == 222) {
if (cpu == 20 || cpu == 75 || cpu == 100 || cpu == 133 || cpu == 333 || cpu == 300 || cpu == 266 || cpu == 222) {
scePowerSetClockFrequency_k = (void *)FindPowerFunction(0x737486F2);
scePowerSetClockFrequency_k(cpu, cpu, bus);

Expand Down
2 changes: 1 addition & 1 deletion user/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ vita_create_self(adrenaline_user.suprx adrenaline_user CONFIG exports.yml UNSAFE
vita_create_stubs(stubs adrenaline_user ${CMAKE_SOURCE_DIR}/exports.yml)

add_custom_target(copy
COMMAND cp adrenaline_user.suprx H:/app/PSPEMUCFW/sce_module/adrenaline_user.suprx
COMMAND cp adrenaline_user.suprx F:/app/PSPEMUCFW/sce_module/adrenaline_user.suprx
DEPENDS adrenaline_user.suprx
)

Expand Down
Binary file modified user/flash0/kd/systemctrl.prx
Binary file not shown.
13 changes: 10 additions & 3 deletions user/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@ int AdrenalineDraw(SceSize args, void *argp) {
vita2d_init();
font = vita2d_load_default_pgf();

vita2d_texture *native_tex = vita2d_create_empty_texture_data(SCREEN_WIDTH, SCREEN_HEIGHT, CONVERT_ADDRESS(NATIVE_FRAMEBUFFER), SCE_GXM_TEXTURE_FORMAT_U5U6U5_BGR);
if (!native_tex)
return -1;

vita2d_texture *psp_tex = vita2d_create_empty_texture(PSP_SCREEN_LINE, PSP_SCREEN_HEIGHT);
if (!psp_tex)
return -1;
Expand Down Expand Up @@ -471,6 +475,7 @@ int AdrenalineDraw(SceSize args, void *argp) {
int lastPops = 0;

while (1) {
int draw_native = *(uint32_t *)CONVERT_ADDRESS(DRAW_NATIVE);
SceAdrenaline *adrenaline = (SceAdrenaline *)CONVERT_ADDRESS(ADRENALINE_ADDRESS);

// pause/unpause pops once after switching from psp to pops mode
Expand Down Expand Up @@ -541,7 +546,7 @@ int AdrenalineDraw(SceSize args, void *argp) {
}

// Do not draw if dialog is running
if (sceCommonDialogIsRunning() || (config.graphics_filtering == 0 && menu_open == 0)) {
if (sceCommonDialogIsRunning() || (config.graphics_filtering == 0 && menu_open == 0 && draw_native == 0)) {
sceDisplayWaitVblankStart();
continue;
}
Expand Down Expand Up @@ -578,7 +583,7 @@ int AdrenalineDraw(SceSize args, void *argp) {
vita2d_texture_set_filters(pops_tex, SCE_GXM_TEXTURE_FILTER_POINT, SCE_GXM_TEXTURE_FILTER_POINT);
}

if (!adrenaline->pops_mode || adrenaline->draw_psp_screen_in_pops) {
if ((!adrenaline->pops_mode && !draw_native) || adrenaline->draw_psp_screen_in_pops) {
// Copy PSP framebuffer
sceDmacMemcpy(psp_data, (void *)SCE_PSPEMU_FRAMEBUFFER, SCE_PSPEMU_FRAMEBUFFER_SIZE);

Expand All @@ -587,6 +592,8 @@ int AdrenalineDraw(SceSize args, void *argp) {
float scale_y = 2.00f;
getPspScreenScale(&scale_x, &scale_y);
vita2d_draw_texture_scale_rotate_hotspot(psp_tex, 480.0f, 272.0f, scale_x, scale_y, 0.0, 240.0, 136.0);
} else if (draw_native) {
vita2d_draw_texture_scale_rotate_hotspot(native_tex, 480.0f, 272.0f, 1.0f, 1.0f, 0.0, 480.0, 272.0);
} else {
// Draw pops screen
float scale_x = 1.0f;
Expand Down Expand Up @@ -653,7 +660,7 @@ int AdrenalineDraw(SceSize args, void *argp) {
frames++;

// Sync
if (!adrenaline->pops_mode || adrenaline->draw_psp_screen_in_pops)
if ((!adrenaline->pops_mode && !draw_native) || adrenaline->draw_psp_screen_in_pops)
sceCompatLCDCSync();
else
sceDisplayWaitVblankStart();
Expand Down
25 changes: 24 additions & 1 deletion user/states.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ void makeSaveStatePath(char *path, int num) {

extern void *pops_data;

static uint32_t convert565To8888(uint16_t color) {
uint8_t red_value = (color & 0xF800) >> 11;
uint8_t green_value = (color & 0x7E0) >> 5;
uint8_t blue_value = (color & 0x1F);

uint8_t alpha = 0xFF;
uint8_t red = red_value << 3;
uint8_t green = green_value << 2;
uint8_t blue = blue_value << 3;

return (alpha << 24) | (red << 16) | (green << 8) | blue;
}

int saveFrameBuffer(SceUID fd) {
sceCompatLCDCSync();

Expand All @@ -87,9 +100,19 @@ int saveFrameBuffer(SceUID fd) {

int i = 0;

int draw_native = *(uint32_t *)CONVERT_ADDRESS(DRAW_NATIVE);
SceAdrenaline *adrenaline = (SceAdrenaline *)ScePspemuConvertAddress(ADRENALINE_ADDRESS, KERMIT_INPUT_MODE, ADRENALINE_SIZE);

if (adrenaline->pops_mode) {
if (draw_native) {
int y;
for (y = 0; y < SCREEN_HEIGHT; y += 4) {
int x;
for (x = 0; x < SCREEN_WIDTH; x += 4) {
uint16_t color = ((uint16_t *)CONVERT_ADDRESS(NATIVE_FRAMEBUFFER))[x + SCREEN_WIDTH * y];
buf[i++] = convert565To8888(color);
}
}
} else if (adrenaline->pops_mode) {
int y;
for (y = 0; y < SCREEN_HEIGHT; y += 4) {
int x;
Expand Down

0 comments on commit 7938368

Please sign in to comment.