From da14b10e729adb90f3e2eaa85eb3c7450097e9a2 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 9 Dec 2019 00:51:52 +1000 Subject: [PATCH] Split MemoryCard and PadDevice (now Controller) --- src/core/CMakeLists.txt | 4 +-- src/core/controller.cpp | 38 +++++++++++++++++++++++++ src/core/{pad_device.h => controller.h} | 8 +++--- src/core/core.vcxproj | 4 +-- src/core/core.vcxproj.filters | 4 +-- src/core/digital_controller.h | 4 +-- src/core/memory_card.cpp | 2 +- src/core/memory_card.h | 14 ++++----- src/core/pad.cpp | 6 ++-- src/core/pad.h | 8 +++--- src/core/pad_device.cpp | 38 ------------------------- src/core/sio.cpp | 2 +- src/core/sio.h | 2 +- src/core/system.cpp | 4 +-- src/core/system.h | 4 +-- 15 files changed, 71 insertions(+), 71 deletions(-) create mode 100644 src/core/controller.cpp rename src/core/{pad_device.h => controller.h} (82%) delete mode 100644 src/core/pad_device.cpp diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 69abea7af..4b5050f16 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -6,6 +6,8 @@ add_library(core bus.inl cdrom.cpp cdrom.h + controller.cpp + controller.h cpu_code_cache.cpp cpu_code_cache.h cpu_core.cpp @@ -48,8 +50,6 @@ add_library(core memory_card.h pad.cpp pad.h - pad_device.cpp - pad_device.h save_state_version.h settings.cpp settings.h diff --git a/src/core/controller.cpp b/src/core/controller.cpp new file mode 100644 index 000000000..d588aee2a --- /dev/null +++ b/src/core/controller.cpp @@ -0,0 +1,38 @@ +#include "controller.h" +#include "common/state_wrapper.h" +#include "digital_controller.h" + +Controller::Controller() = default; + +Controller::~Controller() = default; + +void Controller::Reset() {} + +bool Controller::DoState(StateWrapper& sw) +{ + return !sw.HasError(); +} + +void Controller::ResetTransferState() {} + +bool Controller::Transfer(const u8 data_in, u8* data_out) +{ + *data_out = 0xFF; + return false; +} + +std::shared_ptr Controller::Create(std::string_view type_name) +{ + if (type_name == "DigitalController") + return DigitalController::Create(); + + return {}; +} + +std::optional Controller::GetButtonCodeByName(std::string_view type_name, std::string_view button_name) +{ + if (type_name == "DigitalController") + return DigitalController::GetButtonCodeByName(button_name); + + return {}; +} diff --git a/src/core/pad_device.h b/src/core/controller.h similarity index 82% rename from src/core/pad_device.h rename to src/core/controller.h index 6c21cc5da..c65b33aa7 100644 --- a/src/core/pad_device.h +++ b/src/core/controller.h @@ -5,11 +5,11 @@ class StateWrapper; -class PadDevice +class Controller { public: - PadDevice(); - virtual ~PadDevice(); + Controller(); + virtual ~Controller(); virtual void Reset(); virtual bool DoState(StateWrapper& sw); @@ -21,7 +21,7 @@ public: virtual bool Transfer(const u8 data_in, u8* data_out); /// Creates a new controller of the specified type. - static std::shared_ptr Create(std::string_view type_name); + static std::shared_ptr Create(std::string_view type_name); /// Gets the integer code for a button in the specified controller type. static std::optional GetButtonCodeByName(std::string_view type_name, std::string_view button_name); diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index 6ec7923e0..7cfa9f99b 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -74,7 +74,7 @@ - + @@ -111,7 +111,7 @@ - + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index 1a64b2e40..f48756ea3 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -14,7 +14,6 @@ - @@ -37,6 +36,7 @@ + @@ -56,7 +56,6 @@ - @@ -76,6 +75,7 @@ + diff --git a/src/core/digital_controller.h b/src/core/digital_controller.h index 15d1a14c5..ae3b020d4 100644 --- a/src/core/digital_controller.h +++ b/src/core/digital_controller.h @@ -1,10 +1,10 @@ #pragma once -#include "pad_device.h" +#include "controller.h" #include #include #include -class DigitalController final : public PadDevice +class DigitalController final : public Controller { public: enum class Button : u8 diff --git a/src/core/memory_card.cpp b/src/core/memory_card.cpp index 3858c1a4d..964dde4a4 100644 --- a/src/core/memory_card.cpp +++ b/src/core/memory_card.cpp @@ -245,7 +245,7 @@ std::shared_ptr MemoryCard::Open(System* system, std::string_view fi { SmallString message; message.AppendString("Memory card at '"); - message.AppendString(filename.data(), filename.length()); + message.AppendString(filename.data(), static_cast(filename.length())); message.AppendString("' could not be read, formatting."); Log_ErrorPrint(message); mc->Format(); diff --git a/src/core/memory_card.h b/src/core/memory_card.h index 9cbd0096a..3e029a87e 100644 --- a/src/core/memory_card.h +++ b/src/core/memory_card.h @@ -1,6 +1,6 @@ #pragma once #include "common/bitfield.h" -#include "pad_device.h" +#include "controller.h" #include #include #include @@ -8,7 +8,7 @@ class System; -class MemoryCard final : public PadDevice +class MemoryCard final { public: enum : u32 @@ -19,16 +19,16 @@ public: }; MemoryCard(System* system); - ~MemoryCard() override; + ~MemoryCard(); static std::shared_ptr Create(System* system); static std::shared_ptr Open(System* system, std::string_view filename); - void Reset() override; - bool DoState(StateWrapper& sw) override; + void Reset(); + bool DoState(StateWrapper& sw); - void ResetTransferState() override; - bool Transfer(const u8 data_in, u8* data_out) override; + void ResetTransferState(); + bool Transfer(const u8 data_in, u8* data_out); void Format(); diff --git a/src/core/pad.cpp b/src/core/pad.cpp index e4c9bfef8..4ebc06257 100644 --- a/src/core/pad.cpp +++ b/src/core/pad.cpp @@ -4,7 +4,7 @@ #include "host_interface.h" #include "interrupt_controller.h" #include "memory_card.h" -#include "pad_device.h" +#include "controller.h" #include "system.h" Log_SetChannel(Pad); @@ -289,8 +289,8 @@ void Pad::DoTransfer() { Log_DebugPrintf("Transferring slot %d", m_JOY_CTRL.SLOT.GetValue()); - const std::shared_ptr& controller = m_controllers[m_JOY_CTRL.SLOT]; - const std::shared_ptr& memory_card = m_memory_cards[m_JOY_CTRL.SLOT]; + const std::shared_ptr& controller = m_controllers[m_JOY_CTRL.SLOT]; + const std::shared_ptr& memory_card = m_memory_cards[m_JOY_CTRL.SLOT]; // set rx? m_JOY_CTRL.RXEN = true; diff --git a/src/core/pad.h b/src/core/pad.h index 3b5dbda36..24a0c2b51 100644 --- a/src/core/pad.h +++ b/src/core/pad.h @@ -9,7 +9,7 @@ class StateWrapper; class System; class InterruptController; -class PadDevice; +class Controller; class MemoryCard; class Pad @@ -22,8 +22,8 @@ public: void Reset(); bool DoState(StateWrapper& sw); - PadDevice* GetController(u32 slot) { return m_controllers[slot].get(); } - void SetController(u32 slot, std::shared_ptr dev) { m_controllers[slot] = dev; } + Controller* GetController(u32 slot) { return m_controllers[slot].get(); } + void SetController(u32 slot, std::shared_ptr dev) { m_controllers[slot] = dev; } MemoryCard* GetMemoryCard(u32 slot) { return m_memory_cards[slot].get(); } void SetMemoryCard(u32 slot, std::shared_ptr dev) { m_memory_cards[slot] = dev; } @@ -106,7 +106,7 @@ private: System* m_system = nullptr; InterruptController* m_interrupt_controller = nullptr; - std::array, NUM_SLOTS> m_controllers; + std::array, NUM_SLOTS> m_controllers; std::array, NUM_SLOTS> m_memory_cards; State m_state = State::Idle; diff --git a/src/core/pad_device.cpp b/src/core/pad_device.cpp deleted file mode 100644 index b66324a01..000000000 --- a/src/core/pad_device.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "pad_device.h" -#include "common/state_wrapper.h" -#include "digital_controller.h" - -PadDevice::PadDevice() = default; - -PadDevice::~PadDevice() = default; - -void PadDevice::Reset() {} - -bool PadDevice::DoState(StateWrapper& sw) -{ - return !sw.HasError(); -} - -void PadDevice::ResetTransferState() {} - -bool PadDevice::Transfer(const u8 data_in, u8* data_out) -{ - *data_out = 0xFF; - return false; -} - -std::shared_ptr PadDevice::Create(std::string_view type_name) -{ - if (type_name == "DigitalController") - return DigitalController::Create(); - - return {}; -} - -std::optional PadDevice::GetButtonCodeByName(std::string_view type_name, std::string_view button_name) -{ - if (type_name == "DigitalController") - return DigitalController::GetButtonCodeByName(button_name); - - return {}; -} diff --git a/src/core/sio.cpp b/src/core/sio.cpp index f64e57455..c521acdc1 100644 --- a/src/core/sio.cpp +++ b/src/core/sio.cpp @@ -4,7 +4,7 @@ #include "host_interface.h" #include "interrupt_controller.h" #include "memory_card.h" -#include "pad_device.h" +#include "controller.h" #include "system.h" Log_SetChannel(SIO); diff --git a/src/core/sio.h b/src/core/sio.h index 4a1e31f42..008e8f016 100644 --- a/src/core/sio.h +++ b/src/core/sio.h @@ -9,7 +9,7 @@ class StateWrapper; class System; class InterruptController; -class PadDevice; +class Controller; class MemoryCard; class SIO diff --git a/src/core/system.cpp b/src/core/system.cpp index d92645458..076f50cf3 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -5,6 +5,7 @@ #include "bus.h" #include "cdrom.h" #include "common/state_wrapper.h" +#include "controller.h" #include "cpu_code_cache.h" #include "cpu_core.h" #include "dma.h" @@ -16,7 +17,6 @@ #include "mdec.h" #include "memory_card.h" #include "pad.h" -#include "pad_device.h" #include "sio.h" #include "spu.h" #include "timers.h" @@ -448,7 +448,7 @@ void System::StallCPU(TickCount ticks) m_cpu->AddPendingTicks(ticks); } -void System::SetController(u32 slot, std::shared_ptr dev) +void System::SetController(u32 slot, std::shared_ptr dev) { m_pad->SetController(slot, std::move(dev)); } diff --git a/src/core/system.h b/src/core/system.h index 9957a582d..9c8b79179 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -19,7 +19,7 @@ class InterruptController; class GPU; class CDROM; class Pad; -class PadDevice; +class Controller; class Timers; class SPU; class MDEC; @@ -79,7 +79,7 @@ public: // Adds ticks to the global tick counter, simulating the CPU being stalled. void StallCPU(TickCount ticks); - void SetController(u32 slot, std::shared_ptr dev); + void SetController(u32 slot, std::shared_ptr dev); void UpdateMemoryCards(); void UpdateCPUExecutionMode();