Move common platform console to _PlatformConsole.h

This commit is contained in:
UnknownShadow200 2023-08-13 11:32:01 +10:00
parent b5acd75c3e
commit ffee69ffa1
14 changed files with 169 additions and 770 deletions

View File

@ -441,6 +441,7 @@
<ClInclude Include="_GraphicsBase.h" />
<ClInclude Include="_HttpBase.h" />
<ClInclude Include="_PlatformBase.h" />
<ClInclude Include="_PlatformConsole.h" />
<ClInclude Include="_WindowBase.h" />
</ItemGroup>
<ItemGroup>

View File

@ -339,6 +339,9 @@
<ClInclude Include="SSL.h">
<Filter>Header Files\Network</Filter>
</ClInclude>
<ClInclude Include="_PlatformConsole.h">
<Filter>Header Files\Platform</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="String.c">

View File

@ -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 <errno.h>
#include <time.h>
#include <stdlib.h>
@ -27,6 +27,7 @@
#include <netdb.h>
#include <3ds.h>
#include <citro3d.h>
#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
#endif

View File

@ -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 <errno.h>
#include <netdb.h>
#include <stdlib.h>
@ -18,6 +18,7 @@
#include <poll.h>
#include <time.h>
#include <kos.h>
#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
#endif

View File

@ -8,6 +8,7 @@
#include "Utils.h"
#include "Errors.h"
#include "PackedCol.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>
@ -24,6 +25,7 @@
#ifdef HW_RVL
#include <ogc/wiilaunch.h>
#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
#endif

View File

@ -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 <errno.h>
#include <stdlib.h>
#include <string.h>
@ -16,6 +16,7 @@
#include <pspnet_inet.h>
#include <pspnet_resolver.h>
#include <psprtc.h>
#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;
}

View File

@ -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 <errno.h>
#include <stdlib.h>
#include <string.h>
#include <vitasdk.h>
#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;
}

View File

@ -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

View File

@ -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;
/*########################################################################################################################*

View File

@ -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----------------------------------------------------------*

View File

@ -14,6 +14,7 @@
#include <lwip/netdb.h>
#include <lwip/sockets.h>
#include <nxdk/net.h>
#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);
}

View File

@ -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;

View File

@ -2,7 +2,6 @@
#include "String.h"
#include "Logger.h"
#include "Constants.h"
cc_bool Platform_SingleProcess;
/*########################################################################################################################*
*---------------------------------------------------------Memory----------------------------------------------------------*

124
src/_PlatformConsole.h Normal file
View File

@ -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;
}