Skip to content

Commit

Permalink
ymfm: Latch the multi-frequency state at key on. Fixes sor2 punch sou…
Browse files Browse the repository at this point in the history
…nd on megadriv.
  • Loading branch information
aaronsgiles committed Apr 5, 2021
1 parent 4e33773 commit 90d6b1b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/devices/sound/ymfm.cpp
Expand Up @@ -1054,7 +1054,8 @@ void ymopm_registers::log_keyon(u32 choffs, u32 opoffs)
template<bool IsOpnA>
ymopn_registers_base<IsOpnA>::ymopn_registers_base() :
m_lfo_counter(0),
m_lfo_am(0)
m_lfo_am(0),
m_multi_freq(0)
{
// create the waveforms
for (int index = 0; index < WAVEFORM_LENGTH; index++)
Expand All @@ -1073,6 +1074,7 @@ void ymopn_registers_base<IsOpnA>::save(device_t &device)
{
device.save_item(YMFM_NAME(m_lfo_counter));
device.save_item(YMFM_NAME(m_lfo_am));
device.save_item(YMFM_NAME(m_multi_freq));
}
device.save_item(YMFM_NAME(m_regdata));
}
Expand Down Expand Up @@ -1177,11 +1179,22 @@ bool ymopn_registers_base<IsOpnA>::write(u16 index, u8 data, u32 &channel, u32 &
// handle writes to the key on index
if (index == 0x28)
{
// channel in low 2 bits; channel 3 is not valid
channel = BIT(data, 0, 2);
if (channel == 3)
return false;

// upper channels for OPNA
if (IsOpnA)
channel += BIT(data, 2, 1) * 3;

// when channel 2 key on hits, latch the multifrequency state
// megadriv sor2 flips the multi_freq bit on and off during playback
// of its sounds, specifically the punch sound
if (channel == 2)
m_multi_freq = multi_freq();

// operator mask is the top 4 bits
opmask = BIT(data, 4, 4);
return true;
}
Expand Down Expand Up @@ -1276,7 +1289,7 @@ void ymopn_registers_base<IsOpnA>::cache_operator_data(u32 choffs, u32 opoffs, y

// if multi-frequency mode is enabled and this is channel 2,
// fetch one of the special frequencies
if (multi_freq() && choffs == 2)
if (m_multi_freq && choffs == 2)
{
if (opoffs == 2)
block_freq = cache.block_freq = multi_block_freq(1);
Expand Down Expand Up @@ -1388,7 +1401,7 @@ void ymopn_registers_base<IsOpnA>::log_keyon(u32 choffs, u32 opoffs)
u32 opnum = (opoffs & 15) - ((opoffs & 15) / 4) + 12 * BIT(opoffs, 8);

u32 block_freq = ch_block_freq(choffs);
if (multi_freq() && choffs == 2)
if (m_multi_freq && choffs == 2)
{
if (opoffs == 2)
block_freq = multi_block_freq(1);
Expand Down Expand Up @@ -1427,7 +1440,7 @@ void ymopn_registers_base<IsOpnA>::log_keyon(u32 choffs, u32 opoffs)
LOG(" pm=%d", ch_lfo_pm_sens(choffs));
if (am || pm)
LOG(" lfo=%02X", lfo_rate());
if (multi_freq() && choffs == 2)
if (m_multi_freq && choffs == 2)
LOG(" multi=1");
}

Expand Down
3 changes: 2 additions & 1 deletion src/devices/sound/ymfm.h
Expand Up @@ -577,7 +577,7 @@ class ymopn_registers_base : public ymfm_registers_base
u32 lfo_rate() const { return IsOpnA ? byte(0x22, 0, 3) : 0; }
u32 timer_a_value() const { return word(0x24, 0, 8, 0x25, 0, 2); }
u32 timer_b_value() const { return byte(0x26, 0, 8); }
u32 csm() const { return (byte(0x27, 6, 2) == 2); }
u32 csm() const { return byte(0x27, 7, 1); }
u32 multi_freq() const { return (byte(0x27, 6, 2) != 0); }
u32 reset_timer_b() const { return byte(0x27, 5, 1); }
u32 reset_timer_a() const { return byte(0x27, 4, 1); }
Expand Down Expand Up @@ -629,6 +629,7 @@ class ymopn_registers_base : public ymfm_registers_base
// internal state
u32 m_lfo_counter; // LFO counter
u8 m_lfo_am; // current LFO AM value
u8 m_multi_freq; // channel 2 is currently multi-frequency
u8 m_regdata[REGISTERS]; // register data
u16 m_waveform[WAVEFORMS][WAVEFORM_LENGTH]; // waveforms
};
Expand Down

0 comments on commit 90d6b1b

Please sign in to comment.