src/video/riscos/SDL_riscosevents.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 17 Sep 2004 13:20:10 +0000
changeset 955 d74fbf56f2f6
parent 769 b8d311d90021
child 1035 974ba6ae0fa3
permissions -rw-r--r--
Date: Fri, 25 Jun 2004 13:29:15 +0100
From: "alan buckley"
Subject: Modification for RISC OS version of SDL

Ive attached a zip file with the changes to this email, it contains the
following:

The file sdldiff.txt is the output from cvs diff u. .
The directory thread/riscos contains all the new files to support threading.

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