zenilib: zenilib/jni/external/sdl/src/video/psp/SDL_pspevents.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_pspevents.c
Go to the documentation of this file.
1 /*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20 */
21
22 /* Being a null driver, there's no event stream. We just define stubs for
23 most of the API. */
24
25 #include "SDL.h"
26 #include "../../events/SDL_sysevents.h"
27 #include "../../events/SDL_events_c.h"
28 #include "../../events/SDL_keyboard_c.h"
29 #include "SDL_pspvideo.h"
30 #include "SDL_pspevents_c.h"
31 #include "SDL_thread.h"
32 #include "SDL_keyboard.h"
33 #include <psphprm.h>
34
35 #ifdef PSPIRKEYB
36 #include <pspirkeyb.h>
37 #include <pspirkeyb_rawkeys.h>
38
39 #define IRKBD_CONFIG_FILE NULL /* this will take ms0:/seplugins/pspirkeyb.ini */
40
41 static int irkbd_ready = 0;
42 static SDLKey keymap[256];
43 #endif
44
45 static enum PspHprmKeys hprm = 0;
46 static SDL_sem *event_sem = NULL;
47 static SDL_Thread *thread = NULL;
48 static int running = 0;
49 static struct {
50 enum PspHprmKeys id;
51 SDL_Keycode sym;
52 } keymap_psp[] = {
53 { PSP_HPRM_PLAYPAUSE, SDLK_F10 },
54 { PSP_HPRM_FORWARD, SDLK_F11 },
55 { PSP_HPRM_BACK, SDLK_F12 },
56 { PSP_HPRM_VOL_UP, SDLK_F13 },
57 { PSP_HPRM_VOL_DOWN, SDLK_F14 },
58 { PSP_HPRM_HOLD, SDLK_F15 }
59 };
60
61 int EventUpdate(void *data)
62 {
63 while (running) {
64 SDL_SemWait(event_sem);
65 sceHprmPeekCurrentKey(&hprm);
66 SDL_SemPost(event_sem);
67 /* Delay 1/60th of a second */
68 sceKernelDelayThread(1000000 / 60);
69 }
70 return 0;
71 }
72
73 void PSP_PumpEvents(_THIS)
74 {
75 int i;
76 enum PspHprmKeys keys;
77 enum PspHprmKeys changed;
78 static enum PspHprmKeys old_keys = 0;
79 SDL_Keysym sym;
80
81 SDL_SemWait(event_sem);
82 keys = hprm;
83 SDL_SemPost(event_sem);
84
85 /* HPRM Keyboard */
86 changed = old_keys ^ keys;
87 old_keys = keys;
88 if(changed) {
89 for(i=0; i<sizeof(keymap_psp)/sizeof(keymap_psp[0]); i++) {
90 if(changed & keymap_psp[i].id) {
91 sym.scancode = keymap_psp[i].id;
92 sym.sym = keymap_psp[i].sym;
93
94 /* out of date
95 SDL_PrivateKeyboard((keys & keymap_psp[i].id) ?
96 SDL_PRESSED : SDL_RELEASED,
97 &sym);
98 */
99 SDL_SendKeyboardKey((keys & keymap_psp[i].id) ?
100 SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap_psp[i].sym));
101 }
102 }
103 }
104
105 #ifdef PSPIRKEYB
106 if (irkbd_ready) {
107 unsigned char buffer[255];
108 int i, length, count;
109 SIrKeybScanCodeData *scanData;
110
111 if(pspIrKeybReadinput(buffer, &length) >= 0) {
112 if((length % sizeof(SIrKeybScanCodeData)) == 0){
113 count = length / sizeof(SIrKeybScanCodeData);
114 for( i=0; i < count; i++ ) {
115 unsigned char raw, pressed;
116 scanData=(SIrKeybScanCodeData*) buffer+i;
117 raw = scanData->raw;
118 pressed = scanData->pressed;
119 sym.scancode = raw;
120 sym.sym = keymap[raw];
121 /* not tested */
122 /* SDL_PrivateKeyboard(pressed?SDL_PRESSED:SDL_RELEASED, &sym); */
123 SDL_SendKeyboardKey((keys & keymap_psp[i].id) ?
124 SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap[raw]);
125
126 }
127 }
128 }
129 }
130 #endif
131 sceKernelDelayThread(0);
132
133 return;
134 }
135
136 void PSP_InitOSKeymap(_THIS)
137 {
138 #ifdef PSPIRKEYB
139 int i;
140 for (i=0; i<SDL_TABLESIZE(keymap); ++i)
141 keymap[i] = SDLK_UNKNOWN;
142
143 keymap[KEY_ESC] = SDLK_ESCAPE;
144
145 keymap[KEY_F1] = SDLK_F1;
146 keymap[KEY_F2] = SDLK_F2;
147 keymap[KEY_F3] = SDLK_F3;
148 keymap[KEY_F4] = SDLK_F4;
149 keymap[KEY_F5] = SDLK_F5;
150 keymap[KEY_F6] = SDLK_F6;
151 keymap[KEY_F7] = SDLK_F7;
152 keymap[KEY_F8] = SDLK_F8;
153 keymap[KEY_F9] = SDLK_F9;
154 keymap[KEY_F10] = SDLK_F10;
155 keymap[KEY_F11] = SDLK_F11;
156 keymap[KEY_F12] = SDLK_F12;
157 keymap[KEY_F13] = SDLK_PRINT;
158 keymap[KEY_F14] = SDLK_PAUSE;
159
160 keymap[KEY_GRAVE] = SDLK_BACKQUOTE;
161 keymap[KEY_1] = SDLK_1;
162 keymap[KEY_2] = SDLK_2;
163 keymap[KEY_3] = SDLK_3;
164 keymap[KEY_4] = SDLK_4;
165 keymap[KEY_5] = SDLK_5;
166 keymap[KEY_6] = SDLK_6;
167 keymap[KEY_7] = SDLK_7;
168 keymap[KEY_8] = SDLK_8;
169 keymap[KEY_9] = SDLK_9;
170 keymap[KEY_0] = SDLK_0;
171 keymap[KEY_MINUS] = SDLK_MINUS;
172 keymap[KEY_EQUAL] = SDLK_EQUALS;
173 keymap[KEY_BACKSPACE] = SDLK_BACKSPACE;
174
175 keymap[KEY_TAB] = SDLK_TAB;
176 keymap[KEY_Q] = SDLK_q;
177 keymap[KEY_W] = SDLK_w;
178 keymap[KEY_E] = SDLK_e;
179 keymap[KEY_R] = SDLK_r;
180 keymap[KEY_T] = SDLK_t;
181 keymap[KEY_Y] = SDLK_y;
182 keymap[KEY_U] = SDLK_u;
183 keymap[KEY_I] = SDLK_i;
184 keymap[KEY_O] = SDLK_o;
185 keymap[KEY_P] = SDLK_p;
186 keymap[KEY_LEFTBRACE] = SDLK_LEFTBRACKET;
187 keymap[KEY_RIGHTBRACE] = SDLK_RIGHTBRACKET;
188 keymap[KEY_ENTER] = SDLK_RETURN;
189
190 keymap[KEY_CAPSLOCK] = SDLK_CAPSLOCK;
191 keymap[KEY_A] = SDLK_a;
192 keymap[KEY_S] = SDLK_s;
193 keymap[KEY_D] = SDLK_d;
194 keymap[KEY_F] = SDLK_f;
195 keymap[KEY_G] = SDLK_g;
196 keymap[KEY_H] = SDLK_h;
197 keymap[KEY_J] = SDLK_j;
198 keymap[KEY_K] = SDLK_k;
199 keymap[KEY_L] = SDLK_l;
200 keymap[KEY_SEMICOLON] = SDLK_SEMICOLON;
201 keymap[KEY_APOSTROPHE] = SDLK_QUOTE;
202 keymap[KEY_BACKSLASH] = SDLK_BACKSLASH;
203
204 keymap[KEY_Z] = SDLK_z;
205 keymap[KEY_X] = SDLK_x;
206 keymap[KEY_C] = SDLK_c;
207 keymap[KEY_V] = SDLK_v;
208 keymap[KEY_B] = SDLK_b;
209 keymap[KEY_N] = SDLK_n;
210 keymap[KEY_M] = SDLK_m;
211 keymap[KEY_COMMA] = SDLK_COMMA;
212 keymap[KEY_DOT] = SDLK_PERIOD;
213 keymap[KEY_SLASH] = SDLK_SLASH;
214
215 keymap[KEY_SPACE] = SDLK_SPACE;
216
217 keymap[KEY_UP] = SDLK_UP;
218 keymap[KEY_DOWN] = SDLK_DOWN;
219 keymap[KEY_LEFT] = SDLK_LEFT;
220 keymap[KEY_RIGHT] = SDLK_RIGHT;
221
222 keymap[KEY_HOME] = SDLK_HOME;
223 keymap[KEY_END] = SDLK_END;
224 keymap[KEY_INSERT] = SDLK_INSERT;
225 keymap[KEY_DELETE] = SDLK_DELETE;
226
227 keymap[KEY_NUMLOCK] = SDLK_NUMLOCK;
228 keymap[KEY_LEFTMETA] = SDLK_LSUPER;
229
230 keymap[KEY_KPSLASH] = SDLK_KP_DIVIDE;
231 keymap[KEY_KPASTERISK] = SDLK_KP_MULTIPLY;
232 keymap[KEY_KPMINUS] = SDLK_KP_MINUS;
233 keymap[KEY_KPPLUS] = SDLK_KP_PLUS;
234 keymap[KEY_KPDOT] = SDLK_KP_PERIOD;
235 keymap[KEY_KPEQUAL] = SDLK_KP_EQUALS;
236
237 keymap[KEY_LEFTCTRL] = SDLK_LCTRL;
238 keymap[KEY_RIGHTCTRL] = SDLK_RCTRL;
239 keymap[KEY_LEFTALT] = SDLK_LALT;
240 keymap[KEY_RIGHTALT] = SDLK_RALT;
241 keymap[KEY_LEFTSHIFT] = SDLK_LSHIFT;
242 keymap[KEY_RIGHTSHIFT] = SDLK_RSHIFT;
243 #endif
244 }
245
246 void PSP_EventInit(_THIS)
247 {
248 #ifdef PSPIRKEYB
249 int outputmode = PSP_IRKBD_OUTPUT_MODE_SCANCODE;
250 int ret = pspIrKeybInit(IRKBD_CONFIG_FILE, 0);
251 if (ret == PSP_IRKBD_RESULT_OK) {
252 pspIrKeybOutputMode(outputmode);
253 irkbd_ready = 1;
254 } else {
255 irkbd_ready = 0;
256 }
257 #endif
258 /* Start thread to read data */
259 if((event_sem = SDL_CreateSemaphore(1)) == NULL) {
260 SDL_SetError("Can't create input semaphore\n");
261 return;
262 }
263 running = 1;
264 if((thread = SDL_CreateThread(EventUpdate, "PSPInputThread",NULL)) == NULL) {
265 SDL_SetError("Can't create input thread\n");
266 return;
267 }
268 }
269
270 void PSP_EventQuit(_THIS)
271 {
272 running = 0;
273 SDL_WaitThread(thread, NULL);
274 SDL_DestroySemaphore(event_sem);
275 #ifdef PSPIRKEYB
276 if (irkbd_ready) {
277 pspIrKeybFinish();
278 irkbd_ready = 0;
279 }
280 #endif
281 }
282
283 /* end of SDL_pspevents.c ... */
284
SDL_CreateSemaphore
DECLSPEC SDL_sem *SDLCALL SDL_CreateSemaphore(Uint32 initial_value)
Definition: SDL_syssem.c:85
SDLK_F13
Definition: SDL_keycode.h:174
SDLK_f
Definition: SDL_keycode.h:102
EventUpdate
int EventUpdate(void *data)
Definition: SDL_pspevents.c:61
SDLK_KP_EQUALS
Definition: SDL_keycode.h:173
SDLK_EQUALS
Definition: SDL_keycode.h:84
SDLK_KP_MULTIPLY
Definition: SDL_keycode.h:155
SDLK_2
Definition: SDL_keycode.h:73
SDL_pspevents_c.h
SDLK_F3
Definition: SDL_keycode.h:128
SDLK_F15
Definition: SDL_keycode.h:176
SDLK_1
Definition: SDL_keycode.h:72
SDLK_RCTRL
Definition: SDL_keycode.h:277
SDLK_F8
Definition: SDL_keycode.h:133
SDLK_F9
Definition: SDL_keycode.h:134
SDLK_LSHIFT
Definition: SDL_keycode.h:274
SDLK_j
Definition: SDL_keycode.h:106
SDLK_o
Definition: SDL_keycode.h:111
SDL_sem
struct SDL_semaphore SDL_sem
Definition: SDL_mutex.h:107
NULL
#define NULL
Definition: ftobjs.h:61
SDLK_DELETE
Definition: SDL_keycode.h:145
SDLK_SLASH
Definition: SDL_keycode.h:70
SDL_SemWait
DECLSPEC int SDLCALL SDL_SemWait(SDL_sem *sem)
Definition: SDL_syssem.c:180
SDLK_F2
Definition: SDL_keycode.h:127
event_sem
static SDL_sem * event_sem
Definition: SDL_pspevents.c:46
SDLK_BACKSPACE
Definition: SDL_keycode.h:53
SDLK_z
Definition: SDL_keycode.h:122
sym
SDL_Keycode sym
Definition: SDL_pspevents.c:51
SDLK_d
Definition: SDL_keycode.h:100
SDLK_3
Definition: SDL_keycode.h:74
SDLK_8
Definition: SDL_keycode.h:79
SDLK_6
Definition: SDL_keycode.h:77
thread
static SDL_Thread * thread
Definition: SDL_pspevents.c:47
SDL_Keysym::scancode
SDL_Scancode scancode
Definition: SDL_keyboard.h:49
SDLK_F1
Definition: SDL_keycode.h:126
SDL_Keysym
The SDL keysym structure, used in key events.
Definition: SDL_keyboard.h:47
SDLK_l
Definition: SDL_keycode.h:108
SDLK_SEMICOLON
Definition: SDL_keycode.h:82
running
static int running
Definition: SDL_pspevents.c:48
SDLK_s
Definition: SDL_keycode.h:115
SDLK_KP_PLUS
Definition: SDL_keycode.h:157
PSP_EventQuit
void PSP_EventQuit(_THIS)
Definition: SDL_pspevents.c:270
id
GLuint id
Definition: gl2ext.h:1142
SDLK_F6
Definition: SDL_keycode.h:131
SDLK_BACKQUOTE
Definition: SDL_keycode.h:96
SDL_Keycode
Sint32 SDL_Keycode
The SDL virtual key representation.
Definition: SDL_keycode.h:42
SDLK_a
Definition: SDL_keycode.h:97
SDLK_g
Definition: SDL_keycode.h:103
SDLK_e
Definition: SDL_keycode.h:101
SDLK_0
Definition: SDL_keycode.h:71
SDLK_LEFT
Definition: SDL_keycode.h:149
ret
ret
Definition: glew_str_glx.c:2
SDLK_PERIOD
Definition: SDL_keycode.h:69
SDLK_n
Definition: SDL_keycode.h:110
SDLK_c
Definition: SDL_keycode.h:99
SDL_SendKeyboardKey
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:650
SDLK_CAPSLOCK
Definition: SDL_keycode.h:124
SDLK_END
Definition: SDL_keycode.h:146
SDLK_UNKNOWN
Definition: SDL_keycode.h:49
SDLK_i
Definition: SDL_keycode.h:105
SDLK_ESCAPE
Definition: SDL_keycode.h:52
SDL_WaitThread
DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread *thread, int *status)
Definition: SDL_thread.c:399
buffer
EGLContext EGLenum EGLClientBuffer buffer
Definition: eglext.h:87
SDLK_HOME
Definition: SDL_keycode.h:143
SDLK_RETURN
Definition: SDL_keycode.h:51
SDLK_k
Definition: SDL_keycode.h:107
SDLK_COMMA
Definition: SDL_keycode.h:67
SDLK_RSHIFT
Definition: SDL_keycode.h:278
SDLK_4
Definition: SDL_keycode.h:75
length
GLsizei GLsizei * length
Definition: gl2ext.h:792
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
SDLK_KP_DIVIDE
Definition: SDL_keycode.h:154
SDLK_7
Definition: SDL_keycode.h:78
SDL_pspvideo.h
SDLK_F12
Definition: SDL_keycode.h:137
count
GLint GLsizei count
Definition: gl2ext.h:1011
SDLK_m
Definition: SDL_keycode.h:109
SDLK_BACKSLASH
Definition: SDL_keycode.h:92
SDLK_u
Definition: SDL_keycode.h:117
SDLK_h
Definition: SDL_keycode.h:104
SDLK_LALT
Definition: SDL_keycode.h:275
SDL_GetScancodeFromKey
DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromKey(SDL_Keycode key)
Get the scancode corresponding to the given key code according to the current keyboard layout...
Definition: SDL_keyboard.c:872
SDL_SetError
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
Definition: SDL_error.c:53
keymap_psp
static struct @85 keymap_psp[]
SDLK_KP_PERIOD
Definition: SDL_keycode.h:169
PSP_EventInit
void PSP_EventInit(_THIS)
Definition: SDL_pspevents.c:246
SDLK_MINUS
Definition: SDL_keycode.h:68
SDLK_RIGHTBRACKET
Definition: SDL_keycode.h:93
SDL_DestroySemaphore
DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem)
Definition: SDL_syssem.c:111
SDL_CreateThread
DECLSPEC SDL_Thread *SDLCALL SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data)
SDLK_DOWN
Definition: SDL_keycode.h:150
SDLK_SPACE
Definition: SDL_keycode.h:55
SDLK_F11
Definition: SDL_keycode.h:136
SDLK_KP_MINUS
Definition: SDL_keycode.h:156
SDLK_r
Definition: SDL_keycode.h:114
SDLK_LCTRL
Definition: SDL_keycode.h:273
SDLK_w
Definition: SDL_keycode.h:119
SDLK_UP
Definition: SDL_keycode.h:151
SDLK_9
Definition: SDL_keycode.h:80
SDLK_F10
Definition: SDL_keycode.h:135
SDLK_RALT
Definition: SDL_keycode.h:279
SDL_keyboard.h
SDL_TABLESIZE
#define SDL_TABLESIZE(table)
Definition: SDL_stdinc.h:84
SDLK_QUOTE
Definition: SDL_keycode.h:62
SDL_Keysym::sym
SDL_Keycode sym
Definition: SDL_keyboard.h:50
SDLK_q
Definition: SDL_keycode.h:113
SDLK_5
Definition: SDL_keycode.h:76
PSP_PumpEvents
void PSP_PumpEvents(_THIS)
Definition: SDL_pspevents.c:73
SDL_Thread
Definition: SDL_thread_c.h:48
SDLK_LEFTBRACKET
Definition: SDL_keycode.h:91
SDLK_v
Definition: SDL_keycode.h:118
SDLK_F5
Definition: SDL_keycode.h:130
PSP_InitOSKeymap
void PSP_InitOSKeymap(_THIS)
Definition: SDL_pspevents.c:136
SDLK_F4
Definition: SDL_keycode.h:129
SDLK_F7
Definition: SDL_keycode.h:132
SDL_PRESSED
#define SDL_PRESSED
Definition: SDL_events.h:50
i
int i
Definition: pngrutil.c:1377
SDLK_x
Definition: SDL_keycode.h:120
SDLK_p
Definition: SDL_keycode.h:112
SDLK_TAB
Definition: SDL_keycode.h:54
SDL_RELEASED
#define SDL_RELEASED
Definition: SDL_events.h:49
SDL_SemPost
DECLSPEC int SDLCALL SDL_SemPost(SDL_sem *sem)
Definition: SDL_syssem.c:200
SDLK_RIGHT
Definition: SDL_keycode.h:148
SDLK_t
Definition: SDL_keycode.h:116
SDLK_INSERT
Definition: SDL_keycode.h:142
hprm
static enum PspHprmKeys hprm
Definition: SDL_pspevents.c:45
SDLK_F14
Definition: SDL_keycode.h:175
SDLK_b
Definition: SDL_keycode.h:98
SDLK_y
Definition: SDL_keycode.h:121
SDLK_PAUSE
Definition: SDL_keycode.h:141