Merge pull request #4 from AJenbo/psp

Fix threading and get the game running
This commit is contained in:
VoxelTek 2025-06-26 11:54:40 +10:00 committed by GitHub
commit 209e516a6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 51 additions and 0 deletions

View File

@ -5,7 +5,11 @@
#include "mxsemaphore.h"
#include "mxtypes.h"
#ifdef PSP
#include <pspkerneltypes.h>
#else
#include <SDL3/SDL_thread.h>
#endif
class MxCore;
@ -33,9 +37,15 @@ class MxThread {
virtual ~MxThread();
private:
#ifdef PSP
static int ThreadProc(SceSize args, void* argp);
int m_thread;
#else
static int SDLCALL ThreadProc(void* p_thread);
SDL_Thread* m_thread;
#endif
MxBool m_running; // 0x0c
MxSemaphore m_semaphore; // 0x10

View File

@ -3,13 +3,20 @@
#include "decomp.h"
#include <SDL3/SDL_timer.h>
#ifdef PSP
#include <pspkernel.h>
#endif
DECOMP_SIZE_ASSERT(MxThread, 0x1c)
// FUNCTION: LEGO1 0x100bf510
MxThread::MxThread()
{
#ifdef PSP
m_thread = 0;
#else
m_thread = NULL;
#endif
m_running = TRUE;
}
@ -17,7 +24,13 @@ MxThread::MxThread()
MxThread::~MxThread()
{
if (m_thread) {
#ifdef PSP
sceKernelWaitThreadEnd(m_thread, NULL);
sceKernelDeleteThread(m_thread);
m_thread = 0;
#else
SDL_WaitThread(m_thread, NULL);
#endif
}
}
@ -27,6 +40,25 @@ MxResult MxThread::Start(MxS32 p_stackSize, MxS32 p_flag)
MxResult result = FAILURE;
if (m_semaphore.Init(0, 1) == SUCCESS) {
#ifdef PSP
int thid = sceKernelCreateThread(
"MxThread",
ThreadProc,
0x18, // priority (0x18 is typical)
p_stackSize * 4,
0,
NULL
);
if (thid >= 0) {
MxThread* self = this;
int start = sceKernelStartThread(thid, sizeof(MxThread*), &self);
if (start >= 0) {
result = SUCCESS;
m_thread = thid; // store thread ID if needed
}
}
#else
const SDL_PropertiesID props = SDL_CreateProperties();
SDL_SetPointerProperty(props, SDL_PROP_THREAD_CREATE_ENTRY_FUNCTION_POINTER, (void*) MxThread::ThreadProc);
SDL_SetPointerProperty(props, SDL_PROP_THREAD_CREATE_USERDATA_POINTER, this);
@ -37,6 +69,7 @@ MxResult MxThread::Start(MxS32 p_stackSize, MxS32 p_flag)
}
SDL_DestroyProperties(props);
#endif
}
return result;
@ -55,11 +88,19 @@ void MxThread::Terminate()
m_semaphore.Wait();
}
#ifdef PSP
int MxThread::ThreadProc(SceSize args, void* argp)
{
MxThread* self = *(MxThread**) argp;
return self->Run();
}
#else
// FUNCTION: LEGO1 0x100bf680
int MxThread::ThreadProc(void* p_thread)
{
return static_cast<MxThread*>(p_thread)->Run();
}
#endif
// FUNCTION: LEGO1 0x100bf690
MxResult MxThread::Run()