SDL 2.0
SDL_pspevents.c
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2019 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#include "../../SDL_internal.h"
22
23#if SDL_VIDEO_DRIVER_PSP
24
25/* Being a null driver, there's no event stream. We just define stubs for
26 most of the API. */
27
28#include "SDL.h"
29#include "../../events/SDL_sysevents.h"
30#include "../../events/SDL_events_c.h"
31#include "../../events/SDL_keyboard_c.h"
32#include "SDL_pspvideo.h"
33#include "SDL_pspevents_c.h"
34#include "SDL_keyboard.h"
35#include "../../thread/SDL_systhread.h"
36#include <psphprm.h>
37
38#ifdef PSPIRKEYB
39#include <pspirkeyb.h>
40#include <pspirkeyb_rawkeys.h>
41
42#define IRKBD_CONFIG_FILE NULL /* this will take ms0:/seplugins/pspirkeyb.ini */
43
44static int irkbd_ready = 0;
45static SDL_Keycode keymap[256];
46#endif
47
48static enum PspHprmKeys hprm = 0;
49static SDL_sem *event_sem = NULL;
50static SDL_Thread *thread = NULL;
51static int running = 0;
52static struct {
53 enum PspHprmKeys id;
54 SDL_Keycode sym;
55} keymap_psp[] = {
56 { PSP_HPRM_PLAYPAUSE, SDLK_F10 },
57 { PSP_HPRM_FORWARD, SDLK_F11 },
58 { PSP_HPRM_BACK, SDLK_F12 },
59 { PSP_HPRM_VOL_UP, SDLK_F13 },
60 { PSP_HPRM_VOL_DOWN, SDLK_F14 },
61 { PSP_HPRM_HOLD, SDLK_F15 }
62};
63
64int EventUpdate(void *data)
65{
66 while (running) {
67 SDL_SemWait(event_sem);
68 sceHprmPeekCurrentKey(&hprm);
69 SDL_SemPost(event_sem);
70 /* Delay 1/60th of a second */
71 sceKernelDelayThread(1000000 / 60);
72 }
73 return 0;
74}
75
77{
78 int i;
79 enum PspHprmKeys keys;
80 enum PspHprmKeys changed;
81 static enum PspHprmKeys old_keys = 0;
82 SDL_Keysym sym;
83
84 SDL_SemWait(event_sem);
85 keys = hprm;
86 SDL_SemPost(event_sem);
87
88 /* HPRM Keyboard */
89 changed = old_keys ^ keys;
90 old_keys = keys;
91 if(changed) {
92 for(i=0; i<sizeof(keymap_psp)/sizeof(keymap_psp[0]); i++) {
93 if(changed & keymap_psp[i].id) {
94 sym.scancode = keymap_psp[i].id;
95 sym.sym = keymap_psp[i].sym;
96
97 /* out of date
98 SDL_PrivateKeyboard((keys & keymap_psp[i].id) ?
99 SDL_PRESSED : SDL_RELEASED,
100 &sym);
101 */
102 SDL_SendKeyboardKey((keys & keymap_psp[i].id) ?
104 }
105 }
106 }
107
108#ifdef PSPIRKEYB
109 if (irkbd_ready) {
110 unsigned char buffer[255];
111 int i, length, count;
112 SIrKeybScanCodeData *scanData;
113
114 if(pspIrKeybReadinput(buffer, &length) >= 0) {
115 if((length % sizeof(SIrKeybScanCodeData)) == 0){
116 count = length / sizeof(SIrKeybScanCodeData);
117 for( i=0; i < count; i++ ) {
118 unsigned char raw, pressed;
119 scanData=(SIrKeybScanCodeData*) buffer+i;
120 raw = scanData->raw;
121 pressed = scanData->pressed;
122 sym.scancode = raw;
123 sym.sym = keymap[raw];
124 /* not tested */
125 /* SDL_PrivateKeyboard(pressed?SDL_PRESSED:SDL_RELEASED, &sym); */
126 SDL_SendKeyboardKey((keys & keymap_psp[i].id) ?
128
129 }
130 }
131 }
132 }
133#endif
134 sceKernelDelayThread(0);
135
136 return;
137}
138
140{
141#ifdef PSPIRKEYB
142 int i;
143 for (i=0; i<SDL_TABLESIZE(keymap); ++i)
144 keymap[i] = SDLK_UNKNOWN;
145
146 keymap[KEY_ESC] = SDLK_ESCAPE;
147
148 keymap[KEY_F1] = SDLK_F1;
149 keymap[KEY_F2] = SDLK_F2;
150 keymap[KEY_F3] = SDLK_F3;
151 keymap[KEY_F4] = SDLK_F4;
152 keymap[KEY_F5] = SDLK_F5;
153 keymap[KEY_F6] = SDLK_F6;
154 keymap[KEY_F7] = SDLK_F7;
155 keymap[KEY_F8] = SDLK_F8;
156 keymap[KEY_F9] = SDLK_F9;
157 keymap[KEY_F10] = SDLK_F10;
158 keymap[KEY_F11] = SDLK_F11;
159 keymap[KEY_F12] = SDLK_F12;
160 keymap[KEY_F13] = SDLK_PRINT;
161 keymap[KEY_F14] = SDLK_PAUSE;
162
163 keymap[KEY_GRAVE] = SDLK_BACKQUOTE;
164 keymap[KEY_1] = SDLK_1;
165 keymap[KEY_2] = SDLK_2;
166 keymap[KEY_3] = SDLK_3;
167 keymap[KEY_4] = SDLK_4;
168 keymap[KEY_5] = SDLK_5;
169 keymap[KEY_6] = SDLK_6;
170 keymap[KEY_7] = SDLK_7;
171 keymap[KEY_8] = SDLK_8;
172 keymap[KEY_9] = SDLK_9;
173 keymap[KEY_0] = SDLK_0;
174 keymap[KEY_MINUS] = SDLK_MINUS;
175 keymap[KEY_EQUAL] = SDLK_EQUALS;
176 keymap[KEY_BACKSPACE] = SDLK_BACKSPACE;
177
178 keymap[KEY_TAB] = SDLK_TAB;
179 keymap[KEY_Q] = SDLK_q;
180 keymap[KEY_W] = SDLK_w;
181 keymap[KEY_E] = SDLK_e;
182 keymap[KEY_R] = SDLK_r;
183 keymap[KEY_T] = SDLK_t;
184 keymap[KEY_Y] = SDLK_y;
185 keymap[KEY_U] = SDLK_u;
186 keymap[KEY_I] = SDLK_i;
187 keymap[KEY_O] = SDLK_o;
188 keymap[KEY_P] = SDLK_p;
189 keymap[KEY_LEFTBRACE] = SDLK_LEFTBRACKET;
190 keymap[KEY_RIGHTBRACE] = SDLK_RIGHTBRACKET;
191 keymap[KEY_ENTER] = SDLK_RETURN;
192
193 keymap[KEY_CAPSLOCK] = SDLK_CAPSLOCK;
194 keymap[KEY_A] = SDLK_a;
195 keymap[KEY_S] = SDLK_s;
196 keymap[KEY_D] = SDLK_d;
197 keymap[KEY_F] = SDLK_f;
198 keymap[KEY_G] = SDLK_g;
199 keymap[KEY_H] = SDLK_h;
200 keymap[KEY_J] = SDLK_j;
201 keymap[KEY_K] = SDLK_k;
202 keymap[KEY_L] = SDLK_l;
203 keymap[KEY_SEMICOLON] = SDLK_SEMICOLON;
204 keymap[KEY_APOSTROPHE] = SDLK_QUOTE;
205 keymap[KEY_BACKSLASH] = SDLK_BACKSLASH;
206
207 keymap[KEY_Z] = SDLK_z;
208 keymap[KEY_X] = SDLK_x;
209 keymap[KEY_C] = SDLK_c;
210 keymap[KEY_V] = SDLK_v;
211 keymap[KEY_B] = SDLK_b;
212 keymap[KEY_N] = SDLK_n;
213 keymap[KEY_M] = SDLK_m;
214 keymap[KEY_COMMA] = SDLK_COMMA;
215 keymap[KEY_DOT] = SDLK_PERIOD;
216 keymap[KEY_SLASH] = SDLK_SLASH;
217
218 keymap[KEY_SPACE] = SDLK_SPACE;
219
220 keymap[KEY_UP] = SDLK_UP;
221 keymap[KEY_DOWN] = SDLK_DOWN;
222 keymap[KEY_LEFT] = SDLK_LEFT;
223 keymap[KEY_RIGHT] = SDLK_RIGHT;
224
225 keymap[KEY_HOME] = SDLK_HOME;
226 keymap[KEY_END] = SDLK_END;
227 keymap[KEY_INSERT] = SDLK_INSERT;
228 keymap[KEY_DELETE] = SDLK_DELETE;
229
230 keymap[KEY_NUMLOCK] = SDLK_NUMLOCK;
231 keymap[KEY_LEFTMETA] = SDLK_LSUPER;
232
233 keymap[KEY_KPSLASH] = SDLK_KP_DIVIDE;
234 keymap[KEY_KPASTERISK] = SDLK_KP_MULTIPLY;
235 keymap[KEY_KPMINUS] = SDLK_KP_MINUS;
236 keymap[KEY_KPPLUS] = SDLK_KP_PLUS;
237 keymap[KEY_KPDOT] = SDLK_KP_PERIOD;
238 keymap[KEY_KPEQUAL] = SDLK_KP_EQUALS;
239
240 keymap[KEY_LEFTCTRL] = SDLK_LCTRL;
241 keymap[KEY_RIGHTCTRL] = SDLK_RCTRL;
242 keymap[KEY_LEFTALT] = SDLK_LALT;
243 keymap[KEY_RIGHTALT] = SDLK_RALT;
244 keymap[KEY_LEFTSHIFT] = SDLK_LSHIFT;
245 keymap[KEY_RIGHTSHIFT] = SDLK_RSHIFT;
246#endif
247}
248
249void PSP_EventInit(_THIS)
250{
251#ifdef PSPIRKEYB
252 int outputmode = PSP_IRKBD_OUTPUT_MODE_SCANCODE;
253 int ret = pspIrKeybInit(IRKBD_CONFIG_FILE, 0);
254 if (ret == PSP_IRKBD_RESULT_OK) {
255 pspIrKeybOutputMode(outputmode);
256 irkbd_ready = 1;
257 } else {
258 irkbd_ready = 0;
259 }
260#endif
261 /* Start thread to read data */
262 if((event_sem = SDL_CreateSemaphore(1)) == NULL) {
263 SDL_SetError("Can't create input semaphore");
264 return;
265 }
266 running = 1;
267 if((thread = SDL_CreateThreadInternal(EventUpdate, "PSPInputThread", 4096, NULL)) == NULL) {
268 SDL_SetError("Can't create input thread");
269 return;
270 }
271}
272
273void PSP_EventQuit(_THIS)
274{
275 running = 0;
276 SDL_WaitThread(thread, NULL);
277 SDL_DestroySemaphore(event_sem);
278#ifdef PSPIRKEYB
279 if (irkbd_ready) {
280 pspIrKeybFinish();
281 irkbd_ready = 0;
282 }
283#endif
284}
285
286/* end of SDL_pspevents.c ... */
287
288#endif /* SDL_VIDEO_DRIVER_PSP */
289
290/* vi: set ts=4 sw=4 expandtab: */
#define _THIS
#define SDL_SetError
#define SDL_SemPost
#define SDL_SemWait
#define SDL_DestroySemaphore
#define SDL_CreateSemaphore
#define SDL_WaitThread
#define SDL_GetScancodeFromKey
#define SDL_RELEASED
Definition: SDL_events.h:49
#define SDL_PRESSED
Definition: SDL_events.h:50
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:679
@ SDLK_g
Definition: SDL_keycode.h:106
@ SDLK_c
Definition: SDL_keycode.h:102
@ SDLK_RSHIFT
Definition: SDL_keycode.h:281
@ SDLK_0
Definition: SDL_keycode.h:74
@ SDLK_LALT
Definition: SDL_keycode.h:278
@ SDLK_u
Definition: SDL_keycode.h:120
@ SDLK_y
Definition: SDL_keycode.h:124
@ SDLK_BACKSPACE
Definition: SDL_keycode.h:56
@ SDLK_h
Definition: SDL_keycode.h:107
@ SDLK_a
Definition: SDL_keycode.h:100
@ SDLK_F2
Definition: SDL_keycode.h:130
@ SDLK_F12
Definition: SDL_keycode.h:140
@ SDLK_e
Definition: SDL_keycode.h:104
@ SDLK_F13
Definition: SDL_keycode.h:177
@ SDLK_EQUALS
Definition: SDL_keycode.h:87
@ SDLK_SEMICOLON
Definition: SDL_keycode.h:85
@ SDLK_F1
Definition: SDL_keycode.h:129
@ SDLK_UP
Definition: SDL_keycode.h:154
@ SDLK_END
Definition: SDL_keycode.h:149
@ SDLK_DOWN
Definition: SDL_keycode.h:153
@ SDLK_9
Definition: SDL_keycode.h:83
@ SDLK_8
Definition: SDL_keycode.h:82
@ SDLK_TAB
Definition: SDL_keycode.h:57
@ SDLK_i
Definition: SDL_keycode.h:108
@ SDLK_SLASH
Definition: SDL_keycode.h:73
@ SDLK_QUOTE
Definition: SDL_keycode.h:65
@ SDLK_j
Definition: SDL_keycode.h:109
@ SDLK_F6
Definition: SDL_keycode.h:134
@ SDLK_PERIOD
Definition: SDL_keycode.h:72
@ SDLK_n
Definition: SDL_keycode.h:113
@ SDLK_UNKNOWN
Definition: SDL_keycode.h:52
@ SDLK_5
Definition: SDL_keycode.h:79
@ SDLK_F9
Definition: SDL_keycode.h:137
@ SDLK_z
Definition: SDL_keycode.h:125
@ SDLK_F4
Definition: SDL_keycode.h:132
@ SDLK_v
Definition: SDL_keycode.h:121
@ SDLK_KP_PERIOD
Definition: SDL_keycode.h:172
@ SDLK_s
Definition: SDL_keycode.h:118
@ SDLK_KP_PLUS
Definition: SDL_keycode.h:160
@ SDLK_w
Definition: SDL_keycode.h:122
@ SDLK_k
Definition: SDL_keycode.h:110
@ SDLK_BACKQUOTE
Definition: SDL_keycode.h:99
@ SDLK_F3
Definition: SDL_keycode.h:131
@ SDLK_F10
Definition: SDL_keycode.h:138
@ SDLK_r
Definition: SDL_keycode.h:117
@ SDLK_RIGHTBRACKET
Definition: SDL_keycode.h:96
@ SDLK_COMMA
Definition: SDL_keycode.h:70
@ SDLK_LCTRL
Definition: SDL_keycode.h:276
@ SDLK_F8
Definition: SDL_keycode.h:136
@ SDLK_x
Definition: SDL_keycode.h:123
@ SDLK_F14
Definition: SDL_keycode.h:178
@ SDLK_MINUS
Definition: SDL_keycode.h:71
@ SDLK_d
Definition: SDL_keycode.h:103
@ SDLK_b
Definition: SDL_keycode.h:101
@ SDLK_HOME
Definition: SDL_keycode.h:146
@ SDLK_LEFTBRACKET
Definition: SDL_keycode.h:94
@ SDLK_F11
Definition: SDL_keycode.h:139
@ SDLK_F7
Definition: SDL_keycode.h:135
@ SDLK_t
Definition: SDL_keycode.h:119
@ SDLK_m
Definition: SDL_keycode.h:112
@ SDLK_ESCAPE
Definition: SDL_keycode.h:55
@ SDLK_KP_MINUS
Definition: SDL_keycode.h:159
@ SDLK_1
Definition: SDL_keycode.h:75
@ SDLK_SPACE
Definition: SDL_keycode.h:58
@ SDLK_F5
Definition: SDL_keycode.h:133
@ SDLK_PAUSE
Definition: SDL_keycode.h:144
@ SDLK_7
Definition: SDL_keycode.h:81
@ SDLK_LEFT
Definition: SDL_keycode.h:152
@ SDLK_DELETE
Definition: SDL_keycode.h:148
@ SDLK_LSHIFT
Definition: SDL_keycode.h:277
@ SDLK_KP_EQUALS
Definition: SDL_keycode.h:176
@ SDLK_CAPSLOCK
Definition: SDL_keycode.h:127
@ SDLK_BACKSLASH
Definition: SDL_keycode.h:95
@ SDLK_6
Definition: SDL_keycode.h:80
@ SDLK_q
Definition: SDL_keycode.h:116
@ SDLK_INSERT
Definition: SDL_keycode.h:145
@ SDLK_3
Definition: SDL_keycode.h:77
@ SDLK_p
Definition: SDL_keycode.h:115
@ SDLK_RALT
Definition: SDL_keycode.h:282
@ SDLK_RCTRL
Definition: SDL_keycode.h:280
@ SDLK_f
Definition: SDL_keycode.h:105
@ SDLK_o
Definition: SDL_keycode.h:114
@ SDLK_RIGHT
Definition: SDL_keycode.h:151
@ SDLK_F15
Definition: SDL_keycode.h:179
@ SDLK_l
Definition: SDL_keycode.h:111
@ SDLK_4
Definition: SDL_keycode.h:78
@ SDLK_RETURN
Definition: SDL_keycode.h:54
@ SDLK_KP_DIVIDE
Definition: SDL_keycode.h:157
@ SDLK_KP_MULTIPLY
Definition: SDL_keycode.h:158
@ SDLK_2
Definition: SDL_keycode.h:76
Sint32 SDL_Keycode
The SDL virtual key representation.
Definition: SDL_keycode.h:45
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
GLuint id
GLuint buffer
GLuint GLsizei GLsizei * length
void PSP_InitOSKeymap(_THIS)
void PSP_PumpEvents(_THIS)
#define SDL_TABLESIZE(table)
Definition: SDL_stdinc.h:116
SDL_Thread * SDL_CreateThreadInternal(int(*fn)(void *), const char *name, const size_t stacksize, void *data)
Definition: SDL_thread.c:429
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define NULL
Definition: begin_code.h:167
The SDL keysym structure, used in key events.
Definition: SDL_keyboard.h:48
SDL_Keycode sym
Definition: SDL_keyboard.h:50
SDL_Scancode scancode
Definition: SDL_keyboard.h:49