From e0abc0f8213e46d61f3f29ae92668c0f18be5a5c Mon Sep 17 00:00:00 2001 From: Persune Date: Sat, 17 Feb 2024 16:01:33 +0800 Subject: [PATCH] Fix VRC7 period table assembly export --- Source/ChunkRenderText.cpp | 16 +++++++--------- Source/ChunkRenderText.h | 4 +++- Source/Compiler.cpp | 16 ++++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Source/ChunkRenderText.cpp b/Source/ChunkRenderText.cpp index c471db88..5d41d7d8 100644 --- a/Source/ChunkRenderText.cpp +++ b/Source/ChunkRenderText.cpp @@ -487,7 +487,7 @@ 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; @@ -495,17 +495,17 @@ void CChunkRenderText::StoreNSFStub(stNSFHeader Header, bool Bankswitched, vibra 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"); @@ -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"); diff --git a/Source/ChunkRenderText.h b/Source/ChunkRenderText.h index f53f7a2d..48a9805e 100644 --- a/Source/ChunkRenderText.h +++ b/Source/ChunkRenderText.h @@ -47,11 +47,13 @@ class CChunkRenderText void StoreChunks(const std::vector &Chunks); void StoreSamples(const std::vector &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 diff --git a/Source/Compiler.cpp b/Source/Compiler.cpp index 3081e5a5..423dbc2f 100644 --- a/Source/Compiler.cpp +++ b/Source/Compiler.cpp @@ -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; @@ -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); @@ -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) { // // // @@ -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; @@ -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);