comparison src/video/ataricommon/SDL_ikbdevents.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
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 {
43 K_RSHIFT = 0,
44 K_LSHIFT,
45 K_CTRL,
46 K_ALT,
47 K_CAPSLOCK,
48 K_CLRHOME,
49 K_INSERT
50 };
51
52 #define ATARIBIOS_MAXKEYS 128
53
54 #define KEY_PRESSED 0xff 40 #define KEY_PRESSED 0xff
55 #define KEY_UNDEFINED 0x80 41 #define KEY_UNDEFINED 0x80
56 #define KEY_RELEASED 0x00 42 #define KEY_RELEASED 0x00
57 43
58 /* The translation tables from a console scancode to a SDL keysym */
59 #define KT_NOCHANGE -1
60
61 enum
62 {
63 KT_UNSHIFT = 0,
64 KT_SHIFT = 1,
65 KT_CAPS = 2
66 };
67
68 static Uint16 atari_prevmouseb; /* save state of mouse buttons */ 44 static Uint16 atari_prevmouseb; /* save state of mouse buttons */
69 static int caps_state; /* caps lock state */
70 _KEYTAB *curtables;
71 static unsigned char *tab_unshift, *tab_shift, *tab_caps;
72 static SDLKey keymap[ATARIBIOS_MAXKEYS];
73
74 static SDL_keysym *TranslateKey(int scancode, int numkeytable,
75 SDL_keysym * keysym, SDL_bool pressed);
76 45
77 void 46 void
78 AtariIkbd_InitOSKeymap(_THIS) 47 AtariIkbd_InitOSKeymap(_THIS)
79 { 48 {
80 int i; 49 SDL_memset(SDL_AtariIkbd_keyboard, KEY_UNDEFINED, sizeof(SDL_AtariIkbd_keyboard));
81
82 SDL_memset(SDL_AtariIkbd_keyboard, KEY_UNDEFINED, ATARIBIOS_MAXKEYS);
83
84 /* Initialize keymap */
85 for (i = 0; i < ATARIBIOS_MAXKEYS; i++)
86 keymap[i] = SDLK_UNKNOWN;
87
88 /* Functions keys */
89 for (i = 0; i < 10; i++)
90 keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
91
92 /* Cursor keypad */
93 keymap[SCANCODE_HELP] = SDLK_HELP;
94 keymap[SCANCODE_UNDO] = SDLK_UNDO;
95 keymap[SCANCODE_INSERT] = SDLK_INSERT;
96 keymap[SCANCODE_CLRHOME] = SDLK_HOME;
97 keymap[SCANCODE_UP] = SDLK_UP;
98 keymap[SCANCODE_DOWN] = SDLK_DOWN;
99 keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
100 keymap[SCANCODE_LEFT] = SDLK_LEFT;
101
102 /* Special keys */
103 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
104 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
105 keymap[SCANCODE_TAB] = SDLK_TAB;
106 keymap[SCANCODE_ENTER] = SDLK_RETURN;
107 keymap[SCANCODE_DELETE] = SDLK_DELETE;
108 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
109 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
110 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
111 keymap[SCANCODE_LEFTALT] = SDLK_LALT;
112 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
113
114 /* Read XBIOS tables for scancode -> ascii translation */
115 curtables = Keytbl(KT_NOCHANGE, KT_NOCHANGE, KT_NOCHANGE);
116 tab_unshift = curtables->unshift;
117 tab_shift = curtables->shift;
118 tab_caps = curtables->caps;
119
120 /* Set Caps lock initial state */
121 caps_state = (Kbshift(-1) & (1 << K_CAPSLOCK));
122 50
123 /* Now install our handler */ 51 /* Now install our handler */
124 SDL_AtariIkbd_mouseb = SDL_AtariIkbd_mousex = SDL_AtariIkbd_mousey = 0; 52 SDL_AtariIkbd_mouseb = SDL_AtariIkbd_mousex = SDL_AtariIkbd_mousey = 0;
125 atari_prevmouseb = 0; 53 atari_prevmouseb = 0;
126 54
148 SDL_keysym keysym; 76 SDL_keysym keysym;
149 int specialkeys; 77 int specialkeys;
150 78
151 /*--- Send keyboard events ---*/ 79 /*--- Send keyboard events ---*/
152 80
153 /* Update caps lock state */
154 if (SDL_AtariIkbd_keyboard[SCANCODE_CAPSLOCK] == KEY_PRESSED) {
155 caps_state ^= 1;
156 }
157
158 /* Choose the translation table */
159 specialkeys = KT_UNSHIFT;
160 if ((SDL_AtariIkbd_keyboard[SCANCODE_LEFTSHIFT] == KEY_PRESSED)
161 || (SDL_AtariIkbd_keyboard[SCANCODE_RIGHTSHIFT] == KEY_PRESSED)) {
162 specialkeys = KT_SHIFT;
163 }
164 if (caps_state) {
165 specialkeys = KT_CAPS;
166 }
167
168 /* Now generate events */ 81 /* Now generate events */
169 for (i = 0; i < ATARIBIOS_MAXKEYS; i++) { 82 for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
170 /* Key pressed ? */ 83 /* Key pressed ? */
171 if (SDL_AtariIkbd_keyboard[i] == KEY_PRESSED) { 84 if (SDL_AtariIkbd_keyboard[i] == KEY_PRESSED) {
172 SDL_PrivateKeyboard(SDL_PRESSED, 85 SDL_PrivateKeyboard(SDL_PRESSED,
173 TranslateKey(i, specialkeys, &keysym, 86 SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
174 SDL_TRUE));
175 SDL_AtariIkbd_keyboard[i] = KEY_UNDEFINED; 87 SDL_AtariIkbd_keyboard[i] = KEY_UNDEFINED;
176 } 88 }
177 89
178 /* Key released ? */ 90 /* Key released ? */
179 if (SDL_AtariIkbd_keyboard[i] == KEY_RELEASED) { 91 if (SDL_AtariIkbd_keyboard[i] == KEY_RELEASED) {
180 SDL_PrivateKeyboard(SDL_RELEASED, 92 SDL_PrivateKeyboard(SDL_RELEASED,
181 TranslateKey(i, specialkeys, &keysym, 93 SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
182 SDL_FALSE));
183 SDL_AtariIkbd_keyboard[i] = KEY_UNDEFINED; 94 SDL_AtariIkbd_keyboard[i] = KEY_UNDEFINED;
184 } 95 }
185 } 96 }
186 97
187 /*--- Send mouse events ---*/ 98 /*--- Send mouse events ---*/
211 } 122 }
212 atari_prevmouseb = SDL_AtariIkbd_mouseb; 123 atari_prevmouseb = SDL_AtariIkbd_mouseb;
213 } 124 }
214 } 125 }
215 126
216 static SDL_keysym *
217 TranslateKey(int scancode, int numkeytable, SDL_keysym * keysym,
218 SDL_bool pressed)
219 {
220 unsigned char asciicode;
221
222 /* Set the keysym information */
223 keysym->scancode = scancode;
224
225 asciicode = 0;
226 switch (numkeytable) {
227 case KT_UNSHIFT:
228 asciicode = tab_unshift[scancode];
229 break;
230 case KT_SHIFT:
231 asciicode = tab_shift[scancode];
232 break;
233 case KT_CAPS:
234 asciicode = tab_caps[scancode];
235 break;
236 }
237
238 if (asciicode)
239 keysym->sym = asciicode;
240 else
241 keysym->sym = keymap[scancode];
242
243 keysym->mod = KMOD_NONE;
244 keysym->unicode = 0;
245 if (SDL_TranslateUNICODE && pressed) {
246 keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
247 }
248
249 return (keysym);
250 }
251
252 void 127 void
253 AtariIkbd_ShutdownEvents(void) 128 AtariIkbd_ShutdownEvents(void)
254 { 129 {
255 Supexec(SDL_AtariIkbdUninstall); 130 Supexec(SDL_AtariIkbdUninstall);
256 } 131 }