From 91cc13402921ddb5b3b4e695b036a43c3722e615 Mon Sep 17 00:00:00 2001 From: Jacob Potter Date: Fri, 12 Dec 2008 17:32:00 -0500 Subject: [PATCH] make keyboard handler use keysyms --- aseg-paging/keyboard.c | 242 +++++++++++++++++++++++------------------ aseg-paging/keyboard.h | 4 +- aseg-paging/main.c | 5 +- 3 files changed, 140 insertions(+), 111 deletions(-) diff --git a/aseg-paging/keyboard.c b/aseg-paging/keyboard.c index 4b84b4f..a53a6e7 100644 --- a/aseg-paging/keyboard.c +++ b/aseg-paging/keyboard.c @@ -1,4 +1,6 @@ #include "keyboard.h" +#include +#include #include static unsigned char kbd_inj_buffer[128]; @@ -6,109 +8,126 @@ static int kbd_inj_start = 0; static int kbd_inj_end = 0; int kbd_mode = 1; -static const char scancodes2[][8] = { - ['a'] = "\x1c\xf0\x1c", - ['b'] = "\x32\xf0\x32", - ['c'] = "\x21\xf0\x21", - ['d'] = "\x23\xf0\x23", - ['e'] = "\x24\xf0\x24", - ['f'] = "\x2b\xf0\x2b", - ['g'] = "\x34\xf0\x34", - ['h'] = "\x33\xf0\x33", - ['i'] = "\x43\xf0\x43", - ['j'] = "\x3b\xf0\x3b", - ['k'] = "\x42\xf0\x42", - ['l'] = "\x4b\xf0\x4b", - ['m'] = "\x3a\xf0\x3a", - ['n'] = "\x31\xf0\x31", - ['o'] = "\x44\xf0\x44", - ['p'] = "\x4d\xf0\x4d", - ['q'] = "\x15\xf0\x15", - ['r'] = "\x2d\xf0\x2d", - ['s'] = "\x1b\xf0\x1b", - ['t'] = "\x2c\xf0\x2c", - ['u'] = "\x3c\xf0\x3c", - ['v'] = "\x2a\xf0\x2a", - ['w'] = "\x1d\xf0\x1d", - ['x'] = "\x22\xf0\x22", - ['y'] = "\x35\xf0\x35", - ['z'] = "\x1a\xf0\x1a", - ['A'] = "\x12\x1c\xf0\x1c\xf0\x12", - ['B'] = "\x12\x32\xf0\x32\xf0\x12", - ['C'] = "\x12\x21\xf0\x21\xf0\x12", - ['D'] = "\x12\x23\xf0\x23\xf0\x12", - ['E'] = "\x12\x24\xf0\x24\xf0\x12", - ['F'] = "\x12\x2b\xf0\x2b\xf0\x12", - ['G'] = "\x12\x34\xf0\x34\xf0\x12", - ['H'] = "\x12\x33\xf0\x33\xf0\x12", - ['I'] = "\x12\x43\xf0\x43\xf0\x12", - ['J'] = "\x12\x3b\xf0\x3b\xf0\x12", - ['K'] = "\x12\x42\xf0\x42\xf0\x12", - ['L'] = "\x12\x4b\xf0\x4b\xf0\x12", - ['M'] = "\x12\x3a\xf0\x3a\xf0\x12", - ['N'] = "\x12\x31\xf0\x31\xf0\x12", - ['O'] = "\x12\x44\xf0\x44\xf0\x12", - ['P'] = "\x12\x4d\xf0\x4d\xf0\x12", - ['Q'] = "\x12\x15\xf0\x15\xf0\x12", - ['R'] = "\x12\x2d\xf0\x2d\xf0\x12", - ['S'] = "\x12\x1b\xf0\x1b\xf0\x12", - ['T'] = "\x12\x2c\xf0\x2c\xf0\x12", - ['U'] = "\x12\x3c\xf0\x3c\xf0\x12", - ['V'] = "\x12\x2a\xf0\x2a\xf0\x12", - ['W'] = "\x12\x1d\xf0\x1d\xf0\x12", - ['X'] = "\x12\x22\xf0\x22\xf0\x12", - ['Y'] = "\x12\x35\xf0\x35\xf0\x12", - ['Z'] = "\x12\x1a\xf0\x1a\xf0\x12", - ['`'] = "\x0e\xf0\x0e", - ['~'] = "\x12\x0e\xf0\x0e\xf0\x12", - ['1'] = "\x16\xf0\x16", - ['!'] = "\x12\x16\xf0\x16\xf0\x12", - ['2'] = "\x1e\xf0\x1e", - ['@'] = "\x12\x1e\xf0\x1e\xf0\x12", - ['3'] = "\x26\xf0\x26", - ['#'] = "\x12\x26\xf0\x26\xf0\x12", - ['4'] = "\x25\xf0\x25", - ['$'] = "\x12\x25\xf0\x25\xf0\x12", - ['5'] = "\x2e\xf0\x2e", - ['%'] = "\x12\x2e\xf0\x2e\xf0\x12", - ['6'] = "\x36\xf0\x36", - ['^'] = "\x12\x36\xf0\x36\xf0\x12", - ['7'] = "\x3d\xf0\x3d", - ['&'] = "\x12\x3d\xf0\x3d\xf0\x12", - ['8'] = "\x3e\xf0\x3e", - ['*'] = "\x12\x3e\xf0\x3e\xf0\x12", - ['9'] = "\x46\xf0\x46", - ['('] = "\x12\x46\xf0\x46\xf0\x12", - ['0'] = "\x45\xf0\x45", - [')'] = "\x12\x45\xf0\x45\xf0\x12", - ['-'] = "\x4e\xf0\x4e", - ['_'] = "\x12\x4e\xf0\x4e\xf0\x12", - ['='] = "\x55\xf0\x55", - ['+'] = "\x12\x55\xf0\x55\xf0\x12", - ['['] = "\x54\xf0\x54", - ['{'] = "\x12\x54\xf0\x54\xf0\x12", - [']'] = "\x5b\xf0\x5b", - ['}'] = "\x12\x5b\xf0\x5b\xf0\x12", - ['\\'] = "\x5d\xf0\x5d", - ['|'] = "\x12\x5d\xf0\x5d\xf0\x12", - [';'] = "\x4c\xf0\x4c", - [':'] = "\x12\x4c\xf0\x4c\xf0\x12", - ['\''] = "\x52\xf0\x52", - ['"'] = "\x12\x52\xf0\x52\xf0\x12", - [','] = "\x41\xf0\x41", - ['<'] = "\x12\x41\xf0\x41\xf0\x12", - ['.'] = "\x49\xf0\x49", - ['>'] = "\x12\x49\xf0\x49\xf0\x12", - ['/'] = "\x4a\xf0\x4a", - ['?'] = "\x12\x4a\xf0\x4a\xf0\x12", - ['\n'] = "\x5a\xf0\x5a", - ['\t'] = "\x0d\xf0\x0d", - ['\b'] = "\x66\xf0\x66", - [' '] = "\x29\xf0\x29", - [0x82] = "\xE0\x75\xE0\xF0\x75", - [0x83] = "\xE0\x72\xE0\xF0\x72", - [0x84] = "\xE0\x6B\xE0\xF0\x6B", - [0x85] = "\xE0\x74\xE0\xF0\x74" +static const char scancodes2[][2][8] = { + ['a'] = { "\x1c", "\xf0\x1c" }, + ['b'] = { "\x32", "\xf0\x32" }, + ['c'] = { "\x21", "\xf0\x21" }, + ['d'] = { "\x23", "\xf0\x23" }, + ['e'] = { "\x24", "\xf0\x24" }, + ['f'] = { "\x2b", "\xf0\x2b" }, + ['g'] = { "\x34", "\xf0\x34" }, + ['h'] = { "\x33", "\xf0\x33" }, + ['i'] = { "\x43", "\xf0\x43" }, + ['j'] = { "\x3b", "\xf0\x3b" }, + ['k'] = { "\x42", "\xf0\x42" }, + ['l'] = { "\x4b", "\xf0\x4b" }, + ['m'] = { "\x3a", "\xf0\x3a" }, + ['n'] = { "\x31", "\xf0\x31" }, + ['o'] = { "\x44", "\xf0\x44" }, + ['p'] = { "\x4d", "\xf0\x4d" }, + ['q'] = { "\x15", "\xf0\x15" }, + ['r'] = { "\x2d", "\xf0\x2d" }, + ['s'] = { "\x1b", "\xf0\x1b" }, + ['t'] = { "\x2c", "\xf0\x2c" }, + ['u'] = { "\x3c", "\xf0\x3c" }, + ['v'] = { "\x2a", "\xf0\x2a" }, + ['w'] = { "\x1d", "\xf0\x1d" }, + ['x'] = { "\x22", "\xf0\x22" }, + ['y'] = { "\x35", "\xf0\x35" }, + ['z'] = { "\x1a", "\xf0\x1a" }, + ['A'] = { "\x12\x1c", "\xf0\x1c\xf0\x12" }, + ['B'] = { "\x12\x32", "\xf0\x32\xf0\x12" }, + ['C'] = { "\x12\x21", "\xf0\x21\xf0\x12" }, + ['D'] = { "\x12\x23", "\xf0\x23\xf0\x12" }, + ['E'] = { "\x12\x24", "\xf0\x24\xf0\x12" }, + ['F'] = { "\x12\x2b", "\xf0\x2b\xf0\x12" }, + ['G'] = { "\x12\x34", "\xf0\x34\xf0\x12" }, + ['H'] = { "\x12\x33", "\xf0\x33\xf0\x12" }, + ['I'] = { "\x12\x43", "\xf0\x43\xf0\x12" }, + ['J'] = { "\x12\x3b", "\xf0\x3b\xf0\x12" }, + ['K'] = { "\x12\x42", "\xf0\x42\xf0\x12" }, + ['L'] = { "\x12\x4b", "\xf0\x4b\xf0\x12" }, + ['M'] = { "\x12\x3a", "\xf0\x3a\xf0\x12" }, + ['N'] = { "\x12\x31", "\xf0\x31\xf0\x12" }, + ['O'] = { "\x12\x44", "\xf0\x44\xf0\x12" }, + ['P'] = { "\x12\x4d", "\xf0\x4d\xf0\x12" }, + ['Q'] = { "\x12\x15", "\xf0\x15\xf0\x12" }, + ['R'] = { "\x12\x2d", "\xf0\x2d\xf0\x12" }, + ['S'] = { "\x12\x1b", "\xf0\x1b\xf0\x12" }, + ['T'] = { "\x12\x2c", "\xf0\x2c\xf0\x12" }, + ['U'] = { "\x12\x3c", "\xf0\x3c\xf0\x12" }, + ['V'] = { "\x12\x2a", "\xf0\x2a\xf0\x12" }, + ['W'] = { "\x12\x1d", "\xf0\x1d\xf0\x12" }, + ['X'] = { "\x12\x22", "\xf0\x22\xf0\x12" }, + ['Y'] = { "\x12\x35", "\xf0\x35\xf0\x12" }, + ['Z'] = { "\x12\x1a", "\xf0\x1a\xf0\x12" }, + ['`'] = { "\x0e", "\xf0\x0e" }, + ['~'] = { "\x12\x0e", "\xf0\x0e\xf0\x12" }, + ['1'] = { "\x16", "\xf0\x16" }, + ['!'] = { "\x12\x16", "\xf0\x16\xf0\x12" }, + ['2'] = { "\x1e", "\xf0\x1e" }, + ['@'] = { "\x12\x1e", "\xf0\x1e\xf0\x12" }, + ['3'] = { "\x26", "\xf0\x26" }, + ['#'] = { "\x12\x26", "\xf0\x26\xf0\x12" }, + ['4'] = { "\x25", "\xf0\x25" }, + ['$'] = { "\x12\x25", "\xf0\x25\xf0\x12" }, + ['5'] = { "\x2e", "\xf0\x2e" }, + ['%'] = { "\x12\x2e", "\xf0\x2e\xf0\x12" }, + ['6'] = { "\x36", "\xf0\x36" }, + ['^'] = { "\x12\x36", "\xf0\x36\xf0\x12" }, + ['7'] = { "\x3d", "\xf0\x3d" }, + ['&'] = { "\x12\x3d", "\xf0\x3d\xf0\x12" }, + ['8'] = { "\x3e", "\xf0\x3e" }, + ['*'] = { "\x12\x3e", "\xf0\x3e\xf0\x12" }, + ['9'] = { "\x46", "\xf0\x46" }, + ['('] = { "\x12\x46", "\xf0\x46\xf0\x12" }, + ['0'] = { "\x45", "\xf0\x45" }, + [')'] = { "\x12\x45", "\xf0\x45\xf0\x12" }, + ['-'] = { "\x4e", "\xf0\x4e" }, + ['_'] = { "\x12\x4e", "\xf0\x4e\xf0\x12" }, + ['='] = { "\x55", "\xf0\x55" }, + ['+'] = { "\x12\x55", "\xf0\x55\xf0\x12" }, + ['['] = { "\x54", "\xf0\x54" }, + ['{'] = { "\x12\x54", "\xf0\x54\xf0\x12" }, + [']'] = { "\x5b", "\xf0\x5b" }, + ['}'] = { "\x12\x5b", "\xf0\x5b\xf0\x12" }, + ['\\'] = { "\x5d", "\xf0\x5d" }, + ['|'] = { "\x12\x5d", "\xf0\x5d\xf0\x12" }, + [';'] = { "\x4c", "\xf0\x4c" }, + [':'] = { "\x12\x4c", "\xf0\x4c\xf0\x12" }, + ['\''] = { "\x52", "\xf0\x52" }, + ['"'] = { "\x12\x52", "\xf0\x52\xf0\x12" }, + [','] = { "\x41", "\xf0\x41" }, + ['<'] = { "\x12\x41", "\xf0\x41\xf0\x12" }, + ['.'] = { "\x49", "\xf0\x49" }, + ['>'] = { "\x12\x49", "\xf0\x49\xf0\x12" }, + ['/'] = { "\x4a", "\xf0\x4a" }, + [' '] = { "\x29", "\xf0\x29" }, + ['?'] = { "\x12\x4a", "\xf0\x4a\xf0\x12" } +}; + + +static const char scancodes2high[][2][8] = { + [0x08] = { "\x66", "\xf0\x66" }, + [0x09] = { "\x0d", "\xf0\x0d" }, + [0x0d] = { "\x5a", "\xf0\x5a" }, + [0x1b] = { "\x76", "\xf0\x76" }, + [0x63] = { "\xE0\x70", "\xE0\xF0\x70" }, + [0xff] = { "\xE0\x71", "\xE0\xF0\x71" }, + [0x50] = { "\xE0\x6C", "\xE0\xF0\x6C" }, + [0x57] = { "\xE0\x69", "\xE0\xF0\x69" }, + [0x55] = { "\xE0\x75", "\xE0\xF0\x75" }, + [0x56] = { "\xE0\x7A", "\xE0\xF0\x7A" }, + [0x51] = { "\xE0\x74", "\xE0\xF0\x74" }, + [0x52] = { "\xE0\x75", "\xE0\xF0\x75" }, + [0x53] = { "\xE0\x6B", "\xE0\xF0\x6B" }, + [0x54] = { "\xE0\x72", "\xE0\xF0\x72" }, + [0xe1] = { "\x12", "\xf0\x12" }, + [0xe2] = { "\x59", "\xf0\x59" }, + [0xe3] = { "\x14", "\xf0\x14" }, + [0xe4] = { "\xE0\x14", "\xE0\xF0\x14" }, + [0xe9] = { "\x11", "\xf0\x11" }, + [0xea] = { "\xE0\x11", "\xE0\xF0\x11" } }; const unsigned char convert_table[] = { @@ -157,21 +176,28 @@ void kbd_inject_scancode (unsigned char sc) kbd_inj_end %= sizeof(kbd_inj_buffer); } -void kbd_inject_key(unsigned char k) +void kbd_inject_keysym(uint32_t k, int downflag) { const char * c; + if ((k & 0xFFFFFF00) == 0) + { + c = scancodes2[k & 0xFF][downflag ? 0 : 1]; + } else if ((k & 0xFFFFFF00) == 0xFF00) { + c = scancodes2high[k & 0xFF][downflag ? 0 : 1]; + } else { + return; + } + + if (!c) return; + if (kbd_mode == 1) { - c = scancodes2[k]; - if (!c) return; while (*c) { char cconv = sc_convert_1(*c); if (cconv) kbd_inject_scancode(cconv); c++; } } else { - c = scancodes2[k]; - if (!c) return; while (*c) { kbd_inject_scancode(*c); c++; diff --git a/aseg-paging/keyboard.h b/aseg-paging/keyboard.h index 3f66867..28f41b2 100644 --- a/aseg-paging/keyboard.h +++ b/aseg-paging/keyboard.h @@ -1,7 +1,9 @@ #ifndef KEYBOARD_H #define KEYBOARD_H -void kbd_inject_key(unsigned char k); +#include + +void kbd_inject_keysym(uint32_t k, int downflag); unsigned char kbd_get_injected_scancode(); int kbd_has_injected_scancode(); diff --git a/aseg-paging/main.c b/aseg-paging/main.c index 555a6a1..d8fecdd 100644 --- a/aseg-paging/main.c +++ b/aseg-paging/main.c @@ -9,7 +9,7 @@ #include "../net/net.h" #include "vga-overlay.h" #include "../aseg/packet.h" -#include "../aseg/keyboard.h" +#include "keyboard.h" unsigned int lastctr = 0; extern unsigned int counter; @@ -139,7 +139,8 @@ void gbl_rls_handler(smi_event_t ev) dump_log((char *)packet->data); *(unsigned long*)0xAFFD4 = 42; } else if (packet->type == 0xAA) { - kbd_inject_key('A'); + kbd_inject_keysym('A', 1); + kbd_inject_keysym('A', 0); } else { *(unsigned long*)0xAFFD4 = 0x2BADD00D; } -- 2.43.0