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