Skip to content

Commit

Permalink
Merge pull request #72 from jpcima/vgm2608
Browse files Browse the repository at this point in the history
support YM2608 VGM
  • Loading branch information
Wohlstand authored Mar 27, 2019
2 parents 496a615 + 123eb21 commit f4f9c73
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
19 changes: 17 additions & 2 deletions src/FileFormats/format_vgm_import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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(&reg), 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(&reg), 1);
file.read(char_p(&val), 1);
pseudoChip.passReg(1, reg, val);
break;

case 0x56://Write YM2608 port 0
file.read(char_p(&reg), 1);
file.read(char_p(&val), 1);
pseudoChip2608.passReg(0, reg, val);
break;
case 0x57://Write YM2608 port 1
file.read(char_p(&reg), 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
Expand All @@ -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
Expand Down
36 changes: 26 additions & 10 deletions src/FileFormats/ym2612_to_wopi.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#include <stdint.h>
#include <memory>
#include <cstring>
#include <QSet>
#include <QList>
Expand All @@ -11,29 +12,43 @@

class RawYm2612ToWopi
{
struct InstrumentData
{
QSet<QByteArray> cache;
QList<FmBank::Instrument> 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<QByteArray> m_cache;
QList<FmBank::Instrument> m_caughtInstruments;
std::shared_ptr<InstrumentData> 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)
Expand Down Expand Up @@ -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++)
{
Expand Down Expand Up @@ -155,25 +172,24 @@ 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);
}
}
}
}

const QList<FmBank::Instrument> &caughtInstruments()
{
return m_caughtInstruments;
return m_insdata->caughtInstruments;
}

};

#endif // YM2612_TO_WOPI_HPP

0 comments on commit f4f9c73

Please sign in to comment.