src/video/riscos/SDL_riscosevents.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 29 May 2006 04:04:35 +0000
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
permissions -rw-r--r--
more tweaking indent options
slouken@630
     1
/*
slouken@630
     2
    SDL - Simple DirectMedia Layer
slouken@769
     3
    Copyright (C) 1997-2004 Sam Lantinga
slouken@630
     4
slouken@630
     5
    This library is free software; you can redistribute it and/or
slouken@630
     6
    modify it under the terms of the GNU Library General Public
slouken@630
     7
    License as published by the Free Software Foundation; either
slouken@630
     8
    version 2 of the License, or (at your option) any later version.
slouken@630
     9
slouken@630
    10
    This library is distributed in the hope that it will be useful,
slouken@630
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@630
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@630
    13
    Library General Public License for more details.
slouken@630
    14
slouken@630
    15
    You should have received a copy of the GNU Library General Public
slouken@630
    16
    License along with this library; if not, write to the Free
slouken@630
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@630
    18
slouken@630
    19
    Sam Lantinga
slouken@1312
    20
    slouken@libsdl.org
slouken@630
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@630
    23
slouken@630
    24
/*
slouken@1035
    25
     File added by Alan Buckley (alan_baa@hotmail.com) for RISC OS compatability
slouken@630
    26
	 27 March 2003
slouken@630
    27
slouken@630
    28
     Implements keyboard setup, event pump and keyboard and mouse polling
slouken@630
    29
*/
slouken@630
    30
slouken@630
    31
slouken@630
    32
#include "SDL.h"
slouken@1361
    33
#include "../../timer/SDL_timer_c.h"
slouken@1361
    34
#include "../../events/SDL_sysevents.h"
slouken@1361
    35
#include "../../events/SDL_events_c.h"
slouken@1361
    36
#include "../SDL_cursor_c.h"
slouken@630
    37
#include "SDL_riscosvideo.h"
slouken@630
    38
#include "SDL_riscosevents_c.h"
slouken@630
    39
slouken@630
    40
#include "memory.h"
slouken@630
    41
#include "stdlib.h"
slouken@630
    42
#include "ctype.h"
slouken@630
    43
slouken@630
    44
#include "kernel.h"
slouken@630
    45
#include "swis.h"
slouken@630
    46
slouken@1035
    47
/* The translation table from a RISC OS internal key numbers to a SDL keysym */
slouken@630
    48
static SDLKey RO_keymap[SDLK_LAST];
slouken@630
    49
slouken@1035
    50
/* RISC OS Key codes */
slouken@630
    51
#define ROKEY_SHIFT 0
slouken@630
    52
#define ROKEY_CTRL  1
slouken@630
    53
#define ROKEY_ALT   2
slouken@630
    54
/* Left shift is first key we will check for */
slouken@630
    55
#define ROKEY_LEFT_SHIFT 3
slouken@630
    56
slouken@630
    57
/* Need to ignore mouse buttons as they are processed separately */
slouken@630
    58
#define ROKEY_LEFT_MOUSE   9
slouken@630
    59
#define ROKEY_CENTRE_MOUSE 10
slouken@630
    60
#define ROKEY_RIGHT_MOUSE  11
slouken@630
    61
slouken@630
    62
/* No key has been pressed return value*/
slouken@630
    63
#define ROKEY_NONE 255
slouken@630
    64
slouken@630
    65
/* Id of last key in keyboard */
slouken@630
    66
#define ROKEY_LAST_KEY  124
slouken@630
    67
slouken@630
    68
/* Size of array for all keys */
slouken@630
    69
#define ROKEYBD_ARRAYSIZE 125
slouken@630
    70
slouken@630
    71
static char RO_pressed[ROKEYBD_ARRAYSIZE];
slouken@630
    72
slouken@1668
    73
static SDL_keysym *TranslateKey(int intkey, SDL_keysym * keysym, int pressed);
slouken@630
    74
slouken@1668
    75
void RISCOS_PollMouse(_THIS);
slouken@1668
    76
void RISCOS_PollKeyboard();
slouken@630
    77
slouken@1668
    78
void RISCOS_PollMouseHelper(_THIS, int fullscreen);
slouken@630
    79
slouken@1361
    80
#if SDL_THREADS_DISABLED
slouken@1668
    81
