Skip to content

Commit

Permalink
core, revisit ym2612 busy flag implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
irixxxx committed Jun 22, 2024
1 parent b6c6af5 commit 00496e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pico/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions pico/pico_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 -----------------------

Expand Down Expand Up @@ -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) \
Expand Down

0 comments on commit 00496e5

Please sign in to comment.