From bf16f8f59eef80df61597cc6d1bda3ff88b8c4e5 Mon Sep 17 00:00:00 2001 From: cam900 Date: Sat, 10 Dec 2022 13:57:39 +0900 Subject: [PATCH] Reduce register spamming(again) --- src/engine/platform/k007232.cpp | 37 ++++++++++++++++++++------------- src/engine/platform/k007232.h | 10 ++++++--- src/gui/debug.cpp | 5 ++++- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/engine/platform/k007232.cpp b/src/engine/platform/k007232.cpp index 3c2ad157..f18577ee 100644 --- a/src/engine/platform/k007232.cpp +++ b/src/engine/platform/k007232.cpp @@ -149,10 +149,10 @@ void DivPlatformK007232::tick(bool sysTick) { if (stereo) { chan[i].lvol=isMuted[i]?0:(((chan[i].outVol&0xf)*((chan[i].panning>>0)&0xf))/15); chan[i].rvol=isMuted[i]?0:(((chan[i].outVol&0xf)*((chan[i].panning>>4)&0xf))/15); - const unsigned char prevPan=lastPan[i]; - lastPan[i]=(chan[i].lvol&0xf)|((chan[i].rvol&0xf)<<4); - if (prevPan!=lastPan[i]) { + const int newPan=(chan[i].lvol&0xf)|((chan[i].rvol&0xf)<<4); + if (chan[i].prevPan!=newPan) { rWrite(0x10+i,(chan[i].lvol&0xf)|((chan[i].rvol&0xf)<<4)); + chan[i].prevPan=newPan; } } else { @@ -202,8 +202,6 @@ void DivPlatformK007232::tick(bool sysTick) { start=MIN(start,MIN(getSampleMemCapacity(),131072)-1); loop=MIN(loop,MIN(getSampleMemCapacity(),131072)-1); // force keyoff first - chWrite(i,0,0); - chWrite(i,1,0); chWrite(i,2,0xff); chWrite(i,3,0xff); chWrite(i,4,0x1); @@ -219,14 +217,20 @@ void DivPlatformK007232::tick(bool sysTick) { if (prevLoop!=lastLoop) { rWrite(0xd,lastLoop); } - rWrite(0x12+i,bank); - chWrite(i,0,chan[i].freq&0xff); - chWrite(i,1,(chan[i].freq>>8)&0xf); + if (chan[i].prevBank!=bank) { + rWrite(0x12+i,bank); + chan[i].prevBank=bank; + } + if (chan[i].prevFreq!=chan[i].freq) { + chWrite(i,0,chan[i].freq&0xff); + chWrite(i,1,(chan[i].freq>>8)&0xf); + chan[i].prevFreq=chan[i].freq; + } chWrite(i,2,start&0xff); chWrite(i,3,start>>8); chWrite(i,4,start>>16); chWrite(i,5,0); - if (s->isLoopable()) { + if (s->isLoopable() && start!=loop) { chWrite(i,2,loop&0xff); chWrite(i,3,loop>>8); chWrite(i,4,loop>>16); @@ -240,19 +244,23 @@ void DivPlatformK007232::tick(bool sysTick) { chan[i].keyOn=false; } if (chan[i].keyOff) { - chWrite(i,0,0); - chWrite(i,1,0); chWrite(i,2,0xff); chWrite(i,3,0xff); chWrite(i,4,0x1); chWrite(i,5,0); + const unsigned char prevLoop=lastLoop; lastLoop&=~(1<>8)&0xf); + if (chan[i].prevFreq!=chan[i].freq) { + chWrite(i,0,chan[i].freq&0xff); + chWrite(i,1,(chan[i].freq>>8)&0xf); + chan[i].prevFreq=chan[i].freq; + } chan[i].freqChanged=false; } } @@ -413,7 +421,6 @@ void DivPlatformK007232::reset() { k007232.reset(); lastLoop=0; lastVolume=0; - lastPan[0]=lastPan[1]=0; for (int i=0; i<2; i++) { chan[i]=DivPlatformK007232::Channel(); chan[i].std.setEngine(parent); diff --git a/src/engine/platform/k007232.h b/src/engine/platform/k007232.h index 2eb78837..8b42b510 100644 --- a/src/engine/platform/k007232.h +++ b/src/engine/platform/k007232.h @@ -27,11 +27,12 @@ class DivPlatformK007232: public DivDispatch, public k007232_intf { struct Channel { - int freq, baseFreq, pitch, pitch2; + int freq, prevFreq, baseFreq, pitch, pitch2; unsigned int audPos; + int prevBank; int sample, wave, ins; int note; - int panning; + int panning, prevPan; bool active, insChanged, volumeChanged, freqChanged, keyOn, keyOff, inPorta, setPos; int vol, outVol, lvol, rvol; int macroVolMul; @@ -42,14 +43,17 @@ class DivPlatformK007232: public DivDispatch, public k007232_intf { } Channel(): freq(0), + prevFreq(-1), baseFreq(0), pitch(0), pitch2(0), audPos(0), + prevBank(-1), sample(-1), ins(-1), note(0), panning(255), + prevPan(-1), active(false), insChanged(true), volumeChanged(false), @@ -81,7 +85,7 @@ class DivPlatformK007232: public DivDispatch, public k007232_intf { bool sampleLoaded[256]; int delay; - unsigned char lastLoop, lastVolume, lastPan[2]; + unsigned char lastLoop, lastVolume; bool stereo; unsigned char* sampleMem; diff --git a/src/gui/debug.cpp b/src/gui/debug.cpp index 91e5bbbc..d62fcd5d 100644 --- a/src/gui/debug.cpp +++ b/src/gui/debug.cpp @@ -1130,15 +1130,18 @@ void putDispatchChan(void* data, int chanNum, int type) { DivPlatformK007232::Channel* ch=(DivPlatformK007232::Channel*)data; ImGui::Text("> K007232"); ImGui::Text("* freq: %d",ch->freq); + ImGui::Text(" - prev: %d",ch->prevFreq); ImGui::Text(" - base: %d",ch->baseFreq); ImGui::Text(" - pitch: %d",ch->pitch); ImGui::Text(" - pitch2: %d",ch->pitch2); ImGui::Text("* note: %d",ch->note); ImGui::Text("* Sample: %d",ch->sample); ImGui::Text(" - pos: %d",ch->audPos); + ImGui::Text(" - prevBank: %d",ch->prevBank); ImGui::Text("- wave: %d",ch->wave); ImGui::Text("- ins: %d",ch->ins); - ImGui::Text("- panning: %d",ch->panning); + ImGui::Text("* panning: %d",ch->panning); + ImGui::Text(" - prev: %d",ch->prevPan); ImGui::Text("- vol: %.2x",ch->vol); ImGui::Text("- outVol: %.2x",ch->outVol); ImGui::Text("- lvol: %.2x",ch->lvol);