Skip to content

Various module and NSF driver fixes #342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Source/APU/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
const uint8_t SNDCHIP_NONE = 0;
const uint8_t SNDCHIP_VRC6 = 1; // Konami VRCVI
const uint8_t SNDCHIP_VRC7 = 2; // Konami VRCVII
const uint8_t SNDCHIP_FDS = 4; // Famicom Disk Sound
const uint8_t SNDCHIP_FDS = 4; // Famicom Disk System
const uint8_t SNDCHIP_MMC5 = 8; // Nintendo MMC5
const uint8_t SNDCHIP_N163 = 16; // Namco N-106
const uint8_t SNDCHIP_N163 = 16; // Namco N163
const uint8_t SNDCHIP_S5B = 32; // Sunsoft 5B

enum chan_id_t {
Expand All @@ -43,7 +43,7 @@ enum chan_id_t {

CHANID_MMC5_SQUARE1,
CHANID_MMC5_SQUARE2,
CHANID_MMC5_VOICE,
CHANID_MMC5_VOICE, // not counted in NSF export

CHANID_N163_CH1, // // //
CHANID_N163_CH2,
Expand Down
192 changes: 73 additions & 119 deletions Source/ChunkRenderText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ void CChunkRenderText::StoreSamples(const std::vector<const CDSample*> &Samples,
str.Format("\n; DPCM samples (located at DPCM segment)\n");

if (Samples.size() > 0 && !m_bBankSwitched) {
// align first sample for external programs using assembly export
// this allows more flexible memory configurations to directly use the export
str.Append("\n\t.align 64\n");
str.Append("\n\t.segment \"DPCM\"\n");
}

Expand All @@ -162,10 +165,6 @@ void CChunkRenderText::StoreSamples(const std::vector<const CDSample*> &Samples,
if (m_bBankSwitched)
StoreDPCMBankSegment(bank, str);

// align first sample for external programs using assembly export
// this allows more flexible memory configurations to directly use the export
if (i == 0) str.Append("\n\t.align 64\n\n");

// adjust padding if necessary
if ((Address & 0x3F) > 0) {
str.Append("\n\t.align 64\n");
Expand Down Expand Up @@ -199,18 +198,21 @@ void CChunkRenderText::StoreHeaderChunk(CChunk *pChunk, CFile *pFile)
int len = pChunk->GetLength();
int i = 0;

str.AppendFormat("\t.word %s\n", pChunk->GetDataRefName(i++));
str.AppendFormat("\t.word %s\n", pChunk->GetDataRefName(i++));
str.AppendFormat("\t.word %s\n", pChunk->GetDataRefName(i++));
str.AppendFormat("\t.word %s\n", pChunk->GetDataRefName(i++));
str.AppendFormat("\t.word %s\n", pChunk->GetDataRefName(i++)); // // // Groove
str.AppendFormat("\t.byte %i ; flags\n", pChunk->GetData(i++));
if (pChunk->IsDataReference(i))
str.AppendFormat("\t.word %s\n", pChunk->GetDataRefName(i++)); // FDS waves
str.AppendFormat("\t.word %i ; NTSC speed\n", pChunk->GetData(i++));
str.AppendFormat("\t.word %i ; PAL speed\n", pChunk->GetData(i++));
if (i < pChunk->GetLength())
str.AppendFormat("\t.word %i ; N163 channels\n", pChunk->GetData(i++)); // N163 channels
// don't write anything if data doesn't exist
if (len != 0) {
str.AppendFormat("\t.word %s\n", pChunk->GetDataRefName(i++));
str.AppendFormat("\t.word %s\n", pChunk->GetDataRefName(i++));
str.AppendFormat("\t.word %s\n", pChunk->GetDataRefName(i++));
str.AppendFormat("\t.word %s\n", pChunk->GetDataRefName(i++));
str.AppendFormat("\t.word %s\n", pChunk->GetDataRefName(i++)); // // // Groove
str.AppendFormat("\t.byte %i ; flags\n", pChunk->GetData(i++));
if (pChunk->IsDataReference(i))
str.AppendFormat("\t.word %s\n", pChunk->GetDataRefName(i++)); // FDS waves
str.AppendFormat("\t.word %i ; NTSC speed\n", pChunk->GetData(i++));
str.AppendFormat("\t.word %i ; PAL speed\n", pChunk->GetData(i++));
if (i < len)
str.AppendFormat("\t.word %i ; N163 channels\n", pChunk->GetData(i++)); // N163 channels
}

m_headerStrings.Add(str);
}
Expand All @@ -234,18 +236,21 @@ void CChunkRenderText::StoreInstrumentChunk(CChunk *pChunk, CFile *pFile)
CStringA str;
int len = pChunk->GetLength();

str.Format("%s:\n\t.byte %i\n", pChunk->GetLabel(), pChunk->GetData(0));
// don't write anything if data doesn't exist
if (len != 0) {
str.Format("%s:\n\t.byte %i\n", pChunk->GetLabel(), pChunk->GetData(0));

for (int i = 1; i < len; ++i) {
if (pChunk->IsDataReference(i)) {
str.AppendFormat("\t.word %s\n", pChunk->GetDataRefName(i));
}
else {
if (pChunk->GetDataSize(i) == 1) {
str.AppendFormat("\t.byte $%02X\n", pChunk->GetData(i));
for (int i = 1; i < len; ++i) {
if (pChunk->IsDataReference(i)) {
str.AppendFormat("\t.word %s\n", pChunk->GetDataRefName(i));
}
else {
str.AppendFormat("\t.word $%04X\n", pChunk->GetData(i));
if (pChunk->GetDataSize(i) == 1) {
str.AppendFormat("\t.byte $%02X\n", pChunk->GetData(i));
}
else {
str.AppendFormat("\t.word $%04X\n", pChunk->GetData(i));
}
}
}
}
Expand Down Expand Up @@ -287,9 +292,8 @@ void CChunkRenderText::StoreSamplePointersChunk(CChunk *pChunk, CFile *pFile)
// Store sample pointer
str.Format("%s:\n", pChunk->GetLabel());

if (len > 0) {

int len = pChunk->GetLength();
// don't write anything if data doesn't exist
if (len != 0) {
int samplenum = 0;
for (int i = 0; i < len; i += 3) {
CStringA label;
Expand Down Expand Up @@ -458,15 +462,19 @@ void CChunkRenderText::StoreWavetableChunk(CChunk *pChunk, CFile *pFile)

// FDS waves
str.Format("%s:\n", pChunk->GetLabel());
str.Append("\t.byte ");

for (int i = 0; i < len; ++i) {
str.AppendFormat("$%02X", pChunk->GetData(i));
if ((i % 64 == 63) && (i < len - 1))
str.Append("\n\t.byte ");
else {
if (i < len - 1)
str.Append(", ");
// don't write anything if data doesn't exist
if (len != 0) {
str.Append("\t.byte ");

for (int i = 0; i < len; ++i) {
str.AppendFormat("$%02X", pChunk->GetData(i));
if ((i % 64 == 63) && (i < len - 1))
str.Append("\n\t.byte ");
else {
if (i < len - 1)
str.Append(", ");
}
}
}

Expand All @@ -485,17 +493,21 @@ void CChunkRenderText::StoreWavesChunk(CChunk *pChunk, CFile *pFile)

// Namco waves
str.Format("%s:\n", pChunk->GetLabel());
str.AppendFormat("\t.byte %i\n", waves);

str.Append("\t.byte ");

for (int i = 1; i < len; ++i) {
str.AppendFormat("$%02X", pChunk->GetData(i));
if (((i-1) % wave_len == 0) && (i < len))
str.Append("\n\t.byte ");
else {
if (i < len - 1)
str.Append(", ");
// don't write anything if data doesn't exist
if (len != 0) {
str.AppendFormat("\t.byte %i\n", waves);

str.Append("\t.byte ");

for (int i = 1; i < len; ++i) {
str.AppendFormat("$%02X", pChunk->GetData(i));
if (((i - 1) % wave_len == 0) && (i < len))
str.Append("\n\t.byte ");
else {
if (i < len - 1)
str.Append(", ");
}
}
}

Expand Down Expand Up @@ -563,7 +575,7 @@ void CChunkRenderText::StoreNSFStub(unsigned char Expansion, vibrato_t VibratoSt
str.Append("USE_AUX_DATA = 1\n");
bool MultiChip = ((Expansion & (Expansion - 1)) != 0) && UseAllChips;
if (MultiChip) {
// Simulate NSF export multichip
// Simulate NSF export multichip kernel
str.Append("USE_ALL = 1\n");
str.Append("NAMCO_CHANNELS = 8\n");
str.Append("USE_OLDVIBRATO = 1\n");
Expand Down Expand Up @@ -824,74 +836,13 @@ void CChunkRenderText::StoreUpdateExt(unsigned char Expansion) const
WriteFileString(str, m_pFileMultiChipUpdate);
}

void CChunkRenderText::StoreEnableExt(unsigned char Expansion) const
void CChunkRenderText::StoreEnableExt(std::vector<char> &ChannelOrder) 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;
CStringA 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");
StoreByteString(ChannelOrder.data(), (int)ChannelOrder.size(), str, DEFAULT_LINE_BREAK);
WriteFileString(str, m_pFileMultiChipEnable);
}

Expand Down Expand Up @@ -930,16 +881,19 @@ void CChunkRenderText::StoreByteString(const char *pData, int Len, CStringA &str
void CChunkRenderText::StoreByteString(const CChunk *pChunk, CStringA &str, int LineBreak) const
{
int len = pChunk->GetLength();

str.Append("\t.byte ");

for (int i = 0; i < len; ++i) {
str.AppendFormat("$%02X", pChunk->GetData(i));
// don't write anything if data doesn't exist
if (len != 0) {
str.Append("\t.byte ");

if ((i % LineBreak == (LineBreak - 1)) && (i < len - 1))
str.Append("\n\t.byte ");
else if (i < len - 1)
str.Append(", ");
for (int i = 0; i < len; ++i) {
str.AppendFormat("$%02X", pChunk->GetData(i));

if ((i % LineBreak == (LineBreak - 1)) && (i < len - 1))
str.Append("\n\t.byte ");
else if (i < len - 1)
str.Append(", ");
}
}

str.Append("\n");
Expand Down
2 changes: 1 addition & 1 deletion Source/ChunkRenderText.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CChunkRenderText
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 Expansion) const;
void StoreEnableExt(unsigned char Expansion) const;
void StoreEnableExt(std::vector<char> &ChannelOrder) const;
void SetExtraDataFiles(CFile *pFileNSFStub, CFile *pFileNSFHeader, CFile *pFileNSFConfig, CFile *pFilePeriods, CFile *pVibrato, CFile *pFileMultiChipEnable, CFile *pFileMultiChipUpdate);
void SetBankSwitching(bool bBankSwitched = false);

Expand Down
Loading