From: kub Date: Thu, 22 Jun 2023 22:16:47 +0000 (+0002) Subject: sound, improve ym2612 timers implementation X-Git-Tag: v2.00~199 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3d70d1305cdbc6b8c16c63c24efa065c30d9c4f;p=picodrive.git sound, improve ym2612 timers implementation --- diff --git a/pico/debug.c b/pico/debug.c index e8810894..e928d73b 100644 --- a/pico/debug.c +++ b/pico/debug.c @@ -406,7 +406,7 @@ void PDebugZ80Frame(void) if (PicoIn.sndOut) PsndGetSamples(lines); - timers_cycle(); + timers_cycle(Pico.t.z80c_aim); Pico.t.m68c_aim = Pico.t.m68c_cnt; } diff --git a/pico/memory.c b/pico/memory.c index 3267a16a..a9398b8e 100644 --- a/pico/memory.c +++ b/pico/memory.c @@ -1136,31 +1136,26 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80) : ((ym2612.OPN.ST.TA & 0x3fc)|(d&3)); if (ym2612.OPN.ST.TA != TAnew) { + int cycles = is_from_z80 ? z80_cyclesDone() : z80_cycles_from_68k(); + ym2612_sync_timers(cycles, ym2612.OPN.ST.mode, ym2612.OPN.ST.mode); //elprintf(EL_STATUS, "timer a set %i", TAnew); ym2612.OPN.ST.TA = TAnew; //ym2612.OPN.ST.TAC = (1024-TAnew)*18; //ym2612.OPN.ST.TAT = 0; Pico.t.timer_a_step = TIMER_A_TICK_ZCYCLES * (1024 - TAnew); - if (ym2612.OPN.ST.mode & 1) { - // this is not right, should really be done on overflow only - int cycles = is_from_z80 ? z80_cyclesDone() : z80_cycles_from_68k(); - Pico.t.timer_a_next_oflow = (cycles << 8) + Pico.t.timer_a_step; - } elprintf(EL_YMTIMER, "timer a set to %i, %i", 1024 - TAnew, Pico.t.timer_a_next_oflow>>8); } return 0; } case 0x26: // timer B if (ym2612.OPN.ST.TB != d) { + int cycles = is_from_z80 ? z80_cyclesDone() : z80_cycles_from_68k(); + ym2612_sync_timers(cycles, ym2612.OPN.ST.mode, ym2612.OPN.ST.mode); //elprintf(EL_STATUS, "timer b set %i", d); ym2612.OPN.ST.TB = d; //ym2612.OPN.ST.TBC = (256-d) * 288; //ym2612.OPN.ST.TBT = 0; Pico.t.timer_b_step = TIMER_B_TICK_ZCYCLES * (256 - d); // 262800 - if (ym2612.OPN.ST.mode & 2) { - int cycles = is_from_z80 ? z80_cyclesDone() : z80_cycles_from_68k(); - Pico.t.timer_b_next_oflow = (cycles << 8) + Pico.t.timer_b_step; - } elprintf(EL_YMTIMER, "timer b set to %i, %i", 256 - d, Pico.t.timer_b_next_oflow>>8); } return 0; diff --git a/pico/pico_cmn.c b/pico/pico_cmn.c index 2be1c47e..2f1747fe 100644 --- a/pico/pico_cmn.c +++ b/pico/pico_cmn.c @@ -345,7 +345,7 @@ static int PicoFrameHints(void) // get samples from sound chips PsndGetSamples(y); - timers_cycle(); + timers_cycle(Pico.t.z80c_aim); pv->hint_cnt = hint; diff --git a/pico/pico_int.h b/pico/pico_int.h index 055f5ee9..d8b7160b 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -872,16 +872,18 @@ void ym2612_pack_state(void); void ym2612_unpack_state(void); #define TIMER_NO_OFLOW 0x70000000 -// tA = 72 * (1024 - NA) / M, with M = mclock/2 -> tick = 72 * 2/mclock -#define TIMER_A_TICK_ZCYCLES 17203 // zcycles = Q8*tick*zclock = Q8*77*2*7/15 -// tB = 1152 * (256 - NA) / M, -#define TIMER_B_TICK_ZCYCLES 275251 // zcycles = Q8*1152*2*7/15 -#define timers_cycle() \ +// NB ~0.2% timers speed up (1/8(A), 2(B) z80 cycles), HACK for A/V sync in OD2 +// tA = 72 * (1024 - TA) / M, with M = mclock/2 +#define TIMER_A_TICK_ZCYCLES (cycles_68k_to_z80(256LL* 72*2)-32) // Q8 +// tB = 16*72 * ( 256 - TB) / M +#define TIMER_B_TICK_ZCYCLES (cycles_68k_to_z80(256LL*16*72*2)-32*16) // Q8 + +#define timers_cycle(ticks) \ if (Pico.t.timer_a_next_oflow > 0 && Pico.t.timer_a_next_oflow < TIMER_NO_OFLOW) \ - Pico.t.timer_a_next_oflow -= Pico.m.pal ? 70938*256 : 59659*256; \ + Pico.t.timer_a_next_oflow -= ticks << 8; \ if (Pico.t.timer_b_next_oflow > 0 && Pico.t.timer_b_next_oflow < TIMER_NO_OFLOW) \ - Pico.t.timer_b_next_oflow -= Pico.m.pal ? 70938*256 : 59659*256; \ + Pico.t.timer_b_next_oflow -= ticks << 8; \ ym2612_sync_timers(0, ym2612.OPN.ST.mode, ym2612.OPN.ST.mode); #define timers_reset() \