-
Notifications
You must be signed in to change notification settings - Fork 17
/
input.cpp
261 lines (227 loc) · 6.03 KB
/
input.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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
// input.cpp: implementation of the input class.
//
//////////////////////////////////////////////////////////////////////
//Flavor - Convert from DirectInput to SDL/GP2X
#ifndef __GP32__
#include "StdAfx.h"
#endif
#include "main.h"
#include "input.h"
#include "memory.h"
///#include "menu.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
// address where the state of the input device(s) is stored
//unsigned char *InputByte = get_address(0x00006F82);
unsigned char ngpInputState = 0;
unsigned char *InputByte = &ngpInputState;
#ifndef TARGET_PSP
extern SDL_Joystick *joystick;
#endif
#ifdef ZOOM_SUPPORT
extern int zoom;
#endif
#ifdef __GP32__
#define DIK_UP BUTTON_UP
#define DIK_DOWN BUTTON_DOWN
#define DIK_LEFT BUTTON_LEFT
#define DIK_RIGHT BUTTON_RIGHT
#define DIK_SPACE BUTTON_A
#define DIK_N BUTTON_B
#define DIK_S BUTTON_SELECT
#define DIK_O BUTTON_START
#else
#define DIK_UP SDLK_UP
#define DIK_DOWN SDLK_DOWN
#define DIK_LEFT SDLK_LEFT
#define DIK_RIGHT SDLK_RIGHT
#define DIK_SPACE SDLK_a
#define DIK_N SDLK_b
#define DIK_S SDLK_ESCAPE
#define DIK_O SDLK_SPACE
#endif
#define DOWN(x) keystates[x]
#ifdef __GP32__
u16 keystates = 0;
#else
Uint8 *keystates = NULL;
#endif
struct joy_range
{
int minx, maxx, miny, maxy;
} range;
#ifdef __GP32__
void InitInput()
#else
BOOL InitInput(HWND hwnd)
#endif
{
#ifndef TARGET_PSP
#ifndef __GP32__
keystates = PSP_GetKeyStateArray(NULL);
#endif
// setup standard values for input
// NGP/NGPC:
m_sysInfo[NGP].InputKeys[KEY_UP] = DIK_UP;
m_sysInfo[NGP].InputKeys[KEY_DOWN] = DIK_DOWN;
m_sysInfo[NGP].InputKeys[KEY_LEFT] = DIK_LEFT;
m_sysInfo[NGP].InputKeys[KEY_RIGHT] = DIK_RIGHT;
m_sysInfo[NGP].InputKeys[KEY_BUTTON_A] = DIK_SPACE;
m_sysInfo[NGP].InputKeys[KEY_BUTTON_B] = DIK_N;
m_sysInfo[NGP].InputKeys[KEY_SELECT] = DIK_O; // Option button
m_sysInfo[NGPC].InputKeys[KEY_UP] = DIK_UP;
m_sysInfo[NGPC].InputKeys[KEY_DOWN] = DIK_DOWN;
m_sysInfo[NGPC].InputKeys[KEY_LEFT] = DIK_LEFT;
m_sysInfo[NGPC].InputKeys[KEY_RIGHT] = DIK_RIGHT;
m_sysInfo[NGPC].InputKeys[KEY_BUTTON_A] = DIK_SPACE;
m_sysInfo[NGPC].InputKeys[KEY_BUTTON_B] = DIK_N;
m_sysInfo[NGPC].InputKeys[KEY_SELECT] = DIK_O; // Option button
range.minx = -32767;//INT_MIN;
range.maxx = 32767;//INT_MAX;
range.miny = -32767;//INT_MIN;
range.maxy = 32767;//INT_MAX;
#endif /* TARGET_PSP */
return TRUE;
}
#ifdef __GP32__
extern "C"
{
int gp_getButton();
void clearScreen();
}
int zoom=0,zoomy=16;
#endif
#ifndef TARGET_PSP
void UpdateInputState()
{
#ifdef __GP32__
int key = gp_getButton();
if ((key & BUTTON_R) && (key & BUTTON_L))
{
m_bIsActive = FALSE;//Flavor exit emulation
return;
}
if (key & BUTTON_R) {
zoom ^= 1;
while ((key=gp_getButton())&BUTTON_R);
if (!zoom)
clearScreen();
}
if (key & BUTTON_L) {
if (key & BUTTON_DOWN) {
if (zoomy<32)
zoomy+=1;
return;
}
if (key & BUTTON_UP) {
if (zoomy>0)
zoomy-=1;
return;
}
}
if(key & BUTTON_DOWN)
*InputByte = 0x02;
else if(key & BUTTON_UP)
*InputByte = 0x01;
else
*InputByte = 0;
if(key & BUTTON_RIGHT)
*InputByte |= 0x08;
else if(key & BUTTON_LEFT)
*InputByte |= 0x04;
if (key & BUTTON_A)
*InputByte|= 0x10;
if (key & BUTTON_B)
*InputByte|= 0x20;
if (key & BUTTON_SELECT)
*InputByte|= 0x40;
#else
SDL_Event event;
#ifdef TARGET_PSP
while(SDL_PollEvent(&event))
{
}
if (SDL_JoystickGetButton(joystick, PSP_BUTTON_R) && SDL_JoystickGetButton(joystick, PSP_BUTTON_L))
{
m_bIsActive = FALSE;//Flavor exit emulation
return;
}
int x_axis = SDL_JoystickGetAxis (joystick, 0);
int y_axis = SDL_JoystickGetAxis (joystick, 1);
/* if (x_axis < range.minx) range.minx = x_axis;
if (y_axis < range.miny) range.miny = y_axis;
if (x_axis > range.maxx) range.maxx = x_axis;
if (y_axis > range.maxy) range.maxy = y_axis;
*/
*InputByte = 0;
if(SDL_JoystickGetButton(joystick, PSP_BUTTON_DOWN) || (y_axis > (range.miny + 2*(range.maxy - range.miny)/3)))
{
*InputByte |= 0x02;
}
if(SDL_JoystickGetButton(joystick, PSP_BUTTON_UP) || (y_axis < (range.miny + (range.maxy - range.miny)/3)))
{
*InputByte |= 0x01;
}
if(SDL_JoystickGetButton(joystick, PSP_BUTTON_RIGHT) || (x_axis > (range.minx + 2*(range.maxx - range.minx)/3)))
{
*InputByte |= 0x08;
}
if(SDL_JoystickGetButton(joystick, PSP_BUTTON_LEFT) || (x_axis < (range.minx + (range.maxx - range.minx)/3)))
{
*InputByte |= 0x04;
}
if (SDL_JoystickGetButton(joystick, PSP_BUTTON_X))
*InputByte |= 0x10;
if (SDL_JoystickGetButton(joystick, PSP_BUTTON_O))
*InputByte |= 0x20;
if (SDL_JoystickGetButton(joystick, PSP_BUTTON_TRI))
*InputByte |= 0x40;
/* no variable zoom for now
#ifdef ZOOM_SUPPORT
if(SDL_JoystickGetButton(joystick, PSP_BUTTON_R) && zoom<60)//272-152=120/2=60
zoom++;
if(SDL_JoystickGetButton(joystick, PSP_BUTTON_L) && zoom>0)
zoom--;
#endif*/
/*if (SDL_JoystickGetButton(joystick, PSP_BUTTON_VOLUP))
increaseVolume();
else if (SDL_JoystickGetButton(joystick, PSP_BUTTON_VOLDOWN))
decreaseVolume();*/
#else
SYSTEMINFO *si;
PSP_SetKeyStates(); //make sure they're updated
while(SDL_PollEvent(&event))
{
}
if (DOWN(SDLK_r) && DOWN(SDLK_l))
m_bIsActive = FALSE;//Flavor exit emulation
si = &m_sysInfo[NGP];
*InputByte = 0;
if (DOWN(si->InputKeys[KEY_BUTTON_A]))
*InputByte|= 0x10;
if (DOWN(si->InputKeys[KEY_BUTTON_B]))
*InputByte|= 0x20;
if (DOWN(si->InputKeys[KEY_SELECT]))
*InputByte|= 0x40;
if (DOWN(si->InputKeys[KEY_UP]))
*InputByte|= 0x01;
if (DOWN(si->InputKeys[KEY_DOWN]))
*InputByte|= 0x02;
if (DOWN(si->InputKeys[KEY_LEFT]))
*InputByte|= 0x04;
if (DOWN(si->InputKeys[KEY_RIGHT]))
*InputByte|= 0x08;
if (DOWN(SDLK_KP_PLUS))
increaseVolume();
else if (DOWN(SDLK_KP_MINUS))
decreaseVolume();
#endif
#endif
}
#endif /* TARGET_PSP */
void FreeInput()
{
}