From bdebd8bdef6f22fb32c5b71f4610183c5e771448 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 30 Aug 2023 17:39:41 +1000 Subject: [PATCH] System: Allow overriding BIOS in boot parameters --- src/core/system.cpp | 22 ++++++++++++++++++---- src/core/system.h | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/core/system.cpp b/src/core/system.cpp index 1941856d7..0666d0ea3 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -86,7 +86,7 @@ static bool ReadExecutableFromImage(ISOReader& iso, std::string* out_executable_ static void StallCPU(TickCount ticks); -static bool LoadBIOS(); +static bool LoadBIOS(const std::string& override_bios_path); static void InternalReset(); static void ClearRunningGame(); static void DestroySystem(); @@ -138,6 +138,7 @@ static std::string s_running_game_serial; static std::string s_running_game_title; static System::GameHash s_running_game_hash; static bool s_running_unknown_game; +static bool s_was_fast_booted; static float s_throttle_frequency = 60.0f; static float s_target_speed = 1.0f; @@ -329,6 +330,11 @@ bool System::IsRunningUnknownGame() return s_running_unknown_game; } +bool System::WasFastBooted() +{ + return s_was_fast_booted; +} + const BIOS::ImageInfo* System::GetBIOSImageInfo() { return s_bios_image_info; @@ -1241,7 +1247,7 @@ bool System::BootSystem(SystemBootParameters parameters) #endif // Load BIOS image. - if (!LoadBIOS()) + if (!LoadBIOS(parameters.override_bios)) { s_state = State::Shutdown; ClearRunningGame(); @@ -1293,9 +1299,15 @@ bool System::BootSystem(SystemBootParameters parameters) g_settings.bios_patch_fast_boot)) { if (s_bios_image_info && s_bios_image_info->patch_compatible) + { + // TODO: Fast boot without patches... BIOS::PatchBIOSFastBoot(Bus::g_bios, Bus::BIOS_SIZE); + s_was_fast_booted = true; + } else + { Log_ErrorPrintf("Not patching fast boot, as BIOS is not patch compatible."); + } } // Good to go. @@ -1517,6 +1529,7 @@ void System::DestroySystem() s_bios_hash = {}; s_bios_image_info = nullptr; + s_was_fast_booted = false; Host::OnSystemDestroyed(); } @@ -1794,9 +1807,10 @@ bool System::DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_di return !sw.HasError(); } -bool System::LoadBIOS() +bool System::LoadBIOS(const std::string& override_bios_path) { - std::optional bios_image(BIOS::GetBIOSImage(s_region)); + std::optional bios_image( + override_bios_path.empty() ? BIOS::GetBIOSImage(s_region) : FileSystem::ReadBinaryFile(override_bios_path.c_str())); if (!bios_image.has_value()) { Host::ReportFormattedErrorAsync("Error", Host::TranslateString("System", "Failed to load %s BIOS."), diff --git a/src/core/system.h b/src/core/system.h index 01ca448f4..a58d4b7d9 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -38,6 +38,7 @@ struct SystemBootParameters std::string filename; std::string save_state; std::string override_exe; + std::string override_bios; std::optional override_fast_boot; std::optional override_fullscreen; std::optional override_start_paused; @@ -186,6 +187,7 @@ const std::string& GetGameSerial(); const std::string& GetGameTitle(); GameHash GetGameHash(); bool IsRunningUnknownGame(); +bool WasFastBooted(); const BIOS::ImageInfo* GetBIOSImageInfo(); const BIOS::Hash& GetBIOSHash();