From a0f0c863c99af3060efdbc383e555d401ec316fe Mon Sep 17 00:00:00 2001 From: tildearrow Date: Thu, 17 Oct 2024 02:53:08 -0500 Subject: [PATCH] OPN/A/B: fix CSM when using ymfm and now there's a crash --- src/engine/platform/fmshared_OPN.h | 14 ++++++++++++++ src/engine/platform/genesis.cpp | 8 ++++---- src/engine/platform/genesis.h | 15 +-------------- src/engine/platform/ym2203.cpp | 2 +- src/engine/platform/ym2203.h | 10 +++------- src/engine/platform/ym2203ext.cpp | 3 +-- src/engine/platform/ym2608.cpp | 5 ++--- src/engine/platform/ym2608.h | 6 +++--- src/engine/platform/ym2610.cpp | 4 ++-- src/engine/platform/ym2610.h | 4 ++-- src/engine/platform/ym2610b.cpp | 3 +-- src/engine/platform/ym2610b.h | 4 ++-- src/engine/platform/ym2610shared.h | 2 +- 13 files changed, 37 insertions(+), 43 deletions(-) diff --git a/src/engine/platform/fmshared_OPN.h b/src/engine/platform/fmshared_OPN.h index 65f9700c4..6c29ecf93 100644 --- a/src/engine/platform/fmshared_OPN.h +++ b/src/engine/platform/fmshared_OPN.h @@ -22,6 +22,7 @@ #include "fmsharedbase.h" #include "../../../extern/opn/ym3438.h" +#include "sound/ymfm/ymfm_opn.h" #define PLEASE_HELP_ME(_targetChan) \ int boundaryBottom=parent->calcBaseFreq(chipClock,CHIP_FREQBASE,0,false); \ @@ -86,6 +87,19 @@ #define IS_EXTCH_MUTED (isOpMuted[0] && isOpMuted[1] && isOpMuted[2] && isOpMuted[3]) +class DivOPNInterface: public ymfm::ymfm_interface { + int setA, setB; + int countA, countB; + + public: + void clock(int cycles=144); + void ymfm_set_timer(uint32_t tnum, int32_t duration_in_clocks); + DivOPNInterface(): + ymfm::ymfm_interface(), + countA(0), + countB(0) {} +}; + class DivPlatformOPN: public DivPlatformFMBase { protected: const unsigned short ADDR_MULT_DT=0x30; diff --git a/src/engine/platform/genesis.cpp b/src/engine/platform/genesis.cpp index 4bf56581e..903d97a60 100644 --- a/src/engine/platform/genesis.cpp +++ b/src/engine/platform/genesis.cpp @@ -28,7 +28,7 @@ #define IS_REALLY_MUTED(x) (isMuted[x] && (x<5 || !softPCM || (isMuted[5] && isMuted[6]))) -void DivYM2612Interface::ymfm_set_timer(uint32_t tnum, int32_t duration_in_clocks) { +void DivOPNInterface::ymfm_set_timer(uint32_t tnum, int32_t duration_in_clocks) { if (tnum==1) { setB=duration_in_clocks; } else if (tnum==0) { @@ -36,16 +36,16 @@ void DivYM2612Interface::ymfm_set_timer(uint32_t tnum, int32_t duration_in_clock } } -void DivYM2612Interface::clock() { +void DivOPNInterface::clock(int cycles) { if (setA>=0) { - countA-=144; + countA-=cycles; if (countA<0) { m_engine->engine_timer_expired(0); countA+=setA; } } if (setB>=0) { - countB-=144; + countB-=cycles; if (countB<0) { m_engine->engine_timer_expired(1); countB+=setB; diff --git a/src/engine/platform/genesis.h b/src/engine/platform/genesis.h index bd911d0ae..f239cea98 100644 --- a/src/engine/platform/genesis.h +++ b/src/engine/platform/genesis.h @@ -26,19 +26,6 @@ extern "C" { #include "../../../extern/YMF276-LLE/fmopn2.h" } -class DivYM2612Interface: public ymfm::ymfm_interface { - int setA, setB; - int countA, countB; - - public: - void clock(); - void ymfm_set_timer(uint32_t tnum, int32_t duration_in_clocks); - DivYM2612Interface(): - ymfm::ymfm_interface(), - countA(0), - countB(0) {} -}; - class DivPlatformGenesis: public DivPlatformOPN { protected: const unsigned short chanOffs[6]={ @@ -83,7 +70,7 @@ class DivPlatformGenesis: public DivPlatformOPN { ymfm::ym2612* fm_ymfm; ymfm::ym2612::output_data out_ymfm; - DivYM2612Interface iface; + DivOPNInterface iface; int softPCMTimer; diff --git a/src/engine/platform/ym2203.cpp b/src/engine/platform/ym2203.cpp index 0f02848d4..d555e9610 100644 --- a/src/engine/platform/ym2203.cpp +++ b/src/engine/platform/ym2203.cpp @@ -21,7 +21,6 @@ #include "sound/ymfm/ymfm.h" #include "../engine.h" #include -#include #define CHIP_FREQBASE fmFreqBase #define CHIP_DIVIDER fmDivBase @@ -277,6 +276,7 @@ void DivPlatformYM2203::acquire_ymfm(short** buf, size_t len) { } fm->generate(&fmout); + iface.clock(24); os=((fmout.data[0]*fmVol)>>8)+(((fmout.data[1]+fmout.data[2]+fmout.data[3])*ssgVol)>>8); if (os<-32768) os=-32768; diff --git a/src/engine/platform/ym2203.h b/src/engine/platform/ym2203.h index 9113ffe9e..41315659d 100644 --- a/src/engine/platform/ym2203.h +++ b/src/engine/platform/ym2203.h @@ -28,10 +28,6 @@ extern "C" { #include "ay.h" -class DivYM2203Interface: public ymfm::ymfm_interface { - -}; - class DivPlatformYM2203: public DivPlatformOPN { protected: const unsigned short chanOffs[3]={ @@ -48,7 +44,7 @@ class DivPlatformYM2203: public DivPlatformOPN { ym3438_t fm_nuked; ymfm::ym2203* fm; ymfm::ym2203::output_data fmout; - DivYM2203Interface iface; + DivOPNInterface iface; fmopna_t fm_lle; unsigned int dacVal; unsigned int dacVal2; @@ -73,7 +69,7 @@ class DivPlatformYM2203: public DivPlatformOPN { void acquire_lle(short** buf, size_t len); public: - bool isCSM; + unsigned char isCSM; void acquire(short** buf, size_t len); void fillStream(std::vector& stream, int sRate, size_t len); int dispatch(DivCommand c); @@ -100,7 +96,7 @@ class DivPlatformYM2203: public DivPlatformOPN { DivPlatformYM2203(): DivPlatformOPN(2, 3, 6, 6, 6, 4720270.0, 36, 16), prescale(0x2d), - isCSM(false) {} + isCSM(0) {} ~DivPlatformYM2203(); }; #endif diff --git a/src/engine/platform/ym2203ext.cpp b/src/engine/platform/ym2203ext.cpp index 834994492..6b2ded8cd 100644 --- a/src/engine/platform/ym2203ext.cpp +++ b/src/engine/platform/ym2203ext.cpp @@ -19,7 +19,6 @@ #include "ym2203ext.h" #include "../engine.h" -#include #define CHIP_FREQBASE fmFreqBase #define CHIP_DIVIDER fmDivBase @@ -787,7 +786,7 @@ void DivPlatformYM2203Ext::quit() { } void DivPlatformYM2203Ext::setCSM(bool isCSM) { - this->isCSM=isCSM; + this->isCSM=isCSM?1:0; if (isCSM) { csmChan=3; } diff --git a/src/engine/platform/ym2608.cpp b/src/engine/platform/ym2608.cpp index a4d7db85f..3dcb002b6 100644 --- a/src/engine/platform/ym2608.cpp +++ b/src/engine/platform/ym2608.cpp @@ -18,11 +18,9 @@ */ #include "ym2608.h" -#include "sound/ymfm/ymfm.h" #include "../engine.h" #include "../../ta-log.h" #include -#include #define CHIP_FREQBASE fmFreqBase #define CHIP_DIVIDER fmDivBase @@ -462,6 +460,7 @@ void DivPlatformYM2608::acquire_ymfm(short** buf, size_t len) { } fm->generate(&fmout); + iface.clock(48); os[0]=((fmout.data[0]*fmVol)>>8)+((fmout.data[2]*ssgVol)>>8); if (os[0]<-32768) os[0]=-32768; @@ -2040,7 +2039,7 @@ int DivPlatformYM2608::init(DivEngine* p, int channels, int sugRate, const DivCo } void DivPlatformYM2608::setCSM(bool isCSM) { - this->isCSM=isCSM; + this->isCSM=isCSM?1:0; psgChanOffs=6+isCSM; // doing this hurts me... adpcmAChanOffs=9+isCSM; adpcmBChanOffs=15+isCSM; diff --git a/src/engine/platform/ym2608.h b/src/engine/platform/ym2608.h index 0ca851910..d226821a7 100644 --- a/src/engine/platform/ym2608.h +++ b/src/engine/platform/ym2608.h @@ -28,7 +28,7 @@ extern "C" { #include "ay.h" -class DivYM2608Interface: public ymfm::ymfm_interface { +class DivYM2608Interface: public DivOPNInterface { public: unsigned char* adpcmBMem; int sampleBank; @@ -92,7 +92,7 @@ class DivPlatformYM2608: public DivPlatformOPN { void acquire_lle(short** buf, size_t len); public: - bool isCSM; + unsigned char isCSM; void acquire(short** buf, size_t len); void fillStream(std::vector& stream, int sRate, size_t len); int dispatch(DivCommand c); @@ -127,7 +127,7 @@ class DivPlatformYM2608: public DivPlatformOPN { DivPlatformYM2608(): DivPlatformOPN(2, 6, 9, 15, 16, 9440540.0, 72, 32), prescale(0x2d), - isCSM(false) {} + isCSM(0) {} ~DivPlatformYM2608(); }; #endif diff --git a/src/engine/platform/ym2610.cpp b/src/engine/platform/ym2610.cpp index 3113accf1..5d2e23776 100644 --- a/src/engine/platform/ym2610.cpp +++ b/src/engine/platform/ym2610.cpp @@ -18,7 +18,6 @@ */ #include "ym2610.h" -#include const char* regCheatSheetYM2610[]={ // SSG @@ -395,6 +394,7 @@ void DivPlatformYM2610::acquire_ymfm(short** buf, size_t len) { } fm->generate(&fmout); + iface.clock(); os[0]+=((fmout.data[0]*fmVol)>>8)+((fmout.data[2]*ssgVol)>>8); if (os[0]<-32768) os[0]=-32768; @@ -1791,7 +1791,7 @@ int DivPlatformYM2610::init(DivEngine* p, int channels, int sugRate, const DivCo } void DivPlatformYM2610::setCSM(bool isCSM) { - this->isCSM=isCSM; + this->isCSM=isCSM?1:0; psgChanOffs=4+isCSM; // doing this hurts me... adpcmAChanOffs=7+isCSM; adpcmBChanOffs=13+isCSM; diff --git a/src/engine/platform/ym2610.h b/src/engine/platform/ym2610.h index d5c6ea8d0..92458be88 100644 --- a/src/engine/platform/ym2610.h +++ b/src/engine/platform/ym2610.h @@ -45,7 +45,7 @@ class DivPlatformYM2610: public DivPlatformYM2610Base { void acquire_lle(short** buf, size_t len); public: - bool isCSM; + unsigned char isCSM; void acquire(short** buf, size_t len); int dispatch(DivCommand c); void* getChanState(int chan); @@ -71,7 +71,7 @@ class DivPlatformYM2610: public DivPlatformYM2610Base { void quit(); DivPlatformYM2610(): DivPlatformYM2610Base(1,4,7,13,14), - isCSM(false) {} + isCSM(0) {} ~DivPlatformYM2610(); }; #endif diff --git a/src/engine/platform/ym2610b.cpp b/src/engine/platform/ym2610b.cpp index f23ac5c63..af2211755 100644 --- a/src/engine/platform/ym2610b.cpp +++ b/src/engine/platform/ym2610b.cpp @@ -18,7 +18,6 @@ */ #include "ym2610b.h" -#include const char* regCheatSheetYM2610B[]={ // SSG @@ -1864,7 +1863,7 @@ int DivPlatformYM2610B::init(DivEngine* p, int channels, int sugRate, const DivC } void DivPlatformYM2610B::setCSM(bool isCSM) { - this->isCSM=isCSM; + this->isCSM=isCSM?1:0; psgChanOffs=6+isCSM; // doing this hurts me... adpcmAChanOffs=9+isCSM; adpcmBChanOffs=15+isCSM; diff --git a/src/engine/platform/ym2610b.h b/src/engine/platform/ym2610b.h index 67021412f..2858db97d 100644 --- a/src/engine/platform/ym2610b.h +++ b/src/engine/platform/ym2610b.h @@ -41,7 +41,7 @@ class DivPlatformYM2610B: public DivPlatformYM2610Base { void acquire_lle(short** buf, size_t len); public: - bool isCSM; + unsigned char isCSM; void acquire(short** buf, size_t len); int dispatch(DivCommand c); void* getChanState(int chan); @@ -67,7 +67,7 @@ class DivPlatformYM2610B: public DivPlatformYM2610Base { void quit(); DivPlatformYM2610B(): DivPlatformYM2610Base(2,6,9,15,16), - isCSM(false) {} + isCSM(0) {} ~DivPlatformYM2610B(); }; #endif diff --git a/src/engine/platform/ym2610shared.h b/src/engine/platform/ym2610shared.h index 1e60af92e..bcec11829 100644 --- a/src/engine/platform/ym2610shared.h +++ b/src/engine/platform/ym2610shared.h @@ -34,7 +34,7 @@ extern "C" { #define CHIP_FREQBASE fmFreqBase #define CHIP_DIVIDER fmDivBase -class DivYM2610Interface: public ymfm::ymfm_interface { +class DivYM2610Interface: public DivOPNInterface { public: unsigned char* adpcmAMem; unsigned char* adpcmBMem;