sound, improve ym2612 timers implementation

This commit is contained in:
kub 2023-06-22 22:18:47 +00:02
parent e0c4dac19c
commit c3d70d1305
4 changed files with 15 additions and 18 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -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;

View file

@ -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() \