diff --git a/src/core/cpu_core.cpp b/src/core/cpu_core.cpp index 192de70c2..66d468af2 100644 --- a/src/core/cpu_core.cpp +++ b/src/core/cpu_core.cpp @@ -2019,10 +2019,8 @@ bool CPU::UpdateDebugDispatcherFlag() void CPU::ExitExecution() { // can't exit while running events without messing things up - if (TimingEvents::IsRunningEvents()) - TimingEvents::SetFrameDone(); - else - fastjmp_jmp(&s_jmp_buf, 1); + DebugAssert(!TimingEvents::IsRunningEvents()); + fastjmp_jmp(&s_jmp_buf, 1); } bool CPU::HasAnyBreakpoints() diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index 3c2fb95bc..8807b176c 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -977,6 +977,7 @@ void GPU::CRTCTickEvent(TickCount ticks) Timers::AddTicks(HBLANK_TIMER_INDEX, static_cast(hblank_timer_ticks)); } + bool frame_done = false; while (lines_to_draw > 0) { const u32 lines_to_draw_this_loop = @@ -1007,7 +1008,7 @@ void GPU::CRTCTickEvent(TickCount ticks) // TODO: move present in here I guess FlushRender(); UpdateDisplay(); - TimingEvents::SetFrameDone(); + frame_done = true; // switch fields early. this is needed so we draw to the correct one. if (m_GPUSTAT.InInterleaved480iMode()) @@ -1068,6 +1069,9 @@ void GPU::CRTCTickEvent(TickCount ticks) } UpdateCRTCTickEvent(); + + if (frame_done) + System::FrameDone(); } void GPU::CommandTickEvent(TickCount ticks) diff --git a/src/core/system.cpp b/src/core/system.cpp index a926aba95..217103181 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -203,6 +203,9 @@ static u32 CompressAndWriteStateData(std::FILE* fp, std::span src, Sav u32* header_type, Error* error); static bool DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_display, bool is_memory_state); +static bool IsExecutionInterrupted(); +static void ExitExecution(); + static void SetRewinding(bool enabled); static bool SaveRewindState(); static void DoRewind(); @@ -559,6 +562,12 @@ bool System::IsExecutionInterrupted() return s_state != State::Running || s_system_interrupted; } +void System::ExitExecution() +{ + TimingEvents::CancelRunningEvent(); + CPU::ExitExecution(); +} + bool System::IsPaused() { return s_state == State::Paused; @@ -2043,7 +2052,7 @@ void System::FrameDone() if (IsExecutionInterrupted()) { s_system_interrupted = false; - CPU::ExitExecution(); + ExitExecution(); return; } } @@ -2154,7 +2163,7 @@ void System::FrameDone() if (IsExecutionInterrupted()) { s_system_interrupted = false; - CPU::ExitExecution(); + ExitExecution(); return; } } diff --git a/src/core/system.h b/src/core/system.h index 1abdf25b3..14e587159 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -147,7 +147,6 @@ std::string GetInputProfilePath(std::string_view name); State GetState(); void SetState(State new_state); bool IsRunning(); -bool IsExecutionInterrupted(); bool IsPaused(); bool IsShutdown(); bool IsValid(); diff --git a/src/core/timing_event.cpp b/src/core/timing_event.cpp index 39f3a2ff0..c9cd621d6 100644 --- a/src/core/timing_event.cpp +++ b/src/core/timing_event.cpp @@ -32,7 +32,6 @@ struct TimingEventsState TimingEvent* active_events_tail = nullptr; TimingEvent* current_event = nullptr; u32 active_event_count = 0; - bool frame_done = false; GlobalTicks current_event_next_run_time = 0; GlobalTicks global_tick_counter = 0; GlobalTicks event_run_tick_counter = 0; @@ -305,20 +304,19 @@ bool TimingEvents::IsRunningEvents() return (s_state.current_event != nullptr); } -void TimingEvents::SetFrameDone() -{ - s_state.frame_done = true; - CPU::g_state.downcount = 0; -} - void TimingEvents::CancelRunningEvent() { - if (!s_state.current_event) + TimingEvent* const event = s_state.current_event; + if (!event) return; // Might need to sort it, since we're bailing out. - if (s_state.current_event->IsActive()) - SortEvent(s_state.current_event); + if (event->IsActive()) + { + event->m_next_run_time = s_state.current_event_next_run_time; + SortEvent(event); + } + s_state.current_event = nullptr; } @@ -375,12 +373,6 @@ void TimingEvents::RunEvents() CommitGlobalTicks(new_global_ticks); } - if (s_state.frame_done) - { - s_state.frame_done = false; - System::FrameDone(); - } - if (CPU::HasPendingInterrupt()) CPU::DispatchInterrupt(); diff --git a/src/core/timing_event.h b/src/core/timing_event.h index 26f5960b9..f3fe7d5e6 100644 --- a/src/core/timing_event.h +++ b/src/core/timing_event.h @@ -86,7 +86,6 @@ void Shutdown(); bool DoState(StateWrapper& sw); bool IsRunningEvents(); -void SetFrameDone(); void CancelRunningEvent(); void RunEvents(); void CommitLeftoverTicks();