-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard.cpp
95 lines (78 loc) · 2.68 KB
/
keyboard.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "keyboard.h"
KeyboardDriver::KeyboardDriver(InterruptManager* manager)
: InterruptHandler(0x21, manager),
dataport(0x60),
commandport(0x64)
{
while(commandport.Read() & 0x1)
dataport.Read();
commandport.Write(0xAE); // activate interrupts
commandport.Write(0x20); // get current state
uint8_t status = (dataport.Read() | 1) & ~0x10;
commandport.Write(0x60); //set state
dataport.Write(status);
dataport.Write(0xF4);
}
KeyboardDriver::~KeyboardDriver()
{
}
void printf(char*);
uint32_t KeyboardDriver:: HandleInterrupt(uint32_t esp)
{
uint8_t key = dataport.Read();
if(key < 0x80)
{
switch(key)
{
case 0x02: printf("1"); break;
case 0x03: printf("2"); break;
case 0x04: printf("3"); break;
case 0x05: printf("4"); break;
case 0x06: printf("5"); break;
case 0x07: printf("6"); break;
case 0x08: printf("7"); break;
case 0x09: printf("8"); break;
case 0x0A: printf("9"); break;
case 0x0B: printf("0"); break;
case 0x10: printf("q"); break;
case 0x11: printf("w"); break;
case 0x12: printf("e"); break;
case 0x13: printf("r"); break;
case 0x14: printf("t"); break;
case 0x15: printf("y"); break;
case 0x16: printf("u"); break;
case 0x17: printf("i"); break;
case 0x18: printf("o"); break;
case 0x19: printf("p"); break;
case 0x1E: printf("a"); break;
case 0x1F: printf("s"); break;
case 0x20: printf("d"); break;
case 0x21: printf("f"); break;
case 0x22: printf("g"); break;
case 0x23: printf("h"); break;
case 0x24: printf("j"); break;
case 0x25: printf("k"); break;
case 0x26: printf("l"); break;
case 0x2C: printf("z"); break;
case 0x2D: printf("x"); break;
case 0x2E: printf("c"); break;
case 0x2F: printf("v"); break;
case 0x30: printf("b"); break;
case 0x31: printf("n"); break;
case 0x32: printf("m"); break;
case 0x33: printf(","); break;
case 0x34: printf("."); break;
case 0x35: printf("-"); break;
case 0x1C: printf("\n"); break;
case 0x39: printf(" "); break;
default:
char* foo = "KEYBOARD 0x00 ";
char* hex = "0123456789ABCDEF";
foo[11] = hex[(key >> 4) & 0x0F];
foo[12] = hex[key & 0x0F];
printf(foo);
break;
}
}
return esp;
}