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 
44 static int irkbd_ready = 0;
45 static SDL_Keycode keymap[256];
46 #endif
47 
48 static enum PspHprmKeys hprm = 0;
49 static SDL_sem *event_sem = NULL;
50 static SDL_Thread *thread = NULL;
51 static int running = 0;
52 static 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 
64 int 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) ?
103  SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap_psp[i].sym));
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 
249 void 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 
273 void 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: */
SDL.h
SDLK_KP_MINUS
@ SDLK_KP_MINUS
Definition: SDL_keycode.h:159
SDLK_F6
@ SDLK_F6
Definition: SDL_keycode.h:134
SDLK_F5
@ SDLK_F5
Definition: SDL_keycode.h:133
SDLK_x
@ SDLK_x
Definition: SDL_keycode.h:123
SDLK_UNKNOWN
@ SDLK_UNKNOWN
Definition: SDL_keycode.h:52
SDLK_j
@ SDLK_j
Definition: SDL_keycode.h:109
SDLK_8
@ SDLK_8
Definition: SDL_keycode.h:82
SDLK_2
@ SDLK_2
Definition: SDL_keycode.h:76
SDLK_RALT
@ SDLK_RALT
Definition: SDL_keycode.h:282
SDL_CreateSemaphore
#define SDL_CreateSemaphore
Definition: SDL_dynapi_overrides.h:264
SDLK_u
@ SDLK_u
Definition: SDL_keycode.h:120
SDLK_e
@ SDLK_e
Definition: SDL_keycode.h:104
SDLK_6
@ SDLK_6
Definition: SDL_keycode.h:80
NULL
#define NULL
Definition: begin_code.h:167
SDLK_LSHIFT
@ SDLK_LSHIFT
Definition: SDL_keycode.h:277
SDLK_F7
@ SDLK_F7
Definition: SDL_keycode.h:135
SDLK_F8
@ SDLK_F8
Definition: SDL_keycode.h:136
SDL_Keysym::scancode
SDL_Scancode scancode
Definition: SDL_keyboard.h:49
SDLK_PAUSE
@ SDLK_PAUSE
Definition: SDL_keycode.h:144
SDLK_KP_MULTIPLY
@ SDLK_KP_MULTIPLY
Definition: SDL_keycode.h:158
SDLK_F9
@ SDLK_F9
Definition: SDL_keycode.h:137
SDLK_t
@ SDLK_t
Definition: SDL_keycode.h:119
SDLK_f
@ SDLK_f
Definition: SDL_keycode.h:105
SDLK_9
@ SDLK_9
Definition: SDL_keycode.h:83
count
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
SDL_keyboard.h
SDLK_F3
@ SDLK_F3
Definition: SDL_keycode.h:131
SDLK_F11
@ SDLK_F11
Definition: SDL_keycode.h:139
SDLK_DOWN
@ SDLK_DOWN
Definition: SDL_keycode.h:153
SDLK_RIGHTBRACKET
@ SDLK_RIGHTBRACKET
Definition: SDL_keycode.h:96
SDL_pspevents_c.h
SDLK_KP_PLUS
@ SDLK_KP_PLUS
Definition: SDL_keycode.h:160
SDLK_UP
@ SDLK_UP
Definition: SDL_keycode.h:154
SDLK_KP_DIVIDE
@ SDLK_KP_DIVIDE
Definition: SDL_keycode.h:157
SDLK_F15
@ SDLK_F15
Definition: SDL_keycode.h:179
SDL_Thread
Definition: SDL_thread_c.h:54
SDL_RELEASED
#define SDL_RELEASED
Definition: SDL_events.h:49
SDL_Keycode
Sint32 SDL_Keycode
The SDL virtual key representation.
Definition: SDL_keycode.h:45
length
GLuint GLsizei GLsizei * length
Definition: SDL_opengl_glext.h:669
SDLK_LEFT
@ SDLK_LEFT
Definition: SDL_keycode.h:152
SDL_SendKeyboardKey
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:679
SDL_SemPost
#define SDL_SemPost
Definition: SDL_dynapi_overrides.h:269
SDLK_m
@ SDLK_m
Definition: SDL_keycode.h:112
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
SDLK_QUOTE
@ SDLK_QUOTE
Definition: SDL_keycode.h:65
SDLK_KP_EQUALS
@ SDLK_KP_EQUALS
Definition: SDL_keycode.h:176
SDLK_w
@ SDLK_w
Definition: SDL_keycode.h:122
SDL_GetScancodeFromKey
#define SDL_GetScancodeFromKey
Definition: SDL_dynapi_overrides.h:221
SDLK_v
@ SDLK_v
Definition: SDL_keycode.h:121
SDLK_l
@ SDLK_l
Definition: SDL_keycode.h:111
SDLK_ESCAPE
@ SDLK_ESCAPE
Definition: SDL_keycode.h:55
SDLK_g
@ SDLK_g
Definition: SDL_keycode.h:106
SDLK_7
@ SDLK_7
Definition: SDL_keycode.h:81
SDL_PRESSED
#define SDL_PRESSED
Definition: SDL_events.h:50
SDLK_F1
@ SDLK_F1
Definition: SDL_keycode.h:129
SDLK_COMMA
@ SDLK_COMMA
Definition: SDL_keycode.h:70
buffer
GLuint buffer
Definition: SDL_opengl_glext.h:533
SDLK_4
@ SDLK_4
Definition: SDL_keycode.h:78
SDLK_F13
@ SDLK_F13
Definition: SDL_keycode.h:177
SDLK_p
@ SDLK_p
Definition: SDL_keycode.h:115
SDL_CreateThreadInternal
SDL_Thread * SDL_CreateThreadInternal(int(*fn)(void *), const char *name, const size_t stacksize, void *data)
Definition: SDL_thread.c:429
SDLK_F10
@ SDLK_F10
Definition: SDL_keycode.h:138
SDLK_INSERT
@ SDLK_INSERT
Definition: SDL_keycode.h:145
SDLK_F14
@ SDLK_F14
Definition: SDL_keycode.h:178
PSP_InitOSKeymap
void PSP_InitOSKeymap(_THIS)
SDLK_SPACE
@ SDLK_SPACE
Definition: SDL_keycode.h:58
PSP_PumpEvents
void PSP_PumpEvents(_THIS)
SDLK_z
@ SDLK_z
Definition: SDL_keycode.h:125
SDLK_q
@ SDLK_q
Definition: SDL_keycode.h:116
SDLK_BACKQUOTE
@ SDLK_BACKQUOTE
Definition: SDL_keycode.h:99
SDLK_a
@ SDLK_a
Definition: SDL_keycode.h:100
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
SDLK_h
@ SDLK_h
Definition: SDL_keycode.h:107
SDLK_0
@ SDLK_0
Definition: SDL_keycode.h:74
SDLK_END
@ SDLK_END
Definition: SDL_keycode.h:149
SDLK_SLASH
@ SDLK_SLASH
Definition: SDL_keycode.h:73
SDLK_BACKSPACE
@ SDLK_BACKSPACE
Definition: SDL_keycode.h:56
id
GLuint id
Definition: SDL_opengl_glext.h:528
SDLK_DELETE
@ SDLK_DELETE
Definition: SDL_keycode.h:148
SDLK_BACKSLASH
@ SDLK_BACKSLASH
Definition: SDL_keycode.h:95
SDLK_PERIOD
@ SDLK_PERIOD
Definition: SDL_keycode.h:72
SDLK_i
@ SDLK_i
Definition: SDL_keycode.h:108
SDLK_d
@ SDLK_d
Definition: SDL_keycode.h:103
SDLK_RCTRL
@ SDLK_RCTRL
Definition: SDL_keycode.h:280
SDLK_KP_PERIOD
@ SDLK_KP_PERIOD
Definition: SDL_keycode.h:172
SDLK_RETURN
@ SDLK_RETURN
Definition: SDL_keycode.h:54
SDLK_MINUS
@ SDLK_MINUS
Definition: SDL_keycode.h:71
SDLK_LEFTBRACKET
@ SDLK_LEFTBRACKET
Definition: SDL_keycode.h:94
SDL_SemWait
#define SDL_SemWait
Definition: SDL_dynapi_overrides.h:266
SDLK_F4
@ SDLK_F4
Definition: SDL_keycode.h:132
SDL_TABLESIZE
#define SDL_TABLESIZE(table)
Definition: SDL_stdinc.h:116
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
SDLK_RSHIFT
@ SDLK_RSHIFT
Definition: SDL_keycode.h:281
SDL_Keysym::sym
SDL_Keycode sym
Definition: SDL_keyboard.h:50
SDL_pspvideo.h
SDL_Keysym
The SDL keysym structure, used in key events.
Definition: SDL_keyboard.h:47
SDLK_EQUALS
@ SDLK_EQUALS
Definition: SDL_keycode.h:87
SDLK_TAB
@ SDLK_TAB
Definition: SDL_keycode.h:57
SDLK_c
@ SDLK_c
Definition: SDL_keycode.h:102
SDL_DestroySemaphore
#define SDL_DestroySemaphore
Definition: SDL_dynapi_overrides.h:265
SDLK_k
@ SDLK_k
Definition: SDL_keycode.h:110
SDLK_5
@ SDLK_5
Definition: SDL_keycode.h:79
SDLK_CAPSLOCK
@ SDLK_CAPSLOCK
Definition: SDL_keycode.h:127
SDLK_RIGHT
@ SDLK_RIGHT
Definition: SDL_keycode.h:151
SDLK_F12
@ SDLK_F12
Definition: SDL_keycode.h:140
SDLK_3
@ SDLK_3
Definition: SDL_keycode.h:77
SDLK_o
@ SDLK_o
Definition: SDL_keycode.h:114
SDLK_LALT
@ SDLK_LALT
Definition: SDL_keycode.h:278
SDLK_s
@ SDLK_s
Definition: SDL_keycode.h:118
SDLK_HOME
@ SDLK_HOME
Definition: SDL_keycode.h:146
SDLK_r
@ SDLK_r
Definition: SDL_keycode.h:117
SDLK_F2
@ SDLK_F2
Definition: SDL_keycode.h:130
SDLK_LCTRL
@ SDLK_LCTRL
Definition: SDL_keycode.h:276
i
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
SDLK_1
@ SDLK_1
Definition: SDL_keycode.h:75
SDL_WaitThread
#define SDL_WaitThread
Definition: SDL_dynapi_overrides.h:478
SDLK_b
@ SDLK_b
Definition: SDL_keycode.h:101
SDLK_y
@ SDLK_y
Definition: SDL_keycode.h:124
SDLK_SEMICOLON
@ SDLK_SEMICOLON
Definition: SDL_keycode.h:85
SDLK_n
@ SDLK_n
Definition: SDL_keycode.h:113