extern void DRenderer_FillBuffers();
slouken@630
    82
slouken@630
    83
/* Timer running function */
slouken@1668
    84
extern void RISCOS_CheckTimer();
slouken@630
    85
slouken@955
    86
#endif
slouken@955
    87
slouken@1662
    88
void
slouken@1668
    89
FULLSCREEN_PumpEvents(_THIS)
slouken@630
    90
{
slouken@630
    91
    /* Current implementation requires keyboard and mouse polling */
slouken@1668
    92
    RISCOS_PollKeyboard();
slouken@1668
    93
    RISCOS_PollMouse(this);
slouken@1361
    94
#if SDL_THREADS_DISABLED
slouken@1662
    95
//      DRenderer_FillBuffers();
slouken@1662
    96
    if (SDL_timer_running)
slouken@1668
    97
        RISCOS_CheckTimer();
slouken@955
    98
#endif
slouken@630
    99
}
slouken@630
   100
slouken@630
   101
slouken@1662
   102
void
slouken@1668
   103
RISCOS_InitOSKeymap(_THIS)
slouken@630
   104
{
slouken@1662
   105
    int i;
slouken@630
   106
slouken@1662
   107
    /* Map the VK keysyms */
slouken@1668
   108
    for (i = 0; i < SDL_arraysize(RO_keymap); ++i)
slouken@1662
   109
        RO_keymap[i] = SDLK_UNKNOWN;
slouken@630
   110
slouken@1662
   111
    RO_keymap[3] = SDLK_LSHIFT;
slouken@1662
   112
    RO_keymap[4] = SDLK_LCTRL;
slouken@1662
   113
    RO_keymap[5] = SDLK_LALT;
slouken@1662
   114
    RO_keymap[6] = SDLK_RSHIFT;
slouken@1662
   115
    RO_keymap[7] = SDLK_RCTRL;
slouken@1662
   116
    RO_keymap[8] = SDLK_RALT;
slouken@1662
   117
    RO_keymap[16] = SDLK_q;
slouken@1662
   118
    RO_keymap[17] = SDLK_3;
slouken@1662
   119
    RO_keymap[18] = SDLK_4;
slouken@1662
   120
    RO_keymap[19] = SDLK_5;
slouken@1662
   121
    RO_keymap[20] = SDLK_F4;
slouken@1662
   122
    RO_keymap[21] = SDLK_8;
slouken@1662
   123
    RO_keymap[22] = SDLK_F7;
slouken@1662
   124
    RO_keymap[23] = SDLK_MINUS, RO_keymap[25] = SDLK_LEFT;
slouken@1662
   125
    RO_keymap[26] = SDLK_KP6;
slouken@1662
   126
    RO_keymap[27] = SDLK_KP7;
slouken@1662
   127
    RO_keymap[28] = SDLK_F11;
slouken@1662
   128
    RO_keymap[29] = SDLK_F12;
slouken@1662
   129
    RO_keymap[30] = SDLK_F10;
slouken@1662
   130
    RO_keymap[31] = SDLK_SCROLLOCK;
slouken@1662
   131
    RO_keymap[32] = SDLK_PRINT;
slouken@1662
   132
    RO_keymap[33] = SDLK_w;
slouken@1662
   133
    RO_keymap[34] = SDLK_e;
slouken@1662
   134
    RO_keymap[35] = SDLK_t;
slouken@1662
   135
    RO_keymap[36] = SDLK_7;
slouken@1662
   136
    RO_keymap[37] = SDLK_i;
slouken@1662
   137
    RO_keymap[38] = SDLK_9;
slouken@1662
   138
    RO_keymap[39] = SDLK_0;
slouken@1662
   139
    RO_keymap[41] = SDLK_DOWN;
slouken@1662
   140
    RO_keymap[42] = SDLK_KP8;
slouken@1662
   141
    RO_keymap[43] = SDLK_KP9;
slouken@1662
   142
    RO_keymap[44] = SDLK_BREAK;
slouken@1662
   143
    RO_keymap[45] = SDLK_BACKQUOTE;
slouken@630
   144
/*  RO_keymap[46] = SDLK_currency; TODO: Figure out if this has a value */
slouken@1662
   145
    RO_keymap[47] = SDLK_BACKSPACE;
slouken@1662
   146
    RO_keymap[48] = SDLK_1;
slouken@1662
   147
    RO_keymap[49] = SDLK_2;
slouken@1662
   148
    RO_keymap[50] = SDLK_d;
slouken@1662
   149
    RO_keymap[51] = SDLK_r;
slouken@1662
   150
    RO_keymap[52] = SDLK_6;
slouken@1662
   151
    RO_keymap[53] = SDLK_u;
slouken@1662
   152
    RO_keymap[54] = SDLK_o;
slouken@1662
   153
    RO_keymap[55] = SDLK_p;
slouken@1662
   154
    RO_keymap[56] = SDLK_LEFTBRACKET;
slouken@1662
   155
    RO_keymap[57] = SDLK_UP;
slouken@1662
   156
    RO_keymap[58] = SDLK_KP_PLUS;
slouken@1662
   157
    RO_keymap[59] = SDLK_KP_MINUS;
slouken@1662
   158
    RO_keymap[60] = SDLK_KP_ENTER;
slouken@1662
   159
    RO_keymap[61] = SDLK_INSERT;
slouken@1662
   160
    RO_keymap[62] = SDLK_HOME;
slouken@1662
   161
    RO_keymap[63] = SDLK_PAGEUP;
slouken@1662
   162
    RO_keymap[64] = SDLK_CAPSLOCK;
slouken@1662
   163
    RO_keymap[65] = SDLK_a;
slouken@1662
   164
    RO_keymap[66] = SDLK_x;
slouken@1662
   165
    RO_keymap[67] = SDLK_f;
slouken@1662
   166
    RO_keymap[68] = SDLK_y;
slouken@1662
   167
    RO_keymap[69] = SDLK_j;
slouken@1662
   168
    RO_keymap[70] = SDLK_k;
slouken@1662
   169
    RO_keymap[72] = SDLK_SEMICOLON;
slouken@1662
   170
    RO_keymap[73] = SDLK_RETURN;
slouken@1662
   171
    RO_keymap[74] = SDLK_KP_DIVIDE;
slouken@1662
   172
    RO_keymap[76] = SDLK_KP_PERIOD;
slouken@1662
   173
    RO_keymap[77] = SDLK_NUMLOCK;
slouken@1662
   174
    RO_keymap[78] = SDLK_PAGEDOWN;
slouken@1662
   175
    RO_keymap[79] = SDLK_QUOTE;
slouken@1662
   176
    RO_keymap[81] = SDLK_s;
slouken@1662
   177
    RO_keymap[82] = SDLK_c;
slouken@1662
   178
    RO_keymap[83] = SDLK_g;
slouken@1662
   179
    RO_keymap[84] = SDLK_h;
slouken@1662
   180
    RO_keymap[85] = SDLK_n;
slouken@1662
   181
    RO_keymap[86] = SDLK_l;
slouken@1662
   182
    RO_keymap[87] = SDLK_SEMICOLON;
slouken@1662
   183
    RO_keymap[88] = SDLK_RIGHTBRACKET;
slouken@1662
   184
    RO_keymap[89] = SDLK_DELETE;
slouken@1662
   185
    RO_keymap[90] = SDLK_KP_MINUS;
slouken@1662
   186
    RO_keymap[91] = SDLK_KP_MULTIPLY;
slouken@1662
   187
    RO_keymap[93] = SDLK_EQUALS;
slouken@1662
   188
    RO_keymap[94] = SDLK_BACKSLASH;
slouken@1662
   189
    RO_keymap[96] = SDLK_TAB;
slouken@1662
   190
    RO_keymap[97] = SDLK_z;
slouken@1662
   191
    RO_keymap[98] = SDLK_SPACE;
slouken@1662
   192
    RO_keymap[99] = SDLK_v;
slouken@1662
   193
    RO_keymap[100] = SDLK_b;
slouken@1662
   194
    RO_keymap[101] = SDLK_m;
slouken@1662
   195
    RO_keymap[102] = SDLK_COMMA;
slouken@1662
   196
    RO_keymap[103] = SDLK_PERIOD;
slouken@1662
   197
    RO_keymap[104] = SDLK_SLASH;
slouken@1662
   198
    RO_keymap[105] = SDLK_END;
slouken@1662
   199
    RO_keymap[106] = SDLK_KP0;
slouken@1662
   200
    RO_keymap[107] = SDLK_KP1;
slouken@1662
   201
    RO_keymap[108] = SDLK_KP3;
slouken@1662
   202
    RO_keymap[112] = SDLK_ESCAPE;
slouken@1662
   203
    RO_keymap[113] = SDLK_F1;
slouken@1662
   204
    RO_keymap[114] = SDLK_F2;
slouken@1662
   205
    RO_keymap[115] = SDLK_F3;
slouken@1662
   206
    RO_keymap[116] = SDLK_F5;
slouken@1662
   207
    RO_keymap[117] = SDLK_F6;
slouken@1662
   208
    RO_keymap[118] = SDLK_F8;
slouken@1662
   209
    RO_keymap[119] = SDLK_F9;
slouken@1662
   210
    RO_keymap[120] = SDLK_HASH;
slouken@1662
   211
    RO_keymap[121] = SDLK_RIGHT;
slouken@1662
   212
    RO_keymap[122] = SDLK_KP4;
slouken@1662
   213
    RO_keymap[123] = SDLK_KP5;
slouken@1662
   214
    RO_keymap[124] = SDLK_KP2;
slouken@630
   215
slouken@1668
   216
    SDL_memset(RO_pressed, 0, ROKEYBD_ARRAYSIZE);
slouken@630
   217
}
slouken@630
   218
