Forward keyboard reworking from 1.2
authorPatrice Mandin <patmandin@gmail.com>
Wed, 20 Sep 2006 19:47:09 +0000
changeset 2030 d774e9d7c2a8
parent 2029 8640d90b0406
child 2031 f54073d86c82
Forward keyboard reworking from 1.2
src/video/ataricommon/SDL_atarievents.c
src/video/ataricommon/SDL_atarievents_c.h
src/video/ataricommon/SDL_biosevents.c
src/video/ataricommon/SDL_gemdosevents.c
src/video/ataricommon/SDL_ikbdevents.c
src/video/gem/SDL_gemevents.c
--- a/src/video/ataricommon/SDL_atarievents.c	Sat Sep 16 17:13:41 2006 +0000
+++ b/src/video/ataricommon/SDL_atarievents.c	Wed Sep 20 19:47:09 2006 +0000
@@ -30,10 +30,13 @@
  */
 
 #include <mint/cookie.h>
+#include <mint/ostruct.h>
+#include <mint/osbind.h>
 
 #include "../../events/SDL_sysevents.h"
 #include "../../events/SDL_events_c.h"
 
+#include "SDL_atarikeys.h"
 #include "SDL_atarievents_c.h"
 #include "SDL_biosevents_c.h"
 #include "SDL_gemdosevents_c.h"
@@ -49,6 +52,14 @@
     MCH_ARANYM
 };
 
+#ifndef KT_NOCHANGE
+# define KT_NOCHANGE -1
+#endif
+
+/* The translation tables from a console scancode to a SDL keysym */
+static SDLKey keymap[ATARIBIOS_MAXKEYS];
+static unsigned char *keytab_normal;
+
 void (*Atari_ShutdownEvents) (void);
 
 static void
@@ -111,6 +122,8 @@
 {
     Atari_InitializeEvents(this);
 
+    SDL_Atari_InitInternalKeymap(this);
+
     /* Call choosen routine */
     this->InitOSKeymap(this);
 }
@@ -124,6 +137,47 @@
     this->PumpEvents(this);
 }
 
+void
+SDL_Atari_InitInternalKeymap(_THIS)
+{
+    int i;
+    _KEYTAB *key_tables;
+
+    /* Read system tables for scancode -> ascii translation */
+    key_tables = (_KEYTAB *) Keytbl(KT_NOCHANGE, KT_NOCHANGE, KT_NOCHANGE);
+    keytab_normal = key_tables->unshift;
+
+    /* Initialize keymap */
+    for ( i=0; i<ATARIBIOS_MAXKEYS; i++ )
+        keymap[i] = SDLK_UNKNOWN;
+
+    /* Functions keys */
+    for ( i = 0; i<10; i++ )
+        keymap[SCANCODE_F1 + i] = SDLK_F1+i;
+
+    /* Cursor keypad */
+    keymap[SCANCODE_HELP] = SDLK_HELP;
+    keymap[SCANCODE_UNDO] = SDLK_UNDO;
+    keymap[SCANCODE_INSERT] = SDLK_INSERT;
+    keymap[SCANCODE_CLRHOME] = SDLK_HOME;
+    keymap[SCANCODE_UP] = SDLK_UP;
+    keymap[SCANCODE_DOWN] = SDLK_DOWN;
+    keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
+    keymap[SCANCODE_LEFT] = SDLK_LEFT;
+
+    /* Special keys */
+    keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
+    keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
+    keymap[SCANCODE_TAB] = SDLK_TAB;
+    keymap[SCANCODE_ENTER] = SDLK_RETURN;
+    keymap[SCANCODE_DELETE] = SDLK_DELETE;
+    keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
+    keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
+    keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
+    keymap[SCANCODE_LEFTALT] = SDLK_LALT;
+    keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
+}
+
 /* Atari to Unicode charset translation table */
 
 Uint16 SDL_AtariToUnicodeTable[256] = {
@@ -167,4 +221,27 @@
     0x00B0, 0x2022, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x00B3, 0x00AF
 };
 
