From 15373016d05770ac3fbf55d09c5069778f2950f3 Mon Sep 17 00:00:00 2001 From: Sour Date: Fri, 13 Jul 2018 22:19:26 -0400 Subject: [PATCH] Refactoring - removed statics from EmulationSettings --- Core/APU.cpp | 5 +- Core/APU.h | 1 + Core/ArkanoidController.h | 6 +- Core/AsciiTurboFile.h | 2 +- Core/AutoSaveManager.cpp | 2 +- Core/AutomaticRomTest.cpp | 13 +- Core/AviRecorder.cpp | 4 +- Core/BandaiHyperShot.h | 2 +- Core/BandaiKaraoke.h | 2 +- Core/BandaiMicrophone.h | 6 +- Core/BarcodeBattlerReader.h | 4 +- Core/BaseControlDevice.cpp | 9 +- Core/BaseControlDevice.h | 5 +- Core/BaseExpansionAudio.cpp | 4 +- Core/BaseMapper.cpp | 14 +- Core/BaseMapper.h | 2 +- Core/BaseRenderer.cpp | 9 +- Core/BaseVideoFilter.cpp | 20 +- Core/BaseVideoFilter.h | 8 +- Core/BattleBox.h | 2 +- Core/BisqwitNtscFilter.cpp | 13 +- Core/BisqwitNtscFilter.h | 3 +- Core/BizhawkMovie.cpp | 14 +- Core/BizhawkMovie.h | 2 +- Core/CPU.cpp | 13 +- Core/Cheapocabra.h | 2 +- Core/Console.cpp | 97 ++++--- Core/Console.h | 12 +- Core/ControlManager.cpp | 90 +++--- Core/DatachBarcodeReader.h | 4 +- Core/Debugger.cpp | 14 +- Core/DefaultVideoFilter.cpp | 11 +- Core/DefaultVideoFilter.h | 2 +- Core/DeltaModulationChannel.cpp | 2 +- Core/EmulationSettings.cpp | 230 +++++++-------- Core/EmulationSettings.h | 451 ++++++++++++++++-------------- Core/ExcitingBoxingController.h | 2 +- Core/FDS.cpp | 20 +- Core/FDS.h | 1 + Core/FamilyBasicDataRecorder.h | 4 +- Core/FamilyBasicKeyboard.h | 2 +- Core/FamilyMatTrainer.h | 2 +- Core/FceuxMovie.cpp | 2 +- Core/FdsLoader.cpp | 5 - Core/FdsSystemActionManager.h | 2 +- Core/FourScore.h | 2 +- Core/GameClientConnection.cpp | 16 +- Core/GameDatabase.cpp | 133 +-------- Core/GameDatabase.h | 6 +- Core/GameServerConnection.cpp | 2 +- Core/HdData.h | 3 +- Core/HdNesPack.cpp | 7 +- Core/HdNesPack.h | 5 +- Core/HdPackBuilder.cpp | 6 +- Core/HdVideoFilter.cpp | 4 +- Core/HdVideoFilter.h | 3 +- Core/HistoryViewer.cpp | 11 +- Core/HoriTrack.h | 2 +- Core/JissenMahjongController.h | 2 +- Core/KeyManager.cpp | 22 +- Core/KeyManager.h | 4 + Core/KonamiHyperShot.h | 5 +- Core/LuaApi.cpp | 4 +- Core/MMC3.h | 2 +- Core/MapperFactory.cpp | 8 + Core/MemoryDumper.cpp | 8 +- Core/MemoryManager.cpp | 4 +- Core/MesenMovie.cpp | 62 ++-- Core/MessageManager.cpp | 12 +- Core/MessageManager.h | 3 + Core/MovieManager.h | 13 - Core/MovieRecorder.cpp | 49 ++-- Core/NoiseChannel.h | 2 +- Core/NsfMapper.cpp | 22 +- Core/NtscFilter.cpp | 15 +- Core/NtscFilter.h | 4 +- Core/OekaKidsTablet.h | 6 +- Core/OggMixer.cpp | 11 +- Core/OggMixer.h | 4 +- Core/OggReader.cpp | 4 +- Core/OggReader.h | 3 +- Core/PPU.cpp | 69 +++-- Core/PPU.h | 9 +- Core/PartyTap.h | 2 +- Core/PowerPad.h | 2 +- Core/RawVideoFilter.cpp | 2 +- Core/RawVideoFilter.h | 4 +- Core/RecordedRomTest.cpp | 19 +- Core/RewindManager.cpp | 29 +- Core/RewindManager.h | 1 + Core/RomData.h | 1 + Core/SaveStateManager.cpp | 4 +- Core/ScaleFilter.cpp | 5 +- Core/ScaleFilter.h | 2 +- Core/ShortcutKeyHandler.cpp | 67 ++--- Core/SnesController.h | 2 +- Core/SnesMouse.h | 6 +- Core/SoundMixer.cpp | 80 +++--- Core/SoundMixer.h | 1 + Core/SquareChannel.h | 2 +- Core/StandardController.h | 12 +- Core/StereoDelayFilter.cpp | 4 +- Core/StereoDelayFilter.h | 2 +- Core/StereoPanningFilter.cpp | 8 +- Core/StereoPanningFilter.h | 4 +- Core/StudyBox.h | 7 +- Core/SuborKeyboard.h | 2 +- Core/SuborMouse.h | 4 +- Core/SystemActionManager.h | 6 +- Core/TriangleChannel.h | 2 +- Core/Types.h | 7 + Core/UnifLoader.h | 2 +- Core/VideoDecoder.cpp | 44 +-- Core/VideoHud.cpp | 20 +- Core/VideoHud.h | 4 +- Core/VideoRenderer.cpp | 2 +- Core/VsControlManager.cpp | 4 +- Core/Zapper.h | 8 +- Core/iNesLoader.cpp | 4 +- GUI.NET/Config/PreferenceInfo.cs | 5 +- GUI.NET/Debugger/frmDebugger.cs | 4 +- GUI.NET/Forms/frmHistoryViewer.cs | 17 +- GUI.NET/Forms/frmMain.Tools.cs | 2 +- GUI.NET/Forms/frmMain.cs | 3 +- GUI.NET/InteropEmu.cs | 22 +- InteropDLL/ConsoleWrapper.cpp | 166 ++++++----- InteropDLL/DebugWrapper.cpp | 9 +- Libretro/LibretroRenderer.h | 10 +- Libretro/libretro.cpp | 178 ++++++------ Windows/Renderer.cpp | 18 +- Windows/SoundManager.cpp | 8 +- 131 files changed, 1235 insertions(+), 1249 deletions(-) diff --git a/Core/APU.cpp b/Core/APU.cpp index 1eb1b659..01bdd97c 100644 --- a/Core/APU.cpp +++ b/Core/APU.cpp @@ -17,6 +17,7 @@ APU::APU(shared_ptr console) _console = console; _mixer = _console->GetSoundMixer(); + _settings = _console->GetSettings(); _squareChannel[0].reset(new SquareChannel(AudioChannel::Square1, _console, _mixer.get(), true)); _squareChannel[1].reset(new SquareChannel(AudioChannel::Square2, _console, _mixer.get(), false)); @@ -197,10 +198,10 @@ void APU::EndFrame() void APU::ProcessCpuClock() { if(_apuEnabled) { - if(EmulationSettings::GetOverclockRate() == 100 || !EmulationSettings::GetOverclockAdjustApu()) { + if(_settings->GetOverclockRate() == 100 || !_settings->GetOverclockAdjustApu()) { Exec(); } else { - _cyclesNeeded += 1.0 / ((double)EmulationSettings::GetOverclockRate() / 100.0); + _cyclesNeeded += 1.0 / ((double)_settings->GetOverclockRate() / 100.0); while(_cyclesNeeded >= 1.0) { Exec(); _cyclesNeeded--; diff --git a/Core/APU.h b/Core/APU.h index 118df871..c62ded5d 100644 --- a/Core/APU.h +++ b/Core/APU.h @@ -36,6 +36,7 @@ class APU : public Snapshotable, public IMemoryHandler shared_ptr _console; shared_ptr _mixer; + EmulationSettings* _settings; NesModel _nesModel; diff --git a/Core/ArkanoidController.h b/Core/ArkanoidController.h index 661ab47a..7b703b45 100644 --- a/Core/ArkanoidController.h +++ b/Core/ArkanoidController.h @@ -23,9 +23,9 @@ protected: void InternalSetStateFromInput() override { - if(EmulationSettings::InputEnabled()) { + if(_console->GetSettings()->InputEnabled()) { SetPressedState(Buttons::Fire, KeyManager::IsMouseButtonPressed(MouseButton::LeftButton)); - SetMovement(KeyManager::GetMouseMovement(EmulationSettings::GetMouseSensitivity(MouseDevice::ArkanoidController))); + SetMovement(KeyManager::GetMouseMovement(_console->GetSettings()->GetMouseSensitivity(MouseDevice::ArkanoidController))); } } @@ -50,7 +50,7 @@ protected: } public: - ArkanoidController(uint8_t port) : BaseControlDevice(port) + ArkanoidController(shared_ptr console, uint8_t port) : BaseControlDevice(console, port) { } diff --git a/Core/AsciiTurboFile.h b/Core/AsciiTurboFile.h index f49fd40d..776642eb 100644 --- a/Core/AsciiTurboFile.h +++ b/Core/AsciiTurboFile.h @@ -24,7 +24,7 @@ protected: } public: - AsciiTurboFile() : BaseControlDevice(BaseControlDevice::ExpDevicePort) + AsciiTurboFile(shared_ptr console) : BaseControlDevice(console, BaseControlDevice::ExpDevicePort) { BatteryManager::LoadBattery(".tf", _data, AsciiTurboFile::FileSize); } diff --git a/Core/AutoSaveManager.cpp b/Core/AutoSaveManager.cpp index f662f7fd..d3934c43 100644 --- a/Core/AutoSaveManager.cpp +++ b/Core/AutoSaveManager.cpp @@ -11,7 +11,7 @@ AutoSaveManager::AutoSaveManager(shared_ptr console) _autoSaveThread = std::thread([=]() { while(!_stopThread) { bool showMessage = false; - uint32_t autoSaveDelay = EmulationSettings::GetAutoSaveDelay(showMessage) * 60 * 1000; + uint32_t autoSaveDelay = console->GetSettings()->GetAutoSaveDelay(showMessage) * 60 * 1000; if(autoSaveDelay > 0) { if(_timer.GetElapsedMS() > autoSaveDelay) { if(!console->IsDebuggerAttached()) { diff --git a/Core/AutomaticRomTest.cpp b/Core/AutomaticRomTest.cpp index 9deb8c27..9033714f 100644 --- a/Core/AutomaticRomTest.cpp +++ b/Core/AutomaticRomTest.cpp @@ -103,25 +103,26 @@ void AutomaticRomTest::ProcessNotification(ConsoleNotificationType type, void* p int32_t AutomaticRomTest::Run(string filename) { - EmulationSettings::SetMasterVolume(0); _console.reset(new Console()); + EmulationSettings* settings = _console->GetSettings(); + settings->SetMasterVolume(0); _console->GetNotificationManager()->RegisterNotificationListener(shared_from_this()); if(_console->Initialize(filename)) { _console->GetControlManager()->RegisterInputProvider(this); - EmulationSettings::SetFlags(EmulationFlags::ForceMaxSpeed); - EmulationSettings::ClearFlags(EmulationFlags::Paused); + settings->SetFlags(EmulationFlags::ForceMaxSpeed); + settings->ClearFlags(EmulationFlags::Paused); _signal.Wait(); - EmulationSettings::SetFlags(EmulationFlags::Paused); + settings->SetFlags(EmulationFlags::Paused); if(_console->GetFrameCount() < 1800) { //Finished early _errorCode |= 0x10; } - EmulationSettings::ClearFlags(EmulationFlags::ForceMaxSpeed); - EmulationSettings::SetMasterVolume(1.0); + settings->ClearFlags(EmulationFlags::ForceMaxSpeed); + settings->SetMasterVolume(1.0); _console->GetControlManager()->UnregisterInputProvider(this); _console->Stop(); diff --git a/Core/AviRecorder.cpp b/Core/AviRecorder.cpp index 97db9a2e..2aa34da6 100644 --- a/Core/AviRecorder.cpp +++ b/Core/AviRecorder.cpp @@ -29,9 +29,9 @@ AviRecorder::~AviRecorder() uint32_t AviRecorder::GetFps() { if(_console->GetModel() == NesModel::NTSC) { - return EmulationSettings::CheckFlag(EmulationFlags::IntegerFpsMode) ? 60000000 : 60098812; + return _console->GetSettings()->CheckFlag(EmulationFlags::IntegerFpsMode) ? 60000000 : 60098812; } else { - return EmulationSettings::CheckFlag(EmulationFlags::IntegerFpsMode) ? 50000000 : 50006978; + return _console->GetSettings()->CheckFlag(EmulationFlags::IntegerFpsMode) ? 50000000 : 50006978; } } diff --git a/Core/BandaiHyperShot.h b/Core/BandaiHyperShot.h index b7083f09..e367b570 100644 --- a/Core/BandaiHyperShot.h +++ b/Core/BandaiHyperShot.h @@ -25,7 +25,7 @@ protected: { StandardController::InternalSetStateFromInput(); - if(EmulationSettings::InputEnabled()) { + if(_console->GetSettings()->InputEnabled()) { SetPressedState(ZapperButtons::Fire, KeyManager::IsMouseButtonPressed(MouseButton::LeftButton)); MousePosition pos = KeyManager::GetMousePosition(); diff --git a/Core/BandaiKaraoke.h b/Core/BandaiKaraoke.h index 0a7478b8..f6467dcc 100644 --- a/Core/BandaiKaraoke.h +++ b/Core/BandaiKaraoke.h @@ -23,7 +23,7 @@ protected: SelectPRGPage(1, 0x07); SelectCHRPage(0, 0); - _mapperControlDevice.reset(new BandaiMicrophone(_console, EmulationSettings::GetControllerKeys(0))); + _mapperControlDevice.reset(new BandaiMicrophone(_console, _console->GetSettings()->GetControllerKeys(0))); } uint8_t ReadRegister(uint16_t addr) override diff --git a/Core/BandaiMicrophone.h b/Core/BandaiMicrophone.h index e2523e91..b26a2c38 100644 --- a/Core/BandaiMicrophone.h +++ b/Core/BandaiMicrophone.h @@ -6,8 +6,6 @@ class BandaiMicrophone : public BaseControlDevice { protected: - shared_ptr _console; - enum Buttons { A, B, Microphone }; string GetKeyNames() override @@ -18,7 +16,7 @@ protected: void InternalSetStateFromInput() override { //Make sure the key bindings are properly updated (not ideal, but good enough) - _keyMappings = EmulationSettings::GetControllerKeys(0).GetKeyMappingArray(); + _keyMappings = _console->GetSettings()->GetControllerKeys(0).GetKeyMappingArray(); for(KeyMapping keyMapping : _keyMappings) { SetPressedState(Buttons::A, keyMapping.BandaiMicrophoneButtons[0]); @@ -31,7 +29,7 @@ protected: } public: - BandaiMicrophone(shared_ptr console, KeyMappingSet keyMappings) : BaseControlDevice(BaseControlDevice::MapperInputPort, keyMappings) + BandaiMicrophone(shared_ptr console, KeyMappingSet keyMappings) : BaseControlDevice(console, BaseControlDevice::MapperInputPort, keyMappings) { } diff --git a/Core/BarcodeBattlerReader.h b/Core/BarcodeBattlerReader.h index 457227cf..8cd0b423 100644 --- a/Core/BarcodeBattlerReader.h +++ b/Core/BarcodeBattlerReader.h @@ -8,7 +8,6 @@ class BarcodeBattlerReader : public BaseControlDevice, public IBarcodeReader { private: static constexpr int StreamSize = 200; - shared_ptr _console; uint64_t _newBarcode = 0; uint32_t _newBarcodeDigitCount = 0; @@ -51,9 +50,8 @@ protected: } public: - BarcodeBattlerReader(shared_ptr console) : BaseControlDevice(BaseControlDevice::ExpDevicePort) + BarcodeBattlerReader(shared_ptr console) : BaseControlDevice(console, BaseControlDevice::ExpDevicePort) { - _console = console; } void InternalSetStateFromInput() override diff --git a/Core/BaseControlDevice.cpp b/Core/BaseControlDevice.cpp index 8fcd9519..7a5d708d 100644 --- a/Core/BaseControlDevice.cpp +++ b/Core/BaseControlDevice.cpp @@ -2,9 +2,12 @@ #include "BaseControlDevice.h" #include "KeyManager.h" #include "../Utilities/StringUtilities.h" +#include "Console.h" +#include "EmulationSettings.h" -BaseControlDevice::BaseControlDevice(uint8_t port, KeyMappingSet keyMappingSet) +BaseControlDevice::BaseControlDevice(shared_ptr console, uint8_t port, KeyMappingSet keyMappingSet) { + _console = console; _port = port; _strobe = false; _keyMappings = keyMappingSet.GetKeyMappingArray(); @@ -212,12 +215,12 @@ void BaseControlDevice::InvertBit(uint8_t bit) void BaseControlDevice::SetPressedState(uint8_t bit, uint32_t keyCode) { - if(IsKeyboard() && keyCode < 0x200 && !EmulationSettings::IsKeyboardMode()) { + if(IsKeyboard() && keyCode < 0x200 && !_console->GetSettings()->IsKeyboardMode()) { //Prevent keyboard device input when keyboard mode is off return; } - if(EmulationSettings::InputEnabled() && (!EmulationSettings::IsKeyboardMode() || keyCode >= 0x200 || IsKeyboard()) && KeyManager::IsKeyPressed(keyCode)) { + if(_console->GetSettings()->InputEnabled() && (!_console->GetSettings()->IsKeyboardMode() || keyCode >= 0x200 || IsKeyboard()) && KeyManager::IsKeyPressed(keyCode)) { SetBit(bit); } } diff --git a/Core/BaseControlDevice.h b/Core/BaseControlDevice.h index d7d6891a..e0da31d2 100644 --- a/Core/BaseControlDevice.h +++ b/Core/BaseControlDevice.h @@ -6,12 +6,15 @@ #include "ControlDeviceState.h" #include "../Utilities/SimpleLock.h" +class Console; + class BaseControlDevice : public Snapshotable { private: ControlDeviceState _state; protected: + shared_ptr _console; vector _keyMappings; bool _strobe; uint8_t _port; @@ -49,7 +52,7 @@ public: static constexpr uint8_t ExpDevicePort2 = 7; static constexpr uint8_t PortCount = ExpDevicePort2 + 1; - BaseControlDevice(uint8_t port, KeyMappingSet keyMappingSet = KeyMappingSet()); + BaseControlDevice(shared_ptr console, uint8_t port, KeyMappingSet keyMappingSet = KeyMappingSet()); virtual ~BaseControlDevice(); uint8_t GetPort(); diff --git a/Core/BaseExpansionAudio.cpp b/Core/BaseExpansionAudio.cpp index 64f6888b..56db268c 100644 --- a/Core/BaseExpansionAudio.cpp +++ b/Core/BaseExpansionAudio.cpp @@ -16,10 +16,10 @@ void BaseExpansionAudio::StreamState(bool saving) void BaseExpansionAudio::Clock() { if(_console->GetApu()->IsApuEnabled()) { - if(EmulationSettings::GetOverclockRate() == 100 || !EmulationSettings::GetOverclockAdjustApu()) { + if(_console->GetSettings()->GetOverclockRate() == 100 || !_console->GetSettings()->GetOverclockAdjustApu()) { ClockAudio(); } else { - _clocksNeeded += 1.0 / ((double)EmulationSettings::GetOverclockRate() / 100); + _clocksNeeded += 1.0 / ((double)_console->GetSettings()->GetOverclockRate() / 100); while(_clocksNeeded >= 1.0) { ClockAudio(); _clocksNeeded--; diff --git a/Core/BaseMapper.cpp b/Core/BaseMapper.cpp index 07c4c23c..a4270090 100644 --- a/Core/BaseMapper.cpp +++ b/Core/BaseMapper.cpp @@ -318,7 +318,7 @@ void BaseMapper::SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memor void BaseMapper::InitializeRam(void* data, uint32_t length) { - switch(EmulationSettings::GetRamPowerOnState()) { + switch(_console->GetSettings()->GetRamPowerOnState()) { default: case RamPowerOnState::AllZeros: memset(data, 0, length); break; case RamPowerOnState::AllOnes: memset(data, 0xFF, length); break; @@ -335,7 +335,7 @@ void BaseMapper::InitializeRam(void* data, uint32_t length) uint8_t BaseMapper::GetPowerOnByte(uint8_t defaultValue) { - if(EmulationSettings::CheckFlag(EmulationFlags::RandomizeMapperPowerOnState)) { + if(_console->GetSettings()->CheckFlag(EmulationFlags::RandomizeMapperPowerOnState)) { std::random_device rd; std::mt19937 mt(rd()); std::uniform_int_distribution<> dist(0, 255); @@ -398,7 +398,7 @@ void BaseMapper::InitializeChrRam(int32_t chrRamSize) _chrRamSize = chrRamSize >= 0 ? chrRamSize : defaultRamSize; if(_chrRamSize > 0) { _chrRam = new uint8_t[_chrRamSize]; - BaseMapper::InitializeRam(_chrRam, _chrRamSize); + InitializeRam(_chrRam, _chrRamSize); } } @@ -540,8 +540,8 @@ void BaseMapper::Initialize(RomData &romData) _saveRam = new uint8_t[_saveRamSize]; _workRam = new uint8_t[_workRamSize]; - BaseMapper::InitializeRam(_saveRam, _saveRamSize); - BaseMapper::InitializeRam(_workRam, _workRamSize); + InitializeRam(_saveRam, _saveRamSize); + InitializeRam(_workRam, _workRamSize); memset(_prgPageNumbers, 0xEE, sizeof(_prgPageNumbers)); memset(_chrPageNumbers, 0xEE, sizeof(_chrPageNumbers)); @@ -669,11 +669,11 @@ void BaseMapper::SetNametable(uint8_t index, uint8_t nametableIndex) { if(nametableIndex == 2 && _cartNametableRam[0] == nullptr) { _cartNametableRam[0] = new uint8_t[0x400]; - BaseMapper::InitializeRam(_cartNametableRam[0], 0x400); + InitializeRam(_cartNametableRam[0], 0x400); } if(nametableIndex == 3 && _cartNametableRam[1] == nullptr) { _cartNametableRam[1] = new uint8_t[0x400]; - BaseMapper::InitializeRam(_cartNametableRam[1], 0x400); + InitializeRam(_cartNametableRam[1], 0x400); } _nametableIndexes[index] = nametableIndex; diff --git a/Core/BaseMapper.h b/Core/BaseMapper.h index 45ee88e2..90aee524 100644 --- a/Core/BaseMapper.h +++ b/Core/BaseMapper.h @@ -186,7 +186,7 @@ public: uint8_t DebugReadVRAM(uint16_t addr, bool disableSideEffects = true); - static void InitializeRam(void* data, uint32_t length); + void InitializeRam(void* data, uint32_t length); void CopyChrRamTile(uint32_t address, uint8_t *dest); diff --git a/Core/BaseRenderer.cpp b/Core/BaseRenderer.cpp index 3c8d2f5f..100d0661 100644 --- a/Core/BaseRenderer.cpp +++ b/Core/BaseRenderer.cpp @@ -173,16 +173,17 @@ void BaseRenderer::ShowFrameCounter(int lineNumber) void BaseRenderer::DrawCounters() { int lineNumber = 0; - if(EmulationSettings::CheckFlag(EmulationFlags::ShowGameTimer)) { + EmulationSettings* settings = _console->GetSettings(); + if(settings->CheckFlag(EmulationFlags::ShowGameTimer)) { ShowGameTimer(lineNumber++); } - if(EmulationSettings::CheckFlag(EmulationFlags::ShowFPS)) { + if(settings->CheckFlag(EmulationFlags::ShowFPS)) { ShowFpsCounter(lineNumber++); } - if(EmulationSettings::CheckFlag(EmulationFlags::ShowLagCounter)) { + if(settings->CheckFlag(EmulationFlags::ShowLagCounter)) { ShowLagCounter(lineNumber++); } - if(EmulationSettings::CheckFlag(EmulationFlags::ShowFrameCounter)) { + if(settings->CheckFlag(EmulationFlags::ShowFrameCounter)) { ShowFrameCounter(lineNumber++); } } diff --git a/Core/BaseVideoFilter.cpp b/Core/BaseVideoFilter.cpp index 8d137dde..8053d373 100644 --- a/Core/BaseVideoFilter.cpp +++ b/Core/BaseVideoFilter.cpp @@ -6,10 +6,12 @@ #include "StandardController.h" #include "ScaleFilter.h" #include "RotateFilter.h" +#include "Console.h" -BaseVideoFilter::BaseVideoFilter() +BaseVideoFilter::BaseVideoFilter(shared_ptr console) { - _overscan = EmulationSettings::GetOverscanDimensions(); + _console = console; + _overscan = _console->GetSettings()->GetOverscanDimensions(); } BaseVideoFilter::~BaseVideoFilter() @@ -53,7 +55,7 @@ bool BaseVideoFilter::IsOddFrame() void BaseVideoFilter::SendFrame(uint16_t *ppuOutputBuffer, uint32_t frameNumber) { _frameLock.Acquire(); - _overscan = EmulationSettings::GetOverscanDimensions(); + _overscan = _console->GetSettings()->GetOverscanDimensions(); _isOddFrame = frameNumber % 2; UpdateBufferSize(); OnBeforeApplyFilter(); @@ -67,7 +69,7 @@ uint32_t* BaseVideoFilter::GetOutputBuffer() return _outputBuffer; } -void BaseVideoFilter::TakeScreenshot(shared_ptr console, VideoFilterType filterType, string filename, std::stringstream *stream) +void BaseVideoFilter::TakeScreenshot(VideoFilterType filterType, string filename, std::stringstream *stream) { uint32_t* pngBuffer; FrameInfo frameInfo; @@ -85,7 +87,7 @@ void BaseVideoFilter::TakeScreenshot(shared_ptr console, VideoFilterTyp pngBuffer = frameBuffer; - uint32_t rotationAngle = EmulationSettings::GetScreenRotation(); + uint32_t rotationAngle = _console->GetSettings()->GetScreenRotation(); shared_ptr rotateFilter; if(rotationAngle > 0) { rotateFilter.reset(new RotateFilter(rotationAngle)); @@ -95,12 +97,12 @@ void BaseVideoFilter::TakeScreenshot(shared_ptr console, VideoFilterTyp shared_ptr scaleFilter = ScaleFilter::GetScaleFilter(filterType); if(scaleFilter) { - pngBuffer = scaleFilter->ApplyFilter(pngBuffer, frameInfo.Width, frameInfo.Height); + pngBuffer = scaleFilter->ApplyFilter(pngBuffer, frameInfo.Width, frameInfo.Height, _console->GetSettings()->GetPictureSettings().ScanlineIntensity); frameInfo = scaleFilter->GetFrameInfo(frameInfo); } VideoHud hud; - hud.DrawHud(console, pngBuffer, frameInfo, EmulationSettings::GetOverscanDimensions()); + hud.DrawHud(_console, pngBuffer, frameInfo, _console->GetSettings()->GetOverscanDimensions()); if(!filename.empty()) { PNGHelper::WritePNG(filename, pngBuffer, frameInfo.Width, frameInfo.Height); @@ -111,7 +113,7 @@ void BaseVideoFilter::TakeScreenshot(shared_ptr console, VideoFilterTyp delete[] frameBuffer; } -void BaseVideoFilter::TakeScreenshot(shared_ptr console, string romName, VideoFilterType filterType) +void BaseVideoFilter::TakeScreenshot(string romName, VideoFilterType filterType) { string romFilename = FolderUtilities::GetFilename(romName, false); @@ -133,7 +135,7 @@ void BaseVideoFilter::TakeScreenshot(shared_ptr console, string romName counter++; } - TakeScreenshot(console, filterType, ssFilename); + TakeScreenshot(filterType, ssFilename); MessageManager::DisplayMessage("ScreenshotSaved", FolderUtilities::GetFilename(ssFilename, true)); } diff --git a/Core/BaseVideoFilter.h b/Core/BaseVideoFilter.h index 27b796a0..8ef7bb5c 100644 --- a/Core/BaseVideoFilter.h +++ b/Core/BaseVideoFilter.h @@ -19,18 +19,20 @@ private: void UpdateBufferSize(); protected: + shared_ptr _console; + virtual void ApplyFilter(uint16_t *ppuOutputBuffer) = 0; virtual void OnBeforeApplyFilter(); bool IsOddFrame(); public: - BaseVideoFilter(); + BaseVideoFilter(shared_ptr console); virtual ~BaseVideoFilter(); uint32_t* GetOutputBuffer(); void SendFrame(uint16_t *ppuOutputBuffer, uint32_t frameNumber); - void TakeScreenshot(shared_ptr console, string romName, VideoFilterType filterType); - void TakeScreenshot(shared_ptr console, VideoFilterType filterType, string filename, std::stringstream *stream = nullptr); + void TakeScreenshot(string romName, VideoFilterType filterType); + void TakeScreenshot(VideoFilterType filterType, string filename, std::stringstream *stream = nullptr); virtual OverscanDimensions GetOverscan(); virtual FrameInfo GetFrameInfo() = 0; diff --git a/Core/BattleBox.h b/Core/BattleBox.h index 08d5331e..3622c60b 100644 --- a/Core/BattleBox.h +++ b/Core/BattleBox.h @@ -31,7 +31,7 @@ protected: } public: - BattleBox() : BaseControlDevice(BaseControlDevice::ExpDevicePort) + BattleBox(shared_ptr console) : BaseControlDevice(console, BaseControlDevice::ExpDevicePort) { BatteryManager::LoadBattery(".bb", (uint8_t*)_data, BattleBox::FileSize); } diff --git a/Core/BisqwitNtscFilter.cpp b/Core/BisqwitNtscFilter.cpp index fd68d3b7..b53fb1db 100644 --- a/Core/BisqwitNtscFilter.cpp +++ b/Core/BisqwitNtscFilter.cpp @@ -6,8 +6,9 @@ #include "BisqwitNtscFilter.h" #include "PPU.h" #include "EmulationSettings.h" +#include "Console.h" -BisqwitNtscFilter::BisqwitNtscFilter(int resDivider) +BisqwitNtscFilter::BisqwitNtscFilter(shared_ptr console, int resDivider) : BaseVideoFilter(console) { _resDivider = resDivider; _stopThread = false; @@ -84,8 +85,8 @@ FrameInfo BisqwitNtscFilter::GetFrameInfo() void BisqwitNtscFilter::OnBeforeApplyFilter() { - PictureSettings pictureSettings = EmulationSettings::GetPictureSettings(); - NtscFilterSettings ntscSettings = EmulationSettings::GetNtscFilterSettings(); + PictureSettings pictureSettings = _console->GetSettings()->GetPictureSettings(); + NtscFilterSettings ntscSettings = _console->GetSettings()->GetNtscFilterSettings(); _keepVerticalRes = ntscSettings.KeepVerticalResolution; @@ -117,7 +118,7 @@ void BisqwitNtscFilter::RecursiveBlend(int iterationCount, uint64_t *output, uin //Blend 2 pixels at once uint32_t width = GetOverscan().GetScreenWidth() * pixelsPerCycle / 2; - double scanlineIntensity = 1.0 - EmulationSettings::GetPictureSettings().ScanlineIntensity; + double scanlineIntensity = 1.0 - _console->GetSettings()->GetPictureSettings().ScanlineIntensity; if(scanlineIntensity < 1.0 && (iterationCount == 2 || _resDivider == 4)) { //Most likely extremely inefficient scanlines, but works for(uint32_t x = 0; x < width; x++) { @@ -219,7 +220,7 @@ void BisqwitNtscFilter::DecodeFrame(int startRow, int endRow, uint16_t *ppuOutpu //Generate the missing vertical lines outputBuffer = orgBuffer; int lastRow = 239 - GetOverscan().Bottom; - bool verticalBlend = EmulationSettings::GetNtscFilterSettings().VerticalBlend; + bool verticalBlend = _console->GetSettings()->GetNtscFilterSettings().VerticalBlend; for(int y = startRow; y <= endRow; y++) { uint64_t* currentLine = (uint64_t*)outputBuffer; uint64_t* nextLine = y == lastRow ? currentLine : (uint64_t*)(outputBuffer + rowPixelGap); @@ -268,7 +269,7 @@ void BisqwitNtscFilter::NtscDecodeLine(int width, const int8_t* signal, uint32_t auto Cos = [=](int pos) -> char { return _sinetable[(pos + 36) % 12 + phase0]; }; auto Sin = [=](int pos) -> char { return _sinetable[(pos + 36) % 12 + 3 + phase0]; }; - int brightness = (int)(EmulationSettings::GetPictureSettings().Brightness * 750); + int brightness = (int)(_console->GetSettings()->GetPictureSettings().Brightness * 750); int ysum = brightness, isum = 0, qsum = 0; int leftOverscan = GetOverscan().Left * 8; int rightOverscan = width - GetOverscan().Right * 8; diff --git a/Core/BisqwitNtscFilter.h b/Core/BisqwitNtscFilter.h index 89588c7e..c1146d72 100644 --- a/Core/BisqwitNtscFilter.h +++ b/Core/BisqwitNtscFilter.h @@ -43,14 +43,13 @@ private: void RecursiveBlend(int iterationCount, uint64_t *output, uint64_t *currentLine, uint64_t *nextLine, int pixelsPerCycle, bool verticalBlend); void NtscDecodeLine(int width, const int8_t* signal, uint32_t* target, int phase0); - void NtscDecodeLineCustomRes(int width, const int8_t* signal, uint32_t* target, int phase0, int resDivider); void GenerateNtscSignal(int8_t *ntscSignal, int &phase, int rowNumber); void DecodeFrame(int startRow, int endRow, uint16_t *ppuOutputBuffer, uint32_t* outputBuffer, int startPhase); void OnBeforeApplyFilter(); public: - BisqwitNtscFilter(int resDivider); + BisqwitNtscFilter(shared_ptr console, int resDivider); virtual ~BisqwitNtscFilter(); virtual void ApplyFilter(uint16_t *ppuOutputBuffer); diff --git a/Core/BizhawkMovie.cpp b/Core/BizhawkMovie.cpp index d9a71eec..02bede33 100644 --- a/Core/BizhawkMovie.cpp +++ b/Core/BizhawkMovie.cpp @@ -11,7 +11,7 @@ BizhawkMovie::BizhawkMovie(shared_ptr console) { _console = console; - _originalPowerOnState = EmulationSettings::GetRamPowerOnState(); + _originalPowerOnState = _console->GetSettings()->GetRamPowerOnState(); } BizhawkMovie::~BizhawkMovie() @@ -22,8 +22,14 @@ BizhawkMovie::~BizhawkMovie() void BizhawkMovie::Stop() { if(_isPlaying) { - EndMovie(); - EmulationSettings::SetRamPowerOnState(_originalPowerOnState); + MessageManager::DisplayMessage("Movies", "MovieEnded"); + + _console->GetNotificationManager()->SendNotification(ConsoleNotificationType::MovieEnded); + if(_console->GetSettings()->CheckFlag(EmulationFlags::PauseOnMovieEnd)) { + _console->GetSettings()->SetFlags(EmulationFlags::Paused); + } + + _console->GetSettings()->SetRamPowerOnState(_originalPowerOnState); _isPlaying = false; } _console->GetControlManager()->UnregisterInputProvider(this); @@ -190,7 +196,7 @@ bool BizhawkMovie::Play(VirtualFile &file) reader.LoadArchive(ss); _console->GetNotificationManager()->RegisterNotificationListener(shared_from_this()); - EmulationSettings::SetRamPowerOnState(RamPowerOnState::AllOnes); + _console->GetSettings()->SetRamPowerOnState(RamPowerOnState::AllOnes); if(InitializeInputData(reader) && InitializeGameData(reader)) { //NesHawk initializes memory to 1s _isPlaying = true; diff --git a/Core/BizhawkMovie.h b/Core/BizhawkMovie.h index e577a77a..51f69936 100644 --- a/Core/BizhawkMovie.h +++ b/Core/BizhawkMovie.h @@ -21,7 +21,7 @@ protected: vector _dataByFrame[4]; bool _isPlaying = false; RamPowerOnState _originalPowerOnState; - + public: BizhawkMovie(shared_ptr); virtual ~BizhawkMovie(); diff --git a/Core/CPU.cpp b/Core/CPU.cpp index 598b3b57..7a391b6d 100644 --- a/Core/CPU.cpp +++ b/Core/CPU.cpp @@ -346,17 +346,18 @@ uint32_t CPU::GetClockRate(NesModel model) void CPU::StreamState(bool saving) { - uint32_t overclockRate = EmulationSettings::GetOverclockRateSetting(); - bool overclockAdjustApu = EmulationSettings::GetOverclockAdjustApu(); - uint32_t extraScanlinesBeforeNmi = EmulationSettings::GetPpuExtraScanlinesBeforeNmi(); - uint32_t extraScanlinesAfterNmi = EmulationSettings::GetPpuExtraScanlinesAfterNmi(); + EmulationSettings* settings = _console->GetSettings(); + uint32_t overclockRate = settings->GetOverclockRateSetting(); + bool overclockAdjustApu = settings->GetOverclockAdjustApu(); + uint32_t extraScanlinesBeforeNmi = settings->GetPpuExtraScanlinesBeforeNmi(); + uint32_t extraScanlinesAfterNmi = settings->GetPpuExtraScanlinesAfterNmi(); Stream(_state.PC, _state.SP, _state.PS, _state.A, _state.X, _state.Y, _cycleCount, _state.NMIFlag, _state.IRQFlag, _dmcCounter, _dmcDmaRunning, _spriteDmaCounter, _spriteDmaTransfer, overclockRate, overclockAdjustApu, extraScanlinesBeforeNmi, extraScanlinesBeforeNmi); if(!saving) { - EmulationSettings::SetOverclockRate(overclockRate, overclockAdjustApu); - EmulationSettings::SetPpuNmiConfig(extraScanlinesBeforeNmi, extraScanlinesAfterNmi); + settings->SetOverclockRate(overclockRate, overclockAdjustApu); + settings->SetPpuNmiConfig(extraScanlinesBeforeNmi, extraScanlinesAfterNmi); } } \ No newline at end of file diff --git a/Core/Cheapocabra.h b/Core/Cheapocabra.h index d09a1676..75ef59f5 100644 --- a/Core/Cheapocabra.h +++ b/Core/Cheapocabra.h @@ -21,7 +21,7 @@ protected: AddRegisterRange(0x7000, 0x7FFF, MemoryOperation::Write); for(int i = 0; i < 4; i++) { _extraNametables[i] = new uint8_t[0x400]; - BaseMapper::InitializeRam(_extraNametables[i], 0x400); + InitializeRam(_extraNametables[i], 0x400); AddNametable(4 + i, _extraNametables[i]); } _reg = GetPowerOnByte(); diff --git a/Core/Console.cpp b/Core/Console.cpp index aec7856a..6ab12332 100644 --- a/Core/Console.cpp +++ b/Core/Console.cpp @@ -46,9 +46,22 @@ #include "NotificationManager.h" #include "HistoryViewer.h" -Console::Console(shared_ptr master) +Console::Console(shared_ptr master, EmulationSettings* initialSettings) { _master = master; + + if(_master) { + //Slave console should use the same settings as the master + _settings = _master->_settings; + } else { + if(initialSettings) { + _settings.reset(new EmulationSettings(*initialSettings)); + } else { + _settings.reset(new EmulationSettings()); + } + KeyManager::SetSettings(_settings.get()); + } + _model = NesModel::NTSC; } @@ -295,17 +308,17 @@ bool Console::Initialize(VirtualFile &romFile, VirtualFile &patchFile) switch(romInfo.System) { case GameSystem::FDS: - EmulationSettings::SetPpuModel(PpuModel::Ppu2C02); + _settings->SetPpuModel(PpuModel::Ppu2C02); _systemActionManager.reset(new FdsSystemActionManager(shared_from_this(), _mapper)); break; case GameSystem::VsSystem: - EmulationSettings::SetPpuModel(romInfo.VsPpuModel); + _settings->SetPpuModel(romInfo.VsPpuModel); _systemActionManager.reset(new VsSystemActionManager(shared_from_this())); break; default: - EmulationSettings::SetPpuModel(PpuModel::Ppu2C02); + _settings->SetPpuModel(PpuModel::Ppu2C02); _systemActionManager.reset(new SystemActionManager(shared_from_this())); break; } @@ -381,10 +394,10 @@ bool Console::Initialize(VirtualFile &romFile, VirtualFile &patchFile) string modelName = _model == NesModel::PAL ? "PAL" : (_model == NesModel::Dendy ? "Dendy" : "NTSC"); string messageTitle = MessageManager::Localize("GameLoaded") + " (" + modelName + ")"; MessageManager::DisplayMessage(messageTitle, FolderUtilities::GetFilename(GetRomInfo().RomName, false)); - if(EmulationSettings::GetOverclockRate() != 100) { - MessageManager::DisplayMessage("ClockRate", std::to_string(EmulationSettings::GetOverclockRate()) + "%"); + if(_settings->GetOverclockRate() != 100) { + MessageManager::DisplayMessage("ClockRate", std::to_string(_settings->GetOverclockRate()) + "%"); } - EmulationSettings::ClearFlags(EmulationFlags::ForceMaxSpeed); + _settings->ClearFlags(EmulationFlags::ForceMaxSpeed); if(_slave) { _notificationManager->SendNotification(ConsoleNotificationType::VsDualSystemStarted); @@ -438,6 +451,11 @@ shared_ptr Console::GetNotificationManager() return _notificationManager; } +EmulationSettings* Console::GetSettings() +{ + return _settings.get(); +} + bool Console::IsDualSystem() { return _slave != nullptr || _master != nullptr; @@ -552,7 +570,7 @@ void Console::ResetComponents(bool softReset) _soundMixer->StopAudio(true); _memoryManager->Reset(softReset); - if(!EmulationSettings::CheckFlag(EmulationFlags::DisablePpuReset) || !softReset) { + if(!_settings->CheckFlag(EmulationFlags::DisablePpuReset) || !softReset) { _ppu->Reset(); } _apu->Reset(softReset); @@ -638,7 +656,7 @@ void Console::RunSingleFrame() } } - EmulationSettings::DisableOverclocking(_disableOcNextFrame || NsfMapper::GetInstance()); + _settings->DisableOverclocking(_disableOcNextFrame || NsfMapper::GetInstance()); _disableOcNextFrame = false; _systemActionManager->ProcessSystemActions(); @@ -704,7 +722,7 @@ void Console::Run() _slave->_soundMixer->ProcessEndOfFrame(); } - bool displayDebugInfo = EmulationSettings::CheckFlag(EmulationFlags::DisplayDebugInfo); + bool displayDebugInfo = _settings->CheckFlag(EmulationFlags::DisplayDebugInfo); if(displayDebugInfo) { DisplayDebugInformation(clockTimer, lastFrameTimer, lastFrameMin, lastFrameMax, timeLagData); if(_slave) { @@ -717,7 +735,7 @@ void Console::Run() _historyViewer->ProcessEndOfFrame(); } _rewindManager->ProcessEndOfFrame(); - EmulationSettings::DisableOverclocking(_disableOcNextFrame || NsfMapper::GetInstance()); + _settings->DisableOverclocking(_disableOcNextFrame || NsfMapper::GetInstance()); _disableOcNextFrame = false; //Sleep until we're ready to start the next frame @@ -732,9 +750,9 @@ void Console::Run() _runLock.Acquire(); } - - bool paused = EmulationSettings::IsPaused() || _paused; - if(paused && !_stop) { + + bool pausedRequired = _settings->NeedsPause(); + if(pausedRequired && !_stop && !_settings->CheckFlag(EmulationFlags::DebuggerWindowEnabled)) { _notificationManager->SendNotification(ConsoleNotificationType::GamePaused); //Prevent audio from looping endlessly while game is paused @@ -747,24 +765,21 @@ void Console::Run() PlatformUtilities::EnableScreensaver(); PlatformUtilities::RestoreTimerResolution(); - while(paused && !_stop) { + while(pausedRequired && !_stop && !_settings->CheckFlag(EmulationFlags::DebuggerWindowEnabled)) { //Sleep until emulation is resumed std::this_thread::sleep_for(std::chrono::duration(30)); - paused = EmulationSettings::IsPaused() || _paused; + pausedRequired = _settings->NeedsPause(); + _paused = true; } - - if(EmulationSettings::CheckFlag(EmulationFlags::DebuggerWindowEnabled)) { - //Prevent pausing when debugger is active - EmulationSettings::ClearFlags(EmulationFlags::Paused); - } - + _paused = false; + PlatformUtilities::DisableScreensaver(); _runLock.Acquire(); _notificationManager->SendNotification(ConsoleNotificationType::GameResumed); lastFrameTimer.Reset(); } - if(EmulationSettings::CheckFlag(EmulationFlags::UseHighResolutionTimer)) { + if(_settings->CheckFlag(EmulationFlags::UseHighResolutionTimer)) { PlatformUtilities::EnableHighResolutionTimer(); } else { PlatformUtilities::RestoreTimerResolution(); @@ -773,7 +788,7 @@ void Console::Run() _systemActionManager->ProcessSystemActions(); //Get next target time, and adjust based on whether we are ahead or behind - double timeLag = EmulationSettings::GetEmulationSpeed() == 0 ? 0 : clockTimer.GetElapsedMS() - targetTime; + double timeLag = _settings->GetEmulationSpeed() == 0 ? 0 : clockTimer.GetElapsedMS() - targetTime; if(displayDebugInfo) { timeLagData[timeLagDataIndex] = timeLag; timeLagDataIndex = (timeLagDataIndex + 1) & 0x0F; @@ -820,8 +835,7 @@ void Console::Run() PlatformUtilities::EnableScreensaver(); PlatformUtilities::RestoreTimerResolution(); - EmulationSettings::ClearFlags(EmulationFlags::Paused); - EmulationSettings::ClearFlags(EmulationFlags::ForceMaxSpeed); + _settings->ClearFlags(EmulationFlags::ForceMaxSpeed); _initialized = false; @@ -853,7 +867,7 @@ bool Console::IsRunning() } } -bool Console::IsPaused() +bool Console::IsExecutionStopped() { if(_master) { //For slave CPU, return the master's state @@ -863,25 +877,24 @@ bool Console::IsPaused() } } -bool Console::GetPauseStatus() +bool Console::IsPaused() { - return _paused; -} - -void Console::SetPauseStatus(bool paused) -{ - _paused = paused; + if(_master) { + return _master->_paused; + } else { + return _paused; + } } void Console::UpdateNesModel(bool sendNotification) { bool configChanged = false; - if(EmulationSettings::NeedControllerUpdate()) { + if(_settings->NeedControllerUpdate()) { _controlManager->UpdateControlDevices(); configChanged = true; } - NesModel model = EmulationSettings::GetNesModel(); + NesModel model = _settings->GetNesModel(); if(model == NesModel::Auto) { switch(_mapper->GetRomInfo().System) { case GameSystem::NesPal: model = NesModel::PAL; break; @@ -909,7 +922,7 @@ void Console::UpdateNesModel(bool sendNotification) double Console::GetFrameDelay() { - uint32_t emulationSpeed = EmulationSettings::GetEmulationSpeed(); + uint32_t emulationSpeed = _settings->GetEmulationSpeed(); double frameDelay; if(emulationSpeed == 0) { frameDelay = 0; @@ -917,9 +930,9 @@ double Console::GetFrameDelay() //60.1fps (NTSC), 50.01fps (PAL/Dendy) switch(_model) { default: - case NesModel::NTSC: frameDelay = EmulationSettings::CheckFlag(EmulationFlags::IntegerFpsMode) ? 16.6666666666666666667 : 16.63926405550947; break; + case NesModel::NTSC: frameDelay = _settings->CheckFlag(EmulationFlags::IntegerFpsMode) ? 16.6666666666666666667 : 16.63926405550947; break; case NesModel::PAL: - case NesModel::Dendy: frameDelay = EmulationSettings::CheckFlag(EmulationFlags::IntegerFpsMode) ? 20 : 19.99720920217466; break; + case NesModel::Dendy: frameDelay = _settings->CheckFlag(EmulationFlags::IntegerFpsMode) ? 20 : 19.99720920217466; break; } frameDelay /= (double)emulationSpeed / 100.0; } @@ -999,7 +1012,7 @@ void Console::BreakIfDebugging() shared_ptr debugger = _debugger; if(debugger) { debugger->BreakImmediately(); - } else if(EmulationSettings::CheckFlag(EmulationFlags::BreakOnCrash)) { + } else if(_settings->CheckFlag(EmulationFlags::BreakOnCrash)) { //When "Break on Crash" is enabled, open the debugger and break immediately if a crash occurs debugger = GetDebugger(true); debugger->BreakImmediately(); @@ -1072,7 +1085,7 @@ void Console::LoadHdPack(VirtualFile &romFile, VirtualFile &patchFile) { _hdData.reset(); _hdAudioDevice.reset(); - if(EmulationSettings::CheckFlag(EmulationFlags::UseHdPacks)) { + if(_settings->CheckFlag(EmulationFlags::UseHdPacks)) { _hdData.reset(new HdPackData()); if(!HdPackLoader::LoadHdNesPack(romFile, *_hdData.get())) { _hdData.reset(); @@ -1378,7 +1391,7 @@ void Console::DisplayDebugInformation(Timer &clockTimer, Timer &lastFrameTimer, _debugHud->DrawString(10, 10, "Audio Stats", 0xFFFFFF, 0xFF000000, 1, startFrame); _debugHud->DrawString(10, 21, "Latency: ", 0xFFFFFF, 0xFF000000, 1, startFrame); - int color = (stats.AverageLatency > 0 && std::abs(stats.AverageLatency - EmulationSettings::GetAudioLatency()) > 3) ? 0xFF0000 : 0xFFFFFF; + int color = (stats.AverageLatency > 0 && std::abs(stats.AverageLatency - _settings->GetAudioLatency()) > 3) ? 0xFF0000 : 0xFFFFFF; std::stringstream ss; ss << std::fixed << std::setprecision(2) << stats.AverageLatency << " ms"; _debugHud->DrawString(54, 21, ss.str(), color, 0xFF000000, 1, startFrame); diff --git a/Core/Console.h b/Core/Console.h index 2da70499..605c30f2 100644 --- a/Core/Console.h +++ b/Core/Console.h @@ -26,6 +26,7 @@ class DebugHud; class SoundMixer; class NotificationManager; class Debugger; +class EmulationSettings; struct HdPackData; struct HashInfo; @@ -71,6 +72,7 @@ private: shared_ptr _debugHud; shared_ptr _soundMixer; shared_ptr _notificationManager; + shared_ptr _settings; shared_ptr _hdPackBuilder; shared_ptr _hdData; @@ -98,7 +100,7 @@ private: void DisplayDebugInformation(Timer &clockTimer, Timer &lastFrameTimer, double &lastFrameMin, double &lastFrameMax, double *timeLagData); public: - Console(shared_ptr master = nullptr); + Console(shared_ptr master = nullptr, EmulationSettings* initialSettings = nullptr); ~Console(); void Init(); @@ -110,7 +112,8 @@ public: shared_ptr GetDebugHud(); shared_ptr GetSoundMixer(); shared_ptr GetNotificationManager(); - + EmulationSettings* GetSettings(); + bool IsDualSystem(); shared_ptr GetDualConsole(); bool IsMaster(); @@ -191,10 +194,9 @@ public: void ResetLagCounter(); bool IsRunning(); - bool IsPaused(); + bool IsExecutionStopped(); - bool GetPauseStatus(); - void SetPauseStatus(bool paused); + bool IsPaused(); void SetNextFrameOverclockStatus(bool disabled); diff --git a/Core/ControlManager.cpp b/Core/ControlManager.cpp index 9cceecf7..e6c15568 100644 --- a/Core/ControlManager.cpp +++ b/Core/ControlManager.cpp @@ -106,7 +106,7 @@ void ControlManager::RegisterControlDevice(shared_ptr control ControllerType ControlManager::GetControllerType(uint8_t port) { - return EmulationSettings::GetControllerType(port); + return _console->GetSettings()->GetControllerType(port); } shared_ptr ControlManager::CreateControllerDevice(ControllerType type, uint8_t port, shared_ptr console) @@ -115,13 +115,13 @@ shared_ptr ControlManager::CreateControllerDevice(ControllerT switch(type) { case ControllerType::None: break; - case ControllerType::StandardController: device.reset(new StandardController(console, port, EmulationSettings::GetControllerKeys(port))); break; + case ControllerType::StandardController: device.reset(new StandardController(console, port, console->GetSettings()->GetControllerKeys(port))); break; case ControllerType::Zapper: device.reset(new Zapper(console, port)); break; - case ControllerType::ArkanoidController: device.reset(new ArkanoidController(port)); break; - case ControllerType::SnesController: device.reset(new SnesController(port, EmulationSettings::GetControllerKeys(port))); break; - case ControllerType::PowerPad: device.reset(new PowerPad(port, EmulationSettings::GetControllerKeys(port))); break; - case ControllerType::SnesMouse: device.reset(new SnesMouse(port)); break; - case ControllerType::SuborMouse: device.reset(new SuborMouse(port)); break; + case ControllerType::ArkanoidController: device.reset(new ArkanoidController(console, port)); break; + case ControllerType::SnesController: device.reset(new SnesController(console, port, console->GetSettings()->GetControllerKeys(port))); break; + case ControllerType::PowerPad: device.reset(new PowerPad(console, port, console->GetSettings()->GetControllerKeys(port))); break; + case ControllerType::SnesMouse: device.reset(new SnesMouse(console, port)); break; + case ControllerType::SuborMouse: device.reset(new SuborMouse(console, port)); break; case ControllerType::VsZapper: device.reset(new VsZapper(console, port)); break; } @@ -134,21 +134,21 @@ shared_ptr ControlManager::CreateExpansionDevice(ExpansionPor switch(type) { case ExpansionPortDevice::Zapper: device.reset(new Zapper(console, BaseControlDevice::ExpDevicePort)); break; - case ExpansionPortDevice::ArkanoidController: device.reset(new ArkanoidController(BaseControlDevice::ExpDevicePort)); break; - case ExpansionPortDevice::OekaKidsTablet: device.reset(new OekaKidsTablet()); break; - case ExpansionPortDevice::FamilyTrainerMat: device.reset(new FamilyMatTrainer(EmulationSettings::GetControllerKeys(0))); break; - case ExpansionPortDevice::KonamiHyperShot: device.reset(new KonamiHyperShot(console, EmulationSettings::GetControllerKeys(0), EmulationSettings::GetControllerKeys(1))); break; - case ExpansionPortDevice::FamilyBasicKeyboard: device.reset(new FamilyBasicKeyboard(EmulationSettings::GetControllerKeys(0))); break; - case ExpansionPortDevice::PartyTap: device.reset(new PartyTap(EmulationSettings::GetControllerKeys(0))); break; - case ExpansionPortDevice::Pachinko: device.reset(new PachinkoController(console, EmulationSettings::GetControllerKeys(0))); break; - case ExpansionPortDevice::ExcitingBoxing: device.reset(new ExcitingBoxingController(EmulationSettings::GetControllerKeys(0))); break; - case ExpansionPortDevice::JissenMahjong: device.reset(new JissenMahjongController(EmulationSettings::GetControllerKeys(0))); break; - case ExpansionPortDevice::SuborKeyboard: device.reset(new SuborKeyboard(EmulationSettings::GetControllerKeys(0))); break; + case ExpansionPortDevice::ArkanoidController: device.reset(new ArkanoidController(console, BaseControlDevice::ExpDevicePort)); break; + case ExpansionPortDevice::OekaKidsTablet: device.reset(new OekaKidsTablet(console)); break; + case ExpansionPortDevice::FamilyTrainerMat: device.reset(new FamilyMatTrainer(console, console->GetSettings()->GetControllerKeys(0))); break; + case ExpansionPortDevice::KonamiHyperShot: device.reset(new KonamiHyperShot(console, console->GetSettings()->GetControllerKeys(0), console->GetSettings()->GetControllerKeys(1))); break; + case ExpansionPortDevice::FamilyBasicKeyboard: device.reset(new FamilyBasicKeyboard(console, console->GetSettings()->GetControllerKeys(0))); break; + case ExpansionPortDevice::PartyTap: device.reset(new PartyTap(console, console->GetSettings()->GetControllerKeys(0))); break; + case ExpansionPortDevice::Pachinko: device.reset(new PachinkoController(console, console->GetSettings()->GetControllerKeys(0))); break; + case ExpansionPortDevice::ExcitingBoxing: device.reset(new ExcitingBoxingController(console, console->GetSettings()->GetControllerKeys(0))); break; + case ExpansionPortDevice::JissenMahjong: device.reset(new JissenMahjongController(console, console->GetSettings()->GetControllerKeys(0))); break; + case ExpansionPortDevice::SuborKeyboard: device.reset(new SuborKeyboard(console, console->GetSettings()->GetControllerKeys(0))); break; case ExpansionPortDevice::BarcodeBattler: device.reset(new BarcodeBattlerReader(console)); break; - case ExpansionPortDevice::HoriTrack: device.reset(new HoriTrack(console, EmulationSettings::GetControllerKeys(0))); break; - case ExpansionPortDevice::BandaiHyperShot: device.reset(new BandaiHyperShot(console, EmulationSettings::GetControllerKeys(0))); break; - case ExpansionPortDevice::AsciiTurboFile: device.reset(new AsciiTurboFile()); break; - case ExpansionPortDevice::BattleBox: device.reset(new BattleBox()); break; + case ExpansionPortDevice::HoriTrack: device.reset(new HoriTrack(console, console->GetSettings()->GetControllerKeys(0))); break; + case ExpansionPortDevice::BandaiHyperShot: device.reset(new BandaiHyperShot(console, console->GetSettings()->GetControllerKeys(0))); break; + case ExpansionPortDevice::AsciiTurboFile: device.reset(new AsciiTurboFile(console)); break; + case ExpansionPortDevice::BattleBox: device.reset(new BattleBox(console)); break; case ExpansionPortDevice::FourPlayerAdapter: default: break; @@ -160,9 +160,10 @@ shared_ptr ControlManager::CreateExpansionDevice(ExpansionPor void ControlManager::UpdateControlDevices() { auto lock = _deviceLock.AcquireSafe(); + EmulationSettings* settings = _console->GetSettings(); //Reset update flag - EmulationSettings::NeedControllerUpdate(); + settings->NeedControllerUpdate(); bool hadKeyboard = HasKeyboard(); @@ -170,9 +171,9 @@ void ControlManager::UpdateControlDevices() RegisterControlDevice(_systemActionManager); - bool fourScore = EmulationSettings::CheckFlag(EmulationFlags::HasFourScore); - ConsoleType consoleType = EmulationSettings::GetConsoleType(); - ExpansionPortDevice expansionDevice = EmulationSettings::GetExpansionDevice(); + bool fourScore = settings->CheckFlag(EmulationFlags::HasFourScore); + ConsoleType consoleType = settings->GetConsoleType(); + ExpansionPortDevice expansionDevice = settings->GetExpansionDevice(); if(consoleType != ConsoleType::Famicom) { expansionDevice = ExpansionPortDevice::None; @@ -189,7 +190,7 @@ void ControlManager::UpdateControlDevices() if(fourScore && consoleType == ConsoleType::Nes) { //FourScore is only used to provide the signature for reads past the first 16 reads - RegisterControlDevice(shared_ptr(new FourScore())); + RegisterControlDevice(shared_ptr(new FourScore(_console))); } shared_ptr expDevice = CreateExpansionDevice(expansionDevice, _console); @@ -199,9 +200,9 @@ void ControlManager::UpdateControlDevices() bool hasKeyboard = HasKeyboard(); if(!hasKeyboard) { - EmulationSettings::DisableKeyboardMode(); + settings->DisableKeyboardMode(); } else if(!hadKeyboard && hasKeyboard) { - EmulationSettings::EnableKeyboardMode(); + settings->EnableKeyboardMode(); } if(_mapperControlDevice) { @@ -226,17 +227,17 @@ uint8_t ControlManager::GetOpenBusMask(uint8_t port) //Usually this is the most significant byte of the address of the controller port - 0x40. //Paperboy relies on this behavior and requires that reads from the controller ports return exactly $40 or $41 as appropriate." - switch(EmulationSettings::GetConsoleType()) { + switch(_console->GetSettings()->GetConsoleType()) { default: case ConsoleType::Nes: - if(EmulationSettings::CheckFlag(EmulationFlags::UseNes101Hvc101Behavior)) { + if(_console->GetSettings()->CheckFlag(EmulationFlags::UseNes101Hvc101Behavior)) { return port == 0 ? 0xE4 : 0xE0; } else { return 0xE0; } case ConsoleType::Famicom: - if(EmulationSettings::CheckFlag(EmulationFlags::UseNes101Hvc101Behavior)) { + if(_console->GetSettings()->CheckFlag(EmulationFlags::UseNes101Hvc101Behavior)) { return port == 0 ? 0xF8 : 0xE0; } else { return port == 0 ? 0xF8 : 0xE0; @@ -348,6 +349,7 @@ void ControlManager::StreamState(bool saving) { //Restore controllers that were being used at the time the snapshot was made //This is particularely important to ensure proper sync during NetPlay + EmulationSettings* settings = _console->GetSettings(); ControllerType controllerTypes[4]; NesModel nesModel; ExpansionPortDevice expansionDevice; @@ -357,13 +359,13 @@ void ControlManager::StreamState(bool saving) uint32_t zapperDetectionRadius = 0; if(saving) { nesModel = _console->GetModel(); - expansionDevice = EmulationSettings::GetExpansionDevice(); - consoleType = EmulationSettings::GetConsoleType(); - hasFourScore = EmulationSettings::CheckFlag(EmulationFlags::HasFourScore); - useNes101Hvc101Behavior = EmulationSettings::CheckFlag(EmulationFlags::UseNes101Hvc101Behavior); - zapperDetectionRadius = EmulationSettings::GetZapperDetectionRadius(); + expansionDevice = settings->GetExpansionDevice(); + consoleType = settings->GetConsoleType(); + hasFourScore = settings->CheckFlag(EmulationFlags::HasFourScore); + useNes101Hvc101Behavior = settings->CheckFlag(EmulationFlags::UseNes101Hvc101Behavior); + zapperDetectionRadius = settings->GetZapperDetectionRadius(); for(int i = 0; i < 4; i++) { - controllerTypes[i] = EmulationSettings::GetControllerType(i); + controllerTypes[i] = settings->GetControllerType(i); } } @@ -375,16 +377,16 @@ void ControlManager::StreamState(bool saving) Stream(unusedRefreshState, unusedMousePositionX, unusedMousePositionY, nesModel, expansionDevice, consoleType, types, hasFourScore, useNes101Hvc101Behavior, zapperDetectionRadius, _lagCounter, _pollCounter); if(!saving) { - EmulationSettings::SetNesModel(nesModel); - EmulationSettings::SetExpansionDevice(expansionDevice); - EmulationSettings::SetConsoleType(consoleType); + settings->SetNesModel(nesModel); + settings->SetExpansionDevice(expansionDevice); + settings->SetConsoleType(consoleType); for(int i = 0; i < 4; i++) { - EmulationSettings::SetControllerType(i, controllerTypes[i]); + settings->SetControllerType(i, controllerTypes[i]); } - EmulationSettings::SetZapperDetectionRadius(zapperDetectionRadius); - EmulationSettings::SetFlagState(EmulationFlags::HasFourScore, hasFourScore); - EmulationSettings::SetFlagState(EmulationFlags::UseNes101Hvc101Behavior, useNes101Hvc101Behavior); + settings->SetZapperDetectionRadius(zapperDetectionRadius); + settings->SetFlagState(EmulationFlags::HasFourScore, hasFourScore); + settings->SetFlagState(EmulationFlags::UseNes101Hvc101Behavior, useNes101Hvc101Behavior); UpdateControlDevices(); } diff --git a/Core/DatachBarcodeReader.h b/Core/DatachBarcodeReader.h index 6baebcfc..9e9589f0 100644 --- a/Core/DatachBarcodeReader.h +++ b/Core/DatachBarcodeReader.h @@ -8,7 +8,6 @@ class DatachBarcodeReader : public BaseControlDevice, public IBarcodeReader { private: - shared_ptr _console; vector _data; int32_t _insertCycle = 0; uint64_t _newBarcode = 0; @@ -29,9 +28,8 @@ protected: } public: - DatachBarcodeReader(shared_ptr console) : BaseControlDevice(BaseControlDevice::MapperInputPort) + DatachBarcodeReader(shared_ptr console) : BaseControlDevice(console, BaseControlDevice::MapperInputPort) { - _console = console; } void InternalSetStateFromInput() override diff --git a/Core/Debugger.cpp b/Core/Debugger.cpp index 05e9462b..4c85d139 100644 --- a/Core/Debugger.cpp +++ b/Core/Debugger.cpp @@ -29,10 +29,6 @@ #include "CodeDataLogger.h" #include "NotificationManager.h" -#ifndef UINT32_MAX -#define UINT32_MAX ((uint32_t)-1) -#endif - const int Debugger::BreakpointTypeCount; string Debugger::_disassemblerOutput = ""; @@ -253,7 +249,7 @@ void Debugger::SetBreakpoints(Breakpoint breakpoints[], uint32_t length) for(uint32_t j = 0; j < length; j++) { Breakpoint &bp = breakpoints[j]; for(int i = 0; i < Debugger::BreakpointTypeCount; i++) { - bool isEnabled = bp.IsEnabled() && EmulationSettings::CheckFlag(EmulationFlags::DebuggerWindowEnabled); + bool isEnabled = bp.IsEnabled() && _console->GetSettings()->CheckFlag(EmulationFlags::DebuggerWindowEnabled); if((bp.IsMarked() || isEnabled) && bp.HasBreakpointType((BreakpointType)i)) { _breakpoints[i].push_back(bp); vector *rpnList = expEval.GetRpnList(bp.GetCondition()); @@ -897,7 +893,7 @@ const char* Debugger::GetCode(uint32_t &length) { string previousCode = _disassemblerOutput; GenerateCodeOutput(); - bool forceRefresh = length == UINT32_MAX; + bool forceRefresh = length == (uint32_t)-1; length = (uint32_t)_disassemblerOutput.size(); if(!forceRefresh && previousCode.compare(_disassemblerOutput) == 0) { //Return null pointer if the code is identical to last call @@ -1009,7 +1005,7 @@ shared_ptr Debugger::GetMemoryAccessCounter() bool Debugger::IsExecutionStopped() { - return _executionStopped || _console->IsPaused(); + return _executionStopped || _console->IsExecutionStopped(); } bool Debugger::IsPauseIconShown() @@ -1150,7 +1146,7 @@ void Debugger::StopCodeRunner() //Break debugger when code has finished executing SetNextStatement(_returnToAddress); - if(EmulationSettings::CheckFlag(EmulationFlags::DebuggerWindowEnabled)) { + if(_console->GetSettings()->CheckFlag(EmulationFlags::DebuggerWindowEnabled)) { Step(1); } else { Run(); @@ -1378,7 +1374,7 @@ void Debugger::GetDebugEvents(uint32_t* pictureBuffer, DebugEventInfo *infoArray DebugBreakHelper helper(this); uint16_t *buffer = new uint16_t[PPU::PixelCount]; - uint32_t *palette = EmulationSettings::GetRgbPalette(); + uint32_t *palette = _console->GetSettings()->GetRgbPalette(); _ppu->DebugCopyOutputBuffer(buffer); for(int i = 0; i < PPU::PixelCount; i++) { diff --git a/Core/DefaultVideoFilter.cpp b/Core/DefaultVideoFilter.cpp index 12ededa2..8c4024ab 100644 --- a/Core/DefaultVideoFilter.cpp +++ b/Core/DefaultVideoFilter.cpp @@ -6,8 +6,9 @@ #include #include "PPU.h" #include "DebugHud.h" +#include "Console.h" -DefaultVideoFilter::DefaultVideoFilter() +DefaultVideoFilter::DefaultVideoFilter(shared_ptr console) : BaseVideoFilter(console) { InitDecodeTables(); @@ -45,7 +46,7 @@ FrameInfo DefaultVideoFilter::GetFrameInfo() void DefaultVideoFilter::OnBeforeApplyFilter() { - PictureSettings currentSettings = EmulationSettings::GetPictureSettings(); + PictureSettings currentSettings = _console->GetSettings()->GetPictureSettings(); if(_pictureSettings.Hue != currentSettings.Hue || _pictureSettings.Saturation != currentSettings.Saturation) { InitConversionMatrix(currentSettings.Hue, currentSettings.Saturation); } @@ -57,7 +58,7 @@ void DefaultVideoFilter::DecodePpuBuffer(uint16_t *ppuOutputBuffer, uint32_t* ou { uint32_t* out = outputBuffer; OverscanDimensions overscan = GetOverscan(); - double scanlineIntensity = 1.0 - EmulationSettings::GetPictureSettings().ScanlineIntensity; + double scanlineIntensity = 1.0 - _console->GetSettings()->GetPictureSettings().ScanlineIntensity; for(uint32_t i = overscan.Top, iMax = 240 - overscan.Bottom; i < iMax; i++) { if(displayScanlines && (i + overscan.Top) % 2 == 0) { for(uint32_t j = overscan.Left, jMax = 256 - overscan.Right; j < jMax; j++) { @@ -75,7 +76,7 @@ void DefaultVideoFilter::DecodePpuBuffer(uint16_t *ppuOutputBuffer, uint32_t* ou void DefaultVideoFilter::ApplyFilter(uint16_t *ppuOutputBuffer) { - DecodePpuBuffer(ppuOutputBuffer, GetOutputBuffer(), EmulationSettings::GetVideoFilterType() <= VideoFilterType::BisqwitNtsc); + DecodePpuBuffer(ppuOutputBuffer, GetOutputBuffer(), _console->GetSettings()->GetVideoFilterType() <= VideoFilterType::BisqwitNtsc); } void DefaultVideoFilter::RgbToYiq(double r, double g, double b, double &y, double &i, double &q) @@ -131,7 +132,7 @@ void DefaultVideoFilter::InitDecodeTables() uint32_t DefaultVideoFilter::ProcessIntensifyBits(uint16_t ppuPixel, double scanlineIntensity) { - uint32_t pixelOutput = EmulationSettings::GetRgbPalette()[ppuPixel & 0x3F]; + uint32_t pixelOutput = _console->GetSettings()->GetRgbPalette()[ppuPixel & 0x3F]; uint32_t intensifyBits = (ppuPixel >> 6) & 0x07; if(intensifyBits || _needToProcess || scanlineIntensity < 1.0) { diff --git a/Core/DefaultVideoFilter.h b/Core/DefaultVideoFilter.h index c2e4e509..5dbde6f5 100644 --- a/Core/DefaultVideoFilter.h +++ b/Core/DefaultVideoFilter.h @@ -26,7 +26,7 @@ protected: void OnBeforeApplyFilter(); public: - DefaultVideoFilter(); + DefaultVideoFilter(shared_ptr console); void ApplyFilter(uint16_t *ppuOutputBuffer); FrameInfo GetFrameInfo(); }; \ No newline at end of file diff --git a/Core/DeltaModulationChannel.cpp b/Core/DeltaModulationChannel.cpp index d93f3ef2..8fd5f33e 100644 --- a/Core/DeltaModulationChannel.cpp +++ b/Core/DeltaModulationChannel.cpp @@ -156,7 +156,7 @@ void DeltaModulationChannel::WriteRAM(uint16_t addr, uint8_t value) uint8_t previousLevel = _outputLevel; _outputLevel = newValue; - if(EmulationSettings::CheckFlag(EmulationFlags::ReduceDmcPopping) && abs(_outputLevel - previousLevel) > 50) { + if(_console->GetSettings()->CheckFlag(EmulationFlags::ReduceDmcPopping) && abs(_outputLevel - previousLevel) > 50) { //Reduce popping sounds for 4011 writes _outputLevel -= (_outputLevel - previousLevel) / 2; } diff --git a/Core/EmulationSettings.cpp b/Core/EmulationSettings.cpp index 9b2a67b8..5a7b9726 100644 --- a/Core/EmulationSettings.cpp +++ b/Core/EmulationSettings.cpp @@ -8,121 +8,13 @@ uint16_t EmulationSettings::_versionMajor = 0; uint8_t EmulationSettings::_versionMinor = 9; uint8_t EmulationSettings::_versionRevision = 5; -Language EmulationSettings::_displayLanguage = Language::English; +SimpleLock EmulationSettings::_lock; +SimpleLock EmulationSettings::_shortcutLock; +SimpleLock EmulationSettings::_equalizerLock; const vector EmulationSettings::_speedValues = { { 1, 3, 6, 12, 25, 50, 75, 100, 150, 200, 250, 300, 350, 400, 450, 500, 750, 1000, 2000, 4000 } }; -string EmulationSettings::_pauseScreenMessage; - -SimpleLock EmulationSettings::_lock; -uint64_t EmulationSettings::_flags = 0; - -bool EmulationSettings::_audioSettingsChanged = true; -uint32_t EmulationSettings::_audioLatency = 50; -double EmulationSettings::_channelVolume[11] = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }; -double EmulationSettings::_channelPanning[11] = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }; -EqualizerFilterType EmulationSettings::_equalizerFilterType = EqualizerFilterType::None; -vector EmulationSettings::_bandGains = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; -vector EmulationSettings::_bands = { { 40,56,80,113,160,225,320,450,600,750,1000,2000,3000,4000,5000,6000,7000,10000,12500,15000 } }; -double EmulationSettings::_masterVolume = 1.0; -double EmulationSettings::_volumeReduction = 0.75; -uint32_t EmulationSettings::_sampleRate = 44100; -StereoFilter EmulationSettings::_stereoFilter = StereoFilter::None; -int32_t EmulationSettings::_stereoDelay = 0; -double EmulationSettings::_stereoAngle = 0; -double EmulationSettings::_reverbStrength = 0; -double EmulationSettings::_reverbDelay = 0; -uint32_t EmulationSettings::_crossFeedRatio = 0; -SimpleLock EmulationSettings::_equalizerLock; - -NesModel EmulationSettings::_model = NesModel::Auto; -PpuModel EmulationSettings::_ppuModel = PpuModel::Ppu2C02; - -uint32_t EmulationSettings::_emulationSpeed = 100; -uint32_t EmulationSettings::_turboSpeed = 300; -uint32_t EmulationSettings::_rewindSpeed = 100; - -uint32_t EmulationSettings::_rewindBufferSize = 300; - -bool EmulationSettings::_hasOverclock = false; -uint32_t EmulationSettings::_overclockRate = 100; -uint32_t EmulationSettings::_extraScanlinesBeforeNmi = 0; -uint32_t EmulationSettings::_extraScanlinesAfterNmi = 0; -double EmulationSettings::_effectiveOverclockRate = 100; -bool EmulationSettings::_overclockAdjustApu = true; -bool EmulationSettings::_disableOverclocking = false; - -int32_t EmulationSettings::_nsfAutoDetectSilenceDelay = 3000; -int32_t EmulationSettings::_nsfMoveToNextTrackTime = 120; -bool EmulationSettings::_nsfDisableApuIrqs = true; - -uint32_t EmulationSettings::_autoSaveDelay = 5; -bool EmulationSettings::_autoSaveNotify = false; - -bool EmulationSettings::_keyboardModeEnabled = false; - -SimpleLock EmulationSettings::_shortcutLock; -std::unordered_map EmulationSettings::_emulatorKeys[3]; -std::unordered_map> EmulationSettings::_shortcutSupersets[3]; - -RamPowerOnState EmulationSettings::_ramPowerOnState = RamPowerOnState::AllZeros; -uint32_t EmulationSettings::_dipSwitches = 0; - -InputDisplaySettings EmulationSettings::_inputDisplaySettings = { 0, InputDisplayPosition::TopLeft, false }; - -OverscanDimensions EmulationSettings::_overscan; -VideoFilterType EmulationSettings::_videoFilterType = VideoFilterType::None; -VideoResizeFilter EmulationSettings::_resizeFilter = VideoResizeFilter::NearestNeighbor; -double EmulationSettings::_videoScale = 1; -VideoAspectRatio EmulationSettings::_aspectRatio = VideoAspectRatio::NoStretching; -double EmulationSettings::_customAspectRatio = 1.0; -PictureSettings EmulationSettings::_pictureSettings; -NtscFilterSettings EmulationSettings::_ntscFilterSettings; -bool EmulationSettings::_backgroundEnabled = true; -bool EmulationSettings::_spritesEnabled = true; -uint32_t EmulationSettings::_screenRotation = 0; -uint32_t EmulationSettings::_exclusiveRefreshRate = 60; - -ConsoleType EmulationSettings::_consoleType = ConsoleType::Nes; -ExpansionPortDevice EmulationSettings::_expansionDevice = ExpansionPortDevice::None; -ControllerType EmulationSettings::_controllerTypes[4] = { ControllerType::None, ControllerType::None, ControllerType::None, ControllerType::None }; -KeyMappingSet EmulationSettings::_controllerKeys[4] = { KeyMappingSet(), KeyMappingSet(), KeyMappingSet(), KeyMappingSet() }; -bool EmulationSettings::_needControllerUpdate = false; -uint32_t EmulationSettings::_zapperDetectionRadius = 0; -std::unordered_map EmulationSettings::_mouseSensitivity; -int32_t EmulationSettings::_inputPollScanline = 241; - -uint32_t EmulationSettings::_defaultPpuPalette[64] = { /* 2C02 */ 0xFF666666, 0xFF002A88, 0xFF1412A7, 0xFF3B00A4, 0xFF5C007E, 0xFF6E0040, 0xFF6C0600, 0xFF561D00, 0xFF333500, 0xFF0B4800, 0xFF005200, 0xFF004F08, 0xFF00404D, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFADADAD, 0xFF155FD9, 0xFF4240FF, 0xFF7527FE, 0xFFA01ACC, 0xFFB71E7B, 0xFFB53120, 0xFF994E00, 0xFF6B6D00, 0xFF388700, 0xFF0C9300, 0xFF008F32, 0xFF007C8D, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFEFF, 0xFF64B0FF, 0xFF9290FF, 0xFFC676FF, 0xFFF36AFF, 0xFFFE6ECC, 0xFFFE8170, 0xFFEA9E22, 0xFFBCBE00, 0xFF88D800, 0xFF5CE430, 0xFF45E082, 0xFF48CDDE, 0xFF4F4F4F, 0xFF000000, 0xFF000000, 0xFFFFFEFF, 0xFFC0DFFF, 0xFFD3D2FF, 0xFFE8C8FF, 0xFFFBC2FF, 0xFFFEC4EA, 0xFFFECCC5, 0xFFF7D8A5, 0xFFE4E594, 0xFFCFEF96, 0xFFBDF4AB, 0xFFB3F3CC, 0xFFB5EBF2, 0xFFB8B8B8, 0xFF000000, 0xFF000000 }; - -uint32_t EmulationSettings::_currentPalette[64] = { 0xFF666666, 0xFF002A88, 0xFF1412A7, 0xFF3B00A4, 0xFF5C007E, 0xFF6E0040, 0xFF6C0600, 0xFF561D00, 0xFF333500, 0xFF0B4800, 0xFF005200, 0xFF004F08, 0xFF00404D, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFADADAD, 0xFF155FD9, 0xFF4240FF, 0xFF7527FE, 0xFFA01ACC, 0xFFB71E7B, 0xFFB53120, 0xFF994E00, 0xFF6B6D00, 0xFF388700, 0xFF0C9300, 0xFF008F32, 0xFF007C8D, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFEFF, 0xFF64B0FF, 0xFF9290FF, 0xFFC676FF, 0xFFF36AFF, 0xFFFE6ECC, 0xFFFE8170, 0xFFEA9E22, 0xFFBCBE00, 0xFF88D800, 0xFF5CE430, 0xFF45E082, 0xFF48CDDE, 0xFF4F4F4F, 0xFF000000, 0xFF000000, 0xFFFFFEFF, 0xFFC0DFFF, 0xFFD3D2FF, 0xFFE8C8FF, 0xFFFBC2FF, 0xFFFEC4EA, 0xFFFECCC5, 0xFFF7D8A5, 0xFFE4E594, 0xFFCFEF96, 0xFFBDF4AB, 0xFFB3F3CC, 0xFFB5EBF2, 0xFFB8B8B8, 0xFF000000, 0xFF000000 }; - -uint32_t EmulationSettings::_ppuPaletteArgb[11][64] = { - /* 2C02 */ { 0xFF666666, 0xFF002A88, 0xFF1412A7, 0xFF3B00A4, 0xFF5C007E, 0xFF6E0040, 0xFF6C0600, 0xFF561D00, 0xFF333500, 0xFF0B4800, 0xFF005200, 0xFF004F08, 0xFF00404D, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFADADAD, 0xFF155FD9, 0xFF4240FF, 0xFF7527FE, 0xFFA01ACC, 0xFFB71E7B, 0xFFB53120, 0xFF994E00, 0xFF6B6D00, 0xFF388700, 0xFF0C9300, 0xFF008F32, 0xFF007C8D, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFEFF, 0xFF64B0FF, 0xFF9290FF, 0xFFC676FF, 0xFFF36AFF, 0xFFFE6ECC, 0xFFFE8170, 0xFFEA9E22, 0xFFBCBE00, 0xFF88D800, 0xFF5CE430, 0xFF45E082, 0xFF48CDDE, 0xFF4F4F4F, 0xFF000000, 0xFF000000, 0xFFFFFEFF, 0xFFC0DFFF, 0xFFD3D2FF, 0xFFE8C8FF, 0xFFFBC2FF, 0xFFFEC4EA, 0xFFFECCC5, 0xFFF7D8A5, 0xFFE4E594, 0xFFCFEF96, 0xFFBDF4AB, 0xFFB3F3CC, 0xFFB5EBF2, 0xFFB8B8B8, 0xFF000000, 0xFF000000 }, - /* 2C03 */ { 0xFF6D6D6D, 0xFF002491, 0xFF0000DA, 0xFF6D48DA, 0xFF91006D, 0xFFB6006D, 0xFFB62400, 0xFF914800, 0xFF6D4800, 0xFF244800, 0xFF006D24, 0xFF009100, 0xFF004848, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFB6B6B6, 0xFF006DDA, 0xFF0048FF, 0xFF9100FF, 0xFFB600FF, 0xFFFF0091, 0xFFFF0000, 0xFFDA6D00, 0xFF916D00, 0xFF249100, 0xFF009100, 0xFF00B66D, 0xFF009191, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFF6DB6FF, 0xFF9191FF, 0xFFDA6DFF, 0xFFFF00FF, 0xFFFF6DFF, 0xFFFF9100, 0xFFFFB600, 0xFFDADA00, 0xFF6DDA00, 0xFF00FF00, 0xFF48FFDA, 0xFF00FFFF, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFFB6DAFF, 0xFFDAB6FF, 0xFFFFB6FF, 0xFFFF91FF, 0xFFFFB6B6, 0xFFFFDA91, 0xFFFFFF48, 0xFFFFFF6D, 0xFFB6FF48, 0xFF91FF6D, 0xFF48FFDA, 0xFF91DAFF, 0xFF000000, 0xFF000000, 0xFF000000 }, - /* 2C04-0001 */ { 0xFFFFB6B6, 0xFFDA6DFF, 0xFFFF0000, 0xFF9191FF, 0xFF009191, 0xFF244800, 0xFF484848, 0xFFFF0091, 0xFFFFFFFF, 0xFF6D6D6D, 0xFFFFB600, 0xFFB6006D, 0xFF91006D, 0xFFDADA00, 0xFF6D4800, 0xFFFFFFFF, 0xFF6DB6FF, 0xFFDAB66D, 0xFF6D2400, 0xFF6DDA00, 0xFF91DAFF, 0xFFDAB6FF, 0xFFFFDA91, 0xFF0048FF, 0xFFFFDA00, 0xFF48FFDA, 0xFF000000, 0xFF480000, 0xFFDADADA, 0xFF919191, 0xFFFF00FF, 0xFF002491, 0xFF00006D, 0xFFB6DAFF, 0xFFFFB6FF, 0xFF00FF00, 0xFF00FFFF, 0xFF004848, 0xFF00B66D, 0xFFB600FF, 0xFF000000, 0xFF914800, 0xFFFF91FF, 0xFFB62400, 0xFF9100FF, 0xFF0000DA, 0xFFFF9100, 0xFF000000, 0xFF000000, 0xFF249100, 0xFFB6B6B6, 0xFF006D24, 0xFFB6FF48, 0xFF6D48DA, 0xFFFFFF00, 0xFFDA6D00, 0xFF004800, 0xFF006DDA, 0xFF009100, 0xFF242424, 0xFFFFFF6D, 0xFFFF6DFF, 0xFF916D00, 0xFF91FF6D }, - /* 2C04-0002 */ { 0xFF000000, 0xFFFFB600, 0xFF916D00, 0xFFB6FF48, 0xFF91FF6D, 0xFFFF6DFF, 0xFF009191, 0xFFB6DAFF, 0xFFFF0000, 0xFF9100FF, 0xFFFFFF6D, 0xFFFF91FF, 0xFFFFFFFF, 0xFFDA6DFF, 0xFF91DAFF, 0xFF009100, 0xFF004800, 0xFF6DB6FF, 0xFFB62400, 0xFFDADADA, 0xFF00B66D, 0xFF6DDA00, 0xFF480000, 0xFF9191FF, 0xFF484848, 0xFFFF00FF, 0xFF00006D, 0xFF48FFDA, 0xFFDAB6FF, 0xFF6D4800, 0xFF000000, 0xFF6D48DA, 0xFF91006D, 0xFFFFDA91, 0xFFFF9100, 0xFFFFB6FF, 0xFF006DDA, 0xFF6D2400, 0xFFB6B6B6, 0xFF0000DA, 0xFFB600FF, 0xFFFFDA00, 0xFF6D6D6D, 0xFF244800, 0xFF0048FF, 0xFF000000, 0xFFDADA00, 0xFFFFFFFF, 0xFFDAB66D, 0xFF242424, 0xFF00FF00, 0xFFDA6D00, 0xFF004848, 0xFF002491, 0xFFFF0091, 0xFF249100, 0xFF000000, 0xFF00FFFF, 0xFF914800, 0xFFFFFF00, 0xFFFFB6B6, 0xFFB6006D, 0xFF006D24, 0xFF919191 }, - /* 2C04-0003 */ { 0xFFB600FF, 0xFFFF6DFF, 0xFF91FF6D, 0xFFB6B6B6, 0xFF009100, 0xFFFFFFFF, 0xFFB6DAFF, 0xFF244800, 0xFF002491, 0xFF000000, 0xFFFFDA91, 0xFF6D4800, 0xFFFF0091, 0xFFDADADA, 0xFFDAB66D, 0xFF91DAFF, 0xFF9191FF, 0xFF009191, 0xFFB6006D, 0xFF0048FF, 0xFF249100, 0xFF916D00, 0xFFDA6D00, 0xFF00B66D, 0xFF6D6D6D, 0xFF6D48DA, 0xFF000000, 0xFF0000DA, 0xFFFF0000, 0xFFB62400, 0xFFFF91FF, 0xFFFFB6B6, 0xFFDA6DFF, 0xFF004800, 0xFF00006D, 0xFFFFFF00, 0xFF242424, 0xFFFFB600, 0xFFFF9100, 0xFFFFFFFF, 0xFF6DDA00, 0xFF91006D, 0xFF6DB6FF, 0xFFFF00FF, 0xFF006DDA, 0xFF919191, 0xFF000000, 0xFF6D2400, 0xFF00FFFF, 0xFF480000, 0xFFB6FF48, 0xFFFFB6FF, 0xFF914800, 0xFF00FF00, 0xFFDADA00, 0xFF484848, 0xFF006D24, 0xFF000000, 0xFFDAB6FF, 0xFFFFFF6D, 0xFF9100FF, 0xFF48FFDA, 0xFFFFDA00, 0xFF004848 }, - /* 2C04-0004 */ { 0xFF916D00, 0xFF6D48DA, 0xFF009191, 0xFFDADA00, 0xFF000000, 0xFFFFB6B6, 0xFF002491, 0xFFDA6D00, 0xFFB6B6B6, 0xFF6D2400, 0xFF00FF00, 0xFF00006D, 0xFFFFDA91, 0xFFFFFF00, 0xFF009100, 0xFFB6FF48, 0xFFFF6DFF, 0xFF480000, 0xFF0048FF, 0xFFFF91FF, 0xFF000000, 0xFF484848, 0xFFB62400, 0xFFFF9100, 0xFFDAB66D, 0xFF00B66D, 0xFF9191FF, 0xFF249100, 0xFF91006D, 0xFF000000, 0xFF91FF6D, 0xFF6DB6FF, 0xFFB6006D, 0xFF006D24, 0xFF914800, 0xFF0000DA, 0xFF9100FF, 0xFFB600FF, 0xFF6D6D6D, 0xFFFF0091, 0xFF004848, 0xFFDADADA, 0xFF006DDA, 0xFF004800, 0xFF242424, 0xFFFFFF6D, 0xFF919191, 0xFFFF00FF, 0xFFFFB6FF, 0xFFFFFFFF, 0xFF6D4800, 0xFFFF0000, 0xFFFFDA00, 0xFF48FFDA, 0xFFFFFFFF, 0xFF91DAFF, 0xFF000000, 0xFFFFB600, 0xFFDA6DFF, 0xFFB6DAFF, 0xFF6DDA00, 0xFFDAB6FF, 0xFF00FFFF, 0xFF244800 }, - /* 2C05-01 */ { 0xFF6D6D6D, 0xFF002491, 0xFF0000DA, 0xFF6D48DA, 0xFF91006D, 0xFFB6006D, 0xFFB62400, 0xFF914800, 0xFF6D4800, 0xFF244800, 0xFF006D24, 0xFF009100, 0xFF004848, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFB6B6B6, 0xFF006DDA, 0xFF0048FF, 0xFF9100FF, 0xFFB600FF, 0xFFFF0091, 0xFFFF0000, 0xFFDA6D00, 0xFF916D00, 0xFF249100, 0xFF009100, 0xFF00B66D, 0xFF009191, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFF6DB6FF, 0xFF9191FF, 0xFFDA6DFF, 0xFFFF00FF, 0xFFFF6DFF, 0xFFFF9100, 0xFFFFB600, 0xFFDADA00, 0xFF6DDA00, 0xFF00FF00, 0xFF48FFDA, 0xFF00FFFF, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFFB6DAFF, 0xFFDAB6FF, 0xFFFFB6FF, 0xFFFF91FF, 0xFFFFB6B6, 0xFFFFDA91, 0xFFFFFF48, 0xFFFFFF6D, 0xFFB6FF48, 0xFF91FF6D, 0xFF48FFDA, 0xFF91DAFF, 0xFF000000, 0xFF000000, 0xFF000000 }, - /* 2C05-02 */ { 0xFF6D6D6D, 0xFF002491, 0xFF0000DA, 0xFF6D48DA, 0xFF91006D, 0xFFB6006D, 0xFFB62400, 0xFF914800, 0xFF6D4800, 0xFF244800, 0xFF006D24, 0xFF009100, 0xFF004848, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFB6B6B6, 0xFF006DDA, 0xFF0048FF, 0xFF9100FF, 0xFFB600FF, 0xFFFF0091, 0xFFFF0000, 0xFFDA6D00, 0xFF916D00, 0xFF249100, 0xFF009100, 0xFF00B66D, 0xFF009191, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFF6DB6FF, 0xFF9191FF, 0xFFDA6DFF, 0xFFFF00FF, 0xFFFF6DFF, 0xFFFF9100, 0xFFFFB600, 0xFFDADA00, 0xFF6DDA00, 0xFF00FF00, 0xFF48FFDA, 0xFF00FFFF, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFFB6DAFF, 0xFFDAB6FF, 0xFFFFB6FF, 0xFFFF91FF, 0xFFFFB6B6, 0xFFFFDA91, 0xFFFFFF48, 0xFFFFFF6D, 0xFFB6FF48, 0xFF91FF6D, 0xFF48FFDA, 0xFF91DAFF, 0xFF000000, 0xFF000000, 0xFF000000 }, - /* 2C05-03 */ { 0xFF6D6D6D, 0xFF002491, 0xFF0000DA, 0xFF6D48DA, 0xFF91006D, 0xFFB6006D, 0xFFB62400, 0xFF914800, 0xFF6D4800, 0xFF244800, 0xFF006D24, 0xFF009100, 0xFF004848, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFB6B6B6, 0xFF006DDA, 0xFF0048FF, 0xFF9100FF, 0xFFB600FF, 0xFFFF0091, 0xFFFF0000, 0xFFDA6D00, 0xFF916D00, 0xFF249100, 0xFF009100, 0xFF00B66D, 0xFF009191, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFF6DB6FF, 0xFF9191FF, 0xFFDA6DFF, 0xFFFF00FF, 0xFFFF6DFF, 0xFFFF9100, 0xFFFFB600, 0xFFDADA00, 0xFF6DDA00, 0xFF00FF00, 0xFF48FFDA, 0xFF00FFFF, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFFB6DAFF, 0xFFDAB6FF, 0xFFFFB6FF, 0xFFFF91FF, 0xFFFFB6B6, 0xFFFFDA91, 0xFFFFFF48, 0xFFFFFF6D, 0xFFB6FF48, 0xFF91FF6D, 0xFF48FFDA, 0xFF91DAFF, 0xFF000000, 0xFF000000, 0xFF000000 }, - /* 2C05-04 */ { 0xFF6D6D6D, 0xFF002491, 0xFF0000DA, 0xFF6D48DA, 0xFF91006D, 0xFFB6006D, 0xFFB62400, 0xFF914800, 0xFF6D4800, 0xFF244800, 0xFF006D24, 0xFF009100, 0xFF004848, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFB6B6B6, 0xFF006DDA, 0xFF0048FF, 0xFF9100FF, 0xFFB600FF, 0xFFFF0091, 0xFFFF0000, 0xFFDA6D00, 0xFF916D00, 0xFF249100, 0xFF009100, 0xFF00B66D, 0xFF009191, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFF6DB6FF, 0xFF9191FF, 0xFFDA6DFF, 0xFFFF00FF, 0xFFFF6DFF, 0xFFFF9100, 0xFFFFB600, 0xFFDADA00, 0xFF6DDA00, 0xFF00FF00, 0xFF48FFDA, 0xFF00FFFF, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFFB6DAFF, 0xFFDAB6FF, 0xFFFFB6FF, 0xFFFF91FF, 0xFFFFB6B6, 0xFFFFDA91, 0xFFFFFF48, 0xFFFFFF6D, 0xFFB6FF48, 0xFF91FF6D, 0xFF48FFDA, 0xFF91DAFF, 0xFF000000, 0xFF000000, 0xFF000000 }, - /* 2C05-05 */ { 0xFF6D6D6D, 0xFF002491, 0xFF0000DA, 0xFF6D48DA, 0xFF91006D, 0xFFB6006D, 0xFFB62400, 0xFF914800, 0xFF6D4800, 0xFF244800, 0xFF006D24, 0xFF009100, 0xFF004848, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFB6B6B6, 0xFF006DDA, 0xFF0048FF, 0xFF9100FF, 0xFFB600FF, 0xFFFF0091, 0xFFFF0000, 0xFFDA6D00, 0xFF916D00, 0xFF249100, 0xFF009100, 0xFF00B66D, 0xFF009191, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFF6DB6FF, 0xFF9191FF, 0xFFDA6DFF, 0xFFFF00FF, 0xFFFF6DFF, 0xFFFF9100, 0xFFFFB600, 0xFFDADA00, 0xFF6DDA00, 0xFF00FF00, 0xFF48FFDA, 0xFF00FFFF, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFFB6DAFF, 0xFFDAB6FF, 0xFFFFB6FF, 0xFFFF91FF, 0xFFFFB6B6, 0xFFFFDA91, 0xFFFFFF48, 0xFFFFFF6D, 0xFFB6FF48, 0xFF91FF6D, 0xFF48FFDA, 0xFF91DAFF, 0xFF000000, 0xFF000000, 0xFF000000 } -}; - -uint8_t EmulationSettings::_paletteLut[11][64] = { - /* 2C02 */ { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63 }, - /* 2C03 */ { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,15,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,15,62,63 }, - /* 2C04-0001 */ { 53,35,22,34,28,9,29,21,32,0,39,5,4,40,8,32,33,62,31,41,60,50,54,18,63,43,46,30,61,45,36,1,14,49,51,42,44,12,27,20,46,7,52,6,19,2,38,46,46,25,16,10,57,3,55,23,15,17,11,13,56,37,24,58 }, - /* 2C04-0002 */ { 46,39,24,57,58,37,28,49,22,19,56,52,32,35,60,11,15,33,6,61,27,41,30,34,29,36,14,43,50,8,46,3,4,54,38,51,17,31,16,2,20,63,0,9,18,46,40,32,62,13,42,23,12,1,21,25,46,44,7,55,53,5,10,45 }, - /* 2C04-0003 */ { 20,37,58,16,11,32,49,9,1,46,54,8,21,61,62,60,34,28,5,18,25,24,23,27,0,3,46,2,22,6,52,53,35,15,14,55,13,39,38,32,41,4,33,36,17,45,46,31,44,30,57,51,7,42,40,29,10,46,50,56,19,43,63,12 }, - /* 2C04-0004 */ { 24,3,28,40,46,53,1,23,16,31,42,14,54,55,11,57,37,30,18,52,46,29,6,38,62,27,34,25,4,46,58,33,5,10,7,2,19,20,0,21,12,61,17,15,13,56,45,36,51,32,8,22,63,43,32,60,46,39,35,49,41,50,44,9 }, - /* 2C05-01 */ { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,15,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,15,62,63 }, - /* 2C05-02 */ { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,15,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,15,62,63 }, - /* 2C05-03 */ { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,15,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,15,62,63 }, - /* 2C05-04 */ { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,15,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,15,62,63 }, - /* 2C05-05 */ { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,15,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,15,62,63 }, -}; +Language EmulationSettings::_displayLanguage = Language::English; uint32_t EmulationSettings::GetEmulationSpeed(bool ignoreTurbo) { @@ -162,6 +54,120 @@ double EmulationSettings::GetAspectRatio(shared_ptr console) return 0.0; } +void EmulationSettings::InitializeInputDevices(GameInputType inputType, GameSystem system, bool silent) +{ + ControllerType controllers[4] = { ControllerType::StandardController, ControllerType::StandardController, ControllerType::None, ControllerType::None }; + ExpansionPortDevice expDevice = ExpansionPortDevice::None; + ClearFlags(EmulationFlags::HasFourScore); + + auto log = [silent](string text) { + if(!silent) { + MessageManager::Log(text); + } + }; + + bool isFamicom = (system == GameSystem::Famicom || system == GameSystem::FDS || system == GameSystem::Dendy); + + if(inputType == GameInputType::VsZapper) { + //VS Duck Hunt, etc. need the zapper in the first port + log("[Input] VS Zapper connected"); + controllers[0] = ControllerType::Zapper; + } else if(inputType == GameInputType::Zapper) { + log("[Input] Zapper connected"); + if(isFamicom) { + expDevice = ExpansionPortDevice::Zapper; + } else { + controllers[1] = ControllerType::Zapper; + } + } else if(inputType == GameInputType::FourScore) { + log("[Input] Four score connected"); + SetFlags(EmulationFlags::HasFourScore); + controllers[2] = controllers[3] = ControllerType::StandardController; + } else if(inputType == GameInputType::FourPlayerAdapter) { + log("[Input] Four player adapter connected"); + SetFlags(EmulationFlags::HasFourScore); + expDevice = ExpansionPortDevice::FourPlayerAdapter; + controllers[2] = controllers[3] = ControllerType::StandardController; + } else if(inputType == GameInputType::ArkanoidControllerFamicom) { + log("[Input] Arkanoid controller (Famicom) connected"); + expDevice = ExpansionPortDevice::ArkanoidController; + } else if(inputType == GameInputType::ArkanoidControllerNes) { + log("[Input] Arkanoid controller (NES) connected"); + controllers[1] = ControllerType::ArkanoidController; + } else if(inputType == GameInputType::OekaKidsTablet) { + log("[Input] Oeka Kids Tablet connected"); + system = GameSystem::Famicom; + expDevice = ExpansionPortDevice::OekaKidsTablet; + } else if(inputType == GameInputType::KonamiHyperShot) { + log("[Input] Konami Hyper Shot connected"); + system = GameSystem::Famicom; + expDevice = ExpansionPortDevice::KonamiHyperShot; + } else if(inputType == GameInputType::FamilyBasicKeyboard) { + log("[Input] Family Basic Keyboard connected"); + system = GameSystem::Famicom; + expDevice = ExpansionPortDevice::FamilyBasicKeyboard; + } else if(inputType == GameInputType::PartyTap) { + log("[Input] Party Tap connected"); + system = GameSystem::Famicom; + expDevice = ExpansionPortDevice::PartyTap; + } else if(inputType == GameInputType::PachinkoController) { + log("[Input] Pachinko controller connected"); + system = GameSystem::Famicom; + expDevice = ExpansionPortDevice::Pachinko; + } else if(inputType == GameInputType::ExcitingBoxing) { + log("[Input] Exciting Boxing controller connected"); + system = GameSystem::Famicom; + expDevice = ExpansionPortDevice::ExcitingBoxing; + } else if(inputType == GameInputType::SuborKeyboardMouse1) { + log("[Input] Subor mouse connected"); + log("[Input] Subor keyboard connected"); + system = GameSystem::Famicom; + expDevice = ExpansionPortDevice::SuborKeyboard; + controllers[1] = ControllerType::SuborMouse; + } else if(inputType == GameInputType::JissenMahjong) { + log("[Input] Jissen Mahjong controller connected"); + system = GameSystem::Famicom; + expDevice = ExpansionPortDevice::JissenMahjong; + } else if(inputType == GameInputType::BarcodeBattler) { + log("[Input] Barcode Battler barcode reader connected"); + system = GameSystem::Famicom; + expDevice = ExpansionPortDevice::BarcodeBattler; + } else if(inputType == GameInputType::BandaiHypershot) { + log("[Input] Bandai Hyper Shot gun connected"); + system = GameSystem::Famicom; + expDevice = ExpansionPortDevice::BandaiHyperShot; + } else if(inputType == GameInputType::BattleBox) { + log("[Input] Battle Box connected"); + system = GameSystem::Famicom; + expDevice = ExpansionPortDevice::BattleBox; + } else if(inputType == GameInputType::TurboFile) { + log("[Input] Ascii Turbo File connected"); + system = GameSystem::Famicom; + expDevice = ExpansionPortDevice::AsciiTurboFile; + } else if(inputType == GameInputType::FamilyTrainerSideA || inputType == GameInputType::FamilyTrainerSideB) { + log("[Input] Family Trainer mat connected"); + system = GameSystem::Famicom; + expDevice = ExpansionPortDevice::FamilyTrainerMat; + } else if(inputType == GameInputType::PowerPadSideA || inputType == GameInputType::PowerPadSideB) { + log("[Input] Power Pad connected"); + system = GameSystem::NesNtsc; + controllers[1] = ControllerType::PowerPad; + } else if(inputType == GameInputType::SnesControllers) { + log("[Input] 2 SNES controllers connected"); + controllers[0] = ControllerType::SnesController; + controllers[1] = ControllerType::SnesController; + } else { + log("[Input] 2 standard controllers connected"); + } + + isFamicom = (system == GameSystem::Famicom || system == GameSystem::FDS || system == GameSystem::Dendy); + SetConsoleType(isFamicom ? ConsoleType::Famicom : ConsoleType::Nes); + for(int i = 0; i < 4; i++) { + SetControllerType(i, controllers[i]); + } + SetExpansionDevice(expDevice); +} + const vector NesModelNames = { "Auto", "NTSC", diff --git a/Core/EmulationSettings.h b/Core/EmulationSettings.h index d7919f33..419953ce 100644 --- a/Core/EmulationSettings.h +++ b/Core/EmulationSettings.h @@ -31,7 +31,6 @@ enum EmulationFlags : uint64_t SwapDutyCycles = 0x10000, - DisableGameDatabase = 0x20000, AutoConfigureInput = 0x40000, ShowLagCounter = 0x80000, @@ -68,7 +67,6 @@ enum EmulationFlags : uint64_t AdaptiveSpriteLimit = 0x80000000000, - DisableOsd = 0x100000000000, DisableGameSelectionScreen = 0x200000000000, ConfirmExitResetPower = 0x400000000000, @@ -562,101 +560,125 @@ struct InputDisplaySettings class EmulationSettings { private: + static const vector _speedValues; + static uint16_t _versionMajor; static uint8_t _versionMinor; static uint8_t _versionRevision; - - static const vector _speedValues; - - static uint32_t _ppuPaletteArgb[11][64]; - static uint32_t _defaultPpuPalette[64]; - static uint32_t _currentPalette[64]; - static uint8_t _paletteLut[11][64]; - - static string _pauseScreenMessage; - - static uint64_t _flags; - static Language _displayLanguage; - static bool _audioSettingsChanged; - static uint32_t _audioLatency; - static double _channelVolume[11]; - static double _channelPanning[11]; - static EqualizerFilterType _equalizerFilterType; - static vector _bandGains; - static vector _bands; - static double _masterVolume; - static double _volumeReduction; - static uint32_t _sampleRate; - static StereoFilter _stereoFilter; - static int32_t _stereoDelay; - static double _stereoAngle; - static double _reverbStrength; - static double _reverbDelay; - static uint32_t _crossFeedRatio; - - static NesModel _model; - static PpuModel _ppuModel; - - static uint32_t _emulationSpeed; - static uint32_t _turboSpeed; - static uint32_t _rewindSpeed; - - static uint32_t _rewindBufferSize; - - static bool _hasOverclock; - static uint32_t _overclockRate; - static bool _overclockAdjustApu; - static bool _disableOverclocking; - static uint32_t _extraScanlinesBeforeNmi; - static uint32_t _extraScanlinesAfterNmi; - static double _effectiveOverclockRate; - static double _effectiveOverclockRateSound; - - static OverscanDimensions _overscan; - static VideoFilterType _videoFilterType; - static double _videoScale; - static VideoAspectRatio _aspectRatio; - static double _customAspectRatio; - static VideoResizeFilter _resizeFilter; - static PictureSettings _pictureSettings; - static NtscFilterSettings _ntscFilterSettings; - static bool _backgroundEnabled; - static bool _spritesEnabled; - static uint32_t _screenRotation; - static uint32_t _exclusiveRefreshRate; - - static ConsoleType _consoleType; - static ExpansionPortDevice _expansionDevice; - static ControllerType _controllerTypes[4]; - static KeyMappingSet _controllerKeys[4]; - static bool _needControllerUpdate; - static uint32_t _zapperDetectionRadius; - static std::unordered_map _mouseSensitivity; - static int32_t _inputPollScanline; - - static int32_t _nsfAutoDetectSilenceDelay; - static int32_t _nsfMoveToNextTrackTime; - static bool _nsfDisableApuIrqs; - - static InputDisplaySettings _inputDisplaySettings; - - static uint32_t _autoSaveDelay; - static bool _autoSaveNotify; - - static bool _keyboardModeEnabled; - - static std::unordered_map _emulatorKeys[3]; - static std::unordered_map> _shortcutSupersets[3]; - - static RamPowerOnState _ramPowerOnState; - static uint32_t _dipSwitches; - static SimpleLock _shortcutLock; static SimpleLock _equalizerLock; static SimpleLock _lock; + uint32_t _ppuPaletteArgb[11][64] = { + /* 2C02 */ { 0xFF666666, 0xFF002A88, 0xFF1412A7, 0xFF3B00A4, 0xFF5C007E, 0xFF6E0040, 0xFF6C0600, 0xFF561D00, 0xFF333500, 0xFF0B4800, 0xFF005200, 0xFF004F08, 0xFF00404D, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFADADAD, 0xFF155FD9, 0xFF4240FF, 0xFF7527FE, 0xFFA01ACC, 0xFFB71E7B, 0xFFB53120, 0xFF994E00, 0xFF6B6D00, 0xFF388700, 0xFF0C9300, 0xFF008F32, 0xFF007C8D, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFEFF, 0xFF64B0FF, 0xFF9290FF, 0xFFC676FF, 0xFFF36AFF, 0xFFFE6ECC, 0xFFFE8170, 0xFFEA9E22, 0xFFBCBE00, 0xFF88D800, 0xFF5CE430, 0xFF45E082, 0xFF48CDDE, 0xFF4F4F4F, 0xFF000000, 0xFF000000, 0xFFFFFEFF, 0xFFC0DFFF, 0xFFD3D2FF, 0xFFE8C8FF, 0xFFFBC2FF, 0xFFFEC4EA, 0xFFFECCC5, 0xFFF7D8A5, 0xFFE4E594, 0xFFCFEF96, 0xFFBDF4AB, 0xFFB3F3CC, 0xFFB5EBF2, 0xFFB8B8B8, 0xFF000000, 0xFF000000 }, + /* 2C03 */ { 0xFF6D6D6D, 0xFF002491, 0xFF0000DA, 0xFF6D48DA, 0xFF91006D, 0xFFB6006D, 0xFFB62400, 0xFF914800, 0xFF6D4800, 0xFF244800, 0xFF006D24, 0xFF009100, 0xFF004848, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFB6B6B6, 0xFF006DDA, 0xFF0048FF, 0xFF9100FF, 0xFFB600FF, 0xFFFF0091, 0xFFFF0000, 0xFFDA6D00, 0xFF916D00, 0xFF249100, 0xFF009100, 0xFF00B66D, 0xFF009191, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFF6DB6FF, 0xFF9191FF, 0xFFDA6DFF, 0xFFFF00FF, 0xFFFF6DFF, 0xFFFF9100, 0xFFFFB600, 0xFFDADA00, 0xFF6DDA00, 0xFF00FF00, 0xFF48FFDA, 0xFF00FFFF, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFFB6DAFF, 0xFFDAB6FF, 0xFFFFB6FF, 0xFFFF91FF, 0xFFFFB6B6, 0xFFFFDA91, 0xFFFFFF48, 0xFFFFFF6D, 0xFFB6FF48, 0xFF91FF6D, 0xFF48FFDA, 0xFF91DAFF, 0xFF000000, 0xFF000000, 0xFF000000 }, + /* 2C04-0001 */ { 0xFFFFB6B6, 0xFFDA6DFF, 0xFFFF0000, 0xFF9191FF, 0xFF009191, 0xFF244800, 0xFF484848, 0xFFFF0091, 0xFFFFFFFF, 0xFF6D6D6D, 0xFFFFB600, 0xFFB6006D, 0xFF91006D, 0xFFDADA00, 0xFF6D4800, 0xFFFFFFFF, 0xFF6DB6FF, 0xFFDAB66D, 0xFF6D2400, 0xFF6DDA00, 0xFF91DAFF, 0xFFDAB6FF, 0xFFFFDA91, 0xFF0048FF, 0xFFFFDA00, 0xFF48FFDA, 0xFF000000, 0xFF480000, 0xFFDADADA, 0xFF919191, 0xFFFF00FF, 0xFF002491, 0xFF00006D, 0xFFB6DAFF, 0xFFFFB6FF, 0xFF00FF00, 0xFF00FFFF, 0xFF004848, 0xFF00B66D, 0xFFB600FF, 0xFF000000, 0xFF914800, 0xFFFF91FF, 0xFFB62400, 0xFF9100FF, 0xFF0000DA, 0xFFFF9100, 0xFF000000, 0xFF000000, 0xFF249100, 0xFFB6B6B6, 0xFF006D24, 0xFFB6FF48, 0xFF6D48DA, 0xFFFFFF00, 0xFFDA6D00, 0xFF004800, 0xFF006DDA, 0xFF009100, 0xFF242424, 0xFFFFFF6D, 0xFFFF6DFF, 0xFF916D00, 0xFF91FF6D }, + /* 2C04-0002 */ { 0xFF000000, 0xFFFFB600, 0xFF916D00, 0xFFB6FF48, 0xFF91FF6D, 0xFFFF6DFF, 0xFF009191, 0xFFB6DAFF, 0xFFFF0000, 0xFF9100FF, 0xFFFFFF6D, 0xFFFF91FF, 0xFFFFFFFF, 0xFFDA6DFF, 0xFF91DAFF, 0xFF009100, 0xFF004800, 0xFF6DB6FF, 0xFFB62400, 0xFFDADADA, 0xFF00B66D, 0xFF6DDA00, 0xFF480000, 0xFF9191FF, 0xFF484848, 0xFFFF00FF, 0xFF00006D, 0xFF48FFDA, 0xFFDAB6FF, 0xFF6D4800, 0xFF000000, 0xFF6D48DA, 0xFF91006D, 0xFFFFDA91, 0xFFFF9100, 0xFFFFB6FF, 0xFF006DDA, 0xFF6D2400, 0xFFB6B6B6, 0xFF0000DA, 0xFFB600FF, 0xFFFFDA00, 0xFF6D6D6D, 0xFF244800, 0xFF0048FF, 0xFF000000, 0xFFDADA00, 0xFFFFFFFF, 0xFFDAB66D, 0xFF242424, 0xFF00FF00, 0xFFDA6D00, 0xFF004848, 0xFF002491, 0xFFFF0091, 0xFF249100, 0xFF000000, 0xFF00FFFF, 0xFF914800, 0xFFFFFF00, 0xFFFFB6B6, 0xFFB6006D, 0xFF006D24, 0xFF919191 }, + /* 2C04-0003 */ { 0xFFB600FF, 0xFFFF6DFF, 0xFF91FF6D, 0xFFB6B6B6, 0xFF009100, 0xFFFFFFFF, 0xFFB6DAFF, 0xFF244800, 0xFF002491, 0xFF000000, 0xFFFFDA91, 0xFF6D4800, 0xFFFF0091, 0xFFDADADA, 0xFFDAB66D, 0xFF91DAFF, 0xFF9191FF, 0xFF009191, 0xFFB6006D, 0xFF0048FF, 0xFF249100, 0xFF916D00, 0xFFDA6D00, 0xFF00B66D, 0xFF6D6D6D, 0xFF6D48DA, 0xFF000000, 0xFF0000DA, 0xFFFF0000, 0xFFB62400, 0xFFFF91FF, 0xFFFFB6B6, 0xFFDA6DFF, 0xFF004800, 0xFF00006D, 0xFFFFFF00, 0xFF242424, 0xFFFFB600, 0xFFFF9100, 0xFFFFFFFF, 0xFF6DDA00, 0xFF91006D, 0xFF6DB6FF, 0xFFFF00FF, 0xFF006DDA, 0xFF919191, 0xFF000000, 0xFF6D2400, 0xFF00FFFF, 0xFF480000, 0xFFB6FF48, 0xFFFFB6FF, 0xFF914800, 0xFF00FF00, 0xFFDADA00, 0xFF484848, 0xFF006D24, 0xFF000000, 0xFFDAB6FF, 0xFFFFFF6D, 0xFF9100FF, 0xFF48FFDA, 0xFFFFDA00, 0xFF004848 }, + /* 2C04-0004 */ { 0xFF916D00, 0xFF6D48DA, 0xFF009191, 0xFFDADA00, 0xFF000000, 0xFFFFB6B6, 0xFF002491, 0xFFDA6D00, 0xFFB6B6B6, 0xFF6D2400, 0xFF00FF00, 0xFF00006D, 0xFFFFDA91, 0xFFFFFF00, 0xFF009100, 0xFFB6FF48, 0xFFFF6DFF, 0xFF480000, 0xFF0048FF, 0xFFFF91FF, 0xFF000000, 0xFF484848, 0xFFB62400, 0xFFFF9100, 0xFFDAB66D, 0xFF00B66D, 0xFF9191FF, 0xFF249100, 0xFF91006D, 0xFF000000, 0xFF91FF6D, 0xFF6DB6FF, 0xFFB6006D, 0xFF006D24, 0xFF914800, 0xFF0000DA, 0xFF9100FF, 0xFFB600FF, 0xFF6D6D6D, 0xFFFF0091, 0xFF004848, 0xFFDADADA, 0xFF006DDA, 0xFF004800, 0xFF242424, 0xFFFFFF6D, 0xFF919191, 0xFFFF00FF, 0xFFFFB6FF, 0xFFFFFFFF, 0xFF6D4800, 0xFFFF0000, 0xFFFFDA00, 0xFF48FFDA, 0xFFFFFFFF, 0xFF91DAFF, 0xFF000000, 0xFFFFB600, 0xFFDA6DFF, 0xFFB6DAFF, 0xFF6DDA00, 0xFFDAB6FF, 0xFF00FFFF, 0xFF244800 }, + /* 2C05-01 */ { 0xFF6D6D6D, 0xFF002491, 0xFF0000DA, 0xFF6D48DA, 0xFF91006D, 0xFFB6006D, 0xFFB62400, 0xFF914800, 0xFF6D4800, 0xFF244800, 0xFF006D24, 0xFF009100, 0xFF004848, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFB6B6B6, 0xFF006DDA, 0xFF0048FF, 0xFF9100FF, 0xFFB600FF, 0xFFFF0091, 0xFFFF0000, 0xFFDA6D00, 0xFF916D00, 0xFF249100, 0xFF009100, 0xFF00B66D, 0xFF009191, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFF6DB6FF, 0xFF9191FF, 0xFFDA6DFF, 0xFFFF00FF, 0xFFFF6DFF, 0xFFFF9100, 0xFFFFB600, 0xFFDADA00, 0xFF6DDA00, 0xFF00FF00, 0xFF48FFDA, 0xFF00FFFF, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFFB6DAFF, 0xFFDAB6FF, 0xFFFFB6FF, 0xFFFF91FF, 0xFFFFB6B6, 0xFFFFDA91, 0xFFFFFF48, 0xFFFFFF6D, 0xFFB6FF48, 0xFF91FF6D, 0xFF48FFDA, 0xFF91DAFF, 0xFF000000, 0xFF000000, 0xFF000000 }, + /* 2C05-02 */ { 0xFF6D6D6D, 0xFF002491, 0xFF0000DA, 0xFF6D48DA, 0xFF91006D, 0xFFB6006D, 0xFFB62400, 0xFF914800, 0xFF6D4800, 0xFF244800, 0xFF006D24, 0xFF009100, 0xFF004848, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFB6B6B6, 0xFF006DDA, 0xFF0048FF, 0xFF9100FF, 0xFFB600FF, 0xFFFF0091, 0xFFFF0000, 0xFFDA6D00, 0xFF916D00, 0xFF249100, 0xFF009100, 0xFF00B66D, 0xFF009191, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFF6DB6FF, 0xFF9191FF, 0xFFDA6DFF, 0xFFFF00FF, 0xFFFF6DFF, 0xFFFF9100, 0xFFFFB600, 0xFFDADA00, 0xFF6DDA00, 0xFF00FF00, 0xFF48FFDA, 0xFF00FFFF, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFFB6DAFF, 0xFFDAB6FF, 0xFFFFB6FF, 0xFFFF91FF, 0xFFFFB6B6, 0xFFFFDA91, 0xFFFFFF48, 0xFFFFFF6D, 0xFFB6FF48, 0xFF91FF6D, 0xFF48FFDA, 0xFF91DAFF, 0xFF000000, 0xFF000000, 0xFF000000 }, + /* 2C05-03 */ { 0xFF6D6D6D, 0xFF002491, 0xFF0000DA, 0xFF6D48DA, 0xFF91006D, 0xFFB6006D, 0xFFB62400, 0xFF914800, 0xFF6D4800, 0xFF244800, 0xFF006D24, 0xFF009100, 0xFF004848, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFB6B6B6, 0xFF006DDA, 0xFF0048FF, 0xFF9100FF, 0xFFB600FF, 0xFFFF0091, 0xFFFF0000, 0xFFDA6D00, 0xFF916D00, 0xFF249100, 0xFF009100, 0xFF00B66D, 0xFF009191, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFF6DB6FF, 0xFF9191FF, 0xFFDA6DFF, 0xFFFF00FF, 0xFFFF6DFF, 0xFFFF9100, 0xFFFFB600, 0xFFDADA00, 0xFF6DDA00, 0xFF00FF00, 0xFF48FFDA, 0xFF00FFFF, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFFB6DAFF, 0xFFDAB6FF, 0xFFFFB6FF, 0xFFFF91FF, 0xFFFFB6B6, 0xFFFFDA91, 0xFFFFFF48, 0xFFFFFF6D, 0xFFB6FF48, 0xFF91FF6D, 0xFF48FFDA, 0xFF91DAFF, 0xFF000000, 0xFF000000, 0xFF000000 }, + /* 2C05-04 */ { 0xFF6D6D6D, 0xFF002491, 0xFF0000DA, 0xFF6D48DA, 0xFF91006D, 0xFFB6006D, 0xFFB62400, 0xFF914800, 0xFF6D4800, 0xFF244800, 0xFF006D24, 0xFF009100, 0xFF004848, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFB6B6B6, 0xFF006DDA, 0xFF0048FF, 0xFF9100FF, 0xFFB600FF, 0xFFFF0091, 0xFFFF0000, 0xFFDA6D00, 0xFF916D00, 0xFF249100, 0xFF009100, 0xFF00B66D, 0xFF009191, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFF6DB6FF, 0xFF9191FF, 0xFFDA6DFF, 0xFFFF00FF, 0xFFFF6DFF, 0xFFFF9100, 0xFFFFB600, 0xFFDADA00, 0xFF6DDA00, 0xFF00FF00, 0xFF48FFDA, 0xFF00FFFF, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFFB6DAFF, 0xFFDAB6FF, 0xFFFFB6FF, 0xFFFF91FF, 0xFFFFB6B6, 0xFFFFDA91, 0xFFFFFF48, 0xFFFFFF6D, 0xFFB6FF48, 0xFF91FF6D, 0xFF48FFDA, 0xFF91DAFF, 0xFF000000, 0xFF000000, 0xFF000000 }, + /* 2C05-05 */ { 0xFF6D6D6D, 0xFF002491, 0xFF0000DA, 0xFF6D48DA, 0xFF91006D, 0xFFB6006D, 0xFFB62400, 0xFF914800, 0xFF6D4800, 0xFF244800, 0xFF006D24, 0xFF009100, 0xFF004848, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFB6B6B6, 0xFF006DDA, 0xFF0048FF, 0xFF9100FF, 0xFFB600FF, 0xFFFF0091, 0xFFFF0000, 0xFFDA6D00, 0xFF916D00, 0xFF249100, 0xFF009100, 0xFF00B66D, 0xFF009191, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFF6DB6FF, 0xFF9191FF, 0xFFDA6DFF, 0xFFFF00FF, 0xFFFF6DFF, 0xFFFF9100, 0xFFFFB600, 0xFFDADA00, 0xFF6DDA00, 0xFF00FF00, 0xFF48FFDA, 0xFF00FFFF, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFFB6DAFF, 0xFFDAB6FF, 0xFFFFB6FF, 0xFFFF91FF, 0xFFFFB6B6, 0xFFFFDA91, 0xFFFFFF48, 0xFFFFFF6D, 0xFFB6FF48, 0xFF91FF6D, 0xFF48FFDA, 0xFF91DAFF, 0xFF000000, 0xFF000000, 0xFF000000 } + }; + + uint32_t _defaultPpuPalette[64] = { /* 2C02 */ 0xFF666666, 0xFF002A88, 0xFF1412A7, 0xFF3B00A4, 0xFF5C007E, 0xFF6E0040, 0xFF6C0600, 0xFF561D00, 0xFF333500, 0xFF0B4800, 0xFF005200, 0xFF004F08, 0xFF00404D, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFADADAD, 0xFF155FD9, 0xFF4240FF, 0xFF7527FE, 0xFFA01ACC, 0xFFB71E7B, 0xFFB53120, 0xFF994E00, 0xFF6B6D00, 0xFF388700, 0xFF0C9300, 0xFF008F32, 0xFF007C8D, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFEFF, 0xFF64B0FF, 0xFF9290FF, 0xFFC676FF, 0xFFF36AFF, 0xFFFE6ECC, 0xFFFE8170, 0xFFEA9E22, 0xFFBCBE00, 0xFF88D800, 0xFF5CE430, 0xFF45E082, 0xFF48CDDE, 0xFF4F4F4F, 0xFF000000, 0xFF000000, 0xFFFFFEFF, 0xFFC0DFFF, 0xFFD3D2FF, 0xFFE8C8FF, 0xFFFBC2FF, 0xFFFEC4EA, 0xFFFECCC5, 0xFFF7D8A5, 0xFFE4E594, 0xFFCFEF96, 0xFFBDF4AB, 0xFFB3F3CC, 0xFFB5EBF2, 0xFFB8B8B8, 0xFF000000, 0xFF000000 }; + uint32_t _currentPalette[64] = { 0xFF666666, 0xFF002A88, 0xFF1412A7, 0xFF3B00A4, 0xFF5C007E, 0xFF6E0040, 0xFF6C0600, 0xFF561D00, 0xFF333500, 0xFF0B4800, 0xFF005200, 0xFF004F08, 0xFF00404D, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFADADAD, 0xFF155FD9, 0xFF4240FF, 0xFF7527FE, 0xFFA01ACC, 0xFFB71E7B, 0xFFB53120, 0xFF994E00, 0xFF6B6D00, 0xFF388700, 0xFF0C9300, 0xFF008F32, 0xFF007C8D, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFEFF, 0xFF64B0FF, 0xFF9290FF, 0xFFC676FF, 0xFFF36AFF, 0xFFFE6ECC, 0xFFFE8170, 0xFFEA9E22, 0xFFBCBE00, 0xFF88D800, 0xFF5CE430, 0xFF45E082, 0xFF48CDDE, 0xFF4F4F4F, 0xFF000000, 0xFF000000, 0xFFFFFEFF, 0xFFC0DFFF, 0xFFD3D2FF, 0xFFE8C8FF, 0xFFFBC2FF, 0xFFFEC4EA, 0xFFFECCC5, 0xFFF7D8A5, 0xFFE4E594, 0xFFCFEF96, 0xFFBDF4AB, 0xFFB3F3CC, 0xFFB5EBF2, 0xFFB8B8B8, 0xFF000000, 0xFF000000 }; + + static constexpr uint8_t _paletteLut[11][64] = { + /* 2C02 */ { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63 }, + /* 2C03 */ { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,15,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,15,62,63 }, + /* 2C04-0001 */ { 53,35,22,34,28,9,29,21,32,0,39,5,4,40,8,32,33,62,31,41,60,50,54,18,63,43,46,30,61,45,36,1,14,49,51,42,44,12,27,20,46,7,52,6,19,2,38,46,46,25,16,10,57,3,55,23,15,17,11,13,56,37,24,58 }, + /* 2C04-0002 */ { 46,39,24,57,58,37,28,49,22,19,56,52,32,35,60,11,15,33,6,61,27,41,30,34,29,36,14,43,50,8,46,3,4,54,38,51,17,31,16,2,20,63,0,9,18,46,40,32,62,13,42,23,12,1,21,25,46,44,7,55,53,5,10,45 }, + /* 2C04-0003 */ { 20,37,58,16,11,32,49,9,1,46,54,8,21,61,62,60,34,28,5,18,25,24,23,27,0,3,46,2,22,6,52,53,35,15,14,55,13,39,38,32,41,4,33,36,17,45,46,31,44,30,57,51,7,42,40,29,10,46,50,56,19,43,63,12 }, + /* 2C04-0004 */ { 24,3,28,40,46,53,1,23,16,31,42,14,54,55,11,57,37,30,18,52,46,29,6,38,62,27,34,25,4,46,58,33,5,10,7,2,19,20,0,21,12,61,17,15,13,56,45,36,51,32,8,22,63,43,32,60,46,39,35,49,41,50,44,9 }, + /* 2C05-01 */ { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,15,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,15,62,63 }, + /* 2C05-02 */ { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,15,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,15,62,63 }, + /* 2C05-03 */ { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,15,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,15,62,63 }, + /* 2C05-04 */ { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,15,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,15,62,63 }, + /* 2C05-05 */ { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,15,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,15,62,63 }, + }; + + string _pauseScreenMessage; + + uint64_t _flags = 0; + + bool _audioSettingsChanged = false; + uint32_t _audioLatency = 50; + double _channelVolume[11] = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }; + double _channelPanning[11] = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }; + EqualizerFilterType _equalizerFilterType = EqualizerFilterType::None; + vector _bandGains = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + vector _bands = { { 40,56,80,113,160,225,320,450,600,750,1000,2000,3000,4000,5000,6000,7000,10000,12500,15000 } }; + double _masterVolume = 1.0; + double _volumeReduction = 0.75; + uint32_t _sampleRate = 48000; + StereoFilter _stereoFilter = StereoFilter::None; + int32_t _stereoDelay = 0; + double _stereoAngle = 0; + double _reverbStrength = 0; + double _reverbDelay = 0; + uint32_t _crossFeedRatio = 0; + + NesModel _model = NesModel::Auto; + PpuModel _ppuModel = PpuModel::Ppu2C02; + + uint32_t _emulationSpeed = 100; + uint32_t _turboSpeed = 300; + uint32_t _rewindSpeed = 100; + + uint32_t _rewindBufferSize = 300; + + bool _hasOverclock = false; + uint32_t _overclockRate = 100; + bool _overclockAdjustApu = true; + bool _disableOverclocking = false; + uint32_t _extraScanlinesBeforeNmi = 0; + uint32_t _extraScanlinesAfterNmi = 0; + double _effectiveOverclockRate = 100; + + OverscanDimensions _overscan; + VideoFilterType _videoFilterType = VideoFilterType::None; + double _videoScale = 1; + VideoAspectRatio _aspectRatio = VideoAspectRatio::NoStretching; + double _customAspectRatio = 1.0; + VideoResizeFilter _resizeFilter = VideoResizeFilter::NearestNeighbor; + PictureSettings _pictureSettings; + NtscFilterSettings _ntscFilterSettings; + bool _backgroundEnabled = true; + bool _spritesEnabled = true; + uint32_t _screenRotation = 0; + uint32_t _exclusiveRefreshRate = 60; + + ConsoleType _consoleType = ConsoleType::Nes; + ExpansionPortDevice _expansionDevice = ExpansionPortDevice::None; + ControllerType _controllerTypes[4] = { ControllerType::None, ControllerType::None, ControllerType::None, ControllerType::None }; + KeyMappingSet _controllerKeys[4] = { KeyMappingSet(), KeyMappingSet(), KeyMappingSet(), KeyMappingSet() }; + bool _needControllerUpdate = false; + uint32_t _zapperDetectionRadius = 0; + std::unordered_map _mouseSensitivity; + int32_t _inputPollScanline = 241; + + int32_t _nsfAutoDetectSilenceDelay = 3000; + int32_t _nsfMoveToNextTrackTime = 120; + bool _nsfDisableApuIrqs = true; + + InputDisplaySettings _inputDisplaySettings = { 0, InputDisplayPosition::TopLeft, false }; + + uint32_t _autoSaveDelay = 5; + bool _autoSaveNotify = false; + + bool _keyboardModeEnabled = false; + + std::unordered_map _emulatorKeys[3]; + std::unordered_map> _shortcutSupersets[3]; + + RamPowerOnState _ramPowerOnState = RamPowerOnState::AllZeros; + uint32_t _dipSwitches = 0; + public: static uint32_t GetMesenVersion() { @@ -668,7 +690,7 @@ public: return std::to_string(_versionMajor) + "." + std::to_string(_versionMinor) + "." + std::to_string(_versionRevision); } - static void SetFlags(uint64_t flags) + void SetFlags(uint64_t flags) { if((_flags & flags) != flags) { //Need a lock to prevent flag changes from being ignored due to multithreaded access @@ -683,7 +705,7 @@ public: } } - static void SetFlagState(EmulationFlags flag, bool enabled) + void SetFlagState(EmulationFlags flag, bool enabled) { if(enabled) { SetFlags(flag); @@ -692,7 +714,7 @@ public: } } - static void ClearFlags(uint64_t flags) + void ClearFlags(uint64_t flags) { if((_flags & flags) != 0) { //Need a lock to prevent flag changes from being ignored due to multithreaded access @@ -707,7 +729,7 @@ public: } } - static bool CheckFlag(EmulationFlags flag) + bool CheckFlag(EmulationFlags flag) { return (_flags & flag) == flag; } @@ -722,33 +744,33 @@ public: return _displayLanguage; } - static bool IsPaused() + bool NeedsPause() { return (CheckFlag(EmulationFlags::Paused) || (CheckFlag(EmulationFlags::InBackground) && CheckFlag(EmulationFlags::PauseWhenInBackground) && !GameClient::Connected())) && !CheckFlag(EmulationFlags::DebuggerWindowEnabled); } - static bool InputEnabled() + bool InputEnabled() { - return !EmulationSettings::CheckFlag(EmulationFlags::InBackground) || EmulationSettings::CheckFlag(EmulationFlags::AllowBackgroundInput); + return !CheckFlag(EmulationFlags::InBackground) || CheckFlag(EmulationFlags::AllowBackgroundInput); } - static void SetNesModel(NesModel model) + void SetNesModel(NesModel model) { _model = model; } - static NesModel GetNesModel() + NesModel GetNesModel() { return _model; } - static void SetPpuModel(PpuModel ppuModel) + void SetPpuModel(PpuModel ppuModel) { _ppuModel = ppuModel; UpdateCurrentPalette(); } - static void UpdateCurrentPalette() + void UpdateCurrentPalette() { if(CheckFlag(EmulationFlags::UseCustomVsPalette)) { for(int i = 0; i < 64; i++) { @@ -759,19 +781,19 @@ public: } } - static PpuModel GetPpuModel() + PpuModel GetPpuModel() { return _ppuModel; } //0: Muted, 0.5: Default, 1.0: Max volume - static void SetChannelVolume(AudioChannel channel, double volume) + void SetChannelVolume(AudioChannel channel, double volume) { _channelVolume[(int)channel] = volume; _audioSettingsChanged = true; } - static void SetMasterVolume(double volume, double volumeReduction = -1.0) + void SetMasterVolume(double volume, double volumeReduction = -1.0) { _masterVolume = volume; if(volumeReduction >= 0) { @@ -780,19 +802,19 @@ public: _audioSettingsChanged = true; } - static void SetChannelPanning(AudioChannel channel, double panning) + void SetChannelPanning(AudioChannel channel, double panning) { _channelPanning[(int)channel] = panning; _audioSettingsChanged = true; } - static vector GetBandGains() + vector GetBandGains() { auto lock = _equalizerLock.AcquireSafe(); return _bandGains; } - static void SetBandGain(int band, double gain) + void SetBandGain(int band, double gain) { auto lock = _equalizerLock.AcquireSafe(); if(band < (int)_bandGains.size()) { @@ -801,13 +823,13 @@ public: } } - static vector GetEqualizerBands() + vector GetEqualizerBands() { auto lock = _equalizerLock.AcquireSafe(); return _bands; } - static void SetEqualizerBands(double *bands, uint32_t bandCount) + void SetEqualizerBands(double *bands, uint32_t bandCount) { auto lock = _equalizerLock.AcquireSafe(); _bands.clear(); @@ -818,91 +840,91 @@ public: } } - static EqualizerFilterType GetEqualizerFilterType() + EqualizerFilterType GetEqualizerFilterType() { return _equalizerFilterType; } - static void SetEqualizerFilterType(EqualizerFilterType filter) + void SetEqualizerFilterType(EqualizerFilterType filter) { _equalizerFilterType = filter; _audioSettingsChanged = true; } - static void SetSampleRate(uint32_t sampleRate) + void SetSampleRate(uint32_t sampleRate) { _sampleRate = sampleRate; _audioSettingsChanged = true; } - static uint32_t GetSampleRate() + uint32_t GetSampleRate() { return _sampleRate; } - static void SetAudioLatency(uint32_t msLatency) + void SetAudioLatency(uint32_t msLatency) { _audioLatency = msLatency; _audioSettingsChanged = true; } - static void SetStereoFilter(StereoFilter stereoFilter) + void SetStereoFilter(StereoFilter stereoFilter) { _stereoFilter = stereoFilter; _audioSettingsChanged = true; } - static void SetStereoDelay(int32_t delay) + void SetStereoDelay(int32_t delay) { _stereoDelay = delay; _audioSettingsChanged = true; } - static void SetStereoPanningAngle(double angle) + void SetStereoPanningAngle(double angle) { _stereoAngle = angle; _audioSettingsChanged = true; } - static void SetReverbParameters(double strength, double delay) + void SetReverbParameters(double strength, double delay) { _reverbStrength = strength; _reverbDelay = delay; _audioSettingsChanged = true; } - static StereoFilter GetStereoFilter() + StereoFilter GetStereoFilter() { return _stereoFilter; } - static int32_t GetStereoDelay() + int32_t GetStereoDelay() { return _stereoDelay; } - static double GetStereoPanningAngle() + double GetStereoPanningAngle() { return _stereoAngle; } - static double GetReverbStrength() + double GetReverbStrength() { return _reverbStrength; } - static double GetReverbDelay() + double GetReverbDelay() { return _reverbDelay; } - static void SetCrossFeedRatio(uint32_t ratio) + void SetCrossFeedRatio(uint32_t ratio) { _crossFeedRatio = ratio; _audioSettingsChanged = true; } - static bool NeedAudioSettingsUpdate() + bool NeedAudioSettingsUpdate() { bool value = _audioSettingsChanged; if(value) { @@ -911,13 +933,13 @@ public: return value; } - static uint32_t GetCrossFeedRatio() + uint32_t GetCrossFeedRatio() { return _crossFeedRatio; } //0: No limit, Number: % of default speed (50/60fps) - static void SetEmulationSpeed(uint32_t emulationSpeed, bool displaySpeed = false) + void SetEmulationSpeed(uint32_t emulationSpeed, bool displaySpeed = false) { if(_emulationSpeed != emulationSpeed) { _emulationSpeed = emulationSpeed; @@ -927,58 +949,58 @@ public: } } - static void IncreaseEmulationSpeed() + void IncreaseEmulationSpeed() { if(_emulationSpeed == _speedValues.back()) { - EmulationSettings::SetEmulationSpeed(0, true); + SetEmulationSpeed(0, true); } else if(_emulationSpeed != 0) { for(size_t i = 0; i < _speedValues.size(); i++) { if(_speedValues[i] > _emulationSpeed) { - EmulationSettings::SetEmulationSpeed(_speedValues[i], true); + SetEmulationSpeed(_speedValues[i], true); break; } } } } - static void DecreaseEmulationSpeed() + void DecreaseEmulationSpeed() { if(_emulationSpeed == 0) { - EmulationSettings::SetEmulationSpeed(_speedValues.back(), true); + SetEmulationSpeed(_speedValues.back(), true); } else if(_emulationSpeed > _speedValues.front()) { for(int i = (int)_speedValues.size() - 1; i >= 0; i--) { if(_speedValues[i] < _emulationSpeed) { - EmulationSettings::SetEmulationSpeed(_speedValues[i], true); + SetEmulationSpeed(_speedValues[i], true); break; } } } } - static void SetTurboRewindSpeed(uint32_t turboSpeed, uint32_t rewindSpeed) + void SetTurboRewindSpeed(uint32_t turboSpeed, uint32_t rewindSpeed) { _turboSpeed = turboSpeed; _rewindSpeed = rewindSpeed; } - static uint32_t GetRewindSpeed() + uint32_t GetRewindSpeed() { return _rewindSpeed; } - static void SetRewindBufferSize(uint32_t seconds) + void SetRewindBufferSize(uint32_t seconds) { _rewindBufferSize = seconds; } - static uint32_t GetRewindBufferSize() + uint32_t GetRewindBufferSize() { return _rewindBufferSize; } - static uint32_t GetEmulationSpeed(bool ignoreTurbo = false); + uint32_t GetEmulationSpeed(bool ignoreTurbo = false); - static void UpdateEffectiveOverclockRate() + void UpdateEffectiveOverclockRate() { if(_disableOverclocking) { _effectiveOverclockRate = 100; @@ -989,7 +1011,7 @@ public: _audioSettingsChanged = true; } - static void DisableOverclocking(bool disabled) + void DisableOverclocking(bool disabled) { if(_disableOverclocking != disabled) { _disableOverclocking = disabled; @@ -997,27 +1019,27 @@ public: } } - static uint32_t GetOverclockRateSetting() + uint32_t GetOverclockRateSetting() { return _overclockRate; } - static bool HasOverclock() + bool HasOverclock() { return _hasOverclock; } - static double GetOverclockRate() + double GetOverclockRate() { return _effectiveOverclockRate; } - static bool GetOverclockAdjustApu() + bool GetOverclockAdjustApu() { return _overclockAdjustApu; } - static void SetOverclockRate(uint32_t overclockRate, bool adjustApu) + void SetOverclockRate(uint32_t overclockRate, bool adjustApu) { if(_overclockRate != overclockRate || _overclockAdjustApu != adjustApu) { _overclockRate = overclockRate; @@ -1028,21 +1050,21 @@ public: //TODOCONSOLE //MessageManager::SendNotification(ConsoleNotificationType::ConfigChanged); - MessageManager::DisplayMessage("ClockRate", std::to_string((uint32_t)EmulationSettings::GetOverclockRate()) + "%"); + MessageManager::DisplayMessage("ClockRate", std::to_string((uint32_t)GetOverclockRate()) + "%"); } } - static uint32_t GetPpuExtraScanlinesBeforeNmi() + uint32_t GetPpuExtraScanlinesBeforeNmi() { return _disableOverclocking ? 0 : _extraScanlinesBeforeNmi; } - static uint32_t GetPpuExtraScanlinesAfterNmi() + uint32_t GetPpuExtraScanlinesAfterNmi() { return _disableOverclocking ? 0 : _extraScanlinesAfterNmi; } - static void SetPpuNmiConfig(uint32_t extraScanlinesBeforeNmi, uint32_t extraScanlinesAfterNmi) + void SetPpuNmiConfig(uint32_t extraScanlinesBeforeNmi, uint32_t extraScanlinesAfterNmi) { if(_extraScanlinesBeforeNmi != extraScanlinesBeforeNmi || _extraScanlinesAfterNmi != extraScanlinesAfterNmi) { if(extraScanlinesBeforeNmi > 0 || extraScanlinesAfterNmi > 0) { @@ -1056,7 +1078,7 @@ public: } } - static void SetOverscanDimensions(uint8_t left, uint8_t right, uint8_t top, uint8_t bottom) + void SetOverscanDimensions(uint8_t left, uint8_t right, uint8_t top, uint8_t bottom) { if(_overscan.Left != left || _overscan.Right != right || _overscan.Top != top || _overscan.Bottom != bottom) { _overscan.Left = left; @@ -1066,73 +1088,73 @@ public: } } - static OverscanDimensions GetOverscanDimensions() + OverscanDimensions GetOverscanDimensions() { return _overscan; } - static double GetChannelVolume(AudioChannel channel) + double GetChannelVolume(AudioChannel channel) { return _channelVolume[(int)channel]; } - static double GetMasterVolume() + double GetMasterVolume() { return _masterVolume; } - static double GetVolumeReduction() + double GetVolumeReduction() { return _volumeReduction; } - static double GetChannelPanning(AudioChannel channel) + double GetChannelPanning(AudioChannel channel) { return _channelPanning[(int)channel]; } - static uint32_t GetAudioLatency() + uint32_t GetAudioLatency() { return _audioLatency; } - static void SetVideoFilterType(VideoFilterType videoFilterType) + void SetVideoFilterType(VideoFilterType videoFilterType) { _videoFilterType = videoFilterType; } - static VideoFilterType GetVideoFilterType() + VideoFilterType GetVideoFilterType() { return _videoFilterType; } - static void SetVideoResizeFilter(VideoResizeFilter videoResizeFilter) + void SetVideoResizeFilter(VideoResizeFilter videoResizeFilter) { _resizeFilter = videoResizeFilter; } - static VideoResizeFilter GetVideoResizeFilter() + VideoResizeFilter GetVideoResizeFilter() { return _resizeFilter; } - static void SetVideoAspectRatio(VideoAspectRatio aspectRatio, double customRatio) + void SetVideoAspectRatio(VideoAspectRatio aspectRatio, double customRatio) { _aspectRatio = aspectRatio; _customAspectRatio = customRatio; } - static bool GetBackgroundEnabled() + bool GetBackgroundEnabled() { return _backgroundEnabled; } - static bool GetSpritesEnabled() + bool GetSpritesEnabled() { return _spritesEnabled; } - static void SetPictureSettings(double brightness, double contrast, double saturation, double hue, double scanlineIntensity) + void SetPictureSettings(double brightness, double contrast, double saturation, double hue, double scanlineIntensity) { _pictureSettings.Brightness = brightness; _pictureSettings.Contrast = contrast; @@ -1141,12 +1163,12 @@ public: _pictureSettings.ScanlineIntensity = scanlineIntensity; } - static PictureSettings GetPictureSettings() + PictureSettings GetPictureSettings() { return _pictureSettings; } - static void SetNtscFilterSettings(double artifacts, double bleed, double fringing, double gamma, double resolution, double sharpness, bool mergeFields, double yFilterLength, double iFilterLength, double qFilterLength, bool verticalBlend, bool keepVerticalResolution) + void SetNtscFilterSettings(double artifacts, double bleed, double fringing, double gamma, double resolution, double sharpness, bool mergeFields, double yFilterLength, double iFilterLength, double qFilterLength, bool verticalBlend, bool keepVerticalResolution) { _ntscFilterSettings.Artifacts = artifacts; _ntscFilterSettings.Bleed = bleed; @@ -1165,111 +1187,112 @@ public: _ntscFilterSettings.KeepVerticalResolution = keepVerticalResolution; } - static NtscFilterSettings GetNtscFilterSettings() + NtscFilterSettings GetNtscFilterSettings() { return _ntscFilterSettings; } - static double GetAspectRatio(shared_ptr console); + double GetAspectRatio(shared_ptr console); + void InitializeInputDevices(GameInputType inputType, GameSystem system, bool silent); - static void SetVideoScale(double scale) + void SetVideoScale(double scale) { if(_videoScale != scale) { _videoScale = scale; } } - static double GetVideoScale() + double GetVideoScale() { return _videoScale; } - static void SetScreenRotation(uint32_t angle) + void SetScreenRotation(uint32_t angle) { _screenRotation = angle; } - static uint32_t GetScreenRotation() + uint32_t GetScreenRotation() { return _screenRotation; } - static void SetExclusiveRefreshRate(uint32_t refreshRate) + void SetExclusiveRefreshRate(uint32_t refreshRate) { _exclusiveRefreshRate = refreshRate; } - static uint32_t GetExclusiveRefreshRate() + uint32_t GetExclusiveRefreshRate() { return _exclusiveRefreshRate; } - static uint32_t* GetRgbPalette() + uint32_t* GetRgbPalette() { return _currentPalette; } - static void GetRgbPalette(uint32_t* paletteBuffer) + void GetRgbPalette(uint32_t* paletteBuffer) { memcpy(paletteBuffer, _ppuPaletteArgb[0], sizeof(_ppuPaletteArgb[0])); } - static void SetRgbPalette(uint32_t* paletteBuffer) + void SetRgbPalette(uint32_t* paletteBuffer) { memcpy(_ppuPaletteArgb[0], paletteBuffer, sizeof(_ppuPaletteArgb[0])); UpdateCurrentPalette(); } - static bool IsDefaultPalette() + bool IsDefaultPalette() { return memcmp(_defaultPpuPalette, GetRgbPalette(), sizeof(_defaultPpuPalette)) == 0; } - static void SetExpansionDevice(ExpansionPortDevice expansionDevice) + void SetExpansionDevice(ExpansionPortDevice expansionDevice) { _expansionDevice = expansionDevice; _needControllerUpdate = true; } - static ExpansionPortDevice GetExpansionDevice() + ExpansionPortDevice GetExpansionDevice() { return _expansionDevice; } - static void SetConsoleType(ConsoleType type) + void SetConsoleType(ConsoleType type) { _consoleType = type; _needControllerUpdate = true; } - static ConsoleType GetConsoleType() + ConsoleType GetConsoleType() { return _consoleType; } - static void SetControllerType(uint8_t port, ControllerType type) + void SetControllerType(uint8_t port, ControllerType type) { _controllerTypes[port] = type; _needControllerUpdate = true; } - static ControllerType GetControllerType(uint8_t port) + ControllerType GetControllerType(uint8_t port) { return _controllerTypes[port]; } - static void SetControllerKeys(uint8_t port, KeyMappingSet keyMappings) + void SetControllerKeys(uint8_t port, KeyMappingSet keyMappings) { _controllerKeys[port] = keyMappings; _needControllerUpdate = true; } - static KeyMappingSet GetControllerKeys(uint8_t port) + KeyMappingSet GetControllerKeys(uint8_t port) { return _controllerKeys[port]; } - static void ClearShortcutKeys() + void ClearShortcutKeys() { auto lock = _shortcutLock.AcquireSafe(); _emulatorKeys[0].clear(); @@ -1286,7 +1309,7 @@ public: SetShortcutKey(EmulatorShortcut::Exit, keyComb, 2); } - static void SetShortcutKey(EmulatorShortcut shortcut, KeyCombination keyCombination, int keySetIndex) + void SetShortcutKey(EmulatorShortcut shortcut, KeyCombination keyCombination, int keySetIndex) { auto lock = _shortcutLock.AcquireSafe(); _emulatorKeys[keySetIndex][(uint32_t)shortcut] = keyCombination; @@ -1302,7 +1325,7 @@ public: } } - static KeyCombination GetShortcutKey(EmulatorShortcut shortcut, int keySetIndex) + KeyCombination GetShortcutKey(EmulatorShortcut shortcut, int keySetIndex) { auto lock = _shortcutLock.AcquireSafe(); auto result = _emulatorKeys[keySetIndex].find((int)shortcut); @@ -1312,13 +1335,13 @@ public: return {}; } - static vector GetShortcutSupersets(EmulatorShortcut shortcut, int keySetIndex) + vector GetShortcutSupersets(EmulatorShortcut shortcut, int keySetIndex) { auto lock = _shortcutLock.AcquireSafe(); return _shortcutSupersets[keySetIndex][(uint32_t)shortcut]; } - static bool NeedControllerUpdate() + bool NeedControllerUpdate() { if(_needControllerUpdate) { _needControllerUpdate = false; @@ -1328,12 +1351,12 @@ public: } } - static void SetMouseSensitivity(MouseDevice device, double sensitivity) + void SetMouseSensitivity(MouseDevice device, double sensitivity) { _mouseSensitivity[(int)device] = sensitivity; } - static double GetMouseSensitivity(MouseDevice device) + double GetMouseSensitivity(MouseDevice device) { auto result = _mouseSensitivity.find((int)device); if(result != _mouseSensitivity.end()) { @@ -1343,106 +1366,106 @@ public: } } - static void SetZapperDetectionRadius(uint32_t detectionRadius) + void SetZapperDetectionRadius(uint32_t detectionRadius) { _zapperDetectionRadius = detectionRadius; } - static uint32_t GetZapperDetectionRadius() + uint32_t GetZapperDetectionRadius() { return _zapperDetectionRadius; } - static void SetInputPollScanline(int32_t scanline) + void SetInputPollScanline(int32_t scanline) { _inputPollScanline = scanline; } - static int32_t GetInputPollScanline() + int32_t GetInputPollScanline() { return _inputPollScanline; } - static bool HasZapper() + bool HasZapper() { return _controllerTypes[0] == ControllerType::Zapper || _controllerTypes[1] == ControllerType::Zapper || (_consoleType == ConsoleType::Famicom && _expansionDevice == ExpansionPortDevice::Zapper); } - static bool HasArkanoidPaddle() + bool HasArkanoidPaddle() { return _controllerTypes[0] == ControllerType::ArkanoidController || _controllerTypes[1] == ControllerType::ArkanoidController || (_consoleType == ConsoleType::Famicom && _expansionDevice == ExpansionPortDevice::ArkanoidController); } - static void SetNsfConfig(int32_t autoDetectSilence, int32_t moveToNextTrackTime, bool disableApuIrqs) + void SetNsfConfig(int32_t autoDetectSilence, int32_t moveToNextTrackTime, bool disableApuIrqs) { _nsfAutoDetectSilenceDelay = autoDetectSilence; _nsfMoveToNextTrackTime = moveToNextTrackTime; _nsfDisableApuIrqs = disableApuIrqs; } - static int32_t GetNsfAutoDetectSilenceDelay() + int32_t GetNsfAutoDetectSilenceDelay() { return _nsfAutoDetectSilenceDelay; } - static int32_t GetNsfMoveToNextTrackTime() + int32_t GetNsfMoveToNextTrackTime() { return _nsfMoveToNextTrackTime; } - static bool GetNsfDisableApuIrqs() + bool GetNsfDisableApuIrqs() { return _nsfDisableApuIrqs; } - static void SetInputDisplaySettings(uint8_t visiblePorts, InputDisplayPosition displayPosition, bool displayHorizontally) + void SetInputDisplaySettings(uint8_t visiblePorts, InputDisplayPosition displayPosition, bool displayHorizontally) { _inputDisplaySettings = { visiblePorts, displayPosition, displayHorizontally }; } - static InputDisplaySettings GetInputDisplaySettings() + InputDisplaySettings GetInputDisplaySettings() { return _inputDisplaySettings; } - static void SetRamPowerOnState(RamPowerOnState state) + void SetRamPowerOnState(RamPowerOnState state) { _ramPowerOnState = state; } - static RamPowerOnState GetRamPowerOnState() + RamPowerOnState GetRamPowerOnState() { return _ramPowerOnState; } - static void SetAutoSaveOptions(uint32_t delayInMinutes, bool showMessage) + void SetAutoSaveOptions(uint32_t delayInMinutes, bool showMessage) { _autoSaveDelay = delayInMinutes; _autoSaveNotify = showMessage; } - static uint32_t GetAutoSaveDelay(bool &showMessage) + uint32_t GetAutoSaveDelay(bool &showMessage) { showMessage = _autoSaveNotify; return _autoSaveDelay; } - static void SetDipSwitches(uint32_t dipSwitches) + void SetDipSwitches(uint32_t dipSwitches) { _dipSwitches = dipSwitches; } - static uint32_t GetDipSwitches() + uint32_t GetDipSwitches() { return _dipSwitches; } - static bool IsKeyboardMode() + bool IsKeyboardMode() { return _keyboardModeEnabled; } - static void EnableKeyboardMode() + void EnableKeyboardMode() { if(!_keyboardModeEnabled) { _keyboardModeEnabled = true; @@ -1450,7 +1473,7 @@ public: } } - static void DisableKeyboardMode() + void DisableKeyboardMode() { if(_keyboardModeEnabled) { _keyboardModeEnabled = false; @@ -1458,12 +1481,12 @@ public: } } - static void SetPauseScreenMessage(string message) + void SetPauseScreenMessage(string message) { _pauseScreenMessage = message; } - static string GetPauseScreenMessage() + string GetPauseScreenMessage() { return _pauseScreenMessage; } diff --git a/Core/ExcitingBoxingController.h b/Core/ExcitingBoxingController.h index 98fda6af..6ac7d34f 100644 --- a/Core/ExcitingBoxingController.h +++ b/Core/ExcitingBoxingController.h @@ -30,7 +30,7 @@ protected: } public: - ExcitingBoxingController(KeyMappingSet keyMappings) : BaseControlDevice(BaseControlDevice::ExpDevicePort, keyMappings) + ExcitingBoxingController(shared_ptr console, KeyMappingSet keyMappings) : BaseControlDevice(console, BaseControlDevice::ExpDevicePort, keyMappings) { } diff --git a/Core/FDS.cpp b/Core/FDS.cpp index d1768d61..64c36494 100644 --- a/Core/FDS.cpp +++ b/Core/FDS.cpp @@ -10,6 +10,8 @@ void FDS::InitMapper() { + _settings = _console->GetSettings(); + //FDS BIOS SetCpuMemoryMapping(0xE000, 0xFFFF, 0, PrgMemoryType::PrgRom, MemoryAccessType::Read); @@ -171,7 +173,7 @@ uint8_t FDS::ReadRAM(uint16_t addr) void FDS::ProcessAutoDiskInsert() { if(IsAutoInsertDiskEnabled()) { - bool fastForwardEnabled = EmulationSettings::CheckFlag(EmulationFlags::FdsFastForwardOnLoad); + bool fastForwardEnabled = _settings->CheckFlag(EmulationFlags::FdsFastForwardOnLoad); uint32_t currentFrame = _console->GetPpu()->GetFrameCount(); if(_previousFrame != currentFrame) { _previousFrame = currentFrame; @@ -179,11 +181,11 @@ void FDS::ProcessAutoDiskInsert() //After reading a disk, wait until this counter reaches 0 before //automatically ejecting the disk the next time $4032 is read _autoDiskEjectCounter--; - EmulationSettings::SetFlagState(EmulationFlags::ForceMaxSpeed, fastForwardEnabled && _autoDiskEjectCounter != 0); + _settings->SetFlagState(EmulationFlags::ForceMaxSpeed, fastForwardEnabled && _autoDiskEjectCounter != 0); } else if(_autoDiskSwitchCounter > 0) { //After ejecting the disk, wait a bit before we insert a new one _autoDiskSwitchCounter--; - EmulationSettings::SetFlagState(EmulationFlags::ForceMaxSpeed, fastForwardEnabled && _autoDiskSwitchCounter != 0); + _settings->SetFlagState(EmulationFlags::ForceMaxSpeed, fastForwardEnabled && _autoDiskSwitchCounter != 0); if(_autoDiskSwitchCounter == 0) { //Insert a disk (real disk/side will be selected when game executes $E445 MessageManager::Log("[FDS] Auto-inserted dummy disk."); @@ -195,7 +197,7 @@ void FDS::ProcessAutoDiskInsert() } else if(_restartAutoInsertCounter > 0) { //After ejecting the disk, wait a bit before we insert a new one _restartAutoInsertCounter--; - EmulationSettings::SetFlagState(EmulationFlags::ForceMaxSpeed, fastForwardEnabled && _restartAutoInsertCounter != 0); + _settings->SetFlagState(EmulationFlags::ForceMaxSpeed, fastForwardEnabled && _restartAutoInsertCounter != 0); if(_restartAutoInsertCounter == 0) { //Wait a bit before ejecting the disk (eject in ~34 frames) MessageManager::Log("[FDS] Game failed to load disk, try again."); @@ -210,10 +212,10 @@ void FDS::ProcessAutoDiskInsert() void FDS::ProcessCpuClock() { - if(EmulationSettings::CheckFlag(EmulationFlags::FdsFastForwardOnLoad)) { - EmulationSettings::SetFlagState(EmulationFlags::ForceMaxSpeed, _scanningDisk || !_gameStarted); + if(_settings->CheckFlag(EmulationFlags::FdsFastForwardOnLoad)) { + _settings->SetFlagState(EmulationFlags::ForceMaxSpeed, _scanningDisk || !_gameStarted); } else { - EmulationSettings::ClearFlags(EmulationFlags::ForceMaxSpeed); + _settings->ClearFlags(EmulationFlags::ForceMaxSpeed); } ProcessAutoDiskInsert(); @@ -506,7 +508,7 @@ void FDS::StreamState(bool saving) FDS::~FDS() { //Restore emulation speed to normal when closing - EmulationSettings::ClearFlags(EmulationFlags::ForceMaxSpeed); + _settings->ClearFlags(EmulationFlags::ForceMaxSpeed); } ConsoleFeatures FDS::GetAvailableFeatures() @@ -543,5 +545,5 @@ bool FDS::IsDiskInserted() bool FDS::IsAutoInsertDiskEnabled() { - return !_disableAutoInsertDisk && EmulationSettings::CheckFlag(EmulationFlags::FdsAutoInsertDisk) && !MovieManager::Playing() && !MovieManager::Recording(); + return !_disableAutoInsertDisk && _settings->CheckFlag(EmulationFlags::FdsAutoInsertDisk) && !MovieManager::Playing() && !MovieManager::Recording(); } \ No newline at end of file diff --git a/Core/FDS.h b/Core/FDS.h index d916b2c6..69f78381 100644 --- a/Core/FDS.h +++ b/Core/FDS.h @@ -16,6 +16,7 @@ private: bool _disableAutoInsertDisk; unique_ptr _audio; + EmulationSettings* _settings = nullptr; //Write registers uint16_t _irqReloadValue = 0; diff --git a/Core/FamilyBasicDataRecorder.h b/Core/FamilyBasicDataRecorder.h index 0baec39b..c89f8a51 100644 --- a/Core/FamilyBasicDataRecorder.h +++ b/Core/FamilyBasicDataRecorder.h @@ -9,7 +9,6 @@ class FamilyBasicDataRecorder : public BaseControlDevice { private: static constexpr int32_t SamplingRate = 88; - shared_ptr _console; vector _data; vector _fileData; bool _enabled = false; @@ -46,9 +45,8 @@ protected: } public: - FamilyBasicDataRecorder(shared_ptr console) : BaseControlDevice(BaseControlDevice::ExpDevicePort2) + FamilyBasicDataRecorder(shared_ptr console) : BaseControlDevice(console, BaseControlDevice::ExpDevicePort2) { - _console = console; } ~FamilyBasicDataRecorder() diff --git a/Core/FamilyBasicKeyboard.h b/Core/FamilyBasicKeyboard.h index 752a62d5..e9366023 100644 --- a/Core/FamilyBasicKeyboard.h +++ b/Core/FamilyBasicKeyboard.h @@ -83,7 +83,7 @@ protected: } public: - FamilyBasicKeyboard(KeyMappingSet keyMappings) : BaseControlDevice(BaseControlDevice::ExpDevicePort, keyMappings) + FamilyBasicKeyboard(shared_ptr console, KeyMappingSet keyMappings) : BaseControlDevice(console, BaseControlDevice::ExpDevicePort, keyMappings) { } diff --git a/Core/FamilyMatTrainer.h b/Core/FamilyMatTrainer.h index fa53b9a1..8eeaeffa 100644 --- a/Core/FamilyMatTrainer.h +++ b/Core/FamilyMatTrainer.h @@ -15,7 +15,7 @@ protected: } public: - FamilyMatTrainer(KeyMappingSet keyMappings) : PowerPad(BaseControlDevice::ExpDevicePort, keyMappings) + FamilyMatTrainer(shared_ptr console, KeyMappingSet keyMappings) : PowerPad(console, BaseControlDevice::ExpDevicePort, keyMappings) { } diff --git a/Core/FceuxMovie.cpp b/Core/FceuxMovie.cpp index b04634a8..b98445fc 100644 --- a/Core/FceuxMovie.cpp +++ b/Core/FceuxMovie.cpp @@ -26,7 +26,7 @@ bool FceuxMovie::InitializeData(stringstream &filestream) vector md5array = Base64::Decode(line.substr(19, line.size() - 20)); HashInfo hashInfo; hashInfo.PrgChrMd5 = HexUtilities::ToHex(md5array); - EmulationSettings::SetRamPowerOnState(RamPowerOnState::AllZeros); + _console->GetSettings()->SetRamPowerOnState(RamPowerOnState::AllZeros); if(_console->LoadMatchingRom("", hashInfo)) { result = true; } else { diff --git a/Core/FdsLoader.cpp b/Core/FdsLoader.cpp index c7429454..ae2e8b38 100644 --- a/Core/FdsLoader.cpp +++ b/Core/FdsLoader.cpp @@ -151,10 +151,5 @@ RomData FdsLoader::LoadRom(vector& romFile, string filename) romData.BiosMissing = true; } - //Setup default controllers - if(!_checkOnly && EmulationSettings::CheckFlag(EmulationFlags::AutoConfigureInput)) { - GameDatabase::InitializeInputDevices(GameInputType::FamicomControllers, GameSystem::FDS); - } - return romData; } diff --git a/Core/FdsSystemActionManager.h b/Core/FdsSystemActionManager.h index 5bf28868..b1ab43a2 100644 --- a/Core/FdsSystemActionManager.h +++ b/Core/FdsSystemActionManager.h @@ -36,7 +36,7 @@ public: _mapper = std::dynamic_pointer_cast(mapper); _sideCount = std::dynamic_pointer_cast(mapper)->GetSideCount(); - if(EmulationSettings::CheckFlag(EmulationFlags::FdsAutoLoadDisk)) { + if(console->GetSettings()->CheckFlag(EmulationFlags::FdsAutoLoadDisk)) { InsertDisk(0); } } diff --git a/Core/FourScore.h b/Core/FourScore.h index d524e01b..e7f8781a 100644 --- a/Core/FourScore.h +++ b/Core/FourScore.h @@ -23,7 +23,7 @@ protected: } public: - FourScore() : BaseControlDevice(BaseControlDevice::ExpDevicePort) + FourScore(shared_ptr console) : BaseControlDevice(console, BaseControlDevice::ExpDevicePort) { } diff --git a/Core/GameClientConnection.cpp b/Core/GameClientConnection.cpp index 639edc32..6a7a5a0e 100644 --- a/Core/GameClientConnection.cpp +++ b/Core/GameClientConnection.cpp @@ -43,7 +43,7 @@ void GameClientConnection::Shutdown() _console->GetControlManager()->UnregisterInputProvider(this); _console->GetNotificationManager()->SendNotification(ConsoleNotificationType::DisconnectedFromServer); MessageManager::DisplayMessage("NetPlay", "ConnectionLost"); - EmulationSettings::ClearFlags(EmulationFlags::ForceMaxSpeed); + _console->GetSettings()->ClearFlags(EmulationFlags::ForceMaxSpeed); } } @@ -122,9 +122,9 @@ void GameClientConnection::ProcessMessage(NetMessage* message) _gameLoaded = AttemptLoadGame(gameInfo->GetRomFilename(), gameInfo->GetCrc32Hash()); if(gameInfo->IsPaused()) { - EmulationSettings::SetFlags(EmulationFlags::Paused); + _console->GetSettings()->SetFlags(EmulationFlags::Paused); } else { - EmulationSettings::ClearFlags(EmulationFlags::Paused); + _console->GetSettings()->ClearFlags(EmulationFlags::Paused); } _console->Resume(); break; @@ -193,10 +193,10 @@ bool GameClientConnection::SetInput(BaseControlDevice *device) if(_inputData[port].size() > _minimumQueueSize) { //Too much data, catch up - EmulationSettings::SetFlags(EmulationFlags::ForceMaxSpeed); + _console->GetSettings()->SetFlags(EmulationFlags::ForceMaxSpeed); } else { - EmulationSettings::ClearFlags(EmulationFlags::ForceMaxSpeed); - EmulationSettings::SetEmulationSpeed(100); + _console->GetSettings()->ClearFlags(EmulationFlags::ForceMaxSpeed); + _console->GetSettings()->SetEmulationSpeed(100); } device->SetRawState(state); @@ -207,10 +207,10 @@ bool GameClientConnection::SetInput(BaseControlDevice *device) void GameClientConnection::InitControlDevice() { if(_controllerPort == BaseControlDevice::ExpDevicePort) { - _newControlDevice = ControlManager::CreateExpansionDevice(EmulationSettings::GetExpansionDevice(), _console); + _newControlDevice = ControlManager::CreateExpansionDevice(_console->GetSettings()->GetExpansionDevice(), _console); } else { //Pretend we are using port 0 (to use player 1's keybindings during netplay) - _newControlDevice = ControlManager::CreateControllerDevice(EmulationSettings::GetControllerType(_controllerPort), 0, _console); + _newControlDevice = ControlManager::CreateControllerDevice(_console->GetSettings()->GetControllerType(_controllerPort), 0, _console); } } diff --git a/Core/GameDatabase.cpp b/Core/GameDatabase.cpp index a357e05f..6e1aaf54 100644 --- a/Core/GameDatabase.cpp +++ b/Core/GameDatabase.cpp @@ -10,6 +10,7 @@ #include "UnifLoader.h" std::unordered_map GameDatabase::_gameDatabase; +bool GameDatabase::_enabled = true; template T GameDatabase::ToInt(string value) @@ -217,130 +218,14 @@ GameInputType GameDatabase::GetInputType(GameSystem system, string inputType) } } -void GameDatabase::InitializeInputDevices(RomInfo &romInfo) +void GameDatabase::SetGameDatabaseState(bool enabled) { - InitDatabase(); - - auto result = _gameDatabase.find(romInfo.Hash.PrgChrCrc32); - if(romInfo.IsNes20Header || result != _gameDatabase.end()) { - InitializeInputDevices(romInfo.InputType, romInfo.System, true); - } else { - InitializeInputDevices(GameInputType::Default, GameSystem::NesNtsc, true); - } + _enabled = enabled; } -void GameDatabase::InitializeInputDevices(GameInputType inputType, GameSystem system, bool silent) +bool GameDatabase::IsEnabled() { - ControllerType controllers[4] = { ControllerType::StandardController, ControllerType::StandardController, ControllerType::None, ControllerType::None }; - ExpansionPortDevice expDevice = ExpansionPortDevice::None; - EmulationSettings::ClearFlags(EmulationFlags::HasFourScore); - - auto log = [silent](string text) { - if(!silent) { - MessageManager::Log(text); - } - }; - - bool isFamicom = (system == GameSystem::Famicom || system == GameSystem::FDS || system == GameSystem::Dendy); - - if(inputType == GameInputType::VsZapper) { - //VS Duck Hunt, etc. need the zapper in the first port - log("[Input] VS Zapper connected"); - controllers[0] = ControllerType::Zapper; - } else if(inputType == GameInputType::Zapper) { - log("[Input] Zapper connected"); - if(isFamicom) { - expDevice = ExpansionPortDevice::Zapper; - } else { - controllers[1] = ControllerType::Zapper; - } - } else if(inputType == GameInputType::FourScore) { - log("[Input] Four score connected"); - EmulationSettings::SetFlags(EmulationFlags::HasFourScore); - controllers[2] = controllers[3] = ControllerType::StandardController; - } else if(inputType == GameInputType::FourPlayerAdapter) { - log("[Input] Four player adapter connected"); - EmulationSettings::SetFlags(EmulationFlags::HasFourScore); - expDevice = ExpansionPortDevice::FourPlayerAdapter; - controllers[2] = controllers[3] = ControllerType::StandardController; - } else if(inputType == GameInputType::ArkanoidControllerFamicom) { - log("[Input] Arkanoid controller (Famicom) connected"); - expDevice = ExpansionPortDevice::ArkanoidController; - } else if(inputType == GameInputType::ArkanoidControllerNes) { - log("[Input] Arkanoid controller (NES) connected"); - controllers[1] = ControllerType::ArkanoidController; - } else if(inputType == GameInputType::OekaKidsTablet) { - log("[Input] Oeka Kids Tablet connected"); - system = GameSystem::Famicom; - expDevice = ExpansionPortDevice::OekaKidsTablet; - } else if(inputType == GameInputType::KonamiHyperShot) { - log("[Input] Konami Hyper Shot connected"); - system = GameSystem::Famicom; - expDevice = ExpansionPortDevice::KonamiHyperShot; - } else if(inputType == GameInputType::FamilyBasicKeyboard) { - log("[Input] Family Basic Keyboard connected"); - system = GameSystem::Famicom; - expDevice = ExpansionPortDevice::FamilyBasicKeyboard; - } else if(inputType == GameInputType::PartyTap) { - log("[Input] Party Tap connected"); - system = GameSystem::Famicom; - expDevice = ExpansionPortDevice::PartyTap; - } else if(inputType == GameInputType::PachinkoController) { - log("[Input] Pachinko controller connected"); - system = GameSystem::Famicom; - expDevice = ExpansionPortDevice::Pachinko; - } else if(inputType == GameInputType::ExcitingBoxing) { - log("[Input] Exciting Boxing controller connected"); - system = GameSystem::Famicom; - expDevice = ExpansionPortDevice::ExcitingBoxing; - } else if(inputType == GameInputType::SuborKeyboardMouse1) { - log("[Input] Subor mouse connected"); - log("[Input] Subor keyboard connected"); - system = GameSystem::Famicom; - expDevice = ExpansionPortDevice::SuborKeyboard; - controllers[1] = ControllerType::SuborMouse; - } else if(inputType == GameInputType::JissenMahjong) { - log("[Input] Jissen Mahjong controller connected"); - system = GameSystem::Famicom; - expDevice = ExpansionPortDevice::JissenMahjong; - } else if(inputType == GameInputType::BarcodeBattler) { - log("[Input] Barcode Battler barcode reader connected"); - system = GameSystem::Famicom; - expDevice = ExpansionPortDevice::BarcodeBattler; - } else if(inputType == GameInputType::BandaiHypershot) { - log("[Input] Bandai Hyper Shot gun connected"); - system = GameSystem::Famicom; - expDevice = ExpansionPortDevice::BandaiHyperShot; - } else if(inputType == GameInputType::BattleBox) { - log("[Input] Battle Box connected"); - system = GameSystem::Famicom; - expDevice = ExpansionPortDevice::BattleBox; - } else if(inputType == GameInputType::TurboFile) { - log("[Input] Ascii Turbo File connected"); - system = GameSystem::Famicom; - expDevice = ExpansionPortDevice::AsciiTurboFile; - } else if(inputType == GameInputType::FamilyTrainerSideA || inputType == GameInputType::FamilyTrainerSideB) { - log("[Input] Family Trainer mat connected"); - system = GameSystem::Famicom; - expDevice = ExpansionPortDevice::FamilyTrainerMat; - } else if(inputType == GameInputType::PowerPadSideA || inputType == GameInputType::PowerPadSideB) { - log("[Input] Power Pad connected"); - system = GameSystem::NesNtsc; - controllers[1] = ControllerType::PowerPad; - } else if(inputType == GameInputType::SnesControllers) { - log("[Input] 2 SNES controllers connected"); - controllers[0] = ControllerType::SnesController; - controllers[1] = ControllerType::SnesController; - } else { - log("[Input] 2 standard controllers connected"); - } - - isFamicom = (system == GameSystem::Famicom || system == GameSystem::FDS || system == GameSystem::Dendy); - EmulationSettings::SetConsoleType(isFamicom ? ConsoleType::Famicom : ConsoleType::Nes); - for(int i = 0; i < 4; i++) { - EmulationSettings::SetControllerType(i, controllers[i]); - } - EmulationSettings::SetExpansionDevice(expDevice); + return _enabled; } uint8_t GameDatabase::GetSubMapper(GameInfo &info) @@ -591,6 +476,7 @@ void GameDatabase::SetGameInfo(uint32_t romCrc, RomData &romData, bool updateRom if(updateRomData) { MessageManager::Log("[DB] Database info will be used instead of file header."); + romData.Info.IsInDatabase = true; UpdateRomData(info, romData); } @@ -601,13 +487,6 @@ void GameDatabase::SetGameInfo(uint32_t romCrc, RomData &romData, bool updateRom MessageManager::Log("[DB] Game not found in database"); } - if(foundInDatabase || romData.Info.IsNes20Header) { - //If in DB or a NES 2.0 file, auto-configure the inputs - if(EmulationSettings::CheckFlag(EmulationFlags::AutoConfigureInput)) { - InitializeInputDevices(romData.Info.InputType, romData.Info.System); - } - } - #ifdef LIBRETRO SetVsSystemDefaults(romData.Info.Hash.PrgCrc32); #endif diff --git a/Core/GameDatabase.h b/Core/GameDatabase.h index 6eafd575..ab20c202 100644 --- a/Core/GameDatabase.h +++ b/Core/GameDatabase.h @@ -7,6 +7,7 @@ class GameDatabase { private: static std::unordered_map _gameDatabase; + static bool _enabled; template static T ToInt(string value); @@ -23,9 +24,10 @@ private: public: static void LoadGameDb(vector data); + + static void SetGameDatabaseState(bool enabled); + static bool IsEnabled(); - static void InitializeInputDevices(GameInputType inputType, GameSystem system, bool silent = false); - static void InitializeInputDevices(RomInfo &romInfo); static void SetGameInfo(uint32_t romCrc, RomData &romData, bool updateRomData, bool forHeaderlessRom); static bool GetiNesHeader(uint32_t romCrc, NESHeader &nesHeader); static bool GetDbRomSize(uint32_t romCrc, uint32_t &prgSize, uint32_t &chrSize); diff --git a/Core/GameServerConnection.cpp b/Core/GameServerConnection.cpp index 4fb9fefe..84ab1969 100644 --- a/Core/GameServerConnection.cpp +++ b/Core/GameServerConnection.cpp @@ -59,7 +59,7 @@ void GameServerConnection::SendGameInformation() { _console->Pause(); RomInfo romInfo = _console->GetRomInfo(); - GameInformationMessage gameInfo(romInfo.RomName, romInfo.Hash.Crc32, _controllerPort, EmulationSettings::CheckFlag(EmulationFlags::Paused)); + GameInformationMessage gameInfo(romInfo.RomName, romInfo.Hash.Crc32, _controllerPort, _console->GetSettings()->CheckFlag(EmulationFlags::Paused)); SendNetMessage(gameInfo); SaveStateMessage saveState(_console); SendNetMessage(saveState); diff --git a/Core/HdData.h b/Core/HdData.h index 9902b637..3a028cc1 100644 --- a/Core/HdData.h +++ b/Core/HdData.h @@ -207,10 +207,9 @@ struct HdPackTileInfo : public HdTileKey return true; } - vector ToRgb() + vector ToRgb(uint32_t* palette) { vector rgbBuffer; - uint32_t* palette = EmulationSettings::GetRgbPalette(); for(uint8_t i = 0; i < 8; i++) { uint8_t lowByte = TileData[i]; uint8_t highByte = TileData[i + 8]; diff --git a/Core/HdNesPack.cpp b/Core/HdNesPack.cpp index 76ba345c..3e3a2efd 100644 --- a/Core/HdNesPack.cpp +++ b/Core/HdNesPack.cpp @@ -9,9 +9,10 @@ #include "../Utilities/FolderUtilities.h" #include "../Utilities/PNGHelper.h" -HdNesPack::HdNesPack(shared_ptr hdData) +HdNesPack::HdNesPack(shared_ptr hdData, EmulationSettings* settings) { _hdData = hdData; + _settings = settings; } HdNesPack::~HdNesPack() @@ -162,12 +163,12 @@ void HdNesPack::OnLineStart(HdPpuPixelInfo &lineFirstPixel) void HdNesPack::OnBeforeApplyFilter() { - _palette = _hdData->Palette.size() == 0x40 ? _hdData->Palette.data() : EmulationSettings::GetRgbPalette(); + _palette = _hdData->Palette.size() == 0x40 ? _hdData->Palette.data() : _settings->GetRgbPalette(); _contoursEnabled = (_hdData->OptionFlags & (int)HdPackOptions::NoContours) == 0; _cacheEnabled = (_hdData->OptionFlags & (int)HdPackOptions::DisableCache) == 0; if(_hdData->OptionFlags & (int)HdPackOptions::NoSpriteLimit) { - EmulationSettings::SetFlags(EmulationFlags::RemoveSpriteLimit | EmulationFlags::AdaptiveSpriteLimit); + _settings->SetFlags(EmulationFlags::RemoveSpriteLimit | EmulationFlags::AdaptiveSpriteLimit); } _backgroundIndex = -1; diff --git a/Core/HdNesPack.h b/Core/HdNesPack.h index 73bcdc26..d1760d67 100644 --- a/Core/HdNesPack.h +++ b/Core/HdNesPack.h @@ -2,10 +2,13 @@ #include "stdafx.h" #include "HdData.h" +class EmulationSettings; + class HdNesPack { private: shared_ptr _hdData; + EmulationSettings *_settings; int32_t _backgroundIndex = -1; HdScreenInfo *_hdScreenInfo = nullptr; @@ -37,7 +40,7 @@ private: public: static constexpr uint32_t CurrentVersion = 102; - HdNesPack(shared_ptr hdData); + HdNesPack(shared_ptr hdData, EmulationSettings* settings); ~HdNesPack(); uint32_t GetScale(); diff --git a/Core/HdPackBuilder.cpp b/Core/HdPackBuilder.cpp index 0487b10a..a1479cbf 100644 --- a/Core/HdPackBuilder.cpp +++ b/Core/HdPackBuilder.cpp @@ -86,7 +86,7 @@ void HdPackBuilder::AddTile(HdPackTileInfo *tile, uint32_t usageCount) void HdPackBuilder::ProcessTile(uint32_t x, uint32_t y, uint16_t tileAddr, HdPpuTileInfo &tile, BaseMapper *mapper, bool isSprite, uint32_t chrBankHash, bool transparencyRequired) { if(_flags & HdPackRecordFlags::IgnoreOverscan) { - OverscanDimensions overscan = EmulationSettings::GetOverscanDimensions(); + OverscanDimensions overscan = _console->GetSettings()->GetOverscanDimensions(); if(x < overscan.Left || y < overscan.Top || (PPU::ScreenWidth - x - 1) < overscan.Right || (PPU::ScreenHeight - y - 1) < overscan.Bottom) { //Ignore tiles inside overscan return; @@ -133,7 +133,7 @@ void HdPackBuilder::GenerateHdTile(HdPackTileInfo *tile) { uint32_t hdScale = _hdData.Scale; - vector originalTile = tile->ToRgb(); + vector originalTile = tile->ToRgb(_console->GetSettings()->GetRgbPalette()); vector hdTile(8 * 8 * hdScale*hdScale, 0); switch(_filterType) { @@ -224,7 +224,7 @@ void HdPackBuilder::SaveHdPack() ss << "" << _hdData.Scale << std::endl; ss << "" << _console->GetRomInfo().Hash.Sha1 << std::endl; if(_flags & HdPackRecordFlags::IgnoreOverscan) { - OverscanDimensions overscan = EmulationSettings::GetOverscanDimensions(); + OverscanDimensions overscan = _console->GetSettings()->GetOverscanDimensions(); ss << "" << overscan.Top << "," << overscan.Right << "," << overscan.Bottom << "," << overscan.Left << std::endl; } diff --git a/Core/HdVideoFilter.cpp b/Core/HdVideoFilter.cpp index 280d6391..3242f474 100644 --- a/Core/HdVideoFilter.cpp +++ b/Core/HdVideoFilter.cpp @@ -4,10 +4,10 @@ #include "HdVideoFilter.h" #include "Console.h" -HdVideoFilter::HdVideoFilter(shared_ptr hdData) +HdVideoFilter::HdVideoFilter(shared_ptr console, shared_ptr hdData) : BaseVideoFilter(console) { _hdData = hdData; - _hdNesPack.reset(new HdNesPack(hdData)); + _hdNesPack.reset(new HdNesPack(hdData, console->GetSettings())); } FrameInfo HdVideoFilter::GetFrameInfo() diff --git a/Core/HdVideoFilter.h b/Core/HdVideoFilter.h index 829b1b7a..60879664 100644 --- a/Core/HdVideoFilter.h +++ b/Core/HdVideoFilter.h @@ -3,6 +3,7 @@ #include "BaseVideoFilter.h" class HdNesPack; +class Console; struct HdScreenInfo; struct HdPackData; @@ -15,7 +16,7 @@ private: unique_ptr _hdNesPack = nullptr; public: - HdVideoFilter(shared_ptr hdData); + HdVideoFilter(shared_ptr console, shared_ptr hdData); void ApplyFilter(uint16_t *ppuOutputBuffer) override; FrameInfo GetFrameInfo() override; diff --git a/Core/HistoryViewer.cpp b/Core/HistoryViewer.cpp index fa1dbde6..ea98a444 100644 --- a/Core/HistoryViewer.cpp +++ b/Core/HistoryViewer.cpp @@ -41,15 +41,18 @@ void HistoryViewer::SeekTo(uint32_t seekPosition) if(index < _history.size()) { _console->Pause(); - bool wasPaused = _console->GetPauseStatus(); - _console->SetPauseStatus(false); + bool wasPaused = _console->GetSettings()->CheckFlag(EmulationFlags::Paused); + _console->GetSettings()->ClearFlags(EmulationFlags::Paused); _position = index; RewindData rewindData = _history[_position]; rewindData.LoadState(_console); _console->GetSoundMixer()->StopAudio(true); _pollCounter = 0; - _console->SetPauseStatus(wasPaused); + + if(wasPaused) { + _console->GetSettings()->SetFlags(EmulationFlags::Paused); + } _console->Resume(); } @@ -77,7 +80,7 @@ void HistoryViewer::ProcessEndOfFrame() if(_position >= _history.size()) { //Reached the end of history data - _console->SetPauseStatus(true); + _console->GetSettings()->SetFlags(EmulationFlags::Paused); return; } diff --git a/Core/HoriTrack.h b/Core/HoriTrack.h index 2c6bf2c0..73ec52ad 100644 --- a/Core/HoriTrack.h +++ b/Core/HoriTrack.h @@ -13,7 +13,7 @@ protected: StandardController::InternalSetStateFromInput(); SetPressedState(StandardController::Buttons::A, KeyManager::IsMouseButtonPressed(MouseButton::LeftButton)); SetPressedState(StandardController::Buttons::B, KeyManager::IsMouseButtonPressed(MouseButton::RightButton)); - SetMovement(KeyManager::GetMouseMovement(EmulationSettings::GetMouseSensitivity(MouseDevice::HoriTrack))); + SetMovement(KeyManager::GetMouseMovement(_console->GetSettings()->GetMouseSensitivity(MouseDevice::HoriTrack))); } public: diff --git a/Core/JissenMahjongController.h b/Core/JissenMahjongController.h index 59b72ad1..87b94d5f 100644 --- a/Core/JissenMahjongController.h +++ b/Core/JissenMahjongController.h @@ -32,7 +32,7 @@ protected: } public: - JissenMahjongController(KeyMappingSet keyMappings) : BaseControlDevice(BaseControlDevice::ExpDevicePort, keyMappings) + JissenMahjongController(shared_ptr console, KeyMappingSet keyMappings) : BaseControlDevice(console, BaseControlDevice::ExpDevicePort, keyMappings) { } diff --git a/Core/KeyManager.cpp b/Core/KeyManager.cpp index 2db770e7..062ff507 100644 --- a/Core/KeyManager.cpp +++ b/Core/KeyManager.cpp @@ -5,10 +5,11 @@ #include "EmulationSettings.h" #include "PPU.h" -IKeyManager* KeyManager::_keyManager; -MousePosition KeyManager::_mousePosition; -atomic KeyManager::_xMouseMovement; -atomic KeyManager::_yMouseMovement; +IKeyManager* KeyManager::_keyManager = nullptr; +MousePosition KeyManager::_mousePosition = { 0, 0 }; +atomic KeyManager::_xMouseMovement = 0; +atomic KeyManager::_yMouseMovement = 0; +EmulationSettings* KeyManager::_settings = nullptr; void KeyManager::RegisterKeyManager(IKeyManager* keyManager) { @@ -22,10 +23,15 @@ void KeyManager::RefreshKeyState() } } +void KeyManager::SetSettings(EmulationSettings* settings) +{ + _settings = settings; +} + bool KeyManager::IsKeyPressed(uint32_t keyCode) { if(_keyManager != nullptr) { - return EmulationSettings::InputEnabled() && _keyManager->IsKeyPressed(keyCode); + return _settings->InputEnabled() && _keyManager->IsKeyPressed(keyCode); } return false; } @@ -33,7 +39,7 @@ bool KeyManager::IsKeyPressed(uint32_t keyCode) bool KeyManager::IsMouseButtonPressed(MouseButton button) { if(_keyManager != nullptr) { - return EmulationSettings::InputEnabled() && _keyManager->IsMouseButtonPressed(button); + return _settings->InputEnabled() && _keyManager->IsMouseButtonPressed(button); } return false; } @@ -77,7 +83,7 @@ void KeyManager::SetMouseMovement(int16_t x, int16_t y) MouseMovement KeyManager::GetMouseMovement(double mouseSensitivity) { - double factor = EmulationSettings::GetVideoScale() / mouseSensitivity; + double factor = _settings->GetVideoScale() / mouseSensitivity; MouseMovement mov; mov.dx = (int16_t)(_xMouseMovement / factor); mov.dy = (int16_t)(_yMouseMovement / factor); @@ -93,7 +99,7 @@ void KeyManager::SetMousePosition(double x, double y) _mousePosition.X = -1; _mousePosition.Y = -1; } else { - OverscanDimensions overscan = EmulationSettings::GetOverscanDimensions(); + OverscanDimensions overscan = _settings->GetOverscanDimensions(); _mousePosition.X = (int32_t)(x * (PPU::ScreenWidth - overscan.Left - overscan.Right) + overscan.Left); _mousePosition.Y = (int32_t)(y * (PPU::ScreenHeight - overscan.Top - overscan.Bottom) + overscan.Top); } diff --git a/Core/KeyManager.h b/Core/KeyManager.h index e73d7097..99e72d27 100644 --- a/Core/KeyManager.h +++ b/Core/KeyManager.h @@ -3,6 +3,7 @@ #include "Types.h" class IKeyManager; +class EmulationSettings; enum class MouseButton; class KeyManager @@ -12,9 +13,12 @@ private: static MousePosition _mousePosition; static atomic _xMouseMovement; static atomic _yMouseMovement; + static EmulationSettings* _settings; public: static void RegisterKeyManager(IKeyManager* keyManager); + static void SetSettings(EmulationSettings* settings); + static void RefreshKeyState(); static bool IsKeyPressed(uint32_t keyCode); static bool IsMouseButtonPressed(MouseButton button); diff --git a/Core/KonamiHyperShot.h b/Core/KonamiHyperShot.h index 22cd100f..250a62bb 100644 --- a/Core/KonamiHyperShot.h +++ b/Core/KonamiHyperShot.h @@ -6,8 +6,6 @@ class KonamiHyperShot : public BaseControlDevice { private: - shared_ptr _console; - bool _enableP1 = true; bool _enableP2 = true; uint32_t _p1TurboSpeed; @@ -56,9 +54,8 @@ protected: } public: - KonamiHyperShot(shared_ptr console, KeyMappingSet p1, KeyMappingSet p2) : BaseControlDevice(BaseControlDevice::ExpDevicePort, p1) + KonamiHyperShot(shared_ptr console, KeyMappingSet p1, KeyMappingSet p2) : BaseControlDevice(console, BaseControlDevice::ExpDevicePort, p1) { - _console = console; _p1TurboSpeed = p1.TurboSpeed; _p2TurboSpeed = p2.TurboSpeed; _p2KeyMappings = p2.GetKeyMappingArray(); diff --git a/Core/LuaApi.cpp b/Core/LuaApi.cpp index 5ed45352..56a532ee 100644 --- a/Core/LuaApi.cpp +++ b/Core/LuaApi.cpp @@ -399,7 +399,7 @@ int LuaApi::GetScreenBuffer(lua_State *lua) { LuaCallHelper l(lua); - uint32_t *palette = EmulationSettings::GetRgbPalette(); + uint32_t *palette = _console->GetSettings()->GetRgbPalette(); lua_newtable(lua); for(int y = 0; y < PPU::ScreenHeight; y++) { for(int x = 0; x < PPU::ScreenWidth; x++) { @@ -437,7 +437,7 @@ int LuaApi::GetPixel(lua_State *lua) errorCond(x < 0 || x > 255 || y < 0 || y > 239, "invalid x,y coordinates (must be between 0-255, 0-239)"); //Ignores intensify & grayscale bits - l.Return(EmulationSettings::GetRgbPalette()[_debugger->GetScreenPixel(x, y) & 0x3F] & 0xFFFFFF); + l.Return(_console->GetSettings()->GetRgbPalette()[_debugger->GetScreenPixel(x, y) & 0x3F] & 0xFFFFFF); return l.ReturnCount(); } diff --git a/Core/MMC3.h b/Core/MMC3.h index 3def0264..1b655f71 100644 --- a/Core/MMC3.h +++ b/Core/MMC3.h @@ -300,7 +300,7 @@ class MMC3 : public BaseMapper } //SubMapper 2 = MC-ACC (Acclaim MMC3 clone) - if(!IsMcAcc() && (ForceMmc3RevAIrqs() || EmulationSettings::CheckFlag(EmulationFlags::Mmc3IrqAltBehavior))) { + if(!IsMcAcc() && (ForceMmc3RevAIrqs() || _console->GetSettings()->CheckFlag(EmulationFlags::Mmc3IrqAltBehavior))) { //MMC3 Revision A behavior if((count > 0 || _irqReload) && _irqCounter == 0 && _irqEnabled) { TriggerIrq(); diff --git a/Core/MapperFactory.cpp b/Core/MapperFactory.cpp index 910f6d5a..9550135d 100644 --- a/Core/MapperFactory.cpp +++ b/Core/MapperFactory.cpp @@ -667,6 +667,14 @@ shared_ptr MapperFactory::InitializeFromFile(shared_ptr con if(loader.LoadFile(romFilename, fileData)) { RomData romData = loader.GetRomData(); + + if(romData.Info.IsInDatabase || romData.Info.IsNes20Header) { + //If in DB or a NES 2.0 file, auto-configure the inputs + if(console->GetSettings()->CheckFlag(EmulationFlags::AutoConfigureInput)) { + console->GetSettings()->InitializeInputDevices(romData.Info.InputType, romData.Info.System, false); + } + } + shared_ptr mapper(GetMapperFromID(romData)); if(mapper) { diff --git a/Core/MemoryDumper.cpp b/Core/MemoryDumper.cpp index 78f888d7..c5a2813c 100644 --- a/Core/MemoryDumper.cpp +++ b/Core/MemoryDumper.cpp @@ -270,7 +270,7 @@ uint8_t MemoryDumper::GetMemoryValue(DebugMemoryType memoryType, uint32_t addres void MemoryDumper::GetNametable(int nametableIndex, bool useGrayscalePalette, uint32_t* frameBuffer, uint8_t* tileData, uint8_t* paletteData) { shared_ptr mmc5 = std::dynamic_pointer_cast(_mapper); - uint32_t *rgbPalette = EmulationSettings::GetRgbPalette(); + uint32_t *rgbPalette = _debugger->GetConsole()->GetSettings()->GetRgbPalette(); PPUDebugState state; _ppu->GetState(state); uint16_t bgAddr = state.ControlFlags.BackgroundPatternAddr; @@ -418,7 +418,7 @@ void MemoryDumper::GetChrBank(int bankIndex, uint32_t* frameBuffer, uint8_t pale (_ppu->ReadPaletteRAM(paletteBaseAddr + 3) << 24); } - uint32_t *rgbPalette = EmulationSettings::GetRgbPalette(); + uint32_t *rgbPalette = _debugger->GetConsole()->GetSettings()->GetRgbPalette(); uint8_t chrBuffer[0x1000]; bool chrIsDrawn[0x1000]; bool isChrRam = _mapper->GetMemorySize(DebugMemoryType::ChrRam) > 0; @@ -502,7 +502,7 @@ void MemoryDumper::GetSprites(uint32_t* frameBuffer) memset(frameBuffer, 0, 64*128*sizeof(uint32_t)); uint8_t *spriteRam = _ppu->GetSpriteRam(); - uint32_t *rgbPalette = EmulationSettings::GetRgbPalette(); + uint32_t *rgbPalette = _debugger->GetConsole()->GetSettings()->GetRgbPalette(); PPUDebugState state; _ppu->GetState(state); @@ -562,7 +562,7 @@ void MemoryDumper::GetSprites(uint32_t* frameBuffer) void MemoryDumper::GetPalette(uint32_t* frameBuffer) { - uint32_t *rgbPalette = EmulationSettings::GetRgbPalette(); + uint32_t *rgbPalette = _debugger->GetConsole()->GetSettings()->GetRgbPalette(); for(uint8_t i = 0; i < 32; i++) { frameBuffer[i] = rgbPalette[_ppu->ReadPaletteRAM(i) & 0x3F]; } diff --git a/Core/MemoryManager.cpp b/Core/MemoryManager.cpp index 57332a5b..35b01630 100644 --- a/Core/MemoryManager.cpp +++ b/Core/MemoryManager.cpp @@ -13,7 +13,7 @@ MemoryManager::MemoryManager(shared_ptr console) for(int i = 0; i < 2; i++) { _nametableRAM[i] = new uint8_t[NameTableScreenSize]; - BaseMapper::InitializeRam(_nametableRAM[i], NameTableScreenSize); + _console->GetMapper()->InitializeRam(_nametableRAM[i], NameTableScreenSize); } _ramReadHandlers = new IMemoryHandler*[RAMSize]; @@ -47,7 +47,7 @@ void MemoryManager::SetMapper(shared_ptr mapper) void MemoryManager::Reset(bool softReset) { if(!softReset) { - BaseMapper::InitializeRam(_internalRAM, InternalRAMSize); + _mapper->InitializeRam(_internalRAM, InternalRAMSize); } _mapper->Reset(softReset); diff --git a/Core/MesenMovie.cpp b/Core/MesenMovie.cpp index a33606eb..c7366da0 100644 --- a/Core/MesenMovie.cpp +++ b/Core/MesenMovie.cpp @@ -28,10 +28,16 @@ MesenMovie::~MesenMovie() void MesenMovie::Stop() { if(_playing) { - EndMovie(); + MessageManager::DisplayMessage("Movies", "MovieEnded"); + + _console->GetNotificationManager()->SendNotification(ConsoleNotificationType::MovieEnded); + if(_console->GetSettings()->CheckFlag(EmulationFlags::PauseOnMovieEnd)) { + _console->GetSettings()->SetFlags(EmulationFlags::Paused); + } + _playing = false; } - EmulationSettings::SetInputPollScanline(241); + _console->GetSettings()->SetInputPollScanline(241); _console->GetControlManager()->UnregisterInputProvider(this); } @@ -111,11 +117,11 @@ bool MesenMovie::Play(VirtualFile &file) ApplySettings(); //Disable auto-configure input option (otherwise the movie file's input types are ignored) - bool autoConfigureInput = EmulationSettings::CheckFlag(EmulationFlags::AutoConfigureInput); - EmulationSettings::ClearFlags(EmulationFlags::AutoConfigureInput); + bool autoConfigureInput = _console->GetSettings()->CheckFlag(EmulationFlags::AutoConfigureInput); + _console->GetSettings()->ClearFlags(EmulationFlags::AutoConfigureInput); _console->GetControlManager()->SetPollCounter(0); bool gameLoaded = LoadGame(); - EmulationSettings::SetFlagState(EmulationFlags::AutoConfigureInput, autoConfigureInput); + _console->GetSettings()->SetFlagState(EmulationFlags::AutoConfigureInput, autoConfigureInput); if(!gameLoaded) { _console->Resume(); @@ -181,7 +187,7 @@ bool MesenMovie::LoadGame() //string patchFileSha1 = LoadString(_settings, MovieKeys::PatchFileSha1); //string patchedRomSha1 = LoadString(_settings, MovieKeys::PatchedRomSha1); - if(EmulationSettings::CheckFlag(EmulationFlags::AllowMismatchingSaveState) && _console->GetRomInfo().RomName == gameFile) { + if(_console->GetSettings()->CheckFlag(EmulationFlags::AllowMismatchingSaveState) && _console->GetRomInfo().RomName == gameFile) { //Loaded game has the right name, and we don't want to validate the hash values _console->PowerCycle(); return true; @@ -206,6 +212,8 @@ bool MesenMovie::LoadGame() void MesenMovie::ApplySettings() { + EmulationSettings* settings = _console->GetSettings(); + NesModel region = FromString(LoadString(_settings, MovieKeys::Region), NesModelNames, NesModel::NTSC); ConsoleType consoleType = FromString(LoadString(_settings, MovieKeys::ConsoleType), ConsoleTypeNames, ConsoleType::Nes); ControllerType controller1 = FromString(LoadString(_settings, MovieKeys::Controller1), ControllerTypeNames, ControllerType::None); @@ -214,47 +222,47 @@ void MesenMovie::ApplySettings() ControllerType controller4 = FromString(LoadString(_settings, MovieKeys::Controller4), ControllerTypeNames, ControllerType::None); ExpansionPortDevice expansionDevice = FromString(LoadString(_settings, MovieKeys::ExpansionDevice), ExpansionPortDeviceNames, ExpansionPortDevice::None); - EmulationSettings::SetNesModel(region); - EmulationSettings::SetConsoleType(consoleType); - EmulationSettings::SetControllerType(0, controller1); - EmulationSettings::SetControllerType(1, controller2); - EmulationSettings::SetControllerType(2, controller3); - EmulationSettings::SetControllerType(3, controller4); - EmulationSettings::SetExpansionDevice(expansionDevice); + settings->SetNesModel(region); + settings->SetConsoleType(consoleType); + settings->SetControllerType(0, controller1); + settings->SetControllerType(1, controller2); + settings->SetControllerType(2, controller3); + settings->SetControllerType(3, controller4); + settings->SetExpansionDevice(expansionDevice); uint32_t ramPowerOnState = LoadInt(_settings, MovieKeys::RamPowerOnState); if(ramPowerOnState == 0xFF) { - EmulationSettings::SetRamPowerOnState(RamPowerOnState::AllOnes); + settings->SetRamPowerOnState(RamPowerOnState::AllOnes); } else { - EmulationSettings::SetRamPowerOnState(RamPowerOnState::AllZeros); + settings->SetRamPowerOnState(RamPowerOnState::AllZeros); } - EmulationSettings::SetInputPollScanline(LoadInt(_settings, MovieKeys::InputPollScanline, 240)); + settings->SetInputPollScanline(LoadInt(_settings, MovieKeys::InputPollScanline, 240)); - EmulationSettings::SetZapperDetectionRadius(LoadInt(_settings, MovieKeys::ZapperDetectionRadius)); + settings->SetZapperDetectionRadius(LoadInt(_settings, MovieKeys::ZapperDetectionRadius)); uint32_t cpuClockRate = LoadInt(_settings, MovieKeys::CpuClockRate); if(cpuClockRate != 100) { bool adjustApu = LoadBool(_settings, MovieKeys::OverclockAdjustApu); - EmulationSettings::SetOverclockRate(cpuClockRate, adjustApu); + settings->SetOverclockRate(cpuClockRate, adjustApu); } else { - EmulationSettings::SetOverclockRate(100, true); + settings->SetOverclockRate(100, true); } - EmulationSettings::SetPpuNmiConfig( + settings->SetPpuNmiConfig( LoadInt(_settings, MovieKeys::ExtraScanlinesBeforeNmi), LoadInt(_settings, MovieKeys::ExtraScanlinesAfterNmi) ); - EmulationSettings::SetFlagState(EmulationFlags::DisablePpu2004Reads, LoadBool(_settings, MovieKeys::DisablePpu2004Reads)); - EmulationSettings::SetFlagState(EmulationFlags::DisablePaletteRead, LoadBool(_settings, MovieKeys::DisablePaletteRead)); - EmulationSettings::SetFlagState(EmulationFlags::DisableOamAddrBug, LoadBool(_settings, MovieKeys::DisableOamAddrBug)); - EmulationSettings::SetFlagState(EmulationFlags::UseNes101Hvc101Behavior, LoadBool(_settings, MovieKeys::UseNes101Hvc101Behavior)); - EmulationSettings::SetFlagState(EmulationFlags::EnableOamDecay, LoadBool(_settings, MovieKeys::EnableOamDecay)); - EmulationSettings::SetFlagState(EmulationFlags::DisablePpuReset, LoadBool(_settings, MovieKeys::DisablePpuReset)); + settings->SetFlagState(EmulationFlags::DisablePpu2004Reads, LoadBool(_settings, MovieKeys::DisablePpu2004Reads)); + settings->SetFlagState(EmulationFlags::DisablePaletteRead, LoadBool(_settings, MovieKeys::DisablePaletteRead)); + settings->SetFlagState(EmulationFlags::DisableOamAddrBug, LoadBool(_settings, MovieKeys::DisableOamAddrBug)); + settings->SetFlagState(EmulationFlags::UseNes101Hvc101Behavior, LoadBool(_settings, MovieKeys::UseNes101Hvc101Behavior)); + settings->SetFlagState(EmulationFlags::EnableOamDecay, LoadBool(_settings, MovieKeys::EnableOamDecay)); + settings->SetFlagState(EmulationFlags::DisablePpuReset, LoadBool(_settings, MovieKeys::DisablePpuReset)); //VS System flags - EmulationSettings::SetDipSwitches(HexUtilities::FromHex(LoadString(_settings, MovieKeys::DipSwitches))); + settings->SetDipSwitches(HexUtilities::FromHex(LoadString(_settings, MovieKeys::DipSwitches))); LoadCheats(); } diff --git a/Core/MessageManager.cpp b/Core/MessageManager.cpp index b0b705b3..fd8d6a5e 100644 --- a/Core/MessageManager.cpp +++ b/Core/MessageManager.cpp @@ -605,6 +605,7 @@ std::unordered_map MessageManager::_caResources = { std::list MessageManager::_log; SimpleLock MessageManager::_logLock; +bool MessageManager::_osdEnabled = false; IMessageManager* MessageManager::_messageManager = nullptr; void MessageManager::RegisterMessageManager(IMessageManager* messageManager) @@ -612,6 +613,11 @@ void MessageManager::RegisterMessageManager(IMessageManager* messageManager) MessageManager::_messageManager = messageManager; } +void MessageManager::SetOsdState(bool enabled) +{ + _osdEnabled = enabled; +} + string MessageManager::Localize(string key) { std::unordered_map *resources = nullptr; @@ -656,10 +662,10 @@ void MessageManager::DisplayMessage(string title, string message, string param1, message.replace(startPos, 2, param2); } - if(EmulationSettings::CheckFlag(EmulationFlags::DisableOsd)) { - MessageManager::Log("[" + title + "] " + message); - } else { + if(_osdEnabled) { MessageManager::_messageManager->DisplayMessage(title, message); + } else { + MessageManager::Log("[" + title + "] " + message); } } } diff --git a/Core/MessageManager.h b/Core/MessageManager.h index 38089050..293bcbe0 100644 --- a/Core/MessageManager.h +++ b/Core/MessageManager.h @@ -19,10 +19,13 @@ private: static std::unordered_map _ptResources; static std::unordered_map _caResources; + static bool _osdEnabled; static SimpleLock _logLock; static std::list _log; public: + static void SetOsdState(bool enabled); + static string Localize(string key); static void RegisterMessageManager(IMessageManager* messageManager); diff --git a/Core/MovieManager.h b/Core/MovieManager.h index 876bac75..b2761ffc 100644 --- a/Core/MovieManager.h +++ b/Core/MovieManager.h @@ -11,19 +11,6 @@ class Console; class IMovie : public IInputProvider { -protected: - void EndMovie() - { - MessageManager::DisplayMessage("Movies", "MovieEnded"); - - //TODOCONSOLE - //MessageManager::SendNotification(ConsoleNotificationType::MovieEnded); - - if(EmulationSettings::CheckFlag(EmulationFlags::PauseOnMovieEnd)) { - EmulationSettings::SetFlags(EmulationFlags::Paused); - } - } - public: virtual bool Play(VirtualFile &file) = 0; virtual bool IsPlaying() = 0; diff --git a/Core/MovieRecorder.cpp b/Core/MovieRecorder.cpp index 6b019015..c3dbf377 100644 --- a/Core/MovieRecorder.cpp +++ b/Core/MovieRecorder.cpp @@ -65,9 +65,10 @@ bool MovieRecorder::Record(RecordMovieOptions options) void MovieRecorder::GetGameSettings(stringstream &out) { + EmulationSettings* settings = _console->GetSettings(); NesModel model = _console->GetModel(); - WriteString(out, MovieKeys::MesenVersion, EmulationSettings::GetMesenVersionString()); + WriteString(out, MovieKeys::MesenVersion, settings->GetMesenVersionString()); WriteInt(out, MovieKeys::MovieFormatVersion, MovieRecorder::MovieFormatVersion); VirtualFile romFile = _console->GetRomPath(); @@ -88,40 +89,40 @@ void MovieRecorder::GetGameSettings(stringstream &out) case NesModel::Dendy: WriteString(out, MovieKeys::Region, "Dendy"); break; } - switch(EmulationSettings::GetConsoleType()) { + switch(settings->GetConsoleType()) { case ConsoleType::Nes: WriteString(out, MovieKeys::ConsoleType, "NES"); break; case ConsoleType::Famicom: WriteString(out, MovieKeys::ConsoleType, "Famicom"); break; } - WriteString(out, MovieKeys::Controller1, ControllerTypeNames[(int)EmulationSettings::GetControllerType(0)]); - WriteString(out, MovieKeys::Controller2, ControllerTypeNames[(int)EmulationSettings::GetControllerType(1)]); - if(EmulationSettings::CheckFlag(EmulationFlags::HasFourScore)) { - WriteString(out, MovieKeys::Controller3, ControllerTypeNames[(int)EmulationSettings::GetControllerType(2)]); - WriteString(out, MovieKeys::Controller4, ControllerTypeNames[(int)EmulationSettings::GetControllerType(3)]); + WriteString(out, MovieKeys::Controller1, ControllerTypeNames[(int)settings->GetControllerType(0)]); + WriteString(out, MovieKeys::Controller2, ControllerTypeNames[(int)settings->GetControllerType(1)]); + if(settings->CheckFlag(EmulationFlags::HasFourScore)) { + WriteString(out, MovieKeys::Controller3, ControllerTypeNames[(int)settings->GetControllerType(2)]); + WriteString(out, MovieKeys::Controller4, ControllerTypeNames[(int)settings->GetControllerType(3)]); } - if(EmulationSettings::GetConsoleType() == ConsoleType::Famicom) { - WriteString(out, MovieKeys::ExpansionDevice, ExpansionPortDeviceNames[(int)EmulationSettings::GetExpansionDevice()]); + if(settings->GetConsoleType() == ConsoleType::Famicom) { + WriteString(out, MovieKeys::ExpansionDevice, ExpansionPortDeviceNames[(int)settings->GetExpansionDevice()]); } - WriteInt(out, MovieKeys::CpuClockRate, EmulationSettings::GetOverclockRateSetting()); - WriteInt(out, MovieKeys::ExtraScanlinesBeforeNmi, EmulationSettings::GetPpuExtraScanlinesBeforeNmi()); - WriteInt(out, MovieKeys::ExtraScanlinesAfterNmi, EmulationSettings::GetPpuExtraScanlinesAfterNmi()); - WriteInt(out, MovieKeys::InputPollScanline, EmulationSettings::GetInputPollScanline()); + WriteInt(out, MovieKeys::CpuClockRate, settings->GetOverclockRateSetting()); + WriteInt(out, MovieKeys::ExtraScanlinesBeforeNmi, settings->GetPpuExtraScanlinesBeforeNmi()); + WriteInt(out, MovieKeys::ExtraScanlinesAfterNmi, settings->GetPpuExtraScanlinesAfterNmi()); + WriteInt(out, MovieKeys::InputPollScanline, settings->GetInputPollScanline()); - if(EmulationSettings::GetOverclockRateSetting() != 100) { - WriteBool(out, MovieKeys::OverclockAdjustApu, EmulationSettings::GetOverclockAdjustApu()); + if(settings->GetOverclockRateSetting() != 100) { + WriteBool(out, MovieKeys::OverclockAdjustApu, settings->GetOverclockAdjustApu()); } - WriteBool(out, MovieKeys::DisablePpu2004Reads, EmulationSettings::CheckFlag(EmulationFlags::DisablePpu2004Reads)); - WriteBool(out, MovieKeys::DisablePaletteRead, EmulationSettings::CheckFlag(EmulationFlags::DisablePaletteRead)); - WriteBool(out, MovieKeys::DisableOamAddrBug, EmulationSettings::CheckFlag(EmulationFlags::DisableOamAddrBug)); - WriteBool(out, MovieKeys::UseNes101Hvc101Behavior, EmulationSettings::CheckFlag(EmulationFlags::UseNes101Hvc101Behavior)); - WriteBool(out, MovieKeys::EnableOamDecay, EmulationSettings::CheckFlag(EmulationFlags::EnableOamDecay)); - WriteBool(out, MovieKeys::DisablePpuReset, EmulationSettings::CheckFlag(EmulationFlags::DisablePpuReset)); + WriteBool(out, MovieKeys::DisablePpu2004Reads, settings->CheckFlag(EmulationFlags::DisablePpu2004Reads)); + WriteBool(out, MovieKeys::DisablePaletteRead, settings->CheckFlag(EmulationFlags::DisablePaletteRead)); + WriteBool(out, MovieKeys::DisableOamAddrBug, settings->CheckFlag(EmulationFlags::DisableOamAddrBug)); + WriteBool(out, MovieKeys::UseNes101Hvc101Behavior, settings->CheckFlag(EmulationFlags::UseNes101Hvc101Behavior)); + WriteBool(out, MovieKeys::EnableOamDecay, settings->CheckFlag(EmulationFlags::EnableOamDecay)); + WriteBool(out, MovieKeys::DisablePpuReset, settings->CheckFlag(EmulationFlags::DisablePpuReset)); - WriteInt(out, MovieKeys::ZapperDetectionRadius, EmulationSettings::GetZapperDetectionRadius()); + WriteInt(out, MovieKeys::ZapperDetectionRadius, settings->GetZapperDetectionRadius()); - switch(EmulationSettings::GetRamPowerOnState()) { + switch(settings->GetRamPowerOnState()) { case RamPowerOnState::AllZeros: WriteInt(out, MovieKeys::RamPowerOnState, 0x00); break; case RamPowerOnState::AllOnes: WriteInt(out, MovieKeys::RamPowerOnState, 0xFF); break; case RamPowerOnState::Random: WriteInt(out, MovieKeys::RamPowerOnState, -1); break; //TODO: Shouldn't be used for movies @@ -129,7 +130,7 @@ void MovieRecorder::GetGameSettings(stringstream &out) //VS System flags if(_console->GetAvailableFeatures() == ConsoleFeatures::VsSystem) { - WriteString(out, MovieKeys::DipSwitches, HexUtilities::ToHex(EmulationSettings::GetDipSwitches())); + WriteString(out, MovieKeys::DipSwitches, HexUtilities::ToHex(settings->GetDipSwitches())); } for(CodeInfo &code : _console->GetCheatManager()->GetCheats()) { diff --git a/Core/NoiseChannel.h b/Core/NoiseChannel.h index e4197292..27d78714 100644 --- a/Core/NoiseChannel.h +++ b/Core/NoiseChannel.h @@ -26,7 +26,7 @@ protected: void Clock() override { //Feedback is calculated as the exclusive-OR of bit 0 and one other bit: bit 6 if Mode flag is set, otherwise bit 1. - bool mode = EmulationSettings::CheckFlag(EmulationFlags::DisableNoiseModeFlag) ? false : _modeFlag; + bool mode = _console->GetSettings()->CheckFlag(EmulationFlags::DisableNoiseModeFlag) ? false : _modeFlag; uint16_t feedback = (_shiftRegister & 0x01) ^ ((_shiftRegister >> (mode ? 6 : 1)) & 0x01); _shiftRegister >>= 1; diff --git a/Core/NsfMapper.cpp b/Core/NsfMapper.cpp index d58aef9e..cf6ab6da 100644 --- a/Core/NsfMapper.cpp +++ b/Core/NsfMapper.cpp @@ -10,17 +10,17 @@ NsfMapper* NsfMapper::_instance; NsfMapper::NsfMapper() { _instance = this; - EmulationSettings::DisableOverclocking(true); - EmulationSettings::ClearFlags(EmulationFlags::Paused); - EmulationSettings::SetFlags(EmulationFlags::NsfPlayerEnabled); + _console->GetSettings()->DisableOverclocking(true); + _console->GetSettings()->ClearFlags(EmulationFlags::Paused); + _console->GetSettings()->SetFlags(EmulationFlags::NsfPlayerEnabled); } NsfMapper::~NsfMapper() { if(_instance == this) { _instance = nullptr; - EmulationSettings::DisableOverclocking(false); - EmulationSettings::ClearFlags(EmulationFlags::NsfPlayerEnabled); + _console->GetSettings()->DisableOverclocking(false); + _console->GetSettings()->ClearFlags(EmulationFlags::NsfPlayerEnabled); } } @@ -187,7 +187,7 @@ void NsfMapper::ClockLengthAndFadeCounters() } } - if((_trackEndCounter < 0 || _allowSilenceDetection) && EmulationSettings::GetNsfAutoDetectSilenceDelay() > 0) { + if((_trackEndCounter < 0 || _allowSilenceDetection) && _console->GetSettings()->GetNsfAutoDetectSilenceDelay() > 0) { //No track length specified if(_console->GetSoundMixer()->GetMuteFrameCount() * SoundMixer::CycleLength > _silenceDetectDelay) { //Auto detect end of track after AutoDetectSilenceDelay (in ms) has gone by without sound @@ -213,8 +213,8 @@ void NsfMapper::ClockLengthAndFadeCounters() void NsfMapper::SelectNextTrack() { - if(!EmulationSettings::CheckFlag(EmulationFlags::NsfRepeat)) { - if(EmulationSettings::CheckFlag(EmulationFlags::NsfShuffle)) { + if(!_console->GetSettings()->CheckFlag(EmulationFlags::NsfRepeat)) { + if(_console->GetSettings()->CheckFlag(EmulationFlags::NsfShuffle)) { std::random_device rd; std::mt19937 mt(rd()); std::uniform_int_distribution<> dist(0, _nsfHeader.TotalSongs - 1); @@ -229,7 +229,7 @@ void NsfMapper::SelectNextTrack() void NsfMapper::ProcessCpuClock() { - _console->GetCpu()->SetIrqMask(EmulationSettings::GetNsfDisableApuIrqs() ? (uint8_t)IRQSource::External : 0xFF); + _console->GetCpu()->SetIrqMask(_console->GetSettings()->GetNsfDisableApuIrqs() ? (uint8_t)IRQSource::External : 0xFF); if(_needInit) { TriggerIrq(NsfIrqType::Init); @@ -422,7 +422,7 @@ void NsfMapper::InternalSelectTrack(uint8_t trackNumber, bool requestReset) //Only apply a maximum duration to multi-track NSFs //Single track NSFs will loop or restart after a portion of silence //Substract 1 sec from default track time to account for 1 sec default fade time - _trackEndCounter = (EmulationSettings::GetNsfMoveToNextTrackTime() - 1) * GetClockRate(); + _trackEndCounter = (_console->GetSettings()->GetNsfMoveToNextTrackTime() - 1) * GetClockRate(); _allowSilenceDetection = true; } if(_nsfHeader.TrackFade[trackNumber] >= 0) { @@ -432,7 +432,7 @@ void NsfMapper::InternalSelectTrack(uint8_t trackNumber, bool requestReset) _trackFadeCounter = GetClockRate(); } - _silenceDetectDelay = (uint32_t)((double)EmulationSettings::GetNsfAutoDetectSilenceDelay() / 1000.0 * GetClockRate()); + _silenceDetectDelay = (uint32_t)((double)_console->GetSettings()->GetNsfAutoDetectSilenceDelay() / 1000.0 * GetClockRate()); _fadeLength = _trackFadeCounter; TriggerIrq(NsfIrqType::Init); diff --git a/Core/NtscFilter.cpp b/Core/NtscFilter.cpp index 47000f61..dcc75f8f 100644 --- a/Core/NtscFilter.cpp +++ b/Core/NtscFilter.cpp @@ -2,8 +2,9 @@ #include "NtscFilter.h" #include "PPU.h" #include "EmulationSettings.h" +#include "Console.h" -NtscFilter::NtscFilter() +NtscFilter::NtscFilter(shared_ptr console) : BaseVideoFilter(console) { memset(_basePalette, 0, 64 * 3); _ntscData = new nes_ntsc_t(); @@ -39,7 +40,7 @@ FrameInfo NtscFilter::GetFrameInfo() void NtscFilter::OnBeforeApplyFilter() { bool paletteChanged = false; - uint32_t* palette = EmulationSettings::GetRgbPalette(); + uint32_t* palette = _console->GetSettings()->GetRgbPalette(); for(int i = 0; i < 64; i++) { uint8_t r = (palette[i] >> 16) & 0xFF; uint8_t g = (palette[i] >> 8) & 0xFF; @@ -54,8 +55,8 @@ void NtscFilter::OnBeforeApplyFilter() } } - PictureSettings pictureSettings = EmulationSettings::GetPictureSettings(); - NtscFilterSettings ntscSettings = EmulationSettings::GetNtscFilterSettings(); + PictureSettings pictureSettings = _console->GetSettings()->GetPictureSettings(); + NtscFilterSettings ntscSettings = _console->GetSettings()->GetNtscFilterSettings(); _keepVerticalRes = ntscSettings.KeepVerticalResolution; @@ -76,7 +77,7 @@ void NtscFilter::OnBeforeApplyFilter() _ntscSetup.resolution = ntscSettings.Resolution; _ntscSetup.sharpness = ntscSettings.Sharpness; - _ntscSetup.base_palette = EmulationSettings::IsDefaultPalette() ? nullptr : _basePalette; + _ntscSetup.base_palette = _console->GetSettings()->IsDefaultPalette() ? nullptr : _basePalette; nes_ntsc_init(_ntscData, &_ntscSetup); } @@ -105,8 +106,8 @@ void NtscFilter::GenerateArgbFrame(uint32_t *ntscBuffer) ntscBuffer += rowWidth; } } else { - double scanlineIntensity = 1.0 - EmulationSettings::GetPictureSettings().ScanlineIntensity; - bool verticalBlend = EmulationSettings::GetNtscFilterSettings().VerticalBlend; + double scanlineIntensity = 1.0 - _console->GetSettings()->GetPictureSettings().ScanlineIntensity; + bool verticalBlend = _console->GetSettings()->GetNtscFilterSettings().VerticalBlend; for(int y = PPU::ScreenHeight - 1 - overscan.Bottom; y >= (int)overscan.Top; y--) { uint32_t const* in = ntscBuffer + y * rowWidth; diff --git a/Core/NtscFilter.h b/Core/NtscFilter.h index 93889929..934b1a7c 100644 --- a/Core/NtscFilter.h +++ b/Core/NtscFilter.h @@ -3,6 +3,8 @@ #include "BaseVideoFilter.h" #include "../Utilities/nes_ntsc.h" +class Console; + class NtscFilter : public BaseVideoFilter { private: @@ -18,7 +20,7 @@ protected: void OnBeforeApplyFilter(); public: - NtscFilter(); + NtscFilter(shared_ptr console); virtual ~NtscFilter(); virtual void ApplyFilter(uint16_t *ppuOutputBuffer); diff --git a/Core/OekaKidsTablet.h b/Core/OekaKidsTablet.h index db505a16..9006cef8 100644 --- a/Core/OekaKidsTablet.h +++ b/Core/OekaKidsTablet.h @@ -1,6 +1,8 @@ #pragma once #include "stdafx.h" #include "BaseControlDevice.h" +#include "Console.h" +#include "EmulationSettings.h" class OekaKidsTablet : public BaseControlDevice { @@ -20,7 +22,7 @@ protected: void InternalSetStateFromInput() override { - if(EmulationSettings::InputEnabled()) { + if(_console->GetSettings()->InputEnabled()) { MousePosition pos = KeyManager::GetMousePosition(); SetPressedState(Buttons::Click, KeyManager::IsMouseButtonPressed(MouseButton::LeftButton)); SetPressedState(Buttons::Touch, pos.Y >= 48 || KeyManager::IsMouseButtonPressed(MouseButton::LeftButton)); @@ -35,7 +37,7 @@ protected: } public: - OekaKidsTablet() : BaseControlDevice(BaseControlDevice::ExpDevicePort) + OekaKidsTablet(shared_ptr console) : BaseControlDevice(console, BaseControlDevice::ExpDevicePort) { } diff --git a/Core/OggMixer.cpp b/Core/OggMixer.cpp index 401095c1..03319e67 100644 --- a/Core/OggMixer.cpp +++ b/Core/OggMixer.cpp @@ -10,17 +10,16 @@ enum class OggPlaybackOptions OggMixer::OggMixer() { - Reset(); } -void OggMixer::Reset() +void OggMixer::Reset(uint32_t sampleRate) { _bgm.reset(); _sfx.clear(); _sfxVolume = 128; _bgmVolume = 128; _options = 0; - _sampleRate = EmulationSettings::GetSampleRate(); + _sampleRate = sampleRate; _paused = false; } @@ -95,16 +94,16 @@ bool OggMixer::Play(string filename, bool isSfx, uint32_t startOffset) return false; } -void OggMixer::ApplySamples(int16_t * buffer, size_t sampleCount) +void OggMixer::ApplySamples(int16_t * buffer, size_t sampleCount, double masterVolumne) { if(_bgm && !_paused) { - _bgm->ApplySamples(buffer, sampleCount, _bgmVolume); + _bgm->ApplySamples(buffer, sampleCount, _bgmVolume, masterVolumne); if(_bgm->IsPlaybackOver()) { _bgm.reset(); } } for(shared_ptr &sfx : _sfx) { - sfx->ApplySamples(buffer, sampleCount, _sfxVolume); + sfx->ApplySamples(buffer, sampleCount, _sfxVolume, masterVolumne); } _sfx.erase(std::remove_if(_sfx.begin(), _sfx.end(), [](const shared_ptr& o) { return o->IsPlaybackOver(); }), _sfx.end()); } diff --git a/Core/OggMixer.h b/Core/OggMixer.h index 6786b016..2eb00058 100644 --- a/Core/OggMixer.h +++ b/Core/OggMixer.h @@ -19,9 +19,9 @@ public: OggMixer(); void SetSampleRate(int sampleRate); - void ApplySamples(int16_t* buffer, size_t sampleCount); + void ApplySamples(int16_t* buffer, size_t sampleCount, double masterVolumne); - void Reset(); + void Reset(uint32_t sampleRate); bool Play(string filename, bool isSfx, uint32_t startOffset); void SetPlaybackOptions(uint8_t options); void SetPausedFlag(bool paused); diff --git a/Core/OggReader.cpp b/Core/OggReader.cpp index dcf5f908..86018f57 100644 --- a/Core/OggReader.cpp +++ b/Core/OggReader.cpp @@ -88,7 +88,7 @@ bool OggReader::LoadSamples() return samplesReturned > 0; } -void OggReader::ApplySamples(int16_t * buffer, size_t sampleCount, uint8_t volume) +void OggReader::ApplySamples(int16_t * buffer, size_t sampleCount, uint8_t volume, double masterVolume) { while(blip_samples_avail(_blipLeft) < (int)sampleCount) { if(!LoadSamples()) { @@ -100,7 +100,7 @@ void OggReader::ApplySamples(int16_t * buffer, size_t sampleCount, uint8_t volum blip_read_samples(_blipRight, _outputBuffer + 1, (int)sampleCount, 1); for(size_t i = 0, len = samplesRead * 2; i < len; i++) { - buffer[i] += (int16_t)(_outputBuffer[i] * (EmulationSettings::GetMasterVolume() * volume / 255 / 10)); + buffer[i] += (int16_t)(_outputBuffer[i] * (masterVolume * volume / 255 / 10)); } } diff --git a/Core/OggReader.h b/Core/OggReader.h index 7e03c584..f3d84bc7 100644 --- a/Core/OggReader.h +++ b/Core/OggReader.h @@ -3,7 +3,6 @@ #include "../Utilities/stb_vorbis.h" #include "../Utilities/blip_buf.h" #include "VirtualFile.h" -#include "EmulationSettings.h" class OggReader { @@ -35,6 +34,6 @@ public: bool IsPlaybackOver(); void SetSampleRate(int sampleRate); void SetLoopFlag(bool loop); - void ApplySamples(int16_t* buffer, size_t sampleCount, uint8_t volume); + void ApplySamples(int16_t* buffer, size_t sampleCount, uint8_t volume, double masterVolume); uint32_t GetOffset(); }; diff --git a/Core/PPU.cpp b/Core/PPU.cpp index ed62e601..9aa844e7 100644 --- a/Core/PPU.cpp +++ b/Core/PPU.cpp @@ -15,6 +15,7 @@ PPU::PPU(shared_ptr console) { _console = console; + _settings = _console->GetSettings(); _outputBuffers[0] = new uint16_t[256 * 240]; _outputBuffers[1] = new uint16_t[256 * 240]; @@ -27,8 +28,8 @@ PPU::PPU(shared_ptr console) 0x09, 0x01, 0x34, 0x03, 0x00, 0x04, 0x00, 0x14, 0x08, 0x3A, 0x00, 0x02, 0x00, 0x20, 0x2C, 0x08 }; memcpy(_paletteRAM, paletteRamBootValues, sizeof(_paletteRAM)); - BaseMapper::InitializeRam(_spriteRAM, 0x100); - BaseMapper::InitializeRam(_secondarySpriteRAM, 0x20); + _console->GetMapper()->InitializeRam(_spriteRAM, 0x100); + _console->GetMapper()->InitializeRam(_secondarySpriteRAM, 0x20); Reset(); } @@ -98,7 +99,7 @@ void PPU::Reset() _updateVramAddr = 0; memset(_oamDecayCycles, 0, sizeof(_oamDecayCycles)); - _enableOamDecay = EmulationSettings::CheckFlag(EmulationFlags::EnableOamDecay); + _enableOamDecay = _settings->CheckFlag(EmulationFlags::EnableOamDecay); UpdateMinimumDrawCycles(); } @@ -132,10 +133,10 @@ void PPU::SetNesModel(NesModel model) break; } - _nmiScanline += EmulationSettings::GetPpuExtraScanlinesBeforeNmi(); + _nmiScanline += _settings->GetPpuExtraScanlinesBeforeNmi(); _palSpriteEvalScanline = _nmiScanline + 24; - _standardVblankEnd += EmulationSettings::GetPpuExtraScanlinesBeforeNmi(); - _vblankEnd += EmulationSettings::GetPpuExtraScanlinesAfterNmi() + EmulationSettings::GetPpuExtraScanlinesBeforeNmi(); + _standardVblankEnd += _settings->GetPpuExtraScanlinesBeforeNmi(); + _vblankEnd += _settings->GetPpuExtraScanlinesAfterNmi() + _settings->GetPpuExtraScanlinesBeforeNmi(); } void PPU::GetState(PPUDebugState &state) @@ -236,7 +237,7 @@ uint8_t PPU::ReadRAM(uint16_t addr) returnValue = _state.Status; openBusMask = 0x1F; - switch(EmulationSettings::GetPpuModel()) { + switch(_settings->GetPpuModel()) { case PpuModel::Ppu2C05A: openBusMask = 0x00; returnValue |= 0x1B; break; case PpuModel::Ppu2C05B: openBusMask = 0x00; returnValue |= 0x3D; break; case PpuModel::Ppu2C05C: openBusMask = 0x00; returnValue |= 0x1C; break; @@ -247,7 +248,7 @@ uint8_t PPU::ReadRAM(uint16_t addr) break; case PPURegisters::SpriteData: - if(!EmulationSettings::CheckFlag(EmulationFlags::DisablePpu2004Reads)) { + if(!_settings->CheckFlag(EmulationFlags::DisablePpu2004Reads)) { if(_scanline <= 239 && IsRenderingEnabled()) { //While the screen is begin drawn if(_cycle >= 257 && _cycle <= 320) { @@ -275,7 +276,7 @@ uint8_t PPU::ReadRAM(uint16_t addr) returnValue = _memoryReadBuffer; _memoryReadBuffer = ReadVram(_ppuBusAddress & 0x3FFF, MemoryOperationType::Read); - if((_state.VideoRamAddr & 0x3FFF) >= 0x3F00 && !EmulationSettings::CheckFlag(EmulationFlags::DisablePaletteRead)) { + if((_state.VideoRamAddr & 0x3FFF) >= 0x3F00 && !_settings->CheckFlag(EmulationFlags::DisablePaletteRead)) { returnValue = ReadPaletteRAM(_state.VideoRamAddr) | (_openBus & 0xC0); _console->DebugProcessVramReadOperation(MemoryOperationType::Read, _state.VideoRamAddr & 0x3FFF, returnValue); openBusMask = 0xC0; @@ -303,14 +304,14 @@ void PPU::WriteRAM(uint16_t addr, uint8_t value) switch(GetRegisterID(addr)) { case PPURegisters::Control: - if(EmulationSettings::GetPpuModel() >= PpuModel::Ppu2C05A && EmulationSettings::GetPpuModel() <= PpuModel::Ppu2C05E) { + if(_settings->GetPpuModel() >= PpuModel::Ppu2C05A && _settings->GetPpuModel() <= PpuModel::Ppu2C05E) { SetMaskRegister(value); } else { SetControlRegister(value); } break; case PPURegisters::Mask: - if(EmulationSettings::GetPpuModel() >= PpuModel::Ppu2C05A && EmulationSettings::GetPpuModel() <= PpuModel::Ppu2C05E) { + if(_settings->GetPpuModel() >= PpuModel::Ppu2C05A && _settings->GetPpuModel() <= PpuModel::Ppu2C05E) { SetControlRegister(value); } else { SetMaskRegister(value); @@ -438,8 +439,8 @@ void PPU::SetControlRegister(uint8_t value) void PPU::UpdateMinimumDrawCycles() { - _minimumDrawBgCycle = _flags.BackgroundEnabled ? ((_flags.BackgroundMask || EmulationSettings::CheckFlag(EmulationFlags::ForceBackgroundFirstColumn)) ? 0 : 8) : 300; - _minimumDrawSpriteCycle = _flags.SpritesEnabled ? ((_flags.SpriteMask || EmulationSettings::CheckFlag(EmulationFlags::ForceSpritesFirstColumn)) ? 0 : 8) : 300; + _minimumDrawBgCycle = _flags.BackgroundEnabled ? ((_flags.BackgroundMask || _settings->CheckFlag(EmulationFlags::ForceBackgroundFirstColumn)) ? 0 : 8) : 300; + _minimumDrawSpriteCycle = _flags.SpritesEnabled ? ((_flags.SpriteMask || _settings->CheckFlag(EmulationFlags::ForceSpritesFirstColumn)) ? 0 : 8) : 300; _minimumDrawSpriteStandardCycle = _flags.SpritesEnabled ? (_flags.SpriteMask ? 0 : 8) : 300; } @@ -667,10 +668,10 @@ void PPU::LoadSprite(uint8_t spriteY, uint8_t tileIndex, uint8_t attributes, uin void PPU::LoadExtraSprites() { - if(_spriteCount == 8 && EmulationSettings::CheckFlag(EmulationFlags::RemoveSpriteLimit)) { + if(_spriteCount == 8 && _settings->CheckFlag(EmulationFlags::RemoveSpriteLimit)) { bool loadExtraSprites = true; - if(EmulationSettings::CheckFlag(EmulationFlags::AdaptiveSpriteLimit)) { + if(_settings->CheckFlag(EmulationFlags::AdaptiveSpriteLimit)) { uint16_t lastPosition = 0xFFFF; uint8_t identicalSpriteCount = 0; uint8_t maxIdenticalSpriteCount = 0; @@ -729,7 +730,7 @@ uint8_t PPU::GetPixelColor() if(_cycle > _minimumDrawBgCycle) { //BackgroundMask = false: Hide background in leftmost 8 pixels of screen spriteBgColor = (((_state.LowBitShift << offset) & 0x8000) >> 15) | (((_state.HighBitShift << offset) & 0x8000) >> 14); - if(EmulationSettings::GetBackgroundEnabled()) { + if(_settings->GetBackgroundEnabled()) { backgroundColor = spriteBgColor; } } @@ -759,7 +760,7 @@ uint8_t PPU::GetPixelColor() _console->DebugProcessEvent(EventType::SpriteZeroHit); } - if(EmulationSettings::GetSpritesEnabled() && (backgroundColor == 0 || !_spriteTiles[i].BackgroundPriority)) { + if(_settings->GetSpritesEnabled() && (backgroundColor == 0 || !_spriteTiles[i].BackgroundPriority)) { //Check sprite priority return _lastSprite->PaletteOffset + spriteColor; } @@ -840,7 +841,7 @@ void PPU::ProcessScanline() if(_cycle == 1) { _statusFlags.VerticalBlank = false; } - if(_state.SpriteRamAddr >= 0x08 && IsRenderingEnabled() && !EmulationSettings::CheckFlag(EmulationFlags::DisableOamAddrBug)) { + if(_state.SpriteRamAddr >= 0x08 && IsRenderingEnabled() && !_settings->CheckFlag(EmulationFlags::DisableOamAddrBug)) { //This should only be done if rendering is enabled (otherwise oam_stress test fails immediately) //"If OAMADDR is not less than eight when rendering starts, the eight bytes starting at OAMADDR & 0xF8 are copied to the first eight bytes of OAM" WriteSpriteRam(_cycle - 1, ReadSpriteRam((_state.SpriteRamAddr & 0xF8) + _cycle - 1)); @@ -893,7 +894,7 @@ void PPU::ProcessScanline() if(IsRenderingEnabled()) { ReadVram(GetNameTableAddr()); - if(_scanline == -1 && _cycle == 339 && (_frameCount & 0x01) && _nesModel == NesModel::NTSC && EmulationSettings::GetPpuModel() == PpuModel::Ppu2C02) { + if(_scanline == -1 && _cycle == 339 && (_frameCount & 0x01) && _nesModel == NesModel::NTSC && _settings->GetPpuModel() == PpuModel::Ppu2C02) { //This behavior is NTSC-specific - PAL frames are always the same number of cycles //"With rendering enabled, each odd PPU frame is one PPU clock shorter than normal" (skip from 339 to 0, going over 340) _cycle = 340; @@ -1070,7 +1071,7 @@ void PPU::SendFrame() _console->GetVideoDecoder()->UpdateFrame(_currentOutputBuffer); } - _enableOamDecay = EmulationSettings::CheckFlag(EmulationFlags::EnableOamDecay); + _enableOamDecay = _settings->CheckFlag(EmulationFlags::EnableOamDecay); #endif } @@ -1128,7 +1129,7 @@ void PPU::Exec() UpdateApuStatus(); - if(_scanline == EmulationSettings::GetInputPollScanline()) { + if(_scanline == _settings->GetInputPollScanline()) { _console->GetControlManager()->UpdateInputState(); } @@ -1208,7 +1209,7 @@ void PPU::UpdateState() void PPU::ProcessCpuClock() { - if(!EmulationSettings::HasOverclock()) { + if(!_settings->HasOverclock()) { Exec(); Exec(); Exec(); @@ -1219,9 +1220,9 @@ void PPU::ProcessCpuClock() } else { if(_nesModel == NesModel::PAL) { //PAL PPU runs 3.2 clocks for every CPU clock, so we need to run an extra clock every 5 CPU clocks - _cyclesNeeded += 3.2 / (EmulationSettings::GetOverclockRate() / 100.0); + _cyclesNeeded += 3.2 / (_settings->GetOverclockRate() / 100.0); } else { - _cyclesNeeded += 3.0 / (EmulationSettings::GetOverclockRate() / 100.0); + _cyclesNeeded += 3.0 / (_settings->GetOverclockRate() / 100.0); } while(_cyclesNeeded >= 1.0) { @@ -1246,6 +1247,14 @@ uint8_t* PPU::GetSpriteRam() return _spriteRAM; } +uint32_t PPU::GetPixelBrightness(uint8_t x, uint8_t y) +{ + //Used by Zapper, gives a rough approximation of the brightness level of the specific pixel + uint16_t pixelData = _currentOutputBuffer[y << 8 | x]; + uint32_t argbColor = _settings->GetRgbPalette()[pixelData & 0x3F]; + return (argbColor & 0xFF) + ((argbColor >> 8) & 0xFF) + ((argbColor >> 16) & 0xFF); +} + void PPU::StreamState(bool saving) { ArrayInfo paletteRam = { _paletteRAM, 0x20 }; @@ -1258,9 +1267,9 @@ void PPU::StreamState(bool saving) bool disableOamAddrBug = false; if(saving) { - disablePpu2004Reads = EmulationSettings::CheckFlag(EmulationFlags::DisablePpu2004Reads); - disablePaletteRead = EmulationSettings::CheckFlag(EmulationFlags::DisablePaletteRead); - disableOamAddrBug = EmulationSettings::CheckFlag(EmulationFlags::DisableOamAddrBug); + disablePpu2004Reads = _settings->CheckFlag(EmulationFlags::DisablePpu2004Reads); + disablePaletteRead = _settings->CheckFlag(EmulationFlags::DisablePaletteRead); + disableOamAddrBug = _settings->CheckFlag(EmulationFlags::DisableOamAddrBug); } uint16_t unusedSpriteDmaAddr = 0; @@ -1283,9 +1292,9 @@ void PPU::StreamState(bool saving) } if(!saving) { - EmulationSettings::SetFlagState(EmulationFlags::DisablePpu2004Reads, disablePpu2004Reads); - EmulationSettings::SetFlagState(EmulationFlags::DisablePaletteRead, disablePaletteRead); - EmulationSettings::SetFlagState(EmulationFlags::DisableOamAddrBug, disableOamAddrBug); + _settings->SetFlagState(EmulationFlags::DisablePpu2004Reads, disablePpu2004Reads); + _settings->SetFlagState(EmulationFlags::DisablePaletteRead, disablePaletteRead); + _settings->SetFlagState(EmulationFlags::DisableOamAddrBug, disableOamAddrBug); SetNesModel(_nesModel); UpdateMinimumDrawCycles(); diff --git a/Core/PPU.h b/Core/PPU.h index 4d1d72fe..ebb5792e 100644 --- a/Core/PPU.h +++ b/Core/PPU.h @@ -30,6 +30,7 @@ class PPU : public IMemoryHandler, public Snapshotable { protected: shared_ptr _console; + EmulationSettings* _settings; PPUState _state; int32_t _scanline; @@ -227,13 +228,7 @@ class PPU : public IMemoryHandler, public Snapshotable return _secondarySpriteRAM; } - uint32_t GetPixelBrightness(uint8_t x, uint8_t y) - { - //Used by Zapper, gives a rough approximation of the brightness level of the specific pixel - uint16_t pixelData = _currentOutputBuffer[y << 8 | x]; - uint32_t argbColor = EmulationSettings::GetRgbPalette()[pixelData & 0x3F]; - return (argbColor & 0xFF) + ((argbColor >> 8) & 0xFF) + ((argbColor >> 16) & 0xFF); - } + uint32_t GetPixelBrightness(uint8_t x, uint8_t y); uint16_t GetPixel(uint8_t x, uint8_t y) { diff --git a/Core/PartyTap.h b/Core/PartyTap.h index c9e5951b..a812dcfd 100644 --- a/Core/PartyTap.h +++ b/Core/PartyTap.h @@ -33,7 +33,7 @@ protected: } public: - PartyTap(KeyMappingSet keyMappings) : BaseControlDevice(BaseControlDevice::ExpDevicePort, keyMappings) + PartyTap(shared_ptr console, KeyMappingSet keyMappings) : BaseControlDevice(console, BaseControlDevice::ExpDevicePort, keyMappings) { } diff --git a/Core/PowerPad.h b/Core/PowerPad.h index 88d74368..2b6e6a5e 100644 --- a/Core/PowerPad.h +++ b/Core/PowerPad.h @@ -52,7 +52,7 @@ protected: } public: - PowerPad(uint8_t port, KeyMappingSet keyMappings) : BaseControlDevice(port, keyMappings) + PowerPad(shared_ptr console, uint8_t port, KeyMappingSet keyMappings) : BaseControlDevice(console, port, keyMappings) { _useSideA = keyMappings.PowerpadUseSideA; } diff --git a/Core/RawVideoFilter.cpp b/Core/RawVideoFilter.cpp index dc1fc325..fe261081 100644 --- a/Core/RawVideoFilter.cpp +++ b/Core/RawVideoFilter.cpp @@ -2,7 +2,7 @@ #include "RawVideoFilter.h" #include "PPU.h" -RawVideoFilter::RawVideoFilter() +RawVideoFilter::RawVideoFilter(shared_ptr console) : BaseVideoFilter(console) { //Use the same raw output as the Nestopia core for(int i = 0; i < 512; i++) { diff --git a/Core/RawVideoFilter.h b/Core/RawVideoFilter.h index 20f9fab5..78dfe9aa 100644 --- a/Core/RawVideoFilter.h +++ b/Core/RawVideoFilter.h @@ -3,13 +3,15 @@ #include "stdafx.h" #include "BaseVideoFilter.h" +class Console; + class RawVideoFilter : public BaseVideoFilter { private: uint32_t _rawPalette[512]; public: - RawVideoFilter(); + RawVideoFilter(shared_ptr console); void ApplyFilter(uint16_t *ppuOutputBuffer); FrameInfo GetFrameInfo(); diff --git a/Core/RecordedRomTest.cpp b/Core/RecordedRomTest.cpp index 0079660e..edf5ba6f 100644 --- a/Core/RecordedRomTest.cpp +++ b/Core/RecordedRomTest.cpp @@ -182,17 +182,18 @@ void RecordedRomTest::RecordFromTest(string newTestFilename, string existingTest int32_t RecordedRomTest::Run(string filename) { + EmulationSettings* settings = _console->GetSettings(); string testName = FolderUtilities::GetFilename(filename, false); if(testName.compare("5.MMC3_rev_A") == 0 || testName.compare("6-MMC6") == 0 || testName.compare("6-MMC3_alt") == 0) { - EmulationSettings::SetFlags(EmulationFlags::Mmc3IrqAltBehavior); + settings->SetFlags(EmulationFlags::Mmc3IrqAltBehavior); } else { - EmulationSettings::ClearFlags(EmulationFlags::Mmc3IrqAltBehavior); + settings->ClearFlags(EmulationFlags::Mmc3IrqAltBehavior); } if(testName.compare("demo_pal") == 0 || testName.substr(0, 4).compare("pal_") == 0) { - EmulationSettings::SetNesModel(NesModel::PAL); + settings->SetNesModel(NesModel::PAL); } else { - EmulationSettings::SetNesModel(NesModel::NTSC); + settings->SetNesModel(NesModel::NTSC); } VirtualFile testMovie(filename, "TestMovie.mmo"); @@ -212,7 +213,7 @@ int32_t RecordedRomTest::Run(string filename) return false; } - EmulationSettings::SetMasterVolume(0); + settings->SetMasterVolume(0); _console->Pause(); @@ -236,12 +237,12 @@ int32_t RecordedRomTest::Run(string filename) //Start playing movie if(_console->Initialize(testRom)) { - EmulationSettings::SetFlags(EmulationFlags::ForceMaxSpeed); + settings->SetFlags(EmulationFlags::ForceMaxSpeed); _runningTest = true; MovieManager::Play(testMovie, _console); _console->Resume(); - EmulationSettings::ClearFlags(EmulationFlags::Paused); + _console->GetSettings()->ClearFlags(EmulationFlags::Paused); _signal.Wait(); _runningTest = false; _console->Stop(); @@ -250,8 +251,8 @@ int32_t RecordedRomTest::Run(string filename) return -2; } - EmulationSettings::ClearFlags(EmulationFlags::ForceMaxSpeed); - EmulationSettings::SetMasterVolume(1.0); + settings->ClearFlags(EmulationFlags::ForceMaxSpeed); + settings->SetMasterVolume(1.0); return _badFrameCount; } diff --git a/Core/RewindManager.cpp b/Core/RewindManager.cpp index 4eab812c..5185bcde 100644 --- a/Core/RewindManager.cpp +++ b/Core/RewindManager.cpp @@ -10,6 +10,7 @@ RewindManager::RewindManager(shared_ptr console) { _console = console; + _settings = console->GetSettings(); _rewindState = RewindState::Stopped; _framesToFastForward = 0; AddHistoryBlock(); @@ -41,7 +42,7 @@ void RewindManager::ClearBuffer() void RewindManager::ProcessNotification(ConsoleNotificationType type, void * parameter) { if(type == ConsoleNotificationType::PpuFrameDone) { - if(EmulationSettings::GetRewindBufferSize() > 0) { + if(_settings->GetRewindBufferSize() > 0) { switch(_rewindState) { case RewindState::Starting: case RewindState::Started: @@ -62,8 +63,8 @@ void RewindManager::ProcessNotification(ConsoleNotificationType type, void * par } _historyBackup.clear(); _rewindState = RewindState::Stopped; - EmulationSettings::ClearFlags(EmulationFlags::Rewind); - EmulationSettings::ClearFlags(EmulationFlags::ForceMaxSpeed); + _settings->ClearFlags(EmulationFlags::Rewind); + _settings->ClearFlags(EmulationFlags::ForceMaxSpeed); } break; @@ -79,7 +80,7 @@ void RewindManager::ProcessNotification(ConsoleNotificationType type, void * par void RewindManager::AddHistoryBlock() { - uint32_t maxHistorySize = EmulationSettings::GetRewindBufferSize() * 120; + uint32_t maxHistorySize = _settings->GetRewindBufferSize() * 120; if(maxHistorySize > 0) { while(_history.size() > maxHistorySize) { _history.pop_front(); @@ -114,7 +115,7 @@ void RewindManager::PopHistory() void RewindManager::Start(bool forDebugger) { - if(_rewindState == RewindState::Stopped && EmulationSettings::GetRewindBufferSize() > 0) { + if(_rewindState == RewindState::Stopped && _settings->GetRewindBufferSize() > 0) { _console->Pause(); _rewindState = forDebugger ? RewindState::Debugging : RewindState::Starting; @@ -126,8 +127,8 @@ void RewindManager::Start(bool forDebugger) PopHistory(); _console->GetSoundMixer()->StopAudio(true); - EmulationSettings::SetFlags(EmulationFlags::ForceMaxSpeed); - EmulationSettings::SetFlags(EmulationFlags::Rewind); + _settings->SetFlags(EmulationFlags::ForceMaxSpeed); + _settings->SetFlags(EmulationFlags::Rewind); _console->Resume(); } @@ -143,8 +144,8 @@ void RewindManager::ForceStop() _currentHistory = _historyBackup.front(); _historyBackup.clear(); _rewindState = RewindState::Stopped; - EmulationSettings::ClearFlags(EmulationFlags::ForceMaxSpeed); - EmulationSettings::ClearFlags(EmulationFlags::Rewind); + _settings->ClearFlags(EmulationFlags::ForceMaxSpeed); + _settings->ClearFlags(EmulationFlags::Rewind); } } @@ -180,12 +181,12 @@ void RewindManager::Stop() if(_framesToFastForward > 0) { _rewindState = RewindState::Stopping; _currentHistory.FrameCount = 0; - EmulationSettings::SetFlags(EmulationFlags::ForceMaxSpeed); + _settings->SetFlags(EmulationFlags::ForceMaxSpeed); } else { _rewindState = RewindState::Stopped; _historyBackup.clear(); - EmulationSettings::ClearFlags(EmulationFlags::ForceMaxSpeed); - EmulationSettings::ClearFlags(EmulationFlags::Rewind); + _settings->ClearFlags(EmulationFlags::ForceMaxSpeed); + _settings->ClearFlags(EmulationFlags::Rewind); } _videoHistoryBuilder.clear(); @@ -231,7 +232,7 @@ void RewindManager::ProcessFrame(void * frameBuffer, uint32_t width, uint32_t he if(_rewindState == RewindState::Started || _videoHistory.size() >= RewindManager::BufferSize) { _rewindState = RewindState::Started; - EmulationSettings::ClearFlags(EmulationFlags::ForceMaxSpeed); + _settings->ClearFlags(EmulationFlags::ForceMaxSpeed); if(!_videoHistory.empty()) { _console->GetVideoRenderer()->UpdateFrame(_videoHistory.back().data(), width, height); _videoHistory.pop_back(); @@ -270,7 +271,7 @@ bool RewindManager::ProcessAudio(int16_t * soundBuffer, uint32_t sampleCount, ui void RewindManager::RecordInput(vector> devices) { - if(EmulationSettings::GetRewindBufferSize() > 0 && _rewindState == RewindState::Stopped) { + if(_settings->GetRewindBufferSize() > 0 && _rewindState == RewindState::Stopped) { for(shared_ptr &device : devices) { _currentHistory.InputLogs[device->GetPort()].push_back(device->GetRawState()); } diff --git a/Core/RewindManager.h b/Core/RewindManager.h index 5201cc70..a8b2f61c 100644 --- a/Core/RewindManager.h +++ b/Core/RewindManager.h @@ -24,6 +24,7 @@ private: static constexpr int32_t BufferSize = 30; //Number of frames between each save state shared_ptr _console; + EmulationSettings* _settings; std::deque _history; std::deque _historyBackup; diff --git a/Core/RomData.h b/Core/RomData.h index 0150b4d6..470f801d 100644 --- a/Core/RomData.h +++ b/Core/RomData.h @@ -66,6 +66,7 @@ struct RomInfo RomFormat Format; bool IsNes20Header = false; + bool IsInDatabase = false; uint16_t MapperID = 0; uint8_t SubMapperID = 0; diff --git a/Core/SaveStateManager.cpp b/Core/SaveStateManager.cpp index d616dfea..ffe66f7c 100644 --- a/Core/SaveStateManager.cpp +++ b/Core/SaveStateManager.cpp @@ -161,7 +161,7 @@ bool SaveStateManager::LoadState(istream &stream, bool hashCheckRequired) bool gameLoaded = !romInfo.Hash.Sha1.empty(); if(romInfo.Hash.Sha1 != string(hash)) { //CRC doesn't match - if(!EmulationSettings::CheckFlag(EmulationFlags::AllowMismatchingSaveState) || !gameLoaded || + if(!_console->GetSettings()->CheckFlag(EmulationFlags::AllowMismatchingSaveState) || !gameLoaded || romInfo.MapperID != mapperId || romInfo.SubMapperID != subMapperId) { //If mismatching states aren't allowed, or a game isn't loaded, or the mapper types don't match, try to find and load the matching ROM @@ -222,7 +222,7 @@ bool SaveStateManager::LoadState(int stateIndex) void SaveStateManager::SaveRecentGame(string romName, string romPath, string patchPath) { - if(!EmulationSettings::CheckFlag(EmulationFlags::ConsoleMode) && !EmulationSettings::CheckFlag(EmulationFlags::DisableGameSelectionScreen) && _console->GetRomInfo().Format != RomFormat::Nsf) { + if(!_console->GetSettings()->CheckFlag(EmulationFlags::ConsoleMode) && !_console->GetSettings()->CheckFlag(EmulationFlags::DisableGameSelectionScreen) && _console->GetRomInfo().Format != RomFormat::Nsf) { string filename = FolderUtilities::GetFilename(_console->GetRomInfo().RomName, false) + ".rgd"; ZipWriter writer; writer.Initialize(FolderUtilities::CombinePath(FolderUtilities::GetRecentGamesFolder(), filename)); diff --git a/Core/ScaleFilter.cpp b/Core/ScaleFilter.cpp index 3cb16557..70230cbd 100644 --- a/Core/ScaleFilter.cpp +++ b/Core/ScaleFilter.cpp @@ -62,7 +62,7 @@ void ScaleFilter::UpdateOutputBuffer(uint32_t width, uint32_t height) } } -uint32_t* ScaleFilter::ApplyFilter(uint32_t *inputArgbBuffer, uint32_t width, uint32_t height) +uint32_t* ScaleFilter::ApplyFilter(uint32_t *inputArgbBuffer, uint32_t width, uint32_t height, double scanlineIntensity) { UpdateOutputBuffer(width, height); @@ -82,7 +82,8 @@ uint32_t* ScaleFilter::ApplyFilter(uint32_t *inputArgbBuffer, uint32_t width, ui ApplyPrescaleFilter(inputArgbBuffer); } - double scanlineIntensity = 1.0 - EmulationSettings::GetPictureSettings().ScanlineIntensity; + scanlineIntensity = 1.0 - scanlineIntensity; + if(scanlineIntensity < 1.0) { for(int y = 1, yMax = height * _filterScale; y < yMax; y += 2) { for(int x = 0, xMax = width * _filterScale; x < xMax; x++) { diff --git a/Core/ScaleFilter.h b/Core/ScaleFilter.h index 064cf652..d53de676 100644 --- a/Core/ScaleFilter.h +++ b/Core/ScaleFilter.h @@ -21,7 +21,7 @@ public: ~ScaleFilter(); uint32_t GetScale(); - uint32_t* ApplyFilter(uint32_t *inputArgbBuffer, uint32_t width, uint32_t height); + uint32_t* ApplyFilter(uint32_t *inputArgbBuffer, uint32_t width, uint32_t height, double scanlineIntensity); FrameInfo GetFrameInfo(FrameInfo baseFrameInfo); static shared_ptr GetScaleFilter(VideoFilterType filter); diff --git a/Core/ShortcutKeyHandler.cpp b/Core/ShortcutKeyHandler.cpp index d18e58fe..c660e243 100644 --- a/Core/ShortcutKeyHandler.cpp +++ b/Core/ShortcutKeyHandler.cpp @@ -38,8 +38,8 @@ ShortcutKeyHandler::~ShortcutKeyHandler() bool ShortcutKeyHandler::IsKeyPressed(EmulatorShortcut shortcut) { - KeyCombination keyComb = EmulationSettings::GetShortcutKey(shortcut, _keySetIndex); - vector supersets = EmulationSettings::GetShortcutSupersets(shortcut, _keySetIndex); + KeyCombination keyComb = _console->GetSettings()->GetShortcutKey(shortcut, _keySetIndex); + vector supersets = _console->GetSettings()->GetShortcutSupersets(shortcut, _keySetIndex); for(KeyCombination &superset : supersets) { if(IsKeyPressed(superset)) { //A superset is pressed, ignore this subset @@ -98,21 +98,22 @@ bool ShortcutKeyHandler::DetectKeyRelease(EmulatorShortcut shortcut) void ShortcutKeyHandler::CheckMappedKeys() { + EmulationSettings* settings = _console->GetSettings(); bool isNetplayClient = GameClient::Connected(); bool isMovieActive = MovieManager::Playing() || MovieManager::Recording(); _keyboardMode = false; if(DetectKeyPress(EmulatorShortcut::ToggleKeyboardMode)) { - if(EmulationSettings::IsKeyboardMode()) { - EmulationSettings::DisableKeyboardMode(); + if(settings->IsKeyboardMode()) { + settings->DisableKeyboardMode(); } else { ControlManager* controlManager = _console->GetControlManager(); if(controlManager && controlManager->HasKeyboard()) { - EmulationSettings::EnableKeyboardMode(); + settings->EnableKeyboardMode(); } } } - _keyboardMode = EmulationSettings::IsKeyboardMode(); + _keyboardMode = settings->IsKeyboardMode(); //Let the UI handle these shortcuts for(uint64_t i = (uint64_t)EmulatorShortcut::SwitchDiskSide; i < (uint64_t)EmulatorShortcut::ShortcutCount; i++) { @@ -123,16 +124,16 @@ void ShortcutKeyHandler::CheckMappedKeys() } if(DetectKeyPress(EmulatorShortcut::FastForward)) { - EmulationSettings::SetFlags(EmulationFlags::Turbo); + settings->SetFlags(EmulationFlags::Turbo); } else if(DetectKeyRelease(EmulatorShortcut::FastForward)) { - EmulationSettings::ClearFlags(EmulationFlags::Turbo); + settings->ClearFlags(EmulationFlags::Turbo); } if(DetectKeyPress(EmulatorShortcut::ToggleFastForward)) { - if(EmulationSettings::CheckFlag(EmulationFlags::Turbo)) { - EmulationSettings::ClearFlags(EmulationFlags::Turbo); + if(settings->CheckFlag(EmulationFlags::Turbo)) { + settings->ClearFlags(EmulationFlags::Turbo); } else { - EmulationSettings::SetFlags(EmulationFlags::Turbo); + settings->SetFlags(EmulationFlags::Turbo); } } @@ -184,49 +185,51 @@ void ShortcutKeyHandler::CheckMappedKeys() } if(DetectKeyPress(EmulatorShortcut::RunSingleFrame)) { - if(EmulationSettings::CheckFlag(EmulationFlags::DebuggerWindowEnabled)) { + if(settings->CheckFlag(EmulationFlags::DebuggerWindowEnabled)) { shared_ptr debugger = _console->GetDebugger(false); if(debugger) { debugger->BreakOnScanline(241); } } else { - if(EmulationSettings::CheckFlag(EmulationFlags::Paused)) { - EmulationSettings::ClearFlags(EmulationFlags::Paused); + if(settings->CheckFlag(EmulationFlags::Paused)) { + settings->ClearFlags(EmulationFlags::Paused); _console->Pause(); std::this_thread::sleep_for(std::chrono::duration(50)); - EmulationSettings::SetFlags(EmulationFlags::Paused); + settings->SetFlags(EmulationFlags::Paused); _console->Resume(); } else { - EmulationSettings::SetFlags(EmulationFlags::Paused); + settings->SetFlags(EmulationFlags::Paused); } } } - if(!isNetplayClient && !MovieManager::Recording() && !EmulationSettings::CheckFlag(NsfPlayerEnabled)) { + if(!isNetplayClient && !MovieManager::Recording() && !settings->CheckFlag(NsfPlayerEnabled)) { RewindManager* rewindManager = _console->GetRewindManager(); - if(DetectKeyPress(EmulatorShortcut::ToggleRewind)) { - if(rewindManager->IsRewinding()) { - rewindManager->StopRewinding(); - } else { - rewindManager->StartRewinding(); + if(rewindManager) { + if(DetectKeyPress(EmulatorShortcut::ToggleRewind)) { + if(rewindManager->IsRewinding()) { + rewindManager->StopRewinding(); + } else { + rewindManager->StartRewinding(); + } } - } - if(DetectKeyPress(EmulatorShortcut::Rewind)) { - rewindManager->StartRewinding(); - } else if(DetectKeyRelease(EmulatorShortcut::Rewind)) { - rewindManager->StopRewinding(); - } else if(DetectKeyPress(EmulatorShortcut::RewindTenSecs)) { - rewindManager->RewindSeconds(10); - } else if(DetectKeyPress(EmulatorShortcut::RewindOneMin)) { - rewindManager->RewindSeconds(60); + if(DetectKeyPress(EmulatorShortcut::Rewind)) { + rewindManager->StartRewinding(); + } else if(DetectKeyRelease(EmulatorShortcut::Rewind)) { + rewindManager->StopRewinding(); + } else if(DetectKeyPress(EmulatorShortcut::RewindTenSecs)) { + rewindManager->RewindSeconds(10); + } else if(DetectKeyPress(EmulatorShortcut::RewindOneMin)) { + rewindManager->RewindSeconds(60); + } } } } void ShortcutKeyHandler::ProcessKeys() { - if(!EmulationSettings::InputEnabled()) { + if(!_console->GetSettings()->InputEnabled()) { return; } diff --git a/Core/SnesController.h b/Core/SnesController.h index f6de62b0..3d53c06e 100644 --- a/Core/SnesController.h +++ b/Core/SnesController.h @@ -64,7 +64,7 @@ protected: } public: - SnesController(uint8_t port, KeyMappingSet keyMappings) : BaseControlDevice(port, keyMappings) + SnesController(shared_ptr console, uint8_t port, KeyMappingSet keyMappings) : BaseControlDevice(console, port, keyMappings) { } diff --git a/Core/SnesMouse.h b/Core/SnesMouse.h index cfb3505d..04d1a3da 100644 --- a/Core/SnesMouse.h +++ b/Core/SnesMouse.h @@ -3,6 +3,8 @@ #include "BaseControlDevice.h" #include "IKeyManager.h" #include "KeyManager.h" +#include "Console.h" +#include "EmulationSettings.h" class SnesMouse : public BaseControlDevice { @@ -30,11 +32,11 @@ protected: { SetPressedState(Buttons::Left, KeyManager::IsMouseButtonPressed(MouseButton::LeftButton)); SetPressedState(Buttons::Right, KeyManager::IsMouseButtonPressed(MouseButton::RightButton)); - SetMovement(KeyManager::GetMouseMovement(EmulationSettings::GetMouseSensitivity(MouseDevice::SnesMouse))); + SetMovement(KeyManager::GetMouseMovement(_console->GetSettings()->GetMouseSensitivity(MouseDevice::SnesMouse))); } public: - SnesMouse(uint8_t port) : BaseControlDevice(port) + SnesMouse(shared_ptr console, uint8_t port) : BaseControlDevice(console, port) { } diff --git a/Core/SoundMixer.cpp b/Core/SoundMixer.cpp index c80ee624..d44a1c39 100644 --- a/Core/SoundMixer.cpp +++ b/Core/SoundMixer.cpp @@ -13,12 +13,13 @@ SoundMixer::SoundMixer(shared_ptr console) { _audioDevice = nullptr; _console = console; + _settings = _console->GetSettings(); _eqFrequencyGrid.reset(new orfanidis_eq::freq_grid()); _oggMixer.reset(); _outputBuffer = new int16_t[SoundMixer::MaxSamplesPerFrame]; _blipBufLeft = blip_new(SoundMixer::MaxSamplesPerFrame); _blipBufRight = blip_new(SoundMixer::MaxSamplesPerFrame); - _sampleRate = EmulationSettings::GetSampleRate(); + _sampleRate = _settings->GetSampleRate(); _model = NesModel::NTSC; } @@ -69,7 +70,7 @@ void SoundMixer::StopAudio(bool clearBuffer) void SoundMixer::Reset() { if(_oggMixer) { - _oggMixer->Reset(); + _oggMixer->Reset(_settings->GetSampleRate()); } _fadeRatio = 1.0; _muteFrameCount = 0; @@ -113,48 +114,48 @@ void SoundMixer::PlayAudioBuffer(uint32_t time) } if(_oggMixer) { - _oggMixer->ApplySamples(_outputBuffer, sampleCount); + _oggMixer->ApplySamples(_outputBuffer, sampleCount, _settings->GetMasterVolume()); } if(_console->IsDualSystem()) { - if(_console->IsMaster() && EmulationSettings::CheckFlag(EmulationFlags::VsDualMuteMaster)) { + if(_console->IsMaster() && _settings->CheckFlag(EmulationFlags::VsDualMuteMaster)) { _lowPassFilter.ApplyFilter(_outputBuffer, sampleCount, 0, 0); - } else if(!_console->IsMaster() && EmulationSettings::CheckFlag(EmulationFlags::VsDualMuteSlave)) { + } else if(!_console->IsMaster() && _settings->CheckFlag(EmulationFlags::VsDualMuteSlave)) { _lowPassFilter.ApplyFilter(_outputBuffer, sampleCount, 0, 0); } } RewindManager* rewindManager = _console->GetRewindManager(); - if(!_console->GetVideoRenderer()->IsRecording() && !_waveRecorder && !EmulationSettings::CheckFlag(EmulationFlags::NsfPlayerEnabled)) { - if((EmulationSettings::CheckFlag(EmulationFlags::Turbo) || (rewindManager && rewindManager->IsRewinding())) && EmulationSettings::CheckFlag(EmulationFlags::ReduceSoundInFastForward)) { + if(!_console->GetVideoRenderer()->IsRecording() && !_waveRecorder && !_settings->CheckFlag(EmulationFlags::NsfPlayerEnabled)) { + if((_settings->CheckFlag(EmulationFlags::Turbo) || (rewindManager && rewindManager->IsRewinding())) && _settings->CheckFlag(EmulationFlags::ReduceSoundInFastForward)) { //Reduce volume when fast forwarding or rewinding - _lowPassFilter.ApplyFilter(_outputBuffer, sampleCount, 0, 1.0 - EmulationSettings::GetVolumeReduction()); - } else if(EmulationSettings::CheckFlag(EmulationFlags::InBackground)) { - if(EmulationSettings::CheckFlag(EmulationFlags::MuteSoundInBackground)) { + _lowPassFilter.ApplyFilter(_outputBuffer, sampleCount, 0, 1.0 - _settings->GetVolumeReduction()); + } else if(_settings->CheckFlag(EmulationFlags::InBackground)) { + if(_settings->CheckFlag(EmulationFlags::MuteSoundInBackground)) { //Mute sound when in background _lowPassFilter.ApplyFilter(_outputBuffer, sampleCount, 0, 0); - } else if(EmulationSettings::CheckFlag(EmulationFlags::ReduceSoundInBackground)) { + } else if(_settings->CheckFlag(EmulationFlags::ReduceSoundInBackground)) { //Apply low pass filter/volume reduction when in background (based on options) - _lowPassFilter.ApplyFilter(_outputBuffer, sampleCount, 0, 1.0 - EmulationSettings::GetVolumeReduction()); + _lowPassFilter.ApplyFilter(_outputBuffer, sampleCount, 0, 1.0 - _settings->GetVolumeReduction()); } } } - if(EmulationSettings::GetReverbStrength() > 0) { - _reverbFilter.ApplyFilter(_outputBuffer, sampleCount, _sampleRate, EmulationSettings::GetReverbStrength(), EmulationSettings::GetReverbDelay()); + if(_settings->GetReverbStrength() > 0) { + _reverbFilter.ApplyFilter(_outputBuffer, sampleCount, _sampleRate, _settings->GetReverbStrength(), _settings->GetReverbDelay()); } else { _reverbFilter.ResetFilter(); } - switch(EmulationSettings::GetStereoFilter()) { + switch(_settings->GetStereoFilter()) { case StereoFilter::None: break; - case StereoFilter::Delay: _stereoDelay.ApplyFilter(_outputBuffer, sampleCount, _sampleRate); break; - case StereoFilter::Panning: _stereoPanning.ApplyFilter(_outputBuffer, sampleCount); break; + case StereoFilter::Delay: _stereoDelay.ApplyFilter(_outputBuffer, sampleCount, _sampleRate, _settings->GetStereoDelay()); break; + case StereoFilter::Panning: _stereoPanning.ApplyFilter(_outputBuffer, sampleCount, _settings->GetStereoPanningAngle()); break; } - if(EmulationSettings::GetCrossFeedRatio() > 0) { - _crossFeedFilter.ApplyFilter(_outputBuffer, sampleCount, EmulationSettings::GetCrossFeedRatio()); + if(_settings->GetCrossFeedRatio() > 0) { + _crossFeedFilter.ApplyFilter(_outputBuffer, sampleCount, _settings->GetCrossFeedRatio()); } if(rewindManager && rewindManager->SendAudio(_outputBuffer, (uint32_t)sampleCount, _sampleRate)) { @@ -169,15 +170,15 @@ void SoundMixer::PlayAudioBuffer(uint32_t time) _console->GetVideoRenderer()->AddRecordingSound(_outputBuffer, (uint32_t)sampleCount, _sampleRate); - if(_audioDevice && !EmulationSettings::IsPaused()) { + if(_audioDevice && !_console->IsPaused()) { _audioDevice->PlayBuffer(_outputBuffer, (uint32_t)sampleCount, _sampleRate, true); } } - if(EmulationSettings::NeedAudioSettingsUpdate()) { - if(EmulationSettings::GetSampleRate() != _sampleRate) { + if(_settings->NeedAudioSettingsUpdate()) { + if(_settings->GetSampleRate() != _sampleRate) { //Update sample rate for next frame if setting changed - _sampleRate = EmulationSettings::GetSampleRate(); + _sampleRate = _settings->GetSampleRate(); UpdateRates(true); UpdateEqualizers(true); } else { @@ -198,11 +199,11 @@ void SoundMixer::SetNesModel(NesModel model) void SoundMixer::UpdateRates(bool forceUpdate) { uint32_t newRate = _console->GetCpu()->GetClockRate(_model); - if(!EmulationSettings::GetOverclockAdjustApu()) { - newRate = (uint32_t)(newRate * (double)EmulationSettings::GetOverclockRate() / 100); + if(!_settings->GetOverclockAdjustApu()) { + newRate = (uint32_t)(newRate * (double)_settings->GetOverclockRate() / 100); } - if(EmulationSettings::CheckFlag(EmulationFlags::IntegerFpsMode)) { + if(_settings->CheckFlag(EmulationFlags::IntegerFpsMode)) { //Adjust sample rate when running at 60.0 fps instead of 60.1 if(_model == NesModel::NTSC) { newRate = (uint32_t)(newRate * 60.0 / 60.0988118623484); @@ -212,9 +213,9 @@ void SoundMixer::UpdateRates(bool forceUpdate) } AudioStatistics stats = GetStatistics(); - int32_t requestedLatency = (int32_t)EmulationSettings::GetAudioLatency(); + int32_t requestedLatency = (int32_t)_settings->GetAudioLatency(); double targetRate = _sampleRate; - if(stats.AverageLatency > 0 && EmulationSettings::GetEmulationSpeed() == 100) { + if(stats.AverageLatency > 0 && _settings->GetEmulationSpeed() == 100) { if(stats.AverageLatency > requestedLatency + 2) { targetRate *= 1.005; } else if(stats.AverageLatency < requestedLatency - 2) { @@ -233,8 +234,8 @@ void SoundMixer::UpdateRates(bool forceUpdate) bool hasPanning = false; for(uint32_t i = 0; i < MaxChannelCount; i++) { - _volumes[i] = EmulationSettings::GetChannelVolume((AudioChannel)i); - _panning[i] = EmulationSettings::GetChannelPanning((AudioChannel)i); + _volumes[i] = _settings->GetChannelVolume((AudioChannel)i); + _panning[i] = _settings->GetChannelPanning((AudioChannel)i); if(_panning[i] != 1.0) { if(!_hasPanning) { blip_clear(_blipBufLeft); @@ -282,7 +283,7 @@ void SoundMixer::AddDelta(AudioChannel channel, uint32_t time, int16_t delta) void SoundMixer::EndFrame(uint32_t time) { - double masterVolume = EmulationSettings::GetMasterVolume() * _fadeRatio; + double masterVolume = _settings->GetMasterVolume() * _fadeRatio; sort(_timestamps.begin(), _timestamps.end()); _timestamps.erase(std::unique(_timestamps.begin(), _timestamps.end()), _timestamps.end()); @@ -340,10 +341,10 @@ void SoundMixer::ApplyEqualizer(orfanidis_eq::eq1* equalizer, size_t sampleCount void SoundMixer::UpdateEqualizers(bool forceUpdate) { - EqualizerFilterType type = EmulationSettings::GetEqualizerFilterType(); + EqualizerFilterType type = _settings->GetEqualizerFilterType(); if(type != EqualizerFilterType::None) { - vector bands = EmulationSettings::GetEqualizerBands(); - vector bandGains = EmulationSettings::GetBandGains(); + vector bands = _settings->GetEqualizerBands(); + vector bandGains = _settings->GetBandGains(); if(bands.size() != _eqFrequencyGrid->get_number_of_bands()) { _equalizerLeft.reset(); @@ -358,8 +359,8 @@ void SoundMixer::UpdateEqualizers(bool forceUpdate) _eqFrequencyGrid->add_band((bands[i] + bands[i - 1]) / 2, bands[i], (bands[i + 1] + bands[i]) / 2); } - _equalizerLeft.reset(new orfanidis_eq::eq1(_eqFrequencyGrid.get(), (orfanidis_eq::filter_type)EmulationSettings::GetEqualizerFilterType())); - _equalizerRight.reset(new orfanidis_eq::eq1(_eqFrequencyGrid.get(), (orfanidis_eq::filter_type)EmulationSettings::GetEqualizerFilterType())); + _equalizerLeft.reset(new orfanidis_eq::eq1(_eqFrequencyGrid.get(), (orfanidis_eq::filter_type)_settings->GetEqualizerFilterType())); + _equalizerRight.reset(new orfanidis_eq::eq1(_eqFrequencyGrid.get(), (orfanidis_eq::filter_type)_settings->GetEqualizerFilterType())); _equalizerLeft->set_sample_rate(_sampleRate); _equalizerRight->set_sample_rate(_sampleRate); } @@ -377,7 +378,7 @@ void SoundMixer::UpdateEqualizers(bool forceUpdate) void SoundMixer::StartRecording(string filepath) { auto lock = _waveRecorderLock.AcquireSafe(); - _waveRecorder.reset(new WaveRecorder(filepath, EmulationSettings::GetSampleRate(), true)); + _waveRecorder.reset(new WaveRecorder(filepath, _settings->GetSampleRate(), true)); } void SoundMixer::StopRecording() @@ -410,6 +411,7 @@ OggMixer* SoundMixer::GetOggMixer() { if(!_oggMixer) { _oggMixer.reset(new OggMixer()); + _oggMixer->Reset(_settings->GetSampleRate()); } return _oggMixer.get(); } @@ -433,8 +435,8 @@ void SoundMixer::ProcessEndOfFrame() void SoundMixer::UpdateTargetSampleRate() { AudioStatistics stats = GetStatistics(); - if(stats.AverageLatency > 0 && EmulationSettings::GetEmulationSpeed() == 100) { - int32_t requestedLatency = (int32_t)EmulationSettings::GetAudioLatency(); + if(stats.AverageLatency > 0 && _settings->GetEmulationSpeed() == 100) { + int32_t requestedLatency = (int32_t)_settings->GetAudioLatency(); double targetRate = _sampleRate; //Try to stay within +/- 2ms of requested latency diff --git a/Core/SoundMixer.h b/Core/SoundMixer.h index d3876584..1e8fb3e0 100644 --- a/Core/SoundMixer.h +++ b/Core/SoundMixer.h @@ -32,6 +32,7 @@ private: static constexpr uint32_t MaxChannelCount = 11; IAudioDevice* _audioDevice; + EmulationSettings* _settings; unique_ptr _waveRecorder; SimpleLock _waveRecorderLock; double _fadeRatio; diff --git a/Core/SquareChannel.h b/Core/SquareChannel.h index 2d789102..ab625e99 100644 --- a/Core/SquareChannel.h +++ b/Core/SquareChannel.h @@ -139,7 +139,7 @@ public: InitializeEnvelope(value); _duty = (value & 0xC0) >> 6; - if(EmulationSettings::CheckFlag(EmulationFlags::SwapDutyCycles)) { + if(_console->GetSettings()->CheckFlag(EmulationFlags::SwapDutyCycles)) { _duty = ((_duty & 0x02) >> 1) | ((_duty & 0x01) << 1); } break; diff --git a/Core/StandardController.h b/Core/StandardController.h index 7221ad99..72b48715 100644 --- a/Core/StandardController.h +++ b/Core/StandardController.h @@ -6,7 +6,6 @@ class StandardController : public BaseControlDevice { private: - shared_ptr _console; bool _microphoneEnabled = false; uint32_t _turboSpeed = 0; @@ -51,7 +50,7 @@ protected: SetPressedState(Buttons::Microphone, keyMapping.Microphone); } - if(!EmulationSettings::CheckFlag(EmulationFlags::AllowInvalidInput)) { + if(!_console->GetSettings()->CheckFlag(EmulationFlags::AllowInvalidInput)) { if(IsPressed(Buttons::Up) && IsPressed(Buttons::Down)) { ClearBit(Buttons::Down); } @@ -64,7 +63,7 @@ protected: void RefreshStateBuffer() override { - if(EmulationSettings::GetConsoleType() == ConsoleType::Nes && EmulationSettings::CheckFlag(EmulationFlags::HasFourScore)) { + if(_console->GetSettings()->GetConsoleType() == ConsoleType::Nes && _console->GetSettings()->CheckFlag(EmulationFlags::HasFourScore)) { if(_port >= 2) { _stateBuffer = ToByte() << 8; } else { @@ -79,11 +78,10 @@ protected: public: enum Buttons { Up = 0, Down, Left, Right, Start, Select, B, A, Microphone }; - StandardController(shared_ptr console, uint8_t port, KeyMappingSet keyMappings) : BaseControlDevice(port, keyMappings) + StandardController(shared_ptr console, uint8_t port, KeyMappingSet keyMappings) : BaseControlDevice(console, port, keyMappings) { - _console = console; _turboSpeed = keyMappings.TurboSpeed; - _microphoneEnabled = port == 1 && EmulationSettings::GetConsoleType() == ConsoleType::Famicom; + _microphoneEnabled = port == 1 && _console->GetSettings()->GetConsoleType() == ConsoleType::Famicom; } uint8_t ToByte() @@ -111,7 +109,7 @@ public: if((addr == 0x4016 && (_port & 0x01) == 0) || (addr == 0x4017 && (_port & 0x01) == 1)) { output = _stateBuffer & 0x01; - if(_port >= 2 && EmulationSettings::GetConsoleType() == ConsoleType::Famicom) { + if(_port >= 2 && _console->GetSettings()->GetConsoleType() == ConsoleType::Famicom) { //Famicom outputs P3 & P4 on bit 1 output <<= 1; } diff --git a/Core/StereoDelayFilter.cpp b/Core/StereoDelayFilter.cpp index 21b6d896..9e3e3b85 100644 --- a/Core/StereoDelayFilter.cpp +++ b/Core/StereoDelayFilter.cpp @@ -1,9 +1,9 @@ #include "stdafx.h" #include "StereoDelayFilter.h" -void StereoDelayFilter::ApplyFilter(int16_t* stereoBuffer, size_t sampleCount, uint32_t sampleRate) +void StereoDelayFilter::ApplyFilter(int16_t* stereoBuffer, size_t sampleCount, uint32_t sampleRate, int32_t stereoDelay) { - size_t delaySampleCount = (int32_t)((double)EmulationSettings::GetStereoDelay() / 1000 * sampleRate); + size_t delaySampleCount = (int32_t)((double)stereoDelay / 1000 * sampleRate); if(delaySampleCount != _lastDelay) { _delayedSamplesLeft.clear(); _delayedSamplesRight.clear(); diff --git a/Core/StereoDelayFilter.h b/Core/StereoDelayFilter.h index 51275693..28d83c55 100644 --- a/Core/StereoDelayFilter.h +++ b/Core/StereoDelayFilter.h @@ -12,5 +12,5 @@ private: size_t _lastDelay = 0; public: - void ApplyFilter(int16_t* stereoBuffer, size_t sampleCount, uint32_t sampleRate); + void ApplyFilter(int16_t* stereoBuffer, size_t sampleCount, uint32_t sampleRate, int32_t stereoDelay); }; \ No newline at end of file diff --git a/Core/StereoPanningFilter.cpp b/Core/StereoPanningFilter.cpp index fa130715..447ba790 100644 --- a/Core/StereoPanningFilter.cpp +++ b/Core/StereoPanningFilter.cpp @@ -1,18 +1,16 @@ #include "stdafx.h" #include "StereoPanningFilter.h" -#include "EmulationSettings.h" #include -void StereoPanningFilter::UpdateFactors() +void StereoPanningFilter::UpdateFactors(double angle) { - double angle = EmulationSettings::GetStereoPanningAngle(); _leftChannelFactor = _baseFactor * (std::cos(angle) - std::sin(angle)); _rightChannelFactor = _baseFactor * (std::cos(angle) + std::sin(angle)); } -void StereoPanningFilter::ApplyFilter(int16_t* stereoBuffer, size_t sampleCount) +void StereoPanningFilter::ApplyFilter(int16_t* stereoBuffer, size_t sampleCount, double angle) { - UpdateFactors(); + UpdateFactors(angle); for(size_t i = 0; i < sampleCount * 2; i+=2) { int16_t leftSample = stereoBuffer[i]; diff --git a/Core/StereoPanningFilter.h b/Core/StereoPanningFilter.h index f6923cd7..9774bfad 100644 --- a/Core/StereoPanningFilter.h +++ b/Core/StereoPanningFilter.h @@ -8,8 +8,8 @@ private: double _leftChannelFactor = 0; double _rightChannelFactor = 0; - void UpdateFactors(); + void UpdateFactors(double angle); public: - void ApplyFilter(int16_t* stereoBuffer, size_t sampleCount); + void ApplyFilter(int16_t* stereoBuffer, size_t sampleCount, double angle); }; \ No newline at end of file diff --git a/Core/StudyBox.h b/Core/StudyBox.h index 0a6774c8..b0bca40e 100644 --- a/Core/StudyBox.h +++ b/Core/StudyBox.h @@ -45,12 +45,7 @@ protected: { switch(addr) { case 0x4200: case 0x4203: return 0x00; - case 0x4201: - return 0x10; /* | (EmulationSettings::CheckFlag(EmulationFlags::ShowFPS) ? 0x20 : 0x00) - | (EmulationSettings::CheckFlag(EmulationFlags::Turbo) ? 0x40 : 0x00); */ - /*(EmulationSettings::CheckFlag(EmulationFlags::ShowFPS) ? 0x00 : 0x20) | - (EmulationSettings::CheckFlag(EmulationFlags::Turbo) ? 0x00 : 0x50);*/ - + case 0x4201: return 0x10; case 0x4202: return _tapeReady ? 0x40 : 0x00; default: return 0xFF; } diff --git a/Core/SuborKeyboard.h b/Core/SuborKeyboard.h index 416a2d73..4d149486 100644 --- a/Core/SuborKeyboard.h +++ b/Core/SuborKeyboard.h @@ -87,7 +87,7 @@ protected: } public: - SuborKeyboard(KeyMappingSet keyMappings) : BaseControlDevice(BaseControlDevice::ExpDevicePort, keyMappings) + SuborKeyboard(shared_ptr console, KeyMappingSet keyMappings) : BaseControlDevice(console, BaseControlDevice::ExpDevicePort, keyMappings) { } diff --git a/Core/SuborMouse.h b/Core/SuborMouse.h index c4336d92..7983a8b6 100644 --- a/Core/SuborMouse.h +++ b/Core/SuborMouse.h @@ -27,11 +27,11 @@ protected: { SetPressedState(Buttons::Left, KeyManager::IsMouseButtonPressed(MouseButton::LeftButton)); SetPressedState(Buttons::Right, KeyManager::IsMouseButtonPressed(MouseButton::RightButton)); - SetMovement(KeyManager::GetMouseMovement(EmulationSettings::GetMouseSensitivity(MouseDevice::SuborMouse))); + SetMovement(KeyManager::GetMouseMovement(_console->GetSettings()->GetMouseSensitivity(MouseDevice::SuborMouse))); } public: - SuborMouse(uint8_t port) : BaseControlDevice(port) + SuborMouse(shared_ptr console, uint8_t port) : BaseControlDevice(console, port) { } diff --git a/Core/SystemActionManager.h b/Core/SystemActionManager.h index 8dd1a436..cca76ff4 100644 --- a/Core/SystemActionManager.h +++ b/Core/SystemActionManager.h @@ -6,7 +6,6 @@ class SystemActionManager : public BaseControlDevice { private: - std::weak_ptr _console; bool _needReset = false; bool _needPowerCycle = false; @@ -25,9 +24,8 @@ protected: public: enum Buttons { ResetButton = 0, PowerButton = 1 }; - SystemActionManager(std::shared_ptr console) : BaseControlDevice(BaseControlDevice::ConsoleInputPort) + SystemActionManager(std::shared_ptr console) : BaseControlDevice(console, BaseControlDevice::ConsoleInputPort) { - _console = console; } uint8_t ReadRAM(uint16_t addr) override @@ -71,7 +69,7 @@ public: void ProcessSystemActions() { - shared_ptr console = _console.lock(); + shared_ptr console = _console; if(console) { if(IsPressed(SystemActionManager::Buttons::ResetButton)) { console->ResetComponents(true); diff --git a/Core/TriangleChannel.h b/Core/TriangleChannel.h index 741f6cfd..8bb567c6 100644 --- a/Core/TriangleChannel.h +++ b/Core/TriangleChannel.h @@ -25,7 +25,7 @@ protected: if(_lengthCounter > 0 && _linearCounter > 0) { _sequencePosition = (_sequencePosition + 1) & 0x1F; - if(_period >= 2 || !EmulationSettings::CheckFlag(EmulationFlags::SilenceTriangleHighFreq)) { + if(_period >= 2 || !_console->GetSettings()->CheckFlag(EmulationFlags::SilenceTriangleHighFreq)) { //Disabling the triangle channel when period is < 2 removes "pops" in the audio that are caused by the ultrasonic frequencies //This is less "accurate" in terms of emulation, so this is an option (disabled by default) AddOutput(_sequence[_sequencePosition]); diff --git a/Core/Types.h b/Core/Types.h index cac032fa..8497f178 100644 --- a/Core/Types.h +++ b/Core/Types.h @@ -419,4 +419,11 @@ enum class PpuModel Ppu2C05C = 8, Ppu2C05D = 9, Ppu2C05E = 10 +}; + +enum class ConsoleId +{ + Master = 0, + Slave = 1, + HistoryViewer = 2 }; \ No newline at end of file diff --git a/Core/UnifLoader.h b/Core/UnifLoader.h index 8db1f9f6..06881984 100644 --- a/Core/UnifLoader.h +++ b/Core/UnifLoader.h @@ -210,7 +210,7 @@ public: Log("[UNIF] Battery: " + string(romData.Info.HasBattery ? "Yes" : "No")); if(!_checkOnly) { - GameDatabase::SetGameInfo(romData.Info.Hash.PrgChrCrc32, romData, !EmulationSettings::CheckFlag(EmulationFlags::DisableGameDatabase), false); + GameDatabase::SetGameInfo(romData.Info.Hash.PrgChrCrc32, romData, GameDatabase::IsEnabled(), false); } if(romData.Info.MapperID == UnifBoards::UnknownBoard) { diff --git a/Core/VideoDecoder.cpp b/Core/VideoDecoder.cpp index ad141e25..6c3cecd9 100644 --- a/Core/VideoDecoder.cpp +++ b/Core/VideoDecoder.cpp @@ -39,17 +39,17 @@ FrameInfo VideoDecoder::GetFrameInfo() void VideoDecoder::GetScreenSize(ScreenSize &size, bool ignoreScale) { if(_videoFilter) { - OverscanDimensions overscan = ignoreScale ? _videoFilter->GetOverscan() : EmulationSettings::GetOverscanDimensions(); + OverscanDimensions overscan = ignoreScale ? _videoFilter->GetOverscan() : _console->GetSettings()->GetOverscanDimensions(); FrameInfo frameInfo{ overscan.GetScreenWidth(), overscan.GetScreenHeight(), PPU::ScreenWidth, PPU::ScreenHeight, 4 }; - double aspectRatio = EmulationSettings::GetAspectRatio(_console); - double scale = (ignoreScale ? 1 : EmulationSettings::GetVideoScale()); + double aspectRatio = _console->GetSettings()->GetAspectRatio(_console); + double scale = (ignoreScale ? 1 : _console->GetSettings()->GetVideoScale()); size.Width = (int32_t)(frameInfo.Width * scale); size.Height = (int32_t)(frameInfo.Height * scale); if(aspectRatio != 0.0) { size.Width = (uint32_t)(frameInfo.OriginalHeight * scale * aspectRatio * ((double)frameInfo.Width / frameInfo.OriginalWidth)); } - if(EmulationSettings::GetScreenRotation() % 180) { + if(_console->GetSettings()->GetScreenRotation() % 180) { std::swap(size.Width, size.Height); } @@ -59,35 +59,35 @@ void VideoDecoder::GetScreenSize(ScreenSize &size, bool ignoreScale) void VideoDecoder::UpdateVideoFilter() { - VideoFilterType newFilter = EmulationSettings::GetVideoFilterType(); + VideoFilterType newFilter = _console->GetSettings()->GetVideoFilterType(); if(_videoFilterType != newFilter || _videoFilter == nullptr || (_hdScreenInfo && !_hdFilterEnabled) || (!_hdScreenInfo && _hdFilterEnabled)) { _videoFilterType = newFilter; - _videoFilter.reset(new DefaultVideoFilter()); + _videoFilter.reset(new DefaultVideoFilter(_console)); _scaleFilter.reset(); switch(_videoFilterType) { case VideoFilterType::None: break; - case VideoFilterType::NTSC: _videoFilter.reset(new NtscFilter()); break; - case VideoFilterType::BisqwitNtsc: _videoFilter.reset(new BisqwitNtscFilter(1)); break; - case VideoFilterType::BisqwitNtscHalfRes: _videoFilter.reset(new BisqwitNtscFilter(2)); break; - case VideoFilterType::BisqwitNtscQuarterRes: _videoFilter.reset(new BisqwitNtscFilter(4)); break; - case VideoFilterType::Raw: _videoFilter.reset(new RawVideoFilter()); break; + case VideoFilterType::NTSC: _videoFilter.reset(new NtscFilter(_console)); break; + case VideoFilterType::BisqwitNtsc: _videoFilter.reset(new BisqwitNtscFilter(_console, 1)); break; + case VideoFilterType::BisqwitNtscHalfRes: _videoFilter.reset(new BisqwitNtscFilter(_console, 2)); break; + case VideoFilterType::BisqwitNtscQuarterRes: _videoFilter.reset(new BisqwitNtscFilter(_console, 4)); break; + case VideoFilterType::Raw: _videoFilter.reset(new RawVideoFilter(_console)); break; default: _scaleFilter = ScaleFilter::GetScaleFilter(_videoFilterType); break; } _hdFilterEnabled = false; if(_hdScreenInfo) { - _videoFilter.reset(new HdVideoFilter(_console->GetHdData())); + _videoFilter.reset(new HdVideoFilter(_console, _console->GetHdData())); _hdFilterEnabled = true; } } - if(EmulationSettings::GetScreenRotation() == 0 && _rotateFilter) { + if(_console->GetSettings()->GetScreenRotation() == 0 && _rotateFilter) { _rotateFilter.reset(); - } else if(EmulationSettings::GetScreenRotation() > 0) { - if(!_rotateFilter || _rotateFilter->GetAngle() != EmulationSettings::GetScreenRotation()) { - _rotateFilter.reset(new RotateFilter(EmulationSettings::GetScreenRotation())); + } else if(_console->GetSettings()->GetScreenRotation() > 0) { + if(!_rotateFilter || _rotateFilter->GetAngle() != _console->GetSettings()->GetScreenRotation()) { + _rotateFilter.reset(new RotateFilter(_console->GetSettings()->GetScreenRotation())); } } } @@ -111,7 +111,7 @@ void VideoDecoder::DecodeFrame(bool synchronous) } if(_scaleFilter) { - outputBuffer = _scaleFilter->ApplyFilter(outputBuffer, frameInfo.Width, frameInfo.Height); + outputBuffer = _scaleFilter->ApplyFilter(outputBuffer, frameInfo.Width, frameInfo.Height, _console->GetSettings()->GetPictureSettings().ScanlineIntensity); frameInfo = _scaleFilter->GetFrameInfo(frameInfo); } @@ -121,10 +121,10 @@ void VideoDecoder::DecodeFrame(bool synchronous) ScreenSize screenSize; GetScreenSize(screenSize, true); - if(_previousScale != EmulationSettings::GetVideoScale() || screenSize.Height != _previousScreenSize.Height || screenSize.Width != _previousScreenSize.Width) { + if(_previousScale != _console->GetSettings()->GetVideoScale() || screenSize.Height != _previousScreenSize.Height || screenSize.Width != _previousScreenSize.Width) { _console->GetNotificationManager()->SendNotification(ConsoleNotificationType::ResolutionChanged); } - _previousScale = EmulationSettings::GetVideoScale(); + _previousScale = _console->GetSettings()->GetVideoScale(); _previousScreenSize = screenSize; _lastFrameInfo = frameInfo; @@ -210,7 +210,7 @@ void VideoDecoder::StopThread() _hud.reset(); _hdScreenInfo = nullptr; - EmulationSettings::SetPpuModel(PpuModel::Ppu2C02); + _console->GetSettings()->SetPpuModel(PpuModel::Ppu2C02); UpdateVideoFilter(); if(_ppuOutputBuffer != nullptr) { //Clear whole screen @@ -232,13 +232,13 @@ bool VideoDecoder::IsRunning() void VideoDecoder::TakeScreenshot() { if(_videoFilter) { - _videoFilter->TakeScreenshot(_console, _console->GetRomPath(), _videoFilterType); + _videoFilter->TakeScreenshot(_console->GetRomPath(), _videoFilterType); } } void VideoDecoder::TakeScreenshot(std::stringstream &stream) { if(_videoFilter) { - _videoFilter->TakeScreenshot(_console, _videoFilterType, "", &stream); + _videoFilter->TakeScreenshot(_videoFilterType, "", &stream); } } diff --git a/Core/VideoHud.cpp b/Core/VideoHud.cpp index 028e207f..eab052d9 100644 --- a/Core/VideoHud.cpp +++ b/Core/VideoHud.cpp @@ -12,27 +12,27 @@ void VideoHud::DrawHud(shared_ptr console, uint32_t *outputBuffer, FrameInfo frameInfo, OverscanDimensions overscan) { uint32_t displayCount = 0; - InputDisplaySettings settings = EmulationSettings::GetInputDisplaySettings(); + InputDisplaySettings settings = console->GetSettings()->GetInputDisplaySettings(); vector states = console->GetControlManager()->GetPortStates(); for(int inputPort = 0; inputPort < 4; inputPort++) { if((settings.VisiblePorts >> inputPort) & 0x01) { - if(DisplayControllerInput(states[inputPort], inputPort, outputBuffer, frameInfo, overscan, displayCount)) { + if(DisplayControllerInput(console, states[inputPort], inputPort, outputBuffer, frameInfo, overscan, displayCount)) { displayCount++; } } } - DrawMovieIcons(outputBuffer, frameInfo, overscan); + DrawMovieIcons(console, outputBuffer, frameInfo, overscan); } -bool VideoHud::DisplayControllerInput(ControlDeviceState &state, int inputPort, uint32_t *outputBuffer, FrameInfo &frameInfo, OverscanDimensions &overscan, uint32_t displayIndex) +bool VideoHud::DisplayControllerInput(shared_ptr console, ControlDeviceState &state, int inputPort, uint32_t *outputBuffer, FrameInfo &frameInfo, OverscanDimensions &overscan, uint32_t displayIndex) { - bool axisInverted = (EmulationSettings::GetScreenRotation() % 180) != 0; + bool axisInverted = (console->GetSettings()->GetScreenRotation() % 180) != 0; int scale = frameInfo.Width / (axisInverted ? overscan.GetScreenHeight() : overscan.GetScreenWidth()); uint32_t* rgbaBuffer = outputBuffer; - InputDisplaySettings settings = EmulationSettings::GetInputDisplaySettings(); + InputDisplaySettings settings = console->GetSettings()->GetInputDisplaySettings(); uint32_t yStart, xStart; switch(settings.DisplayPosition) { case InputDisplayPosition::TopLeft: @@ -56,7 +56,7 @@ bool VideoHud::DisplayControllerInput(ControlDeviceState &state, int inputPort, int32_t buttonState = -1; - shared_ptr device = ControlManager::CreateControllerDevice(EmulationSettings::GetControllerType(inputPort), 0, nullptr); + shared_ptr device = ControlManager::CreateControllerDevice(console->GetSettings()->GetControllerType(inputPort), 0, console); if(!device) { return false; } @@ -109,10 +109,10 @@ bool VideoHud::DisplayControllerInput(ControlDeviceState &state, int inputPort, return false; } -void VideoHud::DrawMovieIcons(uint32_t *outputBuffer, FrameInfo &frameInfo, OverscanDimensions &overscan) +void VideoHud::DrawMovieIcons(shared_ptr console, uint32_t *outputBuffer, FrameInfo &frameInfo, OverscanDimensions &overscan) { - if(EmulationSettings::CheckFlag(EmulationFlags::DisplayMovieIcons) && (MovieManager::Playing() || MovieManager::Recording())) { - InputDisplaySettings settings = EmulationSettings::GetInputDisplaySettings(); + if(console->GetSettings()->CheckFlag(EmulationFlags::DisplayMovieIcons) && (MovieManager::Playing() || MovieManager::Recording())) { + InputDisplaySettings settings = console->GetSettings()->GetInputDisplaySettings(); uint32_t xOffset = settings.VisiblePorts > 0 && settings.DisplayPosition == InputDisplayPosition::TopRight ? 50 : 27; uint32_t* rgbaBuffer = (uint32_t*)outputBuffer; int scale = frameInfo.Width / overscan.GetScreenWidth(); diff --git a/Core/VideoHud.h b/Core/VideoHud.h index 698c3c4f..d12be953 100644 --- a/Core/VideoHud.h +++ b/Core/VideoHud.h @@ -14,8 +14,8 @@ private: static const vector _recordIcon; void BlendColors(uint32_t* output, uint32_t input); - bool DisplayControllerInput(ControlDeviceState &state, int inputPort, uint32_t *outputBuffer, FrameInfo &frameInfo, OverscanDimensions &overscan, uint32_t displayIndex); - void DrawMovieIcons(uint32_t *outputBuffer, FrameInfo &frameInfo, OverscanDimensions &overscan); + bool DisplayControllerInput(shared_ptr console, ControlDeviceState &state, int inputPort, uint32_t *outputBuffer, FrameInfo &frameInfo, OverscanDimensions &overscan, uint32_t displayIndex); + void DrawMovieIcons(shared_ptr console, uint32_t *outputBuffer, FrameInfo &frameInfo, OverscanDimensions &overscan); public: void DrawHud(shared_ptr console, uint32_t *outputBuffer, FrameInfo frameInfo, OverscanDimensions overscan); diff --git a/Core/VideoRenderer.cpp b/Core/VideoRenderer.cpp index 67418eb2..6ed4e2a9 100644 --- a/Core/VideoRenderer.cpp +++ b/Core/VideoRenderer.cpp @@ -88,7 +88,7 @@ void VideoRenderer::StartRecording(string filename, VideoCodec codec, uint32_t c shared_ptr recorder(new AviRecorder(_console)); FrameInfo frameInfo = _console->GetVideoDecoder()->GetFrameInfo(); - if(recorder->StartRecording(filename, codec, frameInfo.Width, frameInfo.Height, frameInfo.BitsPerPixel, EmulationSettings::GetSampleRate(), compressionLevel)) { + if(recorder->StartRecording(filename, codec, frameInfo.Width, frameInfo.Height, frameInfo.BitsPerPixel, _console->GetSettings()->GetSampleRate(), compressionLevel)) { _aviRecorder = recorder; } } diff --git a/Core/VsControlManager.cpp b/Core/VsControlManager.cpp index 92b3f0d2..d16c1f09 100644 --- a/Core/VsControlManager.cpp +++ b/Core/VsControlManager.cpp @@ -104,7 +104,7 @@ uint8_t VsControlManager::ReadRAM(uint16_t addr) switch(addr) { case 0x4016: { - uint32_t dipSwitches = EmulationSettings::GetDipSwitches(); + uint32_t dipSwitches = _console->GetSettings()->GetDipSwitches(); if(!_console->IsMaster()) { dipSwitches >>= 8; } @@ -119,7 +119,7 @@ uint8_t VsControlManager::ReadRAM(uint16_t addr) case 0x4017: { value = ControlManager::ReadRAM(addr) & 0x01; - uint32_t dipSwitches = EmulationSettings::GetDipSwitches(); + uint32_t dipSwitches = _console->GetSettings()->GetDipSwitches(); if(!_console->IsMaster()) { dipSwitches >>= 8; } diff --git a/Core/Zapper.h b/Core/Zapper.h index e25eede2..897f0b2e 100644 --- a/Core/Zapper.h +++ b/Core/Zapper.h @@ -10,7 +10,6 @@ class Zapper : public BaseControlDevice { protected: bool HasCoordinates() override { return true; } - shared_ptr _console; string GetKeyNames() override { @@ -21,7 +20,7 @@ protected: void InternalSetStateFromInput() override { - if(EmulationSettings::InputEnabled()) { + if(_console->GetSettings()->InputEnabled()) { SetPressedState(Buttons::Fire, KeyManager::IsMouseButtonPressed(MouseButton::LeftButton)); } @@ -39,9 +38,8 @@ protected: } public: - Zapper(shared_ptr console, uint8_t port) : BaseControlDevice(port) + Zapper(shared_ptr console, uint8_t port) : BaseControlDevice(console, port) { - _console = console; } uint8_t ReadRAM(uint16_t addr) override @@ -66,7 +64,7 @@ public: int32_t scanline = ppu->GetCurrentScanline(); int32_t cycle = ppu->GetCurrentCycle(); - int radius = (int)EmulationSettings::GetZapperDetectionRadius(); + int radius = (int)console->GetSettings()->GetZapperDetectionRadius(); if(pos.X >= 0 && pos.Y >= 0) { for(int yOffset = -radius; yOffset <= radius; yOffset++) { diff --git a/Core/iNesLoader.cpp b/Core/iNesLoader.cpp index 6cadf5cd..52d1bf48 100644 --- a/Core/iNesLoader.cpp +++ b/Core/iNesLoader.cpp @@ -57,7 +57,7 @@ RomData iNesLoader::LoadRom(vector& romFile, NESHeader *preloadedHeader uint32_t prgSize = 0; uint32_t chrSize = 0; - if(EmulationSettings::CheckFlag(EmulationFlags::DisableGameDatabase) || !GameDatabase::GetDbRomSize(romData.Info.Hash.PrgChrCrc32, prgSize, chrSize)) { + if(!GameDatabase::IsEnabled() || !GameDatabase::GetDbRomSize(romData.Info.Hash.PrgChrCrc32, prgSize, chrSize)) { //Fallback on header sizes when game is not in DB (or DB is disabled) prgSize = header.GetPrgSize(); chrSize = header.GetChrSize(); @@ -118,7 +118,7 @@ RomData iNesLoader::LoadRom(vector& romFile, NESHeader *preloadedHeader } if(!_checkOnly) { - GameDatabase::SetGameInfo(romData.Info.Hash.PrgChrCrc32, romData, !EmulationSettings::CheckFlag(EmulationFlags::DisableGameDatabase) && header.GetRomHeaderVersion() != RomHeaderVersion::Nes2_0, preloadedHeader != nullptr); + GameDatabase::SetGameInfo(romData.Info.Hash.PrgChrCrc32, romData, GameDatabase::IsEnabled() && header.GetRomHeaderVersion() != RomHeaderVersion::Nes2_0, preloadedHeader != nullptr); } return romData; diff --git a/GUI.NET/Config/PreferenceInfo.cs b/GUI.NET/Config/PreferenceInfo.cs index 79b11497..a8406789 100644 --- a/GUI.NET/Config/PreferenceInfo.cs +++ b/GUI.NET/Config/PreferenceInfo.cs @@ -177,6 +177,9 @@ namespace Mesen.GUI.Config FileAssociationHelper.UpdateFileAssociation("unf", preferenceInfo.AssociateUnfFiles); } + InteropEmu.SetOsdState(!preferenceInfo.DisableOsd); + InteropEmu.SetGameDatabaseState(!preferenceInfo.DisableGameDatabase); + InteropEmu.SetFlag(EmulationFlags.AllowInvalidInput, preferenceInfo.AllowInvalidInput); InteropEmu.SetFlag(EmulationFlags.RemoveSpriteLimit, preferenceInfo.RemoveSpriteLimit); InteropEmu.SetFlag(EmulationFlags.FdsAutoLoadDisk, preferenceInfo.FdsAutoLoadDisk); @@ -185,9 +188,7 @@ namespace Mesen.GUI.Config InteropEmu.SetFlag(EmulationFlags.PauseOnMovieEnd, preferenceInfo.PauseOnMovieEnd); InteropEmu.SetFlag(EmulationFlags.AllowBackgroundInput, preferenceInfo.AllowBackgroundInput); InteropEmu.SetFlag(EmulationFlags.PauseWhenInBackground, preferenceInfo.PauseWhenInBackground || preferenceInfo.PauseWhenInMenusAndConfig || preferenceInfo.PauseWhenInDebuggingTools); - InteropEmu.SetFlag(EmulationFlags.DisableGameDatabase, preferenceInfo.DisableGameDatabase); InteropEmu.SetFlag(EmulationFlags.UseHighResolutionTimer, !preferenceInfo.DisableHighResolutionTimer); - InteropEmu.SetFlag(EmulationFlags.DisableOsd, preferenceInfo.DisableOsd); InteropEmu.SetFlag(EmulationFlags.AllowMismatchingSaveStates, preferenceInfo.AllowMismatchingSaveStates); InteropEmu.SetFlag(EmulationFlags.ShowFrameCounter, preferenceInfo.ShowFrameCounter); diff --git a/GUI.NET/Debugger/frmDebugger.cs b/GUI.NET/Debugger/frmDebugger.cs index c87ccada..4d6656f3 100644 --- a/GUI.NET/Debugger/frmDebugger.cs +++ b/GUI.NET/Debugger/frmDebugger.cs @@ -179,7 +179,7 @@ namespace Mesen.GUI.Debugger //Break once to show code and then resume execution InteropEmu.DebugStep(1); } - InteropEmu.SetFlag(EmulationFlags.Paused, false); + InteropEmu.Resume(); UpdateDebuggerFlags(); UpdateCdlRatios(); @@ -893,7 +893,7 @@ namespace Mesen.GUI.Debugger InteropEmu.SetFlag(EmulationFlags.DebuggerWindowEnabled, false); BreakpointManager.SetBreakpoints(); if(_wasPaused) { - InteropEmu.SetFlag(EmulationFlags.Paused, true); + InteropEmu.Pause(); } InteropEmu.DebugRun(); diff --git a/GUI.NET/Forms/frmHistoryViewer.cs b/GUI.NET/Forms/frmHistoryViewer.cs index 2b1c9fe1..34489b9a 100644 --- a/GUI.NET/Forms/frmHistoryViewer.cs +++ b/GUI.NET/Forms/frmHistoryViewer.cs @@ -19,13 +19,20 @@ namespace Mesen.GUI.Forms public frmHistoryViewer() { InitializeComponent(); + } + + protected override void OnShown(EventArgs e) + { + base.OnShown(e); InteropEmu.InitializeHistoryViewer(this.Handle, ctrlRenderer.Handle); trkPosition.Maximum = (int)(InteropEmu.GetHistoryViewerTotalFrameCount() / 60); UpdatePositionLabel(0); - InteropEmu.SetHistoryViewerPauseStatus(true); + InteropEmu.Pause(InteropEmu.ConsoleId.HistoryViewer); StartEmuThread(); tmrUpdatePosition.Start(); + + btnPausePlay.Focus(); } protected override void OnClosing(CancelEventArgs e) @@ -56,7 +63,11 @@ namespace Mesen.GUI.Forms if(trkPosition.Value == trkPosition.Maximum) { InteropEmu.SetHistoryViewerPosition(0); } - InteropEmu.SetHistoryViewerPauseStatus(!_paused); + if(_paused) { + InteropEmu.Resume(InteropEmu.ConsoleId.HistoryViewer); + } else { + InteropEmu.Pause(InteropEmu.ConsoleId.HistoryViewer); + } } private void trkPosition_ValueChanged(object sender, EventArgs e) @@ -66,7 +77,7 @@ namespace Mesen.GUI.Forms private void tmrUpdatePosition_Tick(object sender, EventArgs e) { - _paused = InteropEmu.GetHistoryViewerPauseStatus(); + _paused = InteropEmu.IsPaused(InteropEmu.ConsoleId.HistoryViewer); if(_paused) { btnPausePlay.Image = Properties.Resources.Play; } else { diff --git a/GUI.NET/Forms/frmMain.Tools.cs b/GUI.NET/Forms/frmMain.Tools.cs index 0580da07..d25ee8be 100644 --- a/GUI.NET/Forms/frmMain.Tools.cs +++ b/GUI.NET/Forms/frmMain.Tools.cs @@ -387,7 +387,7 @@ namespace Mesen.GUI.Forms mnuDebugDualSystemSecondaryCpu.Checked = !mnuDebugDualSystemSecondaryCpu.Checked; ConfigManager.Config.DebugInfo.DebugConsoleId = mnuDebugDualSystemSecondaryCpu.Checked ? InteropEmu.ConsoleId.Slave : InteropEmu.ConsoleId.Master; ConfigManager.ApplyChanges(); - InteropEmu.DebugSetDebuggerConsole(ConfigManager.Config.DebugInfo.DebugConsoleId == InteropEmu.ConsoleId.Slave ? 1 : 0); + InteropEmu.DebugSetDebuggerConsole(ConfigManager.Config.DebugInfo.DebugConsoleId); } } } diff --git a/GUI.NET/Forms/frmMain.cs b/GUI.NET/Forms/frmMain.cs index fc31bbe8..cc884829 100644 --- a/GUI.NET/Forms/frmMain.cs +++ b/GUI.NET/Forms/frmMain.cs @@ -208,7 +208,7 @@ namespace Mesen.GUI.Forms } mnuDebugDualSystemSecondaryCpu.Checked = ConfigManager.Config.DebugInfo.DebugConsoleId == InteropEmu.ConsoleId.Slave; - InteropEmu.DebugSetDebuggerConsole(ConfigManager.Config.DebugInfo.DebugConsoleId == InteropEmu.ConsoleId.Slave ? 1 : 0); + InteropEmu.DebugSetDebuggerConsole(ConfigManager.Config.DebugInfo.DebugConsoleId); } private void ProcessFullscreenSwitch(List switches) @@ -1089,6 +1089,7 @@ namespace Mesen.GUI.Forms mnuStopMovie.Enabled = running && !netPlay && (moviePlaying || movieRecording); mnuRecordMovie.Enabled = running && !moviePlaying && !movieRecording && !isNetPlayClient; mnuGameConfig.Enabled = !moviePlaying && !movieRecording; + mnuHistoryViewer.Enabled = running; bool waveRecording = InteropEmu.WaveIsRecording(); mnuWaveRecord.Enabled = running && !waveRecording; diff --git a/GUI.NET/InteropEmu.cs b/GUI.NET/InteropEmu.cs index 28273f48..4209f9b9 100644 --- a/GUI.NET/InteropEmu.cs +++ b/GUI.NET/InteropEmu.cs @@ -33,8 +33,6 @@ namespace Mesen.GUI [DllImport(DLLPath)] public static extern UInt32 GetHistoryViewerTotalFrameCount(); [DllImport(DLLPath)] public static extern void SetHistoryViewerPosition(UInt32 seekPosition); [DllImport(DLLPath)] public static extern UInt32 GetHistoryViewerPosition(); - [DllImport(DLLPath)] public static extern void SetHistoryViewerPauseStatus([MarshalAs(UnmanagedType.I1)]bool paused); - [DllImport(DLLPath)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool GetHistoryViewerPauseStatus(); [DllImport(DLLPath)] public static extern void SetDisplayLanguage(Language lang); @@ -81,9 +79,9 @@ namespace Mesen.GUI [DllImport(DLLPath)] public static extern void DisableAllKeys([MarshalAs(UnmanagedType.I1)]bool disabled); [DllImport(DLLPath)] public static extern void Run(); - [DllImport(DLLPath)] public static extern void Pause(); - [DllImport(DLLPath)] public static extern void Resume(); - [DllImport(DLLPath)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool IsPaused(); + [DllImport(DLLPath)] public static extern void Resume(ConsoleId consoleId = ConsoleId.Master); + [DllImport(DLLPath)] public static extern void Pause(ConsoleId consoleId = ConsoleId.Master); + [DllImport(DLLPath)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool IsPaused(ConsoleId consoleId = ConsoleId.Master); [DllImport(DLLPath)] public static extern void Stop(); [DllImport(DLLPath, EntryPoint = "GetRomInfo")] private static extern UInt32 GetRomInfoWrapper(ref InteropRomInfo romInfo, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]string filename = ""); @@ -106,7 +104,7 @@ namespace Mesen.GUI [DllImport(DLLPath)] public static extern void TakeScreenshot(); - [DllImport(DLLPath)] public static extern IntPtr RegisterNotificationCallback(Int32 consoleId, NotificationListener.NotificationCallback callback); + [DllImport(DLLPath)] public static extern IntPtr RegisterNotificationCallback(ConsoleId consoleId, NotificationListener.NotificationCallback callback); [DllImport(DLLPath)] public static extern void UnregisterNotificationCallback(IntPtr notificationListener); [DllImport(DLLPath)] public static extern void DisplayMessage([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]string title, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]string message, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]string param1 = null); @@ -168,6 +166,9 @@ namespace Mesen.GUI [DllImport(DLLPath)] public static extern void SetCheats([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)]InteropCheatInfo[] cheats, UInt32 length); + [DllImport(DLLPath)] public static extern void SetOsdState([MarshalAs(UnmanagedType.I1)]bool enabled); + [DllImport(DLLPath)] public static extern void SetGameDatabaseState([MarshalAs(UnmanagedType.I1)]bool enabled); + [DllImport(DLLPath)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool CheckFlag(EmulationFlags flag); [DllImport(DLLPath)] private static extern void SetFlags(EmulationFlags flags); [DllImport(DLLPath)] private static extern void ClearFlags(EmulationFlags flags); @@ -217,7 +218,7 @@ namespace Mesen.GUI [DllImport(DLLPath, EntryPoint = "GetAudioDevices")] private static extern IntPtr GetAudioDevicesWrapper(); [DllImport(DLLPath)] public static extern void SetAudioDevice(string audioDevice); - [DllImport(DLLPath)] public static extern void DebugSetDebuggerConsole(Int32 consoleId); + [DllImport(DLLPath)] public static extern void DebugSetDebuggerConsole(ConsoleId consoleId); [DllImport(DLLPath)] public static extern void DebugInitialize(); [DllImport(DLLPath)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool DebugIsDebuggerRunning(); [DllImport(DLLPath)] public static extern void DebugRelease(); @@ -1056,7 +1057,8 @@ namespace Mesen.GUI public enum ConsoleId { Master = 0, - Slave = 1 + Slave = 1, + HistoryViewer = 2 } public class NotificationListener : IDisposable @@ -1074,7 +1076,7 @@ namespace Mesen.GUI _callback = (int type, IntPtr parameter) => { this.ProcessNotification(type, parameter); }; - _notificationListener = InteropEmu.RegisterNotificationCallback(consoleId == ConsoleId.Slave ? 1 : 0, _callback); + _notificationListener = InteropEmu.RegisterNotificationCallback(consoleId, _callback); } public void Dispose() @@ -1502,7 +1504,6 @@ namespace Mesen.GUI SwapDutyCycles = 0x10000, - DisableGameDatabase = 0x20000, AutoConfigureInput = 0x40000, ShowLagCounter = 0x80000, @@ -1539,7 +1540,6 @@ namespace Mesen.GUI AdaptiveSpriteLimit = 0x80000000000, - DisableOsd = 0x100000000000, DisableGameSelectionScreen = 0x200000000000, ConfirmExitResetPower = 0x400000000000, diff --git a/InteropDLL/ConsoleWrapper.cpp b/InteropDLL/ConsoleWrapper.cpp index b7195be1..449956de 100644 --- a/InteropDLL/ConsoleWrapper.cpp +++ b/InteropDLL/ConsoleWrapper.cpp @@ -30,6 +30,7 @@ #include "../Core/FdsSystemActionManager.h" #include "../Core/VsSystemActionManager.h" #include "../Core/KeyManager.h" +#include "../Core/GameDatabase.h" #include "../Utilities/SimpleLock.h" #ifdef _WIN32 @@ -59,18 +60,19 @@ void* _viewerHandle = nullptr; string _returnString; string _logString; shared_ptr _console; +EmulationSettings *_settings = nullptr; shared_ptr _recordedRomTest; SimpleLock _externalNotificationListenerLock; vector> _externalNotificationListeners; typedef void (__stdcall *NotificationListenerCallback)(int, void*); -shared_ptr GetConsoleById(int32_t consoleId) +shared_ptr GetConsoleById(ConsoleId consoleId) { shared_ptr console; - if(consoleId == 1) { - //Get the VS Dualsystem's 2nd CPU, only if it's available (and requested) - console = _console->GetDualConsole(); + switch(consoleId) { + case ConsoleId::Slave: console = _console->GetDualConsole(); break; + case ConsoleId::HistoryViewer: console = _historyConsole; break; } if(!console) { @@ -123,6 +125,7 @@ namespace InteropEmu { { _console.reset(new Console()); _console->Init(); + _settings = _console->GetSettings(); } DllExport void __stdcall InitializeEmu(const char* homeFolder, void *windowHandle, void *viewerHandle, bool noAudio, bool noVideo, bool noInput) @@ -188,7 +191,7 @@ namespace InteropEmu { DllExport void __stdcall InitializeHistoryViewer(void *windowHandle, void *viewerHandle) { - _historyConsole.reset(new Console()); + _historyConsole.reset(new Console(nullptr, _settings)); _historyConsole->Init(); _historyConsole->Initialize(_console->GetRomPath(), _console->GetPatchFile()); _historyConsole->CopyRewindData(_console); @@ -218,21 +221,6 @@ namespace InteropEmu { } } - DllExport void __stdcall SetHistoryViewerPauseStatus(bool paused) - { - if(_historyConsole) { - _historyConsole->SetPauseStatus(paused); - } - } - - DllExport bool __stdcall GetHistoryViewerPauseStatus() - { - if(_historyConsole) { - return _historyConsole->GetPauseStatus(); - } - return true; - } - DllExport uint32_t __stdcall GetHistoryViewerTotalFrameCount() { if(_historyConsole) { @@ -283,23 +271,23 @@ namespace InteropEmu { return _returnString.c_str(); } - DllExport void __stdcall SetControllerType(uint32_t port, ControllerType type) { EmulationSettings::SetControllerType(port, type); } - DllExport void __stdcall SetControllerKeys(uint32_t port, KeyMappingSet mappings) { EmulationSettings::SetControllerKeys(port, mappings); } - DllExport void __stdcall SetZapperDetectionRadius(uint32_t detectionRadius) { EmulationSettings::SetZapperDetectionRadius(detectionRadius); } - DllExport void __stdcall SetExpansionDevice(ExpansionPortDevice device) { EmulationSettings::SetExpansionDevice(device); } - DllExport void __stdcall SetConsoleType(ConsoleType type) { EmulationSettings::SetConsoleType(type); } - DllExport void __stdcall SetMouseSensitivity(MouseDevice device, double sensitivity) { EmulationSettings::SetMouseSensitivity(device, sensitivity); } + DllExport void __stdcall SetControllerType(uint32_t port, ControllerType type) { _settings->SetControllerType(port, type); } + DllExport void __stdcall SetControllerKeys(uint32_t port, KeyMappingSet mappings) { _settings->SetControllerKeys(port, mappings); } + DllExport void __stdcall SetZapperDetectionRadius(uint32_t detectionRadius) { _settings->SetZapperDetectionRadius(detectionRadius); } + DllExport void __stdcall SetExpansionDevice(ExpansionPortDevice device) { _settings->SetExpansionDevice(device); } + DllExport void __stdcall SetConsoleType(ConsoleType type) { _settings->SetConsoleType(type); } + DllExport void __stdcall SetMouseSensitivity(MouseDevice device, double sensitivity) { _settings->SetMouseSensitivity(device, sensitivity); } - DllExport void __stdcall ClearShortcutKeys() { EmulationSettings::ClearShortcutKeys(); } - DllExport void __stdcall SetShortcutKey(EmulatorShortcut shortcut, KeyCombination keyCombination, int keySetIndex) { EmulationSettings::SetShortcutKey(shortcut, keyCombination, keySetIndex); } + DllExport void __stdcall ClearShortcutKeys() { _settings->ClearShortcutKeys(); } + DllExport void __stdcall SetShortcutKey(EmulatorShortcut shortcut, KeyCombination keyCombination, int keySetIndex) { _settings->SetShortcutKey(shortcut, keyCombination, keySetIndex); } - DllExport ControllerType __stdcall GetControllerType(uint32_t port) { return EmulationSettings::GetControllerType(port); } - DllExport ExpansionPortDevice GetExpansionDevice() { return EmulationSettings::GetExpansionDevice(); } - DllExport ConsoleType __stdcall GetConsoleType() { return EmulationSettings::GetConsoleType(); } + DllExport ControllerType __stdcall GetControllerType(uint32_t port) { return _settings->GetControllerType(port); } + DllExport ExpansionPortDevice GetExpansionDevice() { return _settings->GetExpansionDevice(); } + DllExport ConsoleType __stdcall GetConsoleType() { return _settings->GetConsoleType(); } - DllExport bool __stdcall HasZapper() { return EmulationSettings::HasZapper(); } - DllExport bool __stdcall HasFourScore() { return EmulationSettings::CheckFlag(EmulationFlags::HasFourScore); } - DllExport bool __stdcall HasArkanoidPaddle() { return EmulationSettings::HasArkanoidPaddle(); } + DllExport bool __stdcall HasZapper() { return _settings->HasZapper(); } + DllExport bool __stdcall HasFourScore() { return _settings->CheckFlag(EmulationFlags::HasFourScore); } + DllExport bool __stdcall HasArkanoidPaddle() { return _settings->HasArkanoidPaddle(); } DllExport void __stdcall SetMousePosition(double x, double y) { KeyManager::SetMousePosition(x, y); } DllExport void __stdcall SetMouseMovement(int16_t x, int16_t y) { KeyManager::SetMouseMovement(x, y); } @@ -343,8 +331,14 @@ namespace InteropEmu { } } - DllExport void __stdcall Resume() { EmulationSettings::ClearFlags(EmulationFlags::Paused); } - DllExport bool __stdcall IsPaused() { return EmulationSettings::CheckFlag(EmulationFlags::Paused); } + DllExport void __stdcall Resume(ConsoleId consoleId) { GetConsoleById(consoleId)->GetSettings()->ClearFlags(EmulationFlags::Paused); } + DllExport bool __stdcall IsPaused(ConsoleId consoleId) { return GetConsoleById(consoleId)->GetSettings()->CheckFlag(EmulationFlags::Paused); } + DllExport void __stdcall Pause(ConsoleId consoleId) + { + if(!GameClient::Connected()) { + GetConsoleById(consoleId)->GetSettings()->SetFlags(EmulationFlags::Paused); + } + } DllExport void __stdcall Stop() { @@ -413,7 +407,7 @@ namespace InteropEmu { DllExport void __stdcall Disconnect() { GameClient::Disconnect(); } DllExport bool __stdcall IsConnected() { return GameClient::Connected(); } - DllExport ControllerType __stdcall NetPlayGetControllerType(int32_t port) { return EmulationSettings::GetControllerType(port); } + DllExport ControllerType __stdcall NetPlayGetControllerType(int32_t port) { return _settings->GetControllerType(port); } DllExport int32_t __stdcall NetPlayGetAvailableControllers() { @@ -442,13 +436,6 @@ namespace InteropEmu { } } - DllExport void __stdcall Pause() - { - if(!IsConnected()) { - EmulationSettings::SetFlags(EmulationFlags::Paused); - } - } - DllExport void __stdcall Release() { ReleaseDualSystemAudioVideo(); @@ -473,7 +460,7 @@ namespace InteropEmu { DllExport void __stdcall TakeScreenshot() { _console->GetVideoDecoder()->TakeScreenshot(); } - DllExport INotificationListener* __stdcall RegisterNotificationCallback(int32_t consoleId, NotificationListenerCallback callback) + DllExport INotificationListener* __stdcall RegisterNotificationCallback(ConsoleId consoleId, NotificationListenerCallback callback) { auto lock = _externalNotificationListenerLock.AcquireSafe(); auto listener = shared_ptr(new InteropNotificationListener(callback)); @@ -576,50 +563,53 @@ namespace InteropEmu { DllExport void __stdcall SetCheats(CheatInfo cheats[], uint32_t length) { _console->GetCheatManager()->SetCheats(cheats, length); } - DllExport bool __stdcall CheckFlag(EmulationFlags flags) { return EmulationSettings::CheckFlag(flags); } - DllExport void __stdcall SetFlags(EmulationFlags flags) { EmulationSettings::SetFlags(flags); } - DllExport void __stdcall ClearFlags(EmulationFlags flags) { EmulationSettings::ClearFlags(flags); } - DllExport void __stdcall SetRamPowerOnState(RamPowerOnState state) { EmulationSettings::SetRamPowerOnState(state); } - DllExport void __stdcall SetDisplayLanguage(Language lang) { EmulationSettings::SetDisplayLanguage(lang); } - DllExport void __stdcall SetChannelVolume(uint32_t channel, double volume) { EmulationSettings::SetChannelVolume((AudioChannel)channel, volume); } - DllExport void __stdcall SetChannelPanning(uint32_t channel, double panning) { EmulationSettings::SetChannelPanning((AudioChannel)channel, panning); } - DllExport void __stdcall SetEqualizerFilterType(EqualizerFilterType filter) { EmulationSettings::SetEqualizerFilterType(filter); } - DllExport void __stdcall SetBandGain(uint32_t band, double gain) { EmulationSettings::SetBandGain(band, gain); } - DllExport void __stdcall SetEqualizerBands(double *bands, uint32_t bandCount) { EmulationSettings::SetEqualizerBands(bands, bandCount); } - DllExport void __stdcall SetMasterVolume(double volume, double volumeReduction) { EmulationSettings::SetMasterVolume(volume, volumeReduction); } - DllExport void __stdcall SetSampleRate(uint32_t sampleRate) { EmulationSettings::SetSampleRate(sampleRate); } - DllExport void __stdcall SetAudioLatency(uint32_t msLatency) { EmulationSettings::SetAudioLatency(msLatency); } - DllExport void __stdcall SetStereoFilter(StereoFilter stereoFilter) { EmulationSettings::SetStereoFilter(stereoFilter); } - DllExport void __stdcall SetStereoDelay(int32_t delay) { EmulationSettings::SetStereoDelay(delay); } - DllExport void __stdcall SetStereoPanningAngle(double angle) { EmulationSettings::SetStereoPanningAngle(angle); } - DllExport void __stdcall SetReverbParameters(double strength, double delay) { EmulationSettings::SetReverbParameters(strength, delay); } - DllExport void __stdcall SetCrossFeedRatio(uint32_t ratio) { EmulationSettings::SetCrossFeedRatio(ratio); } + DllExport void __stdcall SetOsdState(bool enabled) { MessageManager::SetOsdState(enabled); } + DllExport void __stdcall SetGameDatabaseState(bool enabled) { GameDatabase::SetGameDatabaseState(enabled); } + + DllExport bool __stdcall CheckFlag(EmulationFlags flags) { return _settings->CheckFlag(flags); } + DllExport void __stdcall SetFlags(EmulationFlags flags) { _settings->SetFlags(flags); } + DllExport void __stdcall ClearFlags(EmulationFlags flags) { _settings->ClearFlags(flags); } + DllExport void __stdcall SetRamPowerOnState(RamPowerOnState state) { _settings->SetRamPowerOnState(state); } + DllExport void __stdcall SetDisplayLanguage(Language lang) { _settings->SetDisplayLanguage(lang); } + DllExport void __stdcall SetChannelVolume(uint32_t channel, double volume) { _settings->SetChannelVolume((AudioChannel)channel, volume); } + DllExport void __stdcall SetChannelPanning(uint32_t channel, double panning) { _settings->SetChannelPanning((AudioChannel)channel, panning); } + DllExport void __stdcall SetEqualizerFilterType(EqualizerFilterType filter) { _settings->SetEqualizerFilterType(filter); } + DllExport void __stdcall SetBandGain(uint32_t band, double gain) { _settings->SetBandGain(band, gain); } + DllExport void __stdcall SetEqualizerBands(double *bands, uint32_t bandCount) { _settings->SetEqualizerBands(bands, bandCount); } + DllExport void __stdcall SetMasterVolume(double volume, double volumeReduction) { _settings->SetMasterVolume(volume, volumeReduction); } + DllExport void __stdcall SetSampleRate(uint32_t sampleRate) { _settings->SetSampleRate(sampleRate); } + DllExport void __stdcall SetAudioLatency(uint32_t msLatency) { _settings->SetAudioLatency(msLatency); } + DllExport void __stdcall SetStereoFilter(StereoFilter stereoFilter) { _settings->SetStereoFilter(stereoFilter); } + DllExport void __stdcall SetStereoDelay(int32_t delay) { _settings->SetStereoDelay(delay); } + DllExport void __stdcall SetStereoPanningAngle(double angle) { _settings->SetStereoPanningAngle(angle); } + DllExport void __stdcall SetReverbParameters(double strength, double delay) { _settings->SetReverbParameters(strength, delay); } + DllExport void __stdcall SetCrossFeedRatio(uint32_t ratio) { _settings->SetCrossFeedRatio(ratio); } DllExport NesModel __stdcall GetNesModel() { return _console->GetModel(); } - DllExport void __stdcall SetNesModel(uint32_t model) { EmulationSettings::SetNesModel((NesModel)model); } - DllExport void __stdcall SetOverscanDimensions(uint32_t left, uint32_t right, uint32_t top, uint32_t bottom) { EmulationSettings::SetOverscanDimensions(left, right, top, bottom); } - DllExport void __stdcall SetEmulationSpeed(uint32_t emulationSpeed) { EmulationSettings::SetEmulationSpeed(emulationSpeed, true); } - DllExport void __stdcall IncreaseEmulationSpeed() { EmulationSettings::IncreaseEmulationSpeed(); } - DllExport void __stdcall DecreaseEmulationSpeed() { EmulationSettings::DecreaseEmulationSpeed(); } - DllExport uint32_t __stdcall GetEmulationSpeed() { return EmulationSettings::GetEmulationSpeed(true); } - DllExport void __stdcall SetTurboRewindSpeed(uint32_t turboSpeed, uint32_t rewindSpeed) { EmulationSettings::SetTurboRewindSpeed(turboSpeed, rewindSpeed); } - DllExport void __stdcall SetRewindBufferSize(uint32_t seconds) { EmulationSettings::SetRewindBufferSize(seconds); } - DllExport void __stdcall SetOverclockRate(uint32_t overclockRate, bool adjustApu) { EmulationSettings::SetOverclockRate(overclockRate, adjustApu); } - DllExport void __stdcall SetPpuNmiConfig(uint32_t extraScanlinesBeforeNmi, uint32_t extraScanlinesAfterNmi) { EmulationSettings::SetPpuNmiConfig(extraScanlinesBeforeNmi, extraScanlinesAfterNmi); } - DllExport void __stdcall SetVideoScale(double scale) { EmulationSettings::SetVideoScale(scale); } - DllExport void __stdcall SetScreenRotation(uint32_t angle) { EmulationSettings::SetScreenRotation(angle); } - DllExport void __stdcall SetExclusiveRefreshRate(uint32_t angle) { EmulationSettings::SetExclusiveRefreshRate(angle); } - DllExport void __stdcall SetVideoAspectRatio(VideoAspectRatio aspectRatio, double customRatio) { EmulationSettings::SetVideoAspectRatio(aspectRatio, customRatio); } - DllExport void __stdcall SetVideoFilter(VideoFilterType filter) { EmulationSettings::SetVideoFilterType(filter); } - DllExport void __stdcall SetVideoResizeFilter(VideoResizeFilter filter) { EmulationSettings::SetVideoResizeFilter(filter); } - DllExport void __stdcall GetRgbPalette(uint32_t *paletteBuffer) { EmulationSettings::GetRgbPalette(paletteBuffer); } - DllExport void __stdcall SetRgbPalette(uint32_t *paletteBuffer) { EmulationSettings::SetRgbPalette(paletteBuffer); } - DllExport void __stdcall SetPictureSettings(double brightness, double contrast, double saturation, double hue, double scanlineIntensity) { EmulationSettings::SetPictureSettings(brightness, contrast, saturation, hue, scanlineIntensity); } - DllExport void __stdcall SetNtscFilterSettings(double artifacts, double bleed, double fringing, double gamma, double resolution, double sharpness, bool mergeFields, double yFilterLength, double iFilterLength, double qFilterLength, bool verticalBlend) { EmulationSettings::SetNtscFilterSettings(artifacts, bleed, fringing, gamma, resolution, sharpness, mergeFields, yFilterLength, iFilterLength, qFilterLength, verticalBlend, false); } - DllExport void __stdcall SetPauseScreenMessage(char* message) { EmulationSettings::SetPauseScreenMessage(message); } + DllExport void __stdcall SetNesModel(uint32_t model) { _settings->SetNesModel((NesModel)model); } + DllExport void __stdcall SetOverscanDimensions(uint32_t left, uint32_t right, uint32_t top, uint32_t bottom) { _settings->SetOverscanDimensions(left, right, top, bottom); } + DllExport void __stdcall SetEmulationSpeed(uint32_t emulationSpeed) { _settings->SetEmulationSpeed(emulationSpeed, true); } + DllExport void __stdcall IncreaseEmulationSpeed() { _settings->IncreaseEmulationSpeed(); } + DllExport void __stdcall DecreaseEmulationSpeed() { _settings->DecreaseEmulationSpeed(); } + DllExport uint32_t __stdcall GetEmulationSpeed() { return _settings->GetEmulationSpeed(true); } + DllExport void __stdcall SetTurboRewindSpeed(uint32_t turboSpeed, uint32_t rewindSpeed) { _settings->SetTurboRewindSpeed(turboSpeed, rewindSpeed); } + DllExport void __stdcall SetRewindBufferSize(uint32_t seconds) { _settings->SetRewindBufferSize(seconds); } + DllExport void __stdcall SetOverclockRate(uint32_t overclockRate, bool adjustApu) { _settings->SetOverclockRate(overclockRate, adjustApu); } + DllExport void __stdcall SetPpuNmiConfig(uint32_t extraScanlinesBeforeNmi, uint32_t extraScanlinesAfterNmi) { _settings->SetPpuNmiConfig(extraScanlinesBeforeNmi, extraScanlinesAfterNmi); } + DllExport void __stdcall SetVideoScale(double scale) { _settings->SetVideoScale(scale); } + DllExport void __stdcall SetScreenRotation(uint32_t angle) { _settings->SetScreenRotation(angle); } + DllExport void __stdcall SetExclusiveRefreshRate(uint32_t angle) { _settings->SetExclusiveRefreshRate(angle); } + DllExport void __stdcall SetVideoAspectRatio(VideoAspectRatio aspectRatio, double customRatio) { _settings->SetVideoAspectRatio(aspectRatio, customRatio); } + DllExport void __stdcall SetVideoFilter(VideoFilterType filter) { _settings->SetVideoFilterType(filter); } + DllExport void __stdcall SetVideoResizeFilter(VideoResizeFilter filter) { _settings->SetVideoResizeFilter(filter); } + DllExport void __stdcall GetRgbPalette(uint32_t *paletteBuffer) { _settings->GetRgbPalette(paletteBuffer); } + DllExport void __stdcall SetRgbPalette(uint32_t *paletteBuffer) { _settings->SetRgbPalette(paletteBuffer); } + DllExport void __stdcall SetPictureSettings(double brightness, double contrast, double saturation, double hue, double scanlineIntensity) { _settings->SetPictureSettings(brightness, contrast, saturation, hue, scanlineIntensity); } + DllExport void __stdcall SetNtscFilterSettings(double artifacts, double bleed, double fringing, double gamma, double resolution, double sharpness, bool mergeFields, double yFilterLength, double iFilterLength, double qFilterLength, bool verticalBlend) { _settings->SetNtscFilterSettings(artifacts, bleed, fringing, gamma, resolution, sharpness, mergeFields, yFilterLength, iFilterLength, qFilterLength, verticalBlend, false); } + DllExport void __stdcall SetPauseScreenMessage(char* message) { _settings->SetPauseScreenMessage(message); } - DllExport void __stdcall SetInputDisplaySettings(uint8_t visiblePorts, InputDisplayPosition displayPosition, bool displayHorizontally) { EmulationSettings::SetInputDisplaySettings(visiblePorts, displayPosition, displayHorizontally); } - DllExport void __stdcall SetAutoSaveOptions(uint32_t delayInMinutes, bool showMessage) { EmulationSettings::SetAutoSaveOptions(delayInMinutes, showMessage); } + DllExport void __stdcall SetInputDisplaySettings(uint8_t visiblePorts, InputDisplayPosition displayPosition, bool displayHorizontally) { _settings->SetInputDisplaySettings(visiblePorts, displayPosition, displayHorizontally); } + DllExport void __stdcall SetAutoSaveOptions(uint32_t delayInMinutes, bool showMessage) { _settings->SetAutoSaveOptions(delayInMinutes, showMessage); } DllExport const char* __stdcall GetAudioDevices() { @@ -659,7 +649,7 @@ namespace InteropEmu { } } DllExport void __stdcall NsfSetNsfConfig(int32_t autoDetectSilenceDelay, int32_t moveToNextTrackTime, bool disableApuIrqs) { - EmulationSettings::SetNsfConfig(autoDetectSilenceDelay, moveToNextTrackTime, disableApuIrqs); + _settings->SetNsfConfig(autoDetectSilenceDelay, moveToNextTrackTime, disableApuIrqs); } //FDS functions @@ -712,7 +702,7 @@ namespace InteropEmu { DllExport void __stdcall SetDipSwitches(uint32_t dipSwitches) { - EmulationSettings::SetDipSwitches(dipSwitches); + _settings->SetDipSwitches(dipSwitches); } DllExport bool __stdcall IsHdPpu() { return _console->IsHdPpu(); } diff --git a/InteropDLL/DebugWrapper.cpp b/InteropDLL/DebugWrapper.cpp index f3eafae0..42821772 100644 --- a/InteropDLL/DebugWrapper.cpp +++ b/InteropDLL/DebugWrapper.cpp @@ -9,9 +9,12 @@ #include "../Core/Assembler.h" #include "../Core/TraceLogger.h" +enum class ConsoleId; + extern shared_ptr _console; -static int32_t _debugConsoleId = 0; -extern shared_ptr GetConsoleById(int32_t consoleId); +extern shared_ptr GetConsoleById(ConsoleId consoleId); + +static ConsoleId _debugConsoleId = ConsoleId::Master; shared_ptr GetDebugger() { @@ -36,7 +39,7 @@ extern "C" return GetConsoleById(_debugConsoleId)->GetDebugger(false).get() != nullptr; } - DllExport void __stdcall DebugSetDebuggerConsole(int32_t consoleId) + DllExport void __stdcall DebugSetDebuggerConsole(ConsoleId consoleId) { _debugConsoleId = consoleId; } diff --git a/Libretro/LibretroRenderer.h b/Libretro/LibretroRenderer.h index 4ebf9c32..33321929 100644 --- a/Libretro/LibretroRenderer.h +++ b/Libretro/LibretroRenderer.h @@ -55,20 +55,20 @@ public: info.timing.fps = _console->GetModel() == NesModel::NTSC ? 60.098811862348404716732985230828 : 50.006977968268290848936010226333; info.timing.sample_rate = 48000; - float ratio = (float)EmulationSettings::GetAspectRatio(_console); + float ratio = (float)_console->GetSettings()->GetAspectRatio(_console); if(ratio == 0.0f) { ratio = 1.0f; } - ratio *= (float)EmulationSettings::GetOverscanDimensions().GetScreenWidth() / EmulationSettings::GetOverscanDimensions().GetScreenHeight() / 256 * 240; + ratio *= (float)_console->GetSettings()->GetOverscanDimensions().GetScreenWidth() / _console->GetSettings()->GetOverscanDimensions().GetScreenHeight() / 256 * 240; - if(EmulationSettings::GetScreenRotation() % 180) { + if(_console->GetSettings()->GetScreenRotation() % 180) { info.geometry.aspect_ratio = ratio == 0.0f ? 0.0f : 1.0f / ratio; } else { info.geometry.aspect_ratio = ratio; } - info.geometry.base_width = EmulationSettings::GetOverscanDimensions().GetScreenWidth(); - info.geometry.base_height = EmulationSettings::GetOverscanDimensions().GetScreenHeight(); + info.geometry.base_width = _console->GetSettings()->GetOverscanDimensions().GetScreenWidth(); + info.geometry.base_height = _console->GetSettings()->GetOverscanDimensions().GetScreenHeight(); info.geometry.max_width = maxWidth; info.geometry.max_height = maxHeight; diff --git a/Libretro/libretro.cpp b/Libretro/libretro.cpp index c4ced274..e36b5861 100644 --- a/Libretro/libretro.cpp +++ b/Libretro/libretro.cpp @@ -120,11 +120,11 @@ extern "C" { _keyManager.reset(new LibretroKeyManager(_console)); _messageManager.reset(new LibretroMessageManager(logCallback, retroEnv)); - EmulationSettings::SetFlags(EmulationFlags::FdsAutoLoadDisk); - EmulationSettings::SetFlags(EmulationFlags::AutoConfigureInput); - EmulationSettings::SetSampleRate(48000); - EmulationSettings::SetAutoSaveOptions(0, false); - EmulationSettings::SetRewindBufferSize(0); + _console->GetSettings()->SetFlags(EmulationFlags::FdsAutoLoadDisk); + _console->GetSettings()->SetFlags(EmulationFlags::AutoConfigureInput); + _console->GetSettings()->SetSampleRate(48000); + _console->GetSettings()->SetAutoSaveOptions(0, false); + _console->GetSettings()->SetRewindBufferSize(0); } RETRO_API void retro_deinit() @@ -267,9 +267,9 @@ extern "C" { if(retroEnv(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) { string value = string(var.value); if(value == "disabled") { - EmulationSettings::ClearFlags(flagValue); + _console->GetSettings()->ClearFlags(flagValue); } else { - EmulationSettings::SetFlags(flagValue); + _console->GetSettings()->SetFlags(flagValue); } } } @@ -277,7 +277,7 @@ extern "C" { void load_custom_palette() { //Setup default palette in case we can't load the custom one - EmulationSettings::SetRgbPalette(defaultPalette); + _console->GetSettings()->SetRgbPalette(defaultPalette); //Try to load the custom palette from the MesenPalette.pal file string palettePath = FolderUtilities::CombinePath(FolderUtilities::GetHomeFolder(), "MesenPalette.pal"); @@ -293,7 +293,7 @@ extern "C" { for(int i = 0; i < 64; i++) { customPalette[i] = 0xFF000000 | fileData[i * 3 + 2] | (fileData[i * 3 + 1] << 8) | (fileData[i * 3] << 16); } - EmulationSettings::SetRgbPalette(customPalette); + _console->GetSettings()->SetRgbPalette(customPalette); } } } @@ -301,9 +301,9 @@ extern "C" { void update_settings() { struct retro_variable var = { }; - EmulationSettings::SetPictureSettings(0, 0, 0, 0, 0); + _console->GetSettings()->SetPictureSettings(0, 0, 0, 0, 0); - _hdPacksEnabled = EmulationSettings::CheckFlag(EmulationFlags::UseHdPacks); + _hdPacksEnabled = _console->GetSettings()->CheckFlag(EmulationFlags::UseHdPacks); set_flag(MesenNoSpriteLimit, EmulationFlags::RemoveSpriteLimit | EmulationFlags::AdaptiveSpriteLimit); set_flag(MesenHdPacks, EmulationFlags::UseHdPacks); @@ -318,10 +318,10 @@ extern "C" { if(retroEnv(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) { string value = string(var.value); if(value == "enabled") { - EmulationSettings::SetStereoFilter(StereoFilter::Delay); - EmulationSettings::SetStereoDelay(15); + _console->GetSettings()->SetStereoFilter(StereoFilter::Delay); + _console->GetSettings()->SetStereoDelay(15); } else { - EmulationSettings::SetStereoFilter(StereoFilter::None); + _console->GetSettings()->SetStereoFilter(StereoFilter::None); } } @@ -329,30 +329,30 @@ extern "C" { if(retroEnv(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) { string value = string(var.value); if(value == "Disabled") { - EmulationSettings::SetVideoFilterType(VideoFilterType::None); + _console->GetSettings()->SetVideoFilterType(VideoFilterType::None); } else if(value == "Composite (Blargg)") { - EmulationSettings::SetVideoFilterType(VideoFilterType::NTSC); - EmulationSettings::SetNtscFilterSettings(0, 0, 0, 0, 0, 0, false, 0, 0, 0, false, true); + _console->GetSettings()->SetVideoFilterType(VideoFilterType::NTSC); + _console->GetSettings()->SetNtscFilterSettings(0, 0, 0, 0, 0, 0, false, 0, 0, 0, false, true); } else if(value == "S-Video (Blargg)") { - EmulationSettings::SetVideoFilterType(VideoFilterType::NTSC); - EmulationSettings::SetNtscFilterSettings(-1.0, 0, -1.0, 0, 0.2, 0.2, false, 0, 0, 0, false, true); + _console->GetSettings()->SetVideoFilterType(VideoFilterType::NTSC); + _console->GetSettings()->SetNtscFilterSettings(-1.0, 0, -1.0, 0, 0.2, 0.2, false, 0, 0, 0, false, true); } else if(value == "RGB (Blargg)") { - EmulationSettings::SetVideoFilterType(VideoFilterType::NTSC); - EmulationSettings::SetPictureSettings(0, 0, 0, 0, 0); - EmulationSettings::SetNtscFilterSettings(-1.0, -1.0, -1.0, 0, 0.7, 0.2, false, 0, 0, 0, false, true); + _console->GetSettings()->SetVideoFilterType(VideoFilterType::NTSC); + _console->GetSettings()->SetPictureSettings(0, 0, 0, 0, 0); + _console->GetSettings()->SetNtscFilterSettings(-1.0, -1.0, -1.0, 0, 0.7, 0.2, false, 0, 0, 0, false, true); } else if(value == "Monochrome (Blargg)") { - EmulationSettings::SetVideoFilterType(VideoFilterType::NTSC); - EmulationSettings::SetPictureSettings(0, 0, -1.0, 0, 0); - EmulationSettings::SetNtscFilterSettings(-0.2, -0.1, -0.2, 0, 0.7, 0.2, false, 0, 0, 0, false, true); + _console->GetSettings()->SetVideoFilterType(VideoFilterType::NTSC); + _console->GetSettings()->SetPictureSettings(0, 0, -1.0, 0, 0); + _console->GetSettings()->SetNtscFilterSettings(-0.2, -0.1, -0.2, 0, 0.7, 0.2, false, 0, 0, 0, false, true); } else if(value == "Bisqwit 2x") { - EmulationSettings::SetVideoFilterType(VideoFilterType::BisqwitNtscQuarterRes); - EmulationSettings::SetNtscFilterSettings(0, 0, 0, 0, 0, 0, false, 0, 0, 0, false, true); + _console->GetSettings()->SetVideoFilterType(VideoFilterType::BisqwitNtscQuarterRes); + _console->GetSettings()->SetNtscFilterSettings(0, 0, 0, 0, 0, 0, false, 0, 0, 0, false, true); } else if(value == "Bisqwit 4x") { - EmulationSettings::SetVideoFilterType(VideoFilterType::BisqwitNtscHalfRes); - EmulationSettings::SetNtscFilterSettings(0, 0, 0, 0, 0, 0, false, 0, 0, 0, false, true); + _console->GetSettings()->SetVideoFilterType(VideoFilterType::BisqwitNtscHalfRes); + _console->GetSettings()->SetNtscFilterSettings(0, 0, 0, 0, 0, 0, false, 0, 0, 0, false, true); } else if(value == "Bisqwit 8x") { - EmulationSettings::SetVideoFilterType(VideoFilterType::BisqwitNtsc); - EmulationSettings::SetNtscFilterSettings(0, 0, 0, 0, 0, 0, false, 0, 0, 0, false, true); + _console->GetSettings()->SetVideoFilterType(VideoFilterType::BisqwitNtsc); + _console->GetSettings()->SetNtscFilterSettings(0, 0, 0, 0, 0, 0, false, 0, 0, 0, false, true); } } @@ -360,28 +360,28 @@ extern "C" { if(retroEnv(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) { string value = string(var.value); if(value == "Default") { - EmulationSettings::SetRgbPalette(defaultPalette); + _console->GetSettings()->SetRgbPalette(defaultPalette); } else if(value == "Composite Direct (by FirebrandX)") { - EmulationSettings::SetRgbPalette(compositeDirectPalette); + _console->GetSettings()->SetRgbPalette(compositeDirectPalette); } else if(value == "Nes Classic") { - EmulationSettings::SetRgbPalette(nesClassicPalette); + _console->GetSettings()->SetRgbPalette(nesClassicPalette); } else if(value == "Nestopia (RGB)") { - EmulationSettings::SetRgbPalette(nestopiaRgbPalette); + _console->GetSettings()->SetRgbPalette(nestopiaRgbPalette); } else if(value == "Original Hardware (by FirebrandX)") { - EmulationSettings::SetRgbPalette(originalHardwarePalette); + _console->GetSettings()->SetRgbPalette(originalHardwarePalette); } else if(value == "PVM Style (by FirebrandX)") { - EmulationSettings::SetRgbPalette(pvmStylePalette); + _console->GetSettings()->SetRgbPalette(pvmStylePalette); } else if(value == "Sony CXA2025AS") { - EmulationSettings::SetRgbPalette(sonyCxa2025AsPalette); + _console->GetSettings()->SetRgbPalette(sonyCxa2025AsPalette); } else if(value == "Unsaturated v6 (by FirebrandX)") { - EmulationSettings::SetRgbPalette(unsaturatedPalette); + _console->GetSettings()->SetRgbPalette(unsaturatedPalette); } else if(value == "YUV v3 (by FirebrandX)") { - EmulationSettings::SetRgbPalette(yuvPalette); + _console->GetSettings()->SetRgbPalette(yuvPalette); } else if(value == "Custom") { load_custom_palette(); } else if(value == "Raw") { //Using the raw palette replaces the NTSC filters, if one is selected - EmulationSettings::SetVideoFilterType(VideoFilterType::Raw); + _console->GetSettings()->SetVideoFilterType(VideoFilterType::Raw); } } @@ -411,9 +411,9 @@ extern "C" { } if(beforeNmi) { - EmulationSettings::SetPpuNmiConfig(lineCount, 0); + _console->GetSettings()->SetPpuNmiConfig(lineCount, 0); } else { - EmulationSettings::SetPpuNmiConfig(0, lineCount); + _console->GetSettings()->SetPpuNmiConfig(0, lineCount); } } @@ -438,23 +438,23 @@ extern "C" { overscanVertical = 16; } } - EmulationSettings::SetOverscanDimensions(overscanHorizontal, overscanHorizontal, overscanVertical, overscanVertical); + _console->GetSettings()->SetOverscanDimensions(overscanHorizontal, overscanHorizontal, overscanVertical, overscanVertical); var.key = MesenAspectRatio; if(retroEnv(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) { string value = string(var.value); if(value == "Auto") { - EmulationSettings::SetVideoAspectRatio(VideoAspectRatio::Auto, 1.0); + _console->GetSettings()->SetVideoAspectRatio(VideoAspectRatio::Auto, 1.0); } else if(value == "No Stretching") { - EmulationSettings::SetVideoAspectRatio(VideoAspectRatio::NoStretching, 1.0); + _console->GetSettings()->SetVideoAspectRatio(VideoAspectRatio::NoStretching, 1.0); } else if(value == "NTSC") { - EmulationSettings::SetVideoAspectRatio(VideoAspectRatio::NTSC, 1.0); + _console->GetSettings()->SetVideoAspectRatio(VideoAspectRatio::NTSC, 1.0); } else if(value == "PAL") { - EmulationSettings::SetVideoAspectRatio(VideoAspectRatio::PAL, 1.0); + _console->GetSettings()->SetVideoAspectRatio(VideoAspectRatio::PAL, 1.0); } else if(value == "4:3") { - EmulationSettings::SetVideoAspectRatio(VideoAspectRatio::Standard, 1.0); + _console->GetSettings()->SetVideoAspectRatio(VideoAspectRatio::Standard, 1.0); } else if(value == "16:9") { - EmulationSettings::SetVideoAspectRatio(VideoAspectRatio::Widescreen, 1.0); + _console->GetSettings()->SetVideoAspectRatio(VideoAspectRatio::Widescreen, 1.0); } } @@ -462,13 +462,13 @@ extern "C" { if(retroEnv(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) { string value = string(var.value); if(value == "Auto") { - EmulationSettings::SetNesModel(NesModel::Auto); + _console->GetSettings()->SetNesModel(NesModel::Auto); } else if(value == "NTSC") { - EmulationSettings::SetNesModel(NesModel::NTSC); + _console->GetSettings()->SetNesModel(NesModel::NTSC); } else if(value == "PAL") { - EmulationSettings::SetNesModel(NesModel::PAL); + _console->GetSettings()->SetNesModel(NesModel::PAL); } else if(value == "Dendy") { - EmulationSettings::SetNesModel(NesModel::Dendy); + _console->GetSettings()->SetNesModel(NesModel::Dendy); } } @@ -476,11 +476,11 @@ extern "C" { if(retroEnv(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) { string value = string(var.value); if(value == "All 0s (Default)") { - EmulationSettings::SetRamPowerOnState(RamPowerOnState::AllZeros); + _console->GetSettings()->SetRamPowerOnState(RamPowerOnState::AllZeros); } else if(value == "All 1s") { - EmulationSettings::SetRamPowerOnState(RamPowerOnState::AllOnes); + _console->GetSettings()->SetRamPowerOnState(RamPowerOnState::AllOnes); } else if(value == "Random Values") { - EmulationSettings::SetRamPowerOnState(RamPowerOnState::Random); + _console->GetSettings()->SetRamPowerOnState(RamPowerOnState::Random); } } @@ -488,13 +488,13 @@ extern "C" { if(retroEnv(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) { string value = string(var.value); if(value == "None") { - EmulationSettings::SetScreenRotation(0); + _console->GetSettings()->SetScreenRotation(0); } else if(value == u8"90 degrees") { - EmulationSettings::SetScreenRotation(90); + _console->GetSettings()->SetScreenRotation(90); } else if(value == u8"180 degrees") { - EmulationSettings::SetScreenRotation(180); + _console->GetSettings()->SetScreenRotation(180); } else if(value == u8"270 degrees") { - EmulationSettings::SetScreenRotation(270); + _console->GetSettings()->SetScreenRotation(270); } } @@ -523,7 +523,7 @@ extern "C" { auto getKeyBindings = [=](int port) { KeyMappingSet keyMappings; keyMappings.TurboSpeed = turboSpeed; - if(EmulationSettings::GetControllerType(port) == ControllerType::SnesController) { + if(_console->GetSettings()->GetControllerType(port) == ControllerType::SnesController) { keyMappings.Mapping1.LButton = getKeyCode(port, RETRO_DEVICE_ID_JOYPAD_L); keyMappings.Mapping1.RButton = getKeyCode(port, RETRO_DEVICE_ID_JOYPAD_R); keyMappings.Mapping1.A = getKeyCode(port, RETRO_DEVICE_ID_JOYPAD_A); @@ -556,7 +556,7 @@ extern "C" { keyMappings.Mapping1.PartyTapButtons[5] = getKeyCode(4, RETRO_DEVICE_ID_JOYPAD_R); unsigned powerPadPort = 0; - if(EmulationSettings::GetExpansionDevice() == ExpansionPortDevice::FamilyTrainerMat) { + if(_console->GetSettings()->GetExpansionDevice() == ExpansionPortDevice::FamilyTrainerMat) { powerPadPort = 4; } @@ -602,10 +602,10 @@ extern "C" { return keyMappings; }; - EmulationSettings::SetControllerKeys(0, getKeyBindings(0)); - EmulationSettings::SetControllerKeys(1, getKeyBindings(1)); - EmulationSettings::SetControllerKeys(2, getKeyBindings(2)); - EmulationSettings::SetControllerKeys(3, getKeyBindings(3)); + _console->GetSettings()->SetControllerKeys(0, getKeyBindings(0)); + _console->GetSettings()->SetControllerKeys(1, getKeyBindings(1)); + _console->GetSettings()->SetControllerKeys(2, getKeyBindings(2)); + _console->GetSettings()->SetControllerKeys(3, getKeyBindings(3)); retro_system_av_info avInfo = {}; _renderer->GetSystemAudioVideoInfo(avInfo); @@ -614,7 +614,7 @@ extern "C" { RETRO_API void retro_run() { - if(EmulationSettings::CheckFlag(EmulationFlags::ForceMaxSpeed)) { + if(_console->GetSettings()->CheckFlag(EmulationFlags::ForceMaxSpeed)) { //Skip frames to speed up emulation while still outputting at 50/60 fps (needed for FDS fast forward while loading) _renderer->SetSkipMode(true); _soundManager->SetSkipMode(true); @@ -630,7 +630,7 @@ extern "C" { if(retroEnv(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) { update_settings(); - bool hdPacksEnabled = EmulationSettings::CheckFlag(EmulationFlags::UseHdPacks); + bool hdPacksEnabled = _console->GetSettings()->CheckFlag(EmulationFlags::UseHdPacks); if(hdPacksEnabled != _hdPacksEnabled) { //Try to load/unload HD pack when the flag is toggled _console->UpdateHdPackMode(); @@ -727,7 +727,7 @@ extern "C" { unsigned device = _inputDevices[port]; if(device == DEVICE_AUTO) { if(port <= 3) { - switch(EmulationSettings::GetControllerType(port)) { + switch(_console->GetSettings()->GetControllerType(port)) { case ControllerType::StandardController: device = DEVICE_GAMEPAD; break; case ControllerType::PowerPad: device = DEVICE_POWERPAD; break; case ControllerType::SnesController: device = DEVICE_SNESGAMEPAD; break; @@ -737,7 +737,7 @@ extern "C" { default: return; } } else if(port == 4) { - switch(EmulationSettings::GetExpansionDevice()) { + switch(_console->GetSettings()->GetExpansionDevice()) { case ExpansionPortDevice::ArkanoidController: device = DEVICE_ARKANOID; break; case ExpansionPortDevice::BandaiHyperShot: device = DEVICE_BANDAIHYPERSHOT; break; case ExpansionPortDevice::ExcitingBoxing: device = DEVICE_EXCITINGBOXING; break; @@ -836,9 +836,11 @@ extern "C" { { //Setup all "auto" ports RomInfo romInfo = _console->GetRomInfo(); - GameDatabase::InitializeInputDevices(romInfo); - - //TODO: Four Score + if(romInfo.IsInDatabase || romInfo.IsNes20Header) { + _console->GetSettings()->InitializeInputDevices(romInfo.InputType, romInfo.System, true); + } else { + _console->GetSettings()->InitializeInputDevices(GameInputType::Default, GameSystem::NesNtsc, true); + } for(int port = 0; port < 5; port++) { if(_inputDevices[port] != DEVICE_AUTO) { @@ -853,7 +855,7 @@ extern "C" { case DEVICE_SNESGAMEPAD: type = ControllerType::SnesController; break; case DEVICE_SNESMOUSE: type = ControllerType::SnesMouse; break; } - EmulationSettings::SetControllerType(port, type); + _console->GetSettings()->SetControllerType(port, type); } else { ExpansionPortDevice type = ExpansionPortDevice::None; switch(_inputDevices[port]) { @@ -871,25 +873,25 @@ extern "C" { case DEVICE_BATTLEBOX: type = ExpansionPortDevice::BattleBox; break; case DEVICE_FOURPLAYERADAPTER: type = ExpansionPortDevice::FourPlayerAdapter; break; } - EmulationSettings::SetExpansionDevice(type); + _console->GetSettings()->SetExpansionDevice(type); } } } bool hasFourScore = false; - if(EmulationSettings::GetExpansionDevice() != ExpansionPortDevice::None) { - EmulationSettings::SetConsoleType(ConsoleType::Famicom); - if(EmulationSettings::GetExpansionDevice() == ExpansionPortDevice::FourPlayerAdapter) { + if(_console->GetSettings()->GetExpansionDevice() != ExpansionPortDevice::None) { + _console->GetSettings()->SetConsoleType(ConsoleType::Famicom); + if(_console->GetSettings()->GetExpansionDevice() == ExpansionPortDevice::FourPlayerAdapter) { hasFourScore = true; } } else { - EmulationSettings::SetConsoleType(ConsoleType::Nes); - if(EmulationSettings::GetControllerType(2) != ControllerType::None || EmulationSettings::GetControllerType(3) != ControllerType::None) { + _console->GetSettings()->SetConsoleType(ConsoleType::Nes); + if(_console->GetSettings()->GetControllerType(2) != ControllerType::None || _console->GetSettings()->GetControllerType(3) != ControllerType::None) { hasFourScore = true; } } - EmulationSettings::SetFlagState(EmulationFlags::HasFourScore, hasFourScore); + _console->GetSettings()->SetFlagState(EmulationFlags::HasFourScore, hasFourScore); } void retro_set_memory_maps() @@ -968,11 +970,11 @@ extern "C" { update_settings(); //Plug in 2 standard controllers by default, game database will switch the controller types for recognized games - EmulationSettings::SetMasterVolume(10.0); - EmulationSettings::SetControllerType(0, ControllerType::StandardController); - EmulationSettings::SetControllerType(1, ControllerType::StandardController); - EmulationSettings::SetControllerType(2, ControllerType::None); - EmulationSettings::SetControllerType(3, ControllerType::None); + _console->GetSettings()->SetMasterVolume(10.0); + _console->GetSettings()->SetControllerType(0, ControllerType::StandardController); + _console->GetSettings()->SetControllerType(1, ControllerType::StandardController); + _console->GetSettings()->SetControllerType(2, ControllerType::None); + _console->GetSettings()->SetControllerType(3, ControllerType::None); bool result = _console->Initialize(game->path); if(result) { @@ -1024,7 +1026,7 @@ extern "C" { { uint32_t hscale = 1; uint32_t vscale = 1; - switch(EmulationSettings::GetVideoFilterType()) { + switch(_console->GetSettings()->GetVideoFilterType()) { case VideoFilterType::NTSC: hscale = 2; break; case VideoFilterType::BisqwitNtscQuarterRes: hscale = 2; break; case VideoFilterType::BisqwitNtscHalfRes: hscale = 4; break; diff --git a/Windows/Renderer.cpp b/Windows/Renderer.cpp index 513f2942..41ff8d45 100644 --- a/Windows/Renderer.cpp +++ b/Windows/Renderer.cpp @@ -44,16 +44,16 @@ void Renderer::SetScreenSize(uint32_t width, uint32_t height) ScreenSize screenSize; _console->GetVideoDecoder()->GetScreenSize(screenSize, false); - if(_screenHeight != screenSize.Height || _screenWidth != screenSize.Width || _nesFrameHeight != height || _nesFrameWidth != width || _resizeFilter != EmulationSettings::GetVideoResizeFilter() || _newFullscreen != _fullscreen) { + if(_screenHeight != screenSize.Height || _screenWidth != screenSize.Width || _nesFrameHeight != height || _nesFrameWidth != width || _resizeFilter != _console->GetSettings()->GetVideoResizeFilter() || _newFullscreen != _fullscreen) { auto frameLock = _frameLock.AcquireSafe(); auto textureLock = _textureLock.AcquireSafe(); _console->GetVideoDecoder()->GetScreenSize(screenSize, false); - if(_screenHeight != screenSize.Height || _screenWidth != screenSize.Width || _nesFrameHeight != height || _nesFrameWidth != width || _resizeFilter != EmulationSettings::GetVideoResizeFilter() || _newFullscreen != _fullscreen) { + if(_screenHeight != screenSize.Height || _screenWidth != screenSize.Width || _nesFrameHeight != height || _nesFrameWidth != width || _resizeFilter != _console->GetSettings()->GetVideoResizeFilter() || _newFullscreen != _fullscreen) { _nesFrameHeight = height; _nesFrameWidth = width; _newFrameBufferSize = width*height; - bool needReset = _fullscreen != _newFullscreen || _resizeFilter != EmulationSettings::GetVideoResizeFilter(); + bool needReset = _fullscreen != _newFullscreen || _resizeFilter != _console->GetSettings()->GetVideoResizeFilter(); bool fullscreenResizeMode = _fullscreen && _newFullscreen; if(_pSwapChain && _fullscreen && !_newFullscreen) { @@ -277,7 +277,7 @@ HRESULT Renderer::InitDevice() sd.BufferDesc.Width = _realScreenWidth; sd.BufferDesc.Height = _realScreenHeight; sd.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; - sd.BufferDesc.RefreshRate.Numerator = EmulationSettings::GetExclusiveRefreshRate(); + sd.BufferDesc.RefreshRate.Numerator = _console->GetSettings()->GetExclusiveRefreshRate(); sd.BufferDesc.RefreshRate.Denominator = 1; sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; sd.Flags = _fullscreen ? DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH : 0; @@ -400,7 +400,7 @@ HRESULT Renderer::InitDevice() HRESULT Renderer::CreateSamplerState() { - _resizeFilter = EmulationSettings::GetVideoResizeFilter(); + _resizeFilter = _console->GetSettings()->GetVideoResizeFilter(); //Sample state D3D11_SAMPLER_DESC samplerDesc; @@ -573,7 +573,7 @@ void Renderer::DrawPauseScreen(bool disableOverlay) float y = (float)_screenHeight / 2 - stringDimensions.m128_f32[1] / 2 - 8; DrawString("PAUSE", x, y, Colors::AntiqueWhite, 1.0f, _largeFont.get()); - string utf8Message = EmulationSettings::GetPauseScreenMessage(); + string utf8Message = _console->GetSettings()->GetPauseScreenMessage(); if(utf8Message.size() > 0) { std::wstring message = utf8::utf8::decode(utf8Message); float width = MeasureString(message); @@ -584,8 +584,8 @@ void Renderer::DrawPauseScreen(bool disableOverlay) void Renderer::Render() { - bool paused = EmulationSettings::IsPaused() && _console->IsRunning(); - bool disableOverlay = EmulationSettings::CheckFlag(EmulationFlags::HidePauseOverlay); + bool paused = _console->IsPaused() && _console->IsRunning(); + bool disableOverlay = _console->GetSettings()->CheckFlag(EmulationFlags::HidePauseOverlay); shared_ptr debugger = _console->GetDebugger(false); if(debugger && debugger->IsExecutionStopped()) { paused = debugger->IsPauseIconShown(); @@ -630,7 +630,7 @@ void Renderer::Render() _spriteBatch->End(); // Present the information rendered to the back buffer to the front buffer (the screen) - HRESULT hr = _pSwapChain->Present(EmulationSettings::CheckFlag(EmulationFlags::VerticalSync) ? 1 : 0, 0); + HRESULT hr = _pSwapChain->Present(_console->GetSettings()->CheckFlag(EmulationFlags::VerticalSync) ? 1 : 0, 0); if(FAILED(hr)) { MessageManager::Log("SwapChain::Present() failed - Error:" + std::to_string(hr)); if(hr == DXGI_ERROR_DEVICE_REMOVED) { diff --git a/Windows/SoundManager.cpp b/Windows/SoundManager.cpp index e93c0c24..02965800 100644 --- a/Windows/SoundManager.cpp +++ b/Windows/SoundManager.cpp @@ -125,7 +125,7 @@ bool SoundManager::InitializeDirectSound(uint32_t sampleRate, bool isStereo) return false; } - int32_t requestedByteLatency = (int32_t)((float)(sampleRate * EmulationSettings::GetAudioLatency()) / 1000.0f * waveFormat.nBlockAlign); + int32_t requestedByteLatency = (int32_t)((float)(sampleRate * _console->GetSettings()->GetAudioLatency()) / 1000.0f * waveFormat.nBlockAlign); _bufferSize = (int32_t)std::ceil((double)requestedByteLatency * 2 / 0x10000) * 0x10000; // Set the buffer description of the secondary sound buffer that the wave file will be loaded onto. @@ -263,7 +263,7 @@ void SoundManager::ProcessEndOfFrame() _secondaryBuffer->GetCurrentPosition(¤tPlayCursor, &safeWriteCursor); ValidateWriteCursor(safeWriteCursor); - uint32_t emulationSpeed = EmulationSettings::GetEmulationSpeed(); + uint32_t emulationSpeed = _console->GetSettings()->GetEmulationSpeed(); uint32_t targetRate = _sampleRate; if(emulationSpeed > 0 && emulationSpeed < 100) { //Slow down playback when playing at less than 100% @@ -273,7 +273,7 @@ void SoundManager::ProcessEndOfFrame() ProcessLatency(currentPlayCursor, _lastWriteOffset); - if(_averageLatency > 0 && emulationSpeed <= 100 && emulationSpeed > 0 && std::abs(_averageLatency - EmulationSettings::GetAudioLatency()) > 50) { + if(_averageLatency > 0 && emulationSpeed <= 100 && emulationSpeed > 0 && std::abs(_averageLatency - _console->GetSettings()->GetAudioLatency()) > 50) { //Latency is way off (over 50ms gap), stop audio & start again Stop(); } @@ -282,7 +282,7 @@ void SoundManager::ProcessEndOfFrame() void SoundManager::PlayBuffer(int16_t *soundBuffer, uint32_t sampleCount, uint32_t sampleRate, bool isStereo) { uint32_t bytesPerSample = (SoundMixer::BitsPerSample / 8) * (isStereo ? 2 : 1); - uint32_t latency = EmulationSettings::GetAudioLatency(); + uint32_t latency = _console->GetSettings()->GetAudioLatency(); if(_sampleRate != sampleRate || _isStereo != isStereo || _needReset || latency != _previousLatency) { _previousLatency = latency; Release();