48d52ab5 |
1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
2 | * Mupen64plus-input-sdl - plugin.h * |
3 | * Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ * |
4 | * Copyright (C) 2008-2009 Richard Goedeken * |
5 | * Copyright (C) 2008 Tillin9 * |
6 | * Copyright (C) 2002 Blight * |
7 | * * |
8 | * This program is free software; you can redistribute it and/or modify * |
9 | * it under the terms of the GNU General Public License as published by * |
10 | * the Free Software Foundation; either version 2 of the License, or * |
11 | * (at your option) any later version. * |
12 | * * |
13 | * This program is distributed in the hope that it will be useful, * |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 | * GNU General Public License for more details. * |
17 | * * |
18 | * You should have received a copy of the GNU General Public License * |
19 | * along with this program; if not, write to the * |
20 | * Free Software Foundation, Inc., * |
21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * |
22 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
23 | |
24 | #ifndef __PLUGIN_H__ |
25 | #define __PLUGIN_H__ |
26 | |
27 | #include <SDL.h> |
28 | #if ! SDL_VERSION_ATLEAST(1,3,0) |
29 | |
30 | #define SDL_GetKeyboardState SDL_GetKeyState |
31 | #define SDL_SCANCODE_UNKNOWN SDLK_UNKNOWN |
32 | #define SDL_NUM_SCANCODES SDLK_LAST |
33 | #define SDL_SCANCODE_RCTRL SDLK_RCTRL |
34 | #define SDL_SCANCODE_RSHIFT SDLK_RSHIFT |
35 | #define SDL_SCANCODE_LCTRL SDLK_LCTRL |
36 | #define SDL_SCANCODE_LALT SDLK_LALT |
37 | #define SDL_Scancode SDLKey |
38 | |
39 | #endif |
40 | |
41 | #if SDL_VERSION_ATLEAST(2,0,0) |
42 | |
43 | static inline const char* _SDL_JoystickName(int device_index) |
44 | { |
45 | SDL_Joystick *joystick; |
46 | const char *name; |
47 | static char JoyName[256]; |
48 | |
49 | joystick = SDL_JoystickOpen(device_index); |
50 | if (!joystick) |
51 | return NULL; |
52 | |
53 | name = SDL_JoystickName(joystick); |
54 | if (name) |
55 | { |
56 | strncpy(JoyName, name, 255); |
57 | JoyName[255] = 0; |
58 | } |
59 | SDL_JoystickClose(joystick); |
60 | |
61 | return JoyName; |
62 | } |
63 | |
64 | #define SDL_JoystickName(device_index) _SDL_JoystickName(device_index) |
65 | |
66 | #endif |
67 | |
68 | #define M64P_PLUGIN_PROTOTYPES 1 |
69 | #include "m64p_plugin.h" |
70 | #include "m64p_config.h" |
71 | |
72 | #define DEVICE_NO_JOYSTICK (-1) |
73 | |
74 | // Some stuff from n-rage plugin |
75 | #define RD_GETSTATUS 0x00 // get status |
76 | #define RD_READKEYS 0x01 // read button values |
77 | #define RD_READPAK 0x02 // read from controllerpack |
78 | #define RD_WRITEPAK 0x03 // write to controllerpack |
79 | #define RD_RESETCONTROLLER 0xff // reset controller |
80 | #define RD_READEEPROM 0x04 // read eeprom |
81 | #define RD_WRITEEPROM 0x05 // write eeprom |
82 | |
83 | #define PAK_IO_RUMBLE 0xC000 // the address where rumble-commands are sent to |
84 | |
85 | enum EButton |
86 | { |
87 | R_DPAD = 0, |
88 | L_DPAD, |
89 | D_DPAD, |
90 | U_DPAD, |
91 | START_BUTTON, |
92 | Z_TRIG, |
93 | B_BUTTON, |
94 | A_BUTTON, |
95 | R_CBUTTON, |
96 | L_CBUTTON, |
97 | D_CBUTTON, |
98 | U_CBUTTON, |
99 | R_TRIG, |
100 | L_TRIG, |
101 | MEMPAK, |
102 | RUMBLEPAK, |
6ff3e5eb |
103 | R_CBUTTON2, |
104 | L_CBUTTON2, |
105 | D_CBUTTON2, |
106 | U_CBUTTON2, |
48d52ab5 |
107 | X_AXIS, |
108 | Y_AXIS, |
109 | NUM_BUTTONS |
110 | }; |
111 | |
112 | typedef struct |
113 | { |
114 | int button; // button index; -1 if notassigned |
115 | SDL_Scancode key; // sdl keysym; SDL_SCANCODE_UNKNOWN if not assigned |
116 | int axis, axis_dir; // aixs + direction (i.e. 0, 1 = X Axis +; 0, -1 = X Axis -); -1 if notassigned |
117 | int axis_deadzone; // -1 for default, or >= 0 for custom value |
118 | int hat, hat_pos; // hat + hat position; -1 if not assigned |
119 | int mouse; // mouse button |
6ff3e5eb |
120 | int mouse_up; // mouse direction pseudo buttons |
121 | int mouse_down; |
122 | int mouse_left; |
123 | int mouse_right; |
48d52ab5 |
124 | } SButtonMap; |
125 | |
126 | typedef struct |
127 | { |
128 | int button_a, button_b; // up/down or left/right; -1 if not assigned |
129 | SDL_Scancode key_a, key_b; // up/down or left/right; SDL_SCANCODE_UNKNOWN if not assigned |
130 | int axis_a, axis_b; // axis index; -1 if not assigned |
131 | int axis_dir_a, axis_dir_b; // direction (1 = X+, 0, -1 = X-) |
132 | int hat, hat_pos_a, hat_pos_b; // hat + hat position up/down and left/right; -1 if not assigned |
133 | } SAxisMap; |
134 | |
135 | typedef struct |
136 | { |
137 | CONTROL *control; // pointer to CONTROL struct in Core library |
138 | BUTTONS buttons; |
139 | |
140 | // mappings |
6ff3e5eb |
141 | SButtonMap button[NUM_BUTTONS]; // 14 buttons; in the order of EButton + mempak/rumblepak switches |
48d52ab5 |
142 | SAxisMap axis[2]; // 2 axis |
143 | int device; // joystick device; -1 = keyboard; -2 = none |
144 | int mouse; // mouse enabled: 0 = no; 1 = yes |
145 | SDL_Joystick *joystick; // SDL joystick device |
146 | int event_joystick; // the /dev/input/eventX device for force feeback |
147 | int axis_deadzone[2]; // minimum absolute value before analog movement is recognized |
148 | int axis_peak[2]; // highest analog value returned by SDL, used for scaling |
149 | float mouse_sens[2]; // mouse sensitivity |
6ff3e5eb |
150 | int mouse_up; |
151 | int mouse_down; |
152 | int mouse_left; |
153 | int mouse_right; |
48d52ab5 |
154 | } SController; |
155 | |
156 | /* global data definitions */ |
157 | extern SController controller[4]; // 4 controllers |
158 | |
159 | /* global function definitions */ |
160 | extern void DebugMessage(int level, const char *message, ...); |
161 | |
162 | /* declarations of pointers to Core config functions */ |
163 | extern ptr_ConfigListSections ConfigListSections; |
164 | extern ptr_ConfigOpenSection ConfigOpenSection; |
165 | extern ptr_ConfigDeleteSection ConfigDeleteSection; |
166 | extern ptr_ConfigListParameters ConfigListParameters; |
167 | extern ptr_ConfigSaveFile ConfigSaveFile; |
168 | extern ptr_ConfigSaveSection ConfigSaveSection; |
169 | extern ptr_ConfigSetParameter ConfigSetParameter; |
170 | extern ptr_ConfigGetParameter ConfigGetParameter; |
171 | extern ptr_ConfigGetParameterHelp ConfigGetParameterHelp; |
172 | extern ptr_ConfigSetDefaultInt ConfigSetDefaultInt; |
173 | extern ptr_ConfigSetDefaultFloat ConfigSetDefaultFloat; |
174 | extern ptr_ConfigSetDefaultBool ConfigSetDefaultBool; |
175 | extern ptr_ConfigSetDefaultString ConfigSetDefaultString; |
176 | extern ptr_ConfigGetParamInt ConfigGetParamInt; |
177 | extern ptr_ConfigGetParamFloat ConfigGetParamFloat; |
178 | extern ptr_ConfigGetParamBool ConfigGetParamBool; |
179 | extern ptr_ConfigGetParamString ConfigGetParamString; |
180 | |
181 | extern ptr_ConfigGetSharedDataFilepath ConfigGetSharedDataFilepath; |
182 | extern ptr_ConfigGetUserConfigPath ConfigGetUserConfigPath; |
183 | extern ptr_ConfigGetUserDataPath ConfigGetUserDataPath; |
184 | extern ptr_ConfigGetUserCachePath ConfigGetUserCachePath; |
185 | |
186 | #endif // __PLUGIN_H__ |
187 | |