From a5fa24a32ee01d004dd89acbc9ad6c5ee29b89dd Mon Sep 17 00:00:00 2001 From: Sour Date: Mon, 6 Mar 2023 16:42:32 -0500 Subject: [PATCH] NES: Fixed loading NES roms (+ improved behavior/error message display when this happens) --- Core/Shared/EmuSettings.cpp | 2 +- Core/Shared/Emulator.cpp | 14 ++++++++++++++ Core/Shared/Emulator.h | 3 ++- Core/Shared/MessageManager.cpp | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Core/Shared/EmuSettings.cpp b/Core/Shared/EmuSettings.cpp index 4bbd751f..4874c7e2 100644 --- a/Core/Shared/EmuSettings.cpp +++ b/Core/Shared/EmuSettings.cpp @@ -53,7 +53,7 @@ void EmuSettings::Serialize(Serializer& s) SV(_nes.DisableOamAddrBug); SV(_nes.DisablePaletteRead); SV(_nes.DisablePpu2004Reads); SV(_nes.DisableGameGenieBusConflicts); SV(_nes.DisablePpuReset); SV(_nes.EnableOamDecay); SV(_nes.EnablePpu2000ScrollGlitch); SV(_nes.EnablePpu2006ScrollGlitch); SV(_nes.EnablePpuOamRowCorruption); - SV(_nes.RestrictPpuAccessOnFirstFrame); SV(_nes.DisableGameGenieBusConflicts); + SV(_nes.RestrictPpuAccessOnFirstFrame); SV(_nes.PpuExtraScanlinesAfterNmi); SV(_nes.PpuExtraScanlinesBeforeNmi); SV(_nes.Region); SV(_nes.LightDetectionRadius); diff --git a/Core/Shared/Emulator.cpp b/Core/Shared/Emulator.cpp index 4a68f93b..0c8f2b1b 100644 --- a/Core/Shared/Emulator.cpp +++ b/Core/Shared/Emulator.cpp @@ -346,6 +346,20 @@ void Emulator::PowerCycle() } bool Emulator::LoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom, bool forPowerCycle) +{ + try { + return InternalLoadRom(romFile, patchFile, stopRom, forPowerCycle); + } catch(std::exception& ex) { + _videoDecoder->StartThread(); + _videoRenderer->StartThread(); + + MessageManager::DisplayMessage("Error", "UnexpectedError", ex.what()); + Stop(false, true, false); + return false; + } +} + +bool Emulator::InternalLoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom, bool forPowerCycle) { if(!romFile.IsValid()) { MessageManager::DisplayMessage("Error", "CouldNotLoadFile", romFile.GetFileName()); diff --git a/Core/Shared/Emulator.h b/Core/Shared/Emulator.h index 78e605c6..15ece378 100644 --- a/Core/Shared/Emulator.h +++ b/Core/Shared/Emulator.h @@ -131,7 +131,8 @@ private: template void TryLoadRom(VirtualFile& romFile, LoadRomResult& result, unique_ptr& console); void InitConsole(unique_ptr& newConsole, ConsoleMemoryInfo originalConsoleMemory[], bool preserveRom); - + + bool InternalLoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom = true, bool forPowerCycle = false); public: Emulator(); diff --git a/Core/Shared/MessageManager.cpp b/Core/Shared/MessageManager.cpp index 2a22cdec..0ef46cd0 100644 --- a/Core/Shared/MessageManager.cpp +++ b/Core/Shared/MessageManager.cpp @@ -73,6 +73,7 @@ std::unordered_map MessageManager::_enResources = { { "SoundRecorderStarted", u8"Recording to: %1" }, { "SoundRecorderStopped", u8"Recording saved to: %1" }, { "TestFileSavedTo", u8"Test file saved to: %1" }, + { "UnexpectedError", u8"Unexpected error: %1" }, { "UnsupportedMapper", u8"Unsupported mapper (%1), cannot load game." }, { "VideoRecorderStarted", u8"Recording to: %1" }, { "VideoRecorderStopped", u8"Recording saved to: %1" },