From bbd7710234c0b0a67541d576284813fa8eb27728 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 22 Dec 2012 21:23:28 -0800 Subject: [PATCH] Implement sceCtrlGetSamplingCycle() freq changes. --- Core/HLE/sceCtrl.cpp | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/Core/HLE/sceCtrl.cpp b/Core/HLE/sceCtrl.cpp index bfce13d43b..19de18d557 100644 --- a/Core/HLE/sceCtrl.cpp +++ b/Core/HLE/sceCtrl.cpp @@ -76,11 +76,13 @@ static CtrlLatch latch; static int ctrlIdleReset = -1; static int ctrlIdleBack = -1; -static u32 ctrlCycle = 0; +static int ctrlCycle = 0; static std::vector waitingThreads; static std::recursive_mutex ctrlMutex; +static int ctrlTimer = -1; + // STATE END ////////////////////////////////////////////////////////////////////////// @@ -208,9 +210,9 @@ int __CtrlReadBuffer(u32 ctrlDataPtr, u32 nBufs, bool negative, bool peek) return done; } -void __CtrlVblank() +void __CtrlDoSample() { - // When in vblank sampling mode, this samples the ctrl data into the buffers and updates the latch. + // This samples the ctrl data into the buffers and updates the latch. __CtrlUpdateLatch(); // Wake up a single thread that was waiting for the buffer. @@ -232,6 +234,22 @@ retry: } } +void __CtrlVblank() +{ + // This always runs, so make sure we're in vblank mode. + if (ctrlCycle == 0) + __CtrlDoSample(); +} + +void __CtrlTimerUpdate(u64 userdata, int cyclesLate) +{ + // This only runs in timer mode (ctrlCycle > 0.) + _dbg_assert_msg_(HLE, ctrlCycle > 0, "Ctrl: sampling cycle should be > 0"); + + __CtrlDoSample(); + CoreTiming::ScheduleEvent(usToCycles(ctrlCycle), ctrlTimer, 0); +} + void __CtrlInit() { std::lock_guard guard(ctrlMutex); @@ -263,11 +281,13 @@ void __CtrlInit() ctrlCycle = 0; waitingThreads.clear(); + + ctrlTimer = CoreTiming::RegisterEvent("CtrlSampleTimer", __CtrlTimerUpdate); } u32 sceCtrlSetSamplingCycle(u32 cycle) { - WARN_LOG(HLE, "FAKE sceCtrlSetSamplingCycle(%u)", cycle); + DEBUG_LOG(HLE, "sceCtrlSetSamplingCycle(%u)", cycle); if ((cycle > 0 && cycle < 5555) || cycle > 20000) { @@ -278,14 +298,11 @@ u32 sceCtrlSetSamplingCycle(u32 cycle) u32 prev = ctrlCycle; ctrlCycle = cycle; - if (cycle == 0) - { - // TODO: Cancel the timer. - } - else - { - // TODO: Setup the timer. - } + if (prev > 0) + CoreTiming::UnscheduleEvent(ctrlTimer, 0); + if (cycle > 0) + CoreTiming::ScheduleEvent(usToCycles(ctrlCycle), ctrlTimer, 0); + return prev; }