-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Turntable.cpp
155 lines (126 loc) · 3.86 KB
/
Turntable.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright 2010 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <cstring>
#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Core/HW/WiimoteEmu/Attachment/Turntable.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
namespace WiimoteEmu
{
static const u8 turntable_id[] = {0x03, 0x00, 0xa4, 0x20, 0x01, 0x03};
static const u16 turntable_button_bitmasks[] = {
Turntable::BUTTON_L_GREEN, Turntable::BUTTON_L_RED, Turntable::BUTTON_L_BLUE,
Turntable::BUTTON_R_GREEN, Turntable::BUTTON_R_RED, Turntable::BUTTON_R_BLUE,
Turntable::BUTTON_MINUS, Turntable::BUTTON_PLUS, Turntable::BUTTON_EUPHORIA,
};
static const char* const turntable_button_names[] = {
_trans("Green Left"),
_trans("Red Left"),
_trans("Blue Left"),
_trans("Green Right"),
_trans("Red Right"),
_trans("Blue Right"),
"-",
"+",
_trans("Euphoria"),
};
Turntable::Turntable(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Turntable"), _reg)
{
// buttons
groups.emplace_back(m_buttons = new Buttons("Buttons"));
for (auto& turntable_button_name : turntable_button_names)
m_buttons->controls.emplace_back(new ControlGroup::Input(turntable_button_name));
// turntables
groups.emplace_back(m_left_table = new Slider(_trans("Table Left")));
groups.emplace_back(m_right_table = new Slider(_trans("Table Right")));
// stick
groups.emplace_back(m_stick = new AnalogStick("Stick", DEFAULT_ATTACHMENT_STICK_RADIUS));
// effect dial
groups.emplace_back(m_effect_dial = new Triggers(_trans("Effect")));
m_effect_dial->controls.emplace_back(new ControlGroup::Input(_trans("Dial")));
// crossfade
groups.emplace_back(m_crossfade = new Slider(_trans("Crossfade")));
// set up register
// id
memcpy(&id, turntable_id, sizeof(turntable_id));
}
void Turntable::GetState(u8* const data)
{
wm_turntable_extension* const ttdata = (wm_turntable_extension*)data;
ttdata->bt = 0;
// stick
{
ControlState x, y;
m_stick->GetState(&x, &y);
ttdata->sx = static_cast<u8>((x * 0x1F) + 0x20);
ttdata->sy = static_cast<u8>((y * 0x1F) + 0x20);
}
// left table
{
ControlState tt;
s8 tt_;
m_left_table->GetState(&tt);
tt_ = static_cast<s8>(tt * 0x1F);
ttdata->ltable1 = tt_;
ttdata->ltable2 = tt_ >> 5;
}
// right table
{
ControlState tt;
s8 tt_;
m_right_table->GetState(&tt);
tt_ = static_cast<s8>(tt * 0x1F);
ttdata->rtable1 = tt_;
ttdata->rtable2 = tt_ >> 1;
ttdata->rtable3 = tt_ >> 3;
ttdata->rtable4 = tt_ >> 5;
}
// effect dial
{
ControlState dial;
u8 dial_;
m_effect_dial->GetState(&dial);
dial_ = static_cast<u8>(dial * 0x0F);
ttdata->dial1 = dial_;
ttdata->dial2 = dial_ >> 3;
}
// crossfade slider
{
ControlState cfs;
m_crossfade->GetState(&cfs);
ttdata->slider = static_cast<u8>((cfs * 0x07) + 0x08);
}
// buttons
m_buttons->GetState(&ttdata->bt, turntable_button_bitmasks);
// flip button bits :/
ttdata->bt ^= (BUTTON_L_GREEN | BUTTON_L_RED | BUTTON_L_BLUE | BUTTON_R_GREEN | BUTTON_R_RED |
BUTTON_R_BLUE | BUTTON_MINUS | BUTTON_PLUS | BUTTON_EUPHORIA);
}
bool Turntable::IsButtonPressed() const
{
u16 buttons = 0;
m_buttons->GetState(&buttons, turntable_button_bitmasks);
return buttons != 0;
}
ControllerEmu::ControlGroup* Turntable::GetGroup(WiimoteEmu::TurntableGroup group)
{
switch (group)
{
case WiimoteEmu::TurntableGroup::Buttons:
return m_buttons;
case WiimoteEmu::TurntableGroup::Stick:
return m_stick;
case WiimoteEmu::TurntableGroup::EffectDial:
return m_effect_dial;
case WiimoteEmu::TurntableGroup::LeftTable:
return m_left_table;
case WiimoteEmu::TurntableGroup::RightTable:
return m_right_table;
case WiimoteEmu::TurntableGroup::Crossfade:
return m_crossfade;
default:
return nullptr;
}
}
}