keyboard: fix keystroke, add more mapping

This commit is contained in:
Mathieu Maret 2018-11-08 14:12:56 +01:00
parent b159aa0b50
commit 29442c4b05
2 changed files with 58 additions and 47 deletions

View File

@ -58,7 +58,7 @@ const char *scancode[128] = {
/* 52 */ ":", /* 52 */ ":",
/* 53 */ "!", /* 53 */ "!",
/* 54 */ 0, /* right shift*/ /* 54 */ 0, /* right shift*/
/* 55 */ 0, /* 55 */ "*",
/* 56 */ 0, /* left alt*/ /* 56 */ 0, /* left alt*/
/* 57 */ " ", /* 57 */ " ",
/* 58 */ 0, /* caps Lock */ /* 58 */ 0, /* caps Lock */
@ -72,21 +72,21 @@ const char *scancode[128] = {
/* 66 */ "\e[19~", /* F8 */ /* 66 */ "\e[19~", /* F8 */
/* 67 */ "\e[20~", /* F9 */ /* 67 */ "\e[20~", /* F9 */
/* 68 */ "\e[21~", /* F10 */ /* 68 */ "\e[21~", /* F10 */
/* 69 */ 0, /* 69 */ 0, /* VerrNum*/
/* 70 */ 0, /* 70 */ 0,
/* 71 */ 0, /* 71 */ "7",
/* 72 */ 0, /* 72 */ "8",
/* 73 */ 0, /* 73 */ "9",
/* 74 */ 0, /* 74 */ "-",
/* 75 */ 0, /* 75 */ "4",
/* 76 */ 0, /* 76 */ "5",
/* 77 */ 0, /* 77 */ "6",
/* 78 */ 0, /* 78 */ "+",
/* 79 */ 0, /* 79 */ "1", /* pavnum*/
/* 80 */ 0, /* 80 */ "2",
/* 81 */ 0, /* 81 */ "3",
/* 82 */ 0, /* 82 */ "0",
/* 83 */ 0, /* 83 */ ".",
/* 84 */ 0, /* 84 */ 0,
/* 85 */ 0, /* 85 */ 0,
/* 86 */ "<", /* 86 */ "<",
@ -264,41 +264,50 @@ const char *scancode_shift[128] = {
void keyboard_do_irq() void keyboard_do_irq()
{ {
static int lshift = 0; static int lshift = 0;
static int rshift = 0; static int rshift = 0;
static int capslock = 0; static int capslock = 0;
unsigned char c = 0; static int isExt = 0;
if (inb(0x60) != c) { unsigned char c = inb(KEYBOARD_DATA_PORT);
c = inb(0x60); const char *key = NULL;
if (c > 0) { if (c > 0) {
if (c < BREAK_CODE) { if (c == 0xE0) { // non printable such as page up/down ... See https://wiki.osdev.org/Keyboard
switch (c) { isExt = 1;
case 42: } else if (isExt) {
lshift = 1; isExt = 0;
break; return;
case 54: }
rshift = 1; if (c < BREAK_CODE) {
break; switch (c) {
case 58: case 42:
capslock = 1 - capslock; lshift = 1;
break; break;
default: case 54:
if ((lshift || rshift) ^ capslock) rshift = 1;
printf(scancode_shift[(int)c]); break;
else case 58:
printf(scancode[(int)c]); capslock = 1 - capslock;
} break;
}else { default:
c = c - BREAK_CODE; if ((lshift || rshift) ^ capslock) {
switch (c) { key = scancode_shift[(int)c];
case 42: } else {
lshift = 0; key = scancode[(int)c];
break; }
case 54: }
rshift = 0; } else {
} c = c - BREAK_CODE;
switch (c) {
case 42:
lshift = 0;
break;
case 54:
rshift = 0;
} }
} }
} }
if (key)
printf(key);
} }

View File

@ -3,4 +3,6 @@
// Pushing generate MAKE_CODE (<0x80) // Pushing generate MAKE_CODE (<0x80)
// Releasing generate BREAK_CODE (break_code = make_code + 0x80) // Releasing generate BREAK_CODE (break_code = make_code + 0x80)
#define BREAK_CODE 0x80 #define BREAK_CODE 0x80
#define KEYBOARD_DATA_PORT 0x60
void keyboard_do_irq(); void keyboard_do_irq();