diff --git a/src/FileFormats/format_vgm_import.cpp b/src/FileFormats/format_vgm_import.cpp index 305a071..b0f6942 100644 --- a/src/FileFormats/format_vgm_import.cpp +++ b/src/FileFormats/format_vgm_import.cpp @@ -34,6 +34,9 @@ bool VGM_Importer::detect(const QString &, char *magic) FfmtErrCode VGM_Importer::loadFile(QString filePath, FmBank &bank) { RawYm2612ToWopi pseudoChip; + RawYm2612ToWopi pseudoChip2608; + pseudoChip2608.shareInstruments(pseudoChip); + char magic[4]; uint8_t numb[4]; @@ -68,17 +71,28 @@ FfmtErrCode VGM_Importer::loadFile(QString filePath, FmBank &bank) file.read(char_p(&cmd), 1); switch(cmd) { - case 0x52://Write port 0 + case 0x52://Write YM2612 port 0 file.read(char_p(®), 1); file.read(char_p(&val), 1); pseudoChip.passReg(0, reg, val); break; - case 0x53://Write port 1 + case 0x53://Write YM2612 port 1 file.read(char_p(®), 1); file.read(char_p(&val), 1); pseudoChip.passReg(1, reg, val); break; + case 0x56://Write YM2608 port 0 + file.read(char_p(®), 1); + file.read(char_p(&val), 1); + pseudoChip2608.passReg(0, reg, val); + break; + case 0x57://Write YM2608 port 1 + file.read(char_p(®), 1); + file.read(char_p(&val), 1); + pseudoChip2608.passReg(1, reg, val); + break; + case 0x61://Wait samples case 0x62://Wait samples case 0x63://Wait samples @@ -101,6 +115,7 @@ FfmtErrCode VGM_Importer::loadFile(QString filePath, FmBank &bank) if(cmd == 0x61) file.seek(file.pos() + 2); pseudoChip.doAnalyzeState(); + pseudoChip2608.doAnalyzeState(); break; case 0x66://End of sound data diff --git a/src/FileFormats/ym2612_to_wopi.hpp b/src/FileFormats/ym2612_to_wopi.hpp index 8543341..44fb0d6 100644 --- a/src/FileFormats/ym2612_to_wopi.hpp +++ b/src/FileFormats/ym2612_to_wopi.hpp @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -11,29 +12,43 @@ class RawYm2612ToWopi { + struct InstrumentData + { + QSet cache; + QList caughtInstruments; + }; + uint8_t m_ymram[2][0xFF]; char m_magic[4]; bool m_keys[6]; uint8_t m_lfoVal = 0; bool m_dacOn = false; - QSet m_cache; - QList m_caughtInstruments; + std::shared_ptr m_insdata; + public: RawYm2612ToWopi() { + m_insdata.reset(new InstrumentData); reset(); } void reset() { + InstrumentData &insdata = *m_insdata; + insdata.cache.clear(); + insdata.caughtInstruments.clear(); + std::memset(m_magic, 0, 4); std::memset(m_ymram[0], 0, 0xFF); std::memset(m_ymram[1], 0, 0xFF); std::memset(m_keys, 0, sizeof(bool) * 6); m_lfoVal = 0; m_dacOn = false; - m_cache.clear(); - m_caughtInstruments.clear(); + } + + void shareInstruments(RawYm2612ToWopi &other) + { + m_insdata = other.m_insdata; } void passReg(uint8_t port, uint8_t reg, uint8_t val) @@ -73,6 +88,8 @@ class RawYm2612ToWopi void doAnalyzeState() { + InstrumentData &insdata = *m_insdata; + /* Analyze dumps and take the instruments */ for(size_t i = 0; i < 2; i++) { @@ -155,15 +172,15 @@ class RawYm2612ToWopi insRaw[1 + OPERATOR3*7] = (char)ins.getRegLevel(OPERATOR3); insRaw[1 + OPERATOR4*7] = (char)ins.getRegLevel(OPERATOR4); - if(!m_cache.contains(insRaw)) + if(!insdata.cache.contains(insRaw)) { std::snprintf(ins.name, 32, "Ins %d, channel %d", - m_caughtInstruments.size(), + insdata.caughtInstruments.size(), (int)(ch + (3 * i)) ); - m_caughtInstruments.push_back(ins); - m_cache.insert(insRaw); + insdata.caughtInstruments.push_back(ins); + insdata.cache.insert(insRaw); } } } @@ -171,9 +188,8 @@ class RawYm2612ToWopi const QList &caughtInstruments() { - return m_caughtInstruments; + return m_insdata->caughtInstruments; } - }; #endif // YM2612_TO_WOPI_HPP