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