Annotation of frontvm/src/keymap.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.