diff --git a/src/engine/platform/ay.cpp b/src/engine/platform/ay.cpp index ad133c08d..2719f0bb0 100644 --- a/src/engine/platform/ay.cpp +++ b/src/engine/platform/ay.cpp @@ -115,7 +115,7 @@ const unsigned char dacLogTableAY[256]={ void DivPlatformAY8910::runDAC() { for (int i=0; i<3; i++) { - if (chan[i].active && chan[i].psgMode.dac && chan[i].dac.sample!=-1) { + if (chan[i].active && chan[i].currPSGMode.dac && chan[i].dac.sample!=-1) { chan[i].dac.period+=chan[i].dac.rate; bool end=false; bool changed=false; @@ -215,22 +215,22 @@ void DivPlatformAY8910::acquire(short* bufL, short* bufR, size_t start, size_t l void DivPlatformAY8910::updateOutSel(bool immediate) { if (immediate) { immWrite(0x07, - ~((chan[0].psgMode.getTone())| - ((chan[1].psgMode.getTone())<<1)| - ((chan[2].psgMode.getTone())<<2)| - ((chan[0].psgMode.getNoise())<<2)| - ((chan[1].psgMode.getNoise())<<3)| - ((chan[2].psgMode.getNoise())<<4)| + ~((chan[0].currPSGMode.getTone())| + ((chan[1].currPSGMode.getTone())<<1)| + ((chan[2].currPSGMode.getTone())<<2)| + ((chan[0].currPSGMode.getNoise())<<2)| + ((chan[1].currPSGMode.getNoise())<<3)| + ((chan[2].currPSGMode.getNoise())<<4)| ((!ioPortA)<<6)| ((!ioPortB)<<7))); } else { rWrite(0x07, - ~((chan[0].psgMode.getTone())| - ((chan[1].psgMode.getTone())<<1)| - ((chan[2].psgMode.getTone())<<2)| - ((chan[0].psgMode.getNoise())<<2)| - ((chan[1].psgMode.getNoise())<<3)| - ((chan[2].psgMode.getNoise())<<4)| + ~((chan[0].currPSGMode.getTone())| + ((chan[1].currPSGMode.getTone())<<1)| + ((chan[2].currPSGMode.getTone())<<2)| + ((chan[0].currPSGMode.getNoise())<<2)| + ((chan[1].currPSGMode.getNoise())<<3)| + ((chan[2].currPSGMode.getNoise())<<4)| ((!ioPortA)<<6)| ((!ioPortB)<<7))); } @@ -243,13 +243,13 @@ void DivPlatformAY8910::tick(bool sysTick) { if (chan[i].std.vol.had) { chan[i].outVol=MIN(15,chan[i].std.vol.val)-(15-(chan[i].vol&15)); if (chan[i].outVol<0) chan[i].outVol=0; - if (!chan[i].psgMode.dac) { + if (!chan[i].nextPSGMode.dac) { if (isMuted[i]) { rWrite(0x08+i,0); - } else if (intellivision && (chan[i].psgMode.getEnvelope())) { + } else if (intellivision && (chan[i].nextPSGMode.getEnvelope())) { rWrite(0x08+i,(chan[i].outVol&0xc)<<2); } else { - rWrite(0x08+i,(chan[i].outVol&15)|((chan[i].psgMode.getEnvelope())<<2)); + rWrite(0x08+i,(chan[i].outVol&15)|((chan[i].nextPSGMode.getEnvelope())<<2)); } } } @@ -263,14 +263,17 @@ void DivPlatformAY8910::tick(bool sysTick) { rWrite(0x06,31-chan[i].std.duty.val); } if (chan[i].std.wave.had) { - if (!chan[i].psgMode.dac) { - chan[i].psgMode.val=(chan[i].std.wave.val+1)&7; + if (!chan[i].nextPSGMode.dac) { + chan[i].nextPSGMode.val=(chan[i].std.wave.val+1)&7; + if (chan[i].active) { + chan[i].currPSGMode.val=chan[i].nextPSGMode.val; + } if (isMuted[i]) { rWrite(0x08+i,0); - } else if (intellivision && (chan[i].psgMode.getEnvelope())) { + } else if (intellivision && (chan[i].nextPSGMode.getEnvelope())) { rWrite(0x08+i,(chan[i].outVol&0xc)<<2); } else { - rWrite(0x08+i,(chan[i].outVol&15)|((chan[i].psgMode.getEnvelope())<<2)); + rWrite(0x08+i,(chan[i].outVol&15)|((chan[i].nextPSGMode.getEnvelope())<<2)); } } } @@ -285,7 +288,7 @@ void DivPlatformAY8910::tick(bool sysTick) { } if (chan[i].std.phaseReset.had) { if (chan[i].std.phaseReset.val==1) { - if (chan[i].psgMode.dac) { + if (chan[i].nextPSGMode.dac) { if (dumpWrites) addWrite(0xffff0002+(i<<8),0); DivInstrument* ins=parent->getIns(chan[i].ins,DIV_INS_AY); chan[i].dac.sample=ins->amiga.getSample(chan[i].note); @@ -336,12 +339,12 @@ void DivPlatformAY8910::tick(bool sysTick) { if (chan[i].keyOn) { //rWrite(16+i*5+1,((chan[i].duty&3)<<6)|(63-(ins->gb.soundLen&63))); //rWrite(16+i*5+2,((chan[i].vol<<4))|(ins->gb.envLen&7)|((ins->gb.envDir&1)<<3)); - if (chan[i].psgMode.val==0) { - chan[i].psgMode.val=1; + if (!chan[i].nextPSGMode.dac) { + chan[i].currPSGMode.val=chan[i].nextPSGMode.val; } } if (chan[i].keyOff) { - chan[i].psgMode.val=0; + chan[i].currPSGMode.val=0; rWrite(0x08+i,0); } rWrite((i)<<1,chan[i].freq&0xff); @@ -392,11 +395,11 @@ int DivPlatformAY8910::dispatch(DivCommand c) { case DIV_CMD_NOTE_ON: { DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_AY); if (!parent->song.disableSampleMacro && (ins->type==DIV_INS_AMIGA || ins->amiga.useSample)) { - chan[c.chan].psgMode.dac=true; + chan[c.chan].nextPSGMode.dac=true; } else if (chan[c.chan].dac.furnaceDAC) { - chan[c.chan].psgMode.dac=false; + chan[c.chan].nextPSGMode.dac=false; } - if (chan[c.chan].psgMode.dac) { + if (chan[c.chan].nextPSGMode.dac) { if (skipRegisterWrites) break; if (!parent->song.disableSampleMacro && (ins->type==DIV_INS_AMIGA || ins->amiga.useSample)) { chan[c.chan].dac.sample=ins->amiga.getSample(c.value); @@ -445,6 +448,7 @@ int DivPlatformAY8910::dispatch(DivCommand c) { } chan[c.chan].dac.furnaceDAC=false; } + chan[c.chan].currPSGMode.dac=chan[c.chan].nextPSGMode.dac; break; } if (c.value!=DIV_NOTE_NULL) { @@ -458,13 +462,13 @@ int DivPlatformAY8910::dispatch(DivCommand c) { if (!parent->song.brokenOutVol && !chan[c.chan].std.vol.will) { chan[c.chan].outVol=chan[c.chan].vol; } - if (!chan[c.chan].psgMode.dac) { + if (!chan[c.chan].nextPSGMode.dac) { if (isMuted[c.chan]) { rWrite(0x08+c.chan,0); - } else if (intellivision && (chan[c.chan].psgMode.getEnvelope())) { + } else if (intellivision && (chan[c.chan].nextPSGMode.getEnvelope())) { rWrite(0x08+c.chan,(chan[c.chan].vol&0xc)<<2); } else { - rWrite(0x08+c.chan,(chan[c.chan].vol&15)|((chan[c.chan].psgMode.getEnvelope())<<2)); + rWrite(0x08+c.chan,(chan[c.chan].vol&15)|((chan[c.chan].nextPSGMode.getEnvelope())<<2)); } } break; @@ -472,7 +476,7 @@ int DivPlatformAY8910::dispatch(DivCommand c) { case DIV_CMD_NOTE_OFF: chan[c.chan].dac.sample=-1; if (dumpWrites) addWrite(0xffff0002+(c.chan<<8),0); - chan[c.chan].psgMode.dac=false; + chan[c.chan].nextPSGMode.dac=false; chan[c.chan].keyOff=true; chan[c.chan].active=false; chan[c.chan].macroInit(NULL); @@ -486,15 +490,15 @@ int DivPlatformAY8910::dispatch(DivCommand c) { if (!chan[c.chan].std.vol.has) { chan[c.chan].outVol=c.value; } - if (!chan[c.chan].psgMode.dac) { + if (!chan[c.chan].nextPSGMode.dac) { if (isMuted[c.chan]) { rWrite(0x08+c.chan,0); } else { if (chan[c.chan].active) { - if (intellivision && (chan[c.chan].psgMode.getEnvelope())) { + if (intellivision && (chan[c.chan].nextPSGMode.getEnvelope())) { rWrite(0x08+c.chan,(chan[c.chan].vol&0xc)<<2); } else { - rWrite(0x08+c.chan,(chan[c.chan].vol&15)|((chan[c.chan].psgMode.getEnvelope())<<2)); + rWrite(0x08+c.chan,(chan[c.chan].vol&15)|((chan[c.chan].nextPSGMode.getEnvelope())<<2)); } } } @@ -545,16 +549,19 @@ int DivPlatformAY8910::dispatch(DivCommand c) { break; } case DIV_CMD_STD_NOISE_MODE: - if (!chan[c.chan].psgMode.dac) { + if (!chan[c.chan].nextPSGMode.dac) { if (c.value<16) { - chan[c.chan].psgMode.val=(c.value+1)&7; + chan[c.chan].nextPSGMode.val=(c.value+1)&7; + if (chan[c.chan].active) { + chan[c.chan].currPSGMode.val=chan[c.chan].nextPSGMode.val; + } if (isMuted[c.chan]) { rWrite(0x08+c.chan,0); } else if (chan[c.chan].active) { - if (intellivision && (chan[c.chan].psgMode.getEnvelope())) { + if (intellivision && (chan[c.chan].nextPSGMode.getEnvelope())) { rWrite(0x08+c.chan,(chan[c.chan].outVol&0xc)<<2); } else { - rWrite(0x08+c.chan,(chan[c.chan].outVol&15)|((chan[c.chan].psgMode.getEnvelope())<<2)); + rWrite(0x08+c.chan,(chan[c.chan].outVol&15)|((chan[c.chan].nextPSGMode.getEnvelope())<<2)); } } } @@ -567,16 +574,19 @@ int DivPlatformAY8910::dispatch(DivCommand c) { ayEnvMode=c.value>>4; rWrite(0x0d,ayEnvMode); if (c.value&15) { - chan[c.chan].psgMode.envelope|=1; + chan[c.chan].nextPSGMode.envelope|=1; } else { - chan[c.chan].psgMode.envelope&=~1; + chan[c.chan].nextPSGMode.envelope&=~1; + } + if (!chan[c.chan].nextPSGMode.dac && chan[c.chan].active) { + chan[c.chan].currPSGMode.val=chan[c.chan].nextPSGMode.val; } if (isMuted[c.chan]) { rWrite(0x08+c.chan,0); - } else if (intellivision && (chan[c.chan].psgMode.getEnvelope())) { + } else if (intellivision && (chan[c.chan].nextPSGMode.getEnvelope())) { rWrite(0x08+c.chan,(chan[c.chan].vol&0xc)<<2); } else { - rWrite(0x08+c.chan,(chan[c.chan].vol&15)|((chan[c.chan].psgMode.getEnvelope())<<2)); + rWrite(0x08+c.chan,(chan[c.chan].vol&15)|((chan[c.chan].nextPSGMode.getEnvelope())<<2)); } break; case DIV_CMD_AY_ENVELOPE_LOW: @@ -614,7 +624,10 @@ int DivPlatformAY8910::dispatch(DivCommand c) { immWrite(14+(c.value?1:0),(c.value?portBVal:portAVal)); break; case DIV_CMD_SAMPLE_MODE: - chan[c.chan].psgMode.dac=(c.value>0)?1:0; + chan[c.chan].nextPSGMode.dac=(c.value>0)?1:0; + if (chan[c.chan].active) { + chan[c.chan].currPSGMode.dac=chan[c.chan].nextPSGMode.dac; + } break; case DIV_CMD_SAMPLE_BANK: sampleBank=c.value; @@ -650,13 +663,13 @@ void DivPlatformAY8910::muteChannel(int ch, bool mute) { isMuted[ch]=mute; if (isMuted[ch]) { rWrite(0x08+ch,0); - } else if (chan[ch].active && chan[ch].psgMode.dac) { + } else if (chan[ch].active && chan[ch].nextPSGMode.dac) { rWrite(0x08+ch,chan[ch].dac.out); } else { - if (intellivision && (chan[ch].psgMode.getEnvelope()) && chan[ch].active) { + if (intellivision && (chan[ch].nextPSGMode.getEnvelope()) && chan[ch].active) { rWrite(0x08+ch,(chan[ch].vol&0xc)<<2); } else if (chan[ch].active) { - rWrite(0x08+ch,(chan[ch].outVol&15)|((chan[ch].psgMode.getEnvelope())<<2)); + rWrite(0x08+ch,(chan[ch].outVol&15)|((chan[ch].nextPSGMode.getEnvelope())<<2)); } } } diff --git a/src/engine/platform/ay.h b/src/engine/platform/ay.h index e359b3d77..6a8dbc3d4 100644 --- a/src/engine/platform/ay.h +++ b/src/engine/platform/ay.h @@ -54,9 +54,11 @@ class DivPlatformAY8910: public DivDispatch { return dac?0:(envelope<<2); } - PSGMode(): - val(1) {} - } psgMode; + PSGMode(unsigned char v=0): + val(v) {} + }; + PSGMode currPSGMode; + PSGMode nextPSGMode; struct DAC { int sample, rate, period, pos, out; @@ -83,7 +85,8 @@ class DivPlatformAY8910: public DivDispatch { pitch2=0; } Channel(): - psgMode(PSGMode()), + currPSGMode(PSGMode(0)), + nextPSGMode(PSGMode(1)), dac(DAC()), freq(0), baseFreq(0), diff --git a/src/engine/platform/ay8930.cpp b/src/engine/platform/ay8930.cpp index 412d53f99..8bb34ae9b 100644 --- a/src/engine/platform/ay8930.cpp +++ b/src/engine/platform/ay8930.cpp @@ -111,7 +111,7 @@ const unsigned char dacLogTableAY8930[256]={ void DivPlatformAY8930::runDAC() { for (int i=0; i<3; i++) { - if (chan[i].active && chan[i].psgMode.dac && chan[i].dac.sample!=-1) { + if (chan[i].active && chan[i].currPSGMode.dac && chan[i].dac.sample!=-1) { chan[i].dac.period+=chan[i].dac.rate; bool end=false; bool changed=false; @@ -195,22 +195,22 @@ void DivPlatformAY8930::acquire(short* bufL, short* bufR, size_t start, size_t l void DivPlatformAY8930::updateOutSel(bool immediate) { if (immediate) { immWrite(0x07, - ~((chan[0].psgMode.getTone())| - ((chan[1].psgMode.getTone())<<1)| - ((chan[2].psgMode.getTone())<<2)| - ((chan[0].psgMode.getNoise())<<2)| - ((chan[1].psgMode.getNoise())<<3)| - ((chan[2].psgMode.getNoise())<<4)| + ~((chan[0].currPSGMode.getTone())| + ((chan[1].currPSGMode.getTone())<<1)| + ((chan[2].currPSGMode.getTone())<<2)| + ((chan[0].currPSGMode.getNoise())<<2)| + ((chan[1].currPSGMode.getNoise())<<3)| + ((chan[2].currPSGMode.getNoise())<<4)| ((!ioPortA)<<6)| ((!ioPortB)<<7))); } else { rWrite(0x07, - ~((chan[0].psgMode.getTone())| - ((chan[1].psgMode.getTone())<<1)| - ((chan[2].psgMode.getTone())<<2)| - ((chan[0].psgMode.getNoise())<<2)| - ((chan[1].psgMode.getNoise())<<3)| - ((chan[2].psgMode.getNoise())<<4)| + ~((chan[0].currPSGMode.getTone())| + ((chan[1].currPSGMode.getTone())<<1)| + ((chan[2].currPSGMode.getTone())<<2)| + ((chan[0].currPSGMode.getNoise())<<2)| + ((chan[1].currPSGMode.getNoise())<<3)| + ((chan[2].currPSGMode.getNoise())<<4)| ((!ioPortA)<<6)| ((!ioPortB)<<7))); } @@ -235,11 +235,11 @@ void DivPlatformAY8930::tick(bool sysTick) { if (chan[i].std.vol.had) { chan[i].outVol=MIN(31,chan[i].std.vol.val)-(31-(chan[i].vol&31)); if (chan[i].outVol<0) chan[i].outVol=0; - if (!chan[i].psgMode.dac) { + if (!chan[i].nextPSGMode.dac) { if (isMuted[i]) { rWrite(0x08+i,0); } else { - rWrite(0x08+i,(chan[i].outVol&31)|((chan[i].psgMode.getEnvelope())<<3)); + rWrite(0x08+i,(chan[i].outVol&31)|((chan[i].nextPSGMode.getEnvelope())<<3)); } } } @@ -253,13 +253,16 @@ void DivPlatformAY8930::tick(bool sysTick) { rWrite(0x06,chan[i].std.duty.val); } if (chan[i].std.wave.had) { - if (!chan[i].psgMode.dac) { - chan[i].psgMode.val=(chan[i].std.wave.val+1)&7; - if (isMuted[i]) { - rWrite(0x08+i,0); - } else { - rWrite(0x08+i,(chan[i].outVol&31)|((chan[i].psgMode.getEnvelope())<<3)); - } + if (!chan[i].nextPSGMode.dac) { + chan[i].nextPSGMode.val=(chan[i].std.wave.val+1)&7; + if (chan[i].active) { + chan[i].currPSGMode.val=chan[i].nextPSGMode.val; + } + if (isMuted[i]) { + rWrite(0x08+i,0); + } else { + rWrite(0x08+i,(chan[i].outVol&31)|((chan[i].nextPSGMode.getEnvelope())<<3)); + } } } if (chan[i].std.pitch.had) { @@ -273,7 +276,7 @@ void DivPlatformAY8930::tick(bool sysTick) { } if (chan[i].std.phaseReset.had) { if (chan[i].std.phaseReset.val==1) { - if (chan[i].psgMode.dac) { + if (chan[i].nextPSGMode.dac) { if (dumpWrites) addWrite(0xffff0002+(i<<8),0); DivInstrument* ins=parent->getIns(chan[i].ins,DIV_INS_AY8930); chan[i].dac.sample=ins->amiga.getSample(chan[i].note); @@ -333,8 +336,8 @@ void DivPlatformAY8930::tick(bool sysTick) { } if (chan[i].freq>65535) chan[i].freq=65535; if (chan[i].keyOn) { - if (chan[i].psgMode.val==0) { - chan[i].psgMode.val=1; + if (!chan[i].nextPSGMode.dac) { + chan[i].currPSGMode.val=chan[i].nextPSGMode.val; } if (chan[i].insChanged) { if (!chan[i].std.ex1.will) immWrite(0x16+i,chan[i].duty); @@ -342,7 +345,7 @@ void DivPlatformAY8930::tick(bool sysTick) { } } if (chan[i].keyOff) { - chan[i].psgMode.val=0; + chan[i].currPSGMode.val=0; rWrite(0x08+i,0); } rWrite((i)<<1,chan[i].freq&0xff); @@ -393,11 +396,11 @@ int DivPlatformAY8930::dispatch(DivCommand c) { case DIV_CMD_NOTE_ON: { DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_AY8930); if (ins->type==DIV_INS_AMIGA || ins->amiga.useSample) { - chan[c.chan].psgMode.dac=true; + chan[c.chan].nextPSGMode.dac=true; } else if (chan[c.chan].dac.furnaceDAC) { - chan[c.chan].psgMode.dac=false; + chan[c.chan].nextPSGMode.dac=false; } - if (chan[c.chan].psgMode.dac) { + if (chan[c.chan].nextPSGMode.dac) { if (skipRegisterWrites) break; if (ins->type==DIV_INS_AMIGA || ins->amiga.useSample) { chan[c.chan].dac.sample=ins->amiga.getSample(c.value); @@ -446,6 +449,7 @@ int DivPlatformAY8930::dispatch(DivCommand c) { } chan[c.chan].dac.furnaceDAC=false; } + chan[c.chan].currPSGMode.dac=chan[c.chan].nextPSGMode.dac; break; } if (c.value!=DIV_NOTE_NULL) { @@ -459,11 +463,11 @@ int DivPlatformAY8930::dispatch(DivCommand c) { if (!parent->song.brokenOutVol && !chan[c.chan].std.vol.will) { chan[c.chan].outVol=chan[c.chan].vol; } - if (!chan[c.chan].psgMode.dac) { + if (!chan[c.chan].nextPSGMode.dac) { if (isMuted[c.chan]) { rWrite(0x08+c.chan,0); } else { - rWrite(0x08+c.chan,(chan[c.chan].vol&31)|((chan[c.chan].psgMode.getEnvelope())<<3)); + rWrite(0x08+c.chan,(chan[c.chan].vol&31)|((chan[c.chan].nextPSGMode.getEnvelope())<<3)); } } break; @@ -471,7 +475,7 @@ int DivPlatformAY8930::dispatch(DivCommand c) { case DIV_CMD_NOTE_OFF: chan[c.chan].dac.sample=-1; if (dumpWrites) addWrite(0xffff0002+(c.chan<<8),0); - chan[c.chan].psgMode.dac=false; + chan[c.chan].nextPSGMode.dac=false; chan[c.chan].keyOff=true; chan[c.chan].active=false; chan[c.chan].macroInit(NULL); @@ -485,11 +489,11 @@ int DivPlatformAY8930::dispatch(DivCommand c) { if (!chan[c.chan].std.vol.has) { chan[c.chan].outVol=c.value; } - if (!chan[c.chan].psgMode.dac) { + if (!chan[c.chan].nextPSGMode.dac) { if (isMuted[c.chan]) { rWrite(0x08+c.chan,0); } else { - if (chan[c.chan].active) rWrite(0x08+c.chan,(chan[c.chan].vol&31)|((chan[c.chan].psgMode.getEnvelope())<<3)); + if (chan[c.chan].active) rWrite(0x08+c.chan,(chan[c.chan].vol&31)|((chan[c.chan].nextPSGMode.getEnvelope())<<3)); } break; } @@ -540,12 +544,15 @@ int DivPlatformAY8930::dispatch(DivCommand c) { } case DIV_CMD_STD_NOISE_MODE: if (c.value<0x10) { - if (!chan[c.chan].psgMode.dac) { - chan[c.chan].psgMode.val=(c.value+1)&7; + if (!chan[c.chan].nextPSGMode.dac) { + chan[c.chan].nextPSGMode.val=(c.value+1)&7; + if (chan[c.chan].active) { + chan[c.chan].currPSGMode.val=chan[c.chan].nextPSGMode.val; + } if (isMuted[c.chan]) { rWrite(0x08+c.chan,0); } else if (chan[c.chan].active) { - rWrite(0x08+c.chan,(chan[c.chan].outVol&31)|((chan[c.chan].psgMode.getEnvelope())<<3)); + rWrite(0x08+c.chan,(chan[c.chan].outVol&31)|((chan[c.chan].nextPSGMode.getEnvelope())<<3)); } } } else { @@ -560,14 +567,17 @@ int DivPlatformAY8930::dispatch(DivCommand c) { chan[c.chan].envelope.mode=c.value>>4; rWrite(regMode[c.chan],chan[c.chan].envelope.mode); if (c.value&15) { - chan[c.chan].psgMode.envelope|=1; + chan[c.chan].nextPSGMode.envelope|=1; } else { - chan[c.chan].psgMode.envelope&=~1; + chan[c.chan].nextPSGMode.envelope&=~1; + } + if (!chan[c.chan].nextPSGMode.dac && chan[c.chan].active) { + chan[c.chan].currPSGMode.val=chan[c.chan].nextPSGMode.val; } if (isMuted[c.chan]) { rWrite(0x08+c.chan,0); } else { - rWrite(0x08+c.chan,(chan[c.chan].vol&31)|((chan[c.chan].psgMode.getEnvelope())<<3)); + rWrite(0x08+c.chan,(chan[c.chan].vol&31)|((chan[c.chan].nextPSGMode.getEnvelope())<<3)); } break; case DIV_CMD_AY_ENVELOPE_LOW: @@ -616,7 +626,8 @@ int DivPlatformAY8930::dispatch(DivCommand c) { immWrite(14+(c.value?1:0),(c.value?portBVal:portAVal)); break; case DIV_CMD_SAMPLE_MODE: - chan[c.chan].psgMode.dac=(c.value>0)?1:0; + chan[c.chan].nextPSGMode.dac=(c.value>0)?1:0; + chan[c.chan].currPSGMode.dac=chan[c.chan].nextPSGMode.dac; break; case DIV_CMD_SAMPLE_BANK: sampleBank=c.value; @@ -651,10 +662,10 @@ void DivPlatformAY8930::muteChannel(int ch, bool mute) { if (isMuted[ch]) { rWrite(0x08+ch,0); } else if (chan[ch].active) { - if (chan[ch].psgMode.dac) { + if (chan[ch].nextPSGMode.dac) { rWrite(0x08+ch,chan[ch].dac.out&31); } else { - rWrite(0x08+ch,(chan[ch].outVol&31)|((chan[ch].psgMode.getEnvelope())<<3)); + rWrite(0x08+ch,(chan[ch].outVol&31)|((chan[ch].nextPSGMode.getEnvelope())<<3)); } } } diff --git a/src/engine/platform/ay8930.h b/src/engine/platform/ay8930.h index fdfaa7a6d..2ec12c310 100644 --- a/src/engine/platform/ay8930.h +++ b/src/engine/platform/ay8930.h @@ -62,9 +62,11 @@ class DivPlatformAY8930: public DivDispatch { return dac?0:(envelope<<2); } - PSGMode(): - val(1) {} - } psgMode; + PSGMode(unsigned char v=0): + val(v) {} + }; + PSGMode currPSGMode; + PSGMode nextPSGMode; struct DAC { int sample, rate, period, pos, out; @@ -92,7 +94,8 @@ class DivPlatformAY8930: public DivDispatch { } Channel(): envelope(Envelope()), - psgMode(PSGMode()), + currPSGMode(PSGMode(0)), + nextPSGMode(PSGMode(1)), dac(DAC()), freq(0), baseFreq(0), diff --git a/src/gui/debug.cpp b/src/gui/debug.cpp index c769f2f39..f50aa15b7 100644 --- a/src/gui/debug.cpp +++ b/src/gui/debug.cpp @@ -845,10 +845,16 @@ void putDispatchChan(void* data, int chanNum, int type) { ImGui::Text("- note: %d",ch->note); ImGui::Text("- ins: %d",ch->ins); ImGui::Text("* psgMode:"); - ImGui::Text(" - tone: %d",ch->psgMode.tone); - ImGui::Text(" - noise: %d",ch->psgMode.noise); - ImGui::Text(" - envelope: %d",ch->psgMode.envelope); - ImGui::Text(" - dac: %d",ch->psgMode.dac); + ImGui::Text(" * curr:"); + ImGui::Text(" - tone: %d",ch->currPSGMode.tone); + ImGui::Text(" - noise: %d",ch->currPSGMode.noise); + ImGui::Text(" - envelope: %d",ch->currPSGMode.envelope); + ImGui::Text(" - dac: %d",ch->currPSGMode.dac); + ImGui::Text(" * next:"); + ImGui::Text(" - tone: %d",ch->nextPSGMode.tone); + ImGui::Text(" - noise: %d",ch->nextPSGMode.noise); + ImGui::Text(" - envelope: %d",ch->nextPSGMode.envelope); + ImGui::Text(" - dac: %d",ch->nextPSGMode.dac); ImGui::Text("* DAC:"); ImGui::Text(" - sample: %d",ch->dac.sample); ImGui::Text(" - rate: %d",ch->dac.rate); @@ -885,10 +891,16 @@ void putDispatchChan(void* data, int chanNum, int type) { ImGui::Text(" * slide: %d",ch->envelope.slide); ImGui::Text(" - low: %d",ch->envelope.slideLow); ImGui::Text("* psgMode:"); - ImGui::Text(" - tone: %d",ch->psgMode.tone); - ImGui::Text(" - noise: %d",ch->psgMode.noise); - ImGui::Text(" - envelope: %d",ch->psgMode.envelope); - ImGui::Text(" - dac: %d",ch->psgMode.dac); + ImGui::Text(" * curr:"); + ImGui::Text(" - tone: %d",ch->currPSGMode.tone); + ImGui::Text(" - noise: %d",ch->currPSGMode.noise); + ImGui::Text(" - envelope: %d",ch->currPSGMode.envelope); + ImGui::Text(" - dac: %d",ch->currPSGMode.dac); + ImGui::Text(" * next:"); + ImGui::Text(" - tone: %d",ch->nextPSGMode.tone); + ImGui::Text(" - noise: %d",ch->nextPSGMode.noise); + ImGui::Text(" - envelope: %d",ch->nextPSGMode.envelope); + ImGui::Text(" - dac: %d",ch->nextPSGMode.dac); ImGui::Text("* DAC:"); ImGui::Text(" - sample: %d",ch->dac.sample); ImGui::Text(" - rate: %d",ch->dac.rate);