From: kub Date: Sat, 2 Mar 2024 09:36:49 +0000 (+0100) Subject: core, slightly increase accuracy of some hw timers X-Git-Tag: v2.00~107 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80f51a1d59e54aa6b628e5a514434bdd30b8b856;p=picodrive.git core, slightly increase accuracy of some hw timers --- diff --git a/pico/cd/memory.c b/pico/cd/memory.c index 07578284..b13644b1 100644 --- a/pico/cd/memory.c +++ b/pico/cd/memory.c @@ -97,9 +97,9 @@ void m68k_comm_check(u32 a) u32 pcd_stopwatch_read(int sub) { - // ugh.. + // ugh... stopwatch runs 384 cycles per step, divide by mult with inverse u32 d = sub ? SekCyclesDoneS68k() : pcd_cycles_m68k_to_s68k(SekCyclesDone()); - d = (d - Pico_mcd->m.stopwatch_base_c) / 384; + d = ((d - Pico_mcd->m.stopwatch_base_c) * ((1LL << 32) / 384)) >> 32; return d & 0x0fff; } diff --git a/pico/memory.c b/pico/memory.c index c2a40f70..46e0bd4a 100644 --- a/pico/memory.c +++ b/pico/memory.c @@ -1092,7 +1092,7 @@ void ym2612_sync_timers(int z80_cycles, int mode_old, int mode_new) * Starting a timer takes place at the next tick, so xcycles needs to be * rounded up to that: t = next tick# = (xcycles / TICK_ZCYCLES) + 1 */ - unsigned t = ((xcycles * (((1<<20)/TIMER_A_TICK_ZCYCLES)+1))>>20) + 1; + unsigned t = ((xcycles * (((1LL<<32)/TIMER_A_TICK_ZCYCLES)+1))>>32) + 1; Pico.t.timer_a_next_oflow = t*TIMER_A_TICK_ZCYCLES + Pico.t.timer_a_step; } } @@ -1115,7 +1115,7 @@ void ym2612_sync_timers(int z80_cycles, int mode_old, int mode_new) * reset by loading timer b. The first run of timer b after loading is * therefore shorter by up to 15 ticks. */ - unsigned t = ((xcycles * (((1<<20)/TIMER_A_TICK_ZCYCLES)+1))>>20) + 1; + unsigned t = ((xcycles * (((1LL<<32)/TIMER_A_TICK_ZCYCLES)+1))>>32) + 1; int step = Pico.t.timer_b_step - TIMER_A_TICK_ZCYCLES*(t&15); Pico.t.timer_b_next_oflow = t*TIMER_A_TICK_ZCYCLES + step; }