(platform_switch.c) Cleanups

This commit is contained in:
twinaphex 2020-01-19 04:23:07 +01:00
parent 4e7a8a6478
commit 638b65c828

View File

@ -63,7 +63,7 @@ bool platform_switch_has_focus = true;
/* Splash */
static uint32_t *splashData = NULL;
static bool psmInitialized = false;
static bool psmInitialized = false;
static AppletHookCookie applet_hook_cookie;
@ -71,12 +71,19 @@ static AppletHookCookie applet_hook_cookie;
extern bool nxlink_connected;
#endif
void libnx_apply_overclock() {
const size_t profiles_count = sizeof(SWITCH_CPU_PROFILES) / sizeof(SWITCH_CPU_PROFILES[1]);
if (config_get_ptr()->uints.libnx_overclock >= 0 && config_get_ptr()->uints.libnx_overclock <= profiles_count){
if(hosversionBefore(8, 0, 0)) {
void libnx_apply_overclock(void)
{
const size_t profiles_count = sizeof(SWITCH_CPU_PROFILES)
/ sizeof(SWITCH_CPU_PROFILES[1]);
if (config_get_ptr()->uints.libnx_overclock >= 0 && config_get_ptr()->uints.libnx_overclock <= profiles_count)
{
if (hosversionBefore(8, 0, 0))
{
pcvSetClockRate(PcvModule_CpuBus, SWITCH_CPU_SPEEDS_VALUES[config_get_ptr()->uints.libnx_overclock]);
} else {
}
else
{
ClkrstSession session = {0};
clkrstOpenSession(&session, PcvModuleId_CpuBus, 3);
clkrstSetClockRate(&session, SWITCH_CPU_SPEEDS_VALUES[config_get_ptr()->uints.libnx_overclock]);
@ -85,52 +92,59 @@ void libnx_apply_overclock() {
}
}
static void on_applet_hook(AppletHookType hook, void *param) {
static void on_applet_hook(AppletHookType hook, void *param)
{
u32 performance_mode;
AppletFocusState focus_state;
/* Exit request */
switch (hook)
{
case AppletHookType_OnExitRequest:
RARCH_LOG("Got AppletHook OnExitRequest, exiting.\n");
retroarch_main_quit();
break;
case AppletHookType_OnExitRequest:
RARCH_LOG("Got AppletHook OnExitRequest, exiting.\n");
retroarch_main_quit();
break;
/* Focus state*/
case AppletHookType_OnFocusState:
focus_state = appletGetFocusState();
RARCH_LOG("Got AppletHook OnFocusState - new focus state is %d\n", focus_state);
platform_switch_has_focus = focus_state == AppletFocusState_Focused;
if(!platform_switch_has_focus) {
if(hosversionBefore(8, 0, 0)) {
pcvSetClockRate(PcvModule_CpuBus, 1020000000);
} else {
ClkrstSession session = {0};
clkrstOpenSession(&session, PcvModuleId_CpuBus, 3);
clkrstSetClockRate(&session, 1020000000);
clkrstCloseSession(&session);
/* Focus state*/
case AppletHookType_OnFocusState:
focus_state = appletGetFocusState();
RARCH_LOG("Got AppletHook OnFocusState - new focus state is %d\n", focus_state);
platform_switch_has_focus = focus_state == AppletFocusState_Focused;
if (!platform_switch_has_focus)
{
if (hosversionBefore(8, 0, 0))
{
pcvSetClockRate(PcvModule_CpuBus, 1020000000);
}
else
{
ClkrstSession session = {0};
clkrstOpenSession(&session, PcvModuleId_CpuBus, 3);
clkrstSetClockRate(&session, 1020000000);
clkrstCloseSession(&session);
}
}
} else {
else
libnx_apply_overclock();
break;
/* Performance mode */
case AppletHookType_OnPerformanceMode:
/* 0 == Handheld, 1 == Docked
* Since CPU doesn't change we just re-apply */
performance_mode = appletGetPerformanceMode();
libnx_apply_overclock();
}
break;
break;
/* Performance mode */
case AppletHookType_OnPerformanceMode:
// 0 == Handheld, 1 == Docked
// Since CPU doesn't change we just re-apply
performance_mode = appletGetPerformanceMode();
libnx_apply_overclock();
break;
default:
break;
default:
break;
}
}
#endif /* HAVE_LIBNX */
#ifdef IS_SALAMANDER
static void get_first_valid_core(char *path_return)
{
DIR *dir;
@ -140,11 +154,11 @@ static void get_first_valid_core(char *path_return)
path_return[0] = '\0';
dir = opendir(SD_PREFIX "/retroarch/cores");
if (dir != NULL)
if (dir)
{
while ((ent = readdir(dir)) != NULL)
while ((ent = readdir(dir)))
{
if (ent == NULL)
if (!ent)
break;
if (strlen(ent->d_name) > strlen(extension) && !strcmp(ent->d_name + strlen(ent->d_name) - strlen(extension), extension))
{
@ -157,8 +171,10 @@ static void get_first_valid_core(char *path_return)
closedir(dir);
}
}
#endif
static void frontend_switch_get_environment_settings(int *argc, char *argv[], void *args, void *params_data)
static void frontend_switch_get_environment_settings(
int *argc, char *argv[], void *args, void *params_data)
{
unsigned i;
(void)args;
@ -266,10 +282,13 @@ static void frontend_switch_deinit(void *data)
#ifdef HAVE_LIBNX
nifmExit();
if(hosversionBefore(8, 0, 0)) {
if (hosversionBefore(8, 0, 0))
{
pcvSetClockRate(PcvModule_CpuBus, 1020000000);
pcvExit();
} else {
}
else
{
ClkrstSession session = {0};
clkrstOpenSession(&session, PcvModuleId_CpuBus, 3);
clkrstSetClockRate(&session, 1020000000);
@ -548,26 +567,21 @@ ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize)
/* Taken from glibc */
char *realpath(const char *name, char *resolved)
{
char *rpath, *dest, *extra_buf = NULL;
char *rpath, *dest = NULL;
const char *start, *end, *rpath_limit;
long int path_max;
int num_links = 0;
if (name == NULL)
{
/* As per Single Unix Specification V2 we must return an error if
either parameter is a null pointer. We extend this to allow
the RESOLVED parameter to be NULL in case the we are expected to
allocate the room for the return value. */
/* As per Single Unix Specification V2 we must return an error if
either parameter is a null pointer. We extend this to allow
the RESOLVED parameter to be NULL in case the we are expected to
allocate the room for the return value. */
if (!name)
return NULL;
}
/* As per Single Unix Specification V2 we must return an error if
the name argument points to an empty string. */
if (name[0] == '\0')
{
/* As per Single Unix Specification V2 we must return an error if
the name argument points to an empty string. */
return NULL;
}
#ifdef PATH_MAX
path_max = PATH_MAX;
@ -577,10 +591,10 @@ char *realpath(const char *name, char *resolved)
path_max = 1024;
#endif
if (resolved == NULL)
if (!resolved)
{
rpath = malloc(path_max);
if (rpath == NULL)
if (!rpath)
return NULL;
}
else
@ -650,7 +664,7 @@ char *realpath(const char *name, char *resolved)
else
new_size += path_max;
new_rpath = (char *)realloc(rpath, new_size);
if (new_rpath == NULL)
if (!new_rpath)
goto error;
rpath = new_rpath;
rpath_limit = rpath + new_size;
@ -669,7 +683,7 @@ char *realpath(const char *name, char *resolved)
return rpath;
error:
if (resolved == NULL)
if (!resolved)
free(rpath);
return NULL;
}
@ -688,12 +702,10 @@ static void frontend_switch_init(void *data)
{
#ifdef HAVE_LIBNX
bool recording_supported = false;
uint32_t width = 0;
uint32_t height = 0;
nifmInitialize(NifmServiceType_User);
if(hosversionBefore(8, 0, 0))
if (hosversionBefore(8, 0, 0))
pcvInitialize();
else
clkrstInitialize();
@ -703,7 +715,7 @@ static void frontend_switch_init(void *data)
appletSetFocusHandlingMode(AppletFocusHandlingMode_NoSuspend);
appletIsGamePlayRecordingSupported(&recording_supported);
if(recording_supported)
if (recording_supported)
appletInitializeGamePlayRecording();
#ifdef NXLINK
@ -723,65 +735,6 @@ static void frontend_switch_init(void *data)
RARCH_WARN("Error initializing psm\n");
}
#if 0
#ifndef HAVE_OPENGL
/* Load splash */
if (!splashData)
{
rarch_system_info_t *sys_info = runloop_get_system_info();
retro_get_system_info(sys_info);
if (sys_info)
{
const char *core_name = sys_info->info.library_name;
char *full_core_splash_path = (char*)malloc(PATH_MAX);
snprintf(full_core_splash_path,
PATH_MAX, "/retroarch/rgui/splash/%s.png", core_name);
rpng_load_image_argb((const char *)
full_core_splash_path, &splashData, &width, &height);
if (splashData)
{
argb_to_rgba8(splashData, height, width);
frontend_switch_showsplash();
}
else
{
rpng_load_image_argb(
"/retroarch/rgui/splash/RetroArch.png",
&splashData, &width, &height);
if (splashData)
{
argb_to_rgba8(splashData, height, width);
frontend_switch_showsplash();
}
}
free(full_core_splash_path);
}
else
{
rpng_load_image_argb(
"/retroarch/rgui/splash/RetroArch.png",
&splashData, &width, &height);
if (splashData)
{
argb_to_rgba8(splashData, height, width);
frontend_switch_showsplash();
}
}
}
else
{
frontend_switch_showsplash();
}
#endif
#endif
#endif /* HAVE_LIBNX (splash) */
}