src/video/psp/SDL_pspevents.c
author Sam Lantinga
Fri, 27 Jan 2017 21:23:27 -0800
changeset 10861 71d8f9afb690
parent 10737 3406a0f8b041
child 10945 1300a3135d61
permissions -rw-r--r--
Fixed bug 3569 - GL_UpdateViewport leaves PROJECTION matrix selected

Tom Seddon

GL_ActivateRenderer may call GL_UpdateViewport, which leaves the GL_PROJECTION matrix selected. But after GL_ResetState, the GL_MODELVIEW matrix is selected, suggesting that's the intended default state.

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