slouken@630
   219
slouken@630
   220
/* Variable for mouse relative processing */
slouken@630
   221
int mouse_relative = 0;
slouken@630
   222
slouken@630
   223
/* Check to see if we need to enter or leave mouse relative mode */
slouken@630
   224
slouken@1662
   225
void
slouken@1668
   226
RISCOS_CheckMouseMode(_THIS)
slouken@630
   227
{
slouken@630
   228
    /* If the mouse is hidden and input is grabbed, we use relative mode */
slouken@1662
   229
    if (!(SDL_cursorstate & CURSOR_VISIBLE) &&
slouken@1662
   230
        (this->input_grab != SDL_GRAB_OFF)) {
slouken@1662
   231
        mouse_relative = 1;
slouken@1662
   232
    } else {
slouken@1662
   233
        mouse_relative = 0;
slouken@1662
   234
    }
slouken@630
   235
}
slouken@630
   236
slouken@630
   237
slouken@1662
   238
void
slouken@1668
   239
RISCOS_PollMouse(_THIS)
slouken@630
   240
{
slouken@1668
   241
    RISCOS_PollMouseHelper(this, 1);
slouken@630
   242
}
slouken@630
   243
slouken@630
   244
extern int mouseInWindow;
slouken@630
   245
slouken@1662
   246
