diff --git a/src/core/controller.cpp b/src/core/controller.cpp index 9bf210f1a..8cebd9b21 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -23,18 +23,30 @@ bool Controller::Transfer(const u8 data_in, u8* data_out) void Controller::SetButtonState(s32 button_code, bool pressed) {} -std::unique_ptr Controller::Create(std::string_view type_name) +std::unique_ptr Controller::Create(ControllerType type) { - if (type_name == "DigitalController") - return DigitalController::Create(); + switch (type) + { + return {}; - return {}; + case ControllerType::DigitalController: + return DigitalController::Create(); + + case ControllerType::None: + default: + return {}; + } } -std::optional Controller::GetButtonCodeByName(std::string_view type_name, std::string_view button_name) +std::optional Controller::GetButtonCodeByName(ControllerType type, std::string_view button_name) { - if (type_name == "DigitalController") - return DigitalController::GetButtonCodeByName(button_name); + switch (type) + { + case ControllerType::DigitalController: + return DigitalController::GetButtonCodeByName(button_name); - return {}; + case ControllerType::None: + default: + return std::nullopt; + } } diff --git a/src/core/controller.h b/src/core/controller.h index ffe92f8b9..59773f399 100644 --- a/src/core/controller.h +++ b/src/core/controller.h @@ -25,8 +25,8 @@ public: virtual void SetButtonState(s32 button_code, bool pressed); /// Creates a new controller of the specified type. - static std::unique_ptr Create(std::string_view type_name); + static std::unique_ptr Create(ControllerType type); /// 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); + static std::optional GetButtonCodeByName(ControllerType type, std::string_view button_name); }; diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 05f31722b..13b3691ac 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -33,6 +33,9 @@ void Settings::SetDefaults() bios_patch_tty_enable = false; bios_patch_fast_boot = false; + controller_a_type = ControllerType::DigitalController; + controller_b_type = ControllerType::None; + memory_card_a_path = "memory_card_a.mcd"; memory_card_b_path.clear(); } @@ -69,6 +72,11 @@ void Settings::Load(const char* filename) bios_patch_tty_enable = ini.GetBoolValue("BIOS", "PatchTTYEnable", true); bios_patch_fast_boot = ini.GetBoolValue("BIOS", "PatchFastBoot", false); + controller_a_type = ParseControllerTypeName(ini.GetValue("Controller", "PortAType", "DigitalController")) + .value_or(ControllerType::DigitalController); + controller_b_type = + ParseControllerTypeName(ini.GetValue("Controller", "PortBType", "None")).value_or(ControllerType::None); + memory_card_a_path = ini.GetValue("MemoryCard", "CardAPath", "memory_card_a.mcd"); memory_card_b_path = ini.GetValue("MemoryCard", "CardBPath", ""); } @@ -102,6 +110,9 @@ bool Settings::Save(const char* filename) const ini.SetBoolValue("BIOS", "PatchTTYEnable", bios_patch_tty_enable); ini.SetBoolValue("BIOS", "PatchFastBoot", bios_patch_fast_boot); + ini.SetValue("Controller", "PortAType", GetControllerTypeName(controller_a_type)); + ini.SetValue("Controller", "PortBType", GetControllerTypeName(controller_b_type)); + if (!memory_card_a_path.empty()) ini.SetValue("MemoryCard", "CardAPath", memory_card_a_path.c_str()); else @@ -205,3 +216,30 @@ const char* Settings::GetRendererDisplayName(GPURenderer renderer) { return s_gpu_renderer_display_names[static_cast(renderer)]; } + +static std::array s_controller_type_names = {{"None", "DigitalController"}}; +static std::array s_controller_display_names = {{"None", "Digital Controller"}}; + +std::optional Settings::ParseControllerTypeName(const char* str) +{ + int index = 0; + for (const char* name : s_controller_type_names) + { + if (strcasecmp(name, str) == 0) + return static_cast(index); + + index++; + } + + return std::nullopt; +} + +const char* Settings::GetControllerTypeName(ControllerType type) +{ + return s_controller_type_names[static_cast(type)]; +} + +const char* Settings::GetControllerTypeDisplayName(ControllerType type) +{ + return s_controller_display_names[static_cast(type)]; +} diff --git a/src/core/settings.h b/src/core/settings.h index edb149277..eaa40e6d7 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -45,6 +45,9 @@ struct Settings bool bios_patch_tty_enable = false; bool bios_patch_fast_boot = false; + ControllerType controller_a_type = ControllerType::None; + ControllerType controller_b_type = ControllerType::None; + std::string memory_card_a_path; std::string memory_card_b_path; @@ -63,4 +66,8 @@ struct Settings static std::optional ParseRendererName(const char* str); static const char* GetRendererName(GPURenderer renderer); static const char* GetRendererDisplayName(GPURenderer renderer); + + static std::optional ParseControllerTypeName(const char* str); + static const char* GetControllerTypeName(ControllerType type); + static const char* GetControllerTypeDisplayName(ControllerType type); }; diff --git a/src/core/system.cpp b/src/core/system.cpp index a4ee45029..06b9b6b4c 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -462,11 +462,20 @@ void System::UpdateControllers() m_pad->SetController(0, nullptr); m_pad->SetController(1, nullptr); + const Settings& settings = m_host_interface->GetSettings(); + if (settings.controller_a_type != ControllerType::None) { - std::unique_ptr controller = Controller::Create("DigitalController"); + std::unique_ptr controller = Controller::Create(settings.controller_a_type); if (controller) m_pad->SetController(0, std::move(controller)); } + + if (settings.controller_b_type != ControllerType::None) + { + std::unique_ptr controller = Controller::Create(settings.controller_b_type); + if (controller) + m_pad->SetController(1, std::move(controller)); + } } void System::UpdateMemoryCards() diff --git a/src/core/types.h b/src/core/types.h index beb7ee931..059c9ec9c 100644 --- a/src/core/types.h +++ b/src/core/types.h @@ -47,6 +47,12 @@ enum class GPURenderer : u8 Count }; +enum class ControllerType +{ + None, + DigitalController, +}; + enum : u32 { CPU_CODE_CACHE_PAGE_SIZE = 1024,