-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkb.c
126 lines (118 loc) · 3.21 KB
/
kb.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "isr.h"
#define RSHIFT 54;
#define LSHIFT 42;
unsigned char US_KEYBOARD_LAYOUT[128] =
{
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
'9', '0', '-', '=', '\b', /* Backspace */
'\t', /* Tab */
'q', 'w', 'e', 'r', /* 19 */
't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* Enter key */
0, /* 29 - Control */
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 39 */
'\'', '`', 0, /* Left shift */
'\\', 'z', 'x', 'c', 'v', 'b', 'n', /* 49 */
'm', ',', '.', '/', 0, /* Right shift */
'*',
0, /* Alt */
' ', /* Space bar */
0, /* Caps lock */
0, /* 59 - F1 key ... > */
0, 0, 0, 0, 0, 0, 0, 0,
0, /* < ... F10 */
0, /* 69 - Num lock*/
0, /* Scroll Lock */
0, /* Home key */
0, /* Up Arrow */
0, /* Page Up */
'-',
0, /* Left Arrow */
0,
0, /* Right Arrow */
'+',
0, /* 79 - End key*/
0, /* Down Arrow */
0, /* Page Down */
0, /* Insert Key */
0, /* Delete Key */
0, 0, 0,
0, /* F11 Key */
0, /* F12 Key */
0, /* All other keys are undefined */
};
unsigned char US_KEYBOARD_LAYOUT_UPPER[128] =
{
0, 0, '!', '"', '£', '$', '%', '^', '&', '*', /* 9 */
'(', ')', '_', '+', '\b', '\t',
'Q', 'W', 'E', 'R',
'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', /* Enter key */
0, /* 29 - Control */
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', /* 39 */
'|', '¬', 42, /* Left shift */
'\\', 'Z', 'X', 'C', 'V', 'B', 'N', /* 49 */
'M', '<', '>', '?', 0, /* Right shift */
0,
0, /* Alt */
' ', /* Space bar */
58, /* Caps lock */
0, /* 59 - F1 key ... > */
0, 0, 0, 0, 0, 0, 0, 0,
0, /* < ... F10 */
0, /* 69 - Num lock*/
0, /* Scroll Lock */
0, /* Home key */
0, /* Up Arrow */
0, /* Page Up */
'-',
0, /* Left Arrow */
0,
0, /* Right Arrow */
'+',
0, /* 79 - End key*/
0, /* Down Arrow */
0, /* Page Down */
0, /* Insert Key */
0, /* Delete Key */
0, 0, 0,
0, /* F11 Key */
0, /* F12 Key */
0, /* All other keys are undefined */
};
static void keydown_callback(registers_t regs)
{
/* Declared volatile to prevent caching of the variable value in memory. That would be bad and this loop would never break...*/
volatile unsigned char scancode;
unsigned char statuscode;
scancode = inportb(0x60);
statuscode = inportb(0x64);
volatile unsigned int scanint = scancode;
unsigned int uppercase = 0;
/* This is crude but mostly for testing.
If we read a shift, busywait until we get a non-shift character and set our uppercase flag to true */
while(scanint == 54 || scanint == 42)
{
uppercase = 1;
scancode = inportb(0x60);
statuscode = inportb(0x64);
scanint = scancode;
}
if(scancode & 0x80)
{
/* Ignore this for now */
}
else
{
if(uppercase == 1)
{
putch(US_KEYBOARD_LAYOUT_UPPER[scancode]);
}
else
{
putch(US_KEYBOARD_LAYOUT[scancode]);
}
}
}
void init_kb(unsigned int frequency)
{
register_interrupt_handler(IRQ1, &keydown_callback);
}