Skip to content

Commit

Permalink
Add NSF stub file for .asm export
Browse files Browse the repository at this point in the history
  • Loading branch information
Gumball2415 committed Feb 16, 2024
1 parent 72148d6 commit 1f9e366
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 190 deletions.
48 changes: 0 additions & 48 deletions Dn-FamiTracker.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,6 @@
<Manifest />
<Manifest />
<Manifest />
<PreBuildEvent>
<Command>call "$(ProjectDir)Source\drivers\build.cmd"</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Compiling NSF driver</Message>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ASAN-Debug|Win32'">
<Midl>
Expand Down Expand Up @@ -267,12 +261,6 @@
<Manifest />
<Manifest />
<Manifest />
<PreBuildEvent>
<Command>call "$(ProjectDir)Source\drivers\build.cmd"</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Compiling NSF driver</Message>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Midl>
Expand Down Expand Up @@ -314,12 +302,6 @@
<Manifest />
<Manifest />
<Manifest />
<PreBuildEvent>
<Command>call "$(ProjectDir)Source\drivers\build.cmd"</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Compiling NSF driver</Message>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ASAN-Debug|x64'">
<Midl>
Expand Down Expand Up @@ -361,12 +343,6 @@
<Manifest />
<Manifest />
<Manifest />
<PreBuildEvent>
<Command>call "$(ProjectDir)Source\drivers\build.cmd"</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Compiling NSF driver</Message>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Midl>
Expand Down Expand Up @@ -410,12 +386,6 @@
<DataExecutionPrevention>true</DataExecutionPrevention>
</Link>
<Manifest />
<PreBuildEvent>
<Command>call "$(ProjectDir)Source\drivers\build.cmd"</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Compiling NSF driver</Message>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ASAN-Release|Win32'">
<Midl>
Expand Down Expand Up @@ -459,12 +429,6 @@
<DataExecutionPrevention>true</DataExecutionPrevention>
</Link>
<Manifest />
<PreBuildEvent>
<Command>call "$(ProjectDir)Source\drivers\build.cmd"</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Compiling NSF driver</Message>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
Expand Down Expand Up @@ -509,12 +473,6 @@
<DataExecutionPrevention>true</DataExecutionPrevention>
</Link>
<Manifest />
<PreBuildEvent>
<Command>call "$(ProjectDir)Source\drivers\build.cmd"</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Compiling NSF driver</Message>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ASAN-Release|x64'">
<Midl>
Expand Down Expand Up @@ -559,12 +517,6 @@
<DataExecutionPrevention>true</DataExecutionPrevention>
</Link>
<Manifest />
<PreBuildEvent>
<Command>call "$(ProjectDir)Source\drivers\build.cmd"</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Compiling NSF driver</Message>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Source\APU\digital-sound-antiques\emu2413.c" />
Expand Down
12 changes: 3 additions & 9 deletions Dn-FamiTracker.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -747,9 +747,6 @@
<ClCompile Include="Source\ConfigEmulation.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\JsonExporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Source\Exception.h">
Expand Down Expand Up @@ -956,6 +953,9 @@
<ClInclude Include="Source\Compiler.h">
<Filter>Header Files\Export Headers</Filter>
</ClInclude>
<ClInclude Include="Source\Driver.h">
<Filter>Header Files\Export Headers</Filter>
</ClInclude>
<ClInclude Include="Source\PatternCompiler.h">
<Filter>Header Files\Export Headers</Filter>
</ClInclude>
Expand Down Expand Up @@ -1496,12 +1496,6 @@
<ClInclude Include="Source\rigtorp\SPSCQueue.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Source\JsonExporter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Source\Driver.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Dn-FamiTracker.rc">
Expand Down
2 changes: 1 addition & 1 deletion Source/ChunkRenderBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ int CChunkRenderNSF::GetDATAChunkSize() const

