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
|
#include "idt.hpp"
#include "portio.hpp"
#include "vgaterminal.hpp"
#include <array>
#include <cstdint>
#define K_CONTROL_L -1
#define K_SHIFT_L -2
#define K_ALT_L -3
#define K_CAPS -4
#define K_NUM -5
#define K_SCROLL -6
#define K_SHIFT_R -7
#define K_ESCAPE -8
#define K_F1 -10
#define K_F2 -11
#define K_F3 -12
#define K_F4 -13
#define K_F5 -14
#define K_F6 -15
#define K_F7 -16
#define K_F8 -17
#define K_F9 -18
#define K_F10 -19
#define K_F11 -20
#define K_F12 -21
extern TextOutput& term;
static const std::array<char, 0x59> ScanCodeSet1 {{
0, K_ESCAPE,
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
'-', '=', '\b', '\t',
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', '\n', K_CONTROL_L,
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'', '`', K_SHIFT_L, '\\',
'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/',
K_SHIFT_R, '*', K_ALT_L, ' ', K_CAPS,
K_F1, K_F2, K_F3, K_F4, K_F5, K_F6, K_F7, K_F8, K_F9, K_F10,
K_NUM, K_SCROLL, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.',
0, 0, 0, // non-existant
K_F11, K_F12
}};
static constexpr bool isReleased(auto ch) {
return ch & 0x80;
}
static constexpr auto keycode(auto ch) {
return ch & 0x7F;
}
void keyboard_initialize()
{
idt_register_callback(33, [](auto& regs) {
const auto kc = inb(0x60);
if (!isReleased(kc)) {
const auto ch = ScanCodeSet1[keycode(kc)];
if (ch > 0)
term.write(ch);
}
});
}
|