Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Commit

Permalink
Add FPS option as requested by many users
Browse files Browse the repository at this point in the history
Brought to you by Rinnegatamante.
  • Loading branch information
joel16 committed Jul 22, 2018
1 parent 1094cac commit cba08e6
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 38 deletions.
2 changes: 1 addition & 1 deletion exports/vsh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ vsh:
attributes: 0
version:
major: 3
minor: 2
minor: 3
main:
start: module_start
stop: module_stop
3 changes: 2 additions & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
#include <vitasdk.h>

SceBool batteryPercent, batteryLifeTime, batteryTemp, batteryDisplay;
SceBool fps, fpsDisplay;
SceInt c_clock, g_clock, colour;
char titleID[16];
char app_title[5][50], app_titleID[5][50];

SceInt Config_SaveMenuConfig(SceBool, SceBool, SceBool, SceBool, SceInt);
SceInt Config_SaveMenuConfig(SceBool, SceBool, SceBool, SceBool, SceInt, SceBool, SceBool);
SceInt Config_SaveClockConfig(SceInt cpuClock, SceInt gpuClock);
SceInt Config_LoadConfig(SceVoid);
SceInt Config_GetVSHColour(SceVoid);
Expand Down
9 changes: 5 additions & 4 deletions include/menus.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#ifndef PSV_VSH_MENUS_H
#define PSV_VSH_MENUS_H

#define VSH_MAIN_MENU 1
#define VSH_BATTERY_MENU 2
#define VSH_PROGRAM_MENU 3
#define VSH_MAIN_MENU 1
#define VSH_BATTERY_MENU 2
#define VSH_FPS_MENU 3
#define VSH_PROGRAM_MENU 4

extern SceInt profile_max_battery[];
extern SceInt profile_default[];
extern SceInt profile_balance[];
extern SceInt profile_max_performance[];
extern SceInt profile_game[];
extern SceInt *profiles[4];
Expand Down
22 changes: 13 additions & 9 deletions source/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const char *menuConfig =
"display_battery_lifetime = %d\n"
"display_battery_temp = %d\n"
"display_battery_data = %d\n"
"bar_colour = %d\n";
"bar_colour = %d\n"
"display_fps = %d\n"
"display_fps_data = %d\n";

const char *clockConfig =
"CPU_clock = %d\n"
Expand All @@ -23,15 +25,15 @@ const char *launcherConfig =
"[3] title: %s titleID: %s\n"
"[4] title: %s titleID: %s\n";

SceInt Config_SaveMenuConfig(SceBool batteryPercent, SceBool batteryLifeTime, SceBool batteryTemp, SceBool batteryDisplay, SceInt colour)
SceInt Config_SaveMenuConfig(SceBool batteryPercent, SceBool batteryLifeTime, SceBool batteryTemp, SceBool batteryDisplay, SceInt colour, SceBool fps, SceBool fpsDisplay)
{
SceInt ret = 0;

char *menu_config_path = (char *)Utils_SceMalloc(25);
snprintf(menu_config_path, 25, "ur0:/data/vsh/config.cfg");

char *buf = (char *)Utils_SceMalloc(128);
SceInt len = snprintf(buf, 128, menuConfig, batteryPercent, batteryLifeTime, batteryTemp, batteryDisplay, colour);
char *buf = (char *)Utils_SceMalloc(256);
SceInt len = snprintf(buf, 256, menuConfig, batteryPercent, batteryLifeTime, batteryTemp, batteryDisplay, colour, fps, fpsDisplay);

if (R_FAILED(ret = FS_WriteFile(menu_config_path, buf, len)))
{
Expand Down Expand Up @@ -130,14 +132,16 @@ SceInt Config_LoadConfig(SceVoid)
batteryTemp = SCE_FALSE;
batteryDisplay = SCE_FALSE;
colour = 0;
Config_SaveMenuConfig(batteryPercent, batteryLifeTime, batteryTemp, batteryDisplay, colour);
fps = SCE_FALSE;
fpsDisplay = SCE_FALSE;
Config_SaveMenuConfig(batteryPercent, batteryLifeTime, batteryTemp, batteryDisplay, colour, fps, fpsDisplay);
}

if (!(FS_FileExists(launcher_config_path)))
Config_SaveLauncherConfig();

char *buf1 = (char *)Utils_SceMalloc(64);
char *buf2 = (char *)Utils_SceMalloc(128);
char *buf2 = (char *)Utils_SceMalloc(256);
char *buf3 = (char *)Utils_SceMalloc(256);

if (R_FAILED(ret = FS_ReadFile(game_config_path, buf1, 64)))
Expand All @@ -151,7 +155,7 @@ SceInt Config_LoadConfig(SceVoid)
return ret;
}

