Add keyboard scancode

Scancode tabel taken from SOS project
This commit is contained in:
Mathieu Maret 2018-07-19 13:57:47 +02:00
parent 95850e0581
commit 2352c67b7a
4 changed files with 178 additions and 16 deletions

View File

@ -1,6 +1,7 @@
#include "interrupt.h" #include "interrupt.h"
#include "io.h" #include "io.h"
#include "irq.h" #include "irq.h"
#include "keyboard.h"
#include "pic.h" #include "pic.h"
#include "vga.h" #include "vga.h"
@ -8,13 +9,7 @@
__attribute__((interrupt)) void keyboard_handler(struct interrupt_frame *frame) __attribute__((interrupt)) void keyboard_handler(struct interrupt_frame *frame)
{ {
EOIIrq(IRQ_KEYBOARD); EOIIrq(IRQ_KEYBOARD);
char c = 0; keyboard_do_irq();
if (inb(0x60) != c) {
c = inb(0x60);
if (c > 0) {
printInt(c);
}
}
(void)frame; (void)frame;
} }

146
drivers/keyboard.c Normal file
View File

@ -0,0 +1,146 @@
#include "keyboard.h"
#include "vga.h"
#include "io.h"
const char *scancode [128] = {
/* 0 */ 0,
/* 1 */ "\e",
/* 2 */ "&",
/* 3 */ "é",
/* 4 */ "\"",
/* 5 */ "'",
/* 6 */ "(",
/* 7 */ "-",
/* 8 */ "è",
/* 9 */ "_",
/* 10 */ "ç",
/* 11 */ "à",
/* 12 */ ")",
/* 13 */ "=",
/* 14 */ "\b", /* Backspace */
/* 15 */ "\t", /* 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, /* left shift */
/* 43 */ "*",
/* 44 */ "w",
/* 45 */ "x",
/* 46 */ "c",
/* 47 */ "v",
/* 48 */ "b",
/* 49 */ "n",
/* 50 */ ",",
/* 51 */ ";",
/* 52 */ ":",
/* 53 */ "!",
/* 54 */ 0,
/* 55 */ 0,
/* 56 */ 0,
/* 57 */ " ",
/* 58 */ 0,
/* 59 */ "\eOP", /* F1 */
/* 60 */ "\eOQ", /* F2 */
/* 61 */ "\eOR", /* F3 */
/* 62 */ "\eOS", /* F4 */
/* 63 */ "\e[15~", /* F5 */
/* 64 */ "\e[17~", /* F6 */
/* 65 */ "\e[18~", /* F7 */
/* 66 */ "\e[19~", /* F8 */
/* 67 */ "\e[20~", /* F9 */
/* 68 */ "\e[21~", /* 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~", /* F11 */
/* 88 */ "\e[24~", /* 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(){
char c = 0;
if (inb(0x60) != c) {
c = inb(0x60);
if (c > 0) {
printString(scancode[(int)c]);
}
}
}

3
drivers/keyboard.h Normal file
View File

@ -0,0 +1,3 @@
#pragma once
void keyboard_do_irq();

View File

@ -4,7 +4,7 @@
static uint vgaBgColor; static uint vgaBgColor;
static uint vgaColor; static uint vgaColor;
static uint line, col; static int line, col;
int initVGA(uint bgColor, uint color) int initVGA(uint bgColor, uint color)
{ {
@ -97,7 +97,27 @@ void printChar(const char str)
if (str == '\n') { if (str == '\n') {
line++; line++;
col = 0; col = 0;
if (line >= VGA_HEIGHT) {
vgaScrollUp();
line--;
} }
}
else if(str == '\r')
{
col = 0;
}
else if(str == '\b')
{
col--;
if (col < 0) {
col = VGA_WIDTH - 1;
line--;
}
printCharDetails(' ', vgaColor, vgaBgColor, col, line);
}
else
{
printCharDetails(str, vgaColor, vgaBgColor, col++, line);
if (col == VGA_WIDTH) { if (col == VGA_WIDTH) {
col = 0; col = 0;
line++; line++;
@ -106,9 +126,7 @@ void printChar(const char str)
vgaScrollUp(); vgaScrollUp();
line--; line--;
} }
if (str == '\n') }
return;
printCharDetails(str, vgaColor, vgaBgColor, col++, line);
} }
void printStringDetails(const char *str, uint color, uint bgColor, int startX, int startY) void printStringDetails(const char *str, uint color, uint bgColor, int startX, int startY)