Skip to content

Commit

Permalink
Fix VRC7 period table assembly export
Browse files Browse the repository at this point in the history
  • Loading branch information
Gumball2415 committed Feb 17, 2024
1 parent d252309 commit e0abc0f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
16 changes: 7 additions & 9 deletions Source/ChunkRenderText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,25 +487,25 @@ void CChunkRenderText::WriteFileString(const CStringA &str, CFile *pFile) const

// These functions write to a separate file. CFile path to those separate files must be the same as export.

void CChunkRenderText::StoreNSFStub(stNSFHeader Header, bool Bankswitched, vibrato_t VibratoStyle, bool LinearPitch, int ActualNamcoChannels, bool IsAssembly) const
void CChunkRenderText::StoreNSFStub(unsigned char Expansion, bool Bankswitched, vibrato_t VibratoStyle, bool LinearPitch, int ActualNamcoChannels, bool IsAssembly) const
{
CString str;

str.Append(";\n; NSF stub file, used to define compile constants\n;\n\n");
str.Append("PACKAGE = 1\n");
str.Append("HAS_NSF_HEADER = 1\n");
str.Append("USE_AUX_DATA = 1\n");
if (Header.SoundChip & SNDCHIP_VRC6)
if (Expansion & SNDCHIP_VRC6)
str.Append("USE_VRC6 = 1\n");
if (Header.SoundChip & SNDCHIP_VRC7)
if (Expansion & SNDCHIP_VRC7)
str.Append("USE_VRC7 = 1\n");
if (Header.SoundChip & SNDCHIP_FDS)
if (Expansion & SNDCHIP_FDS)
str.Append("USE_FDS = 1\n");
if (Header.SoundChip & SNDCHIP_MMC5)
if (Expansion & SNDCHIP_MMC5)
str.Append("USE_MMC5 = 1\n");
if (Header.SoundChip & SNDCHIP_N163)
if (Expansion & SNDCHIP_N163)
str.Append("USE_N163 = 1\n");
if (Header.SoundChip & SNDCHIP_S5B)
if (Expansion & SNDCHIP_S5B)
str.Append("USE_S5B = 1\n");
if (Bankswitched)
str.Append("USE_BANKSWITCH = 1\n");
Expand Down Expand Up @@ -652,12 +652,10 @@ void CChunkRenderText::StorePeriods(unsigned int *pLUTNTSC, unsigned int* pLUTPA
str.Append(".define ft_vrc7_table ");

for (int i = 0; i <= NOTE_RANGE; ++i) { // // // include last item for linear pitch code optimization
CString str;
if (i == NOTE_RANGE)
str.AppendFormat("$%04X\n", pLUTVRC7[0] << 3);
else
str.AppendFormat("$%04X, ", pLUTVRC7[i] << 2);
str.Append(str);
}

str.Append("\n");
Expand Down
4 changes: 3 additions & 1 deletion Source/ChunkRenderText.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ class CChunkRenderText
void StoreChunks(const std::vector<CChunk *> &Chunks);
void StoreSamples(const std::vector<const CDSample *> &Samples);
void WriteFileString(const CStringA &str, CFile *pFile) const;
void StoreNSFStub(stNSFHeader Header, bool Bankswitched, vibrato_t VibratoStyle, bool LinearPitch, int ActualNamcoChannels, bool IsAssembly = false) const;
void StoreNSFStub(unsigned char Header, bool Bankswitched, vibrato_t VibratoStyle, bool LinearPitch, int ActualNamcoChannels, bool IsAssembly = false) const;
void StoreNSFHeader(stNSFHeader Header) const;
void StoreNSFConfig(unsigned int DPCMSegment, stNSFHeader Header, bool Bankswitched = false) const;
void StorePeriods(unsigned int *pLUTNTSC, unsigned int *pLUTPAL, unsigned int *pLUTSaw, unsigned int *pLUTVRC7, unsigned int *pLUTFDS, unsigned int *pLUTN163) const;
void StoreVibrato(unsigned int *pLUTVibrato) const;
void StoreUpdateExt(unsigned char Header) const;
void StoreChannelEnable(unsigned char Header) const;
void SetExtraDataFiles(CFile *pFileNSFStub, CFile *pFileNSFHeader, CFile *pFileNSFConfig, CFile *pFilePeriods, CFile *pFileVibrato);

// Labels
Expand Down
16 changes: 8 additions & 8 deletions Source/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2792,24 +2792,24 @@ void CCompiler::WriteAssembly(CFile *pFile, bool bExtraData, stNSFHeader Header,
unsigned int LUTNTSC[NOTE_COUNT]{};
unsigned int LUTPAL[NOTE_COUNT]{};
unsigned int LUTSaw[NOTE_COUNT]{};
unsigned int LUTVRC7[NOTE_RANGE]{};
unsigned int LUTFDS[NOTE_COUNT]{};
unsigned int LUTN163[NOTE_COUNT]{};
unsigned int LUTVRC7[NOTE_COUNT]{};

const CSoundGen *pSoundGen = theApp.GetSoundGenerator();
for (int i = 0; i <= CDetuneTable::DETUNE_N163; ++i) { // // //
for (int i = 0; i < CDetuneTable::DETUNE_N163; ++i) { // // //
switch (i) {
case CDetuneTable::DETUNE_NTSC:
for (int j = 0; j < NOTE_COUNT; ++j) LUTNTSC[j] = pSoundGen->ReadPeriodTable(j, i); break;
case CDetuneTable::DETUNE_PAL:
if (MachineType)
if (MachineType != 0)
for (int j = 0; j < NOTE_COUNT; ++j) LUTPAL[j] = pSoundGen->ReadPeriodTable(j, i); break;
case CDetuneTable::DETUNE_SAW:
if (m_iActualChip & SNDCHIP_VRC6)
for (int j = 0; j < NOTE_COUNT; ++j) LUTSaw[j] = pSoundGen->ReadPeriodTable(j, i); break;
case CDetuneTable::DETUNE_VRC7:
if (m_iActualChip & SNDCHIP_VRC7)
for (int j = 0; j < NOTE_COUNT; ++j) LUTVRC7[j] = pSoundGen->ReadPeriodTable(j, i); break;
for (int j = 0; j < NOTE_RANGE; ++j) LUTVRC7[j] = pSoundGen->ReadPeriodTable(j, i); break;
case CDetuneTable::DETUNE_FDS:
if (m_iActualChip & SNDCHIP_FDS)
for (int j = 0; j < NOTE_COUNT; ++j) LUTFDS[j] = pSoundGen->ReadPeriodTable(j, i); break;
Expand All @@ -2827,7 +2827,7 @@ void CCompiler::WriteAssembly(CFile *pFile, bool bExtraData, stNSFHeader Header,
LUTVibrato[i] = pSoundGen->ReadVibratoTable(i);
}
Render.SetExtraDataFiles(pFileNSFStub, pFileNSFHeader, pFileNSFConfig, pFilePeriods, pFileVibrato);
Render.StoreNSFStub(Header, m_bBankSwitched, m_pDocument->GetVibratoStyle(), m_pDocument->GetLinearPitch(), m_iActualNamcoChannels, true);
Render.StoreNSFStub(Header.SoundChip, m_bBankSwitched, m_pDocument->GetVibratoStyle(), m_pDocument->GetLinearPitch(), m_iActualNamcoChannels, true);
Render.StoreNSFHeader(Header);
Render.StoreNSFConfig(m_iSampleStart, Header);
Render.StorePeriods(LUTNTSC, LUTPAL, LUTSaw, LUTVRC7, LUTFDS, LUTN163);
Expand All @@ -2851,9 +2851,9 @@ void CCompiler::WriteBinary(CFile *pFile, bool bExtraData, stNSFHeader Header, i
unsigned int LUTNTSC[NOTE_COUNT]{};
unsigned int LUTPAL[NOTE_COUNT]{};
unsigned int LUTSaw[NOTE_COUNT]{};
unsigned int LUTVRC7[NOTE_RANGE]{};
unsigned int LUTFDS[NOTE_COUNT]{};
unsigned int LUTN163[NOTE_COUNT]{};
unsigned int LUTVRC7[NOTE_COUNT]{};

const CSoundGen *pSoundGen = theApp.GetSoundGenerator();
for (int i = 0; i < CDetuneTable::DETUNE_N163; ++i) { // // //
Expand All @@ -2868,7 +2868,7 @@ void CCompiler::WriteBinary(CFile *pFile, bool bExtraData, stNSFHeader Header, i
for (int j = 0; j < NOTE_COUNT; ++j) LUTSaw[j] = pSoundGen->ReadPeriodTable(j, i); break;
case CDetuneTable::DETUNE_VRC7:
if (m_iActualChip & SNDCHIP_VRC7)
for (int j = 0; j < NOTE_COUNT; ++j) LUTVRC7[j] = pSoundGen->ReadPeriodTable(j, i); break;
for (int j = 0; j < NOTE_RANGE; ++j) LUTVRC7[j] = pSoundGen->ReadPeriodTable(j, i); break;
case CDetuneTable::DETUNE_FDS:
if (m_iActualChip & SNDCHIP_FDS)
for (int j = 0; j < NOTE_COUNT; ++j) LUTFDS[j] = pSoundGen->ReadPeriodTable(j, i); break;
Expand All @@ -2888,7 +2888,7 @@ void CCompiler::WriteBinary(CFile *pFile, bool bExtraData, stNSFHeader Header, i
// get an instance of CChunkRenderText to use its extra data plotting
CChunkRenderText RenderText(nullptr);
RenderText.SetExtraDataFiles(pFileNSFStub, pFileNSFHeader, pFileNSFConfig, pFilePeriods, pFileVibrato);
RenderText.StoreNSFStub(Header, m_bBankSwitched, m_pDocument->GetVibratoStyle(), m_pDocument->GetLinearPitch(), m_iActualNamcoChannels);
RenderText.StoreNSFStub(Header.SoundChip, m_bBankSwitched, m_pDocument->GetVibratoStyle(), m_pDocument->GetLinearPitch(), m_iActualNamcoChannels);
RenderText.StoreNSFHeader(Header);
RenderText.StorePeriods(LUTNTSC, LUTPAL, LUTSaw, LUTVRC7, LUTFDS, LUTN163);
RenderText.StoreVibrato(LUTVibrato);
Expand Down

0 comments on commit e0abc0f

Please sign in to comment.