19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL - Simple DirectMedia Layer
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Copyright (C) 1997-2012 Sam Lantinga
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is free software; you can redistribute it and/or
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    modify it under the terms of the GNU Library General Public
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License as published by the Free Software Foundation; either
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    version 2 of the License, or (at your option) any later version.
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is distributed in the hope that it will be useful,
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    but WITHOUT ANY WARRANTY; without even the implied warranty of
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Library General Public License for more details.
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    You should have received a copy of the GNU Library General Public
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License along with this library; if not, write to the Free
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Sam Lantinga
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    slouken@libsdl.org
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h"
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     File added by Alan Buckley (alan_baa@hotmail.com) for RISC OS compatability
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	 27 March 2003
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Implements keyboard setup, event pump and keyboard and mouse polling
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL.h"
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../timer/SDL_timer_c.h"
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../events/SDL_sysevents.h"
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../events/SDL_events_c.h"
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../SDL_cursor_c.h"
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_riscosvideo.h"
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_riscosevents_c.h"
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "memory.h"
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "stdlib.h"
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "ctype.h"
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "kernel.h"
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "swis.h"
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* The translation table from a RISC OS internal key numbers to a SDL keysym */
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDLKey RO_keymap[SDLK_LAST];
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* RISC OS Key codes */
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define ROKEY_SHIFT 0
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define ROKEY_CTRL  1
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define ROKEY_ALT   2
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Left shift is first key we will check for */
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define ROKEY_LEFT_SHIFT 3
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Need to ignore mouse buttons as they are processed separately */
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define ROKEY_LEFT_MOUSE   9
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define ROKEY_CENTRE_MOUSE 10
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define ROKEY_RIGHT_MOUSE  11
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* No key has been pressed return value*/
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define ROKEY_NONE 255
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Id of last key in keyboard */
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define ROKEY_LAST_KEY  124
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Size of array for all keys */
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define ROKEYBD_ARRAYSIZE 125
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic char RO_pressed[ROKEYBD_ARRAYSIZE];
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDL_keysym *TranslateKey(int intkey, SDL_keysym *keysym, int pressed);
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid RISCOS_PollMouse(_THIS);
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid RISCOS_PollKeyboard();
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid RISCOS_PollMouseHelper(_THIS, int fullscreen);
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_THREADS_DISABLED
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern void DRenderer_FillBuffers();
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Timer running function */
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern void RISCOS_CheckTimer();
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid FULLSCREEN_PumpEvents(_THIS)
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Current implementation requires keyboard and mouse polling */
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	RISCOS_PollKeyboard();
929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	RISCOS_PollMouse(this);
939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_THREADS_DISABLED
949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall//	DRenderer_FillBuffers();
959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (SDL_timer_running) RISCOS_CheckTimer();
969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid RISCOS_InitOSKeymap(_THIS)
1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int i;
1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Map the VK keysyms */
1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	for ( i=0; i<SDL_arraysize(RO_keymap); ++i )
1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		RO_keymap[i] = SDLK_UNKNOWN;
1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[3] = SDLK_LSHIFT;
1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[4] = SDLK_LCTRL;
1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[5] = SDLK_LALT;
1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[6] = SDLK_RSHIFT;
1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[7] = SDLK_RCTRL;
1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[8] = SDLK_RALT;
1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[16] = SDLK_q;
1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[17] = SDLK_3;
1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[18] = SDLK_4;
1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[19] = SDLK_5;
1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[20] = SDLK_F4;
1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[21] = SDLK_8;
1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[22] = SDLK_F7;
1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[23] = SDLK_MINUS,
1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[25] = SDLK_LEFT;
1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[26] = SDLK_KP6;
1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[27] = SDLK_KP7;
1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[28] = SDLK_F11;
1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[29] = SDLK_F12;
1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[30] = SDLK_F10;
1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[31] = SDLK_SCROLLOCK;
1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[32] = SDLK_PRINT;
1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[33] = SDLK_w;
1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[34] = SDLK_e;
1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[35] = SDLK_t;
1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[36] = SDLK_7;
1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[37] = SDLK_i;
1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[38] = SDLK_9;
1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[39] = SDLK_0;
1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[41] = SDLK_DOWN;
1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[42] = SDLK_KP8;
1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[43] = SDLK_KP9;
1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[44] = SDLK_BREAK;
1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[45] = SDLK_BACKQUOTE;
1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*  RO_keymap[46] = SDLK_currency; TODO: Figure out if this has a value */
1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[47] = SDLK_BACKSPACE;
1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[48] = SDLK_1;
1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[49] = SDLK_2;
1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[50] = SDLK_d;
1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[51] = SDLK_r;
1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[52] = SDLK_6;
1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[53] = SDLK_u;
1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[54] = SDLK_o;
1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[55] = SDLK_p;
1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[56] = SDLK_LEFTBRACKET;
1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[57] = SDLK_UP;
1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[58] = SDLK_KP_PLUS;
1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[59] = SDLK_KP_MINUS;
1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[60] = SDLK_KP_ENTER;
1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[61] = SDLK_INSERT;
1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[62] = SDLK_HOME;
1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[63] = SDLK_PAGEUP;
1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[64] = SDLK_CAPSLOCK;
1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[65] = SDLK_a;
1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[66] = SDLK_x;
1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[67] = SDLK_f;
1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[68] = SDLK_y;
1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[69] = SDLK_j;
1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[70] = SDLK_k;
1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[72] = SDLK_SEMICOLON;
1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[73] = SDLK_RETURN;
1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[74] = SDLK_KP_DIVIDE;
1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[76] = SDLK_KP_PERIOD;
1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[77] = SDLK_NUMLOCK;
1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[78] = SDLK_PAGEDOWN;
1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[79] = SDLK_QUOTE;
1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[81] = SDLK_s;
1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[82] = SDLK_c;
1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[83] = SDLK_g;
1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[84] = SDLK_h;
1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[85] = SDLK_n;
1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[86] = SDLK_l;
1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[87] = SDLK_SEMICOLON;
1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[88] = SDLK_RIGHTBRACKET;
1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[89] = SDLK_DELETE;
1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[90] = SDLK_KP_MINUS;
1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[91] = SDLK_KP_MULTIPLY;
1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[93] = SDLK_EQUALS;
1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[94] = SDLK_BACKSLASH;
1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[96] = SDLK_TAB;
1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[97] = SDLK_z;
1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[98] = SDLK_SPACE;
1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[99] = SDLK_v;
1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[100] = SDLK_b;
1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[101] = SDLK_m;
1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[102] = SDLK_COMMA;
1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[103] = SDLK_PERIOD;
1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[104] = SDLK_SLASH;
1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[105] = SDLK_END;
1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[106] = SDLK_KP0;
1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[107] = SDLK_KP1;
1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[108] = SDLK_KP3;
2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[112] = SDLK_ESCAPE;
2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[113] = SDLK_F1;
2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[114] = SDLK_F2;
2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[115] = SDLK_F3;
2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[116] = SDLK_F5;
2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[117] = SDLK_F6;
2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[118] = SDLK_F8;
2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[119] = SDLK_F9;
2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[120] = SDLK_HASH;
2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[121] = SDLK_RIGHT;
2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[122] = SDLK_KP4;
2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[123] = SDLK_KP5;
2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RO_keymap[124] = SDLK_KP2;
2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SDL_memset(RO_pressed, 0, ROKEYBD_ARRAYSIZE);
2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Variable for mouse relative processing */
2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint mouse_relative = 0;
2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Check to see if we need to enter or leave mouse relative mode */
2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid RISCOS_CheckMouseMode(_THIS)
2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* If the mouse is hidden and input is grabbed, we use relative mode */
2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if ( !(SDL_cursorstate & CURSOR_VISIBLE) &&
2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        (this->input_grab != SDL_GRAB_OFF) ) {
2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            mouse_relative = 1;
2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     } else {
2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            mouse_relative = 0;
2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     }
2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid RISCOS_PollMouse(_THIS)
2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   RISCOS_PollMouseHelper(this, 1);
2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern int mouseInWindow;
2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid WIMP_PollMouse(_THIS)
2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   /* Only poll when mouse is over the window */
2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   if (!mouseInWindow) return;
2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   RISCOS_PollMouseHelper(this, 0);
2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Static variables so only changes are reported */
2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic Sint16 last_x = -1, last_y = -1;
2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int last_buttons = 0;
2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Share routine between WIMP and FULLSCREEN for polling mouse and
2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   passing on events */
2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid RISCOS_PollMouseHelper(_THIS, int fullscreen)
2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    _kernel_swi_regs regs;
2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    static int starting = 1;
2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (_kernel_swi(OS_Mouse, &regs, &regs) == NULL)
2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall       Sint16 new_x = regs.r[0]; /* Initialy get as OS units */
2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall       Sint16 new_y = regs.r[1];
2659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall       /* Discard mouse events until they let go of the mouse after starting */
2679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall       if (starting && regs.r[2] != 0)
2689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall         return;
2699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall       else
2709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall         starting = 0;
2719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall       if (new_x != last_x || new_y != last_y || last_buttons != regs.r[2])
2739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall       {
2749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          /* Something changed so generate appropriate events */
2759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          int topLeftX, topLeftY;  /* Top left OS units */
2769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          int x, y;                /* Mouse position in SDL pixels */
2779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          if (fullscreen)
2799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          {
2809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             topLeftX = 0;
2819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             topLeftY = (this->hidden->height << this->hidden->yeig) - 1;
2829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          } else
2839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          {
2849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             int window_state[9];
2859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	         /* Get current window state */
2879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		     window_state[0] = this->hidden->window_handle;
2889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		     regs.r[1] = (unsigned int)window_state;
2899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		     _kernel_swi(Wimp_GetWindowState, &regs, &regs);
2909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             topLeftX = window_state[1];
2929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             topLeftY = window_state[4];
2939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          }
2949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		  /* Convert co-ordinates to workspace */
2969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		  x = new_x - topLeftX;
2979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          y = topLeftY - new_y; /* Y goes from top of window/screen */
2989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	 	  /* Convert OS units to pixels */
3009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	      x >>= this->hidden->xeig;
3019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		  y >>= this->hidden->yeig;
3029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          if (last_x != new_x || last_y != new_y)
3049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          {
3059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             if (mouse_relative)
3069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             {
3079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                int centre_x = SDL_VideoSurface->w/2;
3089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                int centre_y = SDL_VideoSurface->h/2;
3099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                if (centre_x != x || centre_y != y)
3119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                {
3129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                   if (SDL_VideoSurface) SDL_PrivateMouseMotion(0,1,x - centre_x, y - centre_y);
3139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                   last_x = topLeftX + (centre_x << this->hidden->xeig);
3149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                   last_y = topLeftY - (centre_y << this->hidden->yeig);
3159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                   /* Re-centre the mouse pointer, so we still get relative
3179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                      movement when the mouse is at the edge of the window
3189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                      or screen.
3199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                   */
3209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                   {
3219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                      unsigned char block[5];
3229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                      block[0] = 3; /* OSWORD move pointer sub-reason code */
3249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                      block[1] = last_x & 0xFF;
3259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                      block[2] = (last_x >> 8) & 0xFF;
3269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                      block[3] = last_y & 0xFF;
3279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                      block[4] = (last_y >> 8) & 0xFF;
3289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                      regs.r[0] = 21; /* OSWORD pointer stuff code */
3309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                      regs.r[1] = (int)block;
3319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                      _kernel_swi(OS_Word, &regs, &regs);
3329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall               	   }
3339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                }
3349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             } else
3359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             {
3369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                last_x = new_x;
3379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                last_y = new_y;
3389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                SDL_PrivateMouseMotion(0,0,x,y);
3399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             }
3409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          }
3419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          if (last_buttons != regs.r[2])
3439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          {
3449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             int changed = last_buttons ^ regs.r[2];
3459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             last_buttons = regs.r[2];
3469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             if (changed & 4) SDL_PrivateMouseButton((last_buttons & 4) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0);
3479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             if (changed & 2) SDL_PrivateMouseButton((last_buttons & 2) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_MIDDLE, 0, 0);
3489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             if (changed & 1) SDL_PrivateMouseButton((last_buttons & 1) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0);
3499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          }
3509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall       }
3519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
3529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
3539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid RISCOS_PollKeyboard()
3559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
3569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int which_key = ROKEY_LEFT_SHIFT;
3579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int j;
3589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int min_key, max_key;
3599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_keysym key;
3609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Scan the keyboard to see what is pressed */
3629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	while (which_key <= ROKEY_LAST_KEY)
3639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	{
3649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		which_key = (_kernel_osbyte(121, which_key, 0) & 0xFF);
3659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	    if (which_key != ROKEY_NONE)
3669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	    {
3679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		    switch(which_key)
3689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		    {
3699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		    /* Skip over mouse keys */
3709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		    case ROKEY_LEFT_MOUSE:
3719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		    case ROKEY_CENTRE_MOUSE:
3729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		    case ROKEY_RIGHT_MOUSE:
3739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				which_key = ROKEY_RIGHT_MOUSE;
3749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
3759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            /* Ignore keys that cause 2 internal number to be generated */
3779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			case 71: case 24: case 87: case 40:
3789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			    break;
3799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            /* Ignore break as it can be latched on */
3819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            case 44:
3829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                break;
3839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			default:
3859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				RO_pressed[which_key] += 2;
3869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
3879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		    }
3889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			which_key++;
3899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
3909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
3919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Generate key released messages */
3939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	min_key = ROKEY_LAST_KEY+1;
3949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	max_key = ROKEY_LEFT_SHIFT;
3959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	for (j = ROKEY_LEFT_SHIFT; j <= ROKEY_LAST_KEY; j++)
3979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	{
3989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if (RO_pressed[j])
3999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		{
4009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			if (RO_pressed[j] == 1)
4019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			{
4029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				RO_pressed[j] = 0;
4039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(j,&key,0));
4049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			} else
4059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			{
4069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				if (j < min_key) min_key = j;
4079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				if (j > max_key) max_key = j;
4089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
4099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
4109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
4119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Generate key pressed messages */
4139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	for (j = min_key; j <= max_key; j++)
4149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	{
4159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if (RO_pressed[j])
4169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		{
4179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			if (RO_pressed[j] == 2)
4189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			{
4199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				SDL_PrivateKeyboard(SDL_PRESSED,TranslateKey(j,&key,1));
4209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
4219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			RO_pressed[j] = 1;
4229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
4239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
4249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
4259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDL_keysym *TranslateKey(int intkey, SDL_keysym *keysym, int pressed)
4279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
4289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Set the keysym information */
4299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	keysym->scancode = (unsigned char) intkey;
4309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	keysym->sym = RO_keymap[intkey];
4319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	keysym->mod = KMOD_NONE;
4329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	keysym->unicode = 0;
4339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( pressed && SDL_TranslateUNICODE )
4349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	{
4359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		int state;
4369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		int ch;
4379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		state = (_kernel_osbyte(202, 0, 255) & 0xFF);
4399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		/*TODO: Take into account other keyboard layouts */
4419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		ch = keysym->sym; /* This should handle most unshifted keys */
4439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        if (intkey < 9 || ch == SDLK_UNKNOWN)
4459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        {
4469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall           ch = 0;
4479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        } else if (state & 64) /* Control on */
4499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		{
4509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			ch = ch & 31;
4519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		} else
4539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		{
4549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			int topOfKey = 0;
4559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            if (state & 8) /* Shift on */
4569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			{
4579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				topOfKey = 1;
4589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
4599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			if ((state & 16) == 0) /* Caps lock is on */
4619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			{
4629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			   if (ch >= SDLK_a && ch <= SDLK_z)
4639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			   {
4649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 				  if ((state & 128) == 0) /* Shift Enable off */
4659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				  {
4669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				     /* All letter become upper case */
4679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				 	 topOfKey = 1;
4689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				  } else
4699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				  {
4709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				     /* Shift+Letters gives lower case */
4719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				     topOfKey = 1 - topOfKey;
4729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				  }
4739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		       }
4749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
4759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			if (topOfKey)
4779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			{
4789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				/* Key produced with shift held down */
4799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				/* Letters just give upper case version */
4819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				if (ch >= SDLK_a && ch <= SDLK_z) ch = toupper(ch);
4829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				else
4839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				{
4849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					switch(ch)
4859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					{
4869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_HASH:   ch = '~'; break;
4879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_QUOTE:  ch = '@'; break;
4889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_COMMA:  ch = '<'; break;
4899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_MINUS:  ch = '_'; break;
4909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_PERIOD: ch = '>'; break;
4919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_SLASH:  ch = '?'; break;
4929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_0: ch = ')'; break;
4949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_1: ch = '!'; break;
4959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_2: ch = '"'; break;
4969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_3: ch = '�'; break;
4979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_4: ch = '$'; break;
4989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_5: ch = '%'; break;
4999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_6: ch = '^'; break;
5009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_7: ch = '&'; break;
5019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_8: ch = '*'; break;
5029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_9: ch = '('; break;
5039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_SEMICOLON:    ch = ':'; break;
5059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_EQUALS:       ch = '+'; break;
5069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_LEFTBRACKET:  ch = '{'; break;
5079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_BACKSLASH:    ch = '|'; break;
5089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_RIGHTBRACKET: ch = '}'; break;
5099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_BACKQUOTE:    ch = '�'; break;
5109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					default:
5129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						ch = 0; /* Map to zero character if we don't understand it */
5139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						break;
5149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					}
5159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				}
5169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			} else if (ch > 126)
5189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			{
5199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				/* SDL key code < 126 map directly onto their Unicode equivalents */
5209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				/* Keypad 0 to 9 maps to numeric equivalent */
5219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				if (ch >= SDLK_KP0 && ch <= SDLK_KP9) ch = ch - SDLK_KP0 + '0';
5229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				else
5239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				{
5249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					/* Following switch maps other keys that produce an Ascii value */
5259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					switch(ch)
5269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					{
5279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_KP_PERIOD:   ch = '.'; break;
5289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_KP_DIVIDE:   ch = '/'; break;
5299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_KP_MULTIPLY: ch = '*'; break;
5309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_KP_MINUS:    ch = '-'; break;
5319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_KP_PLUS:     ch = '+'; break;
5329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case SDLK_KP_EQUALS:   ch = '='; break;
5339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					default:
5359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						/* If we don't know what it is set the Unicode to 0 */
5369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						ch = 0;
5379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						break;
5389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					}
5399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				}
5409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
5419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
5429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		keysym->unicode = ch;
5449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
5459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(keysym);
5469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
5479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* end of SDL_riscosevents.c ... */
5499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
550