summaryrefslogtreecommitdiff
path: root/src/kernel/dev/ps2keyboard.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/dev/ps2keyboard.cpp')
-rw-r--r--src/kernel/dev/ps2keyboard.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/kernel/dev/ps2keyboard.cpp b/src/kernel/dev/ps2keyboard.cpp
new file mode 100644
index 0000000..31cd75f
--- /dev/null
+++ b/src/kernel/dev/ps2keyboard.cpp
@@ -0,0 +1,55 @@
+#include "ps2keyboard.h"
+
+#include <core/sys.h>
+#include <task/idt.h>
+
+ps2kbd *kbd = 0;
+
+static void kbd_irq(registers*) {
+ kbd->kbdIrq();
+}
+
+ps2kbd::ps2kbd(node* parent) : keyboard(parent) {
+ uint8_t temp = inb(0x60), temp2 = 0;
+ while (temp != temp2) {
+ temp2 = temp;
+ temp = inb(0x60);
+ }
+
+ kbd = this;
+ idt_handleIrq(1, kbd_irq);
+
+ escaped = false;
+
+ updateLeds();
+}
+
+void ps2kbd::updateLeds() {
+ uint8_t tmp = 0;
+ if (scroll) tmp |= 1;
+ if (num) tmp |= 2;
+ if (caps) tmp |= 4;
+ outb(0x60, tmp);
+}
+
+void ps2kbd::kbdIrq() {
+ uint8_t scancode = inb(0x60);
+ if (scancode == 0xE0) {
+ escaped = true;
+ } else {
+ if (scancode & 0x80) {
+ if (escaped) {
+ handle(scancode, false);
+ } else {
+ handle(scancode & 0x7F, false);
+ }
+ } else {
+ if (escaped) {
+ handle(scancode | 0x80, true);
+ } else {
+ handle(scancode, true);
+ }
+ }
+ escaped = false;
+ }
+}