minimal working gtk-less build
[pcsx_rearmed.git] / plugins / dfinput / pad.h
CommitLineData
ef79bbde
P
1/*
2 * Copyright (c) 2009, Wei Mingzhi <whistler@openoffice.org>.
3 * All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses>.
17 */
18
19#ifndef PAD_H_
20#define PAD_H_
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#ifndef _MACOSX
27#include "config.h"
28#endif
29
30#include <stdio.h>
31#include <stdint.h>
32#include <stdlib.h>
33#include <string.h>
34#include <unistd.h>
35#include <pthread.h>
36
37#include <SDL.h>
38#include <SDL_joystick.h>
39
40#ifdef _MACOSX
41#include <Carbon/Carbon.h>
42typedef void *Display;
43#define ThreadID ThreadID_MACOSX
44#else
45#include <X11/Xlib.h>
46#include <X11/Xutil.h>
47#include <X11/keysym.h>
48#include <X11/XKBlib.h>
49#endif
50
51#include "psemu_plugin_defs.h"
52
53#ifdef ENABLE_NLS
54#include <libintl.h>
55#include <locale.h>
56#define _(x) gettext(x)
57#define N_(x) (x)
58#else
59#define _(x) (x)
60#define N_(x) (x)
61#endif
62
63enum {
64 DKEY_SELECT = 0,
65 DKEY_L3,
66 DKEY_R3,
67 DKEY_START,
68 DKEY_UP,
69 DKEY_RIGHT,
70 DKEY_DOWN,
71 DKEY_LEFT,
72 DKEY_L2,
73 DKEY_R2,
74 DKEY_L1,
75 DKEY_R1,
76 DKEY_TRIANGLE,
77 DKEY_CIRCLE,
78 DKEY_CROSS,
79 DKEY_SQUARE,
80
81 DKEY_TOTAL
82};
83
84enum {
85 ANALOG_LEFT = 0,
86 ANALOG_RIGHT,
87
88 ANALOG_TOTAL
89};
90
91enum { NONE = 0, AXIS, HAT, BUTTON };
92
93typedef struct tagKeyDef {
94 uint8_t JoyEvType;
95 union {
96 int16_t d;
97 int16_t Axis; // positive=axis+, negative=axis-, abs(Axis)-1=axis index
98 uint16_t Hat; // 8-bit for hat number, 8-bit for direction
99 uint16_t Button; // button number
100 } J;
101 uint16_t Key;
102} KEYDEF;
103
104enum { ANALOG_XP = 0, ANALOG_XM, ANALOG_YP, ANALOG_YM };
105
106typedef struct tagPadDef {
107 int8_t DevNum;
108 uint16_t Type;
109 KEYDEF KeyDef[DKEY_TOTAL];
110 KEYDEF AnalogDef[ANALOG_TOTAL][4];
111} PADDEF;
112
113typedef struct tagConfig {
114 uint8_t Threaded;
115 PADDEF PadDef[2];
116} CONFIG;
117
118typedef struct tagPadState {
119 SDL_Joystick *JoyDev;
120 uint8_t PadMode;
121 uint8_t PadID;
122 volatile uint16_t KeyStatus;
123 volatile uint16_t JoyKeyStatus;
124 volatile uint8_t AnalogStatus[ANALOG_TOTAL][2]; // 0-255 where 127 is center position
125 volatile uint8_t AnalogKeyStatus[ANALOG_TOTAL][4];
126} PADSTATE;
127
128typedef struct tagGlobalData {
129 CONFIG cfg;
130
131 uint8_t Opened;
132 Display *Disp;
133
134 PADSTATE PadState[2];
135 volatile long KeyLeftOver;
136} GLOBALDATA;
137
138extern GLOBALDATA g;
139
140enum {
141 CMD_READ_DATA_AND_VIBRATE = 0x42,
142 CMD_CONFIG_MODE = 0x43,
143 CMD_SET_MODE_AND_LOCK = 0x44,
144 CMD_QUERY_MODEL_AND_MODE = 0x45,
145 CMD_QUERY_ACT = 0x46, // ??
146 CMD_QUERY_COMB = 0x47, // ??
147 CMD_QUERY_MODE = 0x4C, // QUERY_MODE ??
148 CMD_VIBRATION_TOGGLE = 0x4D,
149};
150
151// cfg.c functions...
152void LoadPADConfig();
153void SavePADConfig();
154
155// sdljoy.c functions...
156void InitSDLJoy();
157void DestroySDLJoy();
158void CheckJoy();
159
160// xkb.c functions...
161void InitKeyboard();
162void DestroyKeyboard();
163void CheckKeyboard();
164
165// analog.c functions...
166void InitAnalog();
167void CheckAnalog();
168int AnalogKeyPressed(uint16_t Key);
169int AnalogKeyReleased(uint16_t Key);
170
171// pad.c functions...
172char *PSEgetLibName(void);
173uint32_t PSEgetLibType(void);
174uint32_t PSEgetLibVersion(void);
175long PADinit(long flags);
176long PADshutdown(void);
177long PADopen(unsigned long *Disp);
178long PADclose(void);
179long PADquery(void);
180unsigned char PADstartPoll(int pad);
181unsigned char PADpoll(unsigned char value);
182long PADreadPort1(PadDataS *pad);
183long PADreadPort2(PadDataS *pad);
184long PADkeypressed(void);
185long PADconfigure(void);
186void PADabout(void);
187long PADtest(void);
188
189#ifdef __cplusplus
190}
191#endif
192
193#endif