src/video/riscos/SDL_riscosevents.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 05 Nov 2003 23:11:05 +0000
changeset 733 9557ac1857a3
parent 658 e71b7108d2d7
child 769 b8d311d90021
permissions -rw-r--r--
Date: Mon, 13 Oct 2003 13:37:18 +0100
From: "alan buckley"
Subject: Modification for RISC OS SDL port (SDL_riscosevents.c)

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