From 00496e5b7e7c3444c16daeea28e553e4681b1715 Mon Sep 17 00:00:00 2001 From: kub Date: Sat, 22 Jun 2024 23:12:31 +0200 Subject: [PATCH] core, revisit ym2612 busy flag implementation --- pico/memory.c | 6 +++--- pico/pico_int.h | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pico/memory.c b/pico/memory.c index 168bad919..17139a0d8 100644 --- a/pico/memory.c +++ b/pico/memory.c @@ -1174,7 +1174,7 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80) // the busy flag in the YM2612 status is actually a 32 cycle timer // (89.6 Z80 cycles), triggered by any write to the data port. - Pico.t.ym2612_busy = (cycles + 90) << 8; // Q8 for convenience + Pico.t.ym2612_busy = (cycles << 8) + YMBUSY_ZCYCLES; // Q8 for convenience switch (addr) { @@ -1288,7 +1288,7 @@ void ym2612_pack_state(void) tac = 1024 - ym2612.OPN.ST.TA; tbc = 256 - ym2612.OPN.ST.TB; if (Pico.t.ym2612_busy > 0) - busy = (Pico.t.ym2612_busy * 32/90) >> 8; + busy = cycles_z80_to_68k(Pico.t.ym2612_busy); if (Pico.t.timer_a_next_oflow != TIMER_NO_OFLOW) tat = (int)((double)(Pico.t.timer_a_step - Pico.t.timer_a_next_oflow) / (double)Pico.t.timer_a_step * tac * 65536); @@ -1344,7 +1344,7 @@ void ym2612_unpack_state(void) return; // no saved timers } - Pico.t.ym2612_busy = (busy << 8) * 90/32; + Pico.t.ym2612_busy = cycles_68k_to_z80(busy); tac = (1024 - ym2612.OPN.ST.TA) << 16; tbc = (256 - ym2612.OPN.ST.TB) << 16; if (ym2612.OPN.ST.mode & 1) diff --git a/pico/pico_int.h b/pico/pico_int.h index 06f00c2f5..79997d9bf 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -209,6 +209,7 @@ extern struct DrZ80 drZ80; // 68k clock = OSC/7, z80 clock = OSC/15, 68k:z80 ratio = 7/15 = 3822.9/8192 #define cycles_68k_to_z80(x) ((x) * 3823 >> 13) +#define cycles_z80_to_68k(x) ((x) * 8777 >> 12) // ----------------------- SH2 CPU ----------------------- @@ -898,10 +899,12 @@ void ym2612_unpack_state(void); #define TIMER_NO_OFLOW 0x70000000 -// tA = 72 * (1024 - TA) / M, with M = mclock/2 -#define TIMER_A_TICK_ZCYCLES cycles_68k_to_z80(256LL* 72*2) // Q8 -// tB = 16*72 * ( 256 - TB) / M -#define TIMER_B_TICK_ZCYCLES cycles_68k_to_z80(256LL*16*72*2) // Q8 +// tA = 24*3 * (1024 - TA) / M, with M = mclock/2 +#define TIMER_A_TICK_ZCYCLES cycles_68k_to_z80(256LL* 24*3*2) // Q8 +// tB = 16*24*3 * ( 256 - TB) / M +#define TIMER_B_TICK_ZCYCLES cycles_68k_to_z80(256LL*16*24*3*2) // Q8 +// busy = 32*3 / M +#define YMBUSY_ZCYCLES cycles_68k_to_z80(256LL* 32*3*2) // Q8 #define timers_cycle(ticks) \ if (Pico.t.ym2612_busy > 0) \