diff --git a/CMakeLists.txt b/CMakeLists.txt index afc39e3fb..5c3129128 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -515,6 +515,7 @@ src/engine/platform/zxbeeper.cpp src/engine/platform/bubsyswsg.cpp src/engine/platform/n163.cpp src/engine/platform/pet.cpp +src/engine/platform/pong.cpp src/engine/platform/vic20.cpp src/engine/platform/vrc6.cpp src/engine/platform/es5506.cpp diff --git a/extern/imgui_patched/backends/imgui_impl_sdl.cpp b/extern/imgui_patched/backends/imgui_impl_sdl.cpp index e7ae8d072..00c55ae80 100644 --- a/extern/imgui_patched/backends/imgui_impl_sdl.cpp +++ b/extern/imgui_patched/backends/imgui_impl_sdl.cpp @@ -65,6 +65,7 @@ #include "imgui.h" #include "imgui_impl_sdl.h" +#include #include // SDL @@ -288,6 +289,7 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event) if (!platform_io.Monitors.empty() && platform_io.Monitors[0].DpiScale > 1.0f) { // The Framebuffer is scaled by an integer ceiling of the actual ratio, so 2.0 not 1.685 on Mac! + //printf("multiply by %f\n",platform_io.Monitors[0].DpiScale); mouse_pos.x *= std::ceil(platform_io.Monitors[0].DpiScale); mouse_pos.y *= std::ceil(platform_io.Monitors[0].DpiScale); } @@ -690,10 +692,11 @@ void ImGui_ImplSDL2_NewFrame() // On Apple and Wayland, The window size is reported in Low DPI, even when running in high DPI mode ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); - if (!platform_io.Monitors.empty() /*&& platform_io.Monitors[0].DpiScale > 1.0f*/ && display_h != h) + if (!platform_io.Monitors.empty() /*&& platform_io.Monitors[0].DpiScale > 1.0f*/ && display_h != h && w != 0) { io.DisplayFramebufferScale = ImVec2(1.0f, 1.0f); io.DisplaySize = ImVec2((float)display_w, (float)display_h); + //printf("write %d/%d to DpiScale\n",display_w,w); platform_io.Monitors[0].DpiScale=(float)display_w/(float)w; } diff --git a/papers/doc/7-systems/nes.md b/papers/doc/7-systems/nes.md index c9b4d0242..37d4a7037 100644 --- a/papers/doc/7-systems/nes.md +++ b/papers/doc/7-systems/nes.md @@ -19,7 +19,65 @@ also known as Famicom. it is a five-channel sound generator: first two channels - `x` is the time. - `y` is the shift. - set to 0 to disable it. +- `15xx`: set envelope mode. + - `0`: envelope + length counter (volume represents envelope duration). + - `1`: length counter (volume represents output volume). + - `2`: looping envelope (volume represents envelope duration). + - `3`: constant volume (default; volume represents output volume). + - pulse and noise channels only. + - you may need to apply a phase reset (using the macro) to make the envelope effective. +- `16xx`: set length counter. + - see table below for possible values. + - this will trigger phase reset. +- `17xx`: set frame counter mode. + - `0`: 4-step. + - NTSC: 120Hz sweeps and lengths; 240Hz envelope. + - PAL: 100Hz sweeps and lengths; 200Hz envelope. + - Dendy: 118.9Hz sweeps and lengths; 237.8Hz envelope. + - `1`: 5-step. + - NTSC: 96Hz sweeps and lengths; 192Hz envelope. + - PAL: 80Hz sweeps and lengths; 160Hz envelope. + - Dendy: 95.1Hz sweeps and lengths; 190.2Hz envelope. - `18xx`: set PCM channel mode. - `00`: PCM (software). - `01`: DPCM (hardware). - when in DPCM mode, samples will sound muffled (due to its nature), availables pitches are limited and loop point is ignored. + +# length counter table + +val | raw | NTSC | PAL | Dendy | NTSC 5-step | PAL 5-step | Dendy 5-step +----|-----|-------|-------|-------|-------------|------------|-------------- + 00 | 10 | 83ms | 100ms | 84ms | 104ms | 125ms | 105ms + 01 | 254 | 2.1s | 2.5s | 2.1s | 2.6s | 3.2s | 2.7s + 02 | 20 | 166ms | 200ms | 168ms | 208ms | 250ms | 210ms + 03 | 2 | 17ms | 20ms | 17ms | 21ms | 25ms | 21ms + 04 | 40 | 333ms | 400ms | 336ms | 417ms | 500ms | 421ms + 05 | 4 | 33ms | 40ms | 34ms | 42ms | 50ms | 42ms + 06 | 80 | 667ms | 800ms | 673ms | 833ms | 1.0s | 841ms + 07 | 6 | 50ms | 60ms | 50ms | 63ms | 75ms | 63ms + 08 | 160 | 1.3s | 1.6s | 1.3s | 1.7s | 2.0s | 1.7s + 09 | 8 | 67ms | 80ms | 67ms | 83ms | 100ms | 84ms + 0A | 60 | 500ms | 600ms | 505ms | 625ms | 750ms | 631ms + 0B | 10 | 83ms | 100ms | 84ms | 104ms | 125ms | 105ms + 0C | 14 | 117ms | 140ms | 118ms | 146ms | 175ms | 147ms + 0D | 12 | 100ms | 120ms | 101ms | 125ms | 150ms | 126ms + 0E | 26 | 217ms | 260ms | 219ms | 271ms | 325ms | 273ms + 0F | 14 | 117ms | 140ms | 118ms | 145ms | 175ms | 147ms + 10 | 12 | 100ms | 120ms | 101ms | 125ms | 150ms | 126ms + 11 | 16 | 133ms | 160ms | 135ms | 167ms | 200ms | 168ms + 12 | 24 | 200ms | 240ms | 202ms | 250ms | 300ms | 252ms + 13 | 18 | 150ms | 180ms | 151ms | 188ms | 225ms | 189ms + 14 | 48 | 400ms | 480ms | 404ms | 500ms | 600ms | 505ms + 15 | 20 | 167ms | 200ms | 168ms | 208ms | 250ms | 210ms + 16 | 96 | 800ms | 960ms | 807ms | 1.0s | 1.2s | 1.0s + 17 | 22 | 183ms | 220ms | 185ms | 229ms | 275ms | 231ms + 18 | 192 | 1.6s | 1.9s | 1.6s | 2.0s | 2.4s | 2.0s + 19 | 24 | 200ms | 240ms | 202ms | 250ms | 300ms | 252ms + 1A | 72 | 600ms | 720ms | 606ms | 750ms | 900ms | 757ms + 1B | 26 | 217ms | 260ms | 219ms | 271ms | 325ms | 273ms + 1C | 16 | 133ms | 160ms | 135ms | 167ms | 200ms | 168ms + 1D | 28 | 233ms | 280ms | 235ms | 292ms | 350ms | 294ms + 1E | 32 | 267ms | 320ms | 269ms | 333ms | 400ms | 336ms + 1F | 30 | 250ms | 300ms | 252ms | 313ms | 375ms | 315ms + +reference: [NESdev](https://www.nesdev.org/wiki/APU_Length_Counter) diff --git a/papers/format.md b/papers/format.md index 66ffc82d1..f3a7566f1 100644 --- a/papers/format.md +++ b/papers/format.md @@ -265,6 +265,7 @@ size | description | - 0xc5: YM2610B CSM - 20 channels | - 0xde: YM2610B extended - 19 channels | - 0xe0: QSound - 19 channels + | - 0xfc: Pong - 1 channel | - 0xfd: Dummy System - 8 channels | - 0xfe: reserved for development | - 0xff: reserved for development diff --git a/src/engine/brrUtils.c b/src/engine/brrUtils.c index f5fce33b1..e3b20c26d 100644 --- a/src/engine/brrUtils.c +++ b/src/engine/brrUtils.c @@ -130,7 +130,7 @@ long brrEncode(short* buf, unsigned char* out, long len, long loopStart) { } // encode with filter - if (i && i!=loopStart) { + if (i /*&& i!=loopStart*/) { // 1: x = o0 - o1 * 15/16 // 2: x = o0 + o2 * 15/16 - o1 * 61/32 // 3: x = o0 + o2 * 13/16 - o1 * 115/64 diff --git a/src/engine/dispatch.h b/src/engine/dispatch.h index 926f8fc7a..6bdccc127 100644 --- a/src/engine/dispatch.h +++ b/src/engine/dispatch.h @@ -217,6 +217,10 @@ enum DivDispatchCmds { DIV_CMD_SNES_ECHO_FEEDBACK, DIV_CMD_SNES_ECHO_FIR, + DIV_CMD_NES_ENV_MODE, + DIV_CMD_NES_LENGTH, + DIV_CMD_NES_COUNT_MODE, + DIV_ALWAYS_SET_VOLUME, // () -> alwaysSetVol DIV_CMD_MAX diff --git a/src/engine/dispatchContainer.cpp b/src/engine/dispatchContainer.cpp index b0d2b69ae..5f0030859 100644 --- a/src/engine/dispatchContainer.cpp +++ b/src/engine/dispatchContainer.cpp @@ -60,6 +60,7 @@ #include "platform/bubsyswsg.h" #include "platform/n163.h" #include "platform/pet.h" +#include "platform/pong.h" #include "platform/vic20.h" #include "platform/vrc6.h" #include "platform/fds.h" @@ -366,6 +367,9 @@ void DivDispatchContainer::init(DivSystem sys, DivEngine* eng, int chanCount, do case DIV_SYSTEM_VIC20: dispatch=new DivPlatformVIC20; break; + case DIV_SYSTEM_PONG: + dispatch=new DivPlatformPong; + break; case DIV_SYSTEM_VRC6: dispatch=new DivPlatformVRC6; break; diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 5be458be5..c3dd7d6e1 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -1042,6 +1042,8 @@ void DivEngine::runExportThread() { curOrder=0; prevOrder=0; curFadeOutSample=0; + lastLoopPos=-1; + totalLoops=0; isFadingOut=false; if (exportFadeOut<=0.01) { remainingLoops=loopCount; @@ -1984,10 +1986,14 @@ void DivEngine::getCommandStream(std::vector& where) { } void DivEngine::playSub(bool preserveDrift, int goalRow) { + logV("playSub() called"); std::chrono::high_resolution_clock::time_point timeStart=std::chrono::high_resolution_clock::now(); for (int i=0; isetSkipRegisterWrites(false); reset(); - if (preserveDrift && curOrder==0) return; + if (preserveDrift && curOrder==0) { + logV("preserveDrift && curOrder is true"); + return; + } bool oldRepeatPattern=repeatPattern; repeatPattern=false; int goal=curOrder; @@ -2000,9 +2006,7 @@ void DivEngine::playSub(bool preserveDrift, int goalRow) { prevDrift=clockDrift; clockDrift=0; cycles=0; - if (preserveDrift) { - endOfSong=false; - } else { + if (!preserveDrift) { ticks=1; tempoAccum=0; totalTicks=0; @@ -2011,6 +2015,7 @@ void DivEngine::playSub(bool preserveDrift, int goalRow) { totalLoops=0; lastLoopPos=-1; } + endOfSong=false; speedAB=false; playing=true; skipping=true; @@ -2352,6 +2357,7 @@ void DivEngine::reset() { speed2=curSubSong->speed2; firstTick=false; shallStop=false; + shallStopSched=false; nextSpeed=speed1; divider=60; if (curSubSong->customTempo) { diff --git a/src/engine/engine.h b/src/engine/engine.h index b30f52b1d..ccb0f6d79 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -328,7 +328,7 @@ class DivEngine { bool lowQuality; bool playing; bool freelance; - bool shallStop; + bool shallStop, shallStopSched; bool speedAB; bool endOfSong; bool consoleMode; @@ -1017,6 +1017,7 @@ class DivEngine { playing(false), freelance(false), shallStop(false), + shallStopSched(false), speedAB(false), endOfSong(false), consoleMode(false), diff --git a/src/engine/platform/mmc5.cpp b/src/engine/platform/mmc5.cpp index 9e3e52920..b52017e85 100644 --- a/src/engine/platform/mmc5.cpp +++ b/src/engine/platform/mmc5.cpp @@ -289,7 +289,7 @@ int DivPlatformMMC5::dispatch(DivCommand c) { } case DIV_CMD_STD_NOISE_MODE: chan[c.chan].duty=c.value; - rWrite(0x5000+c.chan*4,0x30|chan[c.chan].outVol|((chan[c.chan].duty&3)<<6)); + rWrite(0x5000+c.chan*4,0x30|(chan[c.chan].active?chan[c.chan].outVol:0)|((chan[c.chan].duty&3)<<6)); break; case DIV_CMD_SAMPLE_BANK: sampleBank=c.value; diff --git a/src/engine/platform/nes.cpp b/src/engine/platform/nes.cpp index 87f89a9dc..47d815733 100644 --- a/src/engine/platform/nes.cpp +++ b/src/engine/platform/nes.cpp @@ -214,7 +214,7 @@ void DivPlatformNES::tick(bool sysTick) { rWrite(0x4000+i*4,(chan[i].outVol==0)?0:255); chan[i].freqChanged=true; } else { - rWrite(0x4000+i*4,0x30|chan[i].outVol|((chan[i].duty&3)<<6)); + rWrite(0x4000+i*4,(chan[i].envMode<<4)|chan[i].outVol|((chan[i].duty&3)<<6)); } } if (chan[i].std.arp.had) { @@ -239,7 +239,7 @@ void DivPlatformNES::tick(bool sysTick) { } } if (i!=2) { - rWrite(0x4000+i*4,0x30|chan[i].outVol|((chan[i].duty&3)<<6)); + rWrite(0x4000+i*4,(chan[i].envMode<<4)|chan[i].outVol|((chan[i].duty&3)<<6)); } if (i==3) { // noise chan[i].freqChanged=true; @@ -289,11 +289,11 @@ void DivPlatformNES::tick(bool sysTick) { } if (i==3) { // noise rWrite(0x4002+i*4,(chan[i].duty<<7)|chan[i].freq); - rWrite(0x4003+i*4,0xf0); + rWrite(0x4003+i*4,(chan[i].len<<3)); } else { rWrite(0x4002+i*4,chan[i].freq&0xff); if ((chan[i].prevFreq>>8)!=(chan[i].freq>>8) || i==2) { - rWrite(0x4003+i*4,0xf8|(chan[i].freq>>8)); + rWrite(0x4003+i*4,(chan[i].len<<3)|(chan[i].freq>>8)); } if (chan[i].freq!=65535 && chan[i].freq!=0) { chan[i].prevFreq=chan[i].freq; @@ -419,7 +419,7 @@ int DivPlatformNES::dispatch(DivCommand c) { if (c.chan==2) { rWrite(0x4000+c.chan*4,0xff); } else if (!parent->song.brokenOutVol2) { - rWrite(0x4000+c.chan*4,0x30|chan[c.chan].vol|((chan[c.chan].duty&3)<<6)); + rWrite(0x4000+c.chan*4,(chan[c.chan].envMode<<4)|chan[c.chan].vol|((chan[c.chan].duty&3)<<6)); } break; case DIV_CMD_NOTE_OFF: @@ -451,7 +451,7 @@ int DivPlatformNES::dispatch(DivCommand c) { if (c.chan==2) { rWrite(0x4000+c.chan*4,0xff); } else { - rWrite(0x4000+c.chan*4,0x30|chan[c.chan].vol|((chan[c.chan].duty&3)<<6)); + rWrite(0x4000+c.chan*4,(chan[c.chan].envMode<<4)|chan[c.chan].vol|((chan[c.chan].duty&3)<<6)); } } } @@ -491,7 +491,7 @@ int DivPlatformNES::dispatch(DivCommand c) { if (c.chan==3) { // noise chan[c.chan].freqChanged=true; } else if (c.chan<2) { - rWrite(0x4000+c.chan*4,0x30|chan[c.chan].outVol|((chan[c.chan].duty&3)<<6)); + rWrite(0x4000+c.chan*4,(chan[c.chan].active?((chan[c.chan].envMode<<4)|chan[c.chan].outVol):0x30)|((chan[c.chan].duty&3)<<6)); } break; case DIV_CMD_NES_SWEEP: @@ -507,6 +507,24 @@ int DivPlatformNES::dispatch(DivCommand c) { } rWrite(0x4001+(c.chan*4),chan[c.chan].sweep); break; + case DIV_CMD_NES_ENV_MODE: + chan[c.chan].envMode=c.value&3; + if (c.chan==3) { // noise + chan[c.chan].freqChanged=true; + } else if (c.chan<2) { + rWrite(0x4000+c.chan*4,(chan[c.chan].active?((chan[c.chan].envMode<<4)|chan[c.chan].outVol):0x30)|((chan[c.chan].duty&3)<<6)); + } + break; + case DIV_CMD_NES_LENGTH: + if (c.chan>=4) break; + chan[c.chan].len=c.value&0x1f; + chan[c.chan].freqChanged=true; + chan[c.chan].prevFreq=-1; + break; + case DIV_CMD_NES_COUNT_MODE: + countMode=c.value; + rWrite(0x4017,countMode?0x80:0); + break; case DIV_CMD_NES_DMC: rWrite(0x4011,c.value&0x7f); break; @@ -572,6 +590,7 @@ void DivPlatformNES::forceIns() { } rWrite(0x4001,chan[0].sweep); rWrite(0x4005,chan[1].sweep); + rWrite(0x4017,countMode?0x80:0); } void* DivPlatformNES::getChanState(int ch) { @@ -615,6 +634,7 @@ void DivPlatformNES::reset() { dpcmBank=0; dpcmMode=false; goingToLoop=false; + countMode=false; if (useNP) { nes1_NP->Reset(); diff --git a/src/engine/platform/nes.h b/src/engine/platform/nes.h index ef4a9e725..16f52f20c 100644 --- a/src/engine/platform/nes.h +++ b/src/engine/platform/nes.h @@ -28,7 +28,7 @@ class DivPlatformNES: public DivDispatch { struct Channel { int freq, baseFreq, pitch, pitch2, prevFreq, note, ins; - unsigned char duty, sweep; + unsigned char duty, sweep, envMode, len; bool active, insChanged, freqChanged, sweepChanged, keyOn, keyOff, inPorta, furnaceDac; signed char vol, outVol, wave; DivMacroInt std; @@ -46,6 +46,8 @@ class DivPlatformNES: public DivDispatch { ins(-1), duty(0), sweep(8), + envMode(3), + len(0x1f), active(false), insChanged(true), freqChanged(false), @@ -74,6 +76,7 @@ class DivPlatformNES: public DivDispatch { bool dacAntiClickOn; bool useNP; bool goingToLoop; + bool countMode; struct NESAPU* nes; xgm::NES_APU* nes1_NP; xgm::NES_DMC* nes2_NP; diff --git a/src/engine/platform/pong.cpp b/src/engine/platform/pong.cpp new file mode 100644 index 000000000..1015fdda7 --- /dev/null +++ b/src/engine/platform/pong.cpp @@ -0,0 +1,267 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2022 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "pong.h" +#include "../engine.h" +#include "../../ta-log.h" + +#define CHIP_DIVIDER 16 + +void DivPlatformPong::acquire(short* bufL, short* bufR, size_t start, size_t len) { + int out=0; + for (size_t i=start; idata[oscBuf->needle++]=out; + } else { + bufL[i]=0; + oscBuf->data[oscBuf->needle++]=0; + flip=false; + } + } +} + +void DivPlatformPong::tick(bool sysTick) { + for (int i=0; i<1; i++) { + chan[i].std.next(); + if (chan[i].std.vol.had) { + chan[i].outVol=(chan[i].vol && chan[i].std.vol.val); + on=chan[i].outVol; + } + if (chan[i].std.arp.had) { + if (!chan[i].inPorta) { + chan[i].baseFreq=NOTE_PERIODIC(parent->calcArp(chan[i].note,chan[i].std.arp.val)); + } + chan[i].freqChanged=true; + } + if (sysTick) { + flip=false; + pos=0; + } + if (chan[i].std.pitch.had) { + if (chan[i].std.pitch.mode) { + chan[i].pitch2+=chan[i].std.pitch.val; + CLAMP_VAR(chan[i].pitch2,-32768,32767); + } else { + chan[i].pitch2=chan[i].std.pitch.val; + } + chan[i].freqChanged=true; + } + if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) { + chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true,0,chan[i].pitch2,chipClock,CHIP_DIVIDER)-1; + if (chan[i].freq<0) chan[i].freq=0; + if (chan[i].freq>1) chan[i].freq=1; + if (chan[i].keyOn) { + on=true; + } + if (chan[i].keyOff) { + on=false; + } + freq=chan[i].freq; + if (chan[i].keyOn) chan[i].keyOn=false; + if (chan[i].keyOff) chan[i].keyOff=false; + chan[i].freqChanged=false; + } + } +} + +int DivPlatformPong::dispatch(DivCommand c) { + switch (c.cmd) { + case DIV_CMD_NOTE_ON: + if (c.value!=DIV_NOTE_NULL) { + chan[c.chan].baseFreq=NOTE_PERIODIC(c.value); + chan[c.chan].freqChanged=true; + chan[c.chan].note=c.value; + } + chan[c.chan].active=true; + chan[c.chan].keyOn=true; + chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_BEEPER)); + if (!parent->song.brokenOutVol && !chan[c.chan].std.vol.will) { + chan[c.chan].outVol=chan[c.chan].vol; + } + break; + case DIV_CMD_NOTE_OFF: + chan[c.chan].active=false; + chan[c.chan].keyOff=true; + chan[c.chan].macroInit(NULL); + break; + case DIV_CMD_NOTE_OFF_ENV: + case DIV_CMD_ENV_RELEASE: + chan[c.chan].std.release(); + break; + case DIV_CMD_INSTRUMENT: + if (chan[c.chan].ins!=c.value || c.value2==1) { + chan[c.chan].ins=c.value; + } + break; + case DIV_CMD_VOLUME: + if (chan[c.chan].vol!=c.value) { + chan[c.chan].vol=c.value; + if (!chan[c.chan].std.vol.has) { + chan[c.chan].outVol=c.value; + } + if (chan[c.chan].active) { + on=chan[c.chan].vol; + } + } + break; + case DIV_CMD_GET_VOLUME: + return chan[c.chan].vol; + break; + case DIV_CMD_PITCH: + chan[c.chan].pitch=c.value; + chan[c.chan].freqChanged=true; + break; + case DIV_CMD_NOTE_PORTA: { + int destFreq=NOTE_PERIODIC(c.value2); + bool return2=false; + if (destFreq>chan[c.chan].baseFreq) { + chan[c.chan].baseFreq+=c.value; + if (chan[c.chan].baseFreq>=destFreq) { + chan[c.chan].baseFreq=destFreq; + return2=true; + } + } else { + chan[c.chan].baseFreq-=c.value; + if (chan[c.chan].baseFreq<=destFreq) { + chan[c.chan].baseFreq=destFreq; + return2=true; + } + } + chan[c.chan].freqChanged=true; + if (return2) { + chan[c.chan].inPorta=false; + return 2; + } + break; + } + case DIV_CMD_LEGATO: + if (c.chan==3) break; + chan[c.chan].baseFreq=NOTE_PERIODIC(c.value+((chan[c.chan].std.arp.will && !chan[c.chan].std.arp.mode)?(chan[c.chan].std.arp.val):(0))); + chan[c.chan].freqChanged=true; + chan[c.chan].note=c.value; + break; + case DIV_CMD_PRE_PORTA: + if (chan[c.chan].active && c.value2) { + if (parent->song.resetMacroOnPorta) chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_BEEPER)); + } + if (!chan[c.chan].inPorta && c.value && !parent->song.brokenPortaArp && chan[c.chan].std.arp.will) chan[c.chan].baseFreq=NOTE_PERIODIC(chan[c.chan].note); + chan[c.chan].inPorta=c.value; + break; + case DIV_CMD_GET_VOLMAX: + return 1; + break; + case DIV_ALWAYS_SET_VOLUME: + return 1; + break; + default: + break; + } + return 1; +} + +void DivPlatformPong::muteChannel(int ch, bool mute) { + isMuted[ch]=mute; +} + +void DivPlatformPong::forceIns() { + for (int i=0; i<1; i++) { + chan[i].insChanged=true; + } +} + +void* DivPlatformPong::getChanState(int ch) { + return &chan[ch]; +} + +DivMacroInt* DivPlatformPong::getChanMacroInt(int ch) { + return &chan[ch].std; +} + +DivDispatchOscBuffer* DivPlatformPong::getOscBuffer(int ch) { + return oscBuf; +} + +void DivPlatformPong::reset() { + for (int i=0; i<1; i++) { + chan[i]=DivPlatformPong::Channel(); + chan[i].std.setEngine(parent); + } + if (dumpWrites) { + addWrite(0xffffffff,0); + } + + on=false; + lastOn=false; + freq=0; + pos=0; + flip=false; + + memset(regPool,0,2); +} + +bool DivPlatformPong::keyOffAffectsArp(int ch) { + return true; +} + +void DivPlatformPong::setFlags(const DivConfig& flags) { + chipClock=15625; + rate=chipClock; + oscBuf->rate=rate; +} + +void DivPlatformPong::notifyInsDeletion(void* ins) { + for (int i=0; i<1; i++) { + chan[i].std.notifyInsDeletion((DivInstrument*)ins); + } +} + +void DivPlatformPong::poke(unsigned int addr, unsigned short val) { + // ??? +} + +void DivPlatformPong::poke(std::vector& wlist) { + // ??? +} + +int DivPlatformPong::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) { + parent=p; + dumpWrites=false; + skipRegisterWrites=false; + for (int i=0; i<1; i++) { + isMuted[i]=false; + } + oscBuf=new DivDispatchOscBuffer; + setFlags(flags); + + reset(); + return 5; +} + +void DivPlatformPong::quit() { + delete oscBuf; +} + +DivPlatformPong::~DivPlatformPong() { +} diff --git a/src/engine/platform/pong.h b/src/engine/platform/pong.h new file mode 100644 index 000000000..afce74506 --- /dev/null +++ b/src/engine/platform/pong.h @@ -0,0 +1,89 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2022 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _PONG_H +#define _PONG_H + +#include "../dispatch.h" +#include "../macroInt.h" + +class DivPlatformPong: public DivDispatch { + struct Channel { + int freq, baseFreq, pitch, pitch2, note, ins; + unsigned char duty, sweep; + bool active, insChanged, freqChanged, sweepChanged, keyOn, keyOff, inPorta, furnaceDac; + signed char vol, outVol, wave; + DivMacroInt std; + void macroInit(DivInstrument* which) { + std.init(which); + pitch2=0; + } + Channel(): + freq(0), + baseFreq(0), + pitch(0), + pitch2(0), + note(0), + ins(-1), + duty(0), + sweep(8), + active(false), + insChanged(true), + freqChanged(false), + sweepChanged(false), + keyOn(false), + keyOff(false), + inPorta(false), + furnaceDac(false), + vol(1), + outVol(1), + wave(-1) {} + }; + Channel chan[1]; + DivDispatchOscBuffer* oscBuf; + bool isMuted[1]; + bool on, flip, lastOn; + int pos; + bool freq; + unsigned char regPool[2]; + + friend void putDispatchChip(void*,int); + friend void putDispatchChan(void*,int,int); + + public: + void acquire(short* bufL, short* bufR, size_t start, size_t len); + int dispatch(DivCommand c); + void* getChanState(int chan); + DivMacroInt* getChanMacroInt(int ch); + DivDispatchOscBuffer* getOscBuffer(int chan); + void reset(); + void forceIns(); + void tick(bool sysTick=true); + void muteChannel(int ch, bool mute); + bool keyOffAffectsArp(int ch); + void setFlags(const DivConfig& flags); + void notifyInsDeletion(void* ins); + void poke(unsigned int addr, unsigned short val); + void poke(std::vector& wlist); + int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags); + void quit(); + ~DivPlatformPong(); +}; + +#endif diff --git a/src/engine/platform/snes.cpp b/src/engine/platform/snes.cpp index 8ea97c937..fd15cc74d 100644 --- a/src/engine/platform/snes.cpp +++ b/src/engine/platform/snes.cpp @@ -596,10 +596,16 @@ void DivPlatformSNES::writeOutVol(int ch) { void DivPlatformSNES::writeEnv(int ch) { if (chan[ch].state.useEnv) { - chWrite(ch,5,chan[ch].state.a|(chan[ch].state.d<<4)|0x80); - if (chan[ch].state.sus && chan[ch].active) { - chWrite(ch,6,chan[ch].state.s<<5); + if (chan[ch].state.sus) { + if (chan[ch].active) { + chWrite(ch,5,chan[ch].state.a|(chan[ch].state.d<<4)|0x80); + chWrite(ch,6,chan[ch].state.s<<5); + } else { // dec linear + chWrite(ch,7,0x80|chan[ch].state.r); + chWrite(ch,5,0); + } } else { + chWrite(ch,5,chan[ch].state.a|(chan[ch].state.d<<4)|0x80); chWrite(ch,6,chan[ch].state.r|(chan[ch].state.s<<5)); } } else { diff --git a/src/engine/platform/ym2608.cpp b/src/engine/platform/ym2608.cpp index 487398233..ad31e4a45 100644 --- a/src/engine/platform/ym2608.cpp +++ b/src/engine/platform/ym2608.cpp @@ -627,7 +627,7 @@ void DivPlatformYM2608::tick(bool sysTick) { immWrite(0x109,chan[15].freq&0xff); immWrite(0x10a,(chan[15].freq>>8)&0xff); if (chan[15].keyOn || chan[15].keyOff) { - immWrite(0x100,0x01); // reset + if (chan[15].keyOff) immWrite(0x100,0x01); // reset if (chan[15].active && chan[15].keyOn && !chan[15].keyOff) { if (chan[15].sample>=0 && chan[15].samplesong.sampleLen) { DivSample* s=parent->getSample(chan[15].sample); @@ -685,6 +685,7 @@ int DivPlatformYM2608::dispatch(DivCommand c) { chan[c.chan].sample=ins->amiga.getSample(c.value); if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.sampleLen) { DivSample* s=parent->getSample(chan[c.chan].sample); + immWrite(0x100,0x01); // reset immWrite(0x102,(sampleOffB[chan[c.chan].sample]>>5)&0xff); immWrite(0x103,(sampleOffB[chan[c.chan].sample]>>13)&0xff); int end=sampleOffB[chan[c.chan].sample]+s->lengthB-1; @@ -716,6 +717,7 @@ int DivPlatformYM2608::dispatch(DivCommand c) { chan[c.chan].sample=12*sampleBank+c.value%12; if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.sampleLen) { DivSample* s=parent->getSample(chan[c.chan].sample); + immWrite(0x100,0x01); // reset immWrite(0x102,(sampleOffB[chan[c.chan].sample]>>5)&0xff); immWrite(0x103,(sampleOffB[chan[c.chan].sample]>>13)&0xff); int end=sampleOffB[chan[c.chan].sample]+s->lengthB-1; diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index ad1207004..1f5953fc8 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -218,6 +218,10 @@ const char* cmdName[]={ "SNES_ECHO_FEEDBACK", "SNES_ECHO_FIR", + "DIV_CMD_NES_ENV_MODE", + "DIV_CMD_NES_LENGTH", + "DIV_CMD_NES_COUNT_MODE", + "ALWAYS_SET_VOLUME" }; @@ -856,7 +860,8 @@ void DivEngine::processRow(int i, bool afterDelay) { break; case 0xff: // stop song - shallStop=true; + shallStopSched=true; + logV("scheduling stop"); break; } } @@ -1144,7 +1149,11 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) { tempoAccum-=curSubSong->virtualTempoD; if (--ticks<=0) { ret=endOfSong; - if (endOfSong) { + if (shallStopSched) { + logV("acknowledging scheduled stop"); + shallStop=true; + break; + } else if (endOfSong) { if (song.loopModality!=2) { playSub(true); } @@ -1159,7 +1168,7 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) { if (tempoAccum>1023) tempoAccum=1023; } // process stuff - for (int i=0; i0) { if (--chan[i].rowDelay==0) { processRow(i,true); @@ -1287,6 +1296,11 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) { } } } + } else { + // still tick the subtick counter + if (--subticks<=0) { + subticks=tickMult; + } } firstTick=false; @@ -1303,6 +1317,7 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) { sPreview.dir=false; ret=true; shallStop=false; + shallStopSched=false; return ret; } diff --git a/src/engine/song.h b/src/engine/song.h index b168c8836..45591306b 100644 --- a/src/engine/song.h +++ b/src/engine/song.h @@ -117,6 +117,7 @@ enum DivSystem { DIV_SYSTEM_MSM5232, DIV_SYSTEM_T6W28, DIV_SYSTEM_PCM_DAC, + DIV_SYSTEM_PONG, DIV_SYSTEM_DUMMY, DIV_SYSTEM_MAX // boundary for max system number }; diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index 87adc99e7..b1bcc3aac 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -701,6 +701,9 @@ void DivEngine::registerSystems() { {0x12, {DIV_CMD_STD_NOISE_MODE, "12xx: Set duty cycle/noise mode (pulse: 0 to 3; noise: 0 or 1)"}}, {0x13, {DIV_CMD_NES_SWEEP, "13xy: Sweep up (x: time; y: shift)",constVal<0>,effectVal}}, {0x14, {DIV_CMD_NES_SWEEP, "14xy: Sweep down (x: time; y: shift)",constVal<1>,effectVal}}, + {0x15, {DIV_CMD_NES_ENV_MODE, "15xx: Set envelope mode (0: envelope, 1: length, 2: looping, 3: constant)"}}, + {0x16, {DIV_CMD_NES_LENGTH, "16xx: Set length counter (refer to manual for a list of values)"}}, + {0x17, {DIV_CMD_NES_COUNT_MODE, "17xx: Set frame counter mode (0: 4-step, 1: 5-step)"}}, {0x18, {DIV_CMD_SAMPLE_MODE, "18xx: Select PCM/DPCM mode (0: PCM; 1: DPCM)"}} } ); @@ -1110,6 +1113,15 @@ void DivEngine::registerSystems() { {DIV_INS_BEEPER} ); + sysDefs[DIV_SYSTEM_PONG]=new DivSysDef( + "Pong", NULL, 0xfc, 0, 1, false, true, 0, false, 0, + "LOL", + {"Square"}, + {"SQ"}, + {DIV_CH_PULSE}, + {DIV_INS_BEEPER} + ); + sysDefs[DIV_SYSTEM_POKEY]=new DivSysDef( "POKEY", NULL, 0x94, 0, 4, false, true, 0, false, 0, "TIA, but better and more flexible.\nused in the Atari 8-bit family of computers (400/800/XL/XE).", diff --git a/src/engine/vgmOps.cpp b/src/engine/vgmOps.cpp index 8359b7835..3cc1cc5bb 100644 --- a/src/engine/vgmOps.cpp +++ b/src/engine/vgmOps.cpp @@ -2053,9 +2053,11 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p } // write write performVGMWrite(w,song.system[i.first],i.second.write,streamIDs[i.first],loopTimer,loopFreq,loopSample,sampleDir,isSecond[i.first],directStream); + writeCount++; } sortedWrites.clear(); totalWait-=lastOne; + tickCount+=lastOne; } } else { for (int i=0; i=e->song.systemLen) pgSys=0; if (ImGui::BeginCombo("Chip",fmt::sprintf("%d. %s",pgSys+1,e->getSystemName(e->song.system[pgSys])).c_str())) { diff --git a/src/gui/doAction.cpp b/src/gui/doAction.cpp index 6b35f912d..d4145276b 100644 --- a/src/gui/doAction.cpp +++ b/src/gui/doAction.cpp @@ -1340,7 +1340,7 @@ void FurnaceGUI::doAction(int what) { wave->max=255; wave->len=end-start; for (unsigned int i=start; idata[i-start]=(sample->data8[i]&0xff)^0x80; + wave->data[i-start]=(((unsigned short)sample->data16[i]&0xff00)>>8)^0x80; } nextWindow=GUI_WINDOW_WAVE_EDIT; MARK_MODIFIED; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 45c4f018b..522dcbed8 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -3003,6 +3003,7 @@ bool FurnaceGUI::loop() { scrH=ev.window.data2; portrait=(scrW void FurnaceGUI::drawRegView() { if (nextWindow==GUI_WINDOW_REGISTER_VIEW) { @@ -38,6 +39,8 @@ void FurnaceGUI::drawRegView() { } else { ImGui::PushFont(patFont); if (ImGui::BeginTable("Memory",17)) { + ImGui::TableSetupColumn("addr",ImGuiTableColumnFlags_WidthFixed); + ImGui::TableNextRow(); ImGui::TableNextColumn(); for (int i=0; i<16; i++) { diff --git a/src/gui/sysConf.cpp b/src/gui/sysConf.cpp index 0e75db30d..d78114530 100644 --- a/src/gui/sysConf.cpp +++ b/src/gui/sysConf.cpp @@ -1442,6 +1442,7 @@ bool FurnaceGUI::drawSysConf(int chan, DivSystem type, DivConfig& flags, bool mo case DIV_SYSTEM_YMU759: case DIV_SYSTEM_PET: case DIV_SYSTEM_T6W28: + case DIV_SYSTEM_VBOY: ImGui::Text("nothing to configure"); break; default: {