--- previous/src/keymap.c 2018/04/24 19:26:33 1.1.1.2 +++ previous/src/keymap.c 2018/04/24 19:29:51 1.1.1.4 @@ -18,319 +18,401 @@ const char Keymap_fileid[] = "Hatari key #include "screen.h" #include "debugui.h" #include "log.h" -#include "ioMem.h" -#include "m68000.h" +#include "kms.h" #include "SDL.h" -/* - - Byte at address 0x0200e00a contains modifier key values: - - x--- ---- valid - -x-- ---- alt_right - --x- ---- alt_left - ---x ---- command_right - ---- x--- command_left - ---- -x-- shift_right - ---- --x- shift_left - ---- ---x control - - - Byte at address 0x0200e00b contains key values: - - x--- ---- key up (1) or down (0) - -xxx xxxx key_code - - */ +#define LOG_KEYMAP_LEVEL LOG_WARN +Uint8 modifiers = 0; +bool capslock = false; -void Keymap_Init(void) { - if(ConfigureParams.Keyboard.bDisableKeyRepeat) - SDL_EnableKeyRepeat(0, 0); - else - SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); -} - -Uint8 nextkeycode; -Uint8 modkeys; -Uint8 ralt; -Uint8 lalt; -Uint8 rcom; -Uint8 lcom; -Uint8 rshift; -Uint8 lshift; -Uint8 ctrl; +void Keymap_Init(void) { -void Keyboard_Read0(void) { -// Log_Printf(LOG_WARN, "Keyboard read at $%08x PC=$%08x\n", IoAccessCurrentAddress, m68k_getpc()); - IoMem[IoAccessCurrentAddress & 0x1FFFF]=0xA0; } -void Keyboard_Read1(void) { -// Log_Printf(LOG_WARN, "Keyboard read at $%08x PC=$%08x\n", IoAccessCurrentAddress, m68k_getpc()); - IoMem[IoAccessCurrentAddress & 0x1FFFF]=0xF0; -} -void Keyboard_Read2(void) { -// Log_Printf(LOG_WARN, "Keyboard read at $%08x PC=$%08x\n", IoAccessCurrentAddress, m68k_getpc()); - IoMem[IoAccessCurrentAddress & 0x1FFFF]=0x13; -} +/* This function translates the scancodes provided by SDL to + * NeXT scancode values. + */ -void Keycode_Read(void) { -// Log_Printf(LOG_WARN, "Keycode read at $%08x PC=$%08x\n", IoAccessCurrentAddress, m68k_getpc()); - IoMem[0xe002]=0x93; - IoMem[0xe008]=0x10; - - IoMem[0xe00a]=modkeys; // Set modifier Keys - IoMem[0xe00b]=nextkeycode; // Press virtual Key - nextkeycode=nextkeycode | 0x80; // Automatically release virtual Key -} +Uint8 Keymap_GetKeyFromScancode(SDL_Scancode sdlscancode) { + Log_Printf(LOG_KEYMAP_LEVEL, "[Keymap] Scancode: %i (%s)\n", sdlscancode, SDL_GetScancodeName(sdlscancode)); + switch (sdlscancode) { + case SDL_SCANCODE_ESCAPE: return 0x49; + case SDL_SCANCODE_1: return 0x4a; + case SDL_SCANCODE_2: return 0x4b; + case SDL_SCANCODE_3: return 0x4c; + case SDL_SCANCODE_4: return 0x4d; + case SDL_SCANCODE_5: return 0x50; + case SDL_SCANCODE_6: return 0x4f; + case SDL_SCANCODE_7: return 0x4e; + case SDL_SCANCODE_8: return 0x1e; + case SDL_SCANCODE_9: return 0x1f; + case SDL_SCANCODE_0: return 0x20; + case SDL_SCANCODE_MINUS: return 0x1d; + case SDL_SCANCODE_EQUALS: return 0x1c; + case SDL_SCANCODE_BACKSPACE: return 0x1b; + + case SDL_SCANCODE_TAB: return 0x41; + case SDL_SCANCODE_Q: return 0x42; + case SDL_SCANCODE_W: return 0x43; + case SDL_SCANCODE_E: return 0x44; + case SDL_SCANCODE_R: return 0x45; + case SDL_SCANCODE_T: return 0x48; + case SDL_SCANCODE_Y: return 0x47; + case SDL_SCANCODE_U: return 0x46; + case SDL_SCANCODE_I: return 0x06; + case SDL_SCANCODE_O: return 0x07; + case SDL_SCANCODE_P: return 0x08; + case SDL_SCANCODE_LEFTBRACKET: return 0x05; + case SDL_SCANCODE_RIGHTBRACKET: return 0x04; + case SDL_SCANCODE_BACKSLASH: return 0x03; + + case SDL_SCANCODE_A: return 0x39; + case SDL_SCANCODE_S: return 0x3a; + case SDL_SCANCODE_D: return 0x3b; + case SDL_SCANCODE_F: return 0x3c; + case SDL_SCANCODE_G: return 0x3d; + case SDL_SCANCODE_H: return 0x40; + case SDL_SCANCODE_J: return 0x3f; + case SDL_SCANCODE_K: return 0x3e; + case SDL_SCANCODE_L: return 0x2d; + case SDL_SCANCODE_SEMICOLON: return 0x2c; + case SDL_SCANCODE_APOSTROPHE: return 0x2b; + case SDL_SCANCODE_RETURN: return 0x2a; + + case SDL_SCANCODE_Z: return 0x31; + case SDL_SCANCODE_X: return 0x32; + case SDL_SCANCODE_C: return 0x33; + case SDL_SCANCODE_V: return 0x34; + case SDL_SCANCODE_B: return 0x35; + case SDL_SCANCODE_N: return 0x37; + case SDL_SCANCODE_M: return 0x36; + case SDL_SCANCODE_COMMA: return 0x2e; + case SDL_SCANCODE_PERIOD: return 0x2f; + case SDL_SCANCODE_SLASH: return 0x30; + case SDL_SCANCODE_SPACE: return 0x38; + + case SDL_SCANCODE_GRAVE: + case SDL_SCANCODE_NUMLOCKCLEAR: return 0x26; + case SDL_SCANCODE_KP_EQUALS: return 0x27; + case SDL_SCANCODE_KP_DIVIDE: return 0x28; + case SDL_SCANCODE_KP_MULTIPLY: return 0x25; + case SDL_SCANCODE_KP_7: return 0x21; + case SDL_SCANCODE_KP_8: return 0x22; + case SDL_SCANCODE_KP_9: return 0x23; + case SDL_SCANCODE_KP_MINUS: return 0x24; + case SDL_SCANCODE_KP_4: return 0x12; + case SDL_SCANCODE_KP_5: return 0x18; + case SDL_SCANCODE_KP_6: return 0x13; + case SDL_SCANCODE_KP_PLUS: return 0x15; + case SDL_SCANCODE_KP_1: return 0x11; + case SDL_SCANCODE_KP_2: return 0x17; + case SDL_SCANCODE_KP_3: return 0x14; + case SDL_SCANCODE_KP_0: return 0x0b; + case SDL_SCANCODE_KP_PERIOD: return 0x0c; + case SDL_SCANCODE_KP_ENTER: return 0x0d; + + case SDL_SCANCODE_LEFT: return 0x09; + case SDL_SCANCODE_RIGHT: return 0x10; + case SDL_SCANCODE_UP: return 0x16; + case SDL_SCANCODE_DOWN: return 0x0f; + + /* Special keys */ + case SDL_SCANCODE_F10: + case SDL_SCANCODE_DELETE: return 0x58; /* Power */ + case SDL_SCANCODE_F5: + case SDL_SCANCODE_END: return 0x02; /* Sound down */ + case SDL_SCANCODE_F6: + case SDL_SCANCODE_HOME: return 0x1a; /* Sound up */ + case SDL_SCANCODE_F1: + case SDL_SCANCODE_PAGEDOWN: return 0x01; /* Brightness down */ + case SDL_SCANCODE_F2: + case SDL_SCANCODE_PAGEUP: return 0x19; /* Brightness up */ + + default: return 0x00; + } +} -void KeyTranslator(SDL_keysym *sdlkey) { // Translate SDL Keys to NeXT Keycodes - Log_Printf(LOG_WARN, "Key pressed: %s\n", SDL_GetKeyName(sdlkey->sym)); - int symkey = sdlkey->sym; - int modkey = sdlkey->mod; - if (ShortCut_CheckKeys(modkey, symkey, 1)) // Check if we pressed a shortcut - ShortCut_ActKey(); - else +/* These functions translate the scancodes provided by SDL to + * NeXT modifier bits. + */ - switch (sdlkey->sym) { - - case SDLK_RIGHTBRACKET: nextkeycode = 0x04; - break; - case SDLK_LEFTBRACKET: nextkeycode = 0x05; - break; - case SDLK_i: nextkeycode = 0x06; - break; - case SDLK_o: nextkeycode = 0x07; - break; - case SDLK_p: nextkeycode = 0x08; - break; - case SDLK_LEFT: nextkeycode = 0x09; - break; - case SDLK_KP0: nextkeycode = 0x0B; - break; - case SDLK_KP_PERIOD: nextkeycode = 0x0C; - break; - case SDLK_KP_ENTER: nextkeycode = 0x0D; - break; - case SDLK_DOWN: nextkeycode = 0x0F; - break; - case SDLK_RIGHT: nextkeycode = 0x10; - break; - case SDLK_KP1: nextkeycode = 0x11; - break; - case SDLK_KP4: nextkeycode = 0x12; - break; - case SDLK_KP6: nextkeycode = 0x13; - break; - case SDLK_KP3: nextkeycode = 0x14; - break; - case SDLK_KP_PLUS: nextkeycode = 0x15; - break; - case SDLK_UP: nextkeycode = 0x16; +Uint8 Keymap_Keydown_GetModFromScancode(SDL_Scancode sdlscancode) { + switch (sdlscancode) { + case SDL_SCANCODE_LCTRL: + case SDL_SCANCODE_RCTRL: + modifiers|=0x01; break; - case SDLK_KP2: nextkeycode = 0x17; + case SDL_SCANCODE_LSHIFT: + modifiers|=0x02; break; - case SDLK_KP5: nextkeycode = 0x18; + case SDL_SCANCODE_RSHIFT: + modifiers|=0x04; break; - case SDLK_BACKSPACE: nextkeycode = 0x1B; + case SDL_SCANCODE_LGUI: + modifiers|=ConfigureParams.Keyboard.bSwapCmdAlt?0x20:0x08; break; - case SDLK_EQUALS: nextkeycode = 0x1C; + case SDL_SCANCODE_RGUI: + modifiers|=ConfigureParams.Keyboard.bSwapCmdAlt?0x40:0x10; break; - case SDLK_MINUS: nextkeycode = 0x1D; + case SDL_SCANCODE_LALT: + modifiers|=ConfigureParams.Keyboard.bSwapCmdAlt?0x08:0x20; break; - case SDLK_8: nextkeycode = 0x1E; + case SDL_SCANCODE_RALT: + modifiers|=ConfigureParams.Keyboard.bSwapCmdAlt?0x10:0x40; break; - case SDLK_9: nextkeycode = 0x1F; + case SDL_SCANCODE_CAPSLOCK: + capslock=capslock?false:true; break; - case SDLK_0: nextkeycode = 0x20; + default: break; - case SDLK_KP7: nextkeycode = 0x21; - break; - case SDLK_KP8: nextkeycode = 0x22; - break; - case SDLK_KP9: nextkeycode = 0x23; - break; - case SDLK_KP_MINUS: nextkeycode = 0x24; - break; - case SDLK_KP_MULTIPLY: nextkeycode = 0x25; - break; - case SDLK_BACKQUOTE: nextkeycode = 0x26; - break; - case SDLK_KP_EQUALS: nextkeycode = 0x27; - break; - case SDLK_KP_DIVIDE: nextkeycode = 0x28; - break; - case SDLK_RETURN: nextkeycode = 0x2A; - break; - case SDLK_BACKSLASH: nextkeycode = 0x2B; - break; - case SDLK_SEMICOLON: nextkeycode = 0x2C; - break; - case SDLK_l: nextkeycode = 0x2D; - break; - case SDLK_COMMA: nextkeycode = 0x2E; - break; - case SDLK_PERIOD: nextkeycode = 0x2F; - break; - case SDLK_SLASH: nextkeycode = 0x30; - break; - case SDLK_z: nextkeycode = 0x31; - break; - case SDLK_x: nextkeycode = 0x32; - break; - case SDLK_c: nextkeycode = 0x33; - break; - case SDLK_v: nextkeycode = 0x34; - break; - case SDLK_b: nextkeycode = 0x35; - break; - case SDLK_m: nextkeycode = 0x36; - break; - case SDLK_n: nextkeycode = 0x37; - break; - case SDLK_SPACE: nextkeycode = 0x38; - break; - case SDLK_a: nextkeycode = 0x39; - break; - case SDLK_s: nextkeycode = 0x3A; - break; - case SDLK_d: nextkeycode = 0x3B; - break; - case SDLK_f: nextkeycode = 0x3C; - break; - case SDLK_g: nextkeycode = 0x3D; - break; - case SDLK_k: nextkeycode = 0x3E; - break; - case SDLK_j: nextkeycode = 0x3F; - break; - case SDLK_h: nextkeycode = 0x40; - break; - case SDLK_TAB: nextkeycode = 0x41; - break; - case SDLK_q: nextkeycode = 0x42; - break; - case SDLK_w: nextkeycode = 0x43; - break; - case SDLK_e: nextkeycode = 0x44; - break; - case SDLK_r: nextkeycode = 0x45; - break; - case SDLK_u: nextkeycode = 0x46; - break; - case SDLK_y: nextkeycode = 0x47; - break; - case SDLK_t: nextkeycode = 0x48; + } + + return modifiers|(capslock?0x02:0x00); +} + +Uint8 Keymap_Keyup_GetModFromScancode(SDL_Scancode sdlscancode) { + + switch (sdlscancode) { + case SDL_SCANCODE_LCTRL: + case SDL_SCANCODE_RCTRL: + modifiers&=~0x01; break; - case SDLK_ESCAPE: nextkeycode = 0x49; + case SDL_SCANCODE_LSHIFT: + modifiers&=~0x02; break; - case SDLK_1: nextkeycode = 0x4A; + case SDL_SCANCODE_RSHIFT: + modifiers&=~0x04; break; - case SDLK_2: nextkeycode = 0x4B; + case SDL_SCANCODE_LGUI: + modifiers&=~(ConfigureParams.Keyboard.bSwapCmdAlt?0x20:0x08); break; - case SDLK_3: nextkeycode = 0x4C; + case SDL_SCANCODE_RGUI: + modifiers&=~(ConfigureParams.Keyboard.bSwapCmdAlt?0x40:0x10); break; - case SDLK_4: nextkeycode = 0x4D; + case SDL_SCANCODE_LALT: + modifiers&=~(ConfigureParams.Keyboard.bSwapCmdAlt?0x08:0x20); break; - case SDLK_7: nextkeycode = 0x4E; + case SDL_SCANCODE_RALT: + modifiers&=~(ConfigureParams.Keyboard.bSwapCmdAlt?0x10:0x40); break; - case SDLK_6: nextkeycode = 0x4F; + case SDL_SCANCODE_CAPSLOCK: + //capslock=false; break; - case SDLK_5: nextkeycode = 0x50; + default: break; + } + + return modifiers|(capslock?0x02:0x00); +} + + +/* This function translates the key symbols provided by SDL to + * NeXT scancode values. + */ + +Uint8 Keymap_GetKeyFromSymbol(SDL_Keycode sdlkey) { + Log_Printf(LOG_KEYMAP_LEVEL, "[Keymap] Symkey: %s\n", SDL_GetKeyName(sdlkey)); + + switch (sdlkey) { + case SDLK_BACKSLASH: return 0x03; + case SDLK_RIGHTBRACKET: return 0x04; + case SDLK_LEFTBRACKET: return 0x05; + case SDLK_i: return 0x06; + case SDLK_o: return 0x07; + case SDLK_p: return 0x08; + case SDLK_LEFT: return 0x09; + case SDLK_KP_0: return 0x0B; + case SDLK_KP_PERIOD: return 0x0C; + case SDLK_KP_ENTER: return 0x0D; + case SDLK_DOWN: return 0x0F; + case SDLK_RIGHT: return 0x10; + case SDLK_KP_1: return 0x11; + case SDLK_KP_4: return 0x12; + case SDLK_KP_6: return 0x13; + case SDLK_KP_3: return 0x14; + case SDLK_KP_PLUS: return 0x15; + case SDLK_UP: return 0x16; + case SDLK_KP_2: return 0x17; + case SDLK_KP_5: return 0x18; + case SDLK_BACKSPACE: return 0x1B; + case SDLK_EQUALS: return 0x1C; + case SDLK_MINUS: return 0x1D; + case SDLK_8: return 0x1E; + case SDLK_9: return 0x1F; + case SDLK_0: return 0x20; + case SDLK_KP_7: return 0x21; + case SDLK_KP_8: return 0x22; + case SDLK_KP_9: return 0x23; + case SDLK_KP_MINUS: return 0x24; + case SDLK_KP_MULTIPLY: return 0x25; + case SDLK_BACKQUOTE: return 0x26; + case SDLK_KP_EQUALS: return 0x27; + case SDLK_KP_DIVIDE: return 0x28; + case SDLK_RETURN: return 0x2A; + case SDLK_QUOTE: return 0x2B; + case SDLK_SEMICOLON: return 0x2C; + case SDLK_l: return 0x2D; + case SDLK_COMMA: return 0x2E; + case SDLK_PERIOD: return 0x2F; + case SDLK_SLASH: return 0x30; + case SDLK_z: return 0x31; + case SDLK_x: return 0x32; + case SDLK_c: return 0x33; + case SDLK_v: return 0x34; + case SDLK_b: return 0x35; + case SDLK_m: return 0x36; + case SDLK_n: return 0x37; + case SDLK_SPACE: return 0x38; + case SDLK_a: return 0x39; + case SDLK_s: return 0x3A; + case SDLK_d: return 0x3B; + case SDLK_f: return 0x3C; + case SDLK_g: return 0x3D; + case SDLK_k: return 0x3E; + case SDLK_j: return 0x3F; + case SDLK_h: return 0x40; + case SDLK_TAB: return 0x41; + case SDLK_q: return 0x42; + case SDLK_w: return 0x43; + case SDLK_e: return 0x44; + case SDLK_r: return 0x45; + case SDLK_u: return 0x46; + case SDLK_y: return 0x47; + case SDLK_t: return 0x48; + case SDLK_ESCAPE: return 0x49; + case SDLK_1: return 0x4A; + case SDLK_2: return 0x4B; + case SDLK_3: return 0x4C; + case SDLK_4: return 0x4D; + case SDLK_7: return 0x4E; + case SDLK_6: return 0x4F; + case SDLK_5: return 0x50; + + /* Special Keys */ + case SDLK_F10: + case SDLK_DELETE: return 0x58; /* Power */ + case SDLK_F5: + case SDLK_END: return 0x02; /* Sound down */ + case SDLK_F6: + case SDLK_HOME: return 0x1a; /* Sound up */ + case SDLK_F1: + case SDLK_PAGEDOWN: return 0x01; /* Brightness down */ + case SDLK_F2: + case SDLK_PAGEUP: return 0x19; /* Brightness up */ + - /* Modifier Keys */ - case SDLK_RMETA: ctrl = 0x01; + default: return 0x00; break; - case SDLK_LMETA: ctrl = 0x01; + } +} + + +/* These functions translate the key symbols provided by SDL to + * NeXT modifier bits. + */ + +Uint8 Keymap_Keydown_GetModFromSymbol(SDL_Keycode sdl_modifier) { + + switch (sdl_modifier) { + case SDLK_LCTRL: + case SDLK_RCTRL: + modifiers|=0x01; break; - case SDLK_LSHIFT: lshift = 0x02; + case SDLK_LSHIFT: + modifiers|=0x02; break; - case SDLK_RSHIFT: rshift = 0x04; + case SDLK_RSHIFT: + modifiers|=0x04; break; - case SDLK_LCTRL: lcom = 0x08; + case SDLK_LGUI: + modifiers|=ConfigureParams.Keyboard.bSwapCmdAlt?0x20:0x08; break; - case SDLK_RCTRL: rcom = 0x10; + case SDLK_RGUI: + modifiers|=ConfigureParams.Keyboard.bSwapCmdAlt?0x40:0x10; break; - case SDLK_LALT: lalt = 0x20; + case SDLK_LALT: + modifiers|=ConfigureParams.Keyboard.bSwapCmdAlt?0x08:0x20; break; - case SDLK_RALT: ralt = 0x40; + case SDLK_RALT: + modifiers|=ConfigureParams.Keyboard.bSwapCmdAlt?0x10:0x40; break; - case SDLK_CAPSLOCK: lshift = 0x02, rshift = 0x04; + case SDLK_CAPSLOCK: + capslock=capslock?false:true; + break; + default: break; - - /* Special keys not yet emulated: - SOUND_UP_KEY 0x1A - SOUND_DOWN_KEY 0x02 - BRIGHTNESS_UP_KEY 0x19 - BRIGHTNESS_DOWN_KEY 0x01 - POWER_KEY 0x58 - */ - - default: break; } - modkeys = 0x80 | ralt | lalt | rcom | lcom | rshift | lshift | ctrl; - Log_Printf(LOG_WARN, "Modkeys: $%02x\n", modkeys); + + return modifiers|(capslock?0x02:0x00); } - -void KeyRelease(SDL_keysym *sdlkey) { //release modifier Keys - int symkey = sdlkey->sym; - int modkey = sdlkey->mod; - if (ShortCut_CheckKeys(modkey, symkey, 0)) - return; - - switch (sdlkey->sym) { - - case SDLK_RMETA: ctrl = 0x00; +Uint8 Keymap_Keyup_GetModFromSymbol(SDL_Keycode sdl_modifier) { + + switch (sdl_modifier) { + case SDLK_LCTRL: + case SDLK_RCTRL: + modifiers&=~0x01; break; - case SDLK_LMETA: ctrl = 0x00; + case SDLK_LSHIFT: + modifiers&=~0x02; break; - case SDLK_LSHIFT: lshift = 0x00; + case SDLK_RSHIFT: + modifiers&=~0x04; break; - case SDLK_RSHIFT: rshift = 0x00; + case SDLK_LGUI: + modifiers&=~(ConfigureParams.Keyboard.bSwapCmdAlt?0x20:0x08); break; - case SDLK_LCTRL: lcom = 0x00; + case SDLK_RGUI: + modifiers&=~(ConfigureParams.Keyboard.bSwapCmdAlt?0x40:0x10); break; - case SDLK_RCTRL: rcom = 0x00; + case SDLK_LALT: + modifiers&=~(ConfigureParams.Keyboard.bSwapCmdAlt?0x08:0x20); break; - case SDLK_LALT: lalt = 0x00; + case SDLK_RALT: + modifiers&=~(ConfigureParams.Keyboard.bSwapCmdAlt?0x10:0x40); break; - case SDLK_RALT: ralt = 0x00; + case SDLK_CAPSLOCK: + //capslock=false; break; - case SDLK_CAPSLOCK: lshift = 0x00, rshift = 0x00; + default: break; - default: break; } - modkeys = 0x80 | ralt | lalt | rcom | lcom | rshift | lshift | ctrl; - Log_Printf(LOG_WARN, "Modkeys: $%02x\n", modkeys); + + return modifiers|(capslock?0x02:0x00); } - /*-----------------------------------------------------------------------*/ /** - * User press key down + * User pressed key down */ -void Keymap_KeyDown(SDL_keysym *sdlkey) +void Keymap_KeyDown(SDL_Keysym *sdlkey) { - bool bPreviousKeyState; - char STScanCode; - int symkey = sdlkey->sym; - int modkey = sdlkey->mod; - - /*fprintf(stderr, "keydown: sym=%i scan=%i mod=$%x\n",symkey, sdlkey->scancode, modkey);*/ - - if (ShortCut_CheckKeys(modkey, symkey, 1)) - return; + Uint8 next_mod, next_key; + if (ShortCut_CheckKeys(sdlkey->mod, sdlkey->sym, 1)) { // Check if we pressed a shortcut + ShortCut_ActKey(); + return; + } + + if (ConfigureParams.Keyboard.nKeymapType==KEYMAP_SYMBOLIC) { + next_key = Keymap_GetKeyFromSymbol(sdlkey->sym); + next_mod = Keymap_Keydown_GetModFromSymbol(sdlkey->sym); + } else { + next_key = Keymap_GetKeyFromScancode(sdlkey->scancode); + next_mod = Keymap_Keydown_GetModFromScancode(sdlkey->scancode); + } + + Log_Printf(LOG_KEYMAP_LEVEL, "[Keymap] NeXT Keycode: $%02x, Modifiers: $%02x\n", next_key, next_mod); + + kms_keydown(next_mod, next_key); } @@ -338,20 +420,24 @@ void Keymap_KeyDown(SDL_keysym *sdlkey) /** * User released key */ -void Keymap_KeyUp(SDL_keysym *sdlkey) +void Keymap_KeyUp(SDL_Keysym *sdlkey) { - char STScanCode; - int symkey = sdlkey->sym; - int modkey = sdlkey->mod; - - /*fprintf(stderr, "keyup: sym=%i scan=%i mod=$%x\n",symkey, sdlkey->scancode, modkey);*/ - - /* Ignore short-cut keys here */ + Uint8 next_mod, next_key; - if (ShortCut_CheckKeys(modkey, symkey, 0)) + if (ShortCut_CheckKeys(sdlkey->mod, sdlkey->sym, 0)) return; - - + + if (ConfigureParams.Keyboard.nKeymapType==KEYMAP_SYMBOLIC) { + next_key = Keymap_GetKeyFromSymbol(sdlkey->sym); + next_mod = Keymap_Keyup_GetModFromSymbol(sdlkey->sym); + } else { + next_key = Keymap_GetKeyFromScancode(sdlkey->scancode); + next_mod = Keymap_Keyup_GetModFromScancode(sdlkey->scancode); + } + + Log_Printf(LOG_KEYMAP_LEVEL, "[Keymap] NeXT Keycode: $%02x, Modifiers: $%02x\n", next_key, next_mod); + + kms_keyup(next_mod, next_key); } /*-----------------------------------------------------------------------*/ @@ -360,7 +446,7 @@ void Keymap_KeyUp(SDL_keysym *sdlkey) */ void Keymap_SimulateCharacter(char asckey, bool press) { - SDL_keysym sdlkey; + SDL_Keysym sdlkey; sdlkey.mod = KMOD_NONE; sdlkey.scancode = 0; @@ -384,3 +470,81 @@ void Keymap_SimulateCharacter(char ascke } } } + + +/*-----------------------------------------------------------------------*/ +/** + * User moved mouse + */ +void Keymap_MouseMove(int dx, int dy, float lin, float exp) +{ + static bool s_left=false; + static bool s_up=false; + static float s_fdx=0.0; + static float s_fdy=0.0; + + bool left=false; + bool up=false; + float fdx; + float fdy; + + if ((dx!=0) || (dy!=0)) { + /* Remove the sign */ + if (dx<0) { + dx=-dx; + left=true; + } + if (dy<0) { + dy=-dy; + up=true; + } + + /* Exponential adjustmend */ + fdx = pow(dx, exp); + fdy = pow(dy, exp); + + /* Linear adjustment */ + fdx *= lin; + fdy *= lin; + + /* Add residuals */ + if (left==s_left) { + s_fdx+=fdx; + } else { + s_fdx=fdx; + s_left=left; + } + if (up==s_up) { + s_fdy+=fdy; + } else { + s_fdy=fdy; + s_up=up; + } + + /* Convert to integer and save residuals */ + dx=s_fdx; + s_fdx-=dx; + dy=s_fdy; + s_fdy-=dy; + //printf("adjusted: dx=%i, dy=%i\n",dx,dy); + kms_mouse_move(dx, left, dy, up); + } +} + +/*-----------------------------------------------------------------------*/ +/** + * User pressed mouse button + */ +void Keymap_MouseDown(bool left) +{ + kms_mouse_button(left,true); +} + +/*-----------------------------------------------------------------------*/ +/** + * User released mouse button + */ +void Keymap_MouseUp(bool left) +{ + kms_mouse_button(left,false); +}