From 8967df23c2fadacaddd485f0d36f5c097674c9d3 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Tue, 11 Apr 2023 17:53:58 -0400 Subject: [PATCH] Update ymfm to latest upstream --- src/sound/ymfm/ymfm.h | 34 +++++++++++++++++----------------- src/sound/ymfm/ymfm_fm.h | 6 +++--- src/sound/ymfm/ymfm_fm.ipp | 13 +++++++------ src/sound/ymfm/ymfm_opl.cpp | 15 +++++++++++++-- src/sound/ymfm/ymfm_pcm.cpp | 1 - 5 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/sound/ymfm/ymfm.h b/src/sound/ymfm/ymfm.h index ae13faedd..bc0cf8b6c 100644 --- a/src/sound/ymfm/ymfm.h +++ b/src/sound/ymfm/ymfm.h @@ -40,11 +40,11 @@ #include #include #include +#include #include #include #include #include -#include namespace ymfm { @@ -329,7 +329,7 @@ struct ymfm_output // ======================> ymfm_wavfile // this class is a debugging helper that accumulates data and writes it to wav files -template +template class ymfm_wavfile { public: @@ -361,10 +361,10 @@ public: memcpy(&header[12], "fmt ", 4); *(uint32_t *)&header[16] = 16; *(uint16_t *)&header[20] = 1; - *(uint16_t *)&header[22] = _Channels; + *(uint16_t *)&header[22] = Channels; *(uint32_t *)&header[24] = m_samplerate; - *(uint32_t *)&header[28] = m_samplerate * 2 * _Channels; - *(uint16_t *)&header[32] = 2 * _Channels; + *(uint32_t *)&header[28] = m_samplerate * 2 * Channels; + *(uint16_t *)&header[32] = 2 * Channels; *(uint16_t *)&header[34] = 16; memcpy(&header[36], "data", 4); *(uint32_t *)&header[40] = m_buffer.size() * 2 + 44 - 44; @@ -377,24 +377,24 @@ public: } // add data to the file - template - void add(ymfm_output<_Outputs> output) + template + void add(ymfm_output output) { - int16_t sum[_Channels] = { 0 }; - for (int index = 0; index < _Outputs; index++) - sum[index % _Channels] += output.data[index]; - for (int index = 0; index < _Channels; index++) + int16_t sum[Channels] = { 0 }; + for (int index = 0; index < Outputs; index++) + sum[index % Channels] += output.data[index]; + for (int index = 0; index < Channels; index++) m_buffer.push_back(sum[index]); } // add data to the file, using a reference - template - void add(ymfm_output<_Outputs> output, ymfm_output<_Outputs> const &ref) + template + void add(ymfm_output output, ymfm_output const &ref) { - int16_t sum[_Channels] = { 0 }; - for (int index = 0; index < _Outputs; index++) - sum[index % _Channels] += output.data[index] - ref.data[index]; - for (int index = 0; index < _Channels; index++) + int16_t sum[Channels] = { 0 }; + for (int index = 0; index < Outputs; index++) + sum[index % Channels] += output.data[index] - ref.data[index]; + for (int index = 0; index < Channels; index++) m_buffer.push_back(sum[index]); } diff --git a/src/sound/ymfm/ymfm_fm.h b/src/sound/ymfm/ymfm_fm.h index 7c92c0f82..81795f8fe 100644 --- a/src/sound/ymfm/ymfm_fm.h +++ b/src/sound/ymfm/ymfm_fm.h @@ -33,7 +33,7 @@ #pragma once -#define DEBUG_LOG_WAVFILES (0) +#define YMFM_DEBUG_LOG_WAVFILES (0) namespace ymfm { @@ -401,7 +401,7 @@ public: // compute sample rate uint32_t sample_rate(uint32_t baseclock) const { -#if (DEBUG_LOG_WAVFILES) +#if (YMFM_DEBUG_LOG_WAVFILES) for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) m_wavfile[chnum].set_samplerate(baseclock / (m_clock_prescale * OPERATORS)); #endif @@ -453,7 +453,7 @@ protected: RegisterType m_regs; // register accessor std::unique_ptr> m_channel[CHANNELS]; // channel pointers std::unique_ptr> m_operator[OPERATORS]; // operator pointers -#if (DEBUG_LOG_WAVFILES) +#if (YMFM_DEBUG_LOG_WAVFILES) mutable ymfm_wavfile<1> m_wavfile[CHANNELS]; // for debugging #endif }; diff --git a/src/sound/ymfm/ymfm_fm.ipp b/src/sound/ymfm/ymfm_fm.ipp index 7e5109d59..14c1aa965 100644 --- a/src/sound/ymfm/ymfm_fm.ipp +++ b/src/sound/ymfm/ymfm_fm.ipp @@ -1185,6 +1185,7 @@ fm_engine_base::fm_engine_base(ymfm_interface &intf) : m_irq_mask(STATUS_TIMERA | STATUS_TIMERB), m_irq_state(0), m_timer_running{0,0}, + m_total_clocks(0), m_active_channels(ALL_CHANNELS), m_modified_channels(ALL_CHANNELS), m_prepare_count(0) @@ -1200,7 +1201,7 @@ fm_engine_base::fm_engine_base(ymfm_interface &intf) : for (uint32_t opnum = 0; opnum < OPERATORS; opnum++) m_operator[opnum] = std::make_unique>(*this, RegisterType::operator_offset(opnum)); -#if (DEBUG_LOG_WAVFILES) +#if (YMFM_DEBUG_LOG_WAVFILES) for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) m_wavfile[chnum].set_index(chnum); #endif @@ -1332,7 +1333,7 @@ void fm_engine_base::output(output_data &output, uint32_t rshift, chanmask &= debug::GLOBAL_FM_CHANNEL_MASK; // mask out inactive channels - if (!DEBUG_LOG_WAVFILES) + if (!YMFM_DEBUG_LOG_WAVFILES) chanmask &= m_active_channels; // handle the rhythm case, where some of the operators are dedicated @@ -1351,7 +1352,7 @@ void fm_engine_base::output(output_data &output, uint32_t rshift, for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) if (bitfield(chanmask, chnum)) { -#if (DEBUG_LOG_WAVFILES) +#if (YMFM_DEBUG_LOG_WAVFILES) auto reference = output; #endif if (chnum == 6) @@ -1364,7 +1365,7 @@ void fm_engine_base::output(output_data &output, uint32_t rshift, m_channel[chnum]->output_4op(output, rshift, clipmax); else m_channel[chnum]->output_2op(output, rshift, clipmax); -#if (DEBUG_LOG_WAVFILES) +#if (YMFM_DEBUG_LOG_WAVFILES) m_wavfile[chnum].add(output, reference); #endif } @@ -1375,14 +1376,14 @@ void fm_engine_base::output(output_data &output, uint32_t rshift, for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) if (bitfield(chanmask, chnum)) { -#if (DEBUG_LOG_WAVFILES) +#if (YMFM_DEBUG_LOG_WAVFILES) auto reference = output; #endif if (m_channel[chnum]->is4op()) m_channel[chnum]->output_4op(output, rshift, clipmax); else m_channel[chnum]->output_2op(output, rshift, clipmax); -#if (DEBUG_LOG_WAVFILES) +#if (YMFM_DEBUG_LOG_WAVFILES) m_wavfile[chnum].add(output, reference); #endif } diff --git a/src/sound/ymfm/ymfm_opl.cpp b/src/sound/ymfm/ymfm_opl.cpp index 86215c5b2..499bfceef 100644 --- a/src/sound/ymfm/ymfm_opl.cpp +++ b/src/sound/ymfm/ymfm_opl.cpp @@ -100,6 +100,11 @@ opl_registers_base::opl_registers_base() : } } } + + // OPL3/OPL4 have dynamic operators, so initialize the fourop_enable value here + // since operator_map() is called right away, prior to reset() + if (Revision > 2) + m_regdata[0x104 % REGISTERS] = 0; } @@ -1710,9 +1715,15 @@ uint8_t ymf278b::read_status() uint8_t ymf278b::read_data_pcm() { - // write to FM + // read from PCM if (bitfield(m_address, 9) != 0) - return m_pcm.read(m_address & 0xff); + { + uint8_t result = m_pcm.read(m_address & 0xff); + if ((m_address & 0xff) == 0x02) + result |= 0x20; + + return result; + } return 0; } diff --git a/src/sound/ymfm/ymfm_pcm.cpp b/src/sound/ymfm/ymfm_pcm.cpp index 50595133b..34417490c 100644 --- a/src/sound/ymfm/ymfm_pcm.cpp +++ b/src/sound/ymfm/ymfm_pcm.cpp @@ -46,7 +46,6 @@ namespace ymfm void pcm_registers::reset() { std::fill_n(&m_regdata[0], REGISTERS, 0); - m_regdata[0x02] = 0x20; m_regdata[0xf8] = 0x1b; }