NES: add 20xx effect for changing DPCM freq

This commit is contained in:
tildearrow 2023-05-05 00:59:55 -05:00
parent bd53c57658
commit 0c0472ce76
4 changed files with 54 additions and 4 deletions

View file

@ -337,14 +337,22 @@ void DivPlatformNES::tick(bool sysTick) {
goingToLoop=parent->getSample(dacSample)->isLoopable();
// write DPCM
rWrite(0x4015,15);
rWrite(0x4010,calcDPCMRate(dacRate)|(goingToLoop?0x40:0));
if (nextDPCMFreq>=0) {
rWrite(0x4010,nextDPCMFreq|(goingToLoop?0x40:0));
nextDPCMFreq=-1;
} else {
rWrite(0x4010,calcDPCMRate(dacRate)|(goingToLoop?0x40:0));
}
rWrite(0x4012,(dpcmAddr>>6)&0xff);
rWrite(0x4013,dpcmLen&0xff);
rWrite(0x4015,31);
dpcmBank=dpcmAddr>>14;
}
} else {
if (dpcmMode) {
if (nextDPCMFreq>=0) {
rWrite(0x4010,nextDPCMFreq|(goingToLoop?0x40:0));
nextDPCMFreq=-1;
} else {
rWrite(0x4010,calcDPCMRate(dacRate)|(goingToLoop?0x40:0));
}
}
@ -353,6 +361,8 @@ void DivPlatformNES::tick(bool sysTick) {
if (chan[4].keyOn) chan[4].keyOn=false;
chan[4].freqChanged=false;
}
nextDPCMFreq=-1;
}
int DivPlatformNES::dispatch(DivCommand c) {
@ -406,7 +416,12 @@ int DivPlatformNES::dispatch(DivCommand c) {
goingToLoop=parent->getSample(dacSample)->isLoopable();
// write DPCM
rWrite(0x4015,15);
rWrite(0x4010,calcDPCMRate(dacRate)|(goingToLoop?0x40:0));
if (nextDPCMFreq>=0) {
rWrite(0x4010,nextDPCMFreq|(goingToLoop?0x40:0));
nextDPCMFreq=-1;
} else {
rWrite(0x4010,calcDPCMRate(dacRate)|(goingToLoop?0x40:0));
}
rWrite(0x4012,(dpcmAddr>>6)&0xff);
rWrite(0x4013,dpcmLen&0xff);
rWrite(0x4015,31);
@ -555,6 +570,14 @@ int DivPlatformNES::dispatch(DivCommand c) {
rWrite(0x4013,0);
rWrite(0x4015,31);
break;
case DIV_CMD_SAMPLE_FREQ: {
bool goingToLoop=parent->getSample(dacSample)->isLoopable();
if (dpcmMode) {
nextDPCMFreq=c.value&15;
rWrite(0x4010,(c.value&15)|(goingToLoop?0x40:0));
}
break;
}
case DIV_CMD_SAMPLE_BANK:
sampleBank=c.value;
if (sampleBank>(parent->song.sample.size()/12)) {
@ -658,6 +681,7 @@ void DivPlatformNES::reset() {
dpcmMode=dpcmModeDefault;
goingToLoop=false;
countMode=false;
nextDPCMFreq=-1;
if (useNP) {
nes1_NP->Reset();

View file

@ -52,6 +52,7 @@ class DivPlatformNES: public DivDispatch {
unsigned char sampleBank;
unsigned char writeOscBuf;
unsigned char apuType;
signed char nextDPCMFreq;
bool dpcmMode;
bool dpcmModeDefault;
bool dacAntiClickOn;

View file

@ -712,7 +712,8 @@ void DivEngine::registerSystems() {
{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)"}}
{0x18, {DIV_CMD_SAMPLE_MODE, "18xx: Select PCM/DPCM mode (0: PCM; 1: DPCM)"}},
{0x20, {DIV_CMD_SAMPLE_FREQ, "20xx: Set DPCM frequency (0 to F)"}}
}
);