diff --git a/LEGO1/omni/include/mxthread.h b/LEGO1/omni/include/mxthread.h index 8afa4454..ba0d89fa 100644 --- a/LEGO1/omni/include/mxthread.h +++ b/LEGO1/omni/include/mxthread.h @@ -5,7 +5,11 @@ #include "mxsemaphore.h" #include "mxtypes.h" +#ifdef PSP +#include +#else #include +#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 diff --git a/LEGO1/omni/src/system/mxthread.cpp b/LEGO1/omni/src/system/mxthread.cpp index 96e64992..6c118d4d 100644 --- a/LEGO1/omni/src/system/mxthread.cpp +++ b/LEGO1/omni/src/system/mxthread.cpp @@ -3,13 +3,20 @@ #include "decomp.h" #include +#ifdef PSP +#include +#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(p_thread)->Run(); } +#endif // FUNCTION: LEGO1 0x100bf690 MxResult MxThread::Run()