void
slouken@1668
   247
WIMP_PollMouse(_THIS)
slouken@630
   248
{
slouken@1662
   249
    /* Only poll when mouse is over the window */
slouken@1662
   250
    if (!mouseInWindow)
slouken@1662
   251
        return;
slouken@630
   252
slouken@1668
   253
    RISCOS_PollMouseHelper(this, 0);
slouken@630
   254
}
slouken@630
   255
slouken@630
   256
/* Static variables so only changes are reported */
slouken@630
   257
static Sint16 last_x = -1, last_y = -1;
slouken@630
   258
static int last_buttons = 0;
slouken@630
   259
slouken@630
   260
/* Share routine between WIMP and FULLSCREEN for polling mouse and
slouken@630
   261
   passing on events */
slouken@1662
   262
void
slouken@1668
   263
RISCOS_PollMouseHelper(_THIS, int fullscreen)
slouken@630
   264
{
slouken@630
   265
    _kernel_swi_regs regs;
slouken@630
   266
    static int starting = 1;
slouken@630
   267
slouken@1668
   268
    if (_kernel_swi(OS_Mouse, &regs, &regs) == NULL) {
slouken@1662
   269
        Sint16 new_x = regs.r[0];       /* Initialy get as OS units */
slouken@1662
   270
        Sint16 new_y = regs.r[1];
slouken@630
   271
slouken@1662
   272
        /* Discard mouse events until they let go of the mouse after starting */
slouken@1662
   273
        if (starting && regs.r[2] != 0)
slouken@1662
   274
            return;
slouken@1662
   275
        else
slouken@1662
   276
            starting = 0;
slouken@630
   277
slouken@1662
   278
        if (new_x != last_x || new_y != last_y || last_buttons != regs.r[2]) {
slouken@1662
   279
            /* Something changed so generate appropriate events */
slouken@1662
   280
            int topLeftX, topLeftY;     /* Top left OS units */
slouken@1662
   281
            int x, y;           /* Mouse position in SDL pixels */
slouken@630
   282
slouken@1662
   283
            if (fullscreen) {
slouken@1662
   284
                topLeftX = 0;
slouken@1662
   285
                topLeftY = (this->hidden->height << this->hidden->yeig) - 1;
slouken@1662
   286
            } else {
slouken@1662
   287
                int window_state[9];
slouken@630
   288
slouken@1662
   289
                /* Get current window state */
slouken@1662
   290
                window_state[0] = this->hidden->window_handle;
slouken@1662
   291
                regs.r[1] = (unsigned int) window_state;
slouken@1668
   292
                _kernel_swi(Wimp_GetWindowState, &regs, &regs);
slouken@630
   293
slouken@1662
   294
                topLeftX = window_state[1];
slouken@1662
   295
                topLeftY = window_state[4];
slouken@1662
   296
            }
slouken@630
   297
slouken@1662
   298
            /* Convert co-ordinates to workspace */
slouken@1662
   299
            x = new_x - topLeftX;
slouken@1662
   300
            y = topLeftY - new_y;       /* Y goes from top of window/screen */
slouken@630
   301
slouken@1662
   302
            /* Convert OS units to pixels */
slouken@1662
   303
            x >>= this->hidden->xeig;
slouken@1662
   304
            y >>= this->hidden->yeig;
slouken@630
   305
slouken@1662
   306
            if (last_x != new_x || last_y != new_y) {
slouken@1662
   307
                if (mouse_relative) {
slouken@1662
   308
                    int centre_x = SDL_VideoSurface->w / 2;
slouken@1662
   309
                    int centre_y = SDL_VideoSurface->h / 2;
slouken@630
   310
slouken@1662
   311
                    if (centre_x != x || centre_y != y) {
slouken@1662
   312
                        if (SDL_VideoSurface)
slouken@1668
   313
                            SDL_PrivateMouseMotion(0, 1,
slouken@1668
   314
                                                   x - centre_x,
slouken@1668
   315
                                                   y - centre_y);
slouken@1662
   316
                        last_x = topLeftX + (centre_x << this->hidden->xeig);
slouken@1662
   317
                        last_y = topLeftY - (centre_y << this->hidden->yeig);
slouken@630
   318
slouken@1662
   319
                        /* Re-centre the mouse pointer, so we still get relative
slouken@1662
   320
                           movement when the mouse is at the edge of the window
slouken@1662
   321
                           or screen.
slouken@1662
   322
                         */
slouken@1662
   323
                        {
slouken@1662
   324
                            unsigned char block[5];
slouken@630
   325
slouken@1662
   326
                            block[0] = 3;       /* OSWORD move pointer sub-reason code */
slouken@1662
   327
                            block[1] = last_x & 0xFF;
slouken@1662
   328
                            block[2] = (last_x >> 8) & 0xFF;
slouken@1662
   329
                            block[3] = last_y & 0xFF;
slouken@1662
   330
                            block[4] = (last_y >> 8) & 0xFF;
slouken@1662
   331
slouken@1662
   332
                            regs.r[0] = 21;     /* OSWORD pointer stuff code */
slouken@1662
   333
                            regs.r[1] = (int) block;
slouken@1668
   334
                            _kernel_swi(OS_Word, &regs, &regs);
slouken@1662
   335
                        }
slouken@1662
   336
                    }
slouken@1662
   337
                } else {
slouken@1662
   338
                    last_x = new_x;
slouken@1662
   339
                    last_y = new_y;
slouken@1668
   340
                    SDL_PrivateMouseMotion(0, 0, x, y);
slouken@630
   341
                }
slouken@1662
   342
            }
slouken@630
   343
slouken@1662
   344
            if (last_buttons != regs.r[2]) {
slouken@1662
   345
                int changed = last_buttons ^ regs.r[2];
slouken@1662
   346
                last_buttons = regs.r[2];
slouken@1662
   347
                if (changed & 4)
slouken@1668
   348
                    SDL_PrivateMouseButton((last_buttons & 4) ?
slouken@1668
   349
                                           SDL_PRESSED : SDL_RELEASED,
slouken@1668
   350
                                           SDL_BUTTON_LEFT, 0, 0);
slouken@1662
   351
                if (changed & 2)
slouken@1668
   352
                    SDL_PrivateMouseButton((last_buttons & 2) ?
slouken@1668
   353
                                           SDL_PRESSED : SDL_RELEASED,
slouken@1668
   354
                                           SDL_BUTTON_MIDDLE, 0, 0);
slouken@1662
   355
                if (changed & 1)
slouken@1668
   356
                    SDL_PrivateMouseButton((last_buttons & 1) ?
slouken@1668
   357
                                           SDL_PRESSED : SDL_RELEASED,
slouken@1668
   358
                                           SDL_BUTTON_RIGHT, 0, 0);
slouken@1662
   359
            }
slouken@1662
   360
        }
slouken@630
   361
    }
slouken@630
   362
}
slouken@630
   363
