mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-10-11 22:49:50 +00:00
Merge pull request #14897 from jordan-woyak/gba-button-bits
GBAPadEmu: Make GBAPad::GetInput use actual GBA button values.
This commit is contained in:
@@ -10,12 +10,6 @@
|
||||
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
|
||||
#include "InputCommon/GCPadStatus.h"
|
||||
|
||||
static const u16 dpad_bitmasks[] = {PAD_BUTTON_UP, PAD_BUTTON_DOWN, PAD_BUTTON_LEFT,
|
||||
PAD_BUTTON_RIGHT};
|
||||
|
||||
static const u16 button_bitmasks[] = {PAD_BUTTON_B, PAD_BUTTON_A, PAD_TRIGGER_L,
|
||||
PAD_TRIGGER_R, PAD_TRIGGER_Z, PAD_BUTTON_START};
|
||||
|
||||
GBAPad::GBAPad(const unsigned int index) : m_reset_pending(false), m_index(index)
|
||||
{
|
||||
using Translatability = ControllerEmu::Translatability;
|
||||
@@ -67,15 +61,25 @@ GCPadStatus GBAPad::GetInput()
|
||||
const auto lock = GetStateLock();
|
||||
GCPadStatus pad = {};
|
||||
|
||||
static constexpr u16 dpad_bitmasks[] = {
|
||||
GBA_BUTTON_UP,
|
||||
GBA_BUTTON_DOWN,
|
||||
GBA_BUTTON_LEFT,
|
||||
GBA_BUTTON_RIGHT,
|
||||
};
|
||||
|
||||
static constexpr u16 button_bitmasks[] = {
|
||||
GBA_BUTTON_B, GBA_BUTTON_A, GBA_BUTTON_L, GBA_BUTTON_R, GBA_BUTTON_SELECT, GBA_BUTTON_START,
|
||||
};
|
||||
|
||||
// Buttons
|
||||
m_buttons->GetState(&pad.button, button_bitmasks, m_input_override_function);
|
||||
|
||||
// DPad
|
||||
m_dpad->GetState(&pad.button, dpad_bitmasks, m_input_override_function);
|
||||
|
||||
// Use X button as a reset signal
|
||||
if (m_reset_pending)
|
||||
pad.button |= PAD_BUTTON_X;
|
||||
pad.button |= PAD_STATUS_RESET_SIGNAL;
|
||||
m_reset_pending = false;
|
||||
|
||||
return pad;
|
||||
|
||||
@@ -23,6 +23,21 @@ enum class GBAPadGroup
|
||||
class GBAPad : public ControllerEmu::EmulatedController
|
||||
{
|
||||
public:
|
||||
static constexpr u16 GBA_BUTTON_A = 1u << 0;
|
||||
static constexpr u16 GBA_BUTTON_B = 1u << 1;
|
||||
static constexpr u16 GBA_BUTTON_SELECT = 1u << 2;
|
||||
static constexpr u16 GBA_BUTTON_START = 1u << 3;
|
||||
static constexpr u16 GBA_BUTTON_RIGHT = 1u << 4;
|
||||
static constexpr u16 GBA_BUTTON_LEFT = 1u << 5;
|
||||
static constexpr u16 GBA_BUTTON_UP = 1u << 6;
|
||||
static constexpr u16 GBA_BUTTON_DOWN = 1u << 7;
|
||||
static constexpr u16 GBA_BUTTON_R = 1u << 8;
|
||||
static constexpr u16 GBA_BUTTON_L = 1u << 9;
|
||||
|
||||
static constexpr u16 GBA_ALL_BUTTONS = (1u << 10) - 1;
|
||||
|
||||
static constexpr u16 PAD_STATUS_RESET_SIGNAL = 1u << 10;
|
||||
|
||||
explicit GBAPad(unsigned int index);
|
||||
GCPadStatus GetInput();
|
||||
void SetReset(bool reset);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "Core/CoreTiming.h"
|
||||
#include "Core/HW/GBACore.h"
|
||||
#include "Core/HW/GBAPad.h"
|
||||
#include "Core/HW/GBAPadEmu.h"
|
||||
#include "Core/HW/SI/SI.h"
|
||||
#include "Core/HW/SI/SI_DeviceGCController.h"
|
||||
#include "Core/HW/SystemTimers.h"
|
||||
@@ -128,25 +129,11 @@ DataResponse CSIDevice_GBAEmu::GetData(u32& hi, u32& low)
|
||||
SerialInterface::CSIDevice_GCController::HandleMoviePadStatus(m_system.GetMovie(),
|
||||
m_device_number, &pad_status);
|
||||
|
||||
static constexpr std::array<PadButton, 10> buttons_map = {
|
||||
PadButton::PAD_BUTTON_A, // A
|
||||
PadButton::PAD_BUTTON_B, // B
|
||||
PadButton::PAD_TRIGGER_Z, // Select
|
||||
PadButton::PAD_BUTTON_START, // Start
|
||||
PadButton::PAD_BUTTON_RIGHT, // Right
|
||||
PadButton::PAD_BUTTON_LEFT, // Left
|
||||
PadButton::PAD_BUTTON_UP, // Up
|
||||
PadButton::PAD_BUTTON_DOWN, // Down
|
||||
PadButton::PAD_TRIGGER_R, // R
|
||||
PadButton::PAD_TRIGGER_L, // L
|
||||
};
|
||||
// Note: The misused GCPadStatus contains GBA button values.
|
||||
m_keys = pad_status.button & GBAPad::GBA_ALL_BUTTONS;
|
||||
|
||||
m_keys = 0;
|
||||
for (size_t i = 0; i < buttons_map.size(); ++i)
|
||||
m_keys |= static_cast<u16>(static_cast<bool>((pad_status.button & buttons_map[i]))) << i;
|
||||
|
||||
// Use X button as a reset signal for NetPlay/Movies
|
||||
if (pad_status.button & PadButton::PAD_BUTTON_X)
|
||||
// A reset signal for NetPlay/Movies
|
||||
if (pad_status.button & GBAPad::PAD_STATUS_RESET_SIGNAL)
|
||||
m_core->Reset();
|
||||
|
||||
return DataResponse::NoData;
|
||||
|
||||
Reference in New Issue
Block a user