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