src/video/riscos/SDL_riscosevents.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 29 May 2003 04:44:13 +0000
changeset 630 550bccdf04bd
child 658 e71b7108d2d7
permissions -rw-r--r--
Added initial support for RISC OS (thanks Peter Naulls!)
slouken@630
     1
/*
slouken@630
     2
    SDL - Simple DirectMedia Layer
slouken@630
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001  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
slouken@630
    75
void RISCOS_PollMouse(_THIS);
slouken@630
    76
void RISCOS_PollKeyboard();
slouken@630
    77
slouken@630
    78
void RISCOS_PollMouseHelper(_THIS, int fullscreen);
slouken@630
    79
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@630
    85
void FULLSCREEN_PumpEvents(_THIS)
slouken@630
    86
{
slouken@630
    87
    /* Current implementation requires keyboard and mouse polling */
slouken@630
    88
	RISCOS_PollKeyboard();
slouken@630
    89
	RISCOS_PollMouse(this);
slouken@630
    90
	DRenderer_FillBuffers();
slouken@630
    91
	if (SDL_timer_running) RISCOS_CheckTimer();
slouken@630
    92
}
slouken@630
    93
slouken@630
    94
slouken@630
    95
void RISCOS_InitOSKeymap(_THIS)
slouken@630
    96
{
slouken@630
    97
	int i;
slouken@630
    98
slouken@630
    99
	/* Map the VK keysyms */
slouken@630
   100
	for ( i=0; i<SDL_TABLESIZE(RO_keymap); ++i )
slouken@630
   101
		RO_keymap[i] = SDLK_UNKNOWN;
slouken@630
   102
slouken@630
   103
  RO_keymap[3] = SDLK_LSHIFT;
slouken@630
   104
  RO_keymap[4] = SDLK_LCTRL;
slouken@630
   105
  RO_keymap[5] = SDLK_LALT;
slouken@630
   106
  RO_keymap[6] = SDLK_RSHIFT;
slouken@630
   107
  RO_keymap[7] = SDLK_RCTRL;
slouken@630
   108
  RO_keymap[8] = SDLK_RALT;
slouken@630
   109
  RO_keymap[16] = SDLK_q;
slouken@630
   110
  RO_keymap[17] = SDLK_3;
slouken@630
   111
  RO_keymap[18] = SDLK_4;
slouken@630
   112
  RO_keymap[19] = SDLK_5;
slouken@630
   113
  RO_keymap[20] = SDLK_F4;
slouken@630
   114
  RO_keymap[21] = SDLK_8;
slouken@630
   115
  RO_keymap[22] = SDLK_F7;
slouken@630
   116
  RO_keymap[23] = SDLK_MINUS,
slouken@630
   117
  RO_keymap[25] = SDLK_LEFT;
slouken@630
   118
  RO_keymap[26] = SDLK_KP6;
slouken@630
   119
  RO_keymap[27] = SDLK_KP7;
slouken@630
   120
  RO_keymap[28] = SDLK_F11;
slouken@630
   121
  RO_keymap[29] = SDLK_F12;
slouken@630
   122
  RO_keymap[30] = SDLK_F10;
slouken@630
   123
  RO_keymap[31] = SDLK_SCROLLOCK;
slouken@630
   124
  RO_keymap[32] = SDLK_PRINT;
slouken@630
   125
  RO_keymap[33] = SDLK_w;
slouken@630
   126
  RO_keymap[34] = SDLK_e;
slouken@630
   127
  RO_keymap[35] = SDLK_t;
slouken@630
   128
  RO_keymap[36] = SDLK_7;
slouken@630
   129
  RO_keymap[37] = SDLK_i;
slouken@630
   130
  RO_keymap[38] = SDLK_9;
slouken@630
   131
  RO_keymap[39] = SDLK_0;
slouken@630
   132
  RO_keymap[41] = SDLK_DOWN;
slouken@630
   133
  RO_keymap[42] = SDLK_KP8;
slouken@630
   134
  RO_keymap[43] = SDLK_KP9;
slouken@630
   135
  RO_keymap[44] = SDLK_BREAK;
slouken@630
   136
  RO_keymap[45] = SDLK_BACKQUOTE;
slouken@630
   137
/*  RO_keymap[46] = SDLK_currency; TODO: Figure out if this has a value */
slouken@630
   138
  RO_keymap[47] = SDLK_BACKSPACE;
slouken@630
   139
  RO_keymap[48] = SDLK_1;
slouken@630
   140
  RO_keymap[49] = SDLK_2;
slouken@630
   141
  RO_keymap[50] = SDLK_d;
slouken@630
   142
  RO_keymap[51] = SDLK_r;
slouken@630
   143
  RO_keymap[52] = SDLK_6;
slouken@630
   144
  RO_keymap[53] = SDLK_u;
slouken@630
   145
  RO_keymap[54] = SDLK_o;
slouken@630
   146
  RO_keymap[55] = SDLK_p;
slouken@630
   147
  RO_keymap[56] = SDLK_LEFTPAREN;
slouken@630
   148
  RO_keymap[57] = SDLK_UP;
slouken@630
   149
  RO_keymap[58] = SDLK_KP_PLUS;
slouken@630
   150
  RO_keymap[59] = SDLK_KP_MINUS;
slouken@630
   151
  RO_keymap[60] = SDLK_KP_ENTER;
slouken@630
   152
  RO_keymap[61] = SDLK_INSERT;
slouken@630
   153
  RO_keymap[62] = SDLK_HOME;
slouken@630
   154
  RO_keymap[63] = SDLK_PAGEUP;
slouken@630
   155
  RO_keymap[64] = SDLK_CAPSLOCK;
slouken@630
   156
  RO_keymap[65] = SDLK_a;
slouken@630
   157
  RO_keymap[66] = SDLK_x;
slouken@630
   158
  RO_keymap[67] = SDLK_f;
slouken@630
   159
  RO_keymap[68] = SDLK_y;
slouken@630
   160
  RO_keymap[69] = SDLK_j;
slouken@630
   161
  RO_keymap[70] = SDLK_k;
slouken@630
   162
  RO_keymap[72] = SDLK_SEMICOLON;
slouken@630
   163
  RO_keymap[73] = SDLK_RETURN;
slouken@630
   164
  RO_keymap[74] = SDLK_KP_DIVIDE;
slouken@630
   165
  RO_keymap[76] = SDLK_KP_PERIOD;
slouken@630
   166
  RO_keymap[77] = SDLK_NUMLOCK;
slouken@630
   167
  RO_keymap[78] = SDLK_PAGEDOWN;
slouken@630
   168
  RO_keymap[79] = SDLK_QUOTE;
slouken@630
   169
  RO_keymap[81] = SDLK_s;
slouken@630
   170
  RO_keymap[82] = SDLK_c;
slouken@630
   171
  RO_keymap[83] = SDLK_g;
slouken@630
   172
  RO_keymap[84] = SDLK_h;
slouken@630
   173
  RO_keymap[85] = SDLK_n;
slouken@630
   174
  RO_keymap[86] = SDLK_l;
slouken@630
   175
  RO_keymap[87] = SDLK_SEMICOLON;
slouken@630
   176
  RO_keymap[88] = SDLK_RIGHTPAREN;
slouken@630
   177
  RO_keymap[89] = SDLK_DELETE;
slouken@630
   178
  RO_keymap[90] = SDLK_KP_MINUS;
slouken@630
   179
  RO_keymap[91] = SDLK_KP_MULTIPLY;
slouken@630
   180
  RO_keymap[93] = SDLK_EQUALS;
slouken@630
   181
  RO_keymap[94] = SDLK_BACKSLASH;
slouken@630
   182
  RO_keymap[96] = SDLK_TAB;
slouken@630
   183
  RO_keymap[97] = SDLK_z;
slouken@630
   184
  RO_keymap[98] = SDLK_SPACE;
slouken@630
   185
  RO_keymap[99] = SDLK_v;
slouken@630
   186
  RO_keymap[100] = SDLK_b;
slouken@630
   187
  RO_keymap[101] = SDLK_m;
slouken@630
   188
  RO_keymap[102] = SDLK_COMMA;
slouken@630
   189
  RO_keymap[103] = SDLK_PERIOD;
slouken@630
   190
  RO_keymap[104] = SDLK_SLASH;
slouken@630
   191
  RO_keymap[105] = SDLK_END;
slouken@630
   192
  RO_keymap[106] = SDLK_KP0;
slouken@630
   193
  RO_keymap[107] = SDLK_KP1;
slouken@630
   194
  RO_keymap[108] = SDLK_KP3;
slouken@630
   195
  RO_keymap[112] = SDLK_ESCAPE;
slouken@630
   196
  RO_keymap[113] = SDLK_F1;
slouken@630
   197
  RO_keymap[114] = SDLK_F2;
slouken@630
   198
  RO_keymap[115] = SDLK_F3;
slouken@630
   199
  RO_keymap[116] = SDLK_F5;
slouken@630
   200
  RO_keymap[117] = SDLK_F6;
slouken@630
   201
  RO_keymap[118] = SDLK_F8;
slouken@630
   202
  RO_keymap[119] = SDLK_F9;
slouken@630
   203
  RO_keymap[120] = SDLK_HASH;
slouken@630
   204
  RO_keymap[121] = SDLK_RIGHT;
slouken@630
   205
  RO_keymap[122] = SDLK_KP4;
slouken@630
   206
  RO_keymap[123] = SDLK_KP5;
slouken@630
   207
  RO_keymap[124] = SDLK_KP2;
slouken@630
   208
slouken@630
   209
  memset(RO_pressed, 0, ROKEYBD_ARRAYSIZE);
slouken@630
   210
}
slouken@630
   211
