diff --git a/Core/AutomaticRomTest.h b/Core/AutomaticRomTest.h index 3784d399..ce6e8040 100644 --- a/Core/AutomaticRomTest.h +++ b/Core/AutomaticRomTest.h @@ -17,7 +17,7 @@ private: public: AutomaticRomTest(); - ~AutomaticRomTest(); + virtual ~AutomaticRomTest(); void ProcessNotification(ConsoleNotificationType type, void* parameter) override; int32_t Run(string filename); diff --git a/Core/Console.cpp b/Core/Console.cpp index ce7b9ee1..6574871b 100644 --- a/Core/Console.cpp +++ b/Core/Console.cpp @@ -150,7 +150,7 @@ bool Console::LoadMatchingRom(string romName, HashInfo hashInfo) if(!match.empty()) { return Initialize(match); } - return nullptr; + return false; } string Console::FindMatchingRom(string romName, HashInfo hashInfo) diff --git a/Core/MessageManager.cpp b/Core/MessageManager.cpp index 35992eb2..b0b705b3 100644 --- a/Core/MessageManager.cpp +++ b/Core/MessageManager.cpp @@ -1,6 +1,4 @@ #include "stdafx.h" - -#include #include "MessageManager.h" #include "EmulationSettings.h" diff --git a/Core/MessageManager.h b/Core/MessageManager.h index 3378bb96..38089050 100644 --- a/Core/MessageManager.h +++ b/Core/MessageManager.h @@ -3,7 +3,6 @@ #include "stdafx.h" #include "IMessageManager.h" -#include "INotificationListener.h" #include #include "../Utilities/SimpleLock.h" diff --git a/Core/NotificationManager.cpp b/Core/NotificationManager.cpp index d63c9717..aa5f50cd 100644 --- a/Core/NotificationManager.cpp +++ b/Core/NotificationManager.cpp @@ -1,4 +1,5 @@ #include "stdafx.h" +#include #include "NotificationManager.h" void NotificationManager::RegisterNotificationListener(shared_ptr notificationListener) diff --git a/Core/SaveStateManager.cpp b/Core/SaveStateManager.cpp index 93f230b6..09cc3622 100644 --- a/Core/SaveStateManager.cpp +++ b/Core/SaveStateManager.cpp @@ -60,9 +60,10 @@ bool SaveStateManager::LoadState() void SaveStateManager::SaveState(ostream &stream) { uint32_t emuVersion = EmulationSettings::GetMesenVersion(); + uint32_t formatVersion = SaveStateManager::FileFormatVersion; stream.write("MST", 3); stream.write((char*)&emuVersion, sizeof(emuVersion)); - stream.write((char*)&SaveStateManager::FileFormatVersion, sizeof(uint32_t)); + stream.write((char*)&formatVersion, sizeof(uint32_t)); MapperInfo mapperInfo = _console->GetMapperInfo(); stream.write((char*)&mapperInfo.MapperId, sizeof(uint16_t)); diff --git a/InteropDLL/ConsoleWrapper.cpp b/InteropDLL/ConsoleWrapper.cpp index 4a392836..8e60ad56 100644 --- a/InteropDLL/ConsoleWrapper.cpp +++ b/InteropDLL/ConsoleWrapper.cpp @@ -66,6 +66,10 @@ namespace InteropEmu { { _callback = callback; } + + virtual ~InteropNotificationListener() + { + } void ProcessNotification(ConsoleNotificationType type, void* parameter) { @@ -107,7 +111,7 @@ namespace InteropEmu { #ifdef _WIN32 _renderer = new Renderer(_console, (HWND)_viewerHandle); #else - _renderer = new SdlRenderer(_viewerHandle); + _renderer = new SdlRenderer(_console, _viewerHandle); #endif } @@ -115,7 +119,7 @@ namespace InteropEmu { #ifdef _WIN32 _soundManager = new SoundManager(_console, (HWND)_windowHandle); #else - _soundManager = new SdlSoundManager(); + _soundManager = new SdlSoundManager(_console); #endif } @@ -123,7 +127,7 @@ namespace InteropEmu { #ifdef _WIN32 _keyManager = new WindowsKeyManager(_console, (HWND)_windowHandle); #else - _keyManager = new LinuxKeyManager(); + _keyManager = new LinuxKeyManager(_console); #endif KeyManager::RegisterKeyManager(_keyManager); diff --git a/Linux/LinuxKeyManager.cpp b/Linux/LinuxKeyManager.cpp index b4b72725..13b75f05 100755 --- a/Linux/LinuxKeyManager.cpp +++ b/Linux/LinuxKeyManager.cpp @@ -227,8 +227,10 @@ static vector _keyDefinitions = { { "", 246, "XF86WLAN", "" }, }; -LinuxKeyManager::LinuxKeyManager() +LinuxKeyManager::LinuxKeyManager(shared_ptr console) { + _console = console; + ResetKeyState(); vector buttonNames = { @@ -378,14 +380,14 @@ void LinuxKeyManager::StartUpdateDeviceThread() } if(!indexesToRemove.empty() || !controllersToAdd.empty()) { - Console::Pause(); + _console->Pause(); for(int index : indexesToRemove) { _controllers.erase(_controllers.begin()+index); } for(std::shared_ptr controller : controllersToAdd) { _controllers.push_back(controller); } - Console::Resume(); + _console->Resume(); } _stopSignal.Wait(2000); diff --git a/Linux/LinuxKeyManager.h b/Linux/LinuxKeyManager.h index 29155276..449a4ac9 100755 --- a/Linux/LinuxKeyManager.h +++ b/Linux/LinuxKeyManager.h @@ -6,6 +6,7 @@ #include "../Utilities/AutoResetEvent.h" class LinuxGameController; +class Console; struct KeyDefinition { string name; @@ -17,6 +18,7 @@ struct KeyDefinition { class LinuxKeyManager : public IKeyManager { private: + shared_ptr _console; std::vector> _controllers; bool _keyState[0x200]; bool _mouseState[0x03]; @@ -31,7 +33,7 @@ private: void StartUpdateDeviceThread(); public: - LinuxKeyManager(); + LinuxKeyManager(shared_ptr console); virtual ~LinuxKeyManager(); void RefreshState(); diff --git a/Linux/SdlRenderer.cpp b/Linux/SdlRenderer.cpp index da411f76..02b09f00 100755 --- a/Linux/SdlRenderer.cpp +++ b/Linux/SdlRenderer.cpp @@ -5,7 +5,7 @@ #include "../Core/VideoDecoder.h" #include "../Core/EmulationSettings.h" -SdlRenderer::SdlRenderer(void* windowHandle) : _windowHandle(windowHandle) +SdlRenderer::SdlRenderer(shared_ptr console, void* windowHandle) : BaseRenderer(console), _windowHandle(windowHandle) { _frameBuffer = nullptr; SetScreenSize(256,240); @@ -14,7 +14,7 @@ SdlRenderer::SdlRenderer(void* windowHandle) : _windowHandle(windowHandle) SdlRenderer::~SdlRenderer() { - VideoRenderer::GetInstance()->UnregisterRenderingDevice(this); + _console->GetVideoRenderer()->UnregisterRenderingDevice(this); Cleanup(); } @@ -99,7 +99,7 @@ void SdlRenderer::Reset() { Cleanup(); if(Init()) { - VideoRenderer::GetInstance()->RegisterRenderingDevice(this); + _console->GetVideoRenderer()->RegisterRenderingDevice(this); } else { Cleanup(); } @@ -108,7 +108,7 @@ void SdlRenderer::Reset() void SdlRenderer::SetScreenSize(uint32_t width, uint32_t height) { ScreenSize screenSize; - VideoDecoder::GetInstance()->GetScreenSize(screenSize, false); + _console->GetVideoDecoder()->GetScreenSize(screenSize, false); if(_screenHeight != (uint32_t)screenSize.Height || _screenWidth != (uint32_t)screenSize.Width || _nesFrameHeight != height || _nesFrameWidth != width || _resizeFilter != EmulationSettings::GetVideoResizeFilter() || _vsyncEnabled != EmulationSettings::CheckFlag(EmulationFlags::VerticalSync)) { _reinitLock.Acquire(); @@ -147,9 +147,9 @@ void SdlRenderer::Render() return; } - bool paused = EmulationSettings::IsPaused() && Console::IsRunning(); + bool paused = EmulationSettings::IsPaused() && _console->IsRunning(); bool disableOverlay = EmulationSettings::CheckFlag(EmulationFlags::HidePauseOverlay); - shared_ptr debugger = Console::GetInstance()->GetDebugger(false); + shared_ptr debugger = _console->GetDebugger(false); if(debugger && debugger->IsExecutionStopped()) { paused = debugger->IsPauseIconShown(); disableOverlay = true; @@ -185,7 +185,7 @@ void SdlRenderer::Render() if(paused && !EmulationSettings::CheckFlag(EmulationFlags::HidePauseOverlay)) { DrawPauseScreen(disableOverlay); - } else if(VideoDecoder::GetInstance()->IsRunning()) { + } else if(_console->GetVideoDecoder()->IsRunning()) { DrawCounters(); } diff --git a/Linux/SdlRenderer.h b/Linux/SdlRenderer.h index 7b55c1f5..0f909ed9 100755 --- a/Linux/SdlRenderer.h +++ b/Linux/SdlRenderer.h @@ -21,6 +21,8 @@ struct SDL_Window }; typedef struct SDL_Window SDL_Window; +class Console; + class SdlRenderer : public IRenderingDevice, public BaseRenderer { private: @@ -59,7 +61,7 @@ private: bool ContainsCharacter(wchar_t character) override; public: - SdlRenderer(void* windowHandle); + SdlRenderer(shared_ptr console, void* windowHandle); virtual ~SdlRenderer(); void UpdateFrame(void *frameBuffer, uint32_t width, uint32_t height) override; diff --git a/Linux/SdlSoundManager.cpp b/Linux/SdlSoundManager.cpp index ee9627e6..2289c234 100755 --- a/Linux/SdlSoundManager.cpp +++ b/Linux/SdlSoundManager.cpp @@ -2,11 +2,14 @@ #include "../Core/EmulationSettings.h" #include "../Core/MessageManager.h" #include "../Core/SoundMixer.h" +#include "../Core/Console.h" -SdlSoundManager::SdlSoundManager() +SdlSoundManager::SdlSoundManager(shared_ptr console) { + _console = console; + if(InitializeAudio(44100, false)) { - SoundMixer::RegisterAudioDevice(this); + _console->GetSoundMixer()->RegisterAudioDevice(this); } } diff --git a/Linux/SdlSoundManager.h b/Linux/SdlSoundManager.h index c52dbe95..7a1ea932 100755 --- a/Linux/SdlSoundManager.h +++ b/Linux/SdlSoundManager.h @@ -2,10 +2,12 @@ #include #include "../Core/BaseSoundManager.h" +class Console; + class SdlSoundManager : public BaseSoundManager { public: - SdlSoundManager(); + SdlSoundManager(shared_ptr console); ~SdlSoundManager(); void PlayBuffer(int16_t *soundBuffer, uint32_t bufferSize, uint32_t sampleRate, bool isStereo); @@ -28,6 +30,7 @@ private: void WriteToBuffer(uint8_t* output, uint32_t len); private: + shared_ptr _console; SDL_AudioDeviceID _audioDeviceID; string _deviceName; bool _needReset = false;