From 9f54952f0d6e0a4d6e42d14b923fc521c4532ce7 Mon Sep 17 00:00:00 2001 From: Persune Date: Sat, 17 Feb 2024 23:20:10 +0800 Subject: [PATCH] Implement "glob" multichip assembly export --- Source/ChunkRenderText.cpp | 163 ++++++++++++++++++++++++++++---- Source/ChunkRenderText.h | 10 +- Source/Compiler.cpp | 181 +++++++++++++++++++++++++++--------- Source/Compiler.h | 12 ++- Source/drivers/asm/driver.s | 48 +++++----- Source/drivers/asm/player.s | 4 + 6 files changed, 325 insertions(+), 93 deletions(-) diff --git a/Source/ChunkRenderText.cpp b/Source/ChunkRenderText.cpp index 5d41d7d8..a026943b 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(unsigned char Expansion, 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 UseAllChips, bool IsAssembly) const { CString str; @@ -495,29 +495,39 @@ void CChunkRenderText::StoreNSFStub(unsigned char Expansion, bool Bankswitched, str.Append("PACKAGE = 1\n"); str.Append("HAS_NSF_HEADER = 1\n"); str.Append("USE_AUX_DATA = 1\n"); - if (Expansion & SNDCHIP_VRC6) - str.Append("USE_VRC6 = 1\n"); - if (Expansion & SNDCHIP_VRC7) - str.Append("USE_VRC7 = 1\n"); - if (Expansion & SNDCHIP_FDS) - str.Append("USE_FDS = 1\n"); - if (Expansion & SNDCHIP_MMC5) - str.Append("USE_MMC5 = 1\n"); - if (Expansion & SNDCHIP_N163) - str.Append("USE_N163 = 1\n"); - if (Expansion & SNDCHIP_S5B) - str.Append("USE_S5B = 1\n"); - if (Bankswitched) - str.Append("USE_BANKSWITCH = 1\n"); - if (VibratoStyle == VIBRATO_OLD) + if (UseAllChips) { + // Simulate NSF export multichip + str.Append("USE_ALL = 1\n"); + str.Append("NAMCO_CHANNELS = 8\n"); str.Append("USE_OLDVIBRATO = 1\n"); - if (LinearPitch) + str.Append("USE_BANKSWITCH = 1\n"); str.Append("USE_LINEARPITCH = 1\n"); - str.AppendFormat("NAMCO_CHANNELS = %d\n", ActualNamcoChannels); + } + else { + if (Expansion & SNDCHIP_VRC6) + str.Append("USE_VRC6 = 1\n"); + if (Expansion & SNDCHIP_VRC7) + str.Append("USE_VRC7 = 1\n"); + if (Expansion & SNDCHIP_FDS) + str.Append("USE_FDS = 1\n"); + if (Expansion & SNDCHIP_MMC5) + str.Append("USE_MMC5 = 1\n"); + if (Expansion & SNDCHIP_N163) + str.Append("USE_N163 = 1\n"); + if (Expansion & SNDCHIP_S5B) + str.Append("USE_S5B = 1\n"); + str.AppendFormat("NAMCO_CHANNELS = %d\n", ActualNamcoChannels); + if (Bankswitched) + str.Append("USE_BANKSWITCH = 1\n"); + if (VibratoStyle == VIBRATO_OLD) + str.Append("USE_OLDVIBRATO = 1\n"); + if (LinearPitch) + str.Append("USE_LINEARPITCH = 1\n"); + } str.Append("\n.include \"driver/driver.s\"\t; path to NSF driver source\n"); - str.Append("\n.include \"music.asm\"\t; path to NSF export source\n"); + str.Append(".include \"music.asm\"\t\t; path to NSF export source\n"); WriteFileString(str, m_pFileNSFStub); } @@ -685,13 +695,126 @@ void CChunkRenderText::StoreVibrato(unsigned int *pLUTVibrato) const WriteFileString(str, m_pFileVibrato); } -void CChunkRenderText::SetExtraDataFiles(CFile *pFileNSFStub, CFile* pFileNSFHeader, CFile* pFileNSFConfig, CFile* pFilePeriods, CFile* pFileVibrato) +void CChunkRenderText::StoreUpdateExt(unsigned char Expansion) const +{ + // // // special processing for multichip + if ((Expansion & (Expansion - 1)) == false) return; + + CString str; + + str.Append("\t; VRC6\n"); + if (Expansion & SNDCHIP_VRC6) + str.Append("\tjsr ft_update_vrc6"); + else + str.Append("\tnop\n\tnop\n\tnop\n"); + str.Append("\t; VRC7\n"); + if (Expansion & SNDCHIP_VRC7) + str.Append("\tjsr ft_update_vrc7"); + else + str.Append("\tnop\n\tnop\n\tnop\n"); + str.Append("\t; FDS\n"); + if (Expansion & SNDCHIP_FDS) + str.Append("\tjsr ft_update_fds"); + else + str.Append("\tnop\n\tnop\n\tnop\n"); + str.Append("\t; MMC5\n"); + if (Expansion & SNDCHIP_MMC5) + str.Append("\tjsr ft_update_mmc5"); + else + str.Append("\tnop\n\tnop\n\tnop\n"); + str.Append("\t; N163\n"); + if (Expansion & SNDCHIP_N163) + str.Append("\tjsr ft_update_n163"); + else + str.Append("\tnop\n\tnop\n\tnop\n"); + str.Append("\t; S5B\n"); + if (Expansion & SNDCHIP_S5B) + str.Append("\tjsr ft_update_s5b"); + else + str.Append("\tnop\n\tnop\n\tnop\n"); + WriteFileString(str, m_pFileMultiChipUpdate); +} + +void CChunkRenderText::StoreEnableExt(unsigned char Expansion) const +{ + // // // special processing for multichip + if ((Expansion & (Expansion - 1)) == false) return; + /* + if (Expansion & (Expansion - 1)) { // // // special processing for multichip + const int CH_MAP[] = { + 0, 1, 2, 3, 27, + 6, 7, 8, + 4, 5, -1, + 9, 10, 11, 12, 13, 14, 15, 16, + 17, + 21, 22, 23, 24, 25, 26, + 18, 19, 20, + }; + + for (int i = 0; i < CHANNELS; ++i) + pData[FT_CH_ENABLE_ADR + i] = 0; + for (const int x : m_vChanOrder) + pData[FT_CH_ENABLE_ADR + CH_MAP[m_pDocument->GetChannelType(x)]] = 1; + } + */ + // // // special processing for multichip + if ((Expansion & (Expansion - 1)) == false) return; + + CString str; + + str.Append("ft_channel_enable: ;; Patched\n"); + str.Append("\t.byte 1, 1, 1, 1\n"); + + str.Append("\t; MMC5\n"); + if (Expansion & SNDCHIP_MMC5) + str.Append("\t.byte 1, 1\n"); + else + str.Append("\t.byte 0, 0\n"); + + str.Append("\t; VRC6\n"); + if (Expansion & SNDCHIP_VRC6) + str.Append("\t.byte 1, 1, 1\n"); + else + str.Append("\t.byte 0, 0, 0\n"); + + str.Append("\t; N163\n"); + if (Expansion & SNDCHIP_N163) + str.Append("\t.byte 1, 1, 1, 1, 1, 1, 1, 1\n"); + else + str.Append("\t.byte 0, 0, 0, 0, 0, 0, 0, 0\n"); + + str.Append("\t; FDS\n"); + if (Expansion & SNDCHIP_FDS) + str.Append("\t.byte 1\n"); + else + str.Append("\t.byte 0\n"); + + str.Append("\t; S5B\n"); + if (Expansion & SNDCHIP_S5B) + str.Append("\t.byte 1, 1, 1\n"); + else + str.Append("\t.byte 0, 0, 0\n"); + + str.Append("\t; VRC7\n"); + if (Expansion & SNDCHIP_VRC7) + str.Append("\t.byte 1, 1, 1, 1, 1, 1\n"); + else + str.Append("\t.byte 0, 0, 0, 0, 0, 0\n"); + + str.Append("\t; DPCM\n"); + str.Append("\t.byte 1\n"); + WriteFileString(str, m_pFileMultiChipEnable); +} + +void CChunkRenderText::SetExtraDataFiles(CFile *pFileNSFStub, CFile* pFileNSFHeader, CFile* pFileNSFConfig, CFile* pFilePeriods, CFile* pFileVibrato, CFile *pFileMultiChipEnable, CFile *pFileMultiChipUpdate) { m_pFileNSFStub = pFileNSFStub; m_pFileNSFHeader = pFileNSFHeader; m_pFileNSFConfig = pFileNSFConfig; m_pFilePeriods = pFilePeriods; m_pFileVibrato = pFileVibrato; + m_pFileMultiChipEnable = pFileMultiChipEnable; + m_pFileMultiChipUpdate = pFileMultiChipUpdate; } void CChunkRenderText::StoreByteString(const char *pData, int Len, CStringA &str, int LineBreak) const diff --git a/Source/ChunkRenderText.h b/Source/ChunkRenderText.h index 48a9805e..8b7f2207 100644 --- a/Source/ChunkRenderText.h +++ b/Source/ChunkRenderText.h @@ -47,14 +47,14 @@ class CChunkRenderText void StoreChunks(const std::vector &Chunks); void StoreSamples(const std::vector &Samples); void WriteFileString(const CStringA &str, CFile *pFile) const; - void StoreNSFStub(unsigned char 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 UseAllChips, 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); + void StoreUpdateExt(unsigned char Expansion) const; + void StoreEnableExt(unsigned char Expansion) const; + void SetExtraDataFiles(CFile *pFileNSFStub, CFile *pFileNSFHeader, CFile *pFileNSFConfig, CFile *pFilePeriods, CFile *pVibrato, CFile *pFileMultiChipEnable, CFile *pFileMultiChipUpdate); // Labels // // // moved from CCompiler @@ -124,4 +124,6 @@ class CChunkRenderText CFile *m_pFileNSFConfig; CFile *m_pFilePeriods; CFile *m_pFileVibrato; + CFile *m_pFileMultiChipEnable; + CFile *m_pFileMultiChipUpdate; }; diff --git a/Source/Compiler.cpp b/Source/Compiler.cpp index 423dbc2f..588912be 100644 --- a/Source/Compiler.cpp +++ b/Source/Compiler.cpp @@ -118,6 +118,10 @@ const int CCompiler::FLAG_BANKSWITCHED = 1 << 0; const int CCompiler::FLAG_VIBRATO = 1 << 1; const int CCompiler::FLAG_LINEARPITCH = 1 << 2; // // // + +// Enable this to simulate NSF driver export multichip for assembly, which enables all chips internally +constexpr bool UseAllChips = true; + CCompiler *CCompiler::pCompiler = NULL; CCompiler *CCompiler::GetCompiler() @@ -920,7 +924,7 @@ void CCompiler::ExportBIN(LPCTSTR lpszBIN_File, LPCTSTR lpszDPCM_File, int Machi } // Build the music data - if (!CompileData()) { + if (!CompileData(false, UseAllChips)) { // Failed Cleanup(); return; @@ -986,8 +990,7 @@ void CCompiler::ExportBIN(LPCTSTR lpszBIN_File, LPCTSTR lpszDPCM_File, int Machi // Write NSF stub CFile OutputFileNSFStub; - CString stub_directory = FileDirectory; - stub_directory += _T("nsf_stub.s"); + CString stub_directory = FileDirectory + "nsf_stub.s"; if (!OpenFile(stub_directory, OutputFileNSFStub)) { OutputFileNSFStub.Close(); @@ -998,8 +1001,7 @@ void CCompiler::ExportBIN(LPCTSTR lpszBIN_File, LPCTSTR lpszDPCM_File, int Machi // Write NSF header CFile OutputFileNSFHeader; - CString header_directory = FileDirectory; - header_directory += _T("nsf_header.s"); + CString header_directory = FileDirectory + "nsf_header.s"; if (!OpenFile(header_directory, OutputFileNSFHeader)) { OutputFileNSFStub.Close(); @@ -1011,8 +1013,7 @@ void CCompiler::ExportBIN(LPCTSTR lpszBIN_File, LPCTSTR lpszDPCM_File, int Machi // Write NSF config file CFile OutputFileNSFConfig; - CString config_directory = FileDirectory; - config_directory += _T("nsf.cfg"); + CString config_directory = FileDirectory + "nsf.cfg"; if (!OpenFile(config_directory, OutputFileNSFConfig)) { OutputFileNSFStub.Close(); OutputFileNSFHeader.Close(); @@ -1024,8 +1025,7 @@ void CCompiler::ExportBIN(LPCTSTR lpszBIN_File, LPCTSTR lpszDPCM_File, int Machi // Write period file CFile OutputFilePeriods; - CString periods_directory = FileDirectory; - periods_directory += _T("periods.s"); + CString periods_directory = FileDirectory + "periods.s"; if (!OpenFile(periods_directory, OutputFilePeriods)) { OutputFileNSFStub.Close(); @@ -1039,8 +1039,7 @@ void CCompiler::ExportBIN(LPCTSTR lpszBIN_File, LPCTSTR lpszDPCM_File, int Machi // Write vibrato file CFile OutputFileVibrato; - CString vibrato_directory = FileDirectory; - vibrato_directory += _T("vibrato.s"); + CString vibrato_directory = FileDirectory + "vibrato.s"; if (!OpenFile(vibrato_directory, OutputFileVibrato)) { OutputFileNSFStub.Close(); @@ -1053,11 +1052,54 @@ void CCompiler::ExportBIN(LPCTSTR lpszBIN_File, LPCTSTR lpszDPCM_File, int Machi return; } - WriteBinary(&OutputFileBIN, ExtraData, Header, MachineType, &OutputFileNSFStub, &OutputFileNSFHeader, &OutputFileNSFConfig, &OutputFilePeriods, &OutputFileVibrato); - OutputFilePeriods.Close(); - OutputFileVibrato.Close(); + // Write multichip enable file + CFile OutputFileMultiChipEnable; + CString enable_ext_directory = FileDirectory + "enable_ext.s"; + + if (!OpenFile(enable_ext_directory, OutputFileMultiChipEnable)) { + OutputFileNSFStub.Close(); + OutputFileNSFHeader.Close(); + OutputFileNSFConfig.Close(); + OutputFilePeriods.Close(); + OutputFileVibrato.Close(); + OutputFileMultiChipEnable.Close(); + Print(_T("Error: Could not open output multichip handler file\n")); + Cleanup(); + return; + } + + // Write multichip enable file + CFile OutputFileMultiChipUpdate; + CString update_ext_directory = FileDirectory + "update_ext.s"; + + if (!OpenFile(update_ext_directory, OutputFileMultiChipUpdate)) { + OutputFileNSFStub.Close(); + OutputFileNSFHeader.Close(); + OutputFileNSFConfig.Close(); + OutputFilePeriods.Close(); + OutputFileVibrato.Close(); + OutputFileMultiChipEnable.Close(); + OutputFileMultiChipUpdate.Close(); + Print(_T("Error: Could not open output multichip handler file\n")); + Cleanup(); + return; + } + + WriteBinary(&OutputFileBIN, ExtraData, Header, MachineType, + &OutputFileNSFStub, + &OutputFileNSFHeader, + &OutputFileNSFConfig, + &OutputFilePeriods, + &OutputFileVibrato, + &OutputFileMultiChipEnable, + &OutputFileMultiChipUpdate); + OutputFileNSFStub.Close(); OutputFileNSFHeader.Close(); OutputFileNSFConfig.Close(); + OutputFilePeriods.Close(); + OutputFileVibrato.Close(); + OutputFileMultiChipEnable.Close(); + OutputFileMultiChipUpdate.Close(); } else WriteBinary(&OutputFileBIN, ExtraData, Header); @@ -1179,7 +1221,7 @@ void CCompiler::ExportASM(LPCTSTR lpszFileName, int MachineType, bool ExtraData) } // Build the music data - if (!CompileData()) { + if (!CompileData(false, UseAllChips)) { // Failed Cleanup(); return; @@ -1235,8 +1277,7 @@ void CCompiler::ExportASM(LPCTSTR lpszFileName, int MachineType, bool ExtraData) // Write NSF stub CFile OutputFileNSFStub; - CString stub_directory = FileDirectory; - stub_directory += _T("nsf_stub.s"); + CString stub_directory = FileDirectory + "nsf_stub.s"; if (!OpenFile(stub_directory, OutputFileNSFStub)) { OutputFileNSFStub.Close(); @@ -1247,8 +1288,7 @@ void CCompiler::ExportASM(LPCTSTR lpszFileName, int MachineType, bool ExtraData) // Write NSF header CFile OutputFileNSFHeader; - CString header_directory = FileDirectory; - header_directory += _T("nsf_header.s"); + CString header_directory = FileDirectory + "nsf_header.s"; if (!OpenFile(header_directory, OutputFileNSFHeader)) { OutputFileNSFStub.Close(); @@ -1260,8 +1300,7 @@ void CCompiler::ExportASM(LPCTSTR lpszFileName, int MachineType, bool ExtraData) // Write NSF config file CFile OutputFileNSFConfig; - CString config_directory = FileDirectory; - config_directory += _T("nsf.cfg"); + CString config_directory = FileDirectory + "nsf.cfg"; if (!OpenFile(config_directory, OutputFileNSFConfig)) { OutputFileNSFStub.Close(); OutputFileNSFHeader.Close(); @@ -1273,8 +1312,7 @@ void CCompiler::ExportASM(LPCTSTR lpszFileName, int MachineType, bool ExtraData) // Write period file CFile OutputFilePeriods; - CString periods_directory = FileDirectory; - periods_directory += _T("periods.s"); + CString periods_directory = FileDirectory + "periods.s"; if (!OpenFile(periods_directory, OutputFilePeriods)) { OutputFileNSFStub.Close(); @@ -1288,8 +1326,7 @@ void CCompiler::ExportASM(LPCTSTR lpszFileName, int MachineType, bool ExtraData) // Write vibrato file CFile OutputFileVibrato; - CString vibrato_directory = FileDirectory; - vibrato_directory += _T("vibrato.s"); + CString vibrato_directory = FileDirectory + "vibrato.s"; if (!OpenFile(vibrato_directory, OutputFileVibrato)) { OutputFileNSFStub.Close(); @@ -1302,11 +1339,54 @@ void CCompiler::ExportASM(LPCTSTR lpszFileName, int MachineType, bool ExtraData) return; } - WriteAssembly(&OutputFile, ExtraData, Header, MachineType, &OutputFileNSFStub, &OutputFileNSFHeader, &OutputFileNSFConfig, &OutputFilePeriods, &OutputFileVibrato); - OutputFilePeriods.Close(); - OutputFileVibrato.Close(); + // Write multichip enable file + CFile OutputFileMultiChipEnable; + CString enable_ext_directory = FileDirectory + "enable_ext.s"; + + if (!OpenFile(enable_ext_directory, OutputFileMultiChipEnable)) { + OutputFileNSFStub.Close(); + OutputFileNSFHeader.Close(); + OutputFileNSFConfig.Close(); + OutputFilePeriods.Close(); + OutputFileVibrato.Close(); + OutputFileMultiChipEnable.Close(); + Print(_T("Error: Could not open output multichip handler file\n")); + Cleanup(); + return; + } + + // Write multichip enable file + CFile OutputFileMultiChipUpdate; + CString update_ext_directory = FileDirectory + "update_ext.s"; + + if (!OpenFile(update_ext_directory, OutputFileMultiChipUpdate)) { + OutputFileNSFStub.Close(); + OutputFileNSFHeader.Close(); + OutputFileNSFConfig.Close(); + OutputFilePeriods.Close(); + OutputFileVibrato.Close(); + OutputFileMultiChipEnable.Close(); + OutputFileMultiChipUpdate.Close(); + Print(_T("Error: Could not open output multichip handler file\n")); + Cleanup(); + return; + } + + WriteAssembly(&OutputFile, ExtraData, Header, MachineType, + &OutputFileNSFStub, + &OutputFileNSFHeader, + &OutputFileNSFConfig, + &OutputFilePeriods, + &OutputFileVibrato, + &OutputFileMultiChipEnable, + &OutputFileMultiChipUpdate); + OutputFileNSFStub.Close(); OutputFileNSFHeader.Close(); OutputFileNSFConfig.Close(); + OutputFilePeriods.Close(); + OutputFileVibrato.Close(); + OutputFileMultiChipEnable.Close(); + OutputFileMultiChipUpdate.Close(); } else { WriteAssembly(&OutputFile, ExtraData, Header); @@ -1805,7 +1885,7 @@ void CCompiler::AssignLabels(CMap &labelMap) pChunk->AssignLabels(labelMap); } -bool CCompiler::CompileData(bool bUseNSFDRV) +bool CCompiler::CompileData(bool bUseNSFDRV, bool bUseAllExp) { // Compile music data to an object tree // @@ -1911,7 +1991,7 @@ bool CCompiler::CompileData(bool bUseNSFDRV) Print(_T("Building music data...\n")); // Build music data - CreateMainHeader(); + CreateMainHeader(bUseAllExp); CreateSequenceList(); CreateInstrumentList(); CreateSampleList(); @@ -2129,16 +2209,16 @@ bool CCompiler::IsInstrumentInPattern(int index) const return false; } -void CCompiler::CreateMainHeader() +void CCompiler::CreateMainHeader(bool UseAllExp) { // Writes the music header int TicksPerSec = m_pDocument->GetEngineSpeed(); - int Chip = m_pDocument->GetExpansionChip(); // // // - bool bMultichip = (Chip & (Chip - 1)) != 0; - unsigned short DividerNTSC, DividerPAL; + int Chip = m_pDocument->GetExpansionChip(); // // // + bool bMultichip = ((Chip & (Chip - 1)) != 0) && UseAllExp; + CChunk *pChunk = CreateChunk(CHUNK_HEADER, ""); if (TicksPerSec == 0) { @@ -2170,14 +2250,17 @@ void CCompiler::CreateMainHeader() pChunk->StoreByte(Flags); // FDS table, only if FDS is enabled - if (m_pDocument->ExpansionEnabled(SNDCHIP_FDS) || bMultichip) - pChunk->StoreReference(CChunkRenderText::LABEL_WAVETABLE); + if ((Chip & SNDCHIP_FDS) || bMultichip) + if (!(Chip & SNDCHIP_FDS)) + pChunk->StoreReference("0"); + else + pChunk->StoreReference(CChunkRenderText::LABEL_WAVETABLE); pChunk->StoreWord(DividerNTSC); pChunk->StoreWord(DividerPAL); // N163 channel count - if (m_pDocument->ExpansionEnabled(SNDCHIP_N163) || bMultichip) { + if ((Chip & SNDCHIP_N163) || bMultichip) { /*if (m_pDocument->GetExpansionChip() != SNDCHIP_N163) // // // pChunk->StoreByte(8); else*/ pChunk->StoreByte(std::max(m_iActualNamcoChannels, 1)); @@ -2772,7 +2855,9 @@ void CCompiler::WriteAssembly(CFile *pFile, bool bExtraData, stNSFHeader Header, CFile *pFileNSFHeader, CFile *pFileNSFConfig, CFile *pFilePeriods, - CFile *pFileVibrato) + CFile *pFileVibrato, + CFile *pFileMultiChipEnable, + CFile *pFileMultiChipUpdate) { // Dump all chunks and samples as assembly text CChunkRenderText Render(pFile); @@ -2826,12 +2911,16 @@ void CCompiler::WriteAssembly(CFile *pFile, bool bExtraData, stNSFHeader Header, for (int i = 0; i < 256; ++i) { LUTVibrato[i] = pSoundGen->ReadVibratoTable(i); } - Render.SetExtraDataFiles(pFileNSFStub, pFileNSFHeader, pFileNSFConfig, pFilePeriods, pFileVibrato); - Render.StoreNSFStub(Header.SoundChip, m_bBankSwitched, m_pDocument->GetVibratoStyle(), m_pDocument->GetLinearPitch(), m_iActualNamcoChannels, true); + Render.SetExtraDataFiles(pFileNSFStub, pFileNSFHeader, pFileNSFConfig, pFilePeriods, pFileVibrato, pFileMultiChipEnable, pFileMultiChipUpdate); + Render.StoreNSFStub(Header.SoundChip, m_bBankSwitched, m_pDocument->GetVibratoStyle(), m_pDocument->GetLinearPitch(), m_iActualNamcoChannels, UseAllChips, true); Render.StoreNSFHeader(Header); Render.StoreNSFConfig(m_iSampleStart, Header); Render.StorePeriods(LUTNTSC, LUTPAL, LUTSaw, LUTVRC7, LUTFDS, LUTN163); Render.StoreVibrato(LUTVibrato); + if (UseAllChips) { + Render.StoreEnableExt(Header.SoundChip); + Render.StoreUpdateExt(Header.SoundChip); + } } } @@ -2840,7 +2929,9 @@ void CCompiler::WriteBinary(CFile *pFile, bool bExtraData, stNSFHeader Header, i CFile *pFileNSFHeader, CFile *pFileNSFConfig, CFile *pFilePeriods, - CFile *pFileVibrato) + CFile *pFileVibrato, + CFile *pFileMultiChipEnable, + CFile *pFileMultiChipUpdate) { // Dump all chunks as binary CChunkRenderBinary Render(pFile); @@ -2887,11 +2978,15 @@ 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.SoundChip, m_bBankSwitched, m_pDocument->GetVibratoStyle(), m_pDocument->GetLinearPitch(), m_iActualNamcoChannels); + RenderText.SetExtraDataFiles(pFileNSFStub, pFileNSFHeader, pFileNSFConfig, pFilePeriods, pFileVibrato, pFileMultiChipEnable, pFileMultiChipUpdate); + RenderText.StoreNSFStub(Header.SoundChip, m_bBankSwitched, m_pDocument->GetVibratoStyle(), m_pDocument->GetLinearPitch(), m_iActualNamcoChannels, UseAllChips); RenderText.StoreNSFHeader(Header); RenderText.StorePeriods(LUTNTSC, LUTPAL, LUTSaw, LUTVRC7, LUTFDS, LUTN163); RenderText.StoreVibrato(LUTVibrato); + if (UseAllChips) { + RenderText.StoreEnableExt(Header.SoundChip); + RenderText.StoreUpdateExt(Header.SoundChip); + } } } diff --git a/Source/Compiler.h b/Source/Compiler.h index cd6e547e..a5093751 100644 --- a/Source/Compiler.h +++ b/Source/Compiler.h @@ -118,7 +118,7 @@ class CCompiler char* LoadNSFDRV(const driver_t *pDriver) const; // Compiler - bool CompileData(bool bUseNSFDRV = false); + bool CompileData(bool bUseNSFDRV = false, bool UseAllExp = true); void ResolveLabels(); bool ResolveLabelsBankswitched(); void CollectLabels(CMap &labelMap) const; @@ -134,7 +134,7 @@ class CCompiler bool IsPatternAddressed(unsigned int Track, int Pattern, int Channel) const; bool IsInstrumentInPattern(int index) const; - void CreateMainHeader(); + void CreateMainHeader(bool UseAllExp); void CreateSequenceList(); void CreateInstrumentList(); void CreateSampleList(); @@ -162,13 +162,17 @@ class CCompiler CFile *pFileNSFHeader = nullptr, CFile *pFileNSFConfig = nullptr, CFile *pFilePeriods = nullptr, - CFile *pFileVibrato = nullptr); + CFile *pFileVibrato = nullptr, + CFile *FileMultiChipEnable = nullptr, + CFile *FileMultiChipUpdate = nullptr); void WriteBinary(CFile *pFile, bool bExtraData, stNSFHeader Header, int MachineType = 0, CFile *pFileNSFStub = nullptr, CFile *pFileNSFHeader = nullptr, CFile *pFileNSFConfig = nullptr, CFile *pFilePeriods = nullptr, - CFile *pFileVibrato = nullptr); + CFile *pFileVibrato = nullptr, + CFile *FileMultiChipEnable = nullptr, + CFile *FileMultiChipUpdate = nullptr); void WriteSamplesBinary(CFile *pFile); // Object list functions diff --git a/Source/drivers/asm/driver.s b/Source/drivers/asm/driver.s index 3cef4644..084020c8 100644 --- a/Source/drivers/asm/driver.s +++ b/Source/drivers/asm/driver.s @@ -597,28 +597,32 @@ ft_channel_type: .endif .if MULTICHIP ;;; ;; ; -ft_channel_enable: ;; Patch - .byte 1, 1, 1, 1 -.repeat CH_COUNT_MMC5 - .byte .defined(USE_MMC5) -.endrep -.if .defined(USE_VRC6) - .byte .defined(USE_VRC6) -.endif -.repeat CH_COUNT_N163 ; 0CC: check - .byte .defined(USE_N163) -.endrep -.repeat CH_COUNT_FDS - .byte .defined(USE_FDS) -.endrep -.repeat CH_COUNT_S5B - .byte .defined(USE_S5B) -.endrep -.repeat CH_COUNT_VRC7 - .byte .defined(USE_VRC7) -.endrep -.if .defined(USE_DPCM) - .byte 1 +.if .defined(USE_AUX_DATA) .and .defined(USE_ALL) + .include "../enable_ext.s" +.else + ft_channel_enable: ;; Patch + .byte 1, 1, 1, 1 + .repeat CH_COUNT_MMC5 + .byte .defined(USE_MMC5) + .endrep + .if .defined(USE_VRC6) + .byte .defined(USE_VRC6) + .endif + .repeat CH_COUNT_N163 ; 0CC: check + .byte .defined(USE_N163) + .endrep + .repeat CH_COUNT_FDS + .byte .defined(USE_FDS) + .endrep + .repeat CH_COUNT_S5B + .byte .defined(USE_S5B) + .endrep + .repeat CH_COUNT_VRC7 + .byte .defined(USE_VRC7) + .endrep + .if .defined(USE_DPCM) + .byte 1 + .endif .endif .endif diff --git a/Source/drivers/asm/player.s b/Source/drivers/asm/player.s index ad7edf70..8f46ee5e 100644 --- a/Source/drivers/asm/player.s +++ b/Source/drivers/asm/player.s @@ -286,6 +286,9 @@ ft_update_apu: ; Finally update APU and expansion chip registers jsr ft_update_2a03 ft_update_ext: ;; Patch +.if .defined(USE_AUX_DATA) .and .defined(USE_ALL) + .include "../update_ext.s" +.else .if .defined(USE_VRC6) jsr ft_update_vrc6 .endif @@ -304,6 +307,7 @@ ft_update_ext: ;; Patch .if .defined(USE_S5B) jsr ft_update_s5b .endif +.endif END: ; End of music routine, return rts