+SDL_keysym *
+SDL_Atari_TranslateKey(int scancode, SDL_keysym *keysym,
+                       SDL_bool pressed)
+{
+    int asciicode = 0;
+
+    /* Set the keysym information */
+    keysym->scancode = scancode;
+    keysym->mod = KMOD_NONE;
+    keysym->sym = keymap[scancode];
+    keysym->unicode = 0;
+
+    if (keysym->sym == SDLK_UNKNOWN) {
+        keysym->sym = asciicode = keytab_normal[scancode];		
+    }
+
+    if (SDL_TranslateUNICODE && pressed) {
+        keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
+    }
+
+    return(keysym);
+}
+
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/ataricommon/SDL_atarievents_c.h	Sat Sep 16 17:13:41 2006 +0000
+++ b/src/video/ataricommon/SDL_atarievents_c.h	Wed Sep 20 19:47:09 2006 +0000
@@ -35,13 +35,32 @@
 /* Hidden "this" pointer for the video functions */
 #define _THIS	SDL_VideoDevice *this
 
+#define ATARIBIOS_MAXKEYS 128
+
+/* Special keys state */
+#ifndef K_RSHIFT
+enum {
+    K_RSHIFT=0,
+    K_LSHIFT,
+    K_CTRL,
+    K_ALT,
+    K_CAPSLOCK,
+    K_CLRHOME,
+    K_INSERT
+};
+#endif
+
 extern void (*Atari_ShutdownEvents) (void);
 
 extern void Atari_InitOSKeymap(_THIS);
 extern void Atari_PumpEvents(_THIS);
 
+extern void SDL_Atari_InitInternalKeymap(_THIS);
+
 /* Atari to Unicode charset translation table */
 extern Uint16 SDL_AtariToUnicodeTable[256];
+SDL_keysym *SDL_Atari_TranslateKey(int scancode, SDL_keysym *keysym,
+    SDL_bool pressed);
 
 #endif /* _SDL_ATARI_EVENTS_H_ */
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/ataricommon/SDL_biosevents.c	Sat Sep 16 17:13:41 2006 +0000
+++ b/src/video/ataricommon/SDL_biosevents.c	Wed Sep 20 19:47:09 2006 +0000
@@ -39,31 +39,10 @@
 #include "SDL_xbiosevents_c.h"
 #include "SDL_ataridevmouse_c.h"
 
-/* To save state of keyboard */
-#define ATARIBIOS_MAXKEYS 128
-
 static unsigned char bios_currentkeyboard[ATARIBIOS_MAXKEYS];
 static unsigned char bios_previouskeyboard[ATARIBIOS_MAXKEYS];
-static unsigned char bios_currentascii[ATARIBIOS_MAXKEYS];
 static SDL_bool use_dev_mouse = SDL_FALSE;
 
-/* Special keys state */
-enum
-{
-    K_RSHIFT = 0,
-    K_LSHIFT,
-    K_CTRL,
-    K_ALT,
-    K_CAPSLOCK,
-    K_CLRHOME,
-    K_INSERT
-};
-
-/* The translation tables from a console scancode to a SDL keysym */
-static SDLKey keymap[ATARIBIOS_MAXKEYS];
-
-static SDL_keysym *TranslateKey(int scancode, int asciicode,
-                                SDL_keysym * keysym, SDL_bool pressed);
 static void UpdateSpecialKeys(int special_keys_state);
 
 void
@@ -75,36 +54,6 @@
     SDL_memset(bios_currentkeyboard, 0, sizeof(bios_currentkeyboard));
     SDL_memset(bios_previouskeyboard, 0, sizeof(bios_previouskeyboard));
 
