-
Notifications
You must be signed in to change notification settings - Fork 7
/
gamepads.h
213 lines (176 loc) · 5.54 KB
/
gamepads.h
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/* Extenmote : NES, SNES, N64 and Gamecube to Wii remote adapter firmware
* Copyright (C) 2012-2015 Raphael Assenat <raph@raphnet.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _gamepad_h__
#define _gamepad_h__
#define PAD_TYPE_NONE 0
#define PAD_TYPE_CLASSIC 1
#define PAD_TYPE_SNES 2
#define PAD_TYPE_NES 3
#define PAD_TYPE_N64 4
#define PAD_TYPE_GAMECUBE 5
#define PAD_TYPE_MD 6
#define PAD_TYPE_SMS 7
#define NES_RAW_SIZE 1
#define SNES_RAW_SIZE 2
#define N64_RAW_SIZE 4
#define GC_RAW_SIZE 8
#define DB9_RAW_SIZE 2
#define RAW_SIZE_MAX GC_RAW_SIZE
/* Big thanks to the authors of
*
* http://wiibrew.org/wiki/Wiimote/Extension_Controllers/Classic_Controller */
typedef struct _classic_pad_data {
unsigned char pad_type; // PAD_TYPE_CLASSIC
char lx, ly; /* left analog stick */
char rx, ry; /* right analog stick */
char lt, rt; /* left and right triggers (sliders) */
unsigned short buttons;
// raphnet extension (raw N64/Gamecube values)
unsigned char controller_id[2];
unsigned char controller_raw_data[8];
} classic_pad_data;
#define CPAD_BTN_DPAD_RIGHT 0x8000
#define CPAD_BTN_DPAD_DOWN 0x4000
#define CPAD_BTN_DPAD_LEFT 0x0002
#define CPAD_BTN_DPAD_UP 0x0001
#define CPAD_BTN_MINUS 0x1000
#define CPAD_BTN_HOME 0x0800
#define CPAD_BTN_PLUS 0x0400
#define CPAD_BTN_TRIG_LEFT 0x2000
#define CPAD_BTN_TRIG_RIGHT 0x0200
#define CPAD_BTN_RSVD_HIGH 0x0100
#define CPAD_BTN_B 0x0040
#define CPAD_BTN_Y 0x0020
#define CPAD_BTN_A 0x0010
#define CPAD_BTN_X 0x0008
#define CPAD_BTN_ZL 0x0080
#define CPAD_BTN_ZR 0x0004
typedef struct _snes_pad_data {
unsigned char pad_type; // PAD_TYPE_SNES
unsigned short buttons;
unsigned char raw_data[SNES_RAW_SIZE];
} snes_pad_data;
#define SNES_BTN_B 0x0080
#define SNES_BTN_Y 0x0040
#define SNES_BTN_SELECT 0x0020
#define SNES_BTN_START 0x0010
#define SNES_BTN_DPAD_UP 0x0008
#define SNES_BTN_DPAD_DOWN 0x0004
#define SNES_BTN_DPAD_LEFT 0x0002
#define SNES_BTN_DPAD_RIGHT 0x0001
#define SNES_BTN_A 0x8000
#define SNES_BTN_X 0x4000
#define SNES_BTN_L 0x2000
#define SNES_BTN_R 0x1000
typedef struct _nes_pad_data {
unsigned char pad_type; // PAD_TYPE_NES
unsigned char buttons;
unsigned char raw_data[NES_RAW_SIZE];
} nes_pad_data;
#define NES_BTN_A 0x0080
#define NES_BTN_B 0x0040
#define NES_BTN_SELECT 0x0020
#define NES_BTN_START 0x0010
#define NES_BTN_DPAD_UP 0x0008
#define NES_BTN_DPAD_DOWN 0x0004
#define NES_BTN_DPAD_LEFT 0x0002
#define NES_BTN_DPAD_RIGHT 0x0001
typedef struct _n64_pad_data {
unsigned char pad_type; // PAD_TYPE_N64
char x,y;
unsigned short buttons;
unsigned char raw_data[N64_RAW_SIZE];
} n64_pad_data;
#define N64_BTN_A 0x0001
#define N64_BTN_B 0x0002
#define N64_BTN_Z 0x0004
#define N64_BTN_START 0x0008
#define N64_BTN_DPAD_UP 0x0010
#define N64_BTN_DPAD_DOWN 0x0020
#define N64_BTN_DPAD_LEFT 0x0040
#define N64_BTN_DPAD_RIGHT 0x0080
#define N64_BTN_RSVD_LOW1 0x0100
#define N64_BTN_RSVD_LOW2 0x0200
#define N64_BTN_L 0x0400
#define N64_BTN_R 0x0800
#define N64_BTN_C_UP 0x1000
#define N64_BTN_C_DOWN 0x2000
#define N64_BTN_C_LEFT 0x4000
#define N64_BTN_C_RIGHT 0x8000
typedef struct _gc_pad_data {
unsigned char pad_type; // PAD_TYPE_GAMECUBE
char x,y,cx,cy,lt,rt;
unsigned short buttons;
unsigned char raw_data[GC_RAW_SIZE];
} gc_pad_data;
#define GC_BTN_RSVD0 0x0001
#define GC_BTN_RSVD1 0x0002
#define GC_BTN_RSVD2 0x0004
#define GC_BTN_START 0x0008
#define GC_BTN_Y 0x0010
#define GC_BTN_X 0x0020
#define GC_BTN_B 0x0040
#define GC_BTN_A 0x0080
#define GC_BTN_RSVD3 0x0100
#define GC_BTN_L 0x0200
#define GC_BTN_R 0x0400
#define GC_BTN_Z 0x0800
#define GC_BTN_DPAD_UP 0x1000
#define GC_BTN_DPAD_DOWN 0x2000
#define GC_BTN_DPAD_RIGHT 0x4000
#define GC_BTN_DPAD_LEFT 0x8000
#define GC_ALL_BUTTONS (GC_BTN_START|GC_BTN_Y|GC_BTN_X|GC_BTN_B|GC_BTN_A|GC_BTN_L|GC_BTN_R|GC_BTN_Z|GC_BTN_DPAD_UP|GC_BTN_DPAD_DOWN|GC_BTN_DPAD_RIGHT|GC_BTN_DPAD_LEFT)
typedef struct _db9_pad_data {
unsigned char pad_type; // PAD_TYPE_MD or PAD_TYPE_SMS
unsigned short buttons;
unsigned char raw_data[DB9_RAW_SIZE];
} db9_pad_data;
#define DB9_BTN_DPAD_UP 0x0001
#define DB9_BTN_DPAD_DOWN 0x0002
#define DB9_BTN_DPAD_LEFT 0x0004
#define DB9_BTN_DPAD_RIGHT 0x0008
#define DB9_BTN_1 0x0010
#define DB9_BTN_B 0x0010
#define DB9_BTN_2 0x0020
#define DB9_BTN_C 0x0020
#define DB9_BTN_A 0x0040
#define DB9_BTN_X 0x0080
#define DB9_BTN_Y 0x0100
#define DB9_BTN_Z 0x0200
#define DB9_BTN_START 0x0400
#define DB9_BTN_MODE 0x0800
typedef struct _gamepad_data {
union {
unsigned char pad_type; // PAD_TYPE_*
classic_pad_data classic;
snes_pad_data snes;
nes_pad_data nes;
n64_pad_data n64;
gc_pad_data gc;
db9_pad_data db9;
};
} gamepad_data;
typedef struct {
char (*init)(void);
char (*update)(void);
char (*changed)(void);
void (*getReport)(gamepad_data *dst);
void (*setVibration)(int value);
char (*probe)(void);
} Gamepad;
#define IS_SIMULTANEOUS(x,mask) (((x)&(mask)) == (mask))
#endif // _gamepad_h__