void CChunkRenderNSF::StoreChunkBankswitched(const CChunk *pChunk)
{
switch (pChunk->GetType()) {
switch (pChunk->GetType()) {
case CHUNK_FRAME_LIST:
case CHUNK_FRAME:
case CHUNK_PATTERN:
Expand Down
61 changes: 45 additions & 16 deletions Source/ChunkRenderText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const stChunkRenderFunc CChunkRenderText::RENDER_FUNCTIONS[] = {
};

CChunkRenderText::CChunkRenderText(CFile *pFile) : m_pFile(pFile),
m_pFileNSFStub(nullptr),
m_pFileNSFHeader(nullptr),
m_pFileNSFConfig(nullptr),
m_pFilePeriods(nullptr),
Expand Down Expand Up @@ -486,21 +487,48 @@ 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
{
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)
str.Append("USE_VRC6 = 1\n");
if (Header.SoundChip & SNDCHIP_VRC7)
str.Append("USE_VRC7 = 1\n");
if (Header.SoundChip & SNDCHIP_FDS)
str.Append("USE_FDS = 1\n");
if (Header.SoundChip & SNDCHIP_MMC5)
str.Append("USE_MMC5 = 1\n");
if (Header.SoundChip & SNDCHIP_N163)
str.Append("USE_N163 = 1\n");
if (Header.SoundChip & SNDCHIP_S5B)
str.Append("USE_S5B = 1\n");
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.AppendFormat("NAMCO_CHANNELS = %d\n", ActualNamcoChannels);

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");

WriteFileString(str, m_pFileNSFStub);
}

void CChunkRenderText::StoreNSFHeader(stNSFHeader Header) const
{
CString str;

str.Append(";\n; NSF Header\n;\n");
// TODO: make seperate stub file
//if (Header.SoundChip & SNDCHIP_VRC6) str.Append("USE_VRC6 = 1\n");
//if (Header.SoundChip & SNDCHIP_VRC7) str.Append("USE_VRC7 = 1\n");
//if (Header.SoundChip & SNDCHIP_FDS) str.Append("USE_FDS = 1\n");
//if (Header.SoundChip & SNDCHIP_MMC5) str.Append("USE_MMC5 = 1\n");
//if (Header.SoundChip & SNDCHIP_N163) str.Append("USE_N163 = 1\n");
//if (Header.SoundChip & SNDCHIP_S5B) str.Append("USE_S5B = 1\n");
//if (m_bBankSwitched) str.Append("USE_BANKSWITCH = 1\n");
//if (m_pDocument->GetVibratoStyle() == VIBRATO_OLD) str.Append("USE_OLDVIBRATO = 1\n");
//if (m_pDocument->GetLinearPitch()) str.Append("USE_LINEARPITCH = 1\n");
str.Append(".import __FTR_FILEOFFS__\n");
str.Append("NSF2_SIZE = __FTR_FILEOFFS__\n\n");

str.Append("\n.segment \"HEADER1\"\n");
str.AppendFormat(".byte $%02X, $%02X, $%02X, $%02X, $%02X\t; ID\n",
Expand All @@ -527,11 +555,10 @@ void CChunkRenderText::StoreNSFHeader(stNSFHeader Header) const
Header.BankValues[0], Header.BankValues[1], Header.BankValues[2], Header.BankValues[3],
Header.BankValues[4], Header.BankValues[5], Header.BankValues[6], Header.BankValues[7]);
str.AppendFormat(".word $%04X\t\t\t\t\t\t; PAL speed\n", Header.Speed_PAL);
str.AppendFormat(".byte $%02X\t\t\t\t\t\t\t; Region flags\n", Header.Flags);
str.AppendFormat(".byte $%02X\t\t\t\t\t\t; Region flags\n", Header.Flags);
str.Append(".byte EXPANSION_FLAG\t\t\t; Expansion audio flags\n");
str.AppendFormat(".byte $%02X\t\t\t\t\t\t; NSF2 flags\n", Header.NSF2Flags);
str.AppendFormat(".byte $%02X, $%02X, $%02X\t\t\t\t; NSF data length\n",
Header.NSFDataLength[0], Header.NSFDataLength[1], Header.NSFDataLength[2]);
str.Append(".faraddr NSF2_SIZE\t\t\t\t; NSF data length\n");

WriteFileString(str, m_pFileNSFHeader);
}
Expand All @@ -549,7 +576,8 @@ void CChunkRenderText::StoreNSFConfig(unsigned int DPCMSegment, stNSFHeader Head
str.Append(" ZP: start = $00, size = $100, type = rw, file = \"\";\n");
str.Append(" RAM: start = $200, size = $600, type = rw, file = \"\";\n");
str.Append(" HDR: start = $00, size = $80, type = ro, file = %O;\n");
str.Append(" PRG: start = $8000, size = $40000, type = " + segmentAttr + ", file = %O;\n");
str.Append(" PRG: start = $8000, size = $8000, type = " + segmentAttr + ", file = %O;\n");
str.Append(" FTR: start = $0000, size = $4000, type = ro, file = %O, define = yes;\n");
str.Append("}\n\n");
str.Append("SEGMENTS {\n");
str.Append(" ZEROPAGE: load = ZP, type = zp;\n");
Expand All @@ -559,7 +587,7 @@ void CChunkRenderText::StoreNSFConfig(unsigned int DPCMSegment, stNSFHeader Head
str.Append(" HEADER3: load = HDR, type = ro, start = $2E, fillval = $0;\n");
str.Append(" HEADER4: load = HDR, type = ro, start = $4E, fillval = $0;\n");
str.Append(" HEADER5: load = HDR, type = ro, start = $6E;\n");
str.Append(" CODE: load = PRG, type = " + segmentAttr + ", start = $8000;\n");
str.Append(" CODE: load = PRG, type = " + segmentAttr + ";\n");
str.AppendFormat((" DPCM: load = PRG, type = " + segmentAttr + ", start = $%04X;\n"), DPCMSegment);
str.Append("}\n");
}
Expand Down Expand Up @@ -659,8 +687,9 @@ void CChunkRenderText::StoreVibrato(unsigned int *pLUTVibrato) const
WriteFileString(str, m_pFileVibrato);
}

void CChunkRenderText::SetExtraDataFiles(CFile* pFileNSFHeader, CFile* pFileNSFConfig, CFile* pFilePeriods, CFile* pFileVibrato)
void CChunkRenderText::SetExtraDataFiles(CFile *pFileNSFStub, CFile* pFileNSFHeader, CFile* pFileNSFConfig, CFile* pFilePeriods, CFile* pFileVibrato)
{
m_pFileNSFStub = pFileNSFStub;
m_pFileNSFHeader = pFileNSFHeader;
m_pFileNSFConfig = pFileNSFConfig;
m_pFilePeriods = pFilePeriods;
Expand Down
16 changes: 9 additions & 7 deletions Source/ChunkRenderText.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class CChunkRenderText;
class CDSample; // // //

typedef void (CChunkRenderText::*renderFunc_t)(CChunk *pChunk, CFile *pFile);
typedef void (CChunkRenderText:: *renderFunc_t)(CChunk *pChunk, CFile *pFile);

struct stNSFHeader;

Expand All @@ -44,14 +44,15 @@ class CChunkRenderText
{
public:
CChunkRenderText(CFile *pFile);
void StoreChunks(const std::vector<CChunk*> &Chunks);
void StoreSamples(const std::vector<const CDSample*> &Samples);
void WriteFileString(const CStringA& str, CFile* pFile) const;
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 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* pLUTFDS, unsigned int* pLUTN163, unsigned int* pLUTVRC7) const;
void StoreVibrato(unsigned int* pLUTVibrato) const;
void SetExtraDataFiles(CFile* pFileNSFHeader, CFile* pFileNSFConfig, CFile* pFilePeriods, CFile* pFileVibrato);
void StorePeriods(unsigned int *pLUTNTSC, unsigned int *pLUTPAL, unsigned int *pLUTSaw, unsigned int *pLUTFDS, unsigned int *pLUTN163, unsigned int *pLUTVRC7) const;
void StoreVibrato(unsigned int *pLUTVibrato) const;
void SetExtraDataFiles(CFile *pFileNSFStub, CFile *pFileNSFHeader, CFile *pFileNSFConfig, CFile *pFilePeriods, CFile *pFileVibrato);

// Labels
// // // moved from CCompiler
Expand Down Expand Up @@ -116,6 +117,7 @@ class CChunkRenderText
CStringArray m_wavesStrings;

CFile *m_pFile;
CFile *m_pFileNSFStub;
CFile *m_pFileNSFHeader;
CFile *m_pFileNSFConfig;
CFile *m_pFilePeriods;
Expand Down
Loading

0 comments on commit 1f9e366

Please sign in to comment.