NES: add hardware sweep effect

This commit is contained in:
tildearrow 2022-02-01 18:28:48 -05:00
parent f09a0b40c3
commit f03ed7c833
5 changed files with 36 additions and 3 deletions

View file

@ -8,3 +8,11 @@ also known as Famicom.
- `12xx`: set duty cycle or noise mode of channel.
- may be 0-3 for the pulse channels and 0-1 for the noise channel.
- `13xy`: setup sweep up.
- `x` is the time.
- `y` is the shift.
- set to 0 to disable it.
- `14xy`: setup sweep down.
- `x` is the time.
- `y` is the shift.
- set to 0 to disable it.

View file

@ -53,6 +53,8 @@ enum DivDispatchCmds {
DIV_CMD_PCE_LFO_MODE,
DIV_CMD_PCE_LFO_SPEED,
DIV_CMD_NES_SWEEP,
DIV_CMD_C64_CUTOFF,
DIV_CMD_C64_RESONANCE,
DIV_CMD_C64_FILTER_MODE,

View file

@ -300,6 +300,19 @@ int DivPlatformNES::dispatch(DivCommand c) {
chan[c.chan].freqChanged=true;
}
break;
case DIV_CMD_NES_SWEEP:
if (c.chan>1) break;
if (c.value2==0) {
chan[c.chan].sweep=0x08;
} else {
if (!c.value) { // down
chan[c.chan].sweep=0x88|(c.value2&0x77);
} else { // up
chan[c.chan].sweep=0x80|(c.value2&0x77);
}
}
rWrite(0x4001+(c.chan*4),chan[c.chan].sweep);
break;
case DIV_CMD_SAMPLE_BANK:
sampleBank=c.value;
if (sampleBank>(parent->song.sample.size()/12)) {
@ -341,6 +354,8 @@ void DivPlatformNES::forceIns() {
chan[i].insChanged=true;
chan[i].prevFreq=65535;
}
rWrite(0x4001,chan[0].sweep);
rWrite(0x4005,chan[1].sweep);
}
void* DivPlatformNES::getChanState(int ch) {
@ -366,8 +381,8 @@ void DivPlatformNES::reset() {
nes->apu.cpu_opcode_cycle=0;
rWrite(0x4015,(!isMuted[0])|((!isMuted[1])<<1)|((!isMuted[2])<<2)|((!isMuted[3])<<3)|((!isMuted[4])<<4));
rWrite(0x4001,0x08);
rWrite(0x4005,0x08);
rWrite(0x4001,chan[0].sweep);
rWrite(0x4005,chan[1].sweep);
}
bool DivPlatformNES::keyOffAffectsArp(int ch) {

View file

@ -19,7 +19,7 @@ class DivPlatformNES: public DivDispatch {
note(0),
ins(-1),
duty(0),
sweep(0),
sweep(8),
active(false),
insChanged(true),
freqChanged(false),

View file

@ -65,6 +65,8 @@ const char* cmdName[DIV_CMD_MAX]={
"PCE_LFO_MODE",
"PCE_LFO_SPEED",
"NES_SWEEP",
"C64_CUTOFF",
"C64_RESONANCE",
"C64_FILTER_MODE",
@ -178,6 +180,12 @@ bool DivEngine::perSystemEffect(int ch, unsigned char effect, unsigned char effe
case 0x12: // duty or noise mode
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_MODE,ch,effectVal));
break;
case 0x13: // sweep up
dispatchCmd(DivCommand(DIV_CMD_NES_SWEEP,ch,0,effectVal));
break;
case 0x14: // sweep down
dispatchCmd(DivCommand(DIV_CMD_NES_SWEEP,ch,1,effectVal));
break;
default:
return false;
}