slouken@1662
   364
void
slouken@1668
   365
RISCOS_PollKeyboard()
slouken@630
   366
{
slouken@1662
   367
    int which_key = ROKEY_LEFT_SHIFT;
slouken@1662
   368
    int j;
slouken@1662
   369
    int min_key, max_key;
slouken@1662
   370
    SDL_keysym key;
slouken@630
   371
slouken@1662
   372
    /* Scan the keyboard to see what is pressed */
slouken@1662
   373
    while (which_key <= ROKEY_LAST_KEY) {
slouken@1668
   374
        which_key = (_kernel_osbyte(121, which_key, 0) & 0xFF);
slouken@1662
   375
        if (which_key != ROKEY_NONE) {
slouken@1662
   376
            switch (which_key) {
slouken@1662
   377
                /* Skip over mouse keys */
slouken@1662
   378
            case ROKEY_LEFT_MOUSE:
slouken@1662
   379
            case ROKEY_CENTRE_MOUSE:
slouken@1662
   380
            case ROKEY_RIGHT_MOUSE:
slouken@1662
   381
                which_key = ROKEY_RIGHT_MOUSE;
slouken@1662
   382
                break;
slouken@630
   383
slouken@1662
   384
                /* Ignore keys that cause 2 internal number to be generated */
slouken@1662
   385
            case 71:
slouken@1662
   386
            case 24:
slouken@1662
   387
            case 87:
slouken@1662
   388
            case 40:
slouken@1662
   389
                break;
slouken@630
   390
slouken@1662
   391
                /* Ignore break as it can be latched on */
slouken@733
   392
            case 44:
slouken@733
   393
                break;
slouken@733
   394
slouken@1662
   395
            default:
slouken@1662
   396
                RO_pressed[which_key] += 2;
slouken@1662
   397
                break;
slouken@1662
   398
            }
slouken@1662
   399
            which_key++;
slouken@1662
   400
        }
slouken@1662
   401
    }
slouken@630
   402
slouken@1662
   403
    /* Generate key released messages */
slouken@1662
   404
    min_key = ROKEY_LAST_KEY + 1;
slouken@1662
   405
    max_key = ROKEY_LEFT_SHIFT;
slouken@630
   406
slouken@1662
   407
    for (j = ROKEY_LEFT_SHIFT; j <= ROKEY_LAST_KEY; j++) {
slouken@1662
   408
        if (RO_pressed[j]) {
slouken@1662
   409
            if (RO_pressed[j] == 1) {
slouken@1662
   410
                RO_pressed[j] = 0;
slouken@1668
   411
                SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(j, &key, 0));
slouken@1662
   412
            } else {
slouken@1662
   413
                if (j < min_key)
slouken@1662
   414
                    min_key = j;
slouken@1662
   415
                if (j > max_key)
slouken@1662
   416
                    max_key = j;
slouken@1662
   417
            }
slouken@1662
   418
        }
slouken@1662
   419
    }
