Annotation of hatari/src/keymap.c, revision 1.1.1.2

1.1       root        1: /*
                      2:   Hatari
                      3: 
                      4:   Key remapping functions
                      5: */
                      6: 
                      7: #include <stdio.h>
1.1.1.2 ! root        8: #include <SDL_keysym.h>           /* Needed for SDLK_LAST */
1.1       root        9: 
                     10: #include "main.h"
                     11: #include "debug.h"
                     12: #include "keymap.h"
                     13: #include "memAlloc.h"
                     14: #include "misc.h"
                     15: 
1.1.1.2 ! root       16: 
        !            17: /*-----------------------------------------------------------------------*/
1.1       root       18: /*
                     19:   Remap table of Windows 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 Key to ST scan code map table */
1.1.1.2 ! root       93: char Default_KeyToSTScanCode[SDLK_LAST] = {
        !            94: /* ST Code,  PC Code */
1.1       root       95:   -1,    /* 0 */
                     96:   -1,    /* 1 */
                     97:   -1,    /* 2 */
                     98:   -1,    /* 3 */
                     99:   -1,    /* 4 */
                    100:   -1,    /* 5 */
                    101:   -1,    /* 6 */
                    102:   -1,    /* 7 */
                    103:   0x0E,  /* SDLK_BACKSPACE=8 */
                    104:   0x0F,  /* SDLK_TAB=9 */
                    105:   -1,    /* 10 */
                    106:   -1,    /* 11 */
                    107:   -1,    /* SDLK_CLEAR = 12 */
                    108:   0x1C,  /* SDLK_RETURN = 13 */
                    109:   -1,    /* 14 */
                    110:   -1,    /* 15 */
                    111:   -1,    /* 16 */
                    112:   -1,    /* 17 */
                    113:   -1,    /* 18 */
                    114:   -1,    /* SDLK_PAUSE = 19 */
                    115:   -1,    /* 20 */
                    116:   -1,    /* 21 */
                    117:   -1,    /* 22 */
                    118:   -1,    /* 23 */
                    119:   -1,    /* 24 */
                    120:   -1,    /* 25 */
                    121:   -1,    /* 26 */
                    122:   0x01,  /* SDLK_ESCAPE = 27 */
                    123:   -1,    /* 28 */
                    124:   -1,    /* 29 */
                    125:   -1,    /* 30 */
                    126:   -1,    /* 31 */
                    127:   0x39,  /* SDLK_SPACE = 32 */
                    128:   -1,    /* SDLK_EXCLAIM = 33 */
                    129:   -1,    /* SDLK_QUOTEDBL = 34 */
                    130:   -1,    /* SDLK_HASH = 35 */
                    131:   -1,    /* SDLK_DOLLAR = 36 */
                    132:   -1,    /* 37 */
                    133:   -1,    /* SDLK_AMPERSAND = 38 */
                    134:   -1,    /* SDLK_QUOTE = 39 */
                    135:   0x63,  /* SDLK_LEFTPAREN = 40 */
                    136:   0x64,  /* SDLK_RIGHTPAREN = 41 */
                    137:   -1,    /* SDLK_ASTERISK = 42 */
                    138:   0x1B,  /* SDLK_PLUS = 43 */
                    139:   0x33,  /* SDLK_COMMA = 44 */
                    140:   0x35,  /* SDLK_MINUS = 45 */
                    141:   0x34,  /* SDLK_PERIOD = 46 */
                    142:   -1,    /* SDLK_SLASH = 47 */
                    143:   0x0B,  /* SDLK_0 = 48 */
                    144:   0x02,  /* SDLK_1 = 49 */
                    145:   0x03,  /* SDLK_2 = 50 */
                    146:   0x04,  /* SDLK_3 = 51 */
                    147:   0x05,  /* SDLK_4 = 52 */
                    148:   0x06,  /* SDLK_5 = 53 */
                    149:   0x07,  /* SDLK_6 = 54 */
                    150:   0x08,  /* SDLK_7 = 55 */
                    151:   0x09,  /* SDLK_8 = 56 */
                    152:   0x0A,  /* SDLK_9 = 57 */
                    153:   -1,    /* SDLK_COLON = 58 */
                    154:   -1,    /* SDLK_SEMICOLON = 59 */
                    155:   0x60,  /* SDLK_LESS = 60 */
                    156:   -1,    /* SDLK_EQUALS = 61 */
                    157:   -1,    /* SDLK_GREATER  = 62 */
                    158:   -1,    /* SDLK_QUESTION = 63 */
                    159:   -1,    /* SDLK_AT = 64 */
                    160:   -1,    /* 65 */  /* Skip uppercase letters */
                    161:   -1,    /* 66 */
                    162:   -1,    /* 67 */
                    163:   -1,    /* 68 */
                    164:   -1,    /* 69 */
                    165:   -1,    /* 70 */
                    166:   -1,    /* 71 */
                    167:   -1,    /* 72 */
                    168:   -1,    /* 73 */
                    169:   -1,    /* 74 */
                    170:   -1,    /* 75 */
                    171:   -1,    /* 76 */
                    172:   -1,    /* 77 */
                    173:   -1,    /* 78 */
                    174:   -1,    /* 79 */
                    175:   -1,    /* 80 */
                    176:   -1,    /* 81 */
                    177:   -1,    /* 82 */
                    178:   -1,    /* 83 */
                    179:   -1,    /* 84 */
                    180:   -1,    /* 85 */
                    181:   -1,    /* 86 */
                    182:   -1,    /* 87 */
                    183:   -1,    /* 88 */
                    184:   -1,    /* 89 */
                    185:   -1,    /* 90 */
                    186:   -1,    /* SDLK_LEFTBRACKET = 91 */
                    187:   -1,    /* SDLK_BACKSLASH = 92 */
                    188:   -1,    /* SDLK_RIGHTBRACKET = 93 */
                    189:   -1,    /* SDLK_CARET = 94 */
                    190:   -1,    /* SDLK_UNDERSCORE = 95 */
                    191:   -1,    /* SDLK_BACKQUOTE = 96 */
                    192:   0x1E,  /* SDLK_a = 97 */
                    193:   0x30,  /* SDLK_b = 98 */
                    194:   0x2E,  /* SDLK_c = 99 */
                    195:   0x20,  /* SDLK_d = 100 */
                    196:   0x12,  /* SDLK_e = 101 */
                    197:   0x21,  /* SDLK_f = 102 */
                    198:   0x22,  /* SDLK_g = 103 */
                    199:   0x23,  /* SDLK_h = 104 */
                    200:   0x17,  /* SDLK_i = 105 */
                    201:   0x24,  /* SDLK_j = 106 */
                    202:   0x25,  /* SDLK_k = 107 */
                    203:   0x26,  /* SDLK_l = 108 */
                    204:   0x32,  /* SDLK_m = 109 */
                    205:   0x31,  /* SDLK_n = 110 */
                    206:   0x18,  /* SDLK_o = 111 */
                    207:   0x19,  /* SDLK_p = 112 */
                    208:   0x10,  /* SDLK_q = 113 */
                    209:   0x13,  /* SDLK_r = 114 */
                    210:   0x1F,  /* SDLK_s = 115 */
                    211:   0x14,  /* SDLK_t = 116 */
                    212:   0x16,  /* SDLK_u = 117 */
                    213:   0x2F,  /* SDLK_v = 118 */
                    214:   0x11,  /* SDLK_w = 119 */
                    215:   0x2D,  /* SDLK_x = 120 */
                    216:   0x15,  /* SDLK_y = 121 */
                    217:   0x2C,  /* SDLK_z = 122 */
                    218:   -1,    /* 123 */
                    219:   -1,    /* 124 */
                    220:   -1,    /* 125 */
                    221:   -1,    /* 126 */
                    222:   0x53,  /* SDLK_DELETE = 127 */
                    223:   /* End of ASCII mapped keysyms */
                    224:   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 128-143*/
                    225:   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 144-159*/
                    226:   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 160-175*/
                    227:   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 176-191*/
                    228:   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192-207*/
                    229:   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 208-223*/
                    230:   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 224-239*/
                    231:   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 240-255*/
                    232:   /* Numeric keypad: */
                    233:   0x70,    /* SDLK_KP0 = 256 */
                    234:   0x6D,    /* SDLK_KP1 = 257 */
                    235:   0x6E,    /* SDLK_KP2 = 258 */
                    236:   0x6F,    /* SDLK_KP3 = 259 */
                    237:   0x6A,    /* SDLK_KP4 = 260 */
                    238:   0x6B,    /* SDLK_KP5 = 261 */
                    239:   0x6C,    /* SDLK_KP6 = 262 */
                    240:   0x67,    /* SDLK_KP7 = 263 */
                    241:   0x68,    /* SDLK_KP8 = 264 */
                    242:   0x69,    /* SDLK_KP9 = 265 */
                    243:   0x71,    /* SDLK_KP_PERIOD = 266 */
                    244:   0x65,    /* SDLK_KP_DIVIDE = 267 */
                    245:   0x66,    /* SDLK_KP_MULTIPLY = 268 */
                    246:   0x4A,    /* SDLK_KP_MINUS = 269 */
                    247:   0x4E,    /* SDLK_KP_PLUS = 270 */
                    248:   0x72,    /* SDLK_KP_ENTER = 271 */
                    249:   -1,      /* SDLK_KP_EQUALS = 272 */
                    250:   /* Arrows + Home/End pad */
                    251:   0x48,    /* SDLK_UP = 273 */
                    252:   0x50,    /* SDLK_DOWN = 274 */
                    253:   0x4D,    /* SDLK_RIGHT = 275 */
                    254:   0x4B,    /* SDLK_LEFT = 276 */
                    255:   0x52,    /* SDLK_INSERT = 277 */
                    256:   0x47,    /* SDLK_HOME = 278 */
                    257:   0x61,    /* SDLK_END = 279 */
                    258:   0x63,    /* SDLK_PAGEUP = 280 */
                    259:   0x64,    /* SDLK_PAGEDOWN = 281 */
                    260:   /* Function keys */
                    261:   0x3B,    /* SDLK_F1 = 282 */
                    262:   0x3C,    /* SDLK_F2 = 283 */
                    263:   0x3D,    /* SDLK_F3 = 284 */
                    264:   0x3E,    /* SDLK_F4 = 285 */
                    265:   0x3F,    /* SDLK_F5 = 286 */
                    266:   0x40,    /* SDLK_F6 = 287 */
                    267:   0x41,    /* SDLK_F7 = 288 */
                    268:   0x42,    /* SDLK_F8 = 289 */
                    269:   0x43,    /* SDLK_F9 = 290 */
                    270:   0x44,    /* SDLK_F10 = 291 */
                    271:   -1,      /* SDLK_F11 = 292 */
                    272:   -1,      /* SDLK_F12 = 293 */
                    273:   -1,      /* SDLK_F13 = 294 */
                    274:   -1,      /* SDLK_F14 = 295 */
                    275:   -1,      /* SDLK_F15 = 296 */
                    276:   -1,      /* 297 */
                    277:   -1,      /* 298 */
                    278:   -1,      /* 299 */
                    279:   /* Key state modifier keys */
                    280:   -1,    /* SDLK_NUMLOCK = 300 */
                    281:   0x3A,    /* SDLK_CAPSLOCK = 301 */
                    282:   0x61,    /* SDLK_SCROLLOCK = 302 */
                    283:   0x36,    /* SDLK_RSHIFT = 303 */
                    284:   0x2A,    /* SDLK_LSHIFT = 304 */
                    285:   0x1D,    /* SDLK_RCTRL = 305 */
                    286:   0x1D,    /* SDLK_LCTRL = 306 */
                    287:   0x38,    /* SDLK_RALT = 307 */
                    288:   0x38,    /* SDLK_LALT = 308 */
                    289:   -1,      /* SDLK_RMETA = 309 */
                    290:   -1,      /* SDLK_LMETA = 310 */
                    291:   -1,      /* SDLK_LSUPER = 311 */  /* Left "Windows" key */
                    292:   -1,      /* SDLK_RSUPER = 312 */  /* Right "Windows" key */
                    293:   -1,      /* SDLK_MODE = 313 */  /* "Alt Gr" key */
                    294:   -1,      /* SDLK_COMPOSE = 314 */ /* Multi-key compose key */
                    295:   /* Miscellaneous function keys */
                    296:   0x62,    /* SDLK_HELP = 315 */
                    297:   0x63,    /* SDLK_PRINT = 316 */
                    298:   -1,      /* SDLK_SYSREQ = 317 */
                    299:   -1,      /* SDLK_BREAK = 318 */
                    300:   -1,      /* SDLK_MENU = 319 */
                    301: };
                    302: 
                    303: 
