From 936d92dfb82c8266909417bae46f9b511e840490 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 29 Jun 2020 01:51:01 +1000 Subject: [PATCH] System: Add option to force start in software mode --- src/core/gpu.cpp | 6 ------ src/core/gpu.h | 3 --- src/core/system.cpp | 30 ++++++++++++++++-------------- src/core/system.h | 5 +++-- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index 0b5a83b76..6382a9478 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -63,12 +63,6 @@ void GPU::UpdateSettings() UpdateCRTCDisplayParameters(); } -void GPU::UpdateHardwareType() -{ - m_console_is_pal = m_system->IsPALRegion(); - UpdateCRTCDisplayParameters(); -} - void GPU::Reset() { SoftReset(); diff --git a/src/core/gpu.h b/src/core/gpu.h index 889e70c09..065e76ac7 100644 --- a/src/core/gpu.h +++ b/src/core/gpu.h @@ -173,9 +173,6 @@ public: // Converts window coordinates into horizontal ticks and scanlines. Returns false if out of range. Used for lightguns. bool ConvertScreenCoordinatesToBeamTicksAndLines(s32 window_x, s32 window_y, u32* out_tick, u32* out_line) const; - // Updates hardware type from settings. - void UpdateHardwareType(); - protected: TickCount CRTCTicksToSystemTicks(TickCount crtc_ticks, TickCount fractional_ticks) const; TickCount SystemTicksToCRTCTicks(TickCount sysclk_ticks, TickCount* fractional_ticks) const; diff --git a/src/core/system.cpp b/src/core/system.cpp index 3d27b7b5a..4c190a644 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -88,11 +88,7 @@ ConsoleRegion System::GetConsoleRegionForDiscRegion(DiscRegion region) std::unique_ptr System::Create(HostInterface* host_interface) { - std::unique_ptr system(new System(host_interface)); - if (!system->CreateGPU(host_interface->m_settings.gpu_renderer)) - return {}; - - return system; + return std::unique_ptr(new System(host_interface)); } bool System::RecreateGPU(GPURenderer renderer) @@ -138,7 +134,7 @@ void System::SetCPUExecutionMode(CPUExecutionMode mode) bool System::Boot(const SystemBootParameters& params) { if (params.state_stream) - return DoLoadState(params.state_stream.get(), true); + return DoLoadState(params.state_stream.get(), true, params.force_software_renderer); // Load CD image up and detect region. std::unique_ptr media; @@ -201,11 +197,12 @@ bool System::Boot(const SystemBootParameters& params) return false; } + // Component setup. + if (!InitializeComponents(params.force_software_renderer)) + return false; + // Notify change of disc. UpdateRunningGame(params.filename.c_str(), media.get()); - - // Component setup. - InitializeComponents(); UpdateControllers(); UpdateMemoryCards(); Reset(); @@ -243,8 +240,11 @@ bool System::Boot(const SystemBootParameters& params) return true; } -void System::InitializeComponents() +bool System::InitializeComponents(bool force_software_renderer) { + if (!CreateGPU(force_software_renderer ? GPURenderer::Software : GetSettings().gpu_renderer)) + return false; + m_cpu->Initialize(m_bus.get()); m_cpu_code_cache->Initialize(this, m_cpu.get(), m_bus.get(), m_cpu_execution_mode == CPUExecutionMode::Recompiler); m_bus->Initialize(m_cpu.get(), m_cpu_code_cache.get(), m_dma.get(), m_interrupt_controller.get(), m_gpu.get(), @@ -260,9 +260,9 @@ void System::InitializeComponents() m_timers->Initialize(this, m_interrupt_controller.get(), m_gpu.get()); m_spu->Initialize(this, m_dma.get(), m_interrupt_controller.get()); m_mdec->Initialize(this, m_dma.get()); - m_gpu->UpdateHardwareType(); UpdateThrottlePeriod(); + return true; } void System::DestroyComponents() @@ -398,10 +398,10 @@ void System::Reset() bool System::LoadState(ByteStream* state) { - return DoLoadState(state, false); + return DoLoadState(state, false, false); } -bool System::DoLoadState(ByteStream* state, bool init_components) +bool System::DoLoadState(ByteStream* state, bool init_components, bool force_software_renderer) { SAVE_STATE_HEADER header; if (!state->Read2(&header, sizeof(header))) @@ -440,7 +440,9 @@ bool System::DoLoadState(ByteStream* state, bool init_components) if (init_components) { - InitializeComponents(); + if (!InitializeComponents(force_software_renderer)) + return false; + UpdateControllers(); UpdateMemoryCards(); diff --git a/src/core/system.h b/src/core/system.h index f316c602d..45dba7c5c 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -39,6 +39,7 @@ struct SystemBootParameters std::optional override_fast_boot; std::optional override_fullscreen; std::unique_ptr state_stream; + bool force_software_renderer = false; }; class System @@ -145,11 +146,11 @@ public: private: System(HostInterface* host_interface); - bool DoLoadState(ByteStream* stream, bool init_components); + bool DoLoadState(ByteStream* stream, bool init_components, bool force_software_renderer); bool DoState(StateWrapper& sw); bool CreateGPU(GPURenderer renderer); - void InitializeComponents(); + bool InitializeComponents(bool force_software_renderer); void DestroyComponents(); // Active event management