From ec69c30ca0f3dde7a1248ef7dd49e105c8e24d72 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sat, 21 Jun 2025 21:39:29 -0500 Subject: [PATCH] NES: here's your FamiTracker compatibility flag --- src/engine/fileOps/ftm.cpp | 1 + src/engine/platform/nes.cpp | 12 +++++++++--- src/engine/platform/nes.h | 1 + src/gui/sysConf.cpp | 6 ++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/engine/fileOps/ftm.cpp b/src/engine/fileOps/ftm.cpp index 35bca5f38..f1ee0eb15 100644 --- a/src/engine/fileOps/ftm.cpp +++ b/src/engine/fileOps/ftm.cpp @@ -655,6 +655,7 @@ bool DivEngine::loadFTM(unsigned char* file, size_t len, bool dnft, bool dnft_si int map_ch = 0; ds.system[systemID++] = DIV_SYSTEM_NES; + ds.systemFlags[0].set("resetSweep",true); // FamiTracker behavior if (pal) { ds.systemFlags[0].set("clockSel", 1); // PAL clock diff --git a/src/engine/platform/nes.cpp b/src/engine/platform/nes.cpp index 8d4fd8cc0..5513f2996 100644 --- a/src/engine/platform/nes.cpp +++ b/src/engine/platform/nes.cpp @@ -352,9 +352,6 @@ void DivPlatformNES::tick(bool sysTick) { } if (chan[i].sweepChanged) { chan[i].sweepChanged=false; - if (i==0) { - // rWrite(16+i*5,chan[i].sweep); - } } if (i<3) if (chan[i].std.phaseReset.had) { if (chan[i].std.phaseReset.val==1) { @@ -637,6 +634,13 @@ int DivPlatformNES::dispatch(DivCommand c) { } else if (!parent->song.brokenOutVol2) { rWrite(0x4000+c.chan*4,(chan[c.chan].envMode<<4)|chan[c.chan].vol|((chan[c.chan].duty&3)<<6)); } + if (resetSweep && c.chan<2) { + if (chan[c.chan].sweep!=0x08 && !chan[c.chan].sweepChanged) { + chan[c.chan].sweep=0x08; + chan[c.chan].prevFreq=-1; + rWrite(0x4001+(c.chan*4),chan[c.chan].sweep); + } + } break; case DIV_CMD_NOTE_OFF: if (c.chan==4) { @@ -724,6 +728,7 @@ int DivPlatformNES::dispatch(DivCommand c) { } } rWrite(0x4001+(c.chan*4),chan[c.chan].sweep); + chan[c.chan].sweepChanged=true; break; case DIV_CMD_NES_ENV_MODE: chan[c.chan].envMode=c.value&3; @@ -989,6 +994,7 @@ void DivPlatformNES::setFlags(const DivConfig& flags) { } dpcmModeDefault=flags.getBool("dpcmMode",true); + resetSweep=flags.getBool("resetSweep",false); } void DivPlatformNES::notifyInsDeletion(void* ins) { diff --git a/src/engine/platform/nes.h b/src/engine/platform/nes.h index 7c0a10aeb..5ab205ef0 100644 --- a/src/engine/platform/nes.h +++ b/src/engine/platform/nes.h @@ -68,6 +68,7 @@ class DivPlatformNES: public DivDispatch { signed char lastDPCMFreq; bool dpcmMode; bool dpcmModeDefault; + bool resetSweep; bool dacAntiClickOn; bool useNP; bool goingToLoop; diff --git a/src/gui/sysConf.cpp b/src/gui/sysConf.cpp index b36e5f32a..3b6a5d977 100644 --- a/src/gui/sysConf.cpp +++ b/src/gui/sysConf.cpp @@ -611,6 +611,7 @@ bool FurnaceGUI::drawSysConf(int chan, int sysPos, DivSystem type, DivConfig& fl case DIV_SYSTEM_5E01: { int clockSel=flags.getInt("clockSel",0); bool dpcmMode=flags.getBool("dpcmMode",true); + bool resetSweep=flags.getBool("resetSweep",false); ImGui::Text(_("Clock rate:")); @@ -642,10 +643,15 @@ bool FurnaceGUI::drawSysConf(int chan, int sysPos, DivSystem type, DivConfig& fl } ImGui::Unindent(); + if (ImGui::Checkbox(_("Reset sweep on new note"),&resetSweep)) { + altered=true; + } + if (altered) { e->lockSave([&]() { flags.set("clockSel",clockSel); flags.set("dpcmMode",dpcmMode); + flags.set("resetSweep",resetSweep); }); } break;