-
Notifications
You must be signed in to change notification settings - Fork 2
/
SNESController.cpp
84 lines (54 loc) · 1.25 KB
/
SNESController.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
#include "SNESController.h"
SNESController::SNESController(uint8_t clock, uint8_t storbe, uint8_t data) : NESController(clock, storbe, data) {
}
SNESController::~SNESController() {
}
void SNESController::update() {
digitalWrite(storbe, HIGH);
delayMicroseconds(PAD_CLOCK);
digitalWrite(storbe, LOW);
buttons = 0;
for (uint8_t i = 0; i < 16; i++)
buttons |= read() << i;
buttons = ~buttons;
}
bool SNESController::isB() {
return buttons & 1;
}
bool SNESController::isY() {
return buttons & 2;
}
bool SNESController::isA() {
return buttons & 256;
}
bool SNESController::isX() {
return buttons & 512;
}
bool SNESController::isL() {
return buttons & 1024;
}
bool SNESController::isR() {
return buttons & 2048;
}
void SNESController::setJoyStick() {
joy.xAxis = AXIS_CENTER;
joy.yAxis = AXIS_CENTER;
joy.buttons = 0;
if (isUp())
joy.yAxis = AXIS_MIN;
if (isDown())
joy.yAxis = AXIS_MAX;
if (isLeft())
joy.xAxis = AXIS_MIN;
if (isRight())
joy.xAxis = AXIS_MAX;
joy.buttons |= isA();
joy.buttons |= isB() << 1;
joy.buttons |= isY() << 2;
joy.buttons |= isX() << 3;
joy.buttons |= isR() << 4;
joy.buttons |= isL() << 5;
joy.buttons |= isSelect() << 6;
joy.buttons |= isStart() << 7;
Joystick.setState(&joy);
}