if (R_FAILED(ret = FS_ReadFile(menu_config_path, buf2, 128)))
if (R_FAILED(ret = FS_ReadFile(menu_config_path, buf2, 256)))
{
Utils_SceFree(buf3);
Utils_SceFree(buf2);
Expand All @@ -174,7 +178,7 @@ SceInt Config_LoadConfig(SceVoid)
}

sscanf(buf1, clockConfig, &c_clock, &g_clock);
sscanf(buf2, menuConfig, &batteryPercent, &batteryLifeTime, &batteryTemp, &batteryDisplay, &colour);
sscanf(buf2, menuConfig, &batteryPercent, &batteryLifeTime, &batteryTemp, &batteryDisplay, &colour, &fps, &fpsDisplay);
sscanf(buf3, launcherConfig, app_title[0], app_titleID[0], app_title[1], app_titleID[1],
app_title[2], app_titleID[2], app_title[3], app_titleID[3], app_title[4], app_titleID[4]);

Expand Down Expand Up @@ -223,4 +227,4 @@ SceInt Config_GetVSHColour()
}

return col;
}
}
122 changes: 100 additions & 22 deletions source/menus.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#include "power.h"
#include "utils.h"

#define MAIN_MAX_ITEMS 9
#define MAIN_MAX_ITEMS 10
#define BATTERY_MAX_ITEMS 4
#define FPS_MAX_ITEMS 2
#define COLOUR_MAX_ITEMS 8

static SceInt app_list = 0;
Expand Down Expand Up @@ -49,12 +50,13 @@ static SceVoid Menu_DisplayMainMenu(SceVoid)

drawStringfCenter(162, "VSH MENU COLOUR %s", colourStr[colour]);
drawStringCenter(178, "BATTERY OPTIONS ->");
drawStringCenter(194, "LOAD PROGRAM ->");
drawStringCenter(210, "SHUTDOWN DEVICE");
drawStringCenter(226, "SUSPEND DEVICE");
drawStringCenter(242, "REBOOT DEVICE");
drawStringCenter(258, "RESTART VSH");
drawStringCenter(274, "EXIT");
drawStringCenter(194, "FPS SETTINGS ->");
drawStringCenter(210, "LOAD PROGRAM ->");
drawStringCenter(226, "SHUTDOWN DEVICE");
drawStringCenter(242, "SUSPEND DEVICE");
drawStringCenter(258, "REBOOT DEVICE");
drawStringCenter(274, "RESTART VSH");
drawStringCenter(290, "EXIT");

switch(selection)
{
Expand Down Expand Up @@ -82,27 +84,31 @@ static SceVoid Menu_DisplayMainMenu(SceVoid)
break;
case 4:
drawSetColour(WHITE, SKYBLUE);
drawStringCenter(194, "LOAD PROGRAM ->");
drawStringCenter(194, "FPS SETTINGS ->");
break;
case 5:
drawSetColour(WHITE, SKYBLUE);
drawStringCenter(210, "SHUTDOWN DEVICE");
drawStringCenter(210, "LOAD PROGRAM ->");
break;
case 6:
drawSetColour(WHITE, SKYBLUE);
drawStringCenter(226, "SUSPEND DEVICE");
drawStringCenter(226, "SHUTDOWN DEVICE");
break;
case 7:
drawSetColour(WHITE, SKYBLUE);
drawStringCenter(242, "REBOOT DEVICE");
drawStringCenter(242, "SUSPEND DEVICE");
break;
case 8:
drawSetColour(WHITE, SKYBLUE);
drawStringCenter(258, "RESTART VSH");
drawStringCenter(258, "REBOOT DEVICE");
break;
case 9:
drawSetColour(WHITE, SKYBLUE);
drawStringCenter(274, "EXIT");
drawStringCenter(274, "RESTART VSH");
break;
case 10:
drawSetColour(WHITE, SKYBLUE);
drawStringCenter(290, "EXIT");
break;
}
}
Expand Down Expand Up @@ -145,6 +151,34 @@ static SceVoid Menu_DisplayBatteryMenu(SceVoid)
}
}

