Merge branch 'master' of https://github.com/tildearrow/furnace into es5506_alt

This commit is contained in:
cam900 2022-10-26 12:28:24 +09:00
commit 13b2a72a01
27 changed files with 551 additions and 63 deletions

View file

@ -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;

View file

@ -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();

View file

@ -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;

View file

@ -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; i<start+len; i++) {
if (on) {
if (--pos<=0) {
pos=(freq?2:1)<<4;
flip=!flip;
}
out=(flip && !isMuted[0])?32767:0;
bufL[i]=out;
oscBuf->data[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<DivRegWrite>& 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() {
}

View file

@ -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<DivRegWrite>& wlist);
int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags);
void quit();
~DivPlatformPong();
};
#endif

View file

@ -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 {

View file

@ -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].sample<parent->song.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].sample<parent->song.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].sample<parent->song.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;