Input SDL plugin. Compile and run on the OpenPandora. Include config for Pandora...
[mupen64plus-pandora.git] / source / mupen64plus-input-sdl / src / plugin.h
CommitLineData
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
43static 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
85enum 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,
103 X_AXIS,
104 Y_AXIS,
105 NUM_BUTTONS
106};
107
108typedef struct
109{
110 int button; // button index; -1 if notassigned
111 SDL_Scancode key; // sdl keysym; SDL_SCANCODE_UNKNOWN if not assigned
112 int axis, axis_dir; // aixs + direction (i.e. 0, 1 = X Axis +; 0, -1 = X Axis -); -1 if notassigned
113 int axis_deadzone; // -1 for default, or >= 0 for custom value
114 int hat, hat_pos; // hat + hat position; -1 if not assigned
115 int mouse; // mouse button
116} SButtonMap;
117
118typedef struct
119{
120 int button_a, button_b; // up/down or left/right; -1 if not assigned
121 SDL_Scancode key_a, key_b; // up/down or left/right; SDL_SCANCODE_UNKNOWN if not assigned
122 int axis_a, axis_b; // axis index; -1 if not assigned
123 int axis_dir_a, axis_dir_b; // direction (1 = X+, 0, -1 = X-)
124 int hat, hat_pos_a, hat_pos_b; // hat + hat position up/down and left/right; -1 if not assigned
125} SAxisMap;
126
127typedef struct
128{
129 CONTROL *control; // pointer to CONTROL struct in Core library
130 BUTTONS buttons;
131
132 // mappings
133 SButtonMap button[16]; // 14 buttons; in the order of EButton + mempak/rumblepak switches
134 SAxisMap axis[2]; // 2 axis
135 int device; // joystick device; -1 = keyboard; -2 = none
136 int mouse; // mouse enabled: 0 = no; 1 = yes
137 SDL_Joystick *joystick; // SDL joystick device
138 int event_joystick; // the /dev/input/eventX device for force feeback
139 int axis_deadzone[2]; // minimum absolute value before analog movement is recognized
140 int axis_peak[2]; // highest analog value returned by SDL, used for scaling
141 float mouse_sens[2]; // mouse sensitivity
142} SController;
143
144/* global data definitions */
145extern SController controller[4]; // 4 controllers
146
147/* global function definitions */
148extern void DebugMessage(int level, const char *message, ...);
149
150/* declarations of pointers to Core config functions */
151extern ptr_ConfigListSections ConfigListSections;
152extern ptr_ConfigOpenSection ConfigOpenSection;
153extern ptr_ConfigDeleteSection ConfigDeleteSection;
154extern ptr_ConfigListParameters ConfigListParameters;
155extern ptr_ConfigSaveFile ConfigSaveFile;
156extern ptr_ConfigSaveSection ConfigSaveSection;
157extern ptr_ConfigSetParameter ConfigSetParameter;
158extern ptr_ConfigGetParameter ConfigGetParameter;
159extern ptr_ConfigGetParameterHelp ConfigGetParameterHelp;
160extern ptr_ConfigSetDefaultInt ConfigSetDefaultInt;
161extern ptr_ConfigSetDefaultFloat ConfigSetDefaultFloat;
162extern ptr_ConfigSetDefaultBool ConfigSetDefaultBool;
163extern ptr_ConfigSetDefaultString ConfigSetDefaultString;
164extern ptr_ConfigGetParamInt ConfigGetParamInt;
165extern ptr_ConfigGetParamFloat ConfigGetParamFloat;
166extern ptr_ConfigGetParamBool ConfigGetParamBool;
167extern ptr_ConfigGetParamString ConfigGetParamString;
168
169extern ptr_ConfigGetSharedDataFilepath ConfigGetSharedDataFilepath;
170extern ptr_ConfigGetUserConfigPath ConfigGetUserConfigPath;
171extern ptr_ConfigGetUserDataPath ConfigGetUserDataPath;
172extern ptr_ConfigGetUserCachePath ConfigGetUserCachePath;
173
174#endif // __PLUGIN_H__
175