1.1.1.2 ! root      304: char Loaded_KeyToSTScanCode[SDLK_LAST];
1.1       root      305: BOOL bRemapKeyLoaded=FALSE;
                    306: 
                    307: 
1.1.1.2 ! root      308: /*-----------------------------------------------------------------------*/
1.1       root      309: /*
                    310:   Remap SDL Key to ST Scan code
                    311: */
                    312: char Keymap_RemapKeyToSTScanCode(unsigned int Key)
                    313: {
1.1.1.2 ! root      314:   if( Key >= SDLK_LAST )  return -1;  /* Avoid illegal keys */
1.1       root      315:   /* Use default or loaded? */
                    316:   if (bRemapKeyLoaded)
                    317:     return(Loaded_KeyToSTScanCode[Key]);
                    318:   else
                    319:     return(Default_KeyToSTScanCode[Key]);
                    320: }
                    321: 
1.1.1.2 ! root      322: 
        !           323: /*-----------------------------------------------------------------------*/
1.1       root      324: /*
                    325:   Load keyboard remap file
                    326: */
                    327: void Keymap_LoadRemapFile(char *pszFileName)
                    328: {
                    329:   char szString[1024];
                    330:   unsigned int STScanCode,PCScanCode;
                    331:   FILE *in;
                    332: 
1.1.1.2 ! root      333:   /* Default to not loaded */
1.1       root      334:   bRemapKeyLoaded = FALSE;
                    335:   Memory_Set(Loaded_KeyToSTScanCode,-1,sizeof(Loaded_KeyToSTScanCode));
                    336: 
1.1.1.2 ! root      337:   /* Attempt to load file */
1.1       root      338:   if (strlen(pszFileName)>0) {
1.1.1.2 ! root      339:     /* Open file */
1.1       root      340:     in = fopen(pszFileName, "r");
                    341:     if (in) {
                    342:       while(!feof(in)) {
1.1.1.2 ! root      343:         /* Read line from file */
1.1       root      344:         fgets(szString, 1024, in);
1.1.1.2 ! root      345:         /* Remove white-space from start of line */
1.1       root      346:         Misc_RemoveWhiteSpace(szString,sizeof(szString));
                    347:         if (strlen(szString)>0) {
1.1.1.2 ! root      348:           /* Is a comment? */
1.1       root      349:           if ( (szString[0]==';') || (szString[0]=='#') )
                    350:             continue;
1.1.1.2 ! root      351:           /* Read values */
1.1       root      352:           sscanf(szString,"%d,%d",&STScanCode,&PCScanCode);
1.1.1.2 ! root      353:           /* Store into remap table, check both value within range */
        !           354:           if ( (PCScanCode>=0) && (PCScanCode<SDLK_LAST) && (STScanCode>=0) && (STScanCode<256) )
1.1       root      355:             Loaded_KeyToSTScanCode[PCScanCode] = STScanCode;
                    356:         }
                    357:       }
1.1.1.2 ! root      358:       /* Loaded OK */
1.1       root      359:       bRemapKeyLoaded = TRUE;
                    360: 
                    361:       fclose(in);
                    362:     }
                    363:   }
                    364: }

unix.superglobalmegacorp.com

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