From e60fa7740cd7d245d1b22a25fea9df0768d32668 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sun, 19 May 2024 04:34:40 -0400 Subject: mouse support (working in qemu, semi-working in virtualbox) --- kernel/source/interrupts.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'kernel/source/interrupts.cpp') 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 #include #include @@ -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(); + +} -- cgit v1.2.3