From 50fc4091f703d3944812282b40958de8d700de41 Mon Sep 17 00:00:00 2001 From: ekeeke Date: Wed, 23 Sep 2026 22:54:08 +0200 Subject: [PATCH] [Core/CD] minor Main-CPU/Sub-CPU synchronization optimization --- core/cd_hw/scd.c | 10 ++++++---- core/mem68k.c | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/core/cd_hw/scd.c b/core/cd_hw/scd.c index 187753f2..708f4f03 100644 --- a/core/cd_hw/scd.c +++ b/core/cd_hw/scd.c @@ -504,14 +504,16 @@ static void s68k_poll_sync(unsigned int reg_mask) static void m68k_sync(void) { + /* check MAIN-CPU is still running */ if (!m68k.stopped) { - /* relative MAIN-CPU cycle counter */ - unsigned int cycles = (s68k.cycles * MCYCLES_PER_LINE) / SCYCLES_PER_LINE; - - /* sync MAIN-CPU with SUB-CPU (only if MAIN-CPU execution frame is finished, to prevent recursive execution) */ + /* check MAIN-CPU execution frame is finished (to prevent recursive execution) */ if (!m68k.cycle_end) { + /* relative MAIN-CPU cycle counter */ + unsigned int cycles = (s68k.cycles * MCYCLES_PER_LINE) / SCYCLES_PER_LINE; + + /* sync MAIN-CPU with SUB-CPU */ m68k_run(cycles); } } diff --git a/core/mem68k.c b/core/mem68k.c index 0b0354c8..6dd6b004 100644 --- a/core/mem68k.c +++ b/core/mem68k.c @@ -302,14 +302,16 @@ static void m68k_poll_sync(unsigned int reg_mask) static void s68k_sync(void) { + /* check SUB-CPU is still running */ if (!s68k.stopped) { - /* relative SUB-CPU cycle counter */ - unsigned int cycles = (m68k.cycles * SCYCLES_PER_LINE) / MCYCLES_PER_LINE; - - /* sync SUB-CPU with MAIN-CPU (only if SUB-CPU execution frame is finished, to prevent recursive execution) */ + /* check SUB-CPU execution frame is finished (to prevent recursive execution) */ if (!s68k.cycle_end) { + /* relative SUB-CPU cycle counter */ + unsigned int cycles = (m68k.cycles * SCYCLES_PER_LINE) / MCYCLES_PER_LINE; + + /* sync SUB-CPU with MAIN-CPU */ s68k_run(cycles); } }