Wed, 29 Dec 2010 01:38:54 +0000
add first cut keyboard driver
Makefile | file | annotate | diff | revisions | |
src/keyboard.c | file | annotate | diff | revisions |
1.1 --- a/Makefile Tue Dec 28 22:37:21 2010 +0000 1.2 +++ b/Makefile Wed Dec 29 01:38:54 2010 +0000 1.3 @@ -118,7 +118,7 @@ 1.4 TARGET = freebee 1.5 1.6 # source files that produce object files 1.7 -SRC = main.c state.c memory.c wd279x.c 1.8 +SRC = main.c state.c memory.c wd279x.c keyboard.c 1.9 SRC += musashi/m68kcpu.c musashi/m68kdasm.c musashi/m68kops.c musashi/m68kopac.c musashi/m68kopdm.c musashi/m68kopnz.c 1.10 1.11 # source type - either "c" or "cpp" (C or C++)
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/src/keyboard.c Wed Dec 29 01:38:54 2010 +0000 2.3 @@ -0,0 +1,144 @@ 2.4 +#include "SDL.h" 2.5 + 2.6 +/** 2.7 + * Key map -- a mapping from SDLK_xxx constants to scancodes and vice versa. 2.8 + */ 2.9 +struct { 2.10 + SDLKey key; ///< SDLK_xxx key code constant 2.11 + int extended; ///< 1 if this is an extended keycode 2.12 + unsigned char scancode; ///< Keyboard scan code 2.13 +} keymap[] = { 2.14 + { SDLK_UP, 0, 0x01 }, // ROLL/Up [UpArrow] 2.15 + { SDLK_KP2, 0, 0x01 }, // ROLL/Up [Keypad 2] 2.16 +// { SDLK_, 1, 0x02 }, // Clear Line 2.17 +// { SDLK_, 1, 0x03 }, // Rstrt / Ref 2.18 +// { SDLK_, 1, 0x04 }, // Exit 2.19 + { SDLK_KP1, 0, 0x05 }, // PREV [Keypad 1] 2.20 +// { SDLK_, 1, 0x06 }, // Msg 2.21 +// { SDLK_, 1, 0x07 }, // Cancl 2.22 + { SDLK_BACKSPACE, 0, 0x08 }, // Backspace 2.23 + { SDLK_TAB, 0, 0x09 }, // Tab 2.24 +// { SDLK_RETURN, 1, 0x0a }, // ENTER 2.25 + { SDLK_DOWN, 0, 0x0b }, // ROLL/Down [DownArrow] 2.26 + { SDLK_KP0, 0, 0x0b }, // ROLL/Down [Keypad 0] 2.27 + { SDLK_KP3, 0, 0x0c }, // NEXT [Keypad 3] 2.28 + { SDLK_RETURN, 0, 0x0d }, // RETURN [Return] 2.29 + { SDLK_LEFT, 0, 0x0e }, // <-- [LeftArrow] 2.30 + { SDLK_KP_MINUS, 0, 0x0e }, // <-- [Keypad -] 2.31 + { SDLK_RIGHT, 0, 0x0f }, // --> [RightArrow] 2.32 + { SDLK_KP_PERIOD, 0, 0x0f }, // --> [Keypad .] 2.33 +// { SDLK_, 1, 0x10 }, // Creat 2.34 +// { SDLK_, 1, 0x11 }, // Save 2.35 +// { SDLK_, 1, 0x12 }, // Move 2.36 +// { SDLK_, 1, 0x13 }, // Ops 2.37 +// { SDLK_, 1, 0x14 }, // Copy 2.38 + { SDLK_F1, 0, 0x15 }, // F1 2.39 + { SDLK_F2, 0, 0x16 }, // F2 2.40 + { SDLK_F3, 0, 0x17 }, // F3 2.41 + { SDLK_F4, 0, 0x18 }, // F4 2.42 + { SDLK_F5, 0, 0x19 }, // F5 2.43 + { SDLK_F6, 0, 0x1a }, // F6 2.44 + { SDLK_ESCAPE, 0, 0x1b }, // ESC/DEL [Escape] 2.45 + { SDLK_F7, 0, 0x1c }, // F7 2.46 + { SDLK_F8, 0, 0x1d }, // F8 2.47 +// { SDLK_, 1, 0x1e }, // Suspd 2.48 +// { SDLK_, 1, 0x1f }, // Rsume 2.49 + { SDLK_SPACE, 0, 0x20 }, // SPACE [Spacebar] 2.50 +// { SDLK_, 1, 0x21 }, // Undo 2.51 +// { SDLK_, 1, 0x22 }, // Redo 2.52 +// { SDLK_, 1, 0x23 }, // FIND 2.53 +// { SDLK_, 1, 0x24 }, // RPLAC 2.54 + { SDLK_BREAK, 0, 0x25 }, // RESET/BREAK [Pause/Break] 2.55 +// { SDLK_, 1, 0x26 }, // DleteChar 2.56 + { SDLK_QUOTE, 0, 0x27 }, // ' (single-quote) 2.57 +// { SDLK_, 1, 0x28 }, // SLCT/MARK 2.58 +// { SDLK_, 1, 0x29 }, // INPUT/MODE 2.59 +// { SDLK_, 1, 0x2a }, // HELP 2.60 +// Keycode 2B not used 2.61 + { SDLK_COMMA, 0, 0x2c }, // , [Comma] 2.62 + { SDLK_MINUS, 0, 0x2d }, // - [Dash] 2.63 + { SDLK_PERIOD, 0, 0x2e }, // . [Period] 2.64 + { SDLK_SLASH, 0, 0x2f }, // / [Forward-slash] 2.65 + { SDLK_0, 0, 0x30 }, // 0 2.66 + { SDLK_1, 0, 0x31 }, // 1 2.67 + { SDLK_2, 0, 0x32 }, // 2 2.68 + { SDLK_3, 0, 0x33 }, // 3 2.69 + { SDLK_4, 0, 0x34 }, // 4 2.70 + { SDLK_5, 0, 0x35 }, // 5 2.71 + { SDLK_6, 0, 0x36 }, // 6 2.72 + { SDLK_7, 0, 0x37 }, // 7 2.73 + { SDLK_8, 0, 0x38 }, // 8 2.74 + { SDLK_9, 0, 0x39 }, // 9 2.75 +// Keycode 3A not used 2.76 + { SDLK_SEMICOLON, 0, 0x3b }, // ; [Semicolon] 2.77 +// Keycode 3C not used 2.78 + { SDLK_EQUALS, 0, 0x3d }, // = [Equals] 2.79 +// Keycodes 3E, 3F, 40 not used 2.80 +// { SDLK_, 1, 0x41 }, // CMD 2.81 +// { SDLK_, 1, 0x42 }, // CLOSE/OPEN 2.82 + { SDLK_KP7, 0, 0x43 }, // PRINT 2.83 + { SDLK_KP8, 0, 0x44 }, // CLEAR/RFRSH 2.84 + { SDLK_CAPSLOCK, 0, 0x45 }, // Caps Lock 2.85 + { SDLK_KP9, 0, 0x46 }, // PAGE 2.86 + { SDLK_KP4, 0, 0x47 }, // BEG 2.87 + { SDLK_LSHIFT, 0, 0x48 }, // Left Shift 2.88 + { SDLK_RSHIFT, 0, 0x49 }, // Right Shift 2.89 + { SDLK_HOME, 0, 0x4a }, // Home 2.90 + { SDLK_KP5, 0, 0x4a }, // Home [Keypad 5] 2.91 + { SDLK_END, 0, 0x4b }, // End 2.92 + { SDLK_KP6, 0, 0x4b }, // End [Keypad 6] 2.93 + { SDLK_LCTRL, 0, 0x4c }, // Left Ctrl? \___ not sure which is left and which is right... 2.94 + { SDLK_RCTRL, 0, 0x4d }, // Right Ctrl? / 2.95 +// Keycodes 4E thru 5A not used 2.96 + { SDLK_LEFTBRACKET, 0, 0x5b }, // [ 2.97 + { SDLK_BACKSLASH, 0, 0x5c }, // \ (backslash) 2.98 + { SDLK_RIGHTBRACKET, 0, 0x5d }, // ] 2.99 +// Keycodes 5E, 5F not used 2.100 + { SDLK_BACKQUOTE, 0, 0x60 }, // ` 2.101 + { SDLK_a, 0, 0x61 }, // A 2.102 + { SDLK_b, 0, 0x62 }, // B 2.103 + { SDLK_c, 0, 0x63 }, // C 2.104 + { SDLK_d, 0, 0x64 }, // D 2.105 + { SDLK_e, 0, 0x65 }, // E 2.106 + { SDLK_f, 0, 0x66 }, // F 2.107 + { SDLK_g, 0, 0x67 }, // G 2.108 + { SDLK_h, 0, 0x68 }, // H 2.109 + { SDLK_i, 0, 0x69 }, // I 2.110 + { SDLK_j, 0, 0x6a }, // J 2.111 + { SDLK_k, 0, 0x6b }, // K 2.112 + { SDLK_l, 0, 0x6c }, // L 2.113 + { SDLK_m, 0, 0x6d }, // M 2.114 + { SDLK_n, 0, 0x6e }, // N 2.115 + { SDLK_o, 0, 0x6f }, // O 2.116 + { SDLK_p, 0, 0x70 }, // P 2.117 + { SDLK_q, 0, 0x71 }, // Q 2.118 + { SDLK_r, 0, 0x72 }, // R 2.119 + { SDLK_s, 0, 0x73 }, // S 2.120 + { SDLK_t, 0, 0x74 }, // T 2.121 + { SDLK_u, 0, 0x75 }, // U 2.122 + { SDLK_v, 0, 0x76 }, // V 2.123 + { SDLK_w, 0, 0x77 }, // W 2.124 + { SDLK_x, 0, 0x78 }, // X 2.125 + { SDLK_y, 0, 0x79 }, // Y 2.126 + { SDLK_z, 0, 0x7a }, // Z 2.127 +// Keycodes 7B, 7C, 7D not used 2.128 + { SDLK_NUMLOCK, 0, 0x7e } // Numlock 2.129 +// { SDLK_, 1, 0x7f }, // Dlete 2.130 +}; 2.131 + 2.132 +/** 2.133 + * List of key states 2.134 + */ 2.135 +int keystate[0x80]; 2.136 + 2.137 +void keyboard_init(void) 2.138 +{ 2.139 + // Set all key states to "not pressed" 2.140 + for (int i=0; i<(sizeof(keystate)/sizeof(keystate[0])); i++) { 2.141 + keystate[i] = 0; 2.142 + } 2.143 +} 2.144 + 2.145 +void keyboard_event(SDL_Event *ev) 2.146 +{ 2.147 +}