# HG changeset patch # User Patrice Mandin # Date 1158182315 0 # Node ID bf1586b58ef2e0fd738228288bab26f436a1566c # Parent 5d14acfdf84da9b370b0d495a07478eba7bd8b8f Factorize keyboard mapping between drivers diff -r 5d14acfdf84d -r bf1586b58ef2 src/video/ataricommon/SDL_atarievents.c --- a/src/video/ataricommon/SDL_atarievents.c Tue Sep 12 19:34:18 2006 +0000 +++ b/src/video/ataricommon/SDL_atarievents.c Wed Sep 13 21:18:35 2006 +0000 @@ -30,10 +30,13 @@ */ #include +#include +#include #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" @@ -48,6 +51,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 Atari_InitializeEvents(_THIS) @@ -108,10 +119,52 @@ { Atari_InitializeEvents(this); + SDL_Atari_InitInternalKeymap(this); + /* Call choosen routine */ this->InitOSKeymap(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; iscancode = 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); +} diff -r 5d14acfdf84d -r bf1586b58ef2 src/video/ataricommon/SDL_atarievents_c.h --- a/src/video/ataricommon/SDL_atarievents_c.h Tue Sep 12 19:34:18 2006 +0000 +++ b/src/video/ataricommon/SDL_atarievents_c.h Wed Sep 13 21:18:35 2006 +0000 @@ -35,12 +35,31 @@ /* 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_ */ diff -r 5d14acfdf84d -r bf1586b58ef2 src/video/ataricommon/SDL_biosevents.c --- a/src/video/ataricommon/SDL_biosevents.c Tue Sep 12 19:34:18 2006 +0000 +++ b/src/video/ataricommon/SDL_biosevents.c Wed Sep 13 21:18:35 2006 +0000 @@ -39,30 +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 AtariBios_InitOSKeymap(_THIS) @@ -73,45 +53,15 @@ SDL_memset(bios_currentkeyboard, 0, sizeof(bios_currentkeyboard)); SDL_memset(bios_previouskeyboard, 0, sizeof(bios_previouskeyboard)); - /* Initialize keymap */ - for ( i=0; i> 16; - - bios_currentkeyboard[scancode]=0xFF; - bios_currentascii[scancode]=asciicode; + bios_currentkeyboard[(key_pressed>>16)&(ATARIBIOS_MAXKEYS-1)]=0xFF; } /* Read special keys */ @@ -145,12 +88,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) { @@ -160,7 +103,7 @@ } /* Will be previous table */ - SDL_memcpy(bios_previouskeyboard, bios_currentkeyboard, ATARIBIOS_MAXKEYS); + SDL_memcpy(bios_previouskeyboard, bios_currentkeyboard, sizeof(bios_previouskeyboard)); } static void UpdateSpecialKeys(int special_keys_state) @@ -169,7 +112,6 @@ { \ if (special_keys_state & (1<<(numbit))) { \ bios_currentkeyboard[scancode]=0xFF; \ - bios_currentascii[scancode]=0; \ } \ } @@ -180,26 +122,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) { SDL_AtariXbios_RestoreVectors(); diff -r 5d14acfdf84d -r bf1586b58ef2 src/video/ataricommon/SDL_gemdosevents.c --- a/src/video/ataricommon/SDL_gemdosevents.c Tue Sep 12 19:34:18 2006 +0000 +++ b/src/video/ataricommon/SDL_gemdosevents.c Wed Sep 13 21:18:35 2006 +0000 @@ -40,34 +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 }; -/* 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 AtariGemdos_InitOSKeymap(_THIS) @@ -78,45 +60,15 @@ SDL_memset(gemdos_currentkeyboard, 0, sizeof(gemdos_currentkeyboard)); SDL_memset(gemdos_previouskeyboard, 0, sizeof(gemdos_previouskeyboard)); - /* Initialize keymap */ - for ( i=0; i> 16; - - gemdos_currentkeyboard[scancode]=0xFF; - gemdos_currentascii[scancode]=asciicode; + gemdos_currentkeyboard[(key_pressed>>16)&(ATARIBIOS_MAXKEYS-1)]=0xFF; } /* Read special keys */ @@ -149,12 +94,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) { @@ -164,7 +109,7 @@ } /* Will be previous table */ - SDL_memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard, ATARIBIOS_MAXKEYS); + SDL_memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard, sizeof(gemdos_previouskeyboard)); } static void UpdateSpecialKeys(int special_keys_state) @@ -173,7 +118,6 @@ { \ if (special_keys_state & (1<<(numbit))) { \ gemdos_currentkeyboard[scancode]=0xFF; \ - gemdos_currentascii[scancode]=0; \ } \ } @@ -184,26 +128,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) { SDL_AtariXbios_RestoreVectors(); diff -r 5d14acfdf84d -r bf1586b58ef2 src/video/ataricommon/SDL_ikbdevents.c --- a/src/video/ataricommon/SDL_ikbdevents.c Tue Sep 12 19:34:18 2006 +0000 +++ b/src/video/ataricommon/SDL_ikbdevents.c Wed Sep 13 21:18:35 2006 +0000 @@ -37,85 +37,17 @@ #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 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<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) { Supexec(SDL_AtariIkbdUninstall);