duckstation/src/core/digital_controller.h
Stenzek e4a358cacb
Controller: Add Pop'n and Densha De Go Controllers
Variants of digital controller with different buttons grounded.
2024-10-19 16:23:01 +10:00

71 lines
1.5 KiB
C++

// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
#pragma once
#include "controller.h"
#include <memory>
class DigitalController final : public Controller
{
public:
enum class Button : u8
{
Select = 0,
L3 = 1,
R3 = 2,
Start = 3,
Up = 4,
Right = 5,
Down = 6,
Left = 7,
L2 = 8,
R2 = 9,
L1 = 10,
R1 = 11,
Triangle = 12,
Circle = 13,
Cross = 14,
Square = 15,
Count
};
static const Controller::ControllerInfo INFO;
static const Controller::ControllerInfo INFO_POPN;
static const Controller::ControllerInfo INFO_DDGO;
DigitalController(u32 index, u16 button_mask);
~DigitalController() override;
static std::unique_ptr<DigitalController> Create(u32 index, ControllerType type);
ControllerType GetType() const override;
void Reset() override;
bool DoState(StateWrapper& sw, bool apply_input_state) override;
float GetBindState(u32 index) const override;
void SetBindState(u32 index, float value) override;
u32 GetButtonStateBits() const override;
void ResetTransferState() override;
bool Transfer(const u8 data_in, u8* data_out) override;
private:
enum class TransferState : u8
{
Idle,
Ready,
IDMSB,
ButtonsLSB,
ButtonsMSB
};
// buttons are active low
u16 m_button_state = UINT16_C(0xFFFF);
u16 m_button_mask = UINT16_C(0xFFFF);
TransferState m_transfer_state = TransferState::Idle;
};