static SceVoid Menu_DisplayFPSMenu(SceVoid)
{
drawSetColour(WHITE, RGB_GREEN);
drawStringCenter(100, "FPS SETTINGS");

drawSetColour(WHITE, Config_GetVSHColour());

drawStringCenter(130, "<- BACK");
drawStringfCenter(162, "KEEP FPS DISPLAY %s", fpsDisplay? "enabled" : "disabled");
drawStringfCenter(178, "FPS %s", fps? "enabled" : "disabled");

switch(selection)
{
case 0:
drawSetColour(WHITE, SKYBLUE);
drawStringCenter(130, "<- BACK");
break;
case 1:
drawSetColour(WHITE, SKYBLUE);
drawStringfCenter(162, "KEEP FPS DISPLAY %s", fpsDisplay? "enabled" : "disabled");
break;
case 2:
drawSetColour(WHITE, SKYBLUE);
drawStringfCenter(178, "FPS %s", fps? "enabled" : "disabled");
break;
}
}

static SceVoid Menu_DisplayProgramMenu(SceVoid)
{
drawSetColour(WHITE, RGB_GREEN);
Expand Down Expand Up @@ -216,6 +250,8 @@ SceVoid Menu_Display(SceBool vertical_blank)
Menu_DisplayMainMenu();
else if (showVSH == VSH_BATTERY_MENU)
Menu_DisplayBatteryMenu();
else if (showVSH == VSH_FPS_MENU)
Menu_DisplayFPSMenu();
else if (showVSH == VSH_PROGRAM_MENU)
Menu_DisplayProgramMenu();

Expand All @@ -225,7 +261,7 @@ SceVoid Menu_Display(SceBool vertical_blank)

SceInt Menu_HandleControls(SceUInt32 pad)
{
if (showVSH == 1) // Main VSH Menu
if (showVSH == VSH_MAIN_MENU) // Main VSH Menu
{
if (pad & SCE_CTRL_DOWN)
selection += 1;
Expand Down Expand Up @@ -284,7 +320,7 @@ SceInt Menu_HandleControls(SceUInt32 pad)
else
colour = COLOUR_MAX_ITEMS;

Config_SaveMenuConfig(batteryPercent, batteryLifeTime, batteryTemp, batteryDisplay, colour);
Config_SaveMenuConfig(batteryPercent, batteryLifeTime, batteryTemp, batteryDisplay, colour, fps, fpsDisplay);
Config_LoadConfig();
}
else if (pad & SCE_CTRL_RIGHT)
Expand All @@ -294,7 +330,7 @@ SceInt Menu_HandleControls(SceUInt32 pad)
else
colour = 0;

Config_SaveMenuConfig(batteryPercent, batteryLifeTime, batteryTemp, batteryDisplay, colour);
Config_SaveMenuConfig(batteryPercent, batteryLifeTime, batteryTemp, batteryDisplay, colour, fps, fpsDisplay);
Config_LoadConfig();
}
}
Expand All @@ -304,19 +340,24 @@ SceInt Menu_HandleControls(SceUInt32 pad)
showVSH = VSH_BATTERY_MENU;
}
else if ((selection == 4) && (pad & SCE_CTRL_CROSS))
{
selection = 0;
showVSH = VSH_FPS_MENU;
}
else if ((selection == 5) && (pad & SCE_CTRL_CROSS))
{
selection = 0;
showVSH = VSH_PROGRAM_MENU;
}
else if ((selection == 5) && (pad & SCE_CTRL_CROSS))
scePowerRequestStandby();
else if ((selection == 6) && (pad & SCE_CTRL_CROSS))
scePowerRequestSuspend();
scePowerRequestStandby();
else if ((selection == 7) && (pad & SCE_CTRL_CROSS))
scePowerRequestSuspend();
else if ((selection == 8) && (pad & SCE_CTRL_CROSS))
scePowerRequestColdReset();
else if ((selection == 8) && (pad & SCE_CTRL_CROSS))
else if ((selection == 9) && (pad & SCE_CTRL_CROSS))
Utils_RestartVSH();
else if (((selection == 9) && (pad & SCE_CTRL_CROSS)) || (pad & SCE_CTRL_CIRCLE))
else if (((selection == 10) && (pad & SCE_CTRL_CROSS)) || (pad & SCE_CTRL_CIRCLE))
{
selection = 0;
showVSH = 0;
Expand Down Expand Up @@ -359,11 +400,48 @@ SceInt Menu_HandleControls(SceUInt32 pad)
break;
}

