From 9fe592e83a030b5f828f2a6235d04b3ffeb9c516 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sat, 5 Jan 2013 23:24:05 +0100 Subject: [PATCH] Implement sceKernelDelaySysClockThreadCB --- Core/HLE/sceKernel.cpp | 4 ++-- Core/HLE/sceKernelThread.cpp | 43 +++++++++++++++++++++++++++++++++++- Core/HLE/sceKernelThread.h | 4 +++- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp index d5414d95f6..a3f167b824 100644 --- a/Core/HLE/sceKernel.cpp +++ b/Core/HLE/sceKernel.cpp @@ -523,8 +523,8 @@ const HLEFunction ThreadManForUser[] = {0x71bc9871,sceKernelChangeThreadPriority,"sceKernelChangeThreadPriority"}, {0x446D8DE6,WrapI_CUUIUU,"sceKernelCreateThread"}, {0x9fa03cd3,WrapI_I,"sceKernelDeleteThread"}, - {0xBD123D9E,0,"sceKernelDelaySysClockThread"}, - {0x1181E963,0,"sceKernelDelaySysClockThreadCB"}, + {0xBD123D9E,sceKernelDelaySysClockThread,"sceKernelDelaySysClockThread"}, + {0x1181E963,sceKernelDelaySysClockThreadCB,"sceKernelDelaySysClockThreadCB"}, {0xceadeb47,sceKernelDelayThread,"sceKernelDelayThread"}, {0x68da9e36,sceKernelDelayThreadCB,"sceKernelDelayThreadCB"}, {0xaa73c935,sceKernelExitThread,"sceKernelExitThread"}, diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index 9679199f3a..f53cc6f764 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -1051,7 +1051,7 @@ void hleScheduledWakeup(u64 userdata, int cyclesLate) __KernelTriggerWait(WAITTYPE_DELAY, threadID, true); } -void __KernelScheduleWakeup(SceUID threadID, int usFromNow) +void __KernelScheduleWakeup(SceUID threadID, s64 usFromNow) { s64 cycles = usToCycles(usFromNow); CoreTiming::ScheduleEvent(cycles, eventScheduledWakeup, threadID); @@ -1667,6 +1667,47 @@ void sceKernelDelayThread() u32 usec = PARAM(0); if (usec < 200) usec = 200; DEBUG_LOG(HLE,"sceKernelDelayThread(%i usec)",usec); + + SceUID curThread = __KernelGetCurThread(); + __KernelScheduleWakeup(curThread, usec); + __KernelWaitCurThread(WAITTYPE_DELAY, curThread, 0, 0, false); +} + +void sceKernelDelaySysClockThreadCB() +{ + u32 sysclockAddr = PARAM(0); + if (!Memory::IsValidAddress(sysclockAddr)) { + ERROR_LOG(HLE, "sceKernelDelaySysClockThread(%08x) - bad pointer", sysclockAddr); + RETURN(-1); + return; + } + SceKernelSysClock sysclock; + Memory::ReadStruct(sysclockAddr, &sysclock); + + // TODO: Which unit? + u64 usec = sysclock.lo | ((u64)sysclock.hi << 32); + INFO_LOG(HLE, "sceKernelDelaySysClockThread(%08x (%llu))", sysclockAddr, usec); + + SceUID curThread = __KernelGetCurThread(); + __KernelScheduleWakeup(curThread, usec); + __KernelWaitCurThread(WAITTYPE_DELAY, curThread, 0, 0, true); +} + +void sceKernelDelaySysClockThread() +{ + u32 sysclockAddr = PARAM(0); + if (!Memory::IsValidAddress(sysclockAddr)) { + ERROR_LOG(HLE, "sceKernelDelaySysClockThread(%08x) - bad pointer", sysclockAddr); + RETURN(-1); + return; + } + SceKernelSysClock sysclock; + Memory::ReadStruct(sysclockAddr, &sysclock); + + // TODO: Which unit? + u64 usec = sysclock.lo | ((u64)sysclock.hi << 32); + INFO_LOG(HLE, "sceKernelDelaySysClockThread(%08x (%llu))", sysclockAddr, usec); + SceUID curThread = __KernelGetCurThread(); __KernelScheduleWakeup(curThread, usec); __KernelWaitCurThread(WAITTYPE_DELAY, curThread, 0, 0, false); diff --git a/Core/HLE/sceKernelThread.h b/Core/HLE/sceKernelThread.h index 5572ba36bb..bc9b1b05c3 100644 --- a/Core/HLE/sceKernelThread.h +++ b/Core/HLE/sceKernelThread.h @@ -29,6 +29,8 @@ void sceKernelChangeThreadPriority(); int sceKernelCreateThread(const char *threadName, u32 entry, u32 prio, int stacksize, u32 attr, u32 optionAddr); void sceKernelDelayThread(); void sceKernelDelayThreadCB(); +void sceKernelDelaySysClockThread(); +void sceKernelDelaySysClockThreadCB(); int sceKernelDeleteThread(int threadHandle); void sceKernelExitDeleteThread(); void sceKernelExitThread(); @@ -109,7 +111,7 @@ void __KernelThreadingShutdown(); KernelObject *__KernelThreadObject(); KernelObject *__KernelCallbackObject(); -void __KernelScheduleWakeup(int usFromNow, int threadnumber); +void __KernelScheduleWakeup(int threadnumber, s64 usFromNow); SceUID __KernelGetCurThread(); void __KernelSaveContext(ThreadContext *ctx);