#include "idt.hpp" #include "portio.hpp" #include "vgaterminal.hpp" #include #include #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 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); } }); }