slouken@630
   420
slouken@1662
   421
    /* Generate key pressed messages */
slouken@1662
   422
    for (j = min_key; j <= max_key; j++) {
slouken@1662
   423
        if (RO_pressed[j]) {
slouken@1662
   424
            if (RO_pressed[j] == 2) {
slouken@1668
   425
                SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(j, &key, 1));
slouken@1662
   426
            }
slouken@1662
   427
            RO_pressed[j] = 1;
slouken@1662
   428
        }
slouken@1662
   429
    }
slouken@630
   430
}
slouken@630
   431
slouken@1662
   432
static SDL_keysym *
slouken@1668
   433
TranslateKey(int intkey, SDL_keysym * keysym, int pressed)
slouken@630
   434
{
slouken@1662
   435
    /* Set the keysym information */
slouken@1662
   436
    keysym->scancode = (unsigned char) intkey;
slouken@1662
   437
    keysym->sym = RO_keymap[intkey];
slouken@1662
   438
    keysym->mod = KMOD_NONE;
slouken@1662
   439
    keysym->unicode = 0;
slouken@1662
   440
    if (pressed && SDL_TranslateUNICODE) {
slouken@1662
   441
        int state;
slouken@1662
   442
        int ch;
slouken@630
   443
slouken@1668
   444
        state = (_kernel_osbyte(202, 0, 255) & 0xFF);
slouken@630
   445
slouken@1662
   446
        /*TODO: Take into account other keyboard layouts */
slouken@630
   447
slouken@1662
   448
        ch = keysym->sym;       /* This should handle most unshifted keys */
slouken@630
   449
slouken@1662
   450
        if (intkey < 9 || ch == SDLK_UNKNOWN) {
slouken@1662
   451
            ch = 0;
slouken@630
   452
slouken@1662
   453
        } else if (state & 64) {        /* Control on */
slouken@1662
   454
            ch = ch & 31;
slouken@630
   455
slouken@1662
   456
        } else {
slouken@1662
   457
            int topOfKey = 0;
slouken@1662
   458
            if (state & 8) {    /* Shift on */
slouken@1662
   459
                topOfKey = 1;
slouken@1662
   460
            }
slouken@733
   461
slouken@1662
   462
            if ((state & 16) == 0) {    /* Caps lock is on */
slouken@1662
   463
                if (ch >= SDLK_a && ch <= SDLK_z) {
slouken@1662
   464
                    if ((state & 128) == 0) {   /* Shift Enable off */
slouken@1662
   465
                        /* All letter become upper case */
slouken@1662
   466
                        topOfKey = 1;
slouken@1662
   467
                    } else {
slouken@1662
   468
                        /* Shift+Letters gives lower case */
slouken@1662
   469
                        topOfKey = 1 - topOfKey;
slouken@1662
   470
                    }
slouken@1662
   471
                }
slouken@1662
   472
            }
slouken@733
   473
slouken@1662
   474
            if (topOfKey) {
slouken@1662
   475
                /* Key produced with shift held down */
slouken@733
   476
slouken@1662
   477
                /* Letters just give upper case version */
slouken@1662
   478
                if (ch >= SDLK_a && ch <= SDLK_z)
slouken@1668
   479
                    ch = toupper(ch);
slouken@1662
   480
                else {
slouken@1662
   481
                    switch (ch) {
slouken@1662
   482
                    case SDLK_HASH:
slouken@1662
   483
                        ch = '~';
slouken@1662
   484
                        break;
slouken@1662
   485
                    case SDLK_QUOTE:
slouken@1662
   486
                        ch = '@';
slouken@1662
   487
                        break;
slouken@1662
   488
                    case SDLK_COMMA:
slouken@1662
   489
                        ch = '<';
slouken@1662
   490
                        break;
slouken@1662
   491
                    case SDLK_MINUS:
slouken@1662
   492
                        ch = '_';
slouken@1662
   493
                        break;
slouken@1662
   494
                    case SDLK_PERIOD:
slouken@1662
   495
                        ch = '>';
slouken@1662
   496
                        break;
slouken@1662
   497
                    case SDLK_SLASH:
slouken@1662
   498
                        ch = '?';
slouken@1662
   499
                        break;
slouken@733
   500
slouken@1662
   501
                    case SDLK_0:
slouken@1662
   502
                        ch = ')';
slouken@1662
   503
                        break;
slouken@1662
   504
                    case SDLK_1:
slouken@1662
   505
                        ch = '!';
slouken@1662
   506
                        break;
slouken@1662
   507
                    case SDLK_2:
slouken@1662
   508
                        ch = '"';
slouken@1662
   509
                        break;
slouken@1662
   510
                    case SDLK_3:
slouken@1662
   511
                        ch = '';
slouken@1662
   512
                        break;
slouken@1662
   513
                    case SDLK_4:
slouken@1662
   514
                        ch = '$';
slouken@1662
   515
                        break;
slouken@1662
   516
                    case SDLK_5:
slouken@1662
   517
                        ch = '%';
slouken@1662
   518
                        break;
slouken@1662
   519
                    case SDLK_6:
slouken@1662
   520
                        ch = '^';
slouken@1662
   521
                        break;
slouken@1662
   522
                    case SDLK_7:
slouken@1662
   523
                        ch = '&';
slouken@1662
   524
                        break;
slouken@1662
   525
                    case SDLK_8:
slouken@1662
   526
                        ch = '*';
slouken@1662
   527
                        break;
slouken@1662
   528
                    case SDLK_9:
slouken@1662
   529
                        ch = '(';
slouken@1662
   530
                        break;
slouken@733
   531
slouken@1662
   532
                    case SDLK_SEMICOLON:
slouken@1662
   533
                        ch = ':';
slouken@1662
   534
                        break;
slouken@1662
   535
                    case SDLK_EQUALS:
slouken@1662
   536
                        ch = '+';
slouken@1662
   537
                        break;
slouken@1662
   538
                    case SDLK_LEFTBRACKET:
slouken@1662
   539
                        ch = '{';
slouken@1662
   540
                        break;
slouken@1662
   541
                    case SDLK_BACKSLASH:
slouken@1662
   542
                        ch = '|';
slouken@1662
   543
                        break;
slouken@1662
   544
                    case SDLK_RIGHTBRACKET:
slouken@1662
   545
                        ch = '}';
slouken@1662
   546
                        break;
slouken@1662
   547
                    case SDLK_BACKQUOTE:
slouken@1662
   548
                        ch = '';
slouken@1662
   549
                        break;
slouken@733
   550
slouken@1662
   551
                    default:
slouken@1662
   552
                        ch = 0; /* Map to zero character if we don't understand it */
slouken@1662
   553
                        break;
slouken@1662
   554
                    }
slouken@1662
   555
                }
slouken@733
   556
slouken@1662
   557
            } else if (ch > 126) {
slouken@1662
   558
                /* SDL key code < 126 map directly onto their Unicode equivalents */
slouken@1662
   559
                /* Keypad 0 to 9 maps to numeric equivalent */
slouken@1662
   560
                if (ch >= SDLK_KP0 && ch <= SDLK_KP9)
slouken@1662
   561
                    ch = ch - SDLK_KP0 + '0';
slouken@1662
   562
                else {
slouken@1662
   563
                    /* Following switch maps other keys that produce an Ascii value */
slouken@1662
   564
                    switch (ch) {
slouken@1662
   565
                    case SDLK_KP_PERIOD:
slouken@1662
   566
                        ch = '.';
slouken@1662
   567
                        break;
slouken@1662
   568
                    case SDLK_KP_DIVIDE:
slouken@1662
   569
                        ch = '/';
slouken@1662
   570
                        break;
slouken@1662
   571
                    case SDLK_KP_MULTIPLY:
slouken@1662
   572
                        ch = '*';
slouken@1662
   573
                        break;
slouken@1662
   574
                    case SDLK_KP_MINUS:
slouken@1662
   575
                        ch = '-';
slouken@1662
   576
                        break;
slouken@1662
   577
                    case SDLK_KP_PLUS:
slouken@1662
   578
                        ch = '+';
slouken@1662
   579
                        break;
slouken@1662
   580
                    case SDLK_KP_EQUALS:
slouken@1662
   581
                        ch = '=';
slouken@1662
   582
                        break;
slouken@733
   583
slouken@1662
   584
                    default:
slouken@1662
   585
                        /* If we don't know what it is set the Unicode to 0 */
slouken@1662
   586
                        ch = 0;
slouken@1662
   587
                        break;
slouken@1662
   588
                    }
slouken@1662
   589
                }
slouken@1662
   590
            }
slouken@1662
   591
        }
slouken@1662
   592
slouken@1662
   593
        keysym->unicode = ch;
slouken@1662
   594
    }
slouken@1662
   595
    return (keysym);
slouken@630
   596
}
slouken@630
   597
slouken@630
   598
/* end of SDL_riscosevents.c ... */
slouken@1662
   599
/* vi: set ts=4 sw=4 expandtab: */