From fe32ad88fb0e0a9e60a2a1fefe4de93f2ec6c8bb Mon Sep 17 00:00:00 2001 From: M4xw Date: Sun, 15 Mar 2020 07:56:38 -0700 Subject: [PATCH] Core: Add some libnx calls for Switch. --- Core/HLE/sceRtc.cpp | 15 +++++++++++---- SDL/SDLMain.cpp | 29 ++++++++++++++++++++++------- ext/native/base/timeutil.cpp | 6 ++++++ 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/Core/HLE/sceRtc.cpp b/Core/HLE/sceRtc.cpp index 1809430d1c..75e9e3ef3b 100644 --- a/Core/HLE/sceRtc.cpp +++ b/Core/HLE/sceRtc.cpp @@ -37,6 +37,13 @@ #include "Core/HLE/sceKernel.h" #include "Core/HLE/sceRtc.h" +#ifdef HAVE_LIBNX +// I guess that works... +#define setenv(x, y, z) (void*)0 +#define tzset() (void*)0 +#define unsetenv(x) (void*)0 +#endif // HAVE_LIBNX + // This is a base time that everything is relative to. // This way, time doesn't move strangely with savestates, turbo speed, etc. static PSPTimeval rtcBaseTime; @@ -494,7 +501,7 @@ static int sceRtcConvertLocalTimeToUTC(u32 tickLocalPtr,u32 tickUTCPtr) long timezone_val; _get_timezone(&timezone_val); srcTick -= -timezone_val * 1000000ULL; -#elif !defined(_AIX) && !defined(__sgi) && !defined(__hpux) +#elif !defined(_AIX) && !defined(__sgi) && !defined(__hpux) && !defined(HAVE_LIBNX) time_t timezone = 0; tm *time = localtime(&timezone); srcTick -= time->tm_gmtoff*1000000ULL; @@ -519,7 +526,7 @@ static int sceRtcConvertUtcToLocalTime(u32 tickUTCPtr,u32 tickLocalPtr) long timezone_val; _get_timezone(&timezone_val); srcTick += -timezone_val * 1000000ULL; -#elif !defined(_AIX) && !defined(__sgi) && !defined(__hpux) +#elif !defined(_AIX) && !defined(__sgi) && !defined(__hpux) && !defined(HAVE_LIBNX) time_t timezone = 0; tm *time = localtime(&timezone); srcTick += time->tm_gmtoff*1000000ULL; @@ -1054,7 +1061,7 @@ static int sceRtcFormatRFC2822LocalTime(u32 outPtr, u32 srcTickPtr) long timezone_val; _get_timezone(&timezone_val); tz_seconds = -timezone_val; -#elif !defined(_AIX) && !defined(__sgi) && !defined(__hpux) +#elif !defined(_AIX) && !defined(__sgi) && !defined(__hpux) && !defined(HAVE_LIBNX) time_t timezone = 0; tm *time = localtime(&timezone); tz_seconds = time->tm_gmtoff; @@ -1091,7 +1098,7 @@ static int sceRtcFormatRFC3339LocalTime(u32 outPtr, u32 srcTickPtr) long timezone_val; _get_timezone(&timezone_val); tz_seconds = -timezone_val; -#elif !defined(_AIX) && !defined(__sgi) && !defined(__hpux) +#elif !defined(_AIX) && !defined(__sgi) && !defined(__hpux) && !defined(HAVE_LIBNX) time_t timezone = 0; tm *time = localtime(&timezone); tz_seconds = time->tm_gmtoff; diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index ced99103ca..2639a5a23a 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -198,8 +198,9 @@ void OpenDirectory(const char *path) { void LaunchBrowser(const char *url) { #if PPSSPP_PLATFORM(SWITCH) + Uuid uuid = { 0 }; WebWifiConfig conf; - webWifiCreate(&conf, NULL, url, 0, 0); + webWifiCreate(&conf, NULL, url, uuid, 0); webWifiShow(&conf, NULL); #elif defined(MOBILE_DEVICE) ILOG("Would have gone to %s but LaunchBrowser is not implemented on this platform", url); @@ -220,8 +221,9 @@ void LaunchBrowser(const char *url) { void LaunchMarket(const char *url) { #if PPSSPP_PLATFORM(SWITCH) + Uuid uuid = { 0 }; WebWifiConfig conf; - webWifiCreate(&conf, NULL, url, 0, 0); + webWifiCreate(&conf, NULL, url, uuid, 0); webWifiShow(&conf, NULL); #elif defined(MOBILE_DEVICE) ILOG("Would have gone to %s but LaunchMarket is not implemented on this platform", url); @@ -448,6 +450,11 @@ int main(int argc, char *argv[]) { } } +#ifdef HAVE_LIBNX + socketInitializeDefault(); + nxlinkStdio(); +#endif // HAVE_LIBNX + glslang::InitializeProcess(); #if PPSSPP_PLATFORM(RPI) @@ -544,9 +551,9 @@ int main(int argc, char *argv[]) { } // If we're on mobile, don't try for windowed either. -#if defined(MOBILE_DEVICE) +#if defined(MOBILE_DEVICE) && !PPSSPP_PLATFORM(SWITCH) mode |= SDL_WINDOW_FULLSCREEN; -#elif defined(USING_FBDEV) +#elif defined(USING_FBDEV) || PPSSPP_PLATFORM(SWITCH) mode |= SDL_WINDOW_FULLSCREEN_DESKTOP; #else mode |= SDL_WINDOW_RESIZABLE; @@ -592,14 +599,19 @@ int main(int argc, char *argv[]) { // Mac / Linux char path[2048]; +#if PPSSPP_PLATFORM(SWITCH) + strcpy(path, "/switch/ppsspp/"); +#else const char *the_path = getenv("HOME"); if (!the_path) { - struct passwd* pwd = getpwuid(getuid()); + struct passwd *pwd = getpwuid(getuid()); if (pwd) the_path = pwd->pw_dir; } - strcpy(path, the_path); - if (path[strlen(path)-1] != '/') + if (the_path) + strcpy(path, the_path); +#endif + if (strlen(path) > 0 && path[strlen(path) - 1] != '/') strcat(path, "/"); NativeInit(remain_argc, (const char **)remain_argv, path, "/tmp", nullptr); @@ -1139,5 +1151,8 @@ int main(int argc, char *argv[]) { glslang::FinalizeProcess(); ILOG("Leaving main"); +#ifdef HAVE_LIBNX + socketExit(); +#endif return 0; } diff --git a/ext/native/base/timeutil.cpp b/ext/native/base/timeutil.cpp index f48c87a276..5c70e80053 100644 --- a/ext/native/base/timeutil.cpp +++ b/ext/native/base/timeutil.cpp @@ -11,6 +11,10 @@ #include #endif +#ifdef HAVE_LIBNX +#include +#endif // HAVE_LIBNX + static double curtime = 0; static float curtime_f = 0; @@ -79,6 +83,8 @@ int time_now_ms() { void sleep_ms(int ms) { #ifdef _WIN32 Sleep(ms); +#elif defined(HAVE_LIBNX) + svcSleepThread(ms * 1000000); #else usleep(ms * 1000); #endif