diff options
author | Benji Dial <benji@benjidial.net> | 2024-05-19 04:34:40 -0400 |
---|---|---|
committer | Benji Dial <benji@benjidial.net> | 2024-05-19 04:34:40 -0400 |
commit | e60fa7740cd7d245d1b22a25fea9df0768d32668 (patch) | |
tree | 728fa422d3a2abc66a3e2d89e4ef03b72074bb3e /kernel/source/interrupts.cpp | |
parent | b1a912a8a6ff472a49b2e0a09cfd433adfc2cb24 (diff) | |
download | hilbert-os-e60fa7740cd7d245d1b22a25fea9df0768d32668.tar.gz |
mouse support (working in qemu, semi-working in virtualbox)
Diffstat (limited to 'kernel/source/interrupts.cpp')
-rw-r--r-- | kernel/source/interrupts.cpp | 49 |
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(); + +} |