From b8b094e45ecaa7876e02e5ada246ae13e57dfe07 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Tue, 5 Nov 2019 22:26:27 +0100 Subject: Added basic PS/2 mouse support --- src/kernel/input/ps2/mouse.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/kernel/input/ps2/mouse.c') diff --git a/src/kernel/input/ps2/mouse.c b/src/kernel/input/ps2/mouse.c index bef226c..0ee7b2b 100644 --- a/src/kernel/input/ps2/mouse.c +++ b/src/kernel/input/ps2/mouse.c @@ -3,17 +3,19 @@ #include char mouse_cycle = 0; -signed char mouse_byte[3]; -signed char mouse_x = 0; -signed char mouse_y = 0; +char mouse_byte[3]; +int mouse_x = 0; +int mouse_y = 0; int mouse_but_1 = 0; int mouse_but_2 = 0; +int mouse_but_3 = 0; void mouse_handler(struct regs *a_r) { switch (mouse_cycle) { case 0: mouse_byte[0] = receive_b(0x60); - mouse_cycle++; + if (((mouse_byte[0] >> 3) & 1) == 1) mouse_cycle++; + else mouse_cycle = 0; break; case 1: mouse_byte[1] = receive_b(0x60); @@ -21,18 +23,17 @@ void mouse_handler(struct regs *a_r) { break; case 2: mouse_byte[2] = receive_b(0x60); - mouse_x = mouse_byte[1]; - mouse_y = mouse_byte[2]; - mouse_but_1 = (mouse_byte[0] % 2); - mouse_but_2 = ((mouse_byte[0] % 4) - (mouse_byte[0] % 2)) / 2; + mouse_x += mouse_byte[1]; + mouse_y -= mouse_byte[2]; + mouse_but_1 = mouse_byte[0] & 1; + mouse_but_2 = (mouse_byte[0] >> 1) & 1; + mouse_but_3 = (mouse_byte[0] >> 2) & 1; mouse_cycle = 0; + vesa_draw_cursor(mouse_x, mouse_y); break; default: break; } - - if (mouse_but_1 == 1) - vesa_draw_string("CLICK!\n"); } void mouse_wait(unsigned char a_type) { @@ -88,5 +89,5 @@ void mouse_install() { mouse_read(); // Setup the mouse handler - irq_install_handler(2, mouse_handler); + irq_install_handler(12, mouse_handler); } -- cgit v1.2.3