summaryrefslogtreecommitdiff
path: root/kernel/source/interrupts.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/source/interrupts.cpp')
-rw-r--r--kernel/source/interrupts.cpp49
1 files changed, 47 insertions, 2 deletions
diff --git a/kernel/source/interrupts.cpp b/kernel/source/interrupts.cpp
index 6e22121..9b6495e 100644
--- a/kernel/source/interrupts.cpp
+++ b/kernel/source/interrupts.cpp
@@ -1,3 +1,4 @@
+#include <hilbert/kernel/framebuffer.hpp>
#include <hilbert/kernel/input.hpp>
#include <hilbert/kernel/panic.hpp>
@@ -54,7 +55,9 @@ static uint32_t current_flags = 0;
static void got_key(uint32_t key) {
- input::key_queue->insert(current_flags | key);
+ input::input_queue->insert({
+ .keyboard = current_flags | key, .is_mouse = false});
+
input::got_input();
if (key == (input::BREAK | 0x77))
@@ -90,7 +93,7 @@ static void got_key(uint32_t key) {
}
static uint8_t key_so_far[8];
-uint8_t key_so_far_len = 0;
+static uint8_t key_so_far_len = 0;
extern "C" void on_keyboard_interrupt(uint8_t byte) {
@@ -150,3 +153,45 @@ extern "C" void on_keyboard_interrupt(uint8_t byte) {
}
}
+
+static uint8_t mouse_packet_so_far[3];
+static uint8_t mouse_packet_so_far_len = 0;
+
+extern "C" void on_mouse_interrupt(uint8_t byte) {
+
+ if (mouse_packet_so_far_len == 0 && byte == 0xfa)
+ //dirty hack
+ return;
+
+ mouse_packet_so_far[mouse_packet_so_far_len++] = byte;
+ if (mouse_packet_so_far_len < 3)
+ return;
+
+ mouse_packet_so_far_len = 0;
+
+ int16_t x_change = mouse_packet_so_far[1];
+ int16_t y_change = -(int16_t)mouse_packet_so_far[2];
+ if (mouse_packet_so_far[0] & 0x10)
+ x_change -= 0x100;
+ if (mouse_packet_so_far[0] & 0x20)
+ y_change += 0x100;
+
+ input::input_packet packet = {
+ .mouse = {
+ .x_change = x_change, .y_change = y_change,
+ .buttons = (input::buttons_t)(mouse_packet_so_far[0] & 7) },
+ .is_mouse = true };
+
+ if (input::input_queue->count > 0 &&
+ input::input_queue->last_inserted().is_mouse &&
+ input::input_queue->last_inserted().mouse.buttons ==
+ packet.mouse.buttons) {
+ input::input_queue->last_inserted().mouse.x_change = packet.mouse.x_change;
+ input::input_queue->last_inserted().mouse.y_change = packet.mouse.y_change;
+ }
+ else
+ input::input_queue->insert(packet);
+
+ input::got_input();
+
+}