comparison src/video/ataricommon/SDL_ikbdevents.c @ 3860:bf1586b58ef2 SDL-1.2

Factorize keyboard mapping between drivers
author Patrice Mandin <patmandin@gmail.com>
date Wed, 13 Sep 2006 21:18:35 +0000
parents f1816773a309
children a1b03ba2fcd0
comparison
equal deleted inserted replaced
3859:5d14acfdf84d 3860:bf1586b58ef2
35 35
36 #include "SDL_atarikeys.h" 36 #include "SDL_atarikeys.h"
37 #include "SDL_atarievents_c.h" 37 #include "SDL_atarievents_c.h"
38 #include "SDL_ikbdinterrupt_s.h" 38 #include "SDL_ikbdinterrupt_s.h"
39 39
40 /* Special keys state */
41 enum {
42 K_RSHIFT=0,
43 K_LSHIFT,
44 K_CTRL,
45 K_ALT,
46 K_CAPSLOCK,
47 K_CLRHOME,
48 K_INSERT
49 };
50
51 #define ATARIBIOS_MAXKEYS 128
52
53 #define KEY_PRESSED 0xff 40 #define KEY_PRESSED 0xff
54 #define KEY_UNDEFINED 0x80 41 #define KEY_UNDEFINED 0x80
55 #define KEY_RELEASED 0x00 42 #define KEY_RELEASED 0x00
56 43
57 /* The translation tables from a console scancode to a SDL keysym */
58 #define KT_NOCHANGE -1
59
60 enum {
61 KT_UNSHIFT=0,
62 KT_SHIFT=1,
63 KT_CAPS=2
64 };
65
66 static Uint16 atari_prevmouseb; /* save state of mouse buttons */ 44 static Uint16 atari_prevmouseb; /* save state of mouse buttons */
67 static int caps_state; /* caps lock state */
68 _KEYTAB *curtables;
69 static unsigned char *tab_unshift, *tab_shift, *tab_caps;
70 static SDLKey keymap[ATARIBIOS_MAXKEYS];
71
72 static SDL_keysym *TranslateKey(int scancode, int numkeytable, SDL_keysym *keysym,
73 SDL_bool pressed);
74 45
75 void AtariIkbd_InitOSKeymap(_THIS) 46 void AtariIkbd_InitOSKeymap(_THIS)
76 { 47 {
77 int i; 48 int i;
78 49
79 SDL_memset(SDL_AtariIkbd_keyboard, KEY_UNDEFINED, ATARIBIOS_MAXKEYS); 50 SDL_memset(SDL_AtariIkbd_keyboard, KEY_UNDEFINED, sizeof(SDL_AtariIkbd_keyboard));
80
81 /* Initialize keymap */
82 for ( i=0; i<ATARIBIOS_MAXKEYS; i++ )
83 keymap[i] = SDLK_UNKNOWN;
84
85 /* Functions keys */
86 for ( i = 0; i<10; i++ )
87 keymap[SCANCODE_F1 + i] = SDLK_F1+i;
88
89 /* Cursor keypad */
90 keymap[SCANCODE_HELP] = SDLK_HELP;
91 keymap[SCANCODE_UNDO] = SDLK_UNDO;
92 keymap[SCANCODE_INSERT] = SDLK_INSERT;
93 keymap[SCANCODE_CLRHOME] = SDLK_HOME;
94 keymap[SCANCODE_UP] = SDLK_UP;
95 keymap[SCANCODE_DOWN] = SDLK_DOWN;
96 keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
97 keymap[SCANCODE_LEFT] = SDLK_LEFT;
98
99 /* Special keys */
100 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
101 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
102 keymap[SCANCODE_TAB] = SDLK_TAB;
103 keymap[SCANCODE_ENTER] = SDLK_RETURN;
104 keymap[SCANCODE_DELETE] = SDLK_DELETE;
105 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
106 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
107 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
108 keymap[SCANCODE_LEFTALT] = SDLK_LALT;
109 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
110
111 /* Read XBIOS tables for scancode -> ascii translation */
112 curtables=Keytbl(KT_NOCHANGE, KT_NOCHANGE, KT_NOCHANGE);
113 tab_unshift=curtables->unshift;
114 tab_shift=curtables->shift;
115 tab_caps=curtables->caps;
116
117 /* Set Caps lock initial state */
118 caps_state=(Kbshift(-1) & (1<<K_CAPSLOCK));
119 51
120 /* Now install our handler */ 52 /* Now install our handler */
121 SDL_AtariIkbd_mouseb = SDL_AtariIkbd_mousex = SDL_AtariIkbd_mousey = 0; 53 SDL_AtariIkbd_mouseb = SDL_AtariIkbd_mousex = SDL_AtariIkbd_mousey = 0;
122 atari_prevmouseb = 0; 54 atari_prevmouseb = 0;
123 55
138 } 70 }
139 } 71 }
140 72
141 void AtariIkbd_PumpEvents(_THIS) 73 void AtariIkbd_PumpEvents(_THIS)
142 { 74 {
143 int i; 75 int i, specialkeys;
144 SDL_keysym keysym; 76 SDL_keysym keysym;
145 int specialkeys;
146 77
147 /*--- Send keyboard events ---*/ 78 /*--- Send keyboard events ---*/
148 79
149 /* Update caps lock state */
150 if (SDL_AtariIkbd_keyboard[SCANCODE_CAPSLOCK]==KEY_PRESSED) {
151 caps_state ^= 1;
152 }
153
154 /* Choose the translation table */
155 specialkeys=KT_UNSHIFT;
156 if ((SDL_AtariIkbd_keyboard[SCANCODE_LEFTSHIFT]==KEY_PRESSED)
157 || (SDL_AtariIkbd_keyboard[SCANCODE_RIGHTSHIFT]==KEY_PRESSED))
158 {
159 specialkeys = KT_SHIFT;
160 }
161 if (caps_state) {
162 specialkeys = KT_CAPS;
163 }
164
165 /* Now generate events */
166 for (i=0; i<ATARIBIOS_MAXKEYS; i++) { 80 for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
167 /* Key pressed ? */ 81 /* Key pressed ? */
168 if (SDL_AtariIkbd_keyboard[i]==KEY_PRESSED) { 82 if (SDL_AtariIkbd_keyboard[i]==KEY_PRESSED) {
169 SDL_PrivateKeyboard(SDL_PRESSED, 83 SDL_PrivateKeyboard(SDL_PRESSED,
170 TranslateKey(i, specialkeys, &keysym, SDL_TRUE)); 84 SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
171 SDL_AtariIkbd_keyboard[i]=KEY_UNDEFINED; 85 SDL_AtariIkbd_keyboard[i]=KEY_UNDEFINED;
172 } 86 }
173 87
174 /* Key released ? */ 88 /* Key released ? */
175 if (SDL_AtariIkbd_keyboard[i]==KEY_RELEASED) { 89 if (SDL_AtariIkbd_keyboard[i]==KEY_RELEASED) {
176 SDL_PrivateKeyboard(SDL_RELEASED, 90 SDL_PrivateKeyboard(SDL_RELEASED,
177 TranslateKey(i, specialkeys, &keysym, SDL_FALSE)); 91 SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
178 SDL_AtariIkbd_keyboard[i]=KEY_UNDEFINED; 92 SDL_AtariIkbd_keyboard[i]=KEY_UNDEFINED;
179 } 93 }
180 } 94 }
181 95
182 /*--- Send mouse events ---*/ 96 /*--- Send mouse events ---*/
204 } 118 }
205 atari_prevmouseb = SDL_AtariIkbd_mouseb; 119 atari_prevmouseb = SDL_AtariIkbd_mouseb;
206 } 120 }
207 } 121 }
208 122
209 static SDL_keysym *TranslateKey(int scancode, int numkeytable, SDL_keysym *keysym,
210 SDL_bool pressed)
211 {
212 unsigned char asciicode;
213
214 /* Set the keysym information */
215 keysym->scancode = scancode;
216
217 asciicode=0;
218 switch(numkeytable) {
219 case KT_UNSHIFT:
220 asciicode=tab_unshift[scancode];
221 break;
222 case KT_SHIFT:
223 asciicode=tab_shift[scancode];
224 break;
225 case KT_CAPS:
226 asciicode=tab_caps[scancode];
227 break;
228 }
229
230 if (asciicode)
231 keysym->sym = asciicode;
232 else
233 keysym->sym = keymap[scancode];
234
235 keysym->mod = KMOD_NONE;
236 keysym->unicode = 0;
237 if (SDL_TranslateUNICODE && pressed) {
238 keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
239 }
240
241 return(keysym);
242 }
243
244 void AtariIkbd_ShutdownEvents(void) 123 void AtariIkbd_ShutdownEvents(void)
245 { 124 {
246 Supexec(SDL_AtariIkbdUninstall); 125 Supexec(SDL_AtariIkbdUninstall);
247 } 126 }