1.1 diff -r 05ef5f3c5246 -r 51cbc7a44cd9 src/keyboard.c 1.2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 +++ b/src/keyboard.c Wed Dec 29 01:38:54 2010 +0000 1.4 @@ -0,0 +1,144 @@ 1.5 +#include "SDL.h" 1.6 + 1.7 +/** 1.8 + * Key map -- a mapping from SDLK_xxx constants to scancodes and vice versa. 1.9 + */ 1.10 +struct { 1.11 + SDLKey key; ///< SDLK_xxx key code constant 1.12 + int extended; ///< 1 if this is an extended keycode 1.13 + unsigned char scancode; ///< Keyboard scan code 1.14 +} keymap[] = { 1.15 + { SDLK_UP, 0, 0x01 }, // ROLL/Up [UpArrow] 1.16 + { SDLK_KP2, 0, 0x01 }, // ROLL/Up [Keypad 2] 1.17 +// { SDLK_, 1, 0x02 }, // Clear Line 1.18 +// { SDLK_, 1, 0x03 }, // Rstrt / Ref 1.19 +// { SDLK_, 1, 0x04 }, // Exit 1.20 + { SDLK_KP1, 0, 0x05 }, // PREV [Keypad 1] 1.21 +// { SDLK_, 1, 0x06 }, // Msg 1.22 +// { SDLK_, 1, 0x07 }, // Cancl 1.23 + { SDLK_BACKSPACE, 0, 0x08 }, // Backspace 1.24 + { SDLK_TAB, 0, 0x09 }, // Tab 1.25 +// { SDLK_RETURN, 1, 0x0a }, // ENTER 1.26 + { SDLK_DOWN, 0, 0x0b }, // ROLL/Down [DownArrow] 1.27 + { SDLK_KP0, 0, 0x0b }, // ROLL/Down [Keypad 0] 1.28 + { SDLK_KP3, 0, 0x0c }, // NEXT [Keypad 3] 1.29 + { SDLK_RETURN, 0, 0x0d }, // RETURN [Return] 1.30 + { SDLK_LEFT, 0, 0x0e }, // <-- [LeftArrow] 1.31 + { SDLK_KP_MINUS, 0, 0x0e }, // <-- [Keypad -] 1.32 + { SDLK_RIGHT, 0, 0x0f }, // --> [RightArrow] 1.33 + { SDLK_KP_PERIOD, 0, 0x0f }, // --> [Keypad .] 1.34 +// { SDLK_, 1, 0x10 }, // Creat 1.35 +// { SDLK_, 1, 0x11 }, // Save 1.36 +// { SDLK_, 1, 0x12 }, // Move 1.37 +// { SDLK_, 1, 0x13 }, // Ops 1.38 +// { SDLK_, 1, 0x14 }, // Copy 1.39 + { SDLK_F1, 0, 0x15 }, // F1 1.40 + { SDLK_F2, 0, 0x16 }, // F2 1.41 + { SDLK_F3, 0, 0x17 }, // F3 1.42 + { SDLK_F4, 0, 0x18 }, // F4 1.43 + { SDLK_F5, 0, 0x19 }, // F5 1.44 + { SDLK_F6, 0, 0x1a }, // F6 1.45 + { SDLK_ESCAPE, 0, 0x1b }, // ESC/DEL [Escape] 1.46 + { SDLK_F7, 0, 0x1c }, // F7 1.47 + { SDLK_F8, 0, 0x1d }, // F8 1.48 +// { SDLK_, 1, 0x1e }, // Suspd 1.49 +// { SDLK_, 1, 0x1f }, // Rsume 1.50 + { SDLK_SPACE, 0, 0x20 }, // SPACE [Spacebar] 1.51 +// { SDLK_, 1, 0x21 }, // Undo 1.52 +// { SDLK_, 1, 0x22 }, // Redo 1.53 +// { SDLK_, 1, 0x23 }, // FIND 1.54 +// { SDLK_, 1, 0x24 }, // RPLAC 1.55 + { SDLK_BREAK, 0, 0x25 }, // RESET/BREAK [Pause/Break] 1.56 +// { SDLK_, 1, 0x26 }, // DleteChar 1.57 + { SDLK_QUOTE, 0, 0x27 }, // ' (single-quote) 1.58 +// { SDLK_, 1, 0x28 }, // SLCT/MARK 1.59 +// { SDLK_, 1, 0x29 }, // INPUT/MODE 1.60 +// { SDLK_, 1, 0x2a }, // HELP 1.61 +// Keycode 2B not used 1.62 + { SDLK_COMMA, 0, 0x2c }, // , [Comma] 1.63 + { SDLK_MINUS, 0, 0x2d }, // - [Dash] 1.64 + { SDLK_PERIOD, 0, 0x2e }, // . [Period] 1.65 + { SDLK_SLASH, 0, 0x2f }, // / [Forward-slash] 1.66 + { SDLK_0, 0, 0x30 }, // 0 1.67 + { SDLK_1, 0, 0x31 }, // 1 1.68 + { SDLK_2, 0, 0x32 }, // 2 1.69 + { SDLK_3, 0, 0x33 }, // 3 1.70 + { SDLK_4, 0, 0x34 }, // 4 1.71 + { SDLK_5, 0, 0x35 }, // 5 1.72 + { SDLK_6, 0, 0x36 }, // 6 1.73 + { SDLK_7, 0, 0x37 }, // 7 1.74 + { SDLK_8, 0, 0x38 }, // 8 1.75 + { SDLK_9, 0, 0x39 }, // 9 1.76 +// Keycode 3A not used 1.77 + { SDLK_SEMICOLON, 0, 0x3b }, // ; [Semicolon] 1.78 +// Keycode 3C not used 1.79 + { SDLK_EQUALS, 0, 0x3d }, // = [Equals] 1.80 +// Keycodes 3E, 3F, 40 not used 1.81 +// { SDLK_, 1, 0x41 }, // CMD 1.82 +// { SDLK_, 1, 0x42 }, // CLOSE/OPEN 1.83 + { SDLK_KP7, 0, 0x43 }, // PRINT 1.84 + { SDLK_KP8, 0, 0x44 }, // CLEAR/RFRSH 1.85 + { SDLK_CAPSLOCK, 0, 0x45 }, // Caps Lock 1.86 + { SDLK_KP9, 0, 0x46 }, // PAGE 1.87 + { SDLK_KP4, 0, 0x47 }, // BEG 1.88 + { SDLK_LSHIFT, 0, 0x48 }, // Left Shift 1.89 + { SDLK_RSHIFT, 0, 0x49 }, // Right Shift 1.90 + { SDLK_HOME, 0, 0x4a }, // Home 1.91 + { SDLK_KP5, 0, 0x4a }, // Home [Keypad 5] 1.92 + { SDLK_END, 0, 0x4b }, // End 1.93 + { SDLK_KP6, 0, 0x4b }, // End [Keypad 6] 1.94 + { SDLK_LCTRL, 0, 0x4c }, // Left Ctrl? \___ not sure which is left and which is right... 1.95 + { SDLK_RCTRL, 0, 0x4d }, // Right Ctrl? / 1.96 +// Keycodes 4E thru 5A not used 1.97 + { SDLK_LEFTBRACKET, 0, 0x5b }, // [ 1.98 + { SDLK_BACKSLASH, 0, 0x5c }, // \ (backslash) 1.99 + { SDLK_RIGHTBRACKET, 0, 0x5d }, // ] 1.100 +// Keycodes 5E, 5F not used 1.101 + { SDLK_BACKQUOTE, 0, 0x60 }, // ` 1.102 + { SDLK_a, 0, 0x61 }, // A 1.103 + { SDLK_b, 0, 0x62 }, // B 1.104 + { SDLK_c, 0, 0x63 }, // C 1.105 + { SDLK_d, 0, 0x64 }, // D 1.106 + { SDLK_e, 0, 0x65 }, // E 1.107 + { SDLK_f, 0, 0x66 }, // F 1.108 + { SDLK_g, 0, 0x67 }, // G 1.109 + { SDLK_h, 0, 0x68 }, // H 1.110 + { SDLK_i, 0, 0x69 }, // I 1.111 + { SDLK_j, 0, 0x6a }, // J 1.112 + { SDLK_k, 0, 0x6b }, // K 1.113 + { SDLK_l, 0, 0x6c }, // L 1.114 + { SDLK_m, 0, 0x6d }, // M 1.115 + { SDLK_n, 0, 0x6e }, // N 1.116 + { SDLK_o, 0, 0x6f }, // O 1.117 + { SDLK_p, 0, 0x70 }, // P 1.118 + { SDLK_q, 0, 0x71 }, // Q 1.119 + { SDLK_r, 0, 0x72 }, // R 1.120 + { SDLK_s, 0, 0x73 }, // S 1.121 + { SDLK_t, 0, 0x74 }, // T 1.122 + { SDLK_u, 0, 0x75 }, // U 1.123 + { SDLK_v, 0, 0x76 }, // V 1.124 + { SDLK_w, 0, 0x77 }, // W 1.125 + { SDLK_x, 0, 0x78 }, // X 1.126 + { SDLK_y, 0, 0x79 }, // Y 1.127 + { SDLK_z, 0, 0x7a }, // Z 1.128 +// Keycodes 7B, 7C, 7D not used 1.129 + { SDLK_NUMLOCK, 0, 0x7e } // Numlock 1.130 +// { SDLK_, 1, 0x7f }, // Dlete 1.131 +}; 1.132 + 1.133 +/** 1.134 + * List of key states 1.135 + */ 1.136 +int keystate[0x80]; 1.137 + 1.138 +void keyboard_init(void) 1.139 +{ 1.140 + // Set all key states to "not pressed" 1.141 + for (int i=0; i<(sizeof(keystate)/sizeof(keystate[0])); i++) { 1.142 + keystate[i] = 0; 1.143 + } 1.144 +} 1.145 + 1.146 +void keyboard_event(SDL_Event *ev) 1.147 +{ 1.148 +}