From 547fbab29fa1869bee1b9d1b8a2ffbdd24b0b934 Mon Sep 17 00:00:00 2001 From: Souryo Date: Mon, 17 Jul 2017 19:35:16 -0400 Subject: [PATCH] Overclocking: Improved compatibility with games that write to $4011 + fixed PAL issues with OC --- Core/DeltaModulationChannel.cpp | 9 +++++++-- Core/DeltaModulationChannel.h | 2 ++ Core/EmulationSettings.cpp | 1 - Core/EmulationSettings.h | 7 ------- Core/PPU.cpp | 4 +--- Core/PPU.h | 6 +++--- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Core/DeltaModulationChannel.cpp b/Core/DeltaModulationChannel.cpp index 4cb6c718..e256b14a 100644 --- a/Core/DeltaModulationChannel.cpp +++ b/Core/DeltaModulationChannel.cpp @@ -33,6 +33,8 @@ void DeltaModulationChannel::Reset(bool softReset) _silenceFlag = true; _needToRun = false; + _lastValue4011 = 0; + //Not sure if this is accurate, but it seems to make things better rather than worse (for dpcmletterbox) //"On the real thing, I think the power-on value is 428 (or the equivalent at least - it uses a linear feedback shift register), though only the even/oddness should matter for this test." _period = (GetNesModel() == NesModel::NTSC ? _dmcPeriodLookupTableNtsc : _dmcPeriodLookupTablePal)[0] - 1; @@ -153,8 +155,9 @@ void DeltaModulationChannel::WriteRAM(uint16_t addr, uint8_t value) break; case 1: { //4011 + uint8_t newValue = value & 0x7F; uint8_t previousLevel = _outputLevel; - _outputLevel = value & 0x7F; + _outputLevel = newValue; if(EmulationSettings::CheckFlag(EmulationFlags::ReduceDmcPopping) && abs(_outputLevel - previousLevel) > 50) { //Reduce popping sounds for 4011 writes @@ -164,9 +167,11 @@ void DeltaModulationChannel::WriteRAM(uint16_t addr, uint8_t value) //4011 applies new output right away, not on the timer's reload. This fixes bad DMC sound when playing through 4011. AddOutput(_outputLevel); - if((value & 0x7F) > 0 && EmulationSettings::GetOverclockAdjustApu()) { + if(_lastValue4011 != value && newValue > 0) { Console::SetNextFrameOverclockStatus(true); } + + _lastValue4011 = newValue; break; } diff --git a/Core/DeltaModulationChannel.h b/Core/DeltaModulationChannel.h index a3e9edc8..a19f65ee 100644 --- a/Core/DeltaModulationChannel.h +++ b/Core/DeltaModulationChannel.h @@ -30,6 +30,8 @@ private: bool _silenceFlag = true; bool _needToRun = false; + uint8_t _lastValue4011 = 0; + void InitSample(); void FillReadBuffer(); diff --git a/Core/EmulationSettings.cpp b/Core/EmulationSettings.cpp index c291acfd..6d071bcf 100644 --- a/Core/EmulationSettings.cpp +++ b/Core/EmulationSettings.cpp @@ -42,7 +42,6 @@ bool EmulationSettings::_hasOverclock = false; uint32_t EmulationSettings::_overclockRate = 100; uint32_t EmulationSettings::_extraScanlinesBeforeNmi = 0; uint32_t EmulationSettings::_extraScanlinesAfterNmi = 0; -uint32_t EmulationSettings::_ppuScanlineCount = 262; double EmulationSettings::_effectiveOverclockRate = 100; bool EmulationSettings::_overclockAdjustApu = true; bool EmulationSettings::_disableOverclocking = false; diff --git a/Core/EmulationSettings.h b/Core/EmulationSettings.h index e00ebe5f..d6af830a 100644 --- a/Core/EmulationSettings.h +++ b/Core/EmulationSettings.h @@ -397,7 +397,6 @@ private: static bool _disableOverclocking; static uint32_t _extraScanlinesBeforeNmi; static uint32_t _extraScanlinesAfterNmi; - static uint32_t _ppuScanlineCount; static double _effectiveOverclockRate; static double _effectiveOverclockRateSound; @@ -727,12 +726,6 @@ public: _audioSettingsChanged = true; } - static void SetPpuScanlineCount(uint32_t scanlineCount) - { - _ppuScanlineCount = scanlineCount; - UpdateEffectiveOverclockRate(); - } - static void DisableOverclocking(bool disabled) { _disableOverclocking = disabled; diff --git a/Core/PPU.cpp b/Core/PPU.cpp index aa58b4a7..9f443a4e 100644 --- a/Core/PPU.cpp +++ b/Core/PPU.cpp @@ -112,25 +112,23 @@ void PPU::SetNesModel(NesModel model) _vblankEnd = 260; _standardNmiScanline = 241; _standardVblankEnd = 260; - EmulationSettings::SetPpuScanlineCount(262); break; case NesModel::PAL: _nmiScanline = 241; _vblankEnd = 310; _standardNmiScanline = 241; _standardVblankEnd = 310; - EmulationSettings::SetPpuScanlineCount(312); break; case NesModel::Dendy: _nmiScanline = 291; _vblankEnd = 310; _standardNmiScanline = 291; _standardVblankEnd = 310; - EmulationSettings::SetPpuScanlineCount(312); break; } _nmiScanline += EmulationSettings::GetPpuExtraScanlinesBeforeNmi(); + _palSpriteEvalScanline = _nmiScanline + 24; _standardVblankEnd += EmulationSettings::GetPpuExtraScanlinesBeforeNmi(); _vblankEnd += EmulationSettings::GetPpuExtraScanlinesAfterNmi() + EmulationSettings::GetPpuExtraScanlinesBeforeNmi(); } diff --git a/Core/PPU.h b/Core/PPU.h index 5dd58185..4cb4ef16 100644 --- a/Core/PPU.h +++ b/Core/PPU.h @@ -28,8 +28,7 @@ class PPU : public IMemoryHandler, public Snapshotable { protected: static PPU* Instance; - static constexpr uint16_t _palSpriteEvalScanline = 265; - + BaseMapper *_mapper; PPUState _state; @@ -52,7 +51,8 @@ class PPU : public IMemoryHandler, public Snapshotable uint16_t _standardNmiScanline; uint16_t _vblankEnd; uint16_t _nmiScanline; - + uint16_t _palSpriteEvalScanline; + PPUControlFlags _flags; PPUStatusFlags _statusFlags;