From: notaz Date: Fri, 4 Oct 2013 20:24:36 +0000 (+0300) Subject: cd: fix cycle overflow issue X-Git-Tag: v1.91~18 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a6523294e28d7e6c119a578eb65b91af8da77f8d;p=picodrive.git cd: fix cycle overflow issue --- diff --git a/pico/32x/32x.c b/pico/32x/32x.c index b8a84d93..26162e49 100644 --- a/pico/32x/32x.c +++ b/pico/32x/32x.c @@ -547,6 +547,9 @@ void PicoFrame32x(void) p32x_sh2_poll_event(&msh2, SH2_STATE_VPOLL, 0); p32x_sh2_poll_event(&ssh2, SH2_STATE_VPOLL, 0); + if (PicoAHW & PAHW_MCD) + pcd_prepare_frame(); + PicoFrameStart(); PicoFrameHints(); sh2_drc_frame(); diff --git a/pico/cd/mcd.c b/pico/cd/mcd.c index 8451a1c2..24e99e44 100644 --- a/pico/cd/mcd.c +++ b/pico/cd/mcd.c @@ -11,7 +11,9 @@ extern unsigned char formatted_bram[4*0x10]; -static unsigned int m68k_cycle_mult; +static unsigned int mcd_m68k_cycle_mult; +static unsigned int mcd_m68k_cycle_base; +static unsigned int mcd_s68k_cycle_base; void (*PicoMCDopenTray)(void) = NULL; void (*PicoMCDcloseTray)(void) = NULL; @@ -116,14 +118,14 @@ static void pcd_set_cycle_mult(void) { // ~1.63 for NTSC, ~1.645 for PAL if (Pico.m.pal) - m68k_cycle_mult = ((12500000ull << 16) / (50*312*488)); + mcd_m68k_cycle_mult = ((12500000ull << 16) / (50*312*488)); else - m68k_cycle_mult = ((12500000ull << 16) / (60*262*488)) + 1; + mcd_m68k_cycle_mult = ((12500000ull << 16) / (60*262*488)) + 1; } unsigned int pcd_cycles_m68k_to_s68k(unsigned int c) { - return (long long)c * m68k_cycle_mult >> 16; + return (long long)c * mcd_m68k_cycle_mult >> 16; } /* events */ @@ -234,10 +236,13 @@ static void pcd_run_events(unsigned int until) int pcd_sync_s68k(unsigned int m68k_target, int m68k_poll_sync) { #define now SekCycleCntS68k - unsigned int s68k_target = - (unsigned long long)m68k_target * m68k_cycle_mult >> 16; + unsigned int s68k_target; unsigned int target; + target = m68k_target - mcd_m68k_cycle_base; + s68k_target = mcd_s68k_cycle_base + + ((unsigned long long)target * mcd_m68k_cycle_mult >> 16); + elprintf(EL_CD, "s68k sync to %u, %u->%u", m68k_target, now, s68k_target); @@ -307,12 +312,21 @@ void pcd_run_cpus_lockstep(int m68k_cycles) #include "../pico_cmn.c" +void pcd_prepare_frame(void) +{ + pcd_set_cycle_mult(); + + // need this because we can't have direct mapping between + // master<->slave cycle counters because of overflows + mcd_m68k_cycle_base = SekCycleAim; + mcd_s68k_cycle_base = SekCycleAimS68k; +} + PICO_INTERNAL void PicoFrameMCD(void) { - if (!(PicoOpt&POPT_ALT_RENDERER)) - PicoFrameStart(); + PicoFrameStart(); - pcd_set_cycle_mult(); + pcd_prepare_frame(); PicoFrameHints(); } diff --git a/pico/pico.c b/pico/pico.c index 6888080b..8535d486 100644 --- a/pico/pico.c +++ b/pico/pico.c @@ -285,8 +285,11 @@ int z80_scanline_cycles; /* cycles done until z80_scanline */ /* sync z80 to 68k */ PICO_INTERNAL void PicoSyncZ80(unsigned int m68k_cycles_done) { + int m68k_cnt; int cnt; - z80_cycle_aim += cycles_68k_to_z80(m68k_cycles_done - last_z80_sync); + + m68k_cnt = m68k_cycles_done - last_z80_sync; + z80_cycle_aim += cycles_68k_to_z80(m68k_cnt); cnt = z80_cycle_aim - z80_cycle_cnt; last_z80_sync = m68k_cycles_done; diff --git a/pico/pico_int.h b/pico/pico_int.h index 41dc59dc..a8bf7ee4 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -664,6 +664,7 @@ enum pcd_event { extern unsigned int pcd_event_times[PCD_EVENT_COUNT]; void pcd_event_schedule(unsigned int now, enum pcd_event event, int after); void pcd_event_schedule_s68k(enum pcd_event event, int after); +void pcd_prepare_frame(void); unsigned int pcd_cycles_m68k_to_s68k(unsigned int c); int pcd_sync_s68k(unsigned int m68k_target, int m68k_poll_sync); void pcd_run_cpus(int m68k_cycles);