/
TaTaCon.cpp
88 lines (70 loc) · 2.21 KB
/
TaTaCon.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2019 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "Core/HW/WiimoteEmu/Extension/TaTaCon.h"
#include <array>
#include <cstring>
#include "Common/Assert.h"
#include "Common/BitUtils.h"
#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
namespace WiimoteEmu
{
constexpr std::array<u8, 6> tatacon_id{{0x00, 0x00, 0xa4, 0x20, 0x01, 0x11}};
constexpr std::array<u8, 2> center_bitmasks{{
TaTaCon::CENTER_LEFT,
TaTaCon::CENTER_RIGHT,
}};
constexpr std::array<u8, 2> rim_bitmasks{{
TaTaCon::RIM_LEFT,
TaTaCon::RIM_RIGHT,
}};
constexpr std::array<const char*, 2> position_names{{
_trans("Left"),
_trans("Right"),
}};
// i18n: The drum controller used in "Taiko no Tatsujin" games. Also known as a "TaTaCon".
TaTaCon::TaTaCon() : Extension3rdParty("TaTaCon", _trans("Taiko Drum"))
{
// i18n: Refers to the "center" of a TaTaCon drum.
groups.emplace_back(m_center = new ControllerEmu::Buttons(_trans("Center")));
for (auto& name : position_names)
m_center->AddInput(ControllerEmu::Translate, name);
// i18n: Refers to the "rim" of a TaTaCon drum.
groups.emplace_back(m_rim = new ControllerEmu::Buttons(_trans("Rim")));
for (auto& name : position_names)
m_rim->AddInput(ControllerEmu::Translate, name);
}
void TaTaCon::Update()
{
DataFormat tatacon_data = {};
m_center->GetState(&tatacon_data.state, center_bitmasks.data());
m_rim->GetState(&tatacon_data.state, rim_bitmasks.data());
// Flip button bits.
tatacon_data.state ^= 0xff;
Common::BitCastPtr<DataFormat>(&m_reg.controller_data) = tatacon_data;
}
void TaTaCon::Reset()
{
EncryptedExtension::Reset();
m_reg = {};
m_reg.identifier = tatacon_id;
// Assuming calibration is 0xff filled like every other 3rd-party extension.
m_reg.calibration.fill(0xff);
}
ControllerEmu::ControlGroup* TaTaCon::GetGroup(TaTaConGroup group)
{
switch (group)
{
case TaTaConGroup::Center:
return m_center;
case TaTaConGroup::Rim:
return m_rim;
default:
ASSERT(false);
return nullptr;
}
}
} // namespace WiimoteEmu