better mouse demo

This commit is contained in:
Benji Dial 2025-12-25 16:51:25 -05:00
parent 0bc7429173
commit 9fec34806e

View file

@ -16,40 +16,74 @@
*/
#include <framebuffer.h>
#include <panic.h>
#include <ps2.h>
//defined in ps2.asm
//returns -1 if no byte available
int read_ps2_byte();
static uint32_t color = 1;
static void process_keyboard_byte(uint8_t byte) {
(void)byte;
//TODO
}
static void change_color() {
static uint8_t mouse_packet[3];
static int mouse_packet_length = 0;
color ^= color << 13;
color ^= color >> 17;
color ^= color << 5;
static int total_x = 0;
static int total_y = 0;
for (int y = 0; y < fb_height; ++y)
for (int x = 0; x < fb_width; ++x)
*(uint32_t *)&fb_base[y * fb_pitch + x * 4] = color & 0x00ffffff;
static void process_mouse_byte(uint8_t byte) {
mouse_packet[mouse_packet_length] = byte;
if (mouse_packet_length < 2) {
++mouse_packet_length;
return;
}
mouse_packet_length = 0;
int x = mouse_packet[1];
if (mouse_packet[0] & 0x10)
x -= 256;
int y = mouse_packet[2];
if (mouse_packet[0] & 0x20)
y -= 256;
total_x += x;
total_y -= y;
if (total_x < 0)
total_x = 0;
if (total_x >= fb_width)
total_x = fb_width - 1;
if (total_y < 0)
total_y = 0;
if (total_y >= fb_height)
total_y = fb_height - 1;
fb_base[total_y * fb_pitch + total_x * 4] = 0xff;
fb_base[total_y * fb_pitch + total_x * 4 + 1] = 0xff;
fb_base[total_y * fb_pitch + total_x * 4 + 2] = 0xff;
}
void on_keyboard_irq() {
while (read_ps2_byte() != -1)
;
change_color();
while (1) {
int byte = read_ps2_byte();
if (byte == -1)
return;
process_keyboard_byte(byte);
}
}
void on_mouse_irq() {
while (read_ps2_byte() != -1)
;
change_color();
while (1) {
int byte = read_ps2_byte();
if (byte == -1)
return;
process_mouse_byte(byte);
}
}