From 829c51957e1e3c5053d70c7f68812dacc7f9961e Mon Sep 17 00:00:00 2001 From: Sour Date: Mon, 27 Apr 2020 20:47:28 -0400 Subject: [PATCH] Fixed crash when loading VS-DualSystem games that are marked as having no work ram --- Core/Console.cpp | 8 ++++++-- Core/VsControlManager.cpp | 6 ++++++ Core/VsControlManager.h | 1 + Core/VsSystem.h | 9 +++++++-- GUI.NET/Forms/frmMain.cs | 2 +- GUI.NET/InteropEmu.cs | 1 + 6 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Core/Console.cpp b/Core/Console.cpp index 0c64b837..8a297daa 100644 --- a/Core/Console.cpp +++ b/Core/Console.cpp @@ -438,7 +438,9 @@ bool Console::Initialize(VirtualFile &romFile, VirtualFile &patchFile, bool forP } //Used by netplay to take save state after UpdateInputState() is called above, to ensure client+server are in sync - _notificationManager->SendNotification(ConsoleNotificationType::GameInitCompleted); + if(!_master) { + _notificationManager->SendNotification(ConsoleNotificationType::GameInitCompleted); + } Resume(); return true; @@ -627,7 +629,9 @@ void Console::ResetComponents(bool softReset) _resetRunTimers = true; //This notification MUST be sent before the UpdateInputState() below to allow MovieRecorder to grab the first frame's worth of inputs - _notificationManager->SendNotification(softReset ? ConsoleNotificationType::GameReset : ConsoleNotificationType::GameLoaded); + if(!_master) { + _notificationManager->SendNotification(softReset ? ConsoleNotificationType::GameReset : ConsoleNotificationType::GameLoaded); + } if(softReset) { shared_ptr debugger = _debugger; diff --git a/Core/VsControlManager.cpp b/Core/VsControlManager.cpp index 44590f38..1f8b5749 100644 --- a/Core/VsControlManager.cpp +++ b/Core/VsControlManager.cpp @@ -24,10 +24,16 @@ void VsControlManager::Reset(bool softReset) _vsSystemType = _console->GetRomInfo().VsType; if(!softReset && !_console->IsMaster() && _console->GetDualConsole()) { + UnregisterInputProvider(this); RegisterInputProvider(this); } } +VsControlManager::~VsControlManager() +{ + UnregisterInputProvider(this); +} + void VsControlManager::StreamState(bool saving) { ControlManager::StreamState(saving); diff --git a/Core/VsControlManager.h b/Core/VsControlManager.h index b4b88cd4..459cb60a 100644 --- a/Core/VsControlManager.h +++ b/Core/VsControlManager.h @@ -52,6 +52,7 @@ protected: public: using ControlManager::ControlManager; + ~VsControlManager(); void StreamState(bool saving) override; void Reset(bool softReset) override; diff --git a/Core/VsSystem.h b/Core/VsSystem.h index 1f3c908d..07c7f561 100644 --- a/Core/VsSystem.h +++ b/Core/VsSystem.h @@ -99,9 +99,14 @@ public: VsSystem* otherMapper = dynamic_cast(dualConsole->GetMapper()); //Give memory access to master CPU or slave CPU, based on "slaveMasterBit" + if(_saveRamSize == 0 && _workRamSize == 0) { + RemoveCpuMemoryMapping(0x6000, 0x7FFF); + otherMapper->RemoveCpuMemoryMapping(0x6000, 0x7FFF); + } + for(int i = 0; i < 4; i++) { - SetCpuMemoryMapping(0x6000 + i * 0x800, 0x67FF + i * 0x800, _workRam, slaveMasterBit ? MemoryAccessType::ReadWrite : MemoryAccessType::NoAccess); - otherMapper->SetCpuMemoryMapping(0x6000 + i * 0x800, 0x67FF + i * 0x800, _workRam, slaveMasterBit ? MemoryAccessType::NoAccess : MemoryAccessType::ReadWrite); + SetCpuMemoryMapping(0x6000 + i * 0x800, 0x67FF + i * 0x800, HasBattery() ? _saveRam : _workRam, slaveMasterBit ? MemoryAccessType::ReadWrite : MemoryAccessType::NoAccess); + otherMapper->SetCpuMemoryMapping(0x6000 + i * 0x800, 0x67FF + i * 0x800, HasBattery() ? _saveRam : _workRam, slaveMasterBit ? MemoryAccessType::NoAccess : MemoryAccessType::ReadWrite); } } } diff --git a/GUI.NET/Forms/frmMain.cs b/GUI.NET/Forms/frmMain.cs index 32e21252..bfc3b569 100644 --- a/GUI.NET/Forms/frmMain.cs +++ b/GUI.NET/Forms/frmMain.cs @@ -669,7 +669,7 @@ namespace Mesen.GUI.Forms private void _notifListener_OnNotification(InteropEmu.NotificationEventArgs e) { switch(e.NotificationType) { - case InteropEmu.ConsoleNotificationType.GameLoaded: + case InteropEmu.ConsoleNotificationType.GameInitCompleted: VideoInfo.ApplyOverscanConfig(); _currentGame = InteropEmu.GetRomInfo().GetRomName(); InteropEmu.SetNesModel(ConfigManager.Config.Region); diff --git a/GUI.NET/InteropEmu.cs b/GUI.NET/InteropEmu.cs index f362522f..6fb38241 100644 --- a/GUI.NET/InteropEmu.cs +++ b/GUI.NET/InteropEmu.cs @@ -951,6 +951,7 @@ namespace Mesen.GUI BeforeEmulationStop = 19, VsDualSystemStarted = 20, VsDualSystemStopped = 21, + GameInitCompleted = 22 } public enum ControllerType