comparison src/video/gem/SDL_gemevents.c @ 3861:c3625a895caf SDL-1.2

Use new keyboard mapping routines
author Patrice Mandin <patmandin@gmail.com>
date Wed, 13 Sep 2006 21:19:13 +0000
parents f1816773a309
children 57b017e6aebf
comparison
equal deleted inserted replaced
3860:bf1586b58ef2 3861:c3625a895caf
39 #include "../ataricommon/SDL_atarikeys.h" /* for keyboard scancodes */ 39 #include "../ataricommon/SDL_atarikeys.h" /* for keyboard scancodes */
40 #include "../ataricommon/SDL_atarievents_c.h" 40 #include "../ataricommon/SDL_atarievents_c.h"
41 #include "../ataricommon/SDL_xbiosevents_c.h" 41 #include "../ataricommon/SDL_xbiosevents_c.h"
42 #include "../ataricommon/SDL_ataridevmouse_c.h" 42 #include "../ataricommon/SDL_ataridevmouse_c.h"
43 43
44 /* Defines */
45
46 #define ATARIBIOS_MAXKEYS 128
47
48 /* Variables */ 44 /* Variables */
49 45
50 static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS]; 46 static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS];
51 static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS]; 47 static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
52 static unsigned char gem_currentascii[ATARIBIOS_MAXKEYS];
53
54 /* The translation tables from a console scancode to a SDL keysym */
55 static SDLKey keymap[ATARIBIOS_MAXKEYS];
56 48
57 /* Functions prototypes */ 49 /* Functions prototypes */
58 50
59 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
60 SDL_bool pressed);
61 static int do_messages(_THIS, short *message); 51 static int do_messages(_THIS, short *message);
62 static void do_keyboard(short kc, short ks); 52 static void do_keyboard(short kc, short ks);
63 static void do_mouse(_THIS, short mx, short my, short mb, short ks); 53 static void do_mouse(_THIS, short mx, short my, short mb, short ks);
64 54
65 /* Functions */ 55 /* Functions */
66 56
67 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
68 SDL_bool pressed)
69 {
70 /* Set the keysym information */
71 keysym->scancode = scancode;
72
73 if (asciicode)
74 keysym->sym = asciicode;
75 else
76 keysym->sym = keymap[scancode];
77
78 keysym->mod = KMOD_NONE;
79 keysym->unicode = 0;
80 if (SDL_TranslateUNICODE && pressed) {
81 keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
82 }
83
84 return(keysym);
85 }
86
87 void GEM_InitOSKeymap(_THIS) 57 void GEM_InitOSKeymap(_THIS)
88 { 58 {
89 int i;
90
91 SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard)); 59 SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
92 SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard)); 60 SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
93 SDL_memset(gem_currentascii, 0, sizeof(gem_currentascii));
94
95 /* Initialize keymap */
96 for ( i=0; i<ATARIBIOS_MAXKEYS; i++ )
97 keymap[i] = SDLK_UNKNOWN;
98
99 /* Functions keys */
100 for ( i = 0; i<10; i++ )
101 keymap[SCANCODE_F1 + i] = SDLK_F1+i;
102
103 /* Cursor keypad */
104 keymap[SCANCODE_HELP] = SDLK_HELP;
105 keymap[SCANCODE_UNDO] = SDLK_UNDO;
106 keymap[SCANCODE_INSERT] = SDLK_INSERT;
107 keymap[SCANCODE_CLRHOME] = SDLK_HOME;
108 keymap[SCANCODE_UP] = SDLK_UP;
109 keymap[SCANCODE_DOWN] = SDLK_DOWN;
110 keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
111 keymap[SCANCODE_LEFT] = SDLK_LEFT;
112
113 /* Special keys */
114 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
115 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
116 keymap[SCANCODE_TAB] = SDLK_TAB;
117 keymap[SCANCODE_ENTER] = SDLK_RETURN;
118 keymap[SCANCODE_DELETE] = SDLK_DELETE;
119 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
120 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
121 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
122 keymap[SCANCODE_LEFTALT] = SDLK_LALT;
123 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
124 61
125 /* Mouse init */ 62 /* Mouse init */
126 GEM_mouse_relative = SDL_FALSE; 63 GEM_mouse_relative = SDL_FALSE;
64
65 SDL_Atari_InitInternalKeymap(this);
127 } 66 }
128 67
129 void GEM_PumpEvents(_THIS) 68 void GEM_PumpEvents(_THIS)
130 { 69 {
131 short mousex, mousey, mouseb, dummy; 70 short mousex, mousey, mouseb, dummy;
214 /* Now generate keyboard events */ 153 /* Now generate keyboard events */
215 for (i=0; i<ATARIBIOS_MAXKEYS; i++) { 154 for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
216 /* Key pressed ? */ 155 /* Key pressed ? */
217 if (gem_currentkeyboard[i] && !gem_previouskeyboard[i]) 156 if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
218 SDL_PrivateKeyboard(SDL_PRESSED, 157 SDL_PrivateKeyboard(SDL_PRESSED,
219 TranslateKey(i, gem_currentascii[i], &keysym, SDL_TRUE)); 158 SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
220 159
221 /* Key unpressed ? */ 160 /* Key unpressed ? */
222 if (gem_previouskeyboard[i] && !gem_currentkeyboard[i]) 161 if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
223 SDL_PrivateKeyboard(SDL_RELEASED, 162 SDL_PrivateKeyboard(SDL_RELEASED,
224 TranslateKey(i, gem_currentascii[i], &keysym, SDL_FALSE)); 163 SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
225 } 164 }
226 165
227 SDL_memcpy(gem_previouskeyboard,gem_currentkeyboard,sizeof(gem_previouskeyboard)); 166 SDL_memcpy(gem_previouskeyboard,gem_currentkeyboard,sizeof(gem_previouskeyboard));
228 167
229 /* Refresh window name ? */ 168 /* Refresh window name ? */
339 return quit; 278 return quit;
340 } 279 }
341 280
342 static void do_keyboard(short kc, short ks) 281 static void do_keyboard(short kc, short ks)
343 { 282 {
344 int scancode, asciicode; 283 int scancode;
345 284
346 if (kc) { 285 if (kc) {
347 scancode=(kc>>8) & 127; 286 scancode=(kc>>8) & (ATARIBIOS_MAXKEYS-1);
348 asciicode=kc & 255;
349
350 gem_currentkeyboard[scancode]=0xFF; 287 gem_currentkeyboard[scancode]=0xFF;
351 gem_currentascii[scancode]=asciicode;
352 } 288 }
353 289
354 /* Read special keys */ 290 /* Read special keys */
355 if (ks & K_RSHIFT) 291 if (ks & K_RSHIFT)
356 gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF; 292 gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;