comparison src/video/gem/SDL_gemevents.c @ 2030:d774e9d7c2a8

Forward keyboard reworking from 1.2
author Patrice Mandin <patmandin@gmail.com>
date Wed, 20 Sep 2006 19:47:09 +0000
parents d20f4510c718
children adf732f1f016
comparison
equal deleted inserted replaced
2029:8640d90b0406 2030:d774e9d7c2a8
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,
60 SDL_keysym * keysym, 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 *
68 TranslateKey(int scancode, int asciicode, SDL_keysym * keysym,
69 SDL_bool pressed)
70 {
71 /* Set the keysym information */
72 keysym->scancode = scancode;
73
74 if (asciicode)
75 keysym->sym = asciicode;
76 else
77 keysym->sym = keymap[scancode];
78
79 keysym->mod = KMOD_NONE;
80 keysym->unicode = 0;
81 if (SDL_TranslateUNICODE && pressed) {
82 keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
83 }
84
85 return (keysym);
86 }
87
88 void 57 void
89 GEM_InitOSKeymap(_THIS) 58 GEM_InitOSKeymap(_THIS)
90 { 59 {
91 int i;
92
93 SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard)); 60 SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
94 SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard)); 61 SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
95 SDL_memset(gem_currentascii, 0, sizeof(gem_currentascii));
96
97 /* Initialize keymap */
98 for (i = 0; i < ATARIBIOS_MAXKEYS; i++)
99 keymap[i] = SDLK_UNKNOWN;
100
101 /* Functions keys */
102 for (i = 0; i < 10; i++)
103 keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
104
105 /* Cursor keypad */
106 keymap[SCANCODE_HELP] = SDLK_HELP;
107 keymap[SCANCODE_UNDO] = SDLK_UNDO;
108 keymap[SCANCODE_INSERT] = SDLK_INSERT;
109 keymap[SCANCODE_CLRHOME] = SDLK_HOME;
110 keymap[SCANCODE_UP] = SDLK_UP;
111 keymap[SCANCODE_DOWN] = SDLK_DOWN;
112 keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
113 keymap[SCANCODE_LEFT] = SDLK_LEFT;
114
115 /* Special keys */
116 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
117 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
118 keymap[SCANCODE_TAB] = SDLK_TAB;
119 keymap[SCANCODE_ENTER] = SDLK_RETURN;
120 keymap[SCANCODE_DELETE] = SDLK_DELETE;
121 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
122 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
123 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
124 keymap[SCANCODE_LEFTALT] = SDLK_LALT;
125 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
126 62
127 /* Mouse init */ 63 /* Mouse init */
128 GEM_mouse_relative = SDL_FALSE; 64 GEM_mouse_relative = SDL_FALSE;
65
66 SDL_Atari_InitInternalKeymap(this);
129 } 67 }
130 68
131 void 69 void
132 GEM_PumpEvents(_THIS) 70 GEM_PumpEvents(_THIS)
133 { 71 {
202 /* Now generate keyboard events */ 140 /* Now generate keyboard events */
203 for (i = 0; i < ATARIBIOS_MAXKEYS; i++) { 141 for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
204 /* Key pressed ? */ 142 /* Key pressed ? */
205 if (gem_currentkeyboard[i] && !gem_previouskeyboard[i]) 143 if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
206 SDL_PrivateKeyboard(SDL_PRESSED, 144 SDL_PrivateKeyboard(SDL_PRESSED,
207 TranslateKey(i, gem_currentascii[i], 145 SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
208 &keysym, SDL_TRUE));
209 146
210 /* Key unpressed ? */ 147 /* Key unpressed ? */
211 if (gem_previouskeyboard[i] && !gem_currentkeyboard[i]) 148 if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
212 SDL_PrivateKeyboard(SDL_RELEASED, 149 SDL_PrivateKeyboard(SDL_RELEASED,
213 TranslateKey(i, gem_currentascii[i], 150 SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
214 &keysym, SDL_FALSE));
215 } 151 }
216 152
217 SDL_memcpy(gem_previouskeyboard, gem_currentkeyboard, 153 SDL_memcpy(gem_previouskeyboard, gem_currentkeyboard,
218 sizeof(gem_previouskeyboard)); 154 sizeof(gem_previouskeyboard));
219 155
353 do_keyboard(short kc, short ks) 289 do_keyboard(short kc, short ks)
354 { 290 {
355 int scancode, asciicode; 291 int scancode, asciicode;
356 292
357 if (kc) { 293 if (kc) {
358 scancode = (kc >> 8) & 127; 294 scancode=(kc>>8) & (ATARIBIOS_MAXKEYS-1);
359 asciicode = kc & 255; 295 gem_currentkeyboard[scancode]=0xFF;
360
361 gem_currentkeyboard[scancode] = 0xFF;
362 gem_currentascii[scancode] = asciicode;
363 } 296 }
364 297
365 /* Read special keys */ 298 /* Read special keys */
366 if (ks & K_RSHIFT) 299 if (ks & K_RSHIFT)
367 gem_currentkeyboard[SCANCODE_RIGHTSHIFT] = 0xFF; 300 gem_currentkeyboard[SCANCODE_RIGHTSHIFT] = 0xFF;