From 9496c992f7da5bb8644c91d0f093a4f6ab239e5a Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Wed, 22 Jul 2020 00:03:22 +1000 Subject: [PATCH] System: Add an option to preload CD image to RAM --- src/core/host_interface.cpp | 1 + src/core/settings.cpp | 2 ++ src/core/settings.h | 1 + src/core/system.cpp | 9 +++++++++ src/core/system.h | 1 + src/duckstation-qt/consolesettingswidget.cpp | 1 + src/duckstation-qt/consolesettingswidget.ui | 7 +++++++ src/duckstation-sdl/sdl_host_interface.cpp | 1 + 8 files changed, 23 insertions(+) diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index 385772e8e..64b854147 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -362,6 +362,7 @@ void HostInterface::SetDefaultSettings(SettingsInterface& si) si.SetBoolValue("CDROM", "ReadThread", true); si.SetBoolValue("CDROM", "RegionCheck", true); + si.SetBoolValue("CDROM", "LoadImageToRAM", false); si.SetStringValue("Audio", "Backend", Settings::GetAudioBackendName(Settings::DEFAULT_AUDIO_BACKEND)); si.SetIntValue("Audio", "OutputVolume", 100); diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 4de5aa1f9..e3ea19430 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -118,6 +118,7 @@ void Settings::Load(SettingsInterface& si) cdrom_read_thread = si.GetBoolValue("CDROM", "ReadThread", true); cdrom_region_check = si.GetBoolValue("CDROM", "RegionCheck", true); + cdrom_load_image_to_ram = si.GetBoolValue("CDROM", "LoadImageToRAM", false); audio_backend = ParseAudioBackend(si.GetStringValue("Audio", "Backend", GetAudioBackendName(DEFAULT_AUDIO_BACKEND)).c_str()) @@ -213,6 +214,7 @@ void Settings::Save(SettingsInterface& si) const si.SetBoolValue("CDROM", "ReadThread", cdrom_read_thread); si.SetBoolValue("CDROM", "RegionCheck", cdrom_region_check); + si.SetBoolValue("CDROM", "LoadImageToRAM", cdrom_load_image_to_ram); si.SetStringValue("Audio", "Backend", GetAudioBackendName(audio_backend)); si.SetIntValue("Audio", "OutputVolume", audio_output_volume); diff --git a/src/core/settings.h b/src/core/settings.h index d2ccf2bbb..6f84203da 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -100,6 +100,7 @@ struct Settings bool cdrom_read_thread = true; bool cdrom_region_check = true; + bool cdrom_load_image_to_ram = false; AudioBackend audio_backend = AudioBackend::Cubeb; s32 audio_output_volume = 100; diff --git a/src/core/system.cpp b/src/core/system.cpp index d947dd88a..268f2c353 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -14,6 +14,7 @@ #include "gpu.h" #include "host_display.h" #include "host_interface.h" +#include "host_interface_progress_callback.h" #include "interrupt_controller.h" #include "mdec.h" #include "memory_card.h" @@ -163,6 +164,14 @@ bool System::Boot(const SystemBootParameters& params) return false; } + if (params.override_load_image_to_ram.value_or(GetSettings().cdrom_load_image_to_ram)) + { + HostInterfaceProgressCallback callback(m_host_interface); + std::unique_ptr memory_image = CDImage::CreateMemoryImage(media.get(), &callback); + if (memory_image) + media = std::move(memory_image); + } + if (m_region == ConsoleRegion::Auto) { const DiscRegion disc_region = GameList::GetRegionForImage(media.get()); diff --git a/src/core/system.h b/src/core/system.h index 0116169b9..8ae6f71e1 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -38,6 +38,7 @@ struct SystemBootParameters std::string filename; std::optional override_fast_boot; std::optional override_fullscreen; + std::optional override_load_image_to_ram; std::unique_ptr state_stream; bool force_software_renderer = false; }; diff --git a/src/duckstation-qt/consolesettingswidget.cpp b/src/duckstation-qt/consolesettingswidget.cpp index 5a86156fa..1bd67b926 100644 --- a/src/duckstation-qt/consolesettingswidget.cpp +++ b/src/duckstation-qt/consolesettingswidget.cpp @@ -26,6 +26,7 @@ ConsoleSettingsWidget::ConsoleSettingsWidget(QtHostInterface* host_interface, QW Settings::DEFAULT_CPU_EXECUTION_MODE); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.cdromReadThread, "CDROM", "ReadThread"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.cdromRegionCheck, "CDROM", "RegionCheck"); + SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.cdromLoadImageToRAM, "CDROM", "LoadImageToRAM", false); connect(m_ui.biosPathBrowse, &QPushButton::pressed, this, &ConsoleSettingsWidget::onBrowseBIOSPathButtonClicked); } diff --git a/src/duckstation-qt/consolesettingswidget.ui b/src/duckstation-qt/consolesettingswidget.ui index bea393704..7852c65ea 100644 --- a/src/duckstation-qt/consolesettingswidget.ui +++ b/src/duckstation-qt/consolesettingswidget.ui @@ -119,6 +119,13 @@ + + + + Preload Image To RAM + + + diff --git a/src/duckstation-sdl/sdl_host_interface.cpp b/src/duckstation-sdl/sdl_host_interface.cpp index 6427f120b..3adf6c981 100644 --- a/src/duckstation-sdl/sdl_host_interface.cpp +++ b/src/duckstation-sdl/sdl_host_interface.cpp @@ -1109,6 +1109,7 @@ void SDLHostInterface::DrawSettingsWindow() { settings_changed |= ImGui::Checkbox("Use Read Thread (Asynchronous)", &m_settings_copy.cdrom_read_thread); settings_changed |= ImGui::Checkbox("Enable Region Check", &m_settings_copy.cdrom_region_check); + settings_changed |= ImGui::Checkbox("Preload Image To RAM", &m_settings_copy.cdrom_load_image_to_ram); } ImGui::NewLine();