Forward keyboard reworking from 1.2
authorPatrice Mandin <patmandin@gmail.com>
Wed, 20 Sep 2006 19:47:09 +0000
changeset 2030d774e9d7c2a8
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
     1.1 --- a/src/video/ataricommon/SDL_atarievents.c	Sat Sep 16 17:13:41 2006 +0000
     1.2 +++ b/src/video/ataricommon/SDL_atarievents.c	Wed Sep 20 19:47:09 2006 +0000
     1.3 @@ -30,10 +30,13 @@
     1.4   */
     1.5  
     1.6  #include <mint/cookie.h>
     1.7 +#include <mint/ostruct.h>
     1.8 +#include <mint/osbind.h>
     1.9  
    1.10  #include "../../events/SDL_sysevents.h"
    1.11  #include "../../events/SDL_events_c.h"
    1.12  
    1.13 +#include "SDL_atarikeys.h"
    1.14  #include "SDL_atarievents_c.h"
    1.15  #include "SDL_biosevents_c.h"
    1.16  #include "SDL_gemdosevents_c.h"
    1.17 @@ -49,6 +52,14 @@
    1.18      MCH_ARANYM
    1.19  };
    1.20  
    1.21 +#ifndef KT_NOCHANGE
    1.22 +# define KT_NOCHANGE -1
    1.23 +#endif
    1.24 +
    1.25 +/* The translation tables from a console scancode to a SDL keysym */
    1.26 +static SDLKey keymap[ATARIBIOS_MAXKEYS];
    1.27 +static unsigned char *keytab_normal;
    1.28 +
    1.29  void (*Atari_ShutdownEvents) (void);
    1.30  
    1.31  static void
    1.32 @@ -111,6 +122,8 @@
    1.33  {
    1.34      Atari_InitializeEvents(this);
    1.35  
    1.36 +    SDL_Atari_InitInternalKeymap(this);
    1.37 +
    1.38      /* Call choosen routine */
    1.39      this->InitOSKeymap(this);
    1.40  }
    1.41 @@ -124,6 +137,47 @@
    1.42      this->PumpEvents(this);
    1.43  }
    1.44  
    1.45 +void
    1.46 +SDL_Atari_InitInternalKeymap(_THIS)
    1.47 +{
    1.48 +    int i;
    1.49 +    _KEYTAB *key_tables;
    1.50 +
    1.51 +    /* Read system tables for scancode -> ascii translation */
    1.52 +    key_tables = (_KEYTAB *) Keytbl(KT_NOCHANGE, KT_NOCHANGE, KT_NOCHANGE);
    1.53 +    keytab_normal = key_tables->unshift;
    1.54 +
    1.55 +    /* Initialize keymap */
    1.56 +    for ( i=0; i<ATARIBIOS_MAXKEYS; i++ )
    1.57 +        keymap[i] = SDLK_UNKNOWN;
    1.58 +
    1.59 +    /* Functions keys */
    1.60 +    for ( i = 0; i<10; i++ )
    1.61 +        keymap[SCANCODE_F1 + i] = SDLK_F1+i;
    1.62 +
    1.63 +    /* Cursor keypad */
    1.64 +    keymap[SCANCODE_HELP] = SDLK_HELP;
    1.65 +    keymap[SCANCODE_UNDO] = SDLK_UNDO;
    1.66 +    keymap[SCANCODE_INSERT] = SDLK_INSERT;
    1.67 +    keymap[SCANCODE_CLRHOME] = SDLK_HOME;
    1.68 +    keymap[SCANCODE_UP] = SDLK_UP;
    1.69 +    keymap[SCANCODE_DOWN] = SDLK_DOWN;
    1.70 +    keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
    1.71 +    keymap[SCANCODE_LEFT] = SDLK_LEFT;
    1.72 +
    1.73 +    /* Special keys */
    1.74 +    keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
    1.75 +    keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
    1.76 +    keymap[SCANCODE_TAB] = SDLK_TAB;
    1.77 +    keymap[SCANCODE_ENTER] = SDLK_RETURN;
    1.78 +    keymap[SCANCODE_DELETE] = SDLK_DELETE;
    1.79 +    keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
    1.80 +    keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
    1.81 +    keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
    1.82 +    keymap[SCANCODE_LEFTALT] = SDLK_LALT;
    1.83 +    keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
    1.84 +}
    1.85 +
    1.86  /* Atari to Unicode charset translation table */
    1.87  
    1.88  Uint16 SDL_AtariToUnicodeTable[256] = {
    1.89 @@ -167,4 +221,27 @@
    1.90      0x00B0, 0x2022, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x00B3, 0x00AF
    1.91  };
    1.92  
    1.93 +SDL_keysym *
    1.94 +SDL_Atari_TranslateKey(int scancode, SDL_keysym *keysym,
    1.95 +                       SDL_bool pressed)
    1.96 +{
    1.97 +    int asciicode = 0;
    1.98 +
    1.99 +    /* Set the keysym information */
   1.100 +    keysym->scancode = scancode;
   1.101 +    keysym->mod = KMOD_NONE;
   1.102 +    keysym->sym = keymap[scancode];
   1.103 +    keysym->unicode = 0;
   1.104 +
   1.105 +    if (keysym->sym == SDLK_UNKNOWN) {
   1.106 +        keysym->sym = asciicode = keytab_normal[scancode];		
   1.107 +    }
   1.108 +
   1.109 +    if (SDL_TranslateUNICODE && pressed) {
   1.110 +        keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
   1.111 +    }
   1.112 +
   1.113 +    return(keysym);
   1.114 +}
   1.115 +
   1.116  /* vi: set ts=4 sw=4 expandtab: */
     2.1 --- a/src/video/ataricommon/SDL_atarievents_c.h	Sat Sep 16 17:13:41 2006 +0000
     2.2 +++ b/src/video/ataricommon/SDL_atarievents_c.h	Wed Sep 20 19:47:09 2006 +0000
     2.3 @@ -35,13 +35,32 @@
     2.4  /* Hidden "this" pointer for the video functions */
     2.5  #define _THIS	SDL_VideoDevice *this
     2.6  
     2.7 +#define ATARIBIOS_MAXKEYS 128
     2.8 +
     2.9 +/* Special keys state */
    2.10 +#ifndef K_RSHIFT
    2.11 +enum {
    2.12 +    K_RSHIFT=0,
    2.13 +    K_LSHIFT,
    2.14 +    K_CTRL,
    2.15 +    K_ALT,
    2.16 +    K_CAPSLOCK,
    2.17 +    K_CLRHOME,
    2.18 +    K_INSERT
    2.19 +};
    2.20 +#endif
    2.21 +
    2.22  extern void (*Atari_ShutdownEvents) (void);
    2.23  
    2.24  extern void Atari_InitOSKeymap(_THIS);
    2.25  extern void Atari_PumpEvents(_THIS);
    2.26  
    2.27 +extern void SDL_Atari_InitInternalKeymap(_THIS);
    2.28 +
    2.29  /* Atari to Unicode charset translation table */
    2.30  extern Uint16 SDL_AtariToUnicodeTable[256];
    2.31 +SDL_keysym *SDL_Atari_TranslateKey(int scancode, SDL_keysym *keysym,
    2.32 +    SDL_bool pressed);
    2.33  
    2.34  #endif /* _SDL_ATARI_EVENTS_H_ */
    2.35  /* vi: set ts=4 sw=4 expandtab: */
     3.1 --- a/src/video/ataricommon/SDL_biosevents.c	Sat Sep 16 17:13:41 2006 +0000
     3.2 +++ b/src/video/ataricommon/SDL_biosevents.c	Wed Sep 20 19:47:09 2006 +0000
     3.3 @@ -39,31 +39,10 @@
     3.4  #include "SDL_xbiosevents_c.h"
     3.5  #include "SDL_ataridevmouse_c.h"
     3.6  
     3.7 -/* To save state of keyboard */
     3.8 -#define ATARIBIOS_MAXKEYS 128
     3.9 -
    3.10  static unsigned char bios_currentkeyboard[ATARIBIOS_MAXKEYS];
    3.11  static unsigned char bios_previouskeyboard[ATARIBIOS_MAXKEYS];
    3.12 -static unsigned char bios_currentascii[ATARIBIOS_MAXKEYS];
    3.13  static SDL_bool use_dev_mouse = SDL_FALSE;
    3.14  
    3.15 -/* Special keys state */
    3.16 -enum
    3.17 -{
    3.18 -    K_RSHIFT = 0,
    3.19 -    K_LSHIFT,
    3.20 -    K_CTRL,
    3.21 -    K_ALT,
    3.22 -    K_CAPSLOCK,
    3.23 -    K_CLRHOME,
    3.24 -    K_INSERT
    3.25 -};
    3.26 -
    3.27 -/* The translation tables from a console scancode to a SDL keysym */
    3.28 -static SDLKey keymap[ATARIBIOS_MAXKEYS];
    3.29 -
    3.30 -static SDL_keysym *TranslateKey(int scancode, int asciicode,
    3.31 -                                SDL_keysym * keysym, SDL_bool pressed);
    3.32  static void UpdateSpecialKeys(int special_keys_state);
    3.33  
    3.34  void
    3.35 @@ -75,36 +54,6 @@
    3.36      SDL_memset(bios_currentkeyboard, 0, sizeof(bios_currentkeyboard));
    3.37      SDL_memset(bios_previouskeyboard, 0, sizeof(bios_previouskeyboard));
    3.38  
    3.39 -    /* Initialize keymap */
    3.40 -    for (i = 0; i < ATARIBIOS_MAXKEYS; i++)
    3.41 -        keymap[i] = SDLK_UNKNOWN;
    3.42 -
    3.43 -    /* Functions keys */
    3.44 -    for (i = 0; i < 10; i++)
    3.45 -        keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
    3.46 -
    3.47 -    /* Cursor keypad */
    3.48 -    keymap[SCANCODE_HELP] = SDLK_HELP;
    3.49 -    keymap[SCANCODE_UNDO] = SDLK_UNDO;
    3.50 -    keymap[SCANCODE_INSERT] = SDLK_INSERT;
    3.51 -    keymap[SCANCODE_CLRHOME] = SDLK_HOME;
    3.52 -    keymap[SCANCODE_UP] = SDLK_UP;
    3.53 -    keymap[SCANCODE_DOWN] = SDLK_DOWN;
    3.54 -    keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
    3.55 -    keymap[SCANCODE_LEFT] = SDLK_LEFT;
    3.56 -
    3.57 -    /* Special keys */
    3.58 -    keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
    3.59 -    keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
    3.60 -    keymap[SCANCODE_TAB] = SDLK_TAB;
    3.61 -    keymap[SCANCODE_ENTER] = SDLK_RETURN;
    3.62 -    keymap[SCANCODE_DELETE] = SDLK_DELETE;
    3.63 -    keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
    3.64 -    keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
    3.65 -    keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
    3.66 -    keymap[SCANCODE_LEFTALT] = SDLK_LALT;
    3.67 -    keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
    3.68 -
    3.69      use_dev_mouse = (SDL_AtariDevMouse_Open() != 0) ? SDL_TRUE : SDL_FALSE;
    3.70  
    3.71      vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;  /* XBIOS joystick events */
    3.72 @@ -129,15 +78,8 @@
    3.73  
    3.74      while (Bconstat(_CON)) {
    3.75          unsigned long key_pressed;
    3.76 -        unsigned char asciicode, scancode;
    3.77 -
    3.78 -        key_pressed = Bconin(_CON);
    3.79 -
    3.80 -        asciicode = key_pressed;
    3.81 -        scancode = key_pressed >> 16;
    3.82 -
    3.83 -        bios_currentkeyboard[scancode] = 0xFF;
    3.84 -        bios_currentascii[scancode] = asciicode;
    3.85 +        key_pressed=Bconin(_CON);
    3.86 +        bios_currentkeyboard[(key_pressed>>16)&(ATARIBIOS_MAXKEYS-1)]=0xFF;
    3.87      }
    3.88  
    3.89      /* Read special keys */
    3.90 @@ -148,14 +90,12 @@
    3.91          /* Key pressed ? */
    3.92          if (bios_currentkeyboard[i] && !bios_previouskeyboard[i])
    3.93              SDL_PrivateKeyboard(SDL_PRESSED,
    3.94 -                                TranslateKey(i, bios_currentascii[i],
    3.95 -                                             &keysym, SDL_TRUE));
    3.96 +                                SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
    3.97  
    3.98          /* Key unpressed ? */
    3.99          if (bios_previouskeyboard[i] && !bios_currentkeyboard[i])
   3.100              SDL_PrivateKeyboard(SDL_RELEASED,
   3.101 -                                TranslateKey(i, bios_currentascii[i],
   3.102 -                                             &keysym, SDL_FALSE));
   3.103 +                                SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
   3.104      }
   3.105  
   3.106      if (use_dev_mouse) {
   3.107 @@ -166,7 +106,7 @@
   3.108  
   3.109      /* Will be previous table */
   3.110      SDL_memcpy(bios_previouskeyboard, bios_currentkeyboard,
   3.111 -               ATARIBIOS_MAXKEYS);
   3.112 +               sizeof(bios_previouskeyboard));
   3.113  }
   3.114  
   3.115  static void
   3.116 @@ -187,27 +127,6 @@
   3.117      UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
   3.118  }
   3.119  
   3.120 -static SDL_keysym *
   3.121 -TranslateKey(int scancode, int asciicode, SDL_keysym * keysym,
   3.122 -             SDL_bool pressed)
   3.123 -{
   3.124 -    /* Set the keysym information */
   3.125 -    keysym->scancode = scancode;
   3.126 -
   3.127 -    if (asciicode)
   3.128 -        keysym->sym = asciicode;
   3.129 -    else
   3.130 -        keysym->sym = keymap[scancode];
   3.131 -
   3.132 -    keysym->mod = KMOD_NONE;
   3.133 -    keysym->unicode = 0;
   3.134 -    if (SDL_TranslateUNICODE && pressed) {
   3.135 -        keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
   3.136 -    }
   3.137 -
   3.138 -    return (keysym);
   3.139 -}
   3.140 -
   3.141  void
   3.142  AtariBios_ShutdownEvents(void)
   3.143  {
     4.1 --- a/src/video/ataricommon/SDL_gemdosevents.c	Sat Sep 16 17:13:41 2006 +0000
     4.2 +++ b/src/video/ataricommon/SDL_gemdosevents.c	Wed Sep 20 19:47:09 2006 +0000
     4.3 @@ -40,36 +40,16 @@
     4.4  #include "SDL_ataridevmouse_c.h"
     4.5  
     4.6  /* To save state of keyboard */
     4.7 -#define ATARIBIOS_MAXKEYS 128
     4.8  
     4.9  static unsigned char gemdos_currentkeyboard[ATARIBIOS_MAXKEYS];
    4.10  static unsigned char gemdos_previouskeyboard[ATARIBIOS_MAXKEYS];
    4.11 -static unsigned char gemdos_currentascii[ATARIBIOS_MAXKEYS];
    4.12  static SDL_bool use_dev_mouse = SDL_FALSE;
    4.13  
    4.14 -/* Special keys state */
    4.15 -enum
    4.16 -{
    4.17 -    K_RSHIFT = 0,
    4.18 -    K_LSHIFT,
    4.19 -    K_CTRL,
    4.20 -    K_ALT,
    4.21 -    K_CAPSLOCK,
    4.22 -    K_CLRHOME,
    4.23 -    K_INSERT
    4.24 +enum {
    4.25 +	DEV_BUSY=0,
    4.26 +	DEV_READY
    4.27  };
    4.28  
    4.29 -enum
    4.30 -{
    4.31 -    DEV_BUSY = 0,
    4.32 -    DEV_READY
    4.33 -};
    4.34 -
    4.35 -/* The translation tables from a console scancode to a SDL keysym */
    4.36 -static SDLKey keymap[ATARIBIOS_MAXKEYS];
    4.37 -
    4.38 -static SDL_keysym *TranslateKey(int scancode, int asciicode,
    4.39 -                                SDL_keysym * keysym, SDL_bool pressed);
    4.40  static void UpdateSpecialKeys(int special_keys_state);
    4.41  
    4.42  void
    4.43 @@ -81,36 +61,6 @@
    4.44      SDL_memset(gemdos_currentkeyboard, 0, sizeof(gemdos_currentkeyboard));
    4.45      SDL_memset(gemdos_previouskeyboard, 0, sizeof(gemdos_previouskeyboard));
    4.46  
    4.47 -    /* Initialize keymap */
    4.48 -    for (i = 0; i < ATARIBIOS_MAXKEYS; i++)
    4.49 -        keymap[i] = SDLK_UNKNOWN;
    4.50 -
    4.51 -    /* Functions keys */
    4.52 -    for (i = 0; i < 10; i++)
    4.53 -        keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
    4.54 -
    4.55 -    /* Cursor keypad */
    4.56 -    keymap[SCANCODE_HELP] = SDLK_HELP;
    4.57 -    keymap[SCANCODE_UNDO] = SDLK_UNDO;
    4.58 -    keymap[SCANCODE_INSERT] = SDLK_INSERT;
    4.59 -    keymap[SCANCODE_CLRHOME] = SDLK_HOME;
    4.60 -    keymap[SCANCODE_UP] = SDLK_UP;
    4.61 -    keymap[SCANCODE_DOWN] = SDLK_DOWN;
    4.62 -    keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
    4.63 -    keymap[SCANCODE_LEFT] = SDLK_LEFT;
    4.64 -
    4.65 -    /* Special keys */
    4.66 -    keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
    4.67 -    keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
    4.68 -    keymap[SCANCODE_TAB] = SDLK_TAB;
    4.69 -    keymap[SCANCODE_ENTER] = SDLK_RETURN;
    4.70 -    keymap[SCANCODE_DELETE] = SDLK_DELETE;
    4.71 -    keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
    4.72 -    keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
    4.73 -    keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
    4.74 -    keymap[SCANCODE_LEFTALT] = SDLK_LALT;
    4.75 -    keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
    4.76 -
    4.77      use_dev_mouse = (SDL_AtariDevMouse_Open() != 0) ? SDL_TRUE : SDL_FALSE;
    4.78  
    4.79      vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;  /* XBIOS joystick events */
    4.80 @@ -134,15 +84,8 @@
    4.81  
    4.82      while (Cconis() != DEV_BUSY) {
    4.83          unsigned long key_pressed;
    4.84 -        unsigned char scancode, asciicode;
    4.85 -
    4.86 -        key_pressed = Cnecin();
    4.87 -
    4.88 -        asciicode = key_pressed;
    4.89 -        scancode = key_pressed >> 16;
    4.90 -
    4.91 -        gemdos_currentkeyboard[scancode] = 0xFF;
    4.92 -        gemdos_currentascii[scancode] = asciicode;
    4.93 +        key_pressed=Cnecin();
    4.94 +        gemdos_currentkeyboard[(key_pressed>>16)&(ATARIBIOS_MAXKEYS-1)]=0xFF;
    4.95      }
    4.96  
    4.97      /* Read special keys */
    4.98 @@ -153,14 +96,12 @@
    4.99          /* Key pressed ? */
   4.100          if (gemdos_currentkeyboard[i] && !gemdos_previouskeyboard[i])
   4.101              SDL_PrivateKeyboard(SDL_PRESSED,
   4.102 -                                TranslateKey(i, gemdos_currentascii[i],
   4.103 -                                             &keysym, SDL_TRUE));
   4.104 +                                SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
   4.105  
   4.106          /* Key unpressed ? */
   4.107          if (gemdos_previouskeyboard[i] && !gemdos_currentkeyboard[i])
   4.108              SDL_PrivateKeyboard(SDL_RELEASED,
   4.109 -                                TranslateKey(i, gemdos_currentascii[i],
   4.110 -                                             &keysym, SDL_FALSE));
   4.111 +                                SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
   4.112      }
   4.113  
   4.114      if (use_dev_mouse) {
   4.115 @@ -171,7 +112,7 @@
   4.116  
   4.117      /* Will be previous table */
   4.118      SDL_memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard,
   4.119 -               ATARIBIOS_MAXKEYS);
   4.120 +               sizeof(gemdos_previouskeyboard));
   4.121  }
   4.122  
   4.123  static void
   4.124 @@ -192,27 +133,6 @@
   4.125      UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
   4.126  }
   4.127  
   4.128 -static SDL_keysym *
   4.129 -TranslateKey(int scancode, int asciicode, SDL_keysym * keysym,
   4.130 -             SDL_bool pressed)
   4.131 -{
   4.132 -    /* Set the keysym information */
   4.133 -    keysym->scancode = scancode;
   4.134 -
   4.135 -    if (asciicode)
   4.136 -        keysym->sym = asciicode;
   4.137 -    else
   4.138 -        keysym->sym = keymap[scancode];
   4.139 -
   4.140 -    keysym->mod = KMOD_NONE;
   4.141 -    keysym->unicode = 0;
   4.142 -    if (SDL_TranslateUNICODE && pressed) {
   4.143 -        keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
   4.144 -    }
   4.145 -
   4.146 -    return (keysym);
   4.147 -}
   4.148 -
   4.149  void
   4.150  AtariGemdos_ShutdownEvents(void)
   4.151  {
     5.1 --- a/src/video/ataricommon/SDL_ikbdevents.c	Sat Sep 16 17:13:41 2006 +0000
     5.2 +++ b/src/video/ataricommon/SDL_ikbdevents.c	Wed Sep 20 19:47:09 2006 +0000
     5.3 @@ -37,88 +37,16 @@
     5.4  #include "SDL_atarievents_c.h"
     5.5  #include "SDL_ikbdinterrupt_s.h"
     5.6  
     5.7 -/* Special keys state */
     5.8 -enum
     5.9 -{
    5.10 -    K_RSHIFT = 0,
    5.11 -    K_LSHIFT,
    5.12 -    K_CTRL,
    5.13 -    K_ALT,
    5.14 -    K_CAPSLOCK,
    5.15 -    K_CLRHOME,
    5.16 -    K_INSERT
    5.17 -};
    5.18 -
    5.19 -#define ATARIBIOS_MAXKEYS 128
    5.20 -
    5.21  #define KEY_PRESSED		0xff
    5.22  #define KEY_UNDEFINED	0x80
    5.23  #define KEY_RELEASED	0x00
    5.24  
    5.25 -/* The translation tables from a console scancode to a SDL keysym */
    5.26 -#define KT_NOCHANGE -1
    5.27 -
    5.28 -enum
    5.29 -{
    5.30 -    KT_UNSHIFT = 0,
    5.31 -    KT_SHIFT = 1,
    5.32 -    KT_CAPS = 2
    5.33 -};
    5.34 -
    5.35  static Uint16 atari_prevmouseb; /* save state of mouse buttons */
    5.36 -static int caps_state;          /* caps lock state */
    5.37 -_KEYTAB *curtables;
    5.38 -static unsigned char *tab_unshift, *tab_shift, *tab_caps;
    5.39 -static SDLKey keymap[ATARIBIOS_MAXKEYS];
    5.40 -
    5.41 -static SDL_keysym *TranslateKey(int scancode, int numkeytable,
    5.42 -                                SDL_keysym * keysym, SDL_bool pressed);
    5.43  
    5.44  void
    5.45  AtariIkbd_InitOSKeymap(_THIS)
    5.46  {
    5.47 -    int i;
    5.48 -
    5.49 -    SDL_memset(SDL_AtariIkbd_keyboard, KEY_UNDEFINED, ATARIBIOS_MAXKEYS);
    5.50 -
    5.51 -    /* Initialize keymap */
    5.52 -    for (i = 0; i < ATARIBIOS_MAXKEYS; i++)
    5.53 -        keymap[i] = SDLK_UNKNOWN;
    5.54 -
    5.55 -    /* Functions keys */
    5.56 -    for (i = 0; i < 10; i++)
    5.57 -        keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
    5.58 -
    5.59 -    /* Cursor keypad */
    5.60 -    keymap[SCANCODE_HELP] = SDLK_HELP;
    5.61 -    keymap[SCANCODE_UNDO] = SDLK_UNDO;
    5.62 -    keymap[SCANCODE_INSERT] = SDLK_INSERT;
    5.63 -    keymap[SCANCODE_CLRHOME] = SDLK_HOME;
    5.64 -    keymap[SCANCODE_UP] = SDLK_UP;
    5.65 -    keymap[SCANCODE_DOWN] = SDLK_DOWN;
    5.66 -    keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
    5.67 -    keymap[SCANCODE_LEFT] = SDLK_LEFT;
    5.68 -
    5.69 -    /* Special keys */
    5.70 -    keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
    5.71 -    keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
    5.72 -    keymap[SCANCODE_TAB] = SDLK_TAB;
    5.73 -    keymap[SCANCODE_ENTER] = SDLK_RETURN;
    5.74 -    keymap[SCANCODE_DELETE] = SDLK_DELETE;
    5.75 -    keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
    5.76 -    keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
    5.77 -    keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
    5.78 -    keymap[SCANCODE_LEFTALT] = SDLK_LALT;
    5.79 -    keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
    5.80 -
    5.81 -    /* Read XBIOS tables for scancode -> ascii translation */
    5.82 -    curtables = Keytbl(KT_NOCHANGE, KT_NOCHANGE, KT_NOCHANGE);
    5.83 -    tab_unshift = curtables->unshift;
    5.84 -    tab_shift = curtables->shift;
    5.85 -    tab_caps = curtables->caps;
    5.86 -
    5.87 -    /* Set Caps lock initial state */
    5.88 -    caps_state = (Kbshift(-1) & (1 << K_CAPSLOCK));
    5.89 +    SDL_memset(SDL_AtariIkbd_keyboard, KEY_UNDEFINED, sizeof(SDL_AtariIkbd_keyboard));
    5.90  
    5.91      /* Now install our handler */
    5.92      SDL_AtariIkbd_mouseb = SDL_AtariIkbd_mousex = SDL_AtariIkbd_mousey = 0;
    5.93 @@ -150,36 +78,19 @@
    5.94  
    5.95          /*--- Send keyboard events ---*/
    5.96  
    5.97 -    /* Update caps lock state */
    5.98 -    if (SDL_AtariIkbd_keyboard[SCANCODE_CAPSLOCK] == KEY_PRESSED) {
    5.99 -        caps_state ^= 1;
   5.100 -    }
   5.101 -
   5.102 -    /* Choose the translation table */
   5.103 -    specialkeys = KT_UNSHIFT;
   5.104 -    if ((SDL_AtariIkbd_keyboard[SCANCODE_LEFTSHIFT] == KEY_PRESSED)
   5.105 -        || (SDL_AtariIkbd_keyboard[SCANCODE_RIGHTSHIFT] == KEY_PRESSED)) {
   5.106 -        specialkeys = KT_SHIFT;
   5.107 -    }
   5.108 -    if (caps_state) {
   5.109 -        specialkeys = KT_CAPS;
   5.110 -    }
   5.111 -
   5.112      /* Now generate events */
   5.113      for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
   5.114          /* Key pressed ? */
   5.115          if (SDL_AtariIkbd_keyboard[i] == KEY_PRESSED) {
   5.116              SDL_PrivateKeyboard(SDL_PRESSED,
   5.117 -                                TranslateKey(i, specialkeys, &keysym,
   5.118 -                                             SDL_TRUE));
   5.119 +                                SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
   5.120              SDL_AtariIkbd_keyboard[i] = KEY_UNDEFINED;
   5.121          }
   5.122  
   5.123          /* Key released ? */
   5.124          if (SDL_AtariIkbd_keyboard[i] == KEY_RELEASED) {
   5.125              SDL_PrivateKeyboard(SDL_RELEASED,
   5.126 -                                TranslateKey(i, specialkeys, &keysym,
   5.127 -                                             SDL_FALSE));
   5.128 +                                SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
   5.129              SDL_AtariIkbd_keyboard[i] = KEY_UNDEFINED;
   5.130          }
   5.131      }
   5.132 @@ -213,42 +124,6 @@
   5.133      }
   5.134  }
   5.135  
   5.136 -static SDL_keysym *
   5.137 -TranslateKey(int scancode, int numkeytable, SDL_keysym * keysym,
   5.138 -             SDL_bool pressed)
   5.139 -{
   5.140 -    unsigned char asciicode;
   5.141 -
   5.142 -    /* Set the keysym information */
   5.143 -    keysym->scancode = scancode;
   5.144 -
   5.145 -    asciicode = 0;
   5.146 -    switch (numkeytable) {
   5.147 -    case KT_UNSHIFT:
   5.148 -        asciicode = tab_unshift[scancode];
   5.149 -        break;
   5.150 -    case KT_SHIFT:
   5.151 -        asciicode = tab_shift[scancode];
   5.152 -        break;
   5.153 -    case KT_CAPS:
   5.154 -        asciicode = tab_caps[scancode];
   5.155 -        break;
   5.156 -    }
   5.157 -
   5.158 -    if (asciicode)
   5.159 -        keysym->sym = asciicode;
   5.160 -    else
   5.161 -        keysym->sym = keymap[scancode];
   5.162 -
   5.163 -    keysym->mod = KMOD_NONE;
   5.164 -    keysym->unicode = 0;
   5.165 -    if (SDL_TranslateUNICODE && pressed) {
   5.166 -        keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
   5.167 -    }
   5.168 -
   5.169 -    return (keysym);
   5.170 -}
   5.171 -
   5.172  void
   5.173  AtariIkbd_ShutdownEvents(void)
   5.174  {
     6.1 --- a/src/video/gem/SDL_gemevents.c	Sat Sep 16 17:13:41 2006 +0000
     6.2 +++ b/src/video/gem/SDL_gemevents.c	Wed Sep 20 19:47:09 2006 +0000
     6.3 @@ -41,91 +41,29 @@
     6.4  #include "../ataricommon/SDL_xbiosevents_c.h"
     6.5  #include "../ataricommon/SDL_ataridevmouse_c.h"
     6.6  
     6.7 -/* Defines */
     6.8 -
     6.9 -#define ATARIBIOS_MAXKEYS 128
    6.10 -
    6.11  /* Variables */
    6.12  
    6.13  static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS];
    6.14  static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
    6.15 -static unsigned char gem_currentascii[ATARIBIOS_MAXKEYS];
    6.16 -
    6.17 -/* The translation tables from a console scancode to a SDL keysym */
    6.18 -static SDLKey keymap[ATARIBIOS_MAXKEYS];
    6.19  
    6.20  /* Functions prototypes */
    6.21  
    6.22 -static SDL_keysym *TranslateKey(int scancode, int asciicode,
    6.23 -                                SDL_keysym * keysym, SDL_bool pressed);
    6.24  static int do_messages(_THIS, short *message);
    6.25  static void do_keyboard(short kc, short ks);
    6.26  static void do_mouse(_THIS, short mx, short my, short mb, short ks);
    6.27  
    6.28  /* Functions */
    6.29  
    6.30 -static SDL_keysym *
    6.31 -TranslateKey(int scancode, int asciicode, SDL_keysym * keysym,
    6.32 -             SDL_bool pressed)
    6.33 -{
    6.34 -    /* Set the keysym information */
    6.35 -    keysym->scancode = scancode;
    6.36 -
    6.37 -    if (asciicode)
    6.38 -        keysym->sym = asciicode;
    6.39 -    else
    6.40 -        keysym->sym = keymap[scancode];
    6.41 -
    6.42 -    keysym->mod = KMOD_NONE;
    6.43 -    keysym->unicode = 0;
    6.44 -    if (SDL_TranslateUNICODE && pressed) {
    6.45 -        keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
    6.46 -    }
    6.47 -
    6.48 -    return (keysym);
    6.49 -}
    6.50 -
    6.51  void
    6.52  GEM_InitOSKeymap(_THIS)
    6.53  {
    6.54 -    int i;
    6.55 -
    6.56      SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
    6.57      SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
    6.58 -    SDL_memset(gem_currentascii, 0, sizeof(gem_currentascii));
    6.59 -
    6.60 -    /* Initialize keymap */
    6.61 -    for (i = 0; i < ATARIBIOS_MAXKEYS; i++)
    6.62 -        keymap[i] = SDLK_UNKNOWN;
    6.63 -
    6.64 -    /* Functions keys */
    6.65 -    for (i = 0; i < 10; i++)
    6.66 -        keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
    6.67 -
    6.68 -    /* Cursor keypad */
    6.69 -    keymap[SCANCODE_HELP] = SDLK_HELP;
    6.70 -    keymap[SCANCODE_UNDO] = SDLK_UNDO;
    6.71 -    keymap[SCANCODE_INSERT] = SDLK_INSERT;
    6.72 -    keymap[SCANCODE_CLRHOME] = SDLK_HOME;
    6.73 -    keymap[SCANCODE_UP] = SDLK_UP;
    6.74 -    keymap[SCANCODE_DOWN] = SDLK_DOWN;
    6.75 -    keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
    6.76 -    keymap[SCANCODE_LEFT] = SDLK_LEFT;
    6.77 -
    6.78 -    /* Special keys */
    6.79 -    keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
    6.80 -    keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
    6.81 -    keymap[SCANCODE_TAB] = SDLK_TAB;
    6.82 -    keymap[SCANCODE_ENTER] = SDLK_RETURN;
    6.83 -    keymap[SCANCODE_DELETE] = SDLK_DELETE;
    6.84 -    keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
    6.85 -    keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
    6.86 -    keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
    6.87 -    keymap[SCANCODE_LEFTALT] = SDLK_LALT;
    6.88 -    keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
    6.89  
    6.90      /* Mouse init */
    6.91      GEM_mouse_relative = SDL_FALSE;
    6.92 +
    6.93 +    SDL_Atari_InitInternalKeymap(this);
    6.94  }
    6.95  
    6.96  void
    6.97 @@ -204,14 +142,12 @@
    6.98          /* Key pressed ? */
    6.99          if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
   6.100              SDL_PrivateKeyboard(SDL_PRESSED,
   6.101 -                                TranslateKey(i, gem_currentascii[i],
   6.102 -                                             &keysym, SDL_TRUE));
   6.103 +                                SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
   6.104  
   6.105          /* Key unpressed ? */
   6.106          if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
   6.107              SDL_PrivateKeyboard(SDL_RELEASED,
   6.108 -                                TranslateKey(i, gem_currentascii[i],
   6.109 -                                             &keysym, SDL_FALSE));
   6.110 +                                SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
   6.111      }
   6.112  
   6.113      SDL_memcpy(gem_previouskeyboard, gem_currentkeyboard,
   6.114 @@ -355,11 +291,8 @@
   6.115      int scancode, asciicode;
   6.116  
   6.117      if (kc) {
   6.118 -        scancode = (kc >> 8) & 127;
   6.119 -        asciicode = kc & 255;
   6.120 -
   6.121 -        gem_currentkeyboard[scancode] = 0xFF;
   6.122 -        gem_currentascii[scancode] = asciicode;
   6.123 +        scancode=(kc>>8) & (ATARIBIOS_MAXKEYS-1);
   6.124 +        gem_currentkeyboard[scancode]=0xFF;
   6.125      }
   6.126  
   6.127      /* Read special keys */