From 6901d0e45dbf77671d86cb9bf9af98c486db97c8 Mon Sep 17 00:00:00 2001 From: notaz Date: Wed, 9 Oct 2013 02:26:52 +0300 Subject: [PATCH] fix yet another sync issue.. --- pico/cd/mcd.c | 35 +++++++++++++++++++++++++++++++++-- pico/cd/memory.c | 6 ++++++ pico/pico_int.h | 29 +++++++++++++++-------------- 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/pico/cd/mcd.c b/pico/cd/mcd.c index a20b01dc..687dfc3c 100644 --- a/pico/cd/mcd.c +++ b/pico/cd/mcd.c @@ -90,7 +90,32 @@ PICO_INTERNAL int PicoResetMCD(void) return 0; } -static __inline void SekRunS68k(unsigned int to) +static void SekRunM68kOnce(void) +{ + int cyc_do; + pevt_log_m68k_o(EVT_RUN_START); + + if ((cyc_do = SekCycleAim - SekCycleCnt) > 0) { + SekCycleCnt += cyc_do; + +#if defined(EMU_C68K) + PicoCpuCM68k.cycles = cyc_do; + CycloneRun(&PicoCpuCM68k); + SekCycleCnt -= PicoCpuCM68k.cycles; +#elif defined(EMU_M68K) + SekCycleCnt += m68k_execute(cyc_do) - cyc_do; +#elif defined(EMU_F68K) + SekCycleCnt += fm68k_emulate(cyc_do, 0) - cyc_do; +#endif + } + + SekCyclesLeft = 0; + + SekTrace(0); + pevt_log_m68k_o(EVT_RUN_END); +} + +static void SekRunS68k(unsigned int to) { int cyc_do; @@ -305,7 +330,13 @@ void pcd_run_cpus_normal(int m68k_cycles) SekCycleCnt = SekCycleAim - (s68k_left * 40220 >> 16); } - SekSyncM68k(); + while (CYCLES_GT(SekCycleAim, SekCycleCnt)) { + SekRunM68kOnce(); + if (Pico_mcd->m.need_sync) { + Pico_mcd->m.need_sync = 0; + pcd_sync_s68k(SekCycleCnt, 0); + } + } } void pcd_run_cpus_lockstep(int m68k_cycles) diff --git a/pico/cd/memory.c b/pico/cd/memory.c index 05510788..acf29c64 100644 --- a/pico/cd/memory.c +++ b/pico/cd/memory.c @@ -67,6 +67,12 @@ static void remap_word_ram(u32 r3); void m68k_comm_check(u32 a) { pcd_sync_s68k(SekCyclesDone(), 0); + if (a >= 0x0e && !Pico_mcd->m.need_sync) { + // there are cases when slave updates comm and only switches RAM + // over after that (mcd1b), so there must be a resync.. + SekEndRun(64); + Pico_mcd->m.need_sync = 1; + } if (SekNotPolling || a != Pico_mcd->m.m68k_poll_a) { Pico_mcd->m.m68k_poll_a = a; Pico_mcd->m.m68k_poll_cnt = 0; diff --git a/pico/pico_int.h b/pico/pico_int.h index 76c4812e..48d52372 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -396,20 +396,21 @@ struct mcd_pcm struct mcd_misc { - unsigned short hint_vector; - unsigned char busreq; // not s68k_regs[1] - unsigned char s68k_pend_ints; - unsigned int state_flags; // 04 - unsigned int stopwatch_base_c; - unsigned short m68k_poll_a; - unsigned short m68k_poll_cnt; - unsigned short s68k_poll_a; - unsigned short s68k_poll_cnt; - unsigned int s68k_poll_clk; - unsigned char bcram_reg; // 18: battery-backed RAM cart register - unsigned char dmna_ret_2m; - unsigned short pad3; - int pad4[9]; + unsigned short hint_vector; + unsigned char busreq; // not s68k_regs[1] + unsigned char s68k_pend_ints; + unsigned int state_flags; // 04 + unsigned int stopwatch_base_c; + unsigned short m68k_poll_a; + unsigned short m68k_poll_cnt; + unsigned short s68k_poll_a; + unsigned short s68k_poll_cnt; + unsigned int s68k_poll_clk; + unsigned char bcram_reg; // 18: battery-backed RAM cart register + unsigned char dmna_ret_2m; + unsigned char need_sync; + unsigned char pad3; + int pad4[9]; }; typedef struct -- 2.39.5