From 6dc01159ee076ba757c677442cd0605725d69cd9 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Mon, 28 Feb 2022 01:25:10 -0500 Subject: [PATCH] OPLL: 88% TODO: - effects - FM macros (ugh) - muting - proper drum mode - proper VRC7 --- src/engine/platform/opll.cpp | 51 ++++++++++++++++++++++++------------ src/engine/platform/opll.h | 4 +-- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/engine/platform/opll.cpp b/src/engine/platform/opll.cpp index 28285931..a9f98b53 100644 --- a/src/engine/platform/opll.cpp +++ b/src/engine/platform/opll.cpp @@ -241,7 +241,7 @@ void DivPlatformOPLL::tick() { }*/ if (chan[i].keyOn || chan[i].keyOff) { - if (chan[i].drums) { + if (i>=6 && drums) { drumState&=~(0x10>>(chan[i].note%12)); immWrite(0x0e,0x20|drumState); } else { @@ -266,11 +266,11 @@ void DivPlatformOPLL::tick() { int freqt=toFreq(chan[i].freq); chan[i].freqH=freqt>>8; chan[i].freqL=freqt&0xff; - if (!chan[i].drums) { + if (i<6 || !drums) { immWrite(0x10+i,freqt&0xff); } } - if (chan[i].keyOn && chan[i].drums) { + if (chan[i].keyOn && i>=6 && drums) { //printf("%d\n",chan[i].note%12); drumState|=(0x10>>(chan[i].note%12)); immWrite(0x0e,0x20|drumState); @@ -374,19 +374,24 @@ int DivPlatformOPLL::dispatch(DivCommand c) { rWrite(0x07,(car.sl<<4)|(car.rr)); } if (chan[c.chan].state.opllPreset==16) { // compatible drums mode - chan[c.chan].drums=true; - immWrite(0x16,0x20); - immWrite(0x26,0x05); - immWrite(0x16,0x20); - immWrite(0x26,0x05); - immWrite(0x17,0x50); - immWrite(0x27,0x05); - immWrite(0x17,0x50); - immWrite(0x27,0x05); - immWrite(0x18,0xC0); - immWrite(0x28,0x01); + if (c.chan>=6) { + drums=true; + immWrite(0x16,0x20); + immWrite(0x26,0x05); + immWrite(0x16,0x20); + immWrite(0x26,0x05); + immWrite(0x17,0x50); + immWrite(0x27,0x05); + immWrite(0x17,0x50); + immWrite(0x27,0x05); + immWrite(0x18,0xC0); + immWrite(0x28,0x01); + } } else { - chan[c.chan].drums=false; + if (c.chan>=6) { + drums=false; + immWrite(0x0e,0); + } rWrite(0x30+c.chan,(15-(chan[c.chan].outVol*(15-chan[c.chan].state.op[1].tl))/15)|(chan[c.chan].state.opllPreset<<4)); } } @@ -397,7 +402,7 @@ int DivPlatformOPLL::dispatch(DivCommand c) { chan[c.chan].baseFreq=NOTE_FREQUENCY(c.value); chan[c.chan].note=c.value; - if (chan[c.chan].drums) { + if (c.chan>=6 && drums) { switch (chan[c.chan].note%12) { case 0: // kick drumVol[0]=(15-(chan[c.chan].outVol*(15-chan[c.chan].state.op[1].tl))/15); @@ -444,7 +449,7 @@ int DivPlatformOPLL::dispatch(DivCommand c) { if (!chan[c.chan].std.hasVol) { chan[c.chan].outVol=c.value; } - if (!chan[c.chan].drums) { + if (c.chan<6 || !drums) { rWrite(0x30+c.chan,(15-(chan[c.chan].outVol*(15-chan[c.chan].state.op[1].tl))/15)|(chan[c.chan].state.opllPreset<<4)); } break; @@ -587,6 +592,18 @@ void DivPlatformOPLL::forceIns() { chan[i].freqChanged=true; } } + if (drums) { + immWrite(0x16,0x20); + immWrite(0x26,0x05); + immWrite(0x16,0x20); + immWrite(0x26,0x05); + immWrite(0x17,0x50); + immWrite(0x27,0x05); + immWrite(0x17,0x50); + immWrite(0x27,0x05); + immWrite(0x18,0xC0); + immWrite(0x28,0x01); + } } void DivPlatformOPLL::toggleRegisterDump(bool enable) { diff --git a/src/engine/platform/opll.h b/src/engine/platform/opll.h index 5db8e26a..415cda8a 100644 --- a/src/engine/platform/opll.h +++ b/src/engine/platform/opll.h @@ -35,7 +35,7 @@ class DivPlatformOPLL: public DivDispatch { unsigned char freqH, freqL; int freq, baseFreq, pitch, note; unsigned char ins; - bool active, insChanged, freqChanged, keyOn, keyOff, drums, portaPause, furnaceDac, inPorta; + bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, furnaceDac, inPorta; int vol, outVol; unsigned char pan; Channel(): @@ -51,7 +51,6 @@ class DivPlatformOPLL: public DivDispatch { freqChanged(false), keyOn(false), keyOff(false), - drums(false), portaPause(false), furnaceDac(false), inPorta(false), @@ -76,6 +75,7 @@ class DivPlatformOPLL: public DivDispatch { unsigned char regPool[256]; bool useYMFM; + bool drums; short oldWrites[256]; short pendingWrites[256];