From ffee69ffa1957489b48cacc21551a8ff9bb64185 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 13 Aug 2023 11:32:01 +1000 Subject: [PATCH] Move common platform console to _PlatformConsole.h --- src/ClassiCube.vcxproj | 1 + src/ClassiCube.vcxproj.filters | 3 + src/Platform_3DS.c | 129 ++---------------------------- src/Platform_Dreamcast.c | 135 +------------------------------- src/Platform_GCWii.c | 139 ++------------------------------- src/Platform_PSP.c | 131 +------------------------------ src/Platform_PSVita.c | 137 ++------------------------------ src/Platform_Posix.c | 1 + src/Platform_Web.c | 1 + src/Platform_WinApi.c | 1 + src/Platform_Xbox.c | 130 +----------------------------- src/Window_PSP.c | 6 ++ src/_PlatformBase.h | 1 - src/_PlatformConsole.h | 124 +++++++++++++++++++++++++++++ 14 files changed, 169 insertions(+), 770 deletions(-) create mode 100644 src/_PlatformConsole.h diff --git a/src/ClassiCube.vcxproj b/src/ClassiCube.vcxproj index 1efd78d2d..bc22d758b 100644 --- a/src/ClassiCube.vcxproj +++ b/src/ClassiCube.vcxproj @@ -441,6 +441,7 @@ + diff --git a/src/ClassiCube.vcxproj.filters b/src/ClassiCube.vcxproj.filters index 523461f83..6f062f985 100644 --- a/src/ClassiCube.vcxproj.filters +++ b/src/ClassiCube.vcxproj.filters @@ -339,6 +339,9 @@ Header Files\Network + + Header Files\Platform + diff --git a/src/Platform_3DS.c b/src/Platform_3DS.c index 881051fb9..0b878c42c 100644 --- a/src/Platform_3DS.c +++ b/src/Platform_3DS.c @@ -1,6 +1,5 @@ #include "Core.h" #if defined CC_BUILD_3DS - #include "_PlatformBase.h" #include "Stream.h" #include "ExtMath.h" @@ -9,6 +8,7 @@ #include "Utils.h" #include "Errors.h" #include "PackedCol.h" + #include #include #include @@ -27,6 +27,7 @@ #include #include <3ds.h> #include +#include "_PlatformConsole.h" #define US_PER_SEC 1000000LL #define NS_PER_MS 1000000LL @@ -43,31 +44,6 @@ const char* Platform_AppNameSuffix = " 3DS"; unsigned int __stacksize__ = 256 * 1024; -/*########################################################################################################################* -*---------------------------------------------------------Memory----------------------------------------------------------* -*#########################################################################################################################*/ -void Mem_Set(void* dst, cc_uint8 value, cc_uint32 numBytes) { memset(dst, value, numBytes); } -void Mem_Copy(void* dst, const void* src, cc_uint32 numBytes) { memcpy(dst, src, numBytes); } - -void* Mem_TryAlloc(cc_uint32 numElems, cc_uint32 elemsSize) { - cc_uint32 size = CalcMemSize(numElems, elemsSize); - return size ? malloc(size) : NULL; -} - -void* Mem_TryAllocCleared(cc_uint32 numElems, cc_uint32 elemsSize) { - return calloc(numElems, elemsSize); -} - -void* Mem_TryRealloc(void* mem, cc_uint32 numElems, cc_uint32 elemsSize) { - cc_uint32 size = CalcMemSize(numElems, elemsSize); - return size ? realloc(mem, size) : NULL; -} - -void Mem_Free(void* mem) { - if (mem) free(mem); -} - - /*########################################################################################################################* *------------------------------------------------------Logging/Time-------------------------------------------------------* *#########################################################################################################################*/ @@ -120,7 +96,6 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) { /*########################################################################################################################* *-----------------------------------------------------Directory/File------------------------------------------------------* *#########################################################################################################################*/ -void Directory_GetCachePath(cc_string* path) { } static const cc_string root_path = String_FromConst("sdmc:/3ds/ClassiCube/"); static void GetNativePath(char* str, const cc_string* path) { @@ -422,59 +397,10 @@ cc_result Socket_CheckWritable(cc_socket s, cc_bool* writable) { /*########################################################################################################################* -*-----------------------------------------------------Process/Module------------------------------------------------------* +*--------------------------------------------------------Platform---------------------------------------------------------* *#########################################################################################################################*/ -static char gameArgs[GAME_MAX_CMDARGS][STRING_SIZE]; -static int gameNumArgs; -static cc_bool gameHasArgs; - -cc_result Process_StartGame2(const cc_string* args, int numArgs) { - for (int i = 0; i < numArgs; i++) - { - String_CopyToRawArray(gameArgs[i], &args[i]); - } - - Platform_LogConst("START GAME"); - gameHasArgs = true; - gameNumArgs = numArgs; - return 0; -} - -static int GetGameArgs(cc_string* args) { - int count = gameNumArgs; - for (int i = 0; i < count; i++) - { - args[i] = String_FromRawArray(gameArgs[i]); - } - - // clear arguments so after game is closed, launcher is started - gameNumArgs = 0; - return count; -} - -int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) { - if (gameHasArgs) return GetGameArgs(args); - // 3DS *sometimes* doesn't use argv[0] for program name and so argc will be 0 - // (e.g. when running from Citra) - if (!argc) return 0; - - argc--; argv++; // skip executable path argument - - int count = min(argc, GAME_MAX_CMDARGS); - Platform_Log1("ARGS: %i", &count); - - for (int i = 0; i < count; i++) { - args[i] = String_FromReadonly(argv[i]); - Platform_Log2(" ARG %i = %c", &i, argv[i]); - } - return count; -} - -cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) { - return 0; -} - -void Process_Exit(cc_result code) { exit(code); } +#define SOC_CTX_ALIGN 0x1000 +#define SOC_CTX_SIZE 0x1000 * 128 cc_result Process_StartOpen(const cc_string* args) { char url[NATIVE_STR_LEN]; @@ -486,46 +412,6 @@ cc_result Process_StartOpen(const cc_string* args) { // len + 1 for null terminator } - -/*########################################################################################################################* -*--------------------------------------------------------Updater----------------------------------------------------------* -*#########################################################################################################################*/ -const char* const Updater_D3D9 = NULL; -cc_bool Updater_Clean(void) { return true; } - -const struct UpdaterInfo Updater_Info = { "&eCompile latest source code to update", 0 }; - -cc_result Updater_Start(const char** action) { *action = "Starting"; return ERR_NOT_SUPPORTED; } - -cc_result Updater_GetBuildTime(cc_uint64* timestamp) { return ERR_NOT_SUPPORTED; } - -cc_result Updater_MarkExecutable(void) { return ERR_NOT_SUPPORTED; } - -cc_result Updater_SetNewBuildTime(cc_uint64 timestamp) { return ERR_NOT_SUPPORTED; } - - -/*########################################################################################################################* -*-------------------------------------------------------Dynamic lib-------------------------------------------------------* -*#########################################################################################################################*/ - -const cc_string DynamicLib_Ext = String_FromConst(".so"); - -void* DynamicLib_Load2(const cc_string* path) { return NULL; } - -void* DynamicLib_Get2(void* lib, const char* name) { return NULL; } - -cc_bool DynamicLib_DescribeError(cc_string* dst) { - String_AppendConst(dst, "Dynamic linking unsupported"); - return true; -} - - -/*########################################################################################################################* -*--------------------------------------------------------Platform---------------------------------------------------------* -*#########################################################################################################################*/ -#define SOC_CTX_ALIGN 0x1000 -#define SOC_CTX_SIZE 0x1000 * 128 - static void CreateRootDirectory(const char* path) { // create root directories (no permissions anyways) int res = mkdir(path, 0666); @@ -536,8 +422,6 @@ static void CreateRootDirectory(const char* path) { } void Platform_Init(void) { - Platform_SingleProcess = true; - // create root directories (no permissions anyways) CreateRootDirectory("sdmc:/3ds"); CreateRootDirectory("sdmc:/3ds/ClassiCube"); @@ -580,7 +464,8 @@ cc_bool Platform_DescribeError(cc_result res, cc_string* dst) { cc_result Platform_Encrypt(const void* data, int len, cc_string* dst) { return ERR_NOT_SUPPORTED; } + cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) { return ERR_NOT_SUPPORTED; } -#endif \ No newline at end of file +#endif diff --git a/src/Platform_Dreamcast.c b/src/Platform_Dreamcast.c index 3bf03939f..b8a0eac6d 100644 --- a/src/Platform_Dreamcast.c +++ b/src/Platform_Dreamcast.c @@ -1,6 +1,5 @@ #include "Core.h" #if defined CC_BUILD_DREAMCAST - #include "_PlatformBase.h" #include "Stream.h" #include "ExtMath.h" @@ -8,6 +7,7 @@ #include "Window.h" #include "Utils.h" #include "Errors.h" + #include #include #include @@ -18,6 +18,7 @@ #include #include #include +#include "_PlatformConsole.h" const cc_result ReturnCode_FileShareViolation = 1000000000; // not used const cc_result ReturnCode_FileNotFound = ENOENT; @@ -27,31 +28,6 @@ const cc_result ReturnCode_DirectoryExists = EEXIST; const char* Platform_AppNameSuffix = " Dreamcast"; -/*########################################################################################################################* -*---------------------------------------------------------Memory----------------------------------------------------------* -*#########################################################################################################################*/ -void Mem_Set(void* dst, cc_uint8 value, cc_uint32 numBytes) { memset(dst, value, numBytes); } -void Mem_Copy(void* dst, const void* src, cc_uint32 numBytes) { memcpy(dst, src, numBytes); } - -void* Mem_TryAlloc(cc_uint32 numElems, cc_uint32 elemsSize) { - cc_uint32 size = CalcMemSize(numElems, elemsSize); - return size ? malloc(size) : NULL; -} - -void* Mem_TryAllocCleared(cc_uint32 numElems, cc_uint32 elemsSize) { - return calloc(numElems, elemsSize); -} - -void* Mem_TryRealloc(void* mem, cc_uint32 numElems, cc_uint32 elemsSize) { - cc_uint32 size = CalcMemSize(numElems, elemsSize); - return size ? realloc(mem, size) : NULL; -} - -void Mem_Free(void* mem) { - if (mem) free(mem); -} - - /*########################################################################################################################* *------------------------------------------------------Logging/Time-------------------------------------------------------* *#########################################################################################################################*/ @@ -95,13 +71,8 @@ void DateTime_CurrentLocal(struct DateTime* t) { /*########################################################################################################################* *-----------------------------------------------------Directory/File------------------------------------------------------* *#########################################################################################################################*/ -void Directory_GetCachePath(cc_string* path) { } - -extern int __path_absolute(const char *in, char *out, int len); static void GetNativePath(char* str, const cc_string* path) { - //char tmp[NATIVE_STR_LEN + 1]; String_EncodeUtf8(str, path); - //__path_absolute(tmp, str, NATIVE_STR_LEN); } cc_result Directory_Create(const cc_string* path) { @@ -437,111 +408,13 @@ cc_result Socket_CheckWritable(cc_socket s, cc_bool* writable) { /*########################################################################################################################* -*-----------------------------------------------------Process/Module------------------------------------------------------* +*--------------------------------------------------------Platform---------------------------------------------------------* *#########################################################################################################################*/ -static char gameArgs[GAME_MAX_CMDARGS][STRING_SIZE]; -static int gameNumArgs; -static cc_bool gameHasArgs; - -cc_result Process_StartGame2(const cc_string* args, int numArgs) { - for (int i = 0; i < numArgs; i++) - { - String_CopyToRawArray(gameArgs[i], &args[i]); - } - - Platform_LogConst("START GAME"); - gameHasArgs = true; - gameNumArgs = numArgs; - return 0; -} - -static int GetGameArgs(cc_string* args) { - int count = gameNumArgs; - for (int i = 0; i < count; i++) - { - args[i] = String_FromRawArray(gameArgs[i]); - } - - // clear arguments so after game is closed, launcher is started - gameNumArgs = 0; - return count; -} - -int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) { - if (gameHasArgs) return GetGameArgs(args); - // PSP *sometimes* doesn't use argv[0] for program name and so argc will be 0 - if (!argc) return 0; - - argc--; argv++; // skip executable path argument - - int count = min(argc, GAME_MAX_CMDARGS); - Platform_Log1("ARGS: %i", &count); - - for (int i = 0; i < count; i++) - { - args[i] = String_FromReadonly(argv[i]); - Platform_Log2(" ARG %i = %c", &i, argv[i]); - } - return count; -} - -cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) { - return 0; // TODO switch to RomFS ?? -} - -void Process_Exit(cc_result code) { exit(code); } - cc_result Process_StartOpen(const cc_string* args) { return ERR_NOT_SUPPORTED; } - -/*########################################################################################################################* -*--------------------------------------------------------Updater----------------------------------------------------------* -*#########################################################################################################################*/ -const char* const Updater_D3D9 = NULL; -cc_bool Updater_Clean(void) { return true; } - -const struct UpdaterInfo Updater_Info = { "&eCompile latest source code to update", 0 }; - -cc_result Updater_Start(const char** action) { - *action = "Starting game"; - return ERR_NOT_SUPPORTED; -} - -cc_result Updater_GetBuildTime(cc_uint64* timestamp) { - return ERR_NOT_SUPPORTED; -} - -cc_result Updater_MarkExecutable(void) { - return ERR_NOT_SUPPORTED; -} - -cc_result Updater_SetNewBuildTime(cc_uint64 timestamp) { - return ERR_NOT_SUPPORTED; -} - - -/*########################################################################################################################* -*-------------------------------------------------------Dynamic lib-------------------------------------------------------* -*#########################################################################################################################*/ -/* TODO can this actually be supported somehow */ -const cc_string DynamicLib_Ext = String_FromConst(".so"); - -void* DynamicLib_Load2(const cc_string* path) { return NULL; } -void* DynamicLib_Get2(void* lib, const char* name) { return NULL; } - -cc_bool DynamicLib_DescribeError(cc_string* dst) { - String_AppendConst(dst, "Dynamic linking unsupported"); - return true; -} - - -/*########################################################################################################################* -*--------------------------------------------------------Platform---------------------------------------------------------* -*#########################################################################################################################*/ void Platform_Init(void) { - Platform_SingleProcess = true; /*pspDebugSioInit();*/ char cwd[600] = { 0 }; @@ -577,4 +450,4 @@ cc_result Platform_Encrypt(const void* data, int len, cc_string* dst) { cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) { return ERR_NOT_SUPPORTED; } -#endif \ No newline at end of file +#endif diff --git a/src/Platform_GCWii.c b/src/Platform_GCWii.c index 77ed77195..ddc31e71f 100644 --- a/src/Platform_GCWii.c +++ b/src/Platform_GCWii.c @@ -8,6 +8,7 @@ #include "Utils.h" #include "Errors.h" #include "PackedCol.h" + #include #include #include @@ -24,6 +25,7 @@ #ifdef HW_RVL #include #endif +#include "_PlatformConsole.h" const cc_result ReturnCode_FileShareViolation = 1000000000; /* TODO: not used apparently */ const cc_result ReturnCode_FileNotFound = ENOENT; @@ -37,31 +39,6 @@ const char* Platform_AppNameSuffix = " GameCube"; #endif -/*########################################################################################################################* -*---------------------------------------------------------Memory----------------------------------------------------------* -*#########################################################################################################################*/ -void Mem_Set(void* dst, cc_uint8 value, cc_uint32 numBytes) { memset(dst, value, numBytes); } -void Mem_Copy(void* dst, const void* src, cc_uint32 numBytes) { memcpy(dst, src, numBytes); } - -void* Mem_TryAlloc(cc_uint32 numElems, cc_uint32 elemsSize) { - cc_uint32 size = CalcMemSize(numElems, elemsSize); - return size ? malloc(size) : NULL; -} - -void* Mem_TryAllocCleared(cc_uint32 numElems, cc_uint32 elemsSize) { - return calloc(numElems, elemsSize); -} - -void* Mem_TryRealloc(void* mem, cc_uint32 numElems, cc_uint32 elemsSize) { - cc_uint32 size = CalcMemSize(numElems, elemsSize); - return size ? realloc(mem, size) : NULL; -} - -void Mem_Free(void* mem) { - if (mem) free(mem); -} - - /*########################################################################################################################* *------------------------------------------------------Logging/Time-------------------------------------------------------* *#########################################################################################################################*/ @@ -118,7 +95,6 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) { /*########################################################################################################################* *-----------------------------------------------------Directory/File------------------------------------------------------* *#########################################################################################################################*/ -void Directory_GetCachePath(cc_string* path) { } static char root_buffer[NATIVE_STR_LEN]; static cc_string root_path = String_FromArray(root_buffer); @@ -381,12 +357,6 @@ void Waitable_WaitFor(void* handle, cc_uint32 milliseconds) { } -/*########################################################################################################################* -*--------------------------------------------------------Font/Text--------------------------------------------------------* -*#########################################################################################################################*/ -void Platform_LoadSysFonts(void) { } - - /*########################################################################################################################* *---------------------------------------------------------Socket----------------------------------------------------------* *#########################################################################################################################*/ @@ -534,57 +504,8 @@ static void InitSockets(void) { /*########################################################################################################################* -*-----------------------------------------------------Process/Module------------------------------------------------------* +*--------------------------------------------------------Platform---------------------------------------------------------* *#########################################################################################################################*/ -static char gameArgs[GAME_MAX_CMDARGS][STRING_SIZE]; -static int gameNumArgs; -static cc_bool gameHasArgs; -cc_result Process_StartGame2(const cc_string* args, int numArgs) { - for (int i = 0; i < numArgs; i++) - { - String_CopyToRawArray(gameArgs[i], &args[i]); - } - - Platform_LogConst("START GAME"); - gameHasArgs = true; - gameNumArgs = numArgs; - return 0; -} -static int GetGameArgs(cc_string* args) { - int count = gameNumArgs; - for (int i = 0; i < count; i++) - { - args[i] = String_FromRawArray(gameArgs[i]); - } - - // clear arguments so after game is closed, launcher is started - gameNumArgs = 0; - return count; -} -int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) { - if (gameHasArgs) return GetGameArgs(args); - // GC/WII *sometimes* doesn't use argv[0] for program name and so argc will be 0 - if (!argc) return 0; - - // at least The Homebrew Channel loader uses argv[0] for executable filename - // see strcpy(result->args, filename); in loader_load in loader.c - // https://github.com/fail0verflow/hbc/blob/master/channel/channelapp/source/loader.c#L912 - argc--; argv++; - - int count = min(argc, GAME_MAX_CMDARGS); - for (int i = 0; i < count; i++) - { - args[i] = String_FromReadonly(argv[i]); - } - return count; -} - -cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) { - return 0; -} - -void Process_Exit(cc_result code) { exit(code); } - #ifdef HW_RVL cc_result Process_StartOpen(const cc_string* args) { char url[NATIVE_STR_LEN]; @@ -599,56 +520,9 @@ cc_result Process_StartOpen(const cc_string* args) { } #endif - -/*########################################################################################################################* -*--------------------------------------------------------Updater----------------------------------------------------------* -*#########################################################################################################################*/ -const char* const Updater_D3D9 = NULL; -cc_bool Updater_Clean(void) { return true; } - -const struct UpdaterInfo Updater_Info = { "&eCompile latest source code to update", 0 }; - -cc_result Updater_Start(const char** action) { - *action = "Starting game"; - return ERR_NOT_SUPPORTED; -} - -cc_result Updater_GetBuildTime(cc_uint64* timestamp) { - return ERR_NOT_SUPPORTED; -} - -cc_result Updater_MarkExecutable(void) { - return ERR_NOT_SUPPORTED; -} - -cc_result Updater_SetNewBuildTime(cc_uint64 timestamp) { - return ERR_NOT_SUPPORTED; -} - - -/*########################################################################################################################* -*-------------------------------------------------------Dynamic lib-------------------------------------------------------* -*#########################################################################################################################*/ -/* TODO can this actually be supported somehow */ -const cc_string DynamicLib_Ext = String_FromConst(".so"); - -void* DynamicLib_Load2(const cc_string* path) { return NULL; } -void* DynamicLib_Get2(void* lib, const char* name) { return NULL; } - -cc_bool DynamicLib_DescribeError(cc_string* dst) { - String_AppendConst(dst, "Dynamic linking unsupported"); - return true; -} - - -/*########################################################################################################################* -*--------------------------------------------------------Platform---------------------------------------------------------* -*#########################################################################################################################*/ static void AppendDevice(cc_string* path, char* cwd) { // try to find device FAT mounted on, otherwise default to SD card - if (!cwd) { - String_AppendConst(path, "sd"); return; - } + if (!cwd) { String_AppendConst(path, "sd"); return; } Platform_Log1("CWD: %c", cwd); cc_string cwd_ = String_FromReadonly(cwd); @@ -682,8 +556,6 @@ static void CreateRootDirectory(void) { } void Platform_Init(void) { - Platform_SingleProcess = true; - fat_available = fatInitDefault(); FindRootDirectory(); CreateRootDirectory(); @@ -716,7 +588,8 @@ cc_bool Platform_DescribeError(cc_result res, cc_string* dst) { cc_result Platform_Encrypt(const void* data, int len, cc_string* dst) { return ERR_NOT_SUPPORTED; } + cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) { return ERR_NOT_SUPPORTED; } -#endif \ No newline at end of file +#endif diff --git a/src/Platform_PSP.c b/src/Platform_PSP.c index 4c015a0ed..d118ff80b 100644 --- a/src/Platform_PSP.c +++ b/src/Platform_PSP.c @@ -1,6 +1,5 @@ #include "Core.h" #if defined CC_BUILD_PSP - #include "_PlatformBase.h" #include "Stream.h" #include "ExtMath.h" @@ -8,6 +7,7 @@ #include "Window.h" #include "Utils.h" #include "Errors.h" + #include #include #include @@ -16,6 +16,7 @@ #include #include #include +#include "_PlatformConsole.h" const cc_result ReturnCode_FileShareViolation = 1000000000; // not used const cc_result ReturnCode_FileNotFound = ENOENT; @@ -30,31 +31,6 @@ PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER); PSP_DISABLE_AUTOSTART_PTHREAD() // reduces .elf size by 140 kb -/*########################################################################################################################* -*---------------------------------------------------------Memory----------------------------------------------------------* -*#########################################################################################################################*/ -void Mem_Set(void* dst, cc_uint8 value, cc_uint32 numBytes) { memset(dst, value, numBytes); } -void Mem_Copy(void* dst, const void* src, cc_uint32 numBytes) { memcpy(dst, src, numBytes); } - -void* Mem_TryAlloc(cc_uint32 numElems, cc_uint32 elemsSize) { - cc_uint32 size = CalcMemSize(numElems, elemsSize); - return size ? malloc(size) : NULL; -} - -void* Mem_TryAllocCleared(cc_uint32 numElems, cc_uint32 elemsSize) { - return calloc(numElems, elemsSize); -} - -void* Mem_TryRealloc(void* mem, cc_uint32 numElems, cc_uint32 elemsSize) { - cc_uint32 size = CalcMemSize(numElems, elemsSize); - return size ? realloc(mem, size) : NULL; -} - -void Mem_Free(void* mem) { - if (mem) free(mem); -} - - /*########################################################################################################################* *------------------------------------------------------Logging/Time-------------------------------------------------------* *#########################################################################################################################*/ @@ -106,8 +82,6 @@ cc_uint64 Stopwatch_Measure(void) { /*########################################################################################################################* *-----------------------------------------------------Directory/File------------------------------------------------------* *#########################################################################################################################*/ -void Directory_GetCachePath(cc_string* path) { } - extern int __path_absolute(const char *in, char *out, int len); static void GetNativePath(char* str, const cc_string* path) { char tmp[NATIVE_STR_LEN + 1]; @@ -430,111 +404,13 @@ cc_result Socket_CheckWritable(cc_socket s, cc_bool* writable) { /*########################################################################################################################* -*-----------------------------------------------------Process/Module------------------------------------------------------* +*--------------------------------------------------------Platform---------------------------------------------------------* *#########################################################################################################################*/ -static char gameArgs[GAME_MAX_CMDARGS][STRING_SIZE]; -static int gameNumArgs; -static cc_bool gameHasArgs; - -cc_result Process_StartGame2(const cc_string* args, int numArgs) { - for (int i = 0; i < numArgs; i++) - { - String_CopyToRawArray(gameArgs[i], &args[i]); - } - - Platform_LogConst("START GAME"); - gameHasArgs = true; - gameNumArgs = numArgs; - return 0; -} - -static int GetGameArgs(cc_string* args) { - int count = gameNumArgs; - for (int i = 0; i < count; i++) - { - args[i] = String_FromRawArray(gameArgs[i]); - } - - // clear arguments so after game is closed, launcher is started - gameNumArgs = 0; - return count; -} - -int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) { - if (gameHasArgs) return GetGameArgs(args); - // PSP *sometimes* doesn't use argv[0] for program name and so argc will be 0 - if (!argc) return 0; - - argc--; argv++; // skip executable path argument - - int count = min(argc, GAME_MAX_CMDARGS); - Platform_Log1("ARGS: %i", &count); - - for (int i = 0; i < count; i++) - { - args[i] = String_FromReadonly(argv[i]); - Platform_Log2(" ARG %i = %c", &i, argv[i]); - } - return count; -} - -cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) { - return 0; // TODO switch to RomFS ?? -} - -void Process_Exit(cc_result code) { exit(code); } - cc_result Process_StartOpen(const cc_string* args) { return ERR_NOT_SUPPORTED; } - -/*########################################################################################################################* -*--------------------------------------------------------Updater----------------------------------------------------------* -*#########################################################################################################################*/ -const char* const Updater_D3D9 = NULL; -cc_bool Updater_Clean(void) { return true; } - -const struct UpdaterInfo Updater_Info = { "&eCompile latest source code to update", 0 }; - -cc_result Updater_Start(const char** action) { - *action = "Starting game"; - return ERR_NOT_SUPPORTED; -} - -cc_result Updater_GetBuildTime(cc_uint64* timestamp) { - return ERR_NOT_SUPPORTED; -} - -cc_result Updater_MarkExecutable(void) { - return ERR_NOT_SUPPORTED; -} - -cc_result Updater_SetNewBuildTime(cc_uint64 timestamp) { - return ERR_NOT_SUPPORTED; -} - - -/*########################################################################################################################* -*-------------------------------------------------------Dynamic lib-------------------------------------------------------* -*#########################################################################################################################*/ -/* TODO can this actually be supported somehow */ -const cc_string DynamicLib_Ext = String_FromConst(".so"); - -void* DynamicLib_Load2(const cc_string* path) { return NULL; } -void* DynamicLib_Get2(void* lib, const char* name) { return NULL; } - -cc_bool DynamicLib_DescribeError(cc_string* dst) { - String_AppendConst(dst, "Dynamic linking unsupported"); - return true; -} - - -/*########################################################################################################################* -*--------------------------------------------------------Platform---------------------------------------------------------* -*#########################################################################################################################*/ void Platform_Init(void) { - Platform_SingleProcess = true; /*pspDebugSioInit();*/ } void Platform_Free(void) { } @@ -563,6 +439,7 @@ cc_bool Platform_DescribeError(cc_result res, cc_string* dst) { cc_result Platform_Encrypt(const void* data, int len, cc_string* dst) { return ERR_NOT_SUPPORTED; } + cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) { return ERR_NOT_SUPPORTED; } diff --git a/src/Platform_PSVita.c b/src/Platform_PSVita.c index 9867f54b1..8eaf22629 100644 --- a/src/Platform_PSVita.c +++ b/src/Platform_PSVita.c @@ -1,6 +1,5 @@ #include "Core.h" #if defined CC_BUILD_PSVITA - #include "_PlatformBase.h" #include "Stream.h" #include "ExtMath.h" @@ -8,10 +7,12 @@ #include "Window.h" #include "Utils.h" #include "Errors.h" + #include #include #include #include +#include "_PlatformConsole.h" const cc_result ReturnCode_FileShareViolation = 1000000000; // not used const cc_result ReturnCode_FileNotFound = ENOENT; @@ -22,31 +23,6 @@ const char* Platform_AppNameSuffix = " PS Vita"; static int epoll_id; -/*########################################################################################################################* -*---------------------------------------------------------Memory----------------------------------------------------------* -*#########################################################################################################################*/ -void Mem_Set(void* dst, cc_uint8 value, cc_uint32 numBytes) { memset(dst, value, numBytes); } -void Mem_Copy(void* dst, const void* src, cc_uint32 numBytes) { memcpy(dst, src, numBytes); } - -void* Mem_TryAlloc(cc_uint32 numElems, cc_uint32 elemsSize) { - cc_uint32 size = CalcMemSize(numElems, elemsSize); - return size ? malloc(size) : NULL; -} - -void* Mem_TryAllocCleared(cc_uint32 numElems, cc_uint32 elemsSize) { - return calloc(numElems, elemsSize); -} - -void* Mem_TryRealloc(void* mem, cc_uint32 numElems, cc_uint32 elemsSize) { - cc_uint32 size = CalcMemSize(numElems, elemsSize); - return size ? realloc(mem, size) : NULL; -} - -void Mem_Free(void* mem) { - if (mem) free(mem); -} - - /*########################################################################################################################* *------------------------------------------------------Logging/Time-------------------------------------------------------* *#########################################################################################################################*/ @@ -98,13 +74,11 @@ cc_uint64 Stopwatch_Measure(void) { /*########################################################################################################################* *-----------------------------------------------------Directory/File------------------------------------------------------* *#########################################################################################################################*/ -void Directory_GetCachePath(cc_string* path) { } +static const cc_string root_path = String_FromConst("ux0:data/ClassiCube/"); -extern int __path_absolute(const char *in, char *out, int len); static void GetNativePath(char* str, const cc_string* path) { - static const char root_path[20] = "ux0:data/ClassiCube/"; - Mem_Copy(str, root_path, sizeof(root_path)); - str += sizeof(root_path); + Mem_Copy(str, root_path.buffer, root_path.length); + str += root_path.length; String_EncodeUtf8(str, path); } @@ -416,111 +390,13 @@ cc_result Socket_CheckWritable(cc_socket s, cc_bool* writable) { /*########################################################################################################################* -*-----------------------------------------------------Process/Module------------------------------------------------------* +*--------------------------------------------------------Platform---------------------------------------------------------* *#########################################################################################################################*/ -static char gameArgs[GAME_MAX_CMDARGS][STRING_SIZE]; -static int gameNumArgs; -static cc_bool gameHasArgs; - -cc_result Process_StartGame2(const cc_string* args, int numArgs) { - for (int i = 0; i < numArgs; i++) - { - String_CopyToRawArray(gameArgs[i], &args[i]); - } - - Platform_LogConst("START GAME"); - gameHasArgs = true; - gameNumArgs = numArgs; - return 0; -} - -static int GetGameArgs(cc_string* args) { - int count = gameNumArgs; - for (int i = 0; i < count; i++) - { - args[i] = String_FromRawArray(gameArgs[i]); - } - - // clear arguments so after game is closed, launcher is started - gameNumArgs = 0; - return count; -} - -int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) { - if (gameHasArgs) return GetGameArgs(args); - // PS VITA *sometimes* doesn't use argv[0] for program name and so argc will be 0 - if (!argc) return 0; - - argc--; argv++; // skip executable path argument - - int count = min(argc, GAME_MAX_CMDARGS); - Platform_Log1("ARGS: %i", &count); - - for (int i = 0; i < count; i++) - { - args[i] = String_FromReadonly(argv[i]); - Platform_Log2(" ARG %i = %c", &i, argv[i]); - } - return count; -} - -cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) { - return 0; // TODO switch to RomFS ?? -} - -void Process_Exit(cc_result code) { exit(code); } - cc_result Process_StartOpen(const cc_string* args) { return ERR_NOT_SUPPORTED; } - -/*########################################################################################################################* -*--------------------------------------------------------Updater----------------------------------------------------------* -*#########################################################################################################################*/ -const char* const Updater_D3D9 = NULL; -cc_bool Updater_Clean(void) { return true; } - -const struct UpdaterInfo Updater_Info = { "&eCompile latest source code to update", 0 }; - -cc_result Updater_Start(const char** action) { - *action = "Starting game"; - return ERR_NOT_SUPPORTED; -} - -cc_result Updater_GetBuildTime(cc_uint64* timestamp) { - return ERR_NOT_SUPPORTED; -} - -cc_result Updater_MarkExecutable(void) { - return ERR_NOT_SUPPORTED; -} - -cc_result Updater_SetNewBuildTime(cc_uint64 timestamp) { - return ERR_NOT_SUPPORTED; -} - - -/*########################################################################################################################* -*-------------------------------------------------------Dynamic lib-------------------------------------------------------* -*#########################################################################################################################*/ -/* TODO can this actually be supported somehow */ -const cc_string DynamicLib_Ext = String_FromConst(".so"); - -void* DynamicLib_Load2(const cc_string* path) { return NULL; } -void* DynamicLib_Get2(void* lib, const char* name) { return NULL; } - -cc_bool DynamicLib_DescribeError(cc_string* dst) { - String_AppendConst(dst, "Dynamic linking unsupported"); - return true; -} - - -/*########################################################################################################################* -*--------------------------------------------------------Platform---------------------------------------------------------* -*#########################################################################################################################*/ void Platform_Init(void) { - Platform_SingleProcess = true; /*pspDebugSioInit();*/ // TODO: sceNetInit(); epoll_id = sceNetEpollCreate("CC poll", 0); @@ -551,6 +427,7 @@ cc_bool Platform_DescribeError(cc_result res, cc_string* dst) { cc_result Platform_Encrypt(const void* data, int len, cc_string* dst) { return ERR_NOT_SUPPORTED; } + cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) { return ERR_NOT_SUPPORTED; } diff --git a/src/Platform_Posix.c b/src/Platform_Posix.c index 6e8133d34..36810fe39 100644 --- a/src/Platform_Posix.c +++ b/src/Platform_Posix.c @@ -43,6 +43,7 @@ const char* Platform_AppNameSuffix = " iOS alpha"; #else const char* Platform_AppNameSuffix = ""; #endif +cc_bool Platform_SingleProcess; /* Operating system specific include files */ #if defined CC_BUILD_DARWIN diff --git a/src/Platform_Web.c b/src/Platform_Web.c index d5e83c037..060023ed2 100644 --- a/src/Platform_Web.c +++ b/src/Platform_Web.c @@ -37,6 +37,7 @@ const cc_result ReturnCode_SocketInProgess = _EINPROGRESS; const cc_result ReturnCode_SocketWouldBlock = _EAGAIN; const cc_result ReturnCode_DirectoryExists = _EEXIST; const char* Platform_AppNameSuffix = ""; +cc_bool Platform_SingleProcess; /*########################################################################################################################* diff --git a/src/Platform_WinApi.c b/src/Platform_WinApi.c index 1b8bd9620..ba5e02595 100644 --- a/src/Platform_WinApi.c +++ b/src/Platform_WinApi.c @@ -38,6 +38,7 @@ const cc_result ReturnCode_SocketInProgess = WSAEINPROGRESS; const cc_result ReturnCode_SocketWouldBlock = WSAEWOULDBLOCK; const cc_result ReturnCode_DirectoryExists = ERROR_ALREADY_EXISTS; const char* Platform_AppNameSuffix = ""; +cc_bool Platform_SingleProcess; /*########################################################################################################################* *---------------------------------------------------------Memory----------------------------------------------------------* diff --git a/src/Platform_Xbox.c b/src/Platform_Xbox.c index 039b21b81..6b5d00dd0 100644 --- a/src/Platform_Xbox.c +++ b/src/Platform_Xbox.c @@ -14,6 +14,7 @@ #include #include #include +#include "_PlatformConsole.h" static HANDLE heap; const cc_result ReturnCode_FileShareViolation = ERROR_SHARING_VIOLATION; @@ -23,30 +24,6 @@ const cc_result ReturnCode_SocketWouldBlock = WSAEWOULDBLOCK; const cc_result ReturnCode_DirectoryExists = ERROR_ALREADY_EXISTS; const char* Platform_AppNameSuffix = " XBox"; -/*########################################################################################################################* -*---------------------------------------------------------Memory----------------------------------------------------------* -*#########################################################################################################################*/ -void Mem_Set(void* dst, cc_uint8 value, cc_uint32 numBytes) { memset(dst, value, numBytes); } -void Mem_Copy(void* dst, const void* src, cc_uint32 numBytes) { memcpy(dst, src, numBytes); } - -void* Mem_TryAlloc(cc_uint32 numElems, cc_uint32 elemsSize) { - cc_uint32 size = CalcMemSize(numElems, elemsSize); - return size ? malloc(size) : NULL; -} - -void* Mem_TryAllocCleared(cc_uint32 numElems, cc_uint32 elemsSize) { - return calloc(numElems, elemsSize); -} - -void* Mem_TryRealloc(void* mem, cc_uint32 numElems, cc_uint32 elemsSize) { - cc_uint32 size = CalcMemSize(numElems, elemsSize); - return size ? realloc(mem, size) : NULL; -} - -void Mem_Free(void* mem) { - if (mem) free(mem); -} - /*########################################################################################################################* *------------------------------------------------------Logging/Time-------------------------------------------------------* @@ -95,7 +72,7 @@ cc_uint64 Stopwatch_Measure(void) { return KeQueryPerformanceCounter(); } -static void Platform_InitStopwatch(void) { +static void Stopwatch_Init(void) { ULONGLONG freq = KeQueryPerformanceFrequency(); sw_freqMul = 1000 * 1000; @@ -106,11 +83,7 @@ static void Platform_InitStopwatch(void) { /*########################################################################################################################* *-----------------------------------------------------Directory/File------------------------------------------------------* *#########################################################################################################################*/ -void Directory_GetCachePath(cc_string* path) { } - static void GetNativePath(char* str, const cc_string* src) { - if (src->length > FILENAME_SIZE) Logger_Abort("String too long to expand"); - for (int i = 0; i < src->length; i++) { *str++ = (char)src->buffer[i]; @@ -301,12 +274,6 @@ void Waitable_WaitFor(void* handle, cc_uint32 milliseconds) { } -/*########################################################################################################################* -*--------------------------------------------------------Font/Text--------------------------------------------------------* -*#########################################################################################################################*/ -void Platform_LoadSysFonts(void) { } - - /*########################################################################################################################* *---------------------------------------------------------Socket----------------------------------------------------------* *#########################################################################################################################*/ @@ -425,103 +392,14 @@ cc_result Socket_CheckWritable(cc_socket s, cc_bool* writable) { /*########################################################################################################################* -*-----------------------------------------------------Process/Module------------------------------------------------------* +*--------------------------------------------------------Platform---------------------------------------------------------* *#########################################################################################################################*/ -static char gameArgs[GAME_MAX_CMDARGS][STRING_SIZE]; -static int gameNumArgs; -static cc_bool gameHasArgs; - -cc_result Process_StartGame2(const cc_string* args, int numArgs) { - for (int i = 0; i < numArgs; i++) - { - String_CopyToRawArray(gameArgs[i], &args[i]); - } - - Platform_LogConst("START GAME"); - gameHasArgs = true; - gameNumArgs = numArgs; - return 0; -} - -static int GetGameArgs(cc_string* args) { - int count = gameNumArgs; - for (int i = 0; i < count; i++) - { - args[i] = String_FromRawArray(gameArgs[i]); - } - - // clear arguments so after game is closed, launcher is started - gameNumArgs = 0; - return count; -} - -int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) { - if (gameHasArgs) return GetGameArgs(args); - // 3DS *sometimes* doesn't use argv[0] for program name and so argc will be 0 - // (e.g. when running from Citra) - if (!argc) return 0; - - argc--; argv++; // skip executable path argument - - int count = min(argc, GAME_MAX_CMDARGS); - Platform_Log1("ARGS: %i", &count); - - for (int i = 0; i < count; i++) { - args[i] = String_FromReadonly(argv[i]); - Platform_Log2(" ARG %i = %c", &i, argv[i]); - } - return count; -} - -cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) { - return 0; -} - -void Process_Exit(cc_result code) { exit(code); } - cc_result Process_StartOpen(const cc_string* args) { return ERR_NOT_SUPPORTED; } - -/*########################################################################################################################* -*--------------------------------------------------------Updater----------------------------------------------------------* -*#########################################################################################################################*/ -const char* const Updater_D3D9 = NULL; -cc_bool Updater_Clean(void) { return true; } - -const struct UpdaterInfo Updater_Info = { "&eCompile latest source code to update", 0 }; - -cc_result Updater_Start(const char** action) { *action = "Starting"; return ERR_NOT_SUPPORTED; } - -cc_result Updater_GetBuildTime(cc_uint64* timestamp) { return ERR_NOT_SUPPORTED; } - -cc_result Updater_MarkExecutable(void) { return ERR_NOT_SUPPORTED; } - -cc_result Updater_SetNewBuildTime(cc_uint64 timestamp) { return ERR_NOT_SUPPORTED; } - - -/*########################################################################################################################* -*-------------------------------------------------------Dynamic lib-------------------------------------------------------* -*#########################################################################################################################*/ -const cc_string DynamicLib_Ext = String_FromConst(".so"); - -void* DynamicLib_Load2(const cc_string* path) { return NULL; } - -void* DynamicLib_Get2(void* lib, const char* name) { return NULL; } - -cc_bool DynamicLib_DescribeError(cc_string* dst) { - String_AppendConst(dst, "Dynamic linking unsupported"); - return true; -} - - -/*########################################################################################################################* -*--------------------------------------------------------Platform---------------------------------------------------------* -*#########################################################################################################################*/ void Platform_Init(void) { - Platform_SingleProcess = true; - Platform_InitStopwatch(); + Stopwatch_Init(); nxNetInit(NULL); } diff --git a/src/Window_PSP.c b/src/Window_PSP.c index 3e9c8c631..ecd03b917 100644 --- a/src/Window_PSP.c +++ b/src/Window_PSP.c @@ -19,6 +19,12 @@ #define SCREEN_HEIGHT 272 static cc_bool launcherMode; +struct _DisplayData DisplayInfo; +struct _WinData WindowInfo; +// no DPI scaling on Wii/GameCube +int Display_ScaleX(int x) { return x; } +int Display_ScaleY(int y) { return y; } + void Window_Init(void) { DisplayInfo.Width = SCREEN_WIDTH; DisplayInfo.Height = SCREEN_HEIGHT; diff --git a/src/_PlatformBase.h b/src/_PlatformBase.h index be6c1fe4d..92432da28 100644 --- a/src/_PlatformBase.h +++ b/src/_PlatformBase.h @@ -2,7 +2,6 @@ #include "String.h" #include "Logger.h" #include "Constants.h" -cc_bool Platform_SingleProcess; /*########################################################################################################################* *---------------------------------------------------------Memory----------------------------------------------------------* diff --git a/src/_PlatformConsole.h b/src/_PlatformConsole.h new file mode 100644 index 000000000..298c22b45 --- /dev/null +++ b/src/_PlatformConsole.h @@ -0,0 +1,124 @@ +cc_bool Platform_SingleProcess = true; + + +/*########################################################################################################################* +*---------------------------------------------------------Memory----------------------------------------------------------* +*#########################################################################################################################*/ +void Mem_Set(void* dst, cc_uint8 value, cc_uint32 numBytes) { memset(dst, value, numBytes); } +void Mem_Copy(void* dst, const void* src, cc_uint32 numBytes) { memcpy(dst, src, numBytes); } + +void* Mem_TryAlloc(cc_uint32 numElems, cc_uint32 elemsSize) { + cc_uint32 size = CalcMemSize(numElems, elemsSize); + return size ? malloc(size) : NULL; +} + +void* Mem_TryAllocCleared(cc_uint32 numElems, cc_uint32 elemsSize) { + return calloc(numElems, elemsSize); +} + +void* Mem_TryRealloc(void* mem, cc_uint32 numElems, cc_uint32 elemsSize) { + cc_uint32 size = CalcMemSize(numElems, elemsSize); + return size ? realloc(mem, size) : NULL; +} + +void Mem_Free(void* mem) { + if (mem) free(mem); +} + + +/*########################################################################################################################* +*-----------------------------------------------------Directory/File------------------------------------------------------* +*#########################################################################################################################*/ +void Directory_GetCachePath(cc_string* path) { } + + +/*########################################################################################################################* +*-----------------------------------------------------Process/Module------------------------------------------------------* +*#########################################################################################################################*/ +static char gameArgs[GAME_MAX_CMDARGS][STRING_SIZE]; +static int gameNumArgs; +static cc_bool gameHasArgs; + +cc_result Process_StartGame2(const cc_string* args, int numArgs) { + for (int i = 0; i < numArgs; i++) + { + String_CopyToRawArray(gameArgs[i], &args[i]); + } + + Platform_LogConst("START GAME"); + gameHasArgs = true; + gameNumArgs = numArgs; + return 0; +} + +static int GetGameArgs(cc_string* args) { + int count = gameNumArgs; + for (int i = 0; i < count; i++) + { + args[i] = String_FromRawArray(gameArgs[i]); + } + + // clear arguments so after game is closed, launcher is started + gameNumArgs = 0; + return count; +} + +int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) { + if (gameHasArgs) return GetGameArgs(args); + // Consoles *sometimes* doesn't use argv[0] for program name and so argc will be 0 + // (e.g. when running via some emulators) + if (!argc) return 0; + + argc--; argv++; // skip executable path argument + + int count = min(argc, GAME_MAX_CMDARGS); + Platform_Log1("ARGS: %i", &count); + + for (int i = 0; i < count; i++) + { + args[i] = String_FromReadonly(argv[i]); + Platform_Log2(" ARG %i = %c", &i, argv[i]); + } + return count; +} + +cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) { + return 0; +} + +void Process_Exit(cc_result code) { exit(code); } + + +/*########################################################################################################################* +*--------------------------------------------------------Updater----------------------------------------------------------* +*#########################################################################################################################*/ +const char* const Updater_D3D9 = NULL; +cc_bool Updater_Clean(void) { return true; } + +const struct UpdaterInfo Updater_Info = { "&eCompile latest source code to update", 0 }; + +cc_result Updater_Start(const char** action) { + *action = "Starting game"; + return ERR_NOT_SUPPORTED; +} + +cc_result Updater_GetBuildTime(cc_uint64* timestamp) { return ERR_NOT_SUPPORTED; } + +cc_result Updater_MarkExecutable(void) { return ERR_NOT_SUPPORTED; } + +cc_result Updater_SetNewBuildTime(cc_uint64 timestamp) { return ERR_NOT_SUPPORTED; } + + +/*########################################################################################################################* +*-------------------------------------------------------Dynamic lib-------------------------------------------------------* +*#########################################################################################################################*/ +/* TODO can this actually be supported somehow */ +const cc_string DynamicLib_Ext = String_FromConst(".so"); + +void* DynamicLib_Load2(const cc_string* path) { return NULL; } +void* DynamicLib_Get2(void* lib, const char* name) { return NULL; } + +cc_bool DynamicLib_DescribeError(cc_string* dst) { + String_AppendConst(dst, "Dynamic linking unsupported"); + return true; +}