diff --git a/Core/APU.cpp b/Core/APU.cpp index 231c21dd..1d854543 100644 --- a/Core/APU.cpp +++ b/Core/APU.cpp @@ -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; } diff --git a/Core/ApuLengthCounter.cpp b/Core/ApuLengthCounter.cpp new file mode 100644 index 00000000..f4abc42f --- /dev/null +++ b/Core/ApuLengthCounter.cpp @@ -0,0 +1,4 @@ +#include "stdafx.h" +#include "ApuLengthCounter.h" + +bool ApuLengthCounter::_needToRun = false; diff --git a/Core/ApuLengthCounter.h b/Core/ApuLengthCounter.h index 6c561f87..b4c75875 100644 --- a/Core/ApuLengthCounter.h +++ b/Core/ApuLengthCounter.h @@ -8,6 +8,7 @@ private: const vector _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); } diff --git a/Core/BaseApuChannel.h b/Core/BaseApuChannel.h index 841ae043..26185c34 100644 --- a/Core/BaseApuChannel.h +++ b/Core/BaseApuChannel.h @@ -3,6 +3,7 @@ #include "IMemoryHandler.h" #include "../BlipBuffer/Blip_Buffer.h" #include "EmulationSettings.h" +#include "Snapshotable.h" template 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(); diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index 092c2283..2c923ecc 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -330,6 +330,7 @@ + diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index 10706663..36eaaedd 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -295,5 +295,8 @@ Source Files + + Source Files\APU + \ No newline at end of file