Config_SaveMenuConfig(batteryPercent, batteryLifeTime, batteryTemp, batteryDisplay, colour);
Config_SaveMenuConfig(batteryPercent, batteryLifeTime, batteryTemp, batteryDisplay, colour, fps, fpsDisplay);
Config_LoadConfig();
}
}
}
else if (showVSH == VSH_FPS_MENU)
{
if (pad & SCE_CTRL_DOWN)
selection += 1;
else if (pad & SCE_CTRL_UP)
selection -= 1;

if (selection == (FPS_MAX_ITEMS + 1))
selection = 0;
if (selection == -1)
selection = FPS_MAX_ITEMS;

if (((selection == 0) && (pad & SCE_CTRL_CROSS)) || (pad & SCE_CTRL_CIRCLE))
{
selection = 0;
showVSH = VSH_MAIN_MENU;
}
else
{
if ((pad & SCE_CTRL_LEFT) || (pad & SCE_CTRL_RIGHT))
{
switch(selection)
{
case 1:
fpsDisplay = !fpsDisplay;
break;
case 2:
fps = !fps;
break;
}

Config_SaveMenuConfig(batteryPercent, batteryLifeTime, batteryTemp, batteryDisplay, colour, fps, fpsDisplay);
Config_LoadConfig();
}
}

}
else if (showVSH == VSH_PROGRAM_MENU)
{
if (pad & SCE_CTRL_DOWN)
Expand Down
33 changes: 32 additions & 1 deletion source/vsh.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#define CLOCK_SET_DELAY_INIT 5000000 // 5 seconds
#define CLOCK_SET_DELAY_INTERVAL 30000000 // 30 seconds
#define FPS_TIMER_TICK 1000000

#define BUTTON_COMBO_1 ((ctrl->buttons & SCE_CTRL_LTRIGGER) && (ctrl->buttons & SCE_CTRL_RTRIGGER) && (ctrl->buttons & SCE_CTRL_START))
#define BUTTON_COMBO_2 ((ctrl->buttons & SCE_CTRL_L1) && (ctrl->buttons & SCE_CTRL_R1) && (ctrl->buttons & SCE_CTRL_START))
Expand All @@ -25,7 +26,32 @@ static tai_hook_ref_t hook[HOOKS_NUM];

SceInt showVSH = 0;
static SceBool isConfigSet = SCE_FALSE;
static SceUInt64 timer = 0;
static SceUInt64 timer = 0, tick = 0, t_tick = 0;

static SceInt frames = 0, fps_data = 0;

// This function is from Framecounter by Rinnegatamante.
static SceVoid DisplayFPS(SceVoid)
{
t_tick = sceKernelGetProcessTimeWide();

if (tick == 0)
tick = t_tick;
else
{
if ((t_tick - tick) > FPS_TIMER_TICK)
{
fps_data = frames;
frames = 0;
tick = t_tick;
}

drawSetColour(WHITE, Config_GetVSHColour());
drawStringf(0, 528, "FPS: %d", fps_data);
}

frames++;
}

SceInt sceDisplaySetFrameBuf_patched(const SceDisplayFrameBuf *pParam, SceDisplaySetBufSync sync)
{
Expand Down Expand Up @@ -66,6 +92,9 @@ SceInt sceDisplaySetFrameBuf_patched(const SceDisplayFrameBuf *pParam, SceDispla
Power_DisplayBatteryTemp();
}

if ((fpsDisplay && showVSH == 0))
DisplayFPS();

if (showVSH != 0)
{
if (batteryPercent)
Expand All @@ -74,6 +103,8 @@ SceInt sceDisplaySetFrameBuf_patched(const SceDisplayFrameBuf *pParam, SceDispla
Power_DisplayBatteryLifetime();
if (batteryTemp)
Power_DisplayBatteryTemp();
if (fps)
DisplayFPS();

Menu_Display(SCE_FALSE);
}
Expand Down

0 comments on commit cba08e6

Please sign in to comment.