deal with shift keys

This commit is contained in:
Mathieu Maret 2018-07-19 15:15:02 +02:00
parent 5fe28f3c26
commit bffe30c2a2
3 changed files with 298 additions and 140 deletions

View File

@ -1,146 +1,301 @@
#include "keyboard.h" #include "keyboard.h"
#include "vga.h"
#include "io.h" #include "io.h"
#include "vga.h"
const char *scancode [128] = { const char *scancode[128] = {
/* 0 */ 0, /* 0 */ 0,
/* 1 */ "\e", /* 1 */ "\e", /* escape */
/* 2 */ "&", /* 2 */ "&",
/* 3 */ "é", /* 3 */ "é",
/* 4 */ "\"", /* 4 */ "\"",
/* 5 */ "'", /* 5 */ "'",
/* 6 */ "(", /* 6 */ "(",
/* 7 */ "-", /* 7 */ "-",
/* 8 */ "è", /* 8 */ "è",
/* 9 */ "_", /* 9 */ "_",
/* 10 */ "ç", /* 10 */ "ç",
/* 11 */ "à", /* 11 */ "à",
/* 12 */ ")", /* 12 */ ")",
/* 13 */ "=", /* 13 */ "=",
/* 14 */ "\b", /* Backspace */ /* 14 */ "\b", /* Backspace */
/* 15 */ "\t", /* Tab */ /* 15 */ "\t", /* Tab */
/* 16 */ "a", /* 16 */ "a",
/* 17 */ "z", /* 17 */ "z",
/* 18 */ "e", /* 18 */ "e",
/* 19 */ "r", /* 19 */ "r",
/* 20 */ "t", /* 20 */ "t",
/* 21 */ "y", /* 21 */ "y",
/* 22 */ "u", /* 22 */ "u",
/* 23 */ "i", /* 23 */ "i",
/* 24 */ "o", /* 24 */ "o",
/* 25 */ "p", /* 25 */ "p",
/* 26 */ "^", /* 26 */ "^",
/* 27 */ "$", /* 27 */ "$",
/* 28 */ "\n", /* 28 */ "\n",
/* 29 */ 0, /* left control */ /* 29 */ 0, /* left control */
/* 30 */ "q", /* 30 */ "q",
/* 31 */ "s", /* 31 */ "s",
/* 32 */ "d", /* 32 */ "d",
/* 33 */ "f", /* 33 */ "f",
/* 34 */ "g", /* 34 */ "g",
/* 35 */ "h", /* 35 */ "h",
/* 36 */ "j", /* 36 */ "j",
/* 37 */ "k", /* 37 */ "k",
/* 38 */ "l", /* 38 */ "l",
/* 39 */ "m", /* 39 */ "m",
/* 40 */ "ù", /* 40 */ "ù",
/* 41 */ 0, /* 41 */ 0, /*²*/
/* 42 */ 0, /* left shift */ /* 42 */ 0, /* left shift */
/* 43 */ "*", /* 43 */ "*",
/* 44 */ "w", /* 44 */ "w",
/* 45 */ "x", /* 45 */ "x",
/* 46 */ "c", /* 46 */ "c",
/* 47 */ "v", /* 47 */ "v",
/* 48 */ "b", /* 48 */ "b",
/* 49 */ "n", /* 49 */ "n",
/* 50 */ ",", /* 50 */ ",",
/* 51 */ ";", /* 51 */ ";",
/* 52 */ ":", /* 52 */ ":",
/* 53 */ "!", /* 53 */ "!",
/* 54 */ 0, /* 54 */ 0, /* right shift*/
/* 55 */ 0, /* 55 */ 0,
/* 56 */ 0, /* 56 */ 0, /* left alt*/
/* 57 */ " ", /* 57 */ " ",
/* 58 */ 0, /* 58 */ 0,
/* 59 */ "\eOP", /* F1 */ /* 59 */ "\eOP", /* F1 */
/* 60 */ "\eOQ", /* F2 */ /* 60 */ "\eOQ", /* F2 */
/* 61 */ "\eOR", /* F3 */ /* 61 */ "\eOR", /* F3 */
/* 62 */ "\eOS", /* F4 */ /* 62 */ "\eOS", /* F4 */
/* 63 */ "\e[15~", /* F5 */ /* 63 */ "\e[15~", /* F5 */
/* 64 */ "\e[17~", /* F6 */ /* 64 */ "\e[17~", /* F6 */
/* 65 */ "\e[18~", /* F7 */ /* 65 */ "\e[18~", /* F7 */
/* 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,
/* 70 */ 0, /* 70 */ 0,
/* 71 */ 0, /* 71 */ 0,
/* 72 */ 0, /* 72 */ 0,
/* 73 */ 0, /* 73 */ 0,
/* 74 */ 0, /* 74 */ 0,
/* 75 */ 0, /* 75 */ 0,
/* 76 */ 0, /* 76 */ 0,
/* 77 */ 0, /* 77 */ 0,
/* 78 */ 0, /* 78 */ 0,
/* 79 */ 0, /* 79 */ 0,
/* 80 */ 0, /* 80 */ 0,
/* 81 */ 0, /* 81 */ 0,
/* 82 */ 0, /* 82 */ 0,
/* 83 */ 0, /* 83 */ 0,
/* 84 */ 0, /* 84 */ 0,
/* 85 */ 0, /* 85 */ 0,
/* 86 */ "<", /* 86 */ "<",
/* 87 */ "\e[23~", /* F11 */ /* 87 */ "\e[23~", /* F11 */
/* 88 */ "\e[24~", /* F12 */ /* 88 */ "\e[24~", /* F12 */
/* 89 */ 0, /* 89 */ 0,
/* 90 */ 0, /* 90 */ 0,
/* 91 */ 0, /* 91 */ 0,
/* 92 */ 0, /* 92 */ 0,
/* 93 */ 0, /* 93 */ 0,
/* 94 */ 0, /* 94 */ 0,
/* 95 */ 0, /* 95 */ 0,
/* 96 */ 0, /* 96 */ 0,
/* 97 */ 0, /* 97 */ 0,
/* 98 */ 0, /* 98 */ 0,
/* 99 */ 0, /* 99 */ 0,
/* 100 */ 0, /* 100 */ 0,
/* 101 */ 0, /* 101 */ 0,
/* 102 */ 0, /* 102 */ 0,
/* 103 */ 0, /* 103 */ 0,
/* 104 */ 0, /* 104 */ 0,
/* 105 */ 0, /* 105 */ 0,
/* 106 */ 0, /* 106 */ 0,
/* 107 */ 0, /* 107 */ 0,
/* 108 */ 0, /* 108 */ 0,
/* 109 */ 0, /* 109 */ 0,
/* 110 */ 0, /* 110 */ 0,
/* 111 */ 0, /* 111 */ 0,
/* 112 */ 0, /* 112 */ 0,
/* 113 */ 0, /* 113 */ 0,
/* 114 */ 0, /* 114 */ 0,
/* 115 */ 0, /* 115 */ 0,
/* 116 */ 0, /* 116 */ 0,
/* 117 */ 0, /* 117 */ 0,
/* 118 */ 0, /* 118 */ 0,
/* 119 */ 0, /* 119 */ 0,
/* 120 */ 0, /* 120 */ 0,
/* 121 */ 0, /* 121 */ 0,
/* 122 */ 0, /* 122 */ 0,
/* 123 */ 0, /* 123 */ 0,
/* 124 */ 0, /* 124 */ 0,
/* 125 */ 0, /* 125 */ 0,
/* 126 */ 0, /* 126 */ 0,
/* 127 */ 0 /* 127 */ 0};
};
const char *scancode_shift[128] = {
/* 0 */ 0,
/* 1 */ "\e",
/* 2 */ "1",
/* 3 */ "2",
/* 4 */ "3",
/* 5 */ "4",
/* 6 */ "5",
/* 7 */ "6",
/* 8 */ "7",
/* 9 */ "8",
/* 10 */ "9",
/* 11 */ "0",
/* 12 */ "°",
/* 13 */ "+",
/* 14 */ "\b", /* Shift-Backspace */
/* 15 */ "\e[Z", /* Shift-Tab */
/* 16 */ "A",
/* 17 */ "Z",
/* 18 */ "E",
/* 19 */ "R",
/* 20 */ "T",
/* 21 */ "Y",
/* 22 */ "U",
/* 23 */ "I",
/* 24 */ "O",
/* 25 */ "P",
/* 26 */ "\"",
/* 27 */ "£",
/* 28 */ "\n",
/* 29 */ 0, /* left control */
/* 30 */ "Q",
/* 31 */ "S",
/* 32 */ "D",
/* 33 */ "F",
/* 34 */ "G",
/* 35 */ "H",
/* 36 */ "J",
/* 37 */ "K",
/* 38 */ "L",
/* 39 */ "M",
/* 40 */ "%",
/* 41 */ 0,
/* 42 */ 0,
/* 43 */ "µ",
/* 44 */ "W",
/* 45 */ "X",
/* 46 */ "C",
/* 47 */ "V",
/* 48 */ "B",
/* 49 */ "N",
/* 50 */ "?",
/* 51 */ ".",
/* 52 */ "/",
/* 53 */ "§",
/* 54 */ 0,
/* 55 */ 0,
/* 56 */ 0,
/* 57 */ 0,
/* 58 */ 0,
/* 59 */ "\eOP", /* Shift-F1 */
/* 60 */ "\eOQ", /* Shift-F2 */
/* 61 */ "\eOR", /* Shift-F3 */
/* 62 */ "\eOS", /* Shift-F4 */
/* 63 */ "\e[15;2~", /* Shift-F5 */
/* 64 */ "\e[17;2~", /* Shift-F6 */
/* 65 */ "\e[18;2~", /* Shift-F7 */
/* 66 */ "\e[19;2~", /* Shift-F8 */
/* 67 */ "\e[20:2~", /* Shift-F9 */
/* 68 */ "\e[21:2~", /* Shift-F10 */
/* 69 */ 0,
/* 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,
/* 84 */ 0,
/* 85 */ 0,
/* 86 */ ">",
/* 87 */ "\e[23;2~", /* Shift-F11 */
/* 88 */ "\e[24;2~", /* Shift-F12 */
/* 89 */ 0,
/* 90 */ 0,
/* 91 */ 0,
/* 92 */ 0,
/* 93 */ 0,
/* 94 */ 0,
/* 95 */ 0,
/* 96 */ 0,
/* 97 */ 0,
/* 98 */ 0,
/* 99 */ 0,
/* 100 */ 0,
/* 101 */ 0,
/* 102 */ 0,
/* 103 */ 0,
/* 104 */ 0,
/* 105 */ 0,
/* 106 */ 0,
/* 107 */ 0,
/* 108 */ 0,
/* 109 */ 0,
/* 110 */ 0,
/* 111 */ 0,
/* 112 */ 0,
/* 113 */ 0,
/* 114 */ 0,
/* 115 */ 0,
/* 116 */ 0,
/* 117 */ 0,
/* 118 */ 0,
/* 119 */ 0,
/* 120 */ 0,
/* 121 */ 0,
/* 122 */ 0,
/* 123 */ 0,
/* 124 */ 0,
/* 125 */ 0,
/* 126 */ 0,
/* 127 */ 0};
void keyboard_do_irq(){ void keyboard_do_irq()
char c = 0; {
if (inb(0x60) != c) { static int lshift = 0;
c = inb(0x60); static int rshift = 0;
if (c > 0) { unsigned char c = 0;
printString(scancode[(int)c]); 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;
default:
if (lshift || rshift)
printString(scancode_shift[(int)c]);
else
printString(scancode[(int)c]);
}
}else {
c = c - BREAK_CODE;
switch (c) {
case 42:
lshift = 0;
break;
case 54:
rshift = 0;
break;
}
}
}
}
} }

View File

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

View File

@ -81,7 +81,7 @@ main:
; http://www.ctyme.com/intr/rb-0607.htm ; http://www.ctyme.com/intr/rb-0607.htm
; Bios read first 512 bytes, read next disk sector ; Bios read first 512 bytes, read next disk sector
mov ah, 0x2 ;read sectors mov ah, 0x2 ;read sectors
mov al, 10 ;sectors to read mov al, 15 ;sectors to read
mov ch, 0 ;cylinder idx mov ch, 0 ;cylinder idx
mov dh, 0 ;head idx mov dh, 0 ;head idx
mov cl, 2 ;sector idx mov cl, 2 ;sector idx