From 480b26c95c64e7db3384b5c9eca7e47b1574f049 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 5 Dec 2021 16:45:29 -0500 Subject: [PATCH] more C64 work --- src/engine/platform/c64.cpp | 41 ++++++++++++------------------------- src/engine/platform/c64.h | 11 +++++----- src/engine/playback.cpp | 4 +++- 3 files changed, 22 insertions(+), 34 deletions(-) diff --git a/src/engine/platform/c64.cpp b/src/engine/platform/c64.cpp index 0a5603f9b..9f51f1ef3 100644 --- a/src/engine/platform/c64.cpp +++ b/src/engine/platform/c64.cpp @@ -48,15 +48,13 @@ void DivPlatformC64::tick() { sid.write(i*7+2,chan[i].duty&0xff); sid.write(i*7+3,chan[i].duty>>8); } - if (chan[i].sweepChanged) { - chan[i].sweepChanged=false; - if (i==0) { - //rWrite(16+i*5,chan[i].sweep); - } + if (chan[i].std.hadWave) { + chan[i].wave=chan[i].std.wave; + sid.write(i*7+4,(chan[i].wave<<4)|chan[i].active); } if (chan[i].testWhen>0) { if (--chan[i].testWhen<1) { - sid.write(i*7+4,8); + sid.write(i*7+4,(chan[i].wave<<4)|8); } } if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) { @@ -65,24 +63,12 @@ void DivPlatformC64::tick() { if (chan[i].keyOn) { sid.write(i*7+5,(ins->c64.a<<4)|(ins->c64.d)); sid.write(i*7+6,(ins->c64.s<<4)|(ins->c64.r)); - sid.write(i*7+4, - (ins->c64.noiseOn<<7)| - (ins->c64.pulseOn<<6)| - (ins->c64.sawOn<<5)| - (ins->c64.triOn<<4)| - 1 - ); + sid.write(i*7+4,(chan[i].wave<<4)|1); } if (chan[i].keyOff) { sid.write(i*7+5,(ins->c64.a<<4)|(ins->c64.d)); sid.write(i*7+6,(ins->c64.s<<4)|(ins->c64.r)); - sid.write(i*7+4, - (ins->c64.noiseOn<<7)| - (ins->c64.pulseOn<<6)| - (ins->c64.sawOn<<5)| - (ins->c64.triOn<<4)| - 0 - ); + sid.write(i*7+4,(chan[i].wave<<4)|0); } sid.write(i*7,chan[i].freq&0xff); sid.write(i*7+1,chan[i].freq>>8); @@ -95,17 +81,20 @@ void DivPlatformC64::tick() { int DivPlatformC64::dispatch(DivCommand c) { switch (c.cmd) { - case DIV_CMD_NOTE_ON: + case DIV_CMD_NOTE_ON: { + DivInstrument* ins=parent->getIns(chan[c.chan].ins); chan[c.chan].baseFreq=round(FREQ_BASE*pow(2.0f,((float)c.value/12.0f))); chan[c.chan].freqChanged=true; chan[c.chan].note=c.value; chan[c.chan].active=true; chan[c.chan].keyOn=true; - chan[c.chan].duty=(parent->getIns(chan[c.chan].ins)->c64.duty*4095)/100; + chan[c.chan].duty=(ins->c64.duty*4095)/100; sid.write(c.chan*7+2,chan[c.chan].duty&0xff); sid.write(c.chan*7+3,chan[c.chan].duty>>8); - chan[c.chan].std.init(parent->getIns(chan[c.chan].ins)); + chan[c.chan].wave=(ins->c64.noiseOn<<3)|(ins->c64.pulseOn<<2)|(ins->c64.sawOn<<1)|(ins->c64.triOn); + chan[c.chan].std.init(ins); break; + } case DIV_CMD_NOTE_OFF: chan[c.chan].active=false; chan[c.chan].keyOff=true; @@ -159,13 +148,9 @@ int DivPlatformC64::dispatch(DivCommand c) { } case DIV_CMD_STD_NOISE_MODE: chan[c.chan].duty=c.value; - if (c.chan==3) { // noise - chan[c.chan].freqChanged=true; - } break; case DIV_CMD_LEGATO: - if (c.chan==3) break; - chan[c.chan].baseFreq=round(FREQ_BASE/pow(2.0f,((float)c.value/12.0f))); + chan[c.chan].baseFreq=round(FREQ_BASE*pow(2.0f,((float)c.value/12.0f))); chan[c.chan].freqChanged=true; chan[c.chan].note=c.value; break; diff --git a/src/engine/platform/c64.h b/src/engine/platform/c64.h index 20fe9bf38..5aab80223 100644 --- a/src/engine/platform/c64.h +++ b/src/engine/platform/c64.h @@ -8,9 +8,10 @@ class DivPlatformC64: public DivDispatch { struct Channel { int freq, baseFreq, pitch, prevFreq, testWhen; - unsigned char ins, note, duty, sweep; + unsigned char ins, note, sweep, wave; + short duty; bool active, insChanged, freqChanged, sweepChanged, keyOn, keyOff, inPorta; - signed char vol, outVol, wave; + signed char vol, outVol; DivMacroInt std; Channel(): freq(0), @@ -20,8 +21,9 @@ class DivPlatformC64: public DivDispatch { testWhen(0), ins(-1), note(0), - duty(0), sweep(0), + wave(0), + duty(0), active(false), insChanged(true), freqChanged(false), @@ -29,8 +31,7 @@ class DivPlatformC64: public DivDispatch { keyOn(false), keyOff(false), inPorta(false), - vol(15), - wave(-1) {} + vol(15) {} }; Channel chan[3]; diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index 0c9072517..33bf419b6 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -488,7 +488,9 @@ void DivEngine::nextRow() { for (int i=0; idata[curOrder]; if (!(pat->data[curRow][0]==0 && pat->data[curRow][1]==0)) { - dispatchCmd(DivCommand(DIV_CMD_PRE_NOTE,i,ticks)); + if (pat->data[curRow][0]!=100) { + dispatchCmd(DivCommand(DIV_CMD_PRE_NOTE,i,ticks)); + } } } }