apply new hard reset strategy on all OPN chips

This commit is contained in:
tildearrow 2023-01-19 18:22:48 -05:00
parent 48a1e6a976
commit b33ea8f0ac
6 changed files with 187 additions and 100 deletions

View file

@ -47,6 +47,8 @@ class DivPlatformFMBase: public DivDispatch {
0,2,1,3 0,2,1,3
}; };
const unsigned int hardResetCycles=127;
struct FMChannel: public SharedChannel<int> { struct FMChannel: public SharedChannel<int> {
DivInstrumentFM state; DivInstrumentFM state;
unsigned char freqH, freqL; unsigned char freqH, freqL;
@ -83,7 +85,6 @@ class DivPlatformFMBase: public DivDispatch {
unsigned char lastBusy; unsigned char lastBusy;
int delay; int delay;
unsigned int hardResetCycles;
bool flushFirst; bool flushFirst;
unsigned char regPool[512]; unsigned char regPool[512];
@ -124,7 +125,6 @@ class DivPlatformFMBase: public DivDispatch {
DivDispatch(), DivDispatch(),
lastBusy(0), lastBusy(0),
delay(0), delay(0),
hardResetCycles(0),
flushFirst(false) {} flushFirst(false) {}
}; };

View file

@ -549,6 +549,7 @@ void DivPlatformGenesis::tick(bool sysTick) {
immWrite(0xf0,i&0xff); immWrite(0xf0,i&0xff);
} }
for (int i=0; i<csmChan; i++) { for (int i=0; i<csmChan; i++) {
if (i==2 && extMode) continue;
if ((chan[i].keyOn || chan[i].opMaskChanged) && chan[i].hardReset) { if ((chan[i].keyOn || chan[i].opMaskChanged) && chan[i].hardReset) {
if (i<6) { if (i<6) {
immWrite(0x28,(chan[i].opMask<<4)|konOffs[i]); immWrite(0x28,(chan[i].opMask<<4)|konOffs[i]);
@ -1320,8 +1321,6 @@ void DivPlatformGenesis::setFlags(const DivConfig& flags) {
} else { } else {
rate=chipClock/36; rate=chipClock/36;
} }
// 2ms
hardResetCycles=(chipClock/144)/500;
for (int i=0; i<10; i++) { for (int i=0; i<10; i++) {
oscBuf[i]->rate=rate; oscBuf[i]->rate=rate;
} }

View file

@ -411,29 +411,6 @@ void DivPlatformYM2203::tick(bool sysTick) {
rWrite(baseAddr+ADDR_SSG,op.ssgEnv&15); rWrite(baseAddr+ADDR_SSG,op.ssgEnv&15);
} }
} }
if (chan[i].keyOn || chan[i].keyOff) {
if (chan[i].hardReset && chan[i].keyOn) {
for (int j=0; j<4; j++) {
unsigned short baseAddr=chanOffs[i]|opOffs[j];
immWrite(baseAddr+ADDR_SL_RR,0x0f);
immWrite(baseAddr+ADDR_TL,0x7f);
oldWrites[baseAddr+ADDR_SL_RR]=-1;
oldWrites[baseAddr+ADDR_TL]=-1;
//rWrite(baseAddr+ADDR_SL_RR,(op.rr&15)|(op.sl<<4));
}
}
immWrite(0x28,0x00|konOffs[i]);
if (chan[i].hardReset && chan[i].keyOn) {
for (int j=0; j<4; j++) {
unsigned short baseAddr=chanOffs[i]|opOffs[j];
for (int k=0; k<100; k++) {
immWrite(baseAddr+ADDR_SL_RR,0x0f);
}
}
}
chan[i].keyOff=false;
}
} }
for (int i=16; i<256; i++) { for (int i=16; i<256; i++) {
@ -443,6 +420,26 @@ void DivPlatformYM2203::tick(bool sysTick) {
} }
} }
int hardResetElapsed=0;
bool mustHardReset=false;
for (int i=0; i<3; i++) {
if (i==2 && extMode) continue;
if (chan[i].keyOn || chan[i].keyOff) {
immWrite(0x28,0x00|konOffs[i]);
if (chan[i].hardReset && chan[i].keyOn) {
mustHardReset=true;
for (int j=0; j<4; j++) {
unsigned short baseAddr=chanOffs[i]|opOffs[j];
oldWrites[baseAddr+ADDR_SL_RR]=-1;
immWrite(baseAddr+ADDR_SL_RR,0x0f);
hardResetElapsed++;
}
}
chan[i].keyOff=false;
}
}
for (int i=0; i<3; i++) { for (int i=0; i<3; i++) {
if (i==2 && extMode) continue; if (i==2 && extMode) continue;
if (chan[i].freqChanged) { if (chan[i].freqChanged) {
@ -464,15 +461,32 @@ void DivPlatformYM2203::tick(bool sysTick) {
if (chan[i].freq>0x3fff) chan[i].freq=0x3fff; if (chan[i].freq>0x3fff) chan[i].freq=0x3fff;
immWrite(chanOffs[i]+ADDR_FREQH,chan[i].freq>>8); immWrite(chanOffs[i]+ADDR_FREQH,chan[i].freq>>8);
immWrite(chanOffs[i]+ADDR_FREQ,chan[i].freq&0xff); immWrite(chanOffs[i]+ADDR_FREQ,chan[i].freq&0xff);
hardResetElapsed+=2;
chan[i].freqChanged=false; chan[i].freqChanged=false;
} }
if (chan[i].keyOn || chan[i].opMaskChanged) { if ((chan[i].keyOn || chan[i].opMaskChanged) && !chan[i].hardReset) {
immWrite(0x28,(chan[i].opMask<<4)|konOffs[i]);
hardResetElapsed++;
chan[i].opMaskChanged=false;
chan[i].keyOn=false;
}
}
// hard reset handling
if (mustHardReset) {
for (unsigned int i=hardResetElapsed; i<hardResetCycles; i++) {
immWrite(0xf0,i&0xff);
}
for (int i=0; i<3; i++) {
if (i==2 && extMode) continue;
if ((chan[i].keyOn || chan[i].opMaskChanged) && chan[i].hardReset) {
immWrite(0x28,(chan[i].opMask<<4)|konOffs[i]); immWrite(0x28,(chan[i].opMask<<4)|konOffs[i]);
chan[i].opMaskChanged=false; chan[i].opMaskChanged=false;
chan[i].keyOn=false; chan[i].keyOn=false;
} }
} }
} }
}
void DivPlatformYM2203::commitState(int ch, DivInstrument* ins) { void DivPlatformYM2203::commitState(int ch, DivInstrument* ins) {
if (chan[ch].insChanged) { if (chan[ch].insChanged) {

View file

@ -606,29 +606,6 @@ void DivPlatformYM2608::tick(bool sysTick) {
rWrite(baseAddr+ADDR_SSG,op.ssgEnv&15); rWrite(baseAddr+ADDR_SSG,op.ssgEnv&15);
} }
} }
if (chan[i].keyOn || chan[i].keyOff) {
if (chan[i].hardReset && chan[i].keyOn) {
for (int j=0; j<4; j++) {
unsigned short baseAddr=chanOffs[i]|opOffs[j];
immWrite(baseAddr+ADDR_SL_RR,0x0f);
immWrite(baseAddr+ADDR_TL,0x7f);
oldWrites[baseAddr+ADDR_SL_RR]=-1;
oldWrites[baseAddr+ADDR_TL]=-1;
//rWrite(baseAddr+ADDR_SL_RR,(op.rr&15)|(op.sl<<4));
}
}
immWrite(0x28,0x00|konOffs[i]);
if (chan[i].hardReset && chan[i].keyOn) {
for (int j=0; j<4; j++) {
unsigned short baseAddr=chanOffs[i]|opOffs[j];
for (int k=0; k<100; k++) {
immWrite(baseAddr+ADDR_SL_RR,0x0f);
}
}
}
chan[i].keyOff=false;
}
} }
for (int i=16; i<512; i++) { for (int i=16; i<512; i++) {
@ -638,6 +615,26 @@ void DivPlatformYM2608::tick(bool sysTick) {
} }
} }
int hardResetElapsed=0;
bool mustHardReset=false;
for (int i=0; i<6; i++) {
if (i==2 && extMode) continue;
if (chan[i].keyOn || chan[i].keyOff) {
immWrite(0x28,0x00|konOffs[i]);
if (chan[i].hardReset && chan[i].keyOn) {
mustHardReset=true;
for (int j=0; j<4; j++) {
unsigned short baseAddr=chanOffs[i]|opOffs[j];
oldWrites[baseAddr+ADDR_SL_RR]=-1;
immWrite(baseAddr+ADDR_SL_RR,0x0f);
hardResetElapsed++;
}
}
chan[i].keyOff=false;
}
}
for (int i=0; i<6; i++) { for (int i=0; i<6; i++) {
if (i==2 && extMode) continue; if (i==2 && extMode) continue;
if (chan[i].freqChanged) { if (chan[i].freqChanged) {
@ -659,10 +656,12 @@ void DivPlatformYM2608::tick(bool sysTick) {
if (chan[i].freq>0x3fff) chan[i].freq=0x3fff; if (chan[i].freq>0x3fff) chan[i].freq=0x3fff;
immWrite(chanOffs[i]+ADDR_FREQH,chan[i].freq>>8); immWrite(chanOffs[i]+ADDR_FREQH,chan[i].freq>>8);
immWrite(chanOffs[i]+ADDR_FREQ,chan[i].freq&0xff); immWrite(chanOffs[i]+ADDR_FREQ,chan[i].freq&0xff);
hardResetElapsed+=2;
chan[i].freqChanged=false; chan[i].freqChanged=false;
} }
if (chan[i].keyOn || chan[i].opMaskChanged) { if ((chan[i].keyOn || chan[i].opMaskChanged) && !chan[i].hardReset) {
immWrite(0x28,(chan[i].opMask<<4)|konOffs[i]); immWrite(0x28,(chan[i].opMask<<4)|konOffs[i]);
hardResetElapsed++;
chan[i].opMaskChanged=false; chan[i].opMaskChanged=false;
chan[i].keyOn=false; chan[i].keyOn=false;
} }
@ -679,6 +678,7 @@ void DivPlatformYM2608::tick(bool sysTick) {
if (globalRSSVolume!=(chan[i].std.duty.val&0x3f)) { if (globalRSSVolume!=(chan[i].std.duty.val&0x3f)) {
globalRSSVolume=chan[i].std.duty.val&0x3f; globalRSSVolume=chan[i].std.duty.val&0x3f;
immWrite(0x11,globalRSSVolume); immWrite(0x11,globalRSSVolume);
hardResetElapsed++;
} }
} }
if (chan[i].std.panL.had) { if (chan[i].std.panL.had) {
@ -691,6 +691,7 @@ void DivPlatformYM2608::tick(bool sysTick) {
} }
if (!isMuted[i] && (chan[i].std.vol.had || chan[i].std.panL.had)) { if (!isMuted[i] && (chan[i].std.vol.had || chan[i].std.panL.had)) {
immWrite(0x18+(i-9),isMuted[i]?0:((chan[i].pan<<6)|chan[i].outVol)); immWrite(0x18+(i-9),isMuted[i]?0:((chan[i].pan<<6)|chan[i].outVol));
hardResetElapsed++;
} }
} }
if (chan[i].keyOff) { if (chan[i].keyOff) {
@ -709,6 +710,7 @@ void DivPlatformYM2608::tick(bool sysTick) {
if (chan[15].std.vol.had) { if (chan[15].std.vol.had) {
chan[15].outVol=(chan[15].vol*MIN(chan[15].macroVolMul,chan[15].std.vol.val))/chan[15].macroVolMul; chan[15].outVol=(chan[15].vol*MIN(chan[15].macroVolMul,chan[15].std.vol.val))/chan[15].macroVolMul;
immWrite(0x10b,chan[15].outVol); immWrite(0x10b,chan[15].outVol);
hardResetElapsed++;
} }
if (NEW_ARP_STRAT) { if (NEW_ARP_STRAT) {
@ -735,6 +737,7 @@ void DivPlatformYM2608::tick(bool sysTick) {
chan[15].pan=chan[15].std.panL.val&3; chan[15].pan=chan[15].std.panL.val&3;
if (!isMuted[15]) { if (!isMuted[15]) {
immWrite(0x101,(isMuted[15]?0:(chan[15].pan<<6))|2); immWrite(0x101,(isMuted[15]?0:(chan[15].pan<<6))|2);
hardResetElapsed++;
} }
} }
} }
@ -755,12 +758,17 @@ void DivPlatformYM2608::tick(bool sysTick) {
} }
immWrite(0x109,chan[15].freq&0xff); immWrite(0x109,chan[15].freq&0xff);
immWrite(0x10a,(chan[15].freq>>8)&0xff); immWrite(0x10a,(chan[15].freq>>8)&0xff);
hardResetElapsed+=2;
if (chan[15].keyOn || chan[15].keyOff) { if (chan[15].keyOn || chan[15].keyOff) {
if (chan[15].keyOff) immWrite(0x100,0x01); // reset if (chan[15].keyOff) {
immWrite(0x100,0x01); // reset
hardResetElapsed++;
}
if (chan[15].active && chan[15].keyOn && !chan[15].keyOff) { if (chan[15].active && chan[15].keyOn && !chan[15].keyOff) {
if (chan[15].sample>=0 && chan[15].sample<parent->song.sampleLen) { if (chan[15].sample>=0 && chan[15].sample<parent->song.sampleLen) {
DivSample* s=parent->getSample(chan[15].sample); DivSample* s=parent->getSample(chan[15].sample);
immWrite(0x100,(s->isLoopable())?0xb0:0xa0); // start/repeat immWrite(0x100,(s->isLoopable())?0xb0:0xa0); // start/repeat
hardResetElapsed++;
} }
} }
chan[15].keyOn=false; chan[15].keyOn=false;
@ -771,11 +779,13 @@ void DivPlatformYM2608::tick(bool sysTick) {
if (writeRSSOff) { if (writeRSSOff) {
immWrite(0x10,0x80|writeRSSOff); immWrite(0x10,0x80|writeRSSOff);
hardResetElapsed++;
writeRSSOff=0; writeRSSOff=0;
} }
if (writeRSSOn) { if (writeRSSOn) {
immWrite(0x10,writeRSSOn); immWrite(0x10,writeRSSOn);
hardResetElapsed++;
writeRSSOn=0; writeRSSOn=0;
} }
@ -785,8 +795,24 @@ void DivPlatformYM2608::tick(bool sysTick) {
for (DivRegWrite& i: ay->getRegisterWrites()) { for (DivRegWrite& i: ay->getRegisterWrites()) {
if (i.addr>15) continue; if (i.addr>15) continue;
immWrite(i.addr&15,i.val); immWrite(i.addr&15,i.val);
hardResetElapsed++;
} }
ay->getRegisterWrites().clear(); ay->getRegisterWrites().clear();
// hard reset handling
if (mustHardReset) {
for (unsigned int i=hardResetElapsed; i<hardResetCycles; i++) {
immWrite(0xf0,i&0xff);
}
for (int i=0; i<6; i++) {
if (i==2 && extMode) continue;
if ((chan[i].keyOn || chan[i].opMaskChanged) && chan[i].hardReset) {
immWrite(0x28,(chan[i].opMask<<4)|konOffs[i]);
chan[i].opMaskChanged=false;
chan[i].keyOn=false;
}
}
}
} }
void DivPlatformYM2608::commitState(int ch, DivInstrument* ins) { void DivPlatformYM2608::commitState(int ch, DivInstrument* ins) {

View file

@ -539,29 +539,6 @@ void DivPlatformYM2610::tick(bool sysTick) {
rWrite(baseAddr+ADDR_SSG,op.ssgEnv&15); rWrite(baseAddr+ADDR_SSG,op.ssgEnv&15);
} }
} }
if (chan[i].keyOn || chan[i].keyOff) {
if (chan[i].hardReset && chan[i].keyOn) {
for (int j=0; j<4; j++) {
unsigned short baseAddr=chanOffs[i]|opOffs[j];
immWrite(baseAddr+ADDR_SL_RR,0x0f);
immWrite(baseAddr+ADDR_TL,0x7f);
oldWrites[baseAddr+ADDR_SL_RR]=-1;
oldWrites[baseAddr+ADDR_TL]=-1;
//rWrite(baseAddr+ADDR_SL_RR,(op.rr&15)|(op.sl<<4));
}
}
immWrite(0x28,0x00|konOffs[i]);
if (chan[i].hardReset && chan[i].keyOn) {
for (int j=0; j<4; j++) {
unsigned short baseAddr=chanOffs[i]|opOffs[j];
for (int k=0; k<100; k++) {
immWrite(baseAddr+ADDR_SL_RR,0x0f);
}
}
}
chan[i].keyOff=false;
}
} }
for (int i=16; i<512; i++) { for (int i=16; i<512; i++) {
@ -571,6 +548,26 @@ void DivPlatformYM2610::tick(bool sysTick) {
} }
} }
int hardResetElapsed=0;
bool mustHardReset=false;
for (int i=0; i<psgChanOffs; i++) {
if (i==1 && extMode) continue;
if (chan[i].keyOn || chan[i].keyOff) {
immWrite(0x28,0x00|konOffs[i]);
if (chan[i].hardReset && chan[i].keyOn) {
mustHardReset=true;
for (int j=0; j<4; j++) {
unsigned short baseAddr=chanOffs[i]|opOffs[j];
oldWrites[baseAddr+ADDR_SL_RR]=-1;
immWrite(baseAddr+ADDR_SL_RR,0x0f);
hardResetElapsed++;
}
}
chan[i].keyOff=false;
}
}
for (int i=0; i<psgChanOffs; i++) { for (int i=0; i<psgChanOffs; i++) {
if (i==1 && extMode) continue; if (i==1 && extMode) continue;
if (chan[i].freqChanged) { if (chan[i].freqChanged) {
@ -592,10 +589,12 @@ void DivPlatformYM2610::tick(bool sysTick) {
if (chan[i].freq>0x3fff) chan[i].freq=0x3fff; if (chan[i].freq>0x3fff) chan[i].freq=0x3fff;
immWrite(chanOffs[i]+ADDR_FREQH,chan[i].freq>>8); immWrite(chanOffs[i]+ADDR_FREQH,chan[i].freq>>8);
immWrite(chanOffs[i]+ADDR_FREQ,chan[i].freq&0xff); immWrite(chanOffs[i]+ADDR_FREQ,chan[i].freq&0xff);
hardResetElapsed+=2;
chan[i].freqChanged=false; chan[i].freqChanged=false;
} }
if (chan[i].keyOn || chan[i].opMaskChanged) { if ((chan[i].keyOn || chan[i].opMaskChanged) && !chan[i].hardReset) {
immWrite(0x28,(chan[i].opMask<<4)|konOffs[i]); immWrite(0x28,(chan[i].opMask<<4)|konOffs[i]);
hardResetElapsed++;
chan[i].opMaskChanged=false; chan[i].opMaskChanged=false;
chan[i].keyOn=false; chan[i].keyOn=false;
} }
@ -612,6 +611,7 @@ void DivPlatformYM2610::tick(bool sysTick) {
if (globalADPCMAVolume!=(chan[i].std.duty.val&0x3f)) { if (globalADPCMAVolume!=(chan[i].std.duty.val&0x3f)) {
globalADPCMAVolume=chan[i].std.duty.val&0x3f; globalADPCMAVolume=chan[i].std.duty.val&0x3f;
immWrite(0x101,globalADPCMAVolume); immWrite(0x101,globalADPCMAVolume);
hardResetElapsed++;
} }
} }
if (chan[i].std.panL.had) { if (chan[i].std.panL.had) {
@ -624,6 +624,7 @@ void DivPlatformYM2610::tick(bool sysTick) {
} }
if (!isMuted[i] && (chan[i].std.vol.had || chan[i].std.panL.had)) { if (!isMuted[i] && (chan[i].std.vol.had || chan[i].std.panL.had)) {
immWrite(0x108+(i-adpcmAChanOffs),isMuted[i]?0:((chan[i].pan<<6)|chan[i].outVol)); immWrite(0x108+(i-adpcmAChanOffs),isMuted[i]?0:((chan[i].pan<<6)|chan[i].outVol));
hardResetElapsed++;
} }
} }
if (chan[i].keyOff) { if (chan[i].keyOff) {
@ -644,6 +645,7 @@ void DivPlatformYM2610::tick(bool sysTick) {
if (chan[adpcmBChanOffs].std.vol.had) { if (chan[adpcmBChanOffs].std.vol.had) {
chan[adpcmBChanOffs].outVol=(chan[adpcmBChanOffs].vol*MIN(chan[adpcmBChanOffs].macroVolMul,chan[adpcmBChanOffs].std.vol.val))/chan[adpcmBChanOffs].macroVolMul; chan[adpcmBChanOffs].outVol=(chan[adpcmBChanOffs].vol*MIN(chan[adpcmBChanOffs].macroVolMul,chan[adpcmBChanOffs].std.vol.val))/chan[adpcmBChanOffs].macroVolMul;
immWrite(0x1b,chan[adpcmBChanOffs].outVol); immWrite(0x1b,chan[adpcmBChanOffs].outVol);
hardResetElapsed++;
} }
if (NEW_ARP_STRAT) { if (NEW_ARP_STRAT) {
@ -670,6 +672,7 @@ void DivPlatformYM2610::tick(bool sysTick) {
chan[adpcmBChanOffs].pan=chan[adpcmBChanOffs].std.panL.val&3; chan[adpcmBChanOffs].pan=chan[adpcmBChanOffs].std.panL.val&3;
if (!isMuted[adpcmBChanOffs]) { if (!isMuted[adpcmBChanOffs]) {
immWrite(0x11,(isMuted[adpcmBChanOffs]?0:(chan[adpcmBChanOffs].pan<<6))); immWrite(0x11,(isMuted[adpcmBChanOffs]?0:(chan[adpcmBChanOffs].pan<<6)));
hardResetElapsed++;
} }
} }
} }
@ -689,13 +692,16 @@ void DivPlatformYM2610::tick(bool sysTick) {
} }
immWrite(0x19,chan[adpcmBChanOffs].freq&0xff); immWrite(0x19,chan[adpcmBChanOffs].freq&0xff);
immWrite(0x1a,(chan[adpcmBChanOffs].freq>>8)&0xff); immWrite(0x1a,(chan[adpcmBChanOffs].freq>>8)&0xff);
hardResetElapsed+=2;
} }
if (chan[adpcmBChanOffs].keyOn || chan[adpcmBChanOffs].keyOff) { if (chan[adpcmBChanOffs].keyOn || chan[adpcmBChanOffs].keyOff) {
immWrite(0x10,0x01); // reset immWrite(0x10,0x01); // reset
hardResetElapsed++;
if (chan[adpcmBChanOffs].active && chan[adpcmBChanOffs].keyOn && !chan[adpcmBChanOffs].keyOff) { if (chan[adpcmBChanOffs].active && chan[adpcmBChanOffs].keyOn && !chan[adpcmBChanOffs].keyOff) {
if (chan[adpcmBChanOffs].sample>=0 && chan[adpcmBChanOffs].sample<parent->song.sampleLen) { if (chan[adpcmBChanOffs].sample>=0 && chan[adpcmBChanOffs].sample<parent->song.sampleLen) {
DivSample* s=parent->getSample(chan[adpcmBChanOffs].sample); DivSample* s=parent->getSample(chan[adpcmBChanOffs].sample);
immWrite(0x10,(s->isLoopable())?0x90:0x80); // start/repeat immWrite(0x10,(s->isLoopable())?0x90:0x80); // start/repeat
hardResetElapsed++;
} }
} }
chan[adpcmBChanOffs].keyOn=false; chan[adpcmBChanOffs].keyOn=false;
@ -706,11 +712,13 @@ void DivPlatformYM2610::tick(bool sysTick) {
if (writeADPCMAOff) { if (writeADPCMAOff) {
immWrite(0x100,0x80|writeADPCMAOff); immWrite(0x100,0x80|writeADPCMAOff);
hardResetElapsed++;
writeADPCMAOff=0; writeADPCMAOff=0;
} }
if (writeADPCMAOn) { if (writeADPCMAOn) {
immWrite(0x100,writeADPCMAOn); immWrite(0x100,writeADPCMAOn);
hardResetElapsed++;
writeADPCMAOn=0; writeADPCMAOn=0;
} }
@ -720,8 +728,24 @@ void DivPlatformYM2610::tick(bool sysTick) {
for (DivRegWrite& i: ay->getRegisterWrites()) { for (DivRegWrite& i: ay->getRegisterWrites()) {
if (i.addr>15) continue; if (i.addr>15) continue;
immWrite(i.addr&15,i.val); immWrite(i.addr&15,i.val);
hardResetElapsed++;
} }
ay->getRegisterWrites().clear(); ay->getRegisterWrites().clear();
// hard reset handling
if (mustHardReset) {
for (unsigned int i=hardResetElapsed; i<hardResetCycles; i++) {
immWrite(0xf0,i&0xff);
}
for (int i=0; i<psgChanOffs; i++) {
if (i==1 && extMode) continue;
if ((chan[i].keyOn || chan[i].opMaskChanged) && chan[i].hardReset) {
immWrite(0x28,(chan[i].opMask<<4)|konOffs[i]);
chan[i].opMaskChanged=false;
chan[i].keyOn=false;
}
}
}
} }
void DivPlatformYM2610::commitState(int ch, DivInstrument* ins) { void DivPlatformYM2610::commitState(int ch, DivInstrument* ins) {

View file

@ -606,29 +606,6 @@ void DivPlatformYM2610B::tick(bool sysTick) {
rWrite(baseAddr+ADDR_SSG,op.ssgEnv&15); rWrite(baseAddr+ADDR_SSG,op.ssgEnv&15);
} }
} }
if (chan[i].keyOn || chan[i].keyOff) {
if (chan[i].hardReset && chan[i].keyOn) {
for (int j=0; j<4; j++) {
unsigned short baseAddr=chanOffs[i]|opOffs[j];
immWrite(baseAddr+ADDR_SL_RR,0x0f);
immWrite(baseAddr+ADDR_TL,0x7f);
oldWrites[baseAddr+ADDR_SL_RR]=-1;
oldWrites[baseAddr+ADDR_TL]=-1;
//rWrite(baseAddr+ADDR_SL_RR,(op.rr&15)|(op.sl<<4));
}
}
immWrite(0x28,0x00|konOffs[i]);
if (chan[i].hardReset && chan[i].keyOn) {
for (int j=0; j<4; j++) {
unsigned short baseAddr=chanOffs[i]|opOffs[j];
for (int k=0; k<100; k++) {
immWrite(baseAddr+ADDR_SL_RR,0x0f);
}
}
}
chan[i].keyOff=false;
}
} }
for (int i=16; i<512; i++) { for (int i=16; i<512; i++) {
@ -638,6 +615,26 @@ void DivPlatformYM2610B::tick(bool sysTick) {
} }
} }
int hardResetElapsed=0;
bool mustHardReset=false;
for (int i=0; i<psgChanOffs; i++) {
if (i==2 && extMode) continue;
if (chan[i].keyOn || chan[i].keyOff) {
immWrite(0x28,0x00|konOffs[i]);
if (chan[i].hardReset && chan[i].keyOn) {
mustHardReset=true;
for (int j=0; j<4; j++) {
unsigned short baseAddr=chanOffs[i]|opOffs[j];
oldWrites[baseAddr+ADDR_SL_RR]=-1;
immWrite(baseAddr+ADDR_SL_RR,0x0f);
hardResetElapsed++;
}
}
chan[i].keyOff=false;
}
}
for (int i=0; i<psgChanOffs; i++) { for (int i=0; i<psgChanOffs; i++) {
if (i==2 && extMode) continue; if (i==2 && extMode) continue;
if (chan[i].freqChanged) { if (chan[i].freqChanged) {
@ -659,10 +656,12 @@ void DivPlatformYM2610B::tick(bool sysTick) {
if (chan[i].freq>0x3fff) chan[i].freq=0x3fff; if (chan[i].freq>0x3fff) chan[i].freq=0x3fff;
immWrite(chanOffs[i]+ADDR_FREQH,chan[i].freq>>8); immWrite(chanOffs[i]+ADDR_FREQH,chan[i].freq>>8);
immWrite(chanOffs[i]+ADDR_FREQ,chan[i].freq&0xff); immWrite(chanOffs[i]+ADDR_FREQ,chan[i].freq&0xff);
hardResetElapsed+=2;
chan[i].freqChanged=false; chan[i].freqChanged=false;
} }
if (chan[i].keyOn || chan[i].opMaskChanged) { if (chan[i].keyOn || chan[i].opMaskChanged) {
immWrite(0x28,(chan[i].opMask<<4)|konOffs[i]); immWrite(0x28,(chan[i].opMask<<4)|konOffs[i]);
hardResetElapsed++;
chan[i].opMaskChanged=false; chan[i].opMaskChanged=false;
chan[i].keyOn=false; chan[i].keyOn=false;
} }
@ -679,6 +678,7 @@ void DivPlatformYM2610B::tick(bool sysTick) {
if (globalADPCMAVolume!=(chan[i].std.duty.val&0x3f)) { if (globalADPCMAVolume!=(chan[i].std.duty.val&0x3f)) {
globalADPCMAVolume=chan[i].std.duty.val&0x3f; globalADPCMAVolume=chan[i].std.duty.val&0x3f;
immWrite(0x101,globalADPCMAVolume); immWrite(0x101,globalADPCMAVolume);
hardResetElapsed++;
} }
} }
if (chan[i].std.panL.had) { if (chan[i].std.panL.had) {
@ -691,6 +691,7 @@ void DivPlatformYM2610B::tick(bool sysTick) {
} }
if (!isMuted[i] && (chan[i].std.vol.had || chan[i].std.panL.had)) { if (!isMuted[i] && (chan[i].std.vol.had || chan[i].std.panL.had)) {
immWrite(0x108+(i-adpcmAChanOffs),isMuted[i]?0:((chan[i].pan<<6)|chan[i].outVol)); immWrite(0x108+(i-adpcmAChanOffs),isMuted[i]?0:((chan[i].pan<<6)|chan[i].outVol));
hardResetElapsed++;
} }
} }
if (chan[i].keyOff) { if (chan[i].keyOff) {
@ -711,6 +712,7 @@ void DivPlatformYM2610B::tick(bool sysTick) {
if (chan[adpcmBChanOffs].std.vol.had) { if (chan[adpcmBChanOffs].std.vol.had) {
chan[adpcmBChanOffs].outVol=(chan[adpcmBChanOffs].vol*MIN(chan[adpcmBChanOffs].macroVolMul,chan[adpcmBChanOffs].std.vol.val))/chan[adpcmBChanOffs].macroVolMul; chan[adpcmBChanOffs].outVol=(chan[adpcmBChanOffs].vol*MIN(chan[adpcmBChanOffs].macroVolMul,chan[adpcmBChanOffs].std.vol.val))/chan[adpcmBChanOffs].macroVolMul;
immWrite(0x1b,chan[adpcmBChanOffs].outVol); immWrite(0x1b,chan[adpcmBChanOffs].outVol);
hardResetElapsed++;
} }
if (NEW_ARP_STRAT) { if (NEW_ARP_STRAT) {
@ -737,6 +739,7 @@ void DivPlatformYM2610B::tick(bool sysTick) {
chan[adpcmBChanOffs].pan=chan[adpcmBChanOffs].std.panL.val&3; chan[adpcmBChanOffs].pan=chan[adpcmBChanOffs].std.panL.val&3;
if (!isMuted[adpcmBChanOffs]) { if (!isMuted[adpcmBChanOffs]) {
immWrite(0x11,(isMuted[adpcmBChanOffs]?0:(chan[adpcmBChanOffs].pan<<6))); immWrite(0x11,(isMuted[adpcmBChanOffs]?0:(chan[adpcmBChanOffs].pan<<6)));
hardResetElapsed++;
} }
} }
} }
@ -756,13 +759,16 @@ void DivPlatformYM2610B::tick(bool sysTick) {
} }
immWrite(0x19,chan[adpcmBChanOffs].freq&0xff); immWrite(0x19,chan[adpcmBChanOffs].freq&0xff);
immWrite(0x1a,(chan[adpcmBChanOffs].freq>>8)&0xff); immWrite(0x1a,(chan[adpcmBChanOffs].freq>>8)&0xff);
hardResetElapsed+=2;
} }
if (chan[adpcmBChanOffs].keyOn || chan[adpcmBChanOffs].keyOff) { if (chan[adpcmBChanOffs].keyOn || chan[adpcmBChanOffs].keyOff) {
immWrite(0x10,0x01); // reset immWrite(0x10,0x01); // reset
hardResetElapsed++;
if (chan[adpcmBChanOffs].active && chan[adpcmBChanOffs].keyOn && !chan[adpcmBChanOffs].keyOff) { if (chan[adpcmBChanOffs].active && chan[adpcmBChanOffs].keyOn && !chan[adpcmBChanOffs].keyOff) {
if (chan[adpcmBChanOffs].sample>=0 && chan[adpcmBChanOffs].sample<parent->song.sampleLen) { if (chan[adpcmBChanOffs].sample>=0 && chan[adpcmBChanOffs].sample<parent->song.sampleLen) {
DivSample* s=parent->getSample(chan[adpcmBChanOffs].sample); DivSample* s=parent->getSample(chan[adpcmBChanOffs].sample);
immWrite(0x10,(s->isLoopable())?0x90:0x80); // start/repeat immWrite(0x10,(s->isLoopable())?0x90:0x80); // start/repeat
hardResetElapsed++;
} }
} }
chan[adpcmBChanOffs].keyOn=false; chan[adpcmBChanOffs].keyOn=false;
@ -773,11 +779,13 @@ void DivPlatformYM2610B::tick(bool sysTick) {
if (writeADPCMAOff) { if (writeADPCMAOff) {
immWrite(0x100,0x80|writeADPCMAOff); immWrite(0x100,0x80|writeADPCMAOff);
hardResetElapsed++;
writeADPCMAOff=0; writeADPCMAOff=0;
} }
if (writeADPCMAOn) { if (writeADPCMAOn) {
immWrite(0x100,writeADPCMAOn); immWrite(0x100,writeADPCMAOn);
hardResetElapsed++;
writeADPCMAOn=0; writeADPCMAOn=0;
} }
@ -787,8 +795,24 @@ void DivPlatformYM2610B::tick(bool sysTick) {
for (DivRegWrite& i: ay->getRegisterWrites()) { for (DivRegWrite& i: ay->getRegisterWrites()) {
if (i.addr>15) continue; if (i.addr>15) continue;
immWrite(i.addr&15,i.val); immWrite(i.addr&15,i.val);
hardResetElapsed++;
} }
ay->getRegisterWrites().clear(); ay->getRegisterWrites().clear();
// hard reset handling
if (mustHardReset) {
for (unsigned int i=hardResetElapsed; i<hardResetCycles; i++) {
immWrite(0xf0,i&0xff);
}
for (int i=0; i<psgChanOffs; i++) {
if (i==2 && extMode) continue;
if ((chan[i].keyOn || chan[i].opMaskChanged) && chan[i].hardReset) {
immWrite(0x28,(chan[i].opMask<<4)|konOffs[i]);
chan[i].opMaskChanged=false;
chan[i].keyOn=false;
}
}
}
} }
void DivPlatformYM2610B::commitState(int ch, DivInstrument* ins) { void DivPlatformYM2610B::commitState(int ch, DivInstrument* ins) {