-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyboard.c
72 lines (68 loc) · 1.53 KB
/
keyboard.c
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
#include "ps2.h"
#include "vga.h"
#include "keyboard.h"
static char* kbdbuffer;
char *mapping_default = "\?\?1234567890-=??qwertyuiop[]??asdfghjkl;'`?\\zxcvbnm,./??? ???????????????????????????????";
char *mapping_shifted = "\?\?!@#$%^&*()_+??QWERTYUIOP{}??ASDFGHJKL:\"~?|ZXCVBNM<>???? ???????????????????????????????";
int shifted = 0;
int i = 0;
int scanning = 0;
void keyboardScan(char* dataBuffer) {
kbdbuffer = dataBuffer;
scanning = 1;
while(scanning) {asm("hlt");}
}
void keyboardHander(unsigned char inbyte) {
if (scanning == 0) {
return;
}
if (inbyte == 0) {
return;
}
if (inbyte > 0x80)
{
if ((inbyte == 0xaa) || (inbyte == 0xb6))
{
shifted = 0;
}
}
else
{
if ((inbyte == 0x2a) || (inbyte == 0x36))
{
shifted = 1;
}
else if (inbyte == 0x1c)
{
vgaPrint("\r\n");
kbdbuffer[i] = 0;
i = 0;
scanning = 0;
return;
}
else if (inbyte == 0x0e)
{
if (i > 0)
{
i--;
vgaPrint("\b \b");
}
}
else
{
if (shifted)
{
kbdbuffer[i] = mapping_shifted[inbyte];
}
else
{
kbdbuffer[i] = mapping_default[inbyte];
}
writeChar(kbdbuffer[i]);
i++;
}
}
}
void initKeyboard() {
init_ps2_1(keyboardHander);
}