diff --git a/game/overlord/jak2/streamlist.cpp b/game/overlord/jak2/streamlist.cpp index f6dd7614d8..e74cba7fe9 100644 --- a/game/overlord/jak2/streamlist.cpp +++ b/game/overlord/jak2/streamlist.cpp @@ -407,15 +407,20 @@ u32 StreamListThread() { } uVar9 = uVar9 + 1; } while (uVar9 < 4); + SignalSema(EEStreamsList.sema); RequestedStreamsList.unk2_init0 = 1; SignalSema(RequestedStreamsList.sema); + WaitSema(EEPlayList.sema); CheckPlayList(&EEPlayList); SignalSema(EEPlayList.sema); - WaitSema(LfoList.sema); - CheckLfoList(&LfoList); - SignalSema(LfoList.sema); + + // FIXME LfoList hasn't been initialised because of unimplemented + // streamlfo functions. + // WaitSema(LfoList.sema); + // CheckLfoList(&LfoList); + // SignalSema(LfoList.sema); } while (true); return 0; } diff --git a/game/system/IOP_Kernel.cpp b/game/system/IOP_Kernel.cpp index 56b8d663ff..149c1f4d7c 100644 --- a/game/system/IOP_Kernel.cpp +++ b/game/system/IOP_Kernel.cpp @@ -101,7 +101,14 @@ void IOP_Kernel::DelayThread(u32 usec) { void IOP_Kernel::SleepThread() { ASSERT(_currentThread); - _currentThread->state = IopThread::State::Suspend; + if (_currentThread->wakeupCount > 0) { + _currentThread->wakeupCount--; + return; + } + + _currentThread->state = IopThread::State::Wait; + _currentThread->waitType = IopThread::Wait::Sleep; + leaveThread(); } @@ -116,6 +123,13 @@ void IOP_Kernel::YieldThread() { */ void IOP_Kernel::WakeupThread(s32 id) { ASSERT(id > 0); + + auto& thread = threads.at(id); + if (thread.state != IopThread::State::Wait || thread.waitType != IopThread::Wait::Sleep) { + thread.wakeupCount++; + return; + } + threads.at(id).state = IopThread::State::Ready; } diff --git a/game/system/IOP_Kernel.h b/game/system/IOP_Kernel.h index 3409d639a9..065c7caa53 100644 --- a/game/system/IOP_Kernel.h +++ b/game/system/IOP_Kernel.h @@ -53,7 +53,7 @@ struct IopThread { Dormant, }; - enum class Wait { None, Semaphore, Delay, Messagebox, EventFlag }; + enum class Wait { None, Sleep, Semaphore, Delay, Messagebox, EventFlag }; IopThread(std::string n, void (*f)(), s32 ID, u32 pri) : name(std::move(n)), function(f), priority(pri), thID(ID) { @@ -71,6 +71,7 @@ struct IopThread { time_stamp resumeTime = {}; u32 priority = 0; s32 thID = -1; + s32 wakeupCount = 0; }; struct Semaphore {