From d3edc58cb123436cd971a547aeab4a64c9fa3db7 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Mon, 23 May 2022 03:13:22 -0500 Subject: [PATCH] MSM6295: add clock rate flag --- src/engine/platform/msm6295.cpp | 24 ++++++++++++++++++++--- src/engine/platform/msm6295.h | 4 +++- src/engine/platform/sound/oki/msm6295.cpp | 11 ++++++++--- src/gui/sysConf.cpp | 16 +++++++++++++++ 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/engine/platform/msm6295.cpp b/src/engine/platform/msm6295.cpp index 414792313..64ec6b0aa 100644 --- a/src/engine/platform/msm6295.cpp +++ b/src/engine/platform/msm6295.cpp @@ -44,7 +44,7 @@ void DivPlatformMSM6295::acquire(short* bufL, short* bufR, size_t start, size_t QueuedWrite& w=writes.front(); msm->command_w(w.val); writes.pop(); - delay=64; + delay=32; } } else { delay--; @@ -53,6 +53,11 @@ void DivPlatformMSM6295::acquire(short* bufL, short* bufR, size_t start, size_t msm->tick(); bufL[h]=msm->out()<<4; + + if (++updateOsc>=64) { + updateOsc=0; + // TODO: per-channel osc + } } } @@ -295,6 +300,19 @@ void DivPlatformMSM6295::renderSamples() { } } +void DivPlatformMSM6295::setFlags(unsigned int flags) { + if (flags&1) { + chipClock=8448000; + } else { + chipClock=8000000; + } + rate=chipClock/((flags&2)?6:24); + for (int i=0; i<4; i++) { + isMuted[i]=false; + oscBuf[i]->rate=rate/22; + } +} + int DivPlatformMSM6295::init(DivEngine* p, int channels, int sugRate, unsigned int flags) { parent=p; adpcmMem=new unsigned char[getSampleMemCapacity(0)]; @@ -303,13 +321,13 @@ int DivPlatformMSM6295::init(DivEngine* p, int channels, int sugRate, unsigned i iface.sampleBank=0; dumpWrites=false; skipRegisterWrites=false; + updateOsc=0; for (int i=0; i<4; i++) { isMuted[i]=false; oscBuf[i]=new DivDispatchOscBuffer; } - chipClock=8000000; - rate=chipClock/8; msm=new msm6295_core(iface); + setFlags(flags); reset(); return 4; } diff --git a/src/engine/platform/msm6295.h b/src/engine/platform/msm6295.h index 4f6cd4ce1..bedaab41c 100644 --- a/src/engine/platform/msm6295.h +++ b/src/engine/platform/msm6295.h @@ -98,7 +98,7 @@ class DivPlatformMSM6295: public DivDispatch { DivMSM6295Interface iface; unsigned char sampleBank; - int delay; + int delay, updateOsc; bool extMode; @@ -123,12 +123,14 @@ class DivPlatformMSM6295: public DivDispatch { void notifyInsDeletion(void* ins); void poke(unsigned int addr, unsigned short val); void poke(std::vector& wlist); + void setFlags(unsigned int flags); const char** getRegisterSheet(); const char* getEffectName(unsigned char effect); const void* getSampleMem(int index); size_t getSampleMemCapacity(int index); size_t getSampleMemUsage(int index); void renderSamples(); + int init(DivEngine* parent, int channels, int sugRate, unsigned int flags); void quit(); ~DivPlatformMSM6295(); diff --git a/src/engine/platform/sound/oki/msm6295.cpp b/src/engine/platform/sound/oki/msm6295.cpp index 29ca31f9d..6d7b860ce 100644 --- a/src/engine/platform/sound/oki/msm6295.cpp +++ b/src/engine/platform/sound/oki/msm6295.cpp @@ -53,6 +53,11 @@ #include "msm6295.hpp" +#define CORE_DIVIDER 3 + +#define CHANNEL_DELAY (15/CORE_DIVIDER) +#define MASTER_DELAY (33/CORE_DIVIDER) + void msm6295_core::tick() { // command handler @@ -60,7 +65,7 @@ void msm6295_core::tick() { if (bitfield(m_command, 7)) // play voice { - if ((++m_clock) >= ((15 * (m_ss ? 5 : 4)))) + if ((++m_clock) >= ((CHANNEL_DELAY * (m_ss ? 5 : 4)))) { m_clock = 0; if (bitfield(m_next_command, 4, 4) != 0) @@ -84,7 +89,7 @@ void msm6295_core::tick() } else if (bitfield(m_next_command, 7)) // select phrase { - if ((++m_clock) >= ((15 * (m_ss ? 5 : 4)))) + if ((++m_clock) >= ((CHANNEL_DELAY * (m_ss ? 5 : 4)))) { m_clock = 0; m_command = m_next_command; @@ -154,7 +159,7 @@ void msm6295_core::voice_t::tick() else { // playback - if ((++m_clock) >= ((33 * (m_host.m_ss ? 5 : 4)))) + if ((++m_clock) >= ((MASTER_DELAY * (m_host.m_ss ? 5 : 4)))) { m_clock = 0; bool is_end = (m_command != 0); diff --git a/src/gui/sysConf.cpp b/src/gui/sysConf.cpp index 392d3e3a6..a49db16b3 100644 --- a/src/gui/sysConf.cpp +++ b/src/gui/sysConf.cpp @@ -413,6 +413,22 @@ void FurnaceGUI::drawSysConf(int chan, DivSystem type, unsigned int& flags, bool } break; } + case DIV_SYSTEM_MSM6295: { + ImGui::Text("Clock rate:"); + if (ImGui::RadioButton("1MHz",flags==0)) { + copyOfFlags=0; + } + if (ImGui::RadioButton("1.056MHz",flags==1)) { + copyOfFlags=1; + } + if (ImGui::RadioButton("4MHz",flags==2)) { + copyOfFlags=2; + } + if (ImGui::RadioButton("4.224MHz",flags==3)) { + copyOfFlags=3; + } + break; + } case DIV_SYSTEM_GB: case DIV_SYSTEM_SWAN: case DIV_SYSTEM_VERA: