#include "digital_controller.h" #include "common/assert.h" #include "common/state_wrapper.h" #include "host_interface.h" #include "system.h" DigitalController::DigitalController() = default; DigitalController::~DigitalController() = default; ControllerType DigitalController::GetType() const { return ControllerType::DigitalController; } std::optional DigitalController::GetAxisCodeByName(std::string_view axis_name) const { return StaticGetAxisCodeByName(axis_name); } std::optional DigitalController::GetButtonCodeByName(std::string_view button_name) const { return StaticGetButtonCodeByName(button_name); } void DigitalController::Reset() { m_transfer_state = TransferState::Idle; } bool DigitalController::DoState(StateWrapper& sw, bool apply_input_state) { if (!Controller::DoState(sw, apply_input_state)) return false; u16 button_state = m_button_state; sw.Do(&button_state); if (apply_input_state) m_button_state = button_state; sw.Do(&m_transfer_state); return true; } bool DigitalController::GetButtonState(s32 button_code) const { if (button_code < 0 || button_code >= static_cast(Button::Count)) return false; const u16 bit = u16(1) << static_cast(button_code); return ((m_button_state & bit) == 0); } void DigitalController::SetButtonState(Button button, bool pressed) { const u16 bit = u16(1) << static_cast(button); if (pressed) { if (m_button_state & bit) System::SetRunaheadReplayFlag(); m_button_state &= ~bit; } else { if (!(m_button_state & bit)) System::SetRunaheadReplayFlag(); m_button_state |= bit; } } void DigitalController::SetButtonState(s32 button_code, bool pressed) { if (button_code < 0 || button_code >= static_cast(Button::Count)) return; SetButtonState(static_cast