From 4a7e76c4488c9ae4d426484508d2a42cc07533de Mon Sep 17 00:00:00 2001 From: Waldemar Pawlaszek Date: Thu, 22 Dec 2022 22:40:29 +0100 Subject: [PATCH] Renaming new POKEY core to AltASAP. Added core selection. --- CMakeLists.txt | 2 +- src/engine/dispatchContainer.cpp | 1 + src/engine/platform/pokey.cpp | 51 +++++++++++++++---- src/engine/platform/pokey.h | 8 ++- .../sound/pokey/{Pokey.cpp => AltASAP.cpp} | 11 ++-- .../sound/pokey/{Pokey.hpp => AltASAP.hpp} | 4 +- src/gui/gui.h | 2 + src/gui/settings.cpp | 15 +++++- 8 files changed, 71 insertions(+), 23 deletions(-) rename src/engine/platform/sound/pokey/{Pokey.cpp => AltASAP.cpp} (95%) rename src/engine/platform/sound/pokey/{Pokey.hpp => AltASAP.hpp} (75%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b6bd139..6e37c88b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -425,7 +425,7 @@ src/engine/platform/sound/ymfm/ymfm_ssg.cpp src/engine/platform/sound/lynx/Mikey.cpp src/engine/platform/sound/pokey/mzpokeysnd.c -src/engine/platform/sound/pokey/Pokey.cpp +src/engine/platform/sound/pokey/AltASAP.cpp src/engine/platform/sound/qsound.c diff --git a/src/engine/dispatchContainer.cpp b/src/engine/dispatchContainer.cpp index 710a2de4..161aa4e1 100644 --- a/src/engine/dispatchContainer.cpp +++ b/src/engine/dispatchContainer.cpp @@ -341,6 +341,7 @@ void DivDispatchContainer::init(DivSystem sys, DivEngine* eng, int chanCount, do break; case DIV_SYSTEM_POKEY: dispatch=new DivPlatformPOKEY; + ((DivPlatformPOKEY*)dispatch)->setAltASAP(eng->getConfInt("pokeyCore",0)==1); break; case DIV_SYSTEM_QSOUND: dispatch=new DivPlatformQSound; diff --git a/src/engine/platform/pokey.cpp b/src/engine/platform/pokey.cpp index 4a695587..8e1bef25 100644 --- a/src/engine/platform/pokey.cpp +++ b/src/engine/platform/pokey.cpp @@ -65,18 +65,22 @@ const char** DivPlatformPOKEY::getRegisterSheet() { } void DivPlatformPOKEY::acquire(short* bufL, short* bufR, size_t start, size_t len) { + if (useAltASAP) + acquireASAP(bufL, start, len); + else + acquireMZ(bufL, start, len); +} + +void DivPlatformPOKEY::acquireMZ(short* buf, size_t start, size_t len) { for (size_t h=start; hwrite( w.addr, w.val ); Update_pokey_sound_mz(&pokey,w.addr,w.val,0); regPool[w.addr&0x0f]=w.val; writes.pop(); } - mzpokeysnd_process_16(&pokey,&bufL[h],1); - mPokey2->sampleAudio( &bufL[h], 1 ); - bufL[h] *= 160; + mzpokeysnd_process_16(&pokey,&buf[h],1); if (++oscBufDelay>=14) { oscBufDelay=0; @@ -86,6 +90,23 @@ void DivPlatformPOKEY::acquire(short* bufL, short* bufR, size_t start, size_t le oscBuf[3]->data[oscBuf[3]->needle++]=pokey.outvol_3<<11; } } +} + +void DivPlatformPOKEY::acquireASAP(short* buf, size_t start, size_t len) { + while (!writes.empty()) { + QueuedWrite w=writes.front(); + altASAP->write(w.addr, w.val); + writes.pop(); + } + + for (size_t h=start; h=14) { + oscBufDelay=0; + buf[h]=altASAP->sampleAudio(oscBuf); + } else { + buf[h]=altASAP->sampleAudio(); + } + } } void DivPlatformPOKEY::tick(bool sysTick) { @@ -373,8 +394,10 @@ DivDispatchOscBuffer* DivPlatformPOKEY::getOscBuffer(int ch) { } unsigned char* DivPlatformPOKEY::getRegisterPool() { - return const_cast( mPokey2->getRegisterPool() ); - return regPool; + if (useAltASAP) + return const_cast(altASAP->getRegisterPool()); + else + return regPool; } int DivPlatformPOKEY::getRegisterPoolSize() { @@ -392,8 +415,10 @@ void DivPlatformPOKEY::reset() { addWrite(0xffffffff,0); } - ResetPokeyState(&pokey); - mPokey2->reset(); + if (useAltASAP) + altASAP->reset(); + else + ResetPokeyState(&pokey); audctl=0; audctlChanged=true; @@ -425,7 +450,8 @@ void DivPlatformPOKEY::setFlags(const DivConfig& flags) { oscBuf[i]->rate=rate/14; } - mPokey2 = std::make_unique( chipClock, chipClock ); + if (useAltASAP) + altASAP=std::make_unique(chipClock, chipClock); } @@ -447,7 +473,8 @@ int DivPlatformPOKEY::init(DivEngine* p, int channels, int sugRate, const DivCon oscBuf[i]=new DivDispatchOscBuffer; } - MZPOKEYSND_Init(&pokey); + if (!useAltASAP) + MZPOKEYSND_Init(&pokey); setFlags(flags); reset(); @@ -458,6 +485,10 @@ void DivPlatformPOKEY::quit() { for (int i=0; i<4; i++) { delete oscBuf[i]; } +} + +void DivPlatformPOKEY::setAltASAP(bool value){ + useAltASAP=value; } DivPlatformPOKEY::~DivPlatformPOKEY() { diff --git a/src/engine/platform/pokey.h b/src/engine/platform/pokey.h index 9560e113..a326bb37 100644 --- a/src/engine/platform/pokey.h +++ b/src/engine/platform/pokey.h @@ -27,7 +27,7 @@ extern "C" { #include "sound/pokey/mzpokeysnd.h" } -#include "sound/pokey/Pokey.hpp" +#include "sound/pokey/AltASAP.hpp" class DivPlatformPOKEY: public DivDispatch { @@ -52,12 +52,15 @@ class DivPlatformPOKEY: public DivDispatch { bool audctlChanged; unsigned char oscBufDelay; PokeyState pokey; - std::unique_ptr mPokey2; + std::unique_ptr altASAP; + bool useAltASAP; unsigned char regPool[16]; friend void putDispatchChip(void*,int); friend void putDispatchChan(void*,int,int); public: void acquire(short* bufL, short* bufR, size_t start, size_t len); + void acquireMZ(short* buf, size_t start, size_t len); + void acquireASAP(short* buf, size_t start, size_t len); int dispatch(DivCommand c); void* getChanState(int chan); DivMacroInt* getChanMacroInt(int ch); @@ -77,6 +80,7 @@ class DivPlatformPOKEY: public DivDispatch { const char** getRegisterSheet(); int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags); void quit(); + void setAltASAP(bool useAltASAP); ~DivPlatformPOKEY(); }; diff --git a/src/engine/platform/sound/pokey/Pokey.cpp b/src/engine/platform/sound/pokey/AltASAP.cpp similarity index 95% rename from src/engine/platform/sound/pokey/Pokey.cpp rename to src/engine/platform/sound/pokey/AltASAP.cpp index f9f110d2..37174513 100644 --- a/src/engine/platform/sound/pokey/Pokey.cpp +++ b/src/engine/platform/sound/pokey/AltASAP.cpp @@ -20,14 +20,14 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "Pokey.hpp" +#include "AltASAP.hpp" #include #include #include #include #include -namespace Test +namespace AltASAP { namespace @@ -631,12 +631,9 @@ void Pokey::write( uint8_t address, uint8_t value ) mPokey->write( address, value ); } -void Pokey::sampleAudio( int16_t* buf, size_t size, DivDispatchOscBuffer** oscb ) +int16_t Pokey::sampleAudio( DivDispatchOscBuffer** oscb ) { - for ( size_t i = 0; i < size; ++i ) - { - buf[i] = mPokey->sampleAudio( oscb ); - } + return mPokey->sampleAudio( oscb ) * 160; //just some magick value to match the audio level of mzpokeysnd } uint8_t const* Pokey::getRegisterPool() diff --git a/src/engine/platform/sound/pokey/Pokey.hpp b/src/engine/platform/sound/pokey/AltASAP.hpp similarity index 75% rename from src/engine/platform/sound/pokey/Pokey.hpp rename to src/engine/platform/sound/pokey/AltASAP.hpp index 09a21c4a..930bf6aa 100644 --- a/src/engine/platform/sound/pokey/Pokey.hpp +++ b/src/engine/platform/sound/pokey/AltASAP.hpp @@ -6,7 +6,7 @@ // can you forgive me #include "../../../dispatch.h" -namespace Test +namespace AltASAP { class PokeyPimpl; @@ -19,7 +19,7 @@ public: ~Pokey(); void write( uint8_t address, uint8_t value ); - void sampleAudio( int16_t* buf, size_t size, DivDispatchOscBuffer** oscb = NULL ); + int16_t sampleAudio( DivDispatchOscBuffer** oscb = nullptr ); uint8_t const* getRegisterPool(); diff --git a/src/gui/gui.h b/src/gui/gui.h index 805ce67c..bc12fe2c 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -1177,6 +1177,7 @@ class FurnaceGUI { int nesCore; int fdsCore; int c64Core; + int pokeyCore; int pcSpeakerOutMethod; String yrw801Path; String tg100Path; @@ -1309,6 +1310,7 @@ class FurnaceGUI { nesCore(0), fdsCore(0), c64Core(1), + pokeyCore(0), pcSpeakerOutMethod(0), yrw801Path(""), tg100Path(""), diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index d40e4dac..95f83d94 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -102,6 +102,11 @@ const char* c64Cores[]={ "reSIDfp" }; +const char* pokeyCores[]={ + "mzpokeysnd", + "altASAP" +}; + const char* pcspkrOutMethods[]={ "evdev SND_TONE", "KIOCSOUND on /dev/tty1", @@ -1069,6 +1074,10 @@ void FurnaceGUI::drawSettings() { ImGui::SameLine(); ImGui::Combo("##C64Core",&settings.c64Core,c64Cores,2); + ImGui::Text("POKEY core"); + ImGui::SameLine(); + ImGui::Combo("##POKEYCore",&settings.pokeyCore,pokeyCores,2); + ImGui::Separator(); ImGui::Text("PC Speaker strategy"); @@ -2336,6 +2345,7 @@ void FurnaceGUI::syncSettings() { settings.nesCore=e->getConfInt("nesCore",0); settings.fdsCore=e->getConfInt("fdsCore",0); settings.c64Core=e->getConfInt("c64Core",1); + settings.pokeyCore=e->getConfInt("pokeyCore",0); settings.pcSpeakerOutMethod=e->getConfInt("pcSpeakerOutMethod",0); settings.yrw801Path=e->getConfString("yrw801Path",""); settings.tg100Path=e->getConfString("tg100Path",""); @@ -2461,6 +2471,7 @@ void FurnaceGUI::syncSettings() { clampSetting(settings.nesCore,0,1); clampSetting(settings.fdsCore,0,1); clampSetting(settings.c64Core,0,1); + clampSetting(settings.pokeyCore,0,1); clampSetting(settings.pcSpeakerOutMethod,0,4); clampSetting(settings.mainFont,0,6); clampSetting(settings.patFont,0,6); @@ -2604,7 +2615,8 @@ void FurnaceGUI::commitSettings() { settings.snCore!=e->getConfInt("snCore",0) || settings.nesCore!=e->getConfInt("nesCore",0) || settings.fdsCore!=e->getConfInt("fdsCore",0) || - settings.c64Core!=e->getConfInt("c64Core",1) + settings.c64Core!=e->getConfInt("c64Core",1) || + settings.pokeyCore!=e->getConfInt("pokeyCore",0) ); e->setConf("mainFontSize",settings.mainFontSize); @@ -2624,6 +2636,7 @@ void FurnaceGUI::commitSettings() { e->setConf("nesCore",settings.nesCore); e->setConf("fdsCore",settings.fdsCore); e->setConf("c64Core",settings.c64Core); + e->setConf("pokeyCore",settings.pokeyCore); e->setConf("pcSpeakerOutMethod",settings.pcSpeakerOutMethod); e->setConf("yrw801Path",settings.yrw801Path); e->setConf("tg100Path",settings.tg100Path);