|
|
1.1 root 1: /*
1.1.1.6 root 2: Hatari - keymap.c
1.1.1.5 root 3:
4: This file is distributed under the GNU Public License, version 2 or at
5: your option any later version. Read the file gpl.txt for details.
1.1 root 6:
1.1.1.3 root 7: Here we process a key press and the remapping of the scancodes.
1.1 root 8: */
1.1.1.9 ! root 9: const char Keymap_rcsid[] = "Hatari $Id: keymap.c,v 1.28 2006/08/09 08:14:24 eerot Exp $";
1.1 root 10:
11: #include "main.h"
12: #include "keymap.h"
13: #include "misc.h"
1.1.1.5 root 14: #include "configuration.h"
1.1.1.3 root 15: #include "ikbd.h"
16: #include "joy.h"
17: #include "shortcut.h"
18: #include "screen.h"
1.1.1.4 root 19: #include "debugui.h"
1.1.1.9 ! root 20: #include "log.h"
1.1 root 21:
1.1.1.2 root 22:
23: /*-----------------------------------------------------------------------*/
1.1 root 24: /*
1.1.1.5 root 25: Remap table of PC keys to ST scan codes, -ve is invalid key (ie doesn't occur on ST)
1.1 root 26:
27: PC Keyboard:-
28:
29: Esc F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Print Scroll Pause
30:
31: 1 59 60 61 62 63 64 65 66 67 68 87 88 70 69
32:
33:
34: � ! " � $ % ^ & * ( ) _ + Page
35: ` 1 2 3 4 5 6 7 8 9 0 - = <- Ins Home Up
36:
37: 41 2 3 4 5 6 7 8 9 10 11 12 13 14 82 71 73
38: -- -- --
39: |
40: { } | Page
41: Tab Q W E R T Y U I O P [ ] <---- Del End Down
1.1.1.5 root 42:
1.1 root 43: 15 16 17 18 19 20 21 22 23 24 25 26 27 28 83 79 81
44: -- -- --
45:
46: : @ ~ ^
47: Caps A S D F G H J K L ; ' # |
48:
49: 58 30 31 32 33 34 35 36 37 38 39 40 43 72
50: --
1.1.1.5 root 51:
1.1 root 52: ^ | < > ? ^
53: | \ Z X C V B N M , . / | <- | ->
54:
55: 42 86 44 45 46 47 48 49 50 51 52 53 54 75 80 77
56: -- -- --
57:
58: Ctrl Alt SPACE Alt Gr Ctrl
59:
60: 29 56 57 56 29
61: --
62:
63: And:-
64:
65: Num
66: Lock / * -
67:
68: 69 53 55 74
69: -- --
70:
71: 7 8 9 +
72: Home ^ Pg Up
73:
74: 71 72 73 78
75:
76:
77: 4 5 6
78: <- ->
79:
80: 75 76 77
81:
82:
83: 1 2 3
84: End | Pg Dn Enter
85:
86: 79 70 81 28
87: --
88:
89: 0 .
90: Ins Del
91:
92: 82 83
93:
94:
95: */
96:
97:
1.1.1.5 root 98: /* SDL symbolic key to ST scan code mapping table */
99: static const char SymbolicKeyToSTScanCode[SDLK_LAST] =
100: {
1.1.1.2 root 101: /* ST Code, PC Code */
1.1 root 102: -1, /* 0 */
103: -1, /* 1 */
104: -1, /* 2 */
105: -1, /* 3 */
106: -1, /* 4 */
107: -1, /* 5 */
108: -1, /* 6 */
109: -1, /* 7 */
110: 0x0E, /* SDLK_BACKSPACE=8 */
111: 0x0F, /* SDLK_TAB=9 */
112: -1, /* 10 */
113: -1, /* 11 */
1.1.1.5 root 114: 0x47, /* SDLK_CLEAR = 12 */
1.1 root 115: 0x1C, /* SDLK_RETURN = 13 */
116: -1, /* 14 */
117: -1, /* 15 */
118: -1, /* 16 */
119: -1, /* 17 */
120: -1, /* 18 */
121: -1, /* SDLK_PAUSE = 19 */
122: -1, /* 20 */
123: -1, /* 21 */
124: -1, /* 22 */
125: -1, /* 23 */
126: -1, /* 24 */
127: -1, /* 25 */
128: -1, /* 26 */
129: 0x01, /* SDLK_ESCAPE = 27 */
130: -1, /* 28 */
131: -1, /* 29 */
132: -1, /* 30 */
133: -1, /* 31 */
134: 0x39, /* SDLK_SPACE = 32 */
135: -1, /* SDLK_EXCLAIM = 33 */
136: -1, /* SDLK_QUOTEDBL = 34 */
1.1.1.5 root 137: 0x29, /* SDLK_HASH = 35 */
1.1 root 138: -1, /* SDLK_DOLLAR = 36 */
139: -1, /* 37 */
140: -1, /* SDLK_AMPERSAND = 38 */
141: -1, /* SDLK_QUOTE = 39 */
142: 0x63, /* SDLK_LEFTPAREN = 40 */
143: 0x64, /* SDLK_RIGHTPAREN = 41 */
144: -1, /* SDLK_ASTERISK = 42 */
145: 0x1B, /* SDLK_PLUS = 43 */
146: 0x33, /* SDLK_COMMA = 44 */
147: 0x35, /* SDLK_MINUS = 45 */
148: 0x34, /* SDLK_PERIOD = 46 */
149: -1, /* SDLK_SLASH = 47 */
150: 0x0B, /* SDLK_0 = 48 */
151: 0x02, /* SDLK_1 = 49 */
152: 0x03, /* SDLK_2 = 50 */
153: 0x04, /* SDLK_3 = 51 */
154: 0x05, /* SDLK_4 = 52 */
155: 0x06, /* SDLK_5 = 53 */
156: 0x07, /* SDLK_6 = 54 */
157: 0x08, /* SDLK_7 = 55 */
158: 0x09, /* SDLK_8 = 56 */
159: 0x0A, /* SDLK_9 = 57 */
160: -1, /* SDLK_COLON = 58 */
161: -1, /* SDLK_SEMICOLON = 59 */
162: 0x60, /* SDLK_LESS = 60 */
163: -1, /* SDLK_EQUALS = 61 */
164: -1, /* SDLK_GREATER = 62 */
165: -1, /* SDLK_QUESTION = 63 */
166: -1, /* SDLK_AT = 64 */
167: -1, /* 65 */ /* Skip uppercase letters */
168: -1, /* 66 */
169: -1, /* 67 */
170: -1, /* 68 */
171: -1, /* 69 */
172: -1, /* 70 */
173: -1, /* 71 */
174: -1, /* 72 */
175: -1, /* 73 */
176: -1, /* 74 */
177: -1, /* 75 */
178: -1, /* 76 */
179: -1, /* 77 */
180: -1, /* 78 */
181: -1, /* 79 */
182: -1, /* 80 */
183: -1, /* 81 */
184: -1, /* 82 */
185: -1, /* 83 */
186: -1, /* 84 */
187: -1, /* 85 */
188: -1, /* 86 */
189: -1, /* 87 */
190: -1, /* 88 */
191: -1, /* 89 */
192: -1, /* 90 */
1.1.1.5 root 193: 0x63, /* SDLK_LEFTBRACKET = 91 */
1.1 root 194: -1, /* SDLK_BACKSLASH = 92 */
1.1.1.5 root 195: 0x64, /* SDLK_RIGHTBRACKET = 93 */
196: 0x2B, /* SDLK_CARET = 94 */
1.1 root 197: -1, /* SDLK_UNDERSCORE = 95 */
198: -1, /* SDLK_BACKQUOTE = 96 */
199: 0x1E, /* SDLK_a = 97 */
200: 0x30, /* SDLK_b = 98 */
201: 0x2E, /* SDLK_c = 99 */
202: 0x20, /* SDLK_d = 100 */
203: 0x12, /* SDLK_e = 101 */
204: 0x21, /* SDLK_f = 102 */
205: 0x22, /* SDLK_g = 103 */
206: 0x23, /* SDLK_h = 104 */
207: 0x17, /* SDLK_i = 105 */
208: 0x24, /* SDLK_j = 106 */
209: 0x25, /* SDLK_k = 107 */
210: 0x26, /* SDLK_l = 108 */
211: 0x32, /* SDLK_m = 109 */
212: 0x31, /* SDLK_n = 110 */
213: 0x18, /* SDLK_o = 111 */
214: 0x19, /* SDLK_p = 112 */
215: 0x10, /* SDLK_q = 113 */
216: 0x13, /* SDLK_r = 114 */
217: 0x1F, /* SDLK_s = 115 */
218: 0x14, /* SDLK_t = 116 */
219: 0x16, /* SDLK_u = 117 */
220: 0x2F, /* SDLK_v = 118 */
221: 0x11, /* SDLK_w = 119 */
222: 0x2D, /* SDLK_x = 120 */
223: 0x15, /* SDLK_y = 121 */
224: 0x2C, /* SDLK_z = 122 */
225: -1, /* 123 */
226: -1, /* 124 */
227: -1, /* 125 */
228: -1, /* 126 */
229: 0x53, /* SDLK_DELETE = 127 */
230: /* End of ASCII mapped keysyms */
231: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 128-143*/
232: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 144-159*/
233: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 160-175*/
1.1.1.8 root 234: -1, -1, -1, -1, 0x0D, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 176-191*/
1.1 root 235: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192-207*/
1.1.1.8 root 236: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0x0C, /* 208-223*/
1.1.1.5 root 237: -1, -1, -1, -1, 0x28, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 224-239*/
238: -1, -1, -1, -1, -1, -1, 0x27, -1, -1, -1, -1, -1, 0x1A, -1, -1, -1, /* 240-255*/
1.1 root 239: /* Numeric keypad: */
240: 0x70, /* SDLK_KP0 = 256 */
241: 0x6D, /* SDLK_KP1 = 257 */
242: 0x6E, /* SDLK_KP2 = 258 */
243: 0x6F, /* SDLK_KP3 = 259 */
244: 0x6A, /* SDLK_KP4 = 260 */
245: 0x6B, /* SDLK_KP5 = 261 */
246: 0x6C, /* SDLK_KP6 = 262 */
247: 0x67, /* SDLK_KP7 = 263 */
248: 0x68, /* SDLK_KP8 = 264 */
249: 0x69, /* SDLK_KP9 = 265 */
250: 0x71, /* SDLK_KP_PERIOD = 266 */
251: 0x65, /* SDLK_KP_DIVIDE = 267 */
252: 0x66, /* SDLK_KP_MULTIPLY = 268 */
253: 0x4A, /* SDLK_KP_MINUS = 269 */
254: 0x4E, /* SDLK_KP_PLUS = 270 */
255: 0x72, /* SDLK_KP_ENTER = 271 */
256: -1, /* SDLK_KP_EQUALS = 272 */
257: /* Arrows + Home/End pad */
258: 0x48, /* SDLK_UP = 273 */
259: 0x50, /* SDLK_DOWN = 274 */
260: 0x4D, /* SDLK_RIGHT = 275 */
261: 0x4B, /* SDLK_LEFT = 276 */
262: 0x52, /* SDLK_INSERT = 277 */
263: 0x47, /* SDLK_HOME = 278 */
264: 0x61, /* SDLK_END = 279 */
265: 0x63, /* SDLK_PAGEUP = 280 */
266: 0x64, /* SDLK_PAGEDOWN = 281 */
267: /* Function keys */
268: 0x3B, /* SDLK_F1 = 282 */
269: 0x3C, /* SDLK_F2 = 283 */
270: 0x3D, /* SDLK_F3 = 284 */
271: 0x3E, /* SDLK_F4 = 285 */
272: 0x3F, /* SDLK_F5 = 286 */
273: 0x40, /* SDLK_F6 = 287 */
274: 0x41, /* SDLK_F7 = 288 */
275: 0x42, /* SDLK_F8 = 289 */
276: 0x43, /* SDLK_F9 = 290 */
277: 0x44, /* SDLK_F10 = 291 */
278: -1, /* SDLK_F11 = 292 */
279: -1, /* SDLK_F12 = 293 */
280: -1, /* SDLK_F13 = 294 */
281: -1, /* SDLK_F14 = 295 */
282: -1, /* SDLK_F15 = 296 */
283: -1, /* 297 */
284: -1, /* 298 */
285: -1, /* 299 */
286: /* Key state modifier keys */
1.1.1.5 root 287: -1, /* SDLK_NUMLOCK = 300 */
1.1 root 288: 0x3A, /* SDLK_CAPSLOCK = 301 */
289: 0x61, /* SDLK_SCROLLOCK = 302 */
290: 0x36, /* SDLK_RSHIFT = 303 */
291: 0x2A, /* SDLK_LSHIFT = 304 */
292: 0x1D, /* SDLK_RCTRL = 305 */
293: 0x1D, /* SDLK_LCTRL = 306 */
294: 0x38, /* SDLK_RALT = 307 */
295: 0x38, /* SDLK_LALT = 308 */
296: -1, /* SDLK_RMETA = 309 */
297: -1, /* SDLK_LMETA = 310 */
1.1.1.5 root 298: -1, /* SDLK_LSUPER = 311 */
299: -1, /* SDLK_RSUPER = 312 */
300: -1, /* SDLK_MODE = 313 */ /* "Alt Gr" key */
301: -1, /* SDLK_COMPOSE = 314 */
1.1 root 302: /* Miscellaneous function keys */
303: 0x62, /* SDLK_HELP = 315 */
1.1.1.5 root 304: 0x62, /* SDLK_PRINT = 316 */
1.1 root 305: -1, /* SDLK_SYSREQ = 317 */
306: -1, /* SDLK_BREAK = 318 */
307: -1, /* SDLK_MENU = 319 */
1.1.1.5 root 308: -1, /* SDLK_POWER = 320 */
309: -1, /* SDLK_EURO = 321 */
310: 0x61 /* SDLK_UNDO = 322 */
1.1 root 311: };
312:
1.1.1.5 root 313: /* Table for loaded keys: */
314: static char LoadedKeyToSTScanCode[SDLK_LAST];
315:
316: /* This table is used to translate a symbolic keycode to the (SDL) scancode */
317: static Uint8 SdlSymToSdlScan[SDLK_LAST];
318:
1.1 root 319:
1.1.1.3 root 320: /* List of ST scan codes to NOT de-bounce when running in maximum speed */
1.1.1.9 ! root 321: static const char DebounceExtendedKeys[] =
1.1.1.5 root 322: {
1.1.1.3 root 323: 0x1d, /* CTRL */
324: 0x2a, /* Left SHIFT */
325: 0x01, /* ESC */
326: 0x38, /* ALT */
327: 0x36, /* Right SHIFT */
328: 0 /* term */
329: };
330:
331:
1.1.1.5 root 332:
333: /*-----------------------------------------------------------------------*/
334: /*
335: Initialization.
336: */
337: void Keymap_Init(void)
338: {
1.1.1.7 root 339: memset(SdlSymToSdlScan, 0, sizeof(SdlSymToSdlScan)); /* Clear array */
1.1.1.5 root 340: Keymap_LoadRemapFile(ConfigureParams.Keyboard.szMappingFileName);
341: }
342:
343:
344: /*-----------------------------------------------------------------------*/
345: /*
346: Heuristic analysis to find out the obscure scancode offset.
1.1.1.8 root 347: Some keys like 'z' can't be used for detection since they are on different
348: locations on "qwertz" and "azerty" keyboards.
349: This clever code has originally been taken from the emulator Aranym. (cheers!)
1.1.1.5 root 350: */
351: static int Keymap_FindScanCodeOffset(SDL_keysym* keysym)
352: {
353: int offset = -1; /* uninitialized scancode offset */
354: int scanPC = keysym->scancode;
355:
356: if(scanPC == 0) return -1; /* Ignore illegal scancode */
357:
358: switch(keysym->sym)
359: {
360: case SDLK_ESCAPE: offset = scanPC - 0x01; break;
361: case SDLK_1: offset = scanPC - 0x02; break;
362: case SDLK_2: offset = scanPC - 0x03; break;
363: case SDLK_3: offset = scanPC - 0x04; break;
364: case SDLK_4: offset = scanPC - 0x05; break;
365: case SDLK_5: offset = scanPC - 0x06; break;
366: case SDLK_6: offset = scanPC - 0x07; break;
367: case SDLK_7: offset = scanPC - 0x08; break;
368: case SDLK_8: offset = scanPC - 0x09; break;
369: case SDLK_9: offset = scanPC - 0x0a; break;
370: case SDLK_0: offset = scanPC - 0x0b; break;
371: case SDLK_BACKSPACE: offset = scanPC - 0x0e; break;
372: case SDLK_TAB: offset = scanPC - 0x0f; break;
373: case SDLK_RETURN: offset = scanPC - 0x1c; break;
374: case SDLK_SPACE: offset = scanPC - 0x39; break;
1.1.1.8 root 375: /*case SDLK_q: offset = scanPC - 0x10; break;*/ /* different on azerty */
376: /*case SDLK_w: offset = scanPC - 0x11; break;*/ /* different on azerty */
1.1.1.5 root 377: case SDLK_e: offset = scanPC - 0x12; break;
378: case SDLK_r: offset = scanPC - 0x13; break;
379: case SDLK_t: offset = scanPC - 0x14; break;
1.1.1.8 root 380: /*case SDLK_y: offset = scanPC - 0x15; break;*/ /* different on qwertz */
1.1.1.5 root 381: case SDLK_u: offset = scanPC - 0x16; break;
382: case SDLK_i: offset = scanPC - 0x17; break;
383: case SDLK_o: offset = scanPC - 0x18; break;
384: case SDLK_p: offset = scanPC - 0x19; break;
1.1.1.8 root 385: /*case SDLK_a: offset = scanPC - 0x1e; break;*/ /* different on azerty */
1.1.1.5 root 386: case SDLK_s: offset = scanPC - 0x1f; break;
387: case SDLK_d: offset = scanPC - 0x20; break;
388: case SDLK_f: offset = scanPC - 0x21; break;
389: case SDLK_g: offset = scanPC - 0x22; break;
390: case SDLK_h: offset = scanPC - 0x23; break;
391: case SDLK_j: offset = scanPC - 0x24; break;
392: case SDLK_k: offset = scanPC - 0x25; break;
393: case SDLK_l: offset = scanPC - 0x26; break;
1.1.1.8 root 394: /*case SDLK_z: offset = scanPC - 0x2c; break;*/ /* different on qwertz and azerty */
1.1.1.5 root 395: case SDLK_x: offset = scanPC - 0x2d; break;
396: case SDLK_c: offset = scanPC - 0x2e; break;
397: case SDLK_v: offset = scanPC - 0x2f; break;
398: case SDLK_b: offset = scanPC - 0x30; break;
399: case SDLK_n: offset = scanPC - 0x31; break;
1.1.1.8 root 400: /*case SDLK_m: offset = scanPC - 0x32; break;*/ /* different on azerty */
1.1.1.5 root 401: case SDLK_CAPSLOCK: offset = scanPC - 0x3a; break;
402: case SDLK_LSHIFT: offset = scanPC - 0x2a; break;
403: case SDLK_LCTRL: offset = scanPC - 0x1d; break;
404: case SDLK_LALT: offset = scanPC - 0x38; break;
405: case SDLK_F1: offset = scanPC - 0x3b; break;
406: case SDLK_F2: offset = scanPC - 0x3c; break;
407: case SDLK_F3: offset = scanPC - 0x3d; break;
408: case SDLK_F4: offset = scanPC - 0x3e; break;
409: case SDLK_F5: offset = scanPC - 0x3f; break;
410: case SDLK_F6: offset = scanPC - 0x40; break;
411: case SDLK_F7: offset = scanPC - 0x41; break;
412: case SDLK_F8: offset = scanPC - 0x42; break;
413: case SDLK_F9: offset = scanPC - 0x43; break;
414: case SDLK_F10: offset = scanPC - 0x44; break;
415: default: break;
416: }
417:
418: if (offset != -1)
419: {
420: fprintf(stderr, "Detected scancode offset = %d (key: '%s' with scancode $%02x)\n",
421: offset, SDL_GetKeyName(keysym->sym), scanPC);
422: }
423:
424: return offset;
425: }
426:
427:
428: /*-----------------------------------------------------------------------*/
429: /*
430: Map PC scancode to ST scancode.
431: This code was heavily inspired by the emulator Aranym. (cheers!)
432: */
433: static char Keymap_PcToStScanCode(SDL_keysym* keysym)
434: {
435: static int offset = -1; /* uninitialized scancode offset */
436:
437: switch(keysym->sym)
438: {
439: /* Numeric Pad */
440: /* note that the numbers are handled in Keymap_GetKeyPadScanCode()! */
441: case SDLK_KP_DIVIDE: return 0x65; /* Numpad / */
442: case SDLK_KP_MULTIPLY: return 0x66; /* NumPad * */
443: case SDLK_KP_MINUS: return 0x4a; /* NumPad - */
444: case SDLK_KP_PLUS: return 0x4e; /* NumPad + */
445: case SDLK_KP_PERIOD: return 0x71; /* NumPad . */
446: case SDLK_KP_ENTER: return 0x72; /* NumPad Enter */
447:
448: /* Special Keys */
1.1.1.6 root 449: case SDLK_PAGEUP: return 0x62; /* F11 => Help */
450: case SDLK_PAGEDOWN: return 0x61; /* F12 => Undo */
1.1.1.5 root 451: case SDLK_HOME: return 0x47; /* Home */
452: case SDLK_END: return 0x60; /* End => "<>" on German Atari kbd */
453: case SDLK_UP: return 0x48; /* Arrow Up */
454: case SDLK_LEFT: return 0x4b; /* Arrow Left */
455: case SDLK_RIGHT: return 0x4d; /* Arrow Right */
456: case SDLK_DOWN: return 0x50; /* Arrow Down */
457: case SDLK_INSERT: return 0x52; /* Insert */
458: case SDLK_DELETE: return 0x53; /* Delete */
459: case SDLK_LESS: return 0x60; /* "<" */
460:
461: /* Map Right Alt/Alt Gr/Control to the Atari keys */
462: case SDLK_RCTRL: return 0x1d; /* Control */
463: case SDLK_RALT: return 0x38; /* Alternate */
464:
465: default:
466: {
467: /* Process remaining keys: assume that it's PC101 keyboard
468: * and that it is compatible with Atari ST keyboard (basically
469: * same scancodes but on different platforms with different
470: * base offset (framebuffer = 0, X11 = 8).
471: * Try to detect the offset using a little bit of black magic.
472: * If offset is known then simply pass the scancode. */
473: if (offset == -1)
474: {
475: offset = Keymap_FindScanCodeOffset(keysym);
476: }
477:
478: if (offset >= 0)
479: {
480: /* offset is defined so pass the scancode directly */
1.1.1.8 root 481: return (keysym->scancode - offset);
1.1.1.5 root 482: }
483: else
484: {
1.1.1.8 root 485: /* Failed to detect offset, so use default value 8 */
486: fprintf(stderr, "Offset detection failed with "
487: "key '%s', scancode = 0x%02x, symcode = 0x%02x\n",
488: SDL_GetKeyName(keysym->sym), keysym->scancode, keysym->sym);
489: return (keysym->scancode - 8);
1.1.1.5 root 490: }
491: }
492: }
493: }
494:
495:
496: /*-----------------------------------------------------------------------*/
497: /*
498: Remap a keypad key to ST scan code. We use a separate function for this
499: so that we can easily toggle between number and cursor mode with the
500: numlock key.
501: */
502: static char Keymap_GetKeyPadScanCode(SDL_keysym* pKeySym)
503: {
504: if(SDL_GetModState() & KMOD_NUM)
505: {
506: switch(pKeySym->sym)
507: {
508: case SDLK_KP0: return 0x70; /* NumPad 0 */
509: case SDLK_KP1: return 0x6d; /* NumPad 1 */
510: case SDLK_KP2: return 0x6e; /* NumPad 2 */
511: case SDLK_KP3: return 0x6f; /* NumPad 3 */
512: case SDLK_KP4: return 0x6a; /* NumPad 4 */
513: case SDLK_KP5: return 0x6b; /* NumPad 5 */
514: case SDLK_KP6: return 0x6c; /* NumPad 6 */
515: case SDLK_KP7: return 0x67; /* NumPad 7 */
516: case SDLK_KP8: return 0x68; /* NumPad 8 */
517: case SDLK_KP9: return 0x69; /* NumPad 9 */
518: default: break;
519: }
520: }
521: else
522: {
523: switch(pKeySym->sym)
524: {
525: case SDLK_KP0: return 0x70; /* NumPad 0 */
526: case SDLK_KP1: return 0x6d; /* NumPad 1 */
527: case SDLK_KP2: return 0x50; /* Cursor down */
528: case SDLK_KP3: return 0x6f; /* NumPad 3 */
529: case SDLK_KP4: return 0x4b; /* Cursor left */
530: case SDLK_KP5: return 0x50; /* Cursor down (again?) */
531: case SDLK_KP6: return 0x4d; /* Cursor right */
532: case SDLK_KP7: return 0x52; /* Insert - good for Dungeon Master */
533: case SDLK_KP8: return 0x48; /* Cursor up */
534: case SDLK_KP9: return 0x47; /* Home - again for Dungeon Master */
535: default: break;
536: }
537: }
538:
539: return -1;
540: }
1.1 root 541:
542:
1.1.1.2 root 543: /*-----------------------------------------------------------------------*/
1.1 root 544: /*
545: Remap SDL Key to ST Scan code
546: */
1.1.1.5 root 547: char Keymap_RemapKeyToSTScanCode(SDL_keysym* pKeySym)
1.1 root 548: {
1.1.1.5 root 549: if(pKeySym->sym >= SDLK_LAST) return -1; /* Avoid illegal keys */
550:
551: /* Check for keypad first so we can handle numlock */
552: if(ConfigureParams.Keyboard.nKeymapType != KEYMAP_LOADED)
553: {
554: if(pKeySym->sym >= SDLK_KP0 && pKeySym->sym <= SDLK_KP9)
555: {
556: return Keymap_GetKeyPadScanCode(pKeySym);
557: }
558: }
559:
560: /* Remap from PC scancodes? */
561: if(ConfigureParams.Keyboard.nKeymapType == KEYMAP_SCANCODE)
562: {
563: /* We sometimes enter here with an illegal (=0) scancode, so we keep
564: * track of the right scancodes in a table and then use a value from there.
565: */
566: if(pKeySym->scancode != 0)
567: {
568: SdlSymToSdlScan[pKeySym->sym] = pKeySym->scancode;
569: }
570: else
571: {
572: pKeySym->scancode = SdlSymToSdlScan[pKeySym->sym];
573: if(pKeySym->scancode == 0)
574: fprintf(stderr, "Warning: Key scancode is 0!\n");
575: }
576:
577: return Keymap_PcToStScanCode(pKeySym);
578: }
579:
1.1 root 580: /* Use default or loaded? */
1.1.1.5 root 581: if(ConfigureParams.Keyboard.nKeymapType == KEYMAP_LOADED)
582: return LoadedKeyToSTScanCode[pKeySym->sym];
1.1 root 583: else
1.1.1.5 root 584: return SymbolicKeyToSTScanCode[pKeySym->sym];
1.1 root 585: }
586:
1.1.1.2 root 587:
588: /*-----------------------------------------------------------------------*/
1.1 root 589: /*
590: Load keyboard remap file
591: */
592: void Keymap_LoadRemapFile(char *pszFileName)
593: {
594: char szString[1024];
1.1.1.9 ! root 595: int STScanCode, PCKeyCode;
1.1 root 596: FILE *in;
597:
1.1.1.5 root 598: /* Initialize table with default values */
599: memcpy(LoadedKeyToSTScanCode, SymbolicKeyToSTScanCode, sizeof(LoadedKeyToSTScanCode));
1.1 root 600:
1.1.1.2 root 601: /* Attempt to load file */
1.1.1.5 root 602: if (strlen(pszFileName)>0)
603: {
1.1.1.2 root 604: /* Open file */
1.1 root 605: in = fopen(pszFileName, "r");
1.1.1.5 root 606: if (in)
607: {
608: while(!feof(in))
609: {
1.1.1.2 root 610: /* Read line from file */
1.1.1.5 root 611: fgets(szString, sizeof(szString), in);
1.1.1.2 root 612: /* Remove white-space from start of line */
1.1 root 613: Misc_RemoveWhiteSpace(szString,sizeof(szString));
1.1.1.5 root 614: if (strlen(szString)>0)
615: {
1.1.1.2 root 616: /* Is a comment? */
1.1 root 617: if ( (szString[0]==';') || (szString[0]=='#') )
618: continue;
1.1.1.2 root 619: /* Read values */
1.1.1.5 root 620: sscanf(szString, "%d,%d", &PCKeyCode, &STScanCode);
1.1.1.2 root 621: /* Store into remap table, check both value within range */
1.1.1.9 ! root 622: if ( (PCKeyCode>=0) && (PCKeyCode<SDLK_LAST) &&
! 623: (STScanCode>=0) && (STScanCode<256) )
1.1.1.5 root 624: LoadedKeyToSTScanCode[PCKeyCode] = STScanCode;
1.1 root 625: }
626: }
627:
628: fclose(in);
629: }
1.1.1.9 ! root 630: else
! 631: {
! 632: Log_Printf(LOG_DEBUG,
! 633: "Keymap_LoadRemapFile: failed to open keymap file '%s'\n",
! 634: pszFileName);
! 635: }
1.1 root 636: }
637: }
1.1.1.3 root 638:
639:
640: /*-----------------------------------------------------------------------*/
641: /*
642: Scan list of keys to NOT de-bounce when running in maximum speed, eg ALT,SHIFT,CTRL etc...
643: Return TRUE if key requires de-bouncing
644: */
1.1.1.6 root 645: static BOOL Keymap_DebounceSTKey(char STScanCode)
1.1.1.3 root 646: {
647: int i=0;
648:
649: /* Are we in maximum speed, and have disabled key repeat? */
1.1.1.5 root 650: if((ConfigureParams.System.nMinMaxSpeed!=MINMAXSPEED_MIN) && (ConfigureParams.Keyboard.bDisableKeyRepeat))
651: {
1.1.1.3 root 652: /* We should de-bounce all non extended keys, eg leave ALT,SHIFT,CTRL etc... held */
1.1.1.5 root 653: while (DebounceExtendedKeys[i])
654: {
1.1.1.3 root 655: if (STScanCode==DebounceExtendedKeys[i])
656: return(FALSE);
657: i++;
658: }
659:
660: /* De-bounce key */
661: return(TRUE);
662: }
663:
664: /* Do not de-bounce key */
665: return(FALSE);
666: }
667:
668:
669: /*-----------------------------------------------------------------------*/
670: /*
671: Debounce any PC key held down if running with key repeat disabled
672: This is called each ST frame, so keys get held down for one VBL which is enough for 68000 code to scan
673: */
674: void Keymap_DebounceAllKeys(void)
675: {
1.1.1.9 ! root 676: SDLKey key;
1.1.1.3 root 677: char STScanCode;
1.1.1.5 root 678: SDL_keysym tmpKeySym;
1.1.1.3 root 679:
1.1.1.5 root 680: /* Return if we aren't in maximum speed or have not disabled key repeat */
681: if((ConfigureParams.System.nMinMaxSpeed == MINMAXSPEED_MIN)
682: || (!ConfigureParams.Keyboard.bDisableKeyRepeat))
683: {
684: return;
685: }
686:
1.1.1.9 ! root 687: tmpKeySym.mod = KMOD_NONE;
1.1.1.5 root 688:
689: /* Now run through each PC key looking for ones held down */
1.1.1.9 ! root 690: for(key = SDLK_FIRST; key < SDLK_LAST; key++)
1.1.1.4 root 691: {
1.1.1.5 root 692: /* Is key held? */
693: if(Keyboard.KeyStates[key])
1.1.1.4 root 694: {
1.1.1.5 root 695: tmpKeySym.sym = key;
696: tmpKeySym.scancode = 0;
697:
698: /* Get scan code */
699: STScanCode = Keymap_RemapKeyToSTScanCode(&tmpKeySym);
700: if(STScanCode != (char)-1)
1.1.1.4 root 701: {
1.1.1.5 root 702: /* Does this require de-bouncing? */
703: if(Keymap_DebounceSTKey(STScanCode))
704: Keymap_KeyUp(&tmpKeySym);
1.1.1.3 root 705: }
706: }
707: }
708:
709: }
710:
711:
712: /*-----------------------------------------------------------------------*/
713: /*
714: User press key down
715: */
1.1.1.5 root 716: void Keymap_KeyDown(SDL_keysym *sdlkey)
1.1.1.3 root 717: {
718: BOOL bPreviousKeyState;
719: char STScanCode;
1.1.1.5 root 720: int symkey = sdlkey->sym;
721: int modkey = sdlkey->mod;
1.1.1.3 root 722:
1.1.1.6 root 723: /*fprintf(stderr, "keydown: sym=%i scan=%i mod=$%x\n",symkey, sdlkey->scancode, modkey);*/
1.1.1.3 root 724:
1.1.1.9 ! root 725: if (ShortCut_CheckKeys(modkey, symkey, 1))
1.1.1.8 root 726: return;
1.1.1.3 root 727:
1.1.1.8 root 728: /* If using joystick emulation via keyboard, DON'T send keys to keyboard processor!!!
729: * Some games use keyboard as pause! */
730: if (Joy_KeyDown(symkey, modkey))
731: return;
732:
1.1.1.5 root 733: /* Handle special keys */
1.1.1.6 root 734: if (symkey == SDLK_RALT || symkey == SDLK_LMETA || symkey == SDLK_RMETA
735: || symkey == SDLK_MODE || symkey == SDLK_NUMLOCK)
1.1.1.5 root 736: {
737: /* Ignore modifier keys that aren't passed to the ST */
738: return;
739: }
740: else if(symkey == SDLK_PAUSE && bEnableDebug)
1.1.1.4 root 741: {
1.1.1.5 root 742: /* Call the debugger */
1.1.1.3 root 743: if(bInFullScreen) Screen_ReturnFromFullScreen();
744: DebugUI();
1.1.1.5 root 745: return;
1.1.1.4 root 746: }
1.1.1.5 root 747:
748: /* Set down */
749: bPreviousKeyState = Keyboard.KeyStates[symkey];
750: Keyboard.KeyStates[symkey] = TRUE;
1.1.1.3 root 751:
1.1.1.8 root 752: STScanCode = Keymap_RemapKeyToSTScanCode(sdlkey);
753: if (STScanCode != (char)-1)
1.1.1.4 root 754: {
1.1.1.8 root 755: if (!bPreviousKeyState)
756: IKBD_PressSTKey(STScanCode, TRUE);
1.1.1.4 root 757: }
1.1.1.3 root 758: }
759:
760:
761: /*-----------------------------------------------------------------------*/
762: /*
763: User released key
764: */
1.1.1.5 root 765: void Keymap_KeyUp(SDL_keysym *sdlkey)
1.1.1.3 root 766: {
767: char STScanCode;
1.1.1.5 root 768: int symkey = sdlkey->sym;
769: int modkey = sdlkey->mod;
1.1.1.3 root 770:
1.1.1.6 root 771: /*fprintf(stderr, "keyup: sym=%i scan=%i mod=$%x\n",symkey, sdlkey->scancode, modkey);*/
1.1.1.3 root 772:
1.1.1.8 root 773: /* Ignore short-cut keys here */
1.1.1.9 ! root 774:
! 775: if (ShortCut_CheckKeys(modkey, symkey, 0))
1.1.1.8 root 776: return;
1.1.1.5 root 777:
1.1.1.8 root 778: /* If using keyboard emulation, DON'T send keys to keyboard processor!!!
779: * Some games use keyboard as pause! */
780: if (Joy_KeyUp(symkey, modkey))
781: return;
782:
1.1.1.5 root 783: /* Handle special keys */
1.1.1.6 root 784: if (symkey == SDLK_RALT || symkey == SDLK_LMETA || symkey == SDLK_RMETA
785: || symkey == SDLK_MODE || symkey == SDLK_NUMLOCK)
1.1.1.5 root 786: {
787: /* Ignore modifier keys that aren't passed to the ST */
788: return;
789: }
790: else if(symkey == SDLK_CAPSLOCK)
1.1.1.4 root 791: {
1.1.1.5 root 792: /* Simulate another capslock key press */
793: IKBD_PressSTKey(0x3A, TRUE);
794: }
1.1.1.3 root 795:
796: /* Release key (only if was pressed) */
1.1.1.5 root 797: if(Keyboard.KeyStates[symkey])
1.1.1.4 root 798: {
1.1.1.5 root 799: STScanCode = Keymap_RemapKeyToSTScanCode(sdlkey);
800: if(STScanCode != (char)-1)
801: {
1.1.1.3 root 802: IKBD_PressSTKey(STScanCode,FALSE);
1.1.1.5 root 803: }
1.1.1.3 root 804: }
805:
1.1.1.5 root 806: Keyboard.KeyStates[symkey] = FALSE;
1.1.1.3 root 807: }
808:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.