From 9d5f3c1306448169a3e5848c392bba3f947284a1 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 18 Oct 2019 00:20:38 +1000 Subject: [PATCH] CPU: Support stalling CPU for bus activity such as DMA --- src/core/cpu_core.h | 5 +++++ src/core/system.cpp | 5 +++++ src/core/system.h | 3 +++ 3 files changed, 13 insertions(+) diff --git a/src/core/cpu_core.h b/src/core/cpu_core.h index 7da313134..2a0abf653 100644 --- a/src/core/cpu_core.h +++ b/src/core/cpu_core.h @@ -35,6 +35,11 @@ public: TickCount GetPendingTicks() const { return m_pending_ticks; } void ResetPendingTicks() { m_pending_ticks = 0; } + void AddPendingTicks(TickCount ticks) + { + m_pending_ticks += ticks; + m_downcount -= ticks; + } void SetDowncount(TickCount downcount) { m_downcount = (downcount < m_downcount) ? downcount : m_downcount; } void ResetDowncount() { m_downcount = MAX_SLICE_SIZE; } diff --git a/src/core/system.cpp b/src/core/system.cpp index 4a1863570..448586bd7 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -296,6 +296,11 @@ void System::SetDowncount(TickCount downcount) m_cpu->SetDowncount(downcount); } +void System::StallCPU(TickCount ticks) +{ + m_cpu->AddPendingTicks(ticks); +} + void System::SetController(u32 slot, std::shared_ptr dev) { m_pad->SetController(slot, std::move(dev)); diff --git a/src/core/system.h b/src/core/system.h index 6d6752747..10a1645ab 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -58,6 +58,9 @@ public: void SetDowncount(TickCount downcount); void Synchronize(); + // Adds ticks to the global tick counter, simulating the CPU being stalled. + void StallCPU(TickCount ticks); + void SetController(u32 slot, std::shared_ptr dev); void SetMemoryCard(u32 slot, std::shared_ptr dev);