slouken@630
   212
slouken@630
   213
/* Variable for mouse relative processing */
slouken@630
   214
int mouse_relative = 0;
slouken@630
   215
slouken@630
   216
/* Check to see if we need to enter or leave mouse relative mode */
slouken@630
   217
slouken@630
   218
void RISCOS_CheckMouseMode(_THIS)
slouken@630
   219
{
slouken@630
   220
    /* If the mouse is hidden and input is grabbed, we use relative mode */
slouken@630
   221
    if ( !(SDL_cursorstate & CURSOR_VISIBLE) &&
slouken@630
   222
        (this->input_grab != SDL_GRAB_OFF) ) {
slouken@630
   223
            mouse_relative = 1;
slouken@630
   224
     } else {
slouken@630
   225
            mouse_relative = 0;
slouken@630
   226
     }
slouken@630
   227
}
slouken@630
   228
slouken@630
   229
slouken@630
   230
void RISCOS_PollMouse(_THIS)
slouken@630
   231
{
slouken@630
   232
   RISCOS_PollMouseHelper(this, 1);
slouken@630
   233
}
slouken@630
   234
slouken@630
   235
extern int mouseInWindow;
slouken@630
   236
slouken@630
   237
void WIMP_PollMouse(_THIS)
slouken@630
   238
{
slouken@630
   239
   /* Only poll when mouse is over the window */
slouken@630
   240
   if (!mouseInWindow) return;
slouken@630
   241
slouken@630
   242
   RISCOS_PollMouseHelper(this, 0);
slouken@630
   243
}
slouken@630
   244
slouken@630
   245
/* Static variables so only changes are reported */
slouken@630
   246
static Sint16 last_x = -1, last_y = -1;
slouken@630
   247
static int last_buttons = 0;
slouken@630
   248
slouken@630
   249
/* Share routine between WIMP and FULLSCREEN for polling mouse and
slouken@630
   250
   passing on events */
slouken@630
   251
void RISCOS_PollMouseHelper(_THIS, int fullscreen)
slouken@630
   252
{
slouken@630
   253
    _kernel_swi_regs regs;
slouken@630
   254
    static int starting = 1;
slouken@630
   255
slouken@630
   256
    if (_kernel_swi(OS_Mouse, &regs, &regs) == NULL)
slouken@630
   257
    {
slouken@630
   258
       Sint16 new_x = regs.r[0]; /* Initialy get as OS units */
slouken@630
   259
       Sint16 new_y = regs.r[1];
slouken@630
   260
slouken@630
   261
/* Discard mouse events until the let go of the mouse after starting */
slouken@630
   262
       if (starting && regs.r[2] != 0) return;
slouken@630
   263
       else starting = 0;
slouken@630
   264
slouken@630
   265
       if (new_x != last_x || new_y != last_y || last_buttons != regs.r[2])
slouken@630
   266
       {
slouken@630
   267
          /* Something changed so generate appropriate events */
slouken@630
   268
          int topLeftX, topLeftY;  /* Top left OS units */
slouken@630
   269
          int x, y;                /* Mouse position in SDL pixels */
slouken@630
   270
slouken@630
   271
          if (fullscreen)
slouken@630
   272
          {
slouken@630
   273
             topLeftX = 0;
slouken@630
   274
             topLeftY = (this->hidden->height << this->hidden->yeig) - 1;
slouken@630
   275
          } else
slouken@630
   276
          {
slouken@630
   277
             int window_state[9];
slouken@630
   278
slouken@630
   279
	         /* Get current window state */
slouken@630
   280
		     window_state[0] = this->hidden->window_handle;
slouken@630
   281
		     regs.r[1] = (unsigned int)window_state;
slouken@630
   282
		     _kernel_swi(Wimp_GetWindowState, &regs, &regs);
slouken@630
   283
slouken@630
   284
             topLeftX = window_state[1];
slouken@630
   285
             topLeftY = window_state[4];
slouken@630
   286
          }
slouken@630
   287
slouken@630
   288
		  /* Convert co-ordinates to workspace */
slouken@630
   289
		  x = new_x - topLeftX;
slouken@630
   290
          y = topLeftY - new_y; /* Y goes from top of window/screen */
slouken@630
   291
slouken@630
   292
	 	  /* Convert OS units to pixels */
slouken@630
   293
	      x >>= this->hidden->xeig;
slouken@630
   294
		  y >>= this->hidden->yeig;
slouken@630
   295
slouken@630
   296
          if (last_x != new_x || last_y != new_y)
slouken@630
   297
          {
slouken@630
   298
             if (mouse_relative)
slouken@630
   299
             {
slouken@630
   300
                int centre_x = SDL_VideoSurface->w/2;
slouken@630
   301
                int centre_y = SDL_VideoSurface->h/2;
slouken@630
   302
slouken@630
   303
                if (centre_x != x || centre_y != y)
slouken@630
   304
                {
slouken@630
   305
                   if (SDL_VideoSurface) SDL_PrivateMouseMotion(0,1,x - centre_x, y - centre_y);
slouken@630
   306
                   last_x = topLeftX + (centre_x << this->hidden->xeig);
slouken@630
   307
                   last_y = topLeftY - (centre_y << this->hidden->yeig);
slouken@630
   308
slouken@630
   309
                   /* Re-centre the mouse pointer, so we still get relative
slouken@630
   310
                      movement when the mouse is at the edge of the window
slouken@630
   311
                      or screen.
slouken@630
   312
                   */
slouken@630
   313
                   {
slouken@630
   314
                      unsigned char block[5];
slouken@630
   315
slouken@630
   316
                      block[0] = 3; /* OSWORD move pointer sub-reason code */
slouken@630
   317
                      block[1] = last_x & 0xFF;
slouken@630
   318
                      block[2] = (last_x >> 8) & 0xFF;
slouken@630
   319
                      block[3] = last_y & 0xFF;
slouken@630
   320
                      block[4] = (last_y >> 8) & 0xFF;
slouken@630
   321
                       
slouken@630
   322
                      regs.r[0] = 21; /* OSWORD pointer stuff code */
slouken@630
   323
                      regs.r[1] = (int)block;
slouken@630
   324
                      _kernel_swi(OS_Word, &regs, &regs);
slouken@630
   325
               	   }
slouken@630
   326
                }
slouken@630
   327
             } else
slouken@630
   328
             {
slouken@630
   329
                last_x = new_x;
slouken@630
   330
                last_y = new_y;
slouken@630
   331
                SDL_PrivateMouseMotion(0,0,x,y);
slouken@630
   332
             }
slouken@630
   333
          }
slouken@630
   334
slouken@630
   335
          if (last_buttons != regs.r[2])
slouken@630
   336
          {
slouken@630
   337
             int changed = last_buttons ^ regs.r[2];
slouken@630
   338
             last_buttons = regs.r[2];
slouken@630
   339
             if (changed & 4) SDL_PrivateMouseButton((last_buttons & 4) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_LEFT, x, y);
slouken@630
   340
             if (changed & 2) SDL_PrivateMouseButton((last_buttons & 2) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_MIDDLE, x, y);
slouken@630
   341
             if (changed & 1) SDL_PrivateMouseButton((last_buttons & 1) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_RIGHT, x, y);
slouken@630
   342
          }
slouken@630
   343
       }
slouken@630
   344
    }
slouken@630
   345
}
slouken@630
   346
slouken@630
   347
void RISCOS_PollKeyboard()
slouken@630
   348
{
slouken@630
   349
	int which_key = ROKEY_LEFT_SHIFT;
slouken@630
   350
	int j;
slouken@630
   351
	int min_key, max_key;
slouken@630
   352
	SDL_keysym key;
slouken@630
   353
slouken@630
   354
	/* Scan the keyboard to see what is pressed */
slouken@630
   355
	while (which_key <= ROKEY_LAST_KEY)
slouken@630
   356
	{
slouken@630
   357
		which_key = (_kernel_osbyte(121, which_key, 0) & 0xFF);
slouken@630
   358
	    if (which_key != ROKEY_NONE)
slouken@630
   359
		{
slouken@630
   360
		    switch(which_key)
slouken@630
   361
		    {
slouken@630
   362
		    /* Skip over mouse keys */
slouken@630
   363
		    case ROKEY_LEFT_MOUSE:
slouken@630
   364
		    case ROKEY_CENTRE_MOUSE:
slouken@630
   365
		    case ROKEY_RIGHT_MOUSE:
slouken@630
   366
				which_key = ROKEY_RIGHT_MOUSE;
slouken@630
   367
				break;
slouken@630
   368
slouken@630
   369
            /* Ignore keys that cause 2 internal number to be generated */
slouken@630
   370
			case 71: case 24: case 87: case 40:
slouken@630
   371
			    break;
slouken@630
   372
slouken@630
   373
			default:
slouken@630
   374
				RO_pressed[which_key] += 2;
slouken@630
   375
				break;
slouken@630
   376
		    }
slouken@630
   377
			which_key++;
slouken@630
   378
		}
slouken@630
   379
	}
slouken@630
   380
slouken@630
   381
	/* Generate key released messages */
slouken@630
   382
	min_key = ROKEY_LAST_KEY+1;
slouken@630
   383
	max_key = ROKEY_LEFT_SHIFT;
slouken@630
   384
slouken@630
   385
	for (j = ROKEY_LEFT_SHIFT; j <= ROKEY_LAST_KEY; j++)
slouken@630
   386
	{
slouken@630
   387
		if (RO_pressed[j])
slouken@630
   388
		{
slouken@630
   389
			if (RO_pressed[j] == 1)
slouken@630
   390
			{
slouken@630
   391
				RO_pressed[j] = 0;
slouken@630
   392
				SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(j,&key,0));
slouken@630
   393
			} else 
slouken@630
   394
			{
slouken@630
   395
				if (j < min_key) min_key = j;
slouken@630
   396
				if (j > max_key) max_key = j;
slouken@630
   397
			}
slouken@630
   398
		}
slouken@630
   399
	}
slouken@630
   400
slouken@630
   401
	/* Generate key pressed messages */
slouken@630
   402
	for (j = min_key; j <= max_key; j++)
slouken@630
   403
	{
slouken@630
   404
		if (RO_pressed[j])
slouken@630
   405
		{
slouken@630
   406
			if (RO_pressed[j] == 2)
slouken@630
   407
			{
slouken@630
   408
				SDL_PrivateKeyboard(SDL_PRESSED,TranslateKey(j,&key,1));
slouken@630
   409
			}
slouken@630
   410
			RO_pressed[j] = 1;
slouken@630
   411
		}
slouken@630
   412
	}
slouken@630
   413
}
slouken@630
   414
slouken@630
   415
static SDL_keysym *TranslateKey(int intkey, SDL_keysym *keysym, int pressed)
slouken@630
   416
{
slouken@630
   417
	/* Set the keysym information */
slouken@630
   418
	keysym->scancode = (unsigned char) intkey;
slouken@630
   419
	keysym->sym = RO_keymap[intkey];
slouken@630
   420
	keysym->mod = KMOD_NONE;
slouken@630
   421
	keysym->unicode = 0;
slouken@630
   422
	if ( pressed && SDL_TranslateUNICODE )
slouken@630
   423
	{
slouken@630
   424
		int state;
slouken@630
   425
		int ch;
slouken@630
   426
slouken@630
   427
		state = (_kernel_osbyte(202, 0, 255) & 0xFF);
slouken@630
   428
slouken@630
   429
		/*TODO: better key to char mapping */
slouken@630
   430
slouken@630
   431
		ch = keysym->sym; /* This should handle most keys */
slouken@630
   432
slouken@630
   433
        if (intkey < 9)
slouken@630
   434
        {
slouken@630
   435
           ch = 0;
slouken@630
   436
slouken@630
   437
        } else if (state & 64) /* Control on */
slouken@630
   438
		{
slouken@630
   439
			ch = ch & 31;
slouken@630
   440
slouken@630
   441
		} else if ((state & 16) == 0) /* Caps lock is on */
slouken@630
   442
		{
slouken@630
   443
			if ((state & 128) == 0) /* Shift Enable off */
slouken@630
   444
			{
slouken@630
   445
				ch = toupper(ch);
slouken@630
   446
			}
slouken@630
   447
		} else if (state & 8) /* Shift on */
slouken@630
   448
		{
slouken@630
   449
			ch = toupper(ch);
slouken@630
   450
		}
slouken@630
   451
				
slouken@630
   452
		keysym->unicode = ch;
slouken@630
   453
	}
slouken@630
   454
	return(keysym);
slouken@630
   455
}
slouken@630
   456
slouken@630
   457
/* end of SDL_riscosevents.c ... */
slouken@630
   458