-    /* Initialize keymap */
-    for (i = 0; i < ATARIBIOS_MAXKEYS; i++)
-        keymap[i] = SDLK_UNKNOWN;
-
-    /* Functions keys */
-    for (i = 0; i < 10; i++)
-        keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
-
-    /* Cursor keypad */
-    keymap[SCANCODE_HELP] = SDLK_HELP;
-    keymap[SCANCODE_UNDO] = SDLK_UNDO;
-    keymap[SCANCODE_INSERT] = SDLK_INSERT;
-    keymap[SCANCODE_CLRHOME] = SDLK_HOME;
-    keymap[SCANCODE_UP] = SDLK_UP;
-    keymap[SCANCODE_DOWN] = SDLK_DOWN;
-    keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
-    keymap[SCANCODE_LEFT] = SDLK_LEFT;
-
-    /* Special keys */
-    keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
-    keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
-    keymap[SCANCODE_TAB] = SDLK_TAB;
-    keymap[SCANCODE_ENTER] = SDLK_RETURN;
-    keymap[SCANCODE_DELETE] = SDLK_DELETE;
-    keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
-    keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
-    keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
-    keymap[SCANCODE_LEFTALT] = SDLK_LALT;
-    keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
-
     use_dev_mouse = (SDL_AtariDevMouse_Open() != 0) ? SDL_TRUE : SDL_FALSE;
 
     vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;  /* XBIOS joystick events */
@@ -129,15 +78,8 @@
 
     while (Bconstat(_CON)) {
         unsigned long key_pressed;
-        unsigned char asciicode, scancode;
-
-        key_pressed = Bconin(_CON);
-
-        asciicode = key_pressed;
-        scancode = key_pressed >> 16;
-
-        bios_currentkeyboard[scancode] = 0xFF;
-        bios_currentascii[scancode] = asciicode;
+        key_pressed=Bconin(_CON);
+        bios_currentkeyboard[(key_pressed>>16)&(ATARIBIOS_MAXKEYS-1)]=0xFF;
     }
 
     /* Read special keys */
@@ -148,14 +90,12 @@
         /* Key pressed ? */
         if (bios_currentkeyboard[i] && !bios_previouskeyboard[i])
             SDL_PrivateKeyboard(SDL_PRESSED,
-                                TranslateKey(i, bios_currentascii[i],
-                                             &keysym, SDL_TRUE));
+                                SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
 
         /* Key unpressed ? */
         if (bios_previouskeyboard[i] && !bios_currentkeyboard[i])
             SDL_PrivateKeyboard(SDL_RELEASED,
-                                TranslateKey(i, bios_currentascii[i],
-                                             &keysym, SDL_FALSE));
+                                SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
     }
 
     if (use_dev_mouse) {
@@ -166,7 +106,7 @@
 
     /* Will be previous table */
     SDL_memcpy(bios_previouskeyboard, bios_currentkeyboard,
-               ATARIBIOS_MAXKEYS);
+               sizeof(bios_previouskeyboard));
 }
 
 static void
@@ -187,27 +127,6 @@
     UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
 }
 
-static SDL_keysym *
-TranslateKey(int scancode, int asciicode, SDL_keysym * keysym,
-             SDL_bool pressed)
-{
-    /* Set the keysym information */
-    keysym->scancode = scancode;
-
-    if (asciicode)
-        keysym->sym = asciicode;
-    else
-        keysym->sym = keymap[scancode];
-
-    keysym->mod = KMOD_NONE;
-    keysym->unicode = 0;
-    if (SDL_TranslateUNICODE && pressed) {
-        keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
-    }
-
-    return (keysym);
-}
-
 void
 AtariBios_ShutdownEvents(void)
 {
--- a/src/video/ataricommon/SDL_gemdosevents.c	Sat Sep 16 17:13:41 2006 +0000
+++ b/src/video/ataricommon/SDL_gemdosevents.c	Wed Sep 20 19:47:09 2006 +0000
@@ -40,36 +40,16 @@
 #include "SDL_ataridevmouse_c.h"
 
 /* To save state of keyboard */
-#define ATARIBIOS_MAXKEYS 128
 
 static unsigned char gemdos_currentkeyboard[ATARIBIOS_MAXKEYS];
 static unsigned char gemdos_previouskeyboard[ATARIBIOS_MAXKEYS];
-static unsigned char gemdos_currentascii[ATARIBIOS_MAXKEYS];
 static SDL_bool use_dev_mouse = SDL_FALSE;
 
-/* Special keys state */
-enum
-{
-    K_RSHIFT = 0,
-    K_LSHIFT,
-    K_CTRL,
-    K_ALT,
-    K_CAPSLOCK,
-    K_CLRHOME,
-    K_INSERT
+enum {
+	DEV_BUSY=0,
+	DEV_READY
 };
 
-enum
-{
-    DEV_BUSY = 0,
-    DEV_READY
-};
-
-/* The translation tables from a console scancode to a SDL keysym */
-static SDLKey keymap[ATARIBIOS_MAXKEYS];
-
-static SDL_keysym *TranslateKey(int scancode, int asciicode,
-                                SDL_keysym * keysym, SDL_bool pressed);
 static void UpdateSpecialKeys(int special_keys_state);
 
 void
@@ -81,36 +61,6 @@
     SDL_memset(gemdos_currentkeyboard, 0, sizeof(gemdos_currentkeyboard));
     SDL_memset(gemdos_previouskeyboard, 0, sizeof(gemdos_previouskeyboard));
 
-    /* Initialize keymap */
-    for (i = 0; i < ATARIBIOS_MAXKEYS; i++)
-        keymap[i] = SDLK_UNKNOWN;
-
-    /* Functions keys */
-    for (i = 0; i < 10; i++)
-        keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
-
-    /* Cursor keypad */
-    keymap[SCANCODE_HELP] = SDLK_HELP;
-    keymap[SCANCODE_UNDO] = SDLK_UNDO;
-    keymap[SCANCODE_INSERT] = SDLK_INSERT;
-    keymap[SCANCODE_CLRHOME] = SDLK_HOME;
-    keymap[SCANCODE_UP] = SDLK_UP;
-    keymap[SCANCODE_DOWN] = SDLK_DOWN;
-    keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
-    keymap[SCANCODE_LEFT] = SDLK_LEFT;
-
-    /* Special keys */
-    keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
-    keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
-    keymap[SCANCODE_TAB] = SDLK_TAB;
-    keymap[SCANCODE_ENTER] = SDLK_RETURN;
-    keymap[SCANCODE_DELETE] = SDLK_DELETE;
-    keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
-    keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
-    keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
-    keymap[SCANCODE_LEFTALT] = SDLK_LALT;
-    keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
-
     use_dev_mouse = (SDL_AtariDevMouse_Open() != 0) ? SDL_TRUE : SDL_FALSE;
 
     vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;  /* XBIOS joystick events */
@@ -134,15 +84,8 @@
 
     while (Cconis() != DEV_BUSY) {
         unsigned long key_pressed;
-        unsigned char scancode, asciicode;
-
-        key_pressed = Cnecin();
-
-        asciicode = key_pressed;
-        scancode = key_pressed >> 16;
-
-        gemdos_currentkeyboard[scancode] = 0xFF;
-        gemdos_currentascii[scancode] = asciicode;
+        key_pressed=Cnecin();
+        gemdos_currentkeyboard[(key_pressed>>16)&(ATARIBIOS_MAXKEYS-1)]=0xFF;
     }
 
     /* Read special keys */
@@ -153,14 +96,12 @@
         /* Key pressed ? */
         if (gemdos_currentkeyboard[i] && !gemdos_previouskeyboard[i])
             SDL_PrivateKeyboard(SDL_PRESSED,
-                                TranslateKey(i, gemdos_currentascii[i],
-                                             &keysym, SDL_TRUE));
+                                SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
 
         /* Key unpressed ? */
         if (gemdos_previouskeyboard[i] && !gemdos_currentkeyboard[i])
             SDL_PrivateKeyboard(SDL_RELEASED,
-                                TranslateKey(i, gemdos_currentascii[i],
-                                             &keysym, SDL_FALSE));
+                                SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
     }
 
     if (use_dev_mouse) {
@@ -171,7 +112,7 @@
 
     /* Will be previous table */
     SDL_memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard,
-               ATARIBIOS_MAXKEYS);
+               sizeof(gemdos_previouskeyboard));
 }
 
 static void
@@ -192,27 +133,6 @@
     UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
 }
 
-static SDL_keysym *
-TranslateKey(int scancode, int asciicode, SDL_keysym * keysym,
-             SDL_bool pressed)
-{
-    /* Set the keysym information */
-    keysym->scancode = scancode;
-
-    if (asciicode)
-        keysym->sym = asciicode;
-    else
-        keysym->sym = keymap[scancode];
-
-    keysym->mod = KMOD_NONE;
-    keysym->unicode = 0;
-    if (SDL_TranslateUNICODE && pressed) {
-        keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
-    }
-
-    return (keysym);
-}
-
 void
 AtariGemdos_ShutdownEvents(void)
 {
--- a/src/video/ataricommon/SDL_ikbdevents.c	Sat Sep 16 17:13:41 2006 +0000
+++ b/src/video/ataricommon/SDL_ikbdevents.c	Wed Sep 20 19:47:09 2006 +0000
@@ -37,88 +37,16 @@
 #include "SDL_atarievents_c.h"
 #include "SDL_ikbdinterrupt_s.h"
 
-/* Special keys state */
-enum
-{
-    K_RSHIFT = 0,
-    K_LSHIFT,
-    K_CTRL,
-    K_ALT,
-    K_CAPSLOCK,
-    K_CLRHOME,
-    K_INSERT
-};
-
-#define ATARIBIOS_MAXKEYS 128
-
 #define KEY_PRESSED		0xff
 #define KEY_UNDEFINED	0x80
 #define KEY_RELEASED	0x00
 
-/* The translation tables from a console scancode to a SDL keysym */
-#define KT_NOCHANGE -1
-
-enum
-{
-    KT_UNSHIFT = 0,
-    KT_SHIFT = 1,
-    KT_CAPS = 2
-};
-
 static Uint16 atari_prevmouseb; /* save state of mouse buttons */
-static int caps_state;          /* caps lock state */
-_KEYTAB *curtables;
-static unsigned char *tab_unshift, *tab_shift, *tab_caps;
-static SDLKey keymap[ATARIBIOS_MAXKEYS];
-
-static SDL_keysym *TranslateKey(int scancode, int numkeytable,
-                                SDL_keysym * keysym, SDL_bool pressed);
 
 void
 AtariIkbd_InitOSKeymap(_THIS)
 {
-    int i;
-
-    SDL_memset(SDL_AtariIkbd_keyboard, KEY_UNDEFINED, ATARIBIOS_MAXKEYS);
-
-    /* Initialize keymap */
-    for (i = 0; i < ATARIBIOS_MAXKEYS; i++)
-        keymap[i] = SDLK_UNKNOWN;
-
-    /* Functions keys */
-    for (i = 0; i < 10; i++)
-        keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
-
-    /* Cursor keypad */
-    keymap[SCANCODE_HELP] = SDLK_HELP;
-    keymap[SCANCODE_UNDO] = SDLK_UNDO;
-    keymap[SCANCODE_INSERT] = SDLK_INSERT;
-    keymap[SCANCODE_CLRHOME] = SDLK_HOME;
-    keymap[SCANCODE_UP] = SDLK_UP;
-    keymap[SCANCODE_DOWN] = SDLK_DOWN;
-    keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
-    keymap[SCANCODE_LEFT] = SDLK_LEFT;
-
-    /* Special keys */
-    keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
-    keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
-    keymap[SCANCODE_TAB] = SDLK_TAB;
-    keymap[SCANCODE_ENTER] = SDLK_RETURN;
-    keymap[SCANCODE_DELETE] = SDLK_DELETE;
-    keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
-    keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
-    keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
-    keymap[SCANCODE_LEFTALT] = SDLK_LALT;
-    keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
-
-    /* Read XBIOS tables for scancode -> ascii translation */
-    curtables = Keytbl(KT_NOCHANGE, KT_NOCHANGE, KT_NOCHANGE);
-    tab_unshift = curtables->unshift;
-    tab_shift = curtables->shift;
-    tab_caps = curtables->caps;
-
-    /* Set Caps lock initial state */
-    caps_state = (Kbshift(-1) & (1 << K_CAPSLOCK));
+    SDL_memset(SDL_AtariIkbd_keyboard, KEY_UNDEFINED, sizeof(SDL_AtariIkbd_keyboard));
 
     /* Now install our handler */
     SDL_AtariIkbd_mouseb = SDL_AtariIkbd_mousex = SDL_AtariIkbd_mousey = 0;
@@ -150,36 +78,19 @@
 
         /*--- Send keyboard events ---*/
 
-    /* Update caps lock state */
-    if (SDL_AtariIkbd_keyboard[SCANCODE_CAPSLOCK] == KEY_PRESSED) {
-        caps_state ^= 1;
-    }
-
-    /* Choose the translation table */
-    specialkeys = KT_UNSHIFT;
-    if ((SDL_AtariIkbd_keyboard[SCANCODE_LEFTSHIFT] == KEY_PRESSED)
-        || (SDL_AtariIkbd_keyboard[SCANCODE_RIGHTSHIFT] == KEY_PRESSED)) {
-        specialkeys = KT_SHIFT;
-    }
-    if (caps_state) {
-        specialkeys = KT_CAPS;
-    }
-
     /* Now generate events */
     for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
         /* Key pressed ? */
         if (SDL_AtariIkbd_keyboard[i] == KEY_PRESSED) {
             SDL_PrivateKeyboard(SDL_PRESSED,
-                                TranslateKey(i, specialkeys, &keysym,
-                                             SDL_TRUE));
+                                SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
             SDL_AtariIkbd_keyboard[i] = KEY_UNDEFINED;
         }
 
         /* Key released ? */
         if (SDL_AtariIkbd_keyboard[i] == KEY_RELEASED) {
             SDL_PrivateKeyboard(SDL_RELEASED,
-                                TranslateKey(i, specialkeys, &keysym,
-                                             SDL_FALSE));
+                                SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
             SDL_AtariIkbd_keyboard[i] = KEY_UNDEFINED;
         }
     }
@@ -213,42 +124,6 @@
     }
 }
 
-static SDL_keysym *
-TranslateKey(int scancode, int numkeytable, SDL_keysym * keysym,
-             SDL_bool pressed)
-{
-    unsigned char asciicode;
-
-    /* Set the keysym information */
-    keysym->scancode = scancode;
-
-    asciicode = 0;
-    switch (numkeytable) {
-    case KT_UNSHIFT:
-        asciicode = tab_unshift[scancode];
-        break;
-    case KT_SHIFT:
-        asciicode = tab_shift[scancode];
-        break;
-    case KT_CAPS:
-        asciicode = tab_caps[scancode];
-        break;
-    }
-
-    if (asciicode)
-        keysym->sym = asciicode;
-    else
-        keysym->sym = keymap[scancode];
-
-    keysym->mod = KMOD_NONE;
-    keysym->unicode = 0;
-    if (SDL_TranslateUNICODE && pressed) {
-        keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
-    }
-
-    return (keysym);
-}
-
 void
 AtariIkbd_ShutdownEvents(void)
 {
--- a/src/video/gem/SDL_gemevents.c	Sat Sep 16 17:13:41 2006 +0000
+++ b/src/video/gem/SDL_gemevents.c	Wed Sep 20 19:47:09 2006 +0000
@@ -41,91 +41,29 @@
 #include "../ataricommon/SDL_xbiosevents_c.h"
 #include "../ataricommon/SDL_ataridevmouse_c.h"
 
-/* Defines */
-
-#define ATARIBIOS_MAXKEYS 128
-
 /* Variables */
 
 static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS];
 static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
-static unsigned char gem_currentascii[ATARIBIOS_MAXKEYS];
-
-/* The translation tables from a console scancode to a SDL keysym */
-static SDLKey keymap[ATARIBIOS_MAXKEYS];
 
 /* Functions prototypes */
 
-static SDL_keysym *TranslateKey(int scancode, int asciicode,
-                                SDL_keysym * keysym, SDL_bool pressed);
 static int do_messages(_THIS, short *message);
 static void do_keyboard(short kc, short ks);
 static void do_mouse(_THIS, short mx, short my, short mb, short ks);
 
 /* Functions */
 
-static SDL_keysym *
-TranslateKey(int scancode, int asciicode, SDL_keysym * keysym,
-             SDL_bool pressed)
-{
-    /* Set the keysym information */
-    keysym->scancode = scancode;
-
-    if (asciicode)
-        keysym->sym = asciicode;
-    else
-        keysym->sym = keymap[scancode];
-
-    keysym->mod = KMOD_NONE;
-    keysym->unicode = 0;
-    if (SDL_TranslateUNICODE && pressed) {
-        keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
-    }
-
-    return (keysym);
-}
-
 void
 GEM_InitOSKeymap(_THIS)
 {
-    int i;
-
     SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
     SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
-    SDL_memset(gem_currentascii, 0, sizeof(gem_currentascii));
-
-    /* Initialize keymap */
-    for (i = 0; i < ATARIBIOS_MAXKEYS; i++)
-        keymap[i] = SDLK_UNKNOWN;
-
-    /* Functions keys */
-    for (i = 0; i < 10; i++)
-        keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
-
-    /* Cursor keypad */
-    keymap[SCANCODE_HELP] = SDLK_HELP;
-    keymap[SCANCODE_UNDO] = SDLK_UNDO;
-    keymap[SCANCODE_INSERT] = SDLK_INSERT;
-    keymap[SCANCODE_CLRHOME] = SDLK_HOME;
-    keymap[SCANCODE_UP] = SDLK_UP;
-    keymap[SCANCODE_DOWN] = SDLK_DOWN;
-    keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
-    keymap[SCANCODE_LEFT] = SDLK_LEFT;
-
-    /* Special keys */
-    keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
-    keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
-    keymap[SCANCODE_TAB] = SDLK_TAB;
-    keymap[SCANCODE_ENTER] = SDLK_RETURN;
-    keymap[SCANCODE_DELETE] = SDLK_DELETE;
-    keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
-    keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
-    keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
-    keymap[SCANCODE_LEFTALT] = SDLK_LALT;
-    keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
 
     /* Mouse init */
     GEM_mouse_relative = SDL_FALSE;
+
+    SDL_Atari_InitInternalKeymap(this);
 }
 
 void
@@ -204,14 +142,12 @@
         /* Key pressed ? */
         if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
             SDL_PrivateKeyboard(SDL_PRESSED,
-                                TranslateKey(i, gem_currentascii[i],
-                                             &keysym, SDL_TRUE));
+                                SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
 
         /* Key unpressed ? */
         if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
             SDL_PrivateKeyboard(SDL_RELEASED,
-                                TranslateKey(i, gem_currentascii[i],
-                                             &keysym, SDL_FALSE));
+                                SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
     }
 
     SDL_memcpy(gem_previouskeyboard, gem_currentkeyboard,
@@ -355,11 +291,8 @@
     int scancode, asciicode;
 
     if (kc) {
-        scancode = (kc >> 8) & 127;
-        asciicode = kc & 255;
-
-        gem_currentkeyboard[scancode] = 0xFF;
-        gem_currentascii[scancode] = asciicode;
+        scancode=(kc>>8) & (ATARIBIOS_MAXKEYS-1);
+        gem_currentkeyboard[scancode]=0xFF;
     }
 
     /* Read special keys */