From 15018ca4a5645c493ecf8894743afb5e07fa42f9 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 22 Dec 2012 18:30:14 -0800 Subject: [PATCH 1/6] Stub out the sceCtrl idle cancel funcs. --- Core/HLE/sceCtrl.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Core/HLE/sceCtrl.cpp b/Core/HLE/sceCtrl.cpp index 73e03def9d..c5881219f0 100644 --- a/Core/HLE/sceCtrl.cpp +++ b/Core/HLE/sceCtrl.cpp @@ -297,6 +297,7 @@ u32 sceCtrlSetSamplingMode(u32 mode) int sceCtrlGetSamplingMode(u32 modePtr) { u32 retVal = analogEnabled == true ? CTRL_MODE_ANALOG : CTRL_MODE_DIGITAL; + DEBUG_LOG(HLE, "%d=sceCtrlGetSamplingMode(%i)", retVal); if (Memory::IsValidAddress(modePtr)) Memory::Write_U32(retVal, modePtr); @@ -304,10 +305,16 @@ int sceCtrlGetSamplingMode(u32 modePtr) return 0; } -void sceCtrlSetIdleCancelThreshold() +int sceCtrlSetIdleCancelThreshold(int idleReset, int idleBack) { - ERROR_LOG(HLE,"UNIMPL sceCtrlSetIdleCancelThreshold"); - RETURN(0); + ERROR_LOG(HLE, "UNIMPL sceCtrlSetIdleCancelThreshold(%d, %d)", idleReset, idleBack); + return 0; +} + +int sceCtrlGetIdleCancelThreshold(u32 idleResetPtr, u32 idleBackPtr) +{ + ERROR_LOG(HLE, "UNIMPL sceCtrlSetIdleCancelThreshold(%08x, %08x)", idleResetPtr, idleBackPtr); + return 0; } void sceCtrlReadBufferPositive(u32 ctrlDataPtr, u32 nBufs) @@ -393,8 +400,8 @@ static const HLEFunction sceCtrl[] = {0xAF5960F3, 0, "sceCtrl_AF5960F3"}, {0xA68FD260, 0, "sceCtrlClearRapidFire"}, {0x6841BE1A, 0, "sceCtrlSetRapidFire"}, - {0xa7144800, WrapV_V, "sceCtrlSetIdleCancelThreshold"}, - {0x687660fa, 0, "sceCtrlGetIdleCancelThreshold"}, + {0xa7144800, WrapI_II, "sceCtrlSetIdleCancelThreshold"}, + {0x687660fa, WrapI_UU, "sceCtrlGetIdleCancelThreshold"}, }; void Register_sceCtrl() From 91e1cb74087f807c46dbc5b3a8c62ff7556a7260 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 22 Dec 2012 18:41:49 -0800 Subject: [PATCH 2/6] Implement sceCtrl*IdleCancelThreshold(). --- Core/HLE/sceCtrl.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/Core/HLE/sceCtrl.cpp b/Core/HLE/sceCtrl.cpp index c5881219f0..8c9c1f28bf 100644 --- a/Core/HLE/sceCtrl.cpp +++ b/Core/HLE/sceCtrl.cpp @@ -33,6 +33,7 @@ const int PSP_CTRL_ERROR_INVALID_MODE = 0x80000107; const int PSP_CTRL_ERROR_INVALID_NUM_BUFFERS = 0x80000104; +const int PSP_CTRL_ERROR_INVALID_IDLE_PTR = 0x80000023; const int NUM_CTRL_BUFFERS = 64; @@ -72,6 +73,9 @@ static int ctrlBuf = 0; static int ctrlBufRead = 0; static CtrlLatch latch; +static int ctrlIdleReset = -1; +static int ctrlIdleBack = -1; + static std::vector waitingThreads; static std::recursive_mutex ctrlMutex; @@ -307,13 +311,30 @@ int sceCtrlGetSamplingMode(u32 modePtr) int sceCtrlSetIdleCancelThreshold(int idleReset, int idleBack) { - ERROR_LOG(HLE, "UNIMPL sceCtrlSetIdleCancelThreshold(%d, %d)", idleReset, idleBack); + DEBUG_LOG(HLE, "FAKE sceCtrlSetIdleCancelThreshold(%d, %d)", idleReset, idleBack); + + if (idleReset < -1 || idleBack < -1 || idleReset > 128 || idleBack > 128) + return SCE_KERNEL_ERROR_INVALID_VALUE; + + ctrlIdleReset = idleReset; + ctrlIdleBack = idleBack; return 0; } int sceCtrlGetIdleCancelThreshold(u32 idleResetPtr, u32 idleBackPtr) { - ERROR_LOG(HLE, "UNIMPL sceCtrlSetIdleCancelThreshold(%08x, %08x)", idleResetPtr, idleBackPtr); + DEBUG_LOG(HLE, "sceCtrlSetIdleCancelThreshold(%08x, %08x)", idleResetPtr, idleBackPtr); + + if (idleResetPtr && !Memory::IsValidAddress(idleResetPtr)) + return PSP_CTRL_ERROR_INVALID_IDLE_PTR; + if (idleBackPtr && !Memory::IsValidAddress(idleBackPtr)) + return PSP_CTRL_ERROR_INVALID_IDLE_PTR; + + if (idleResetPtr) + Memory::Write_U32(ctrlIdleReset, idleResetPtr); + if (idleBackPtr) + Memory::Write_U32(ctrlIdleBack, idleBackPtr); + return 0; } From 6ad3c2d4541838856c07135afcfb67ce2d2ab5b9 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 22 Dec 2012 19:37:18 -0800 Subject: [PATCH 3/6] Make sure ctrl resets properly on game close/open. --- Core/HLE/sceCtrl.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Core/HLE/sceCtrl.cpp b/Core/HLE/sceCtrl.cpp index 8c9c1f28bf..ca6bf486a4 100644 --- a/Core/HLE/sceCtrl.cpp +++ b/Core/HLE/sceCtrl.cpp @@ -255,14 +255,11 @@ void __CtrlInit() for (int i = 0; i < NUM_CTRL_BUFFERS; i++) memcpy(&ctrlBufs[i], &ctrlCurrent, sizeof(_ctrl_data)); -} -void sceCtrlInit() -{ - __CtrlInit(); + ctrlIdleReset = -1; + ctrlIdleBack = -1; - DEBUG_LOG(HLE,"sceCtrlInit"); - RETURN(0); + waitingThreads.clear(); } u32 sceCtrlSetSamplingCycle(u32 cycle) @@ -406,7 +403,7 @@ u32 sceCtrlReadLatch(u32 latchDataPtr) static const HLEFunction sceCtrl[] = { - {0x3E65A0EA, WrapV_V, "sceCtrlInit"}, //(int unknown), init with 0 + {0x3E65A0EA, 0, "sceCtrlInit"}, //(int unknown), init with 0 {0x1f4011e6, WrapU_U, "sceCtrlSetSamplingMode"}, //(int on); {0x6A2774F3, WrapU_U, "sceCtrlSetSamplingCycle"}, {0x02BAAD91, WrapI_U,"sceCtrlGetSamplingCycle"}, From 8839516c1ecf36c890ce844fbeb1569d0092722d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 22 Dec 2012 20:31:22 -0800 Subject: [PATCH 4/6] Implement sceCtrlGetSamplingCycle(). --- Core/HLE/sceCtrl.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Core/HLE/sceCtrl.cpp b/Core/HLE/sceCtrl.cpp index ca6bf486a4..bfce13d43b 100644 --- a/Core/HLE/sceCtrl.cpp +++ b/Core/HLE/sceCtrl.cpp @@ -76,6 +76,8 @@ static CtrlLatch latch; static int ctrlIdleReset = -1; static int ctrlIdleBack = -1; +static u32 ctrlCycle = 0; + static std::vector waitingThreads; static std::recursive_mutex ctrlMutex; @@ -258,27 +260,40 @@ void __CtrlInit() ctrlIdleReset = -1; ctrlIdleBack = -1; + ctrlCycle = 0; waitingThreads.clear(); } u32 sceCtrlSetSamplingCycle(u32 cycle) { + WARN_LOG(HLE, "FAKE sceCtrlSetSamplingCycle(%u)", cycle); + + if ((cycle > 0 && cycle < 5555) || cycle > 20000) + { + WARN_LOG(HLE, "SCE_KERNEL_ERROR_INVALID_VALUE=sceCtrlSetSamplingCycle(%u)", cycle); + return SCE_KERNEL_ERROR_INVALID_VALUE; + } + + u32 prev = ctrlCycle; + ctrlCycle = cycle; + if (cycle == 0) { - // TODO: Change to vblank when we support something else. - DEBUG_LOG(HLE, "sceCtrlSetSamplingCycle(%u)", cycle); + // TODO: Cancel the timer. } else { - ERROR_LOG(HLE, "UNIMPL sceCtrlSetSamplingCycle(%u)", cycle); + // TODO: Setup the timer. } - return 0; + return prev; } int sceCtrlGetSamplingCycle(u32 cyclePtr) { - ERROR_LOG(HLE, "UNIMPL sceCtrlSetSamplingCycle(%08x)", cyclePtr); + DEBUG_LOG(HLE, "sceCtrlSetSamplingCycle(%08x)", cyclePtr); + if (Memory::IsValidAddress(cyclePtr)) + Memory::Write_U32(ctrlCycle, cyclePtr); return 0; } From bbd7710234c0b0a67541d576284813fa8eb27728 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 22 Dec 2012 21:23:28 -0800 Subject: [PATCH 5/6] 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; } From 13389437d30dde14026ca35634074624dd018f88 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 22 Dec 2012 21:28:01 -0800 Subject: [PATCH 6/6] Update tests. --- pspautotests | 2 +- test.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pspautotests b/pspautotests index 54acddd544..9ea2847b5e 160000 --- a/pspautotests +++ b/pspautotests @@ -1 +1 @@ -Subproject commit 54acddd54469a88aadbaf0e69088aad504b5e1e4 +Subproject commit 9ea2847b5e793b9fae8ccd81f25cc8e4f6a81d7d diff --git a/test.py b/test.py index f352ccf50f..2e1248690b 100755 --- a/test.py +++ b/test.py @@ -49,7 +49,9 @@ tests_good = [ "cpu/fpu/fpu", "ctrl/ctrl", + "ctrl/idle/idle", "ctrl/sampling/sampling", + "ctrl/sampling2/sampling2", "display/display", "dmac/dmactest", "loader/bss/bss",