summary refs log tree commit diff
path: root/src/Platform_PS1.c
diff options
context:
space:
mode:
authorWlodekM <[email protected]>2024-06-16 10:35:45 +0300
committerWlodekM <[email protected]>2024-06-16 10:35:45 +0300
commitabef6da56913f1c55528103e60a50451a39628b1 (patch)
treeb3c8092471ecbb73e568cd0d336efa0e7871ee8d /src/Platform_PS1.c
initial commit
Diffstat (limited to 'src/Platform_PS1.c')
-rw-r--r--src/Platform_PS1.c250
1 files changed, 250 insertions, 0 deletions
diff --git a/src/Platform_PS1.c b/src/Platform_PS1.c
new file mode 100644
index 0000000..02316d5
--- /dev/null
+++ b/src/Platform_PS1.c
@@ -0,0 +1,250 @@
+#include "Core.h"
+#if defined PLAT_PS1
+
+#include "_PlatformBase.h"
+#include "Stream.h"
+#include "ExtMath.h"
+#include "Funcs.h"
+#include "Window.h"
+#include "Utils.h"
+#include "Errors.h"
+#include "Options.h"
+#include "PackedCol.h"
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <psxetc.h>
+#include <psxapi.h>
+#include <psxgpu.h>
+#include <hwregs_c.h>
+void exit(int code) { _boot(); }
+
+// The SDK calloc doesn't zero memory, so need to override it
+void* calloc(size_t num, size_t size) {
+	void* ptr = malloc(num * size);
+	if (ptr) memset(ptr, 0, num * size);
+	return ptr;
+}
+#include "_PlatformConsole.h"
+
+const cc_result ReturnCode_FileShareViolation = 1000000000; // not used
+const cc_result ReturnCode_FileNotFound       = 99999;
+const cc_result ReturnCode_DirectoryExists    = 99999;
+
+const cc_result ReturnCode_SocketInProgess  = -1;
+const cc_result ReturnCode_SocketWouldBlock = -1;
+const char* Platform_AppNameSuffix = " PS1";
+
+
+/*########################################################################################################################*
+*------------------------------------------------------Logging/Time-------------------------------------------------------*
+*#########################################################################################################################*/
+void Platform_Log(const char* msg, int len) {
+	char tmp[2048 + 1];
+	len = min(len, 2048);
+	Mem_Copy(tmp, msg, len); tmp[len] = '\0';
+	
+	printf("%s\n", tmp);
+}
+
+TimeMS DateTime_CurrentUTC(void) {
+	return 0;
+}
+
+void DateTime_CurrentLocal(struct DateTime* t) {
+	Mem_Set(t, 0, sizeof(struct DateTime));
+}
+
+
+/*########################################################################################################################*
+*--------------------------------------------------------Stopwatch--------------------------------------------------------*
+*#########################################################################################################################*/
+static volatile cc_uint32 irq_count;
+
+cc_uint64 Stopwatch_Measure(void) {
+	return irq_count;
+}
+
+cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) {
+	if (end < beg) return 0;
+	return (end - beg) * 1000;
+}
+
+static void timer2_handler(void) { irq_count++; }
+
+static void Stopwatch_Init(void) {
+	TIMER_CTRL(2)	= 0x0258;				// CLK/8 input, IRQ on reload
+	TIMER_RELOAD(2)	= (F_CPU / 8) / 1000;	// 1000 Hz
+
+	EnterCriticalSection();
+	InterruptCallback(IRQ_TIMER2, &timer2_handler);
+	ExitCriticalSection();
+}
+
+
+/*########################################################################################################################*
+*-----------------------------------------------------Directory/File------------------------------------------------------*
+*#########################################################################################################################*/
+static const cc_string root_path = String_FromConst("cdrom:/");
+
+static void GetNativePath(char* str, const cc_string* path) {
+	Mem_Copy(str, root_path.buffer, root_path.length);
+	str += root_path.length;
+	String_EncodeUtf8(str, path);
+}
+
+cc_result Directory_Create(const cc_string* path) {
+	return ERR_NOT_SUPPORTED;
+}
+
+int File_Exists(const cc_string* path) {
+	return ERR_NOT_SUPPORTED;
+}
+
+cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {
+	return ERR_NOT_SUPPORTED;
+}
+
+cc_result File_Open(cc_file* file, const cc_string* path) {
+	return ERR_NOT_SUPPORTED;
+}
+
+cc_result File_Create(cc_file* file, const cc_string* path) {
+	return ERR_NOT_SUPPORTED;
+}
+
+cc_result File_OpenOrCreate(cc_file* file, const cc_string* path) {
+	return ERR_NOT_SUPPORTED;
+}
+
+cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
+	return ERR_NOT_SUPPORTED;
+}
+
+cc_result File_Write(cc_file file, const void* data, cc_uint32 count, cc_uint32* bytesWrote) {
+	return ERR_NOT_SUPPORTED;
+}
+
+cc_result File_Close(cc_file file) {
+	return ERR_NOT_SUPPORTED;
+}
+
+cc_result File_Seek(cc_file file, int offset, int seekType) {	
+	return ERR_NOT_SUPPORTED;
+}
+
+cc_result File_Position(cc_file file, cc_uint32* pos) {
+	return ERR_NOT_SUPPORTED;
+}
+
+cc_result File_Length(cc_file file, cc_uint32* len) {
+	return ERR_NOT_SUPPORTED;
+}
+
+
+/*########################################################################################################################*
+*--------------------------------------------------------Threading--------------------------------------------------------*
+*#########################################################################################################################*/
+void Thread_Sleep(cc_uint32 milliseconds) {
+	// TODO sleep a bit
+	VSync(0);
+}
+
+void Thread_Run(void** handle, Thread_StartFunc func, int stackSize, const char* name) {
+	*handle = NULL;
+}
+
+void Thread_Detach(void* handle) {
+}
+
+void Thread_Join(void* handle) {
+}
+
+void* Mutex_Create(const char* name) {
+	return NULL;
+}
+
+void Mutex_Free(void* handle) {
+}
+
+void Mutex_Lock(void* handle) {
+}
+
+void Mutex_Unlock(void* handle) {
+}
+
+void* Waitable_Create(const char* name) {
+	return NULL;
+}
+
+void Waitable_Free(void* handle) {
+}
+
+void Waitable_Signal(void* handle) {
+}
+
+void Waitable_Wait(void* handle) {
+}
+
+void Waitable_WaitFor(void* handle, cc_uint32 milliseconds) {
+}
+
+
+/*########################################################################################################################*
+*---------------------------------------------------------Socket----------------------------------------------------------*
+*#########################################################################################################################*/
+cc_result Socket_ParseAddress(const cc_string* address, int port, cc_sockaddr* addrs, int* numValidAddrs) {
+	return ERR_NOT_SUPPORTED;
+}
+
+cc_result Socket_Connect(cc_socket* s, cc_sockaddr* addr, cc_bool nonblocking) {
+	return ERR_NOT_SUPPORTED;
+}
+
+cc_result Socket_Read(cc_socket s, cc_uint8* data, cc_uint32 count, cc_uint32* modified) {
+	return ERR_NOT_SUPPORTED;
+}
+
+cc_result Socket_Write(cc_socket s, const cc_uint8* data, cc_uint32 count, cc_uint32* modified) {
+	return ERR_NOT_SUPPORTED;
+}
+
+void Socket_Close(cc_socket s) {
+}
+
+cc_result Socket_CheckReadable(cc_socket s, cc_bool* readable) {
+	return ERR_NOT_SUPPORTED;
+}
+
+cc_result Socket_CheckWritable(cc_socket s, cc_bool* writable) {
+	return ERR_NOT_SUPPORTED;
+}
+
+
+/*########################################################################################################################*
+*--------------------------------------------------------Platform---------------------------------------------------------*
+*#########################################################################################################################*/
+void Platform_Init(void) {
+	ResetGraph(0);
+	Stopwatch_Init();
+}
+
+void Platform_Free(void) { }
+
+cc_bool Platform_DescribeError(cc_result res, cc_string* dst) {
+	return false;
+}
+
+cc_bool Process_OpenSupported = false;
+cc_result Process_StartOpen(const cc_string* args) {
+	return ERR_NOT_SUPPORTED;
+}
+
+
+/*########################################################################################################################*
+*-------------------------------------------------------Encryption--------------------------------------------------------*
+*#########################################################################################################################*/
+static cc_result GetMachineID(cc_uint32* key) {
+	return ERR_NOT_SUPPORTED;
+}
+#endif