Optimized Length Counter "NeedToRun"

This commit is contained in:
Souryo 2015-07-19 22:24:56 -04:00
parent 95c0ab9047
commit 97e36a1e27
6 changed files with 24 additions and 14 deletions

View file

@ -134,7 +134,7 @@ void APU::StaticRun()
bool APU::NeedToRun(uint32_t currentCycle)
{
if(_squareChannel[0]->NeedToRun() || _squareChannel[1]->NeedToRun() || _triangleChannel->NeedToRun() || _noiseChannel->NeedToRun() || _deltaModulationChannel->NeedToRun()) {
if(ApuLengthCounter::NeedToRun()) {
return true;
}

View file

@ -0,0 +1,4 @@
#include "stdafx.h"
#include "ApuLengthCounter.h"
bool ApuLengthCounter::_needToRun = false;

View file

@ -8,6 +8,7 @@ private:
const vector<uint8_t> _lcLookupTable = { { 10, 254, 20, 2, 40, 4, 80, 6, 160, 8, 60, 10, 14, 12, 26, 14, 12, 16, 24, 18, 48, 20, 96, 22, 192, 24, 72, 26, 16, 28, 32, 30 } };
bool _enabled = false;
bool _newHaltValue;
static bool _needToRun;
protected:
bool _lengthCounterHalt;
@ -26,10 +27,20 @@ protected:
}
}
void SetRunFlag()
{
ApuLengthCounter::_needToRun = true;
}
public:
ApuLengthCounter(AudioChannel channel, Blip_Buffer* buffer) : BaseApuChannel(channel, buffer)
{
}
static bool NeedToRun()
{
return ApuLengthCounter::_needToRun;
}
virtual void Reset(bool softReset)
{
@ -49,6 +60,8 @@ public:
_lengthCounter = 0;
_newHaltValue = false;
}
ApuLengthCounter::_needToRun = false;
}
virtual void StreamState(bool saving)
@ -68,6 +81,7 @@ public:
virtual void Run(uint32_t targetCycle)
{
ApuLengthCounter::_needToRun = false;
_lengthCounterHalt = _newHaltValue;
BaseApuChannel::Run(targetCycle);
}

View file

@ -3,6 +3,7 @@
#include "IMemoryHandler.h"
#include "../BlipBuffer/Blip_Buffer.h"
#include "EmulationSettings.h"
#include "Snapshotable.h"
template<int range>
class BaseApuChannel : public IMemoryHandler, public Snapshotable
@ -15,7 +16,6 @@ private:
uint32_t _previousCycle;
AudioChannel _channel;
double _baseVolume;
bool _needToRun;
protected:
uint16_t _timer = 0;
@ -38,11 +38,6 @@ protected:
return _channel;
}
void SetRunFlag()
{
_needToRun = true;
}
public:
virtual void Clock() = 0;
virtual bool GetStatus() = 0;
@ -62,7 +57,6 @@ public:
_period = 0;
_lastOutput = 0;
_previousCycle = 0;
_needToRun = false;
_buffer->clear();
}
@ -78,14 +72,8 @@ public:
}
}
bool NeedToRun()
{
return _needToRun;
}
virtual void Run(uint32_t targetCycle)
{
_needToRun = false;
while(_previousCycle < targetCycle) {
if(_timer == 0) {
Clock();

View file

@ -330,6 +330,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="APU.cpp" />
<ClCompile Include="ApuLengthCounter.cpp" />
<ClCompile Include="Breakpoint.cpp" />
<ClCompile Include="CheatManager.cpp" />
<ClCompile Include="Console.cpp" />

View file

@ -295,5 +295,8 @@
<ClCompile Include="EmulationSettings.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ApuLengthCounter.cpp">
<Filter>Source Files\APU</Filter>
</ClCompile>
</ItemGroup>
</Project>