- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmouse.c
More file actions
Latest commit
49 lines (41 loc) · 1.26 KB
/
Copy pathmouse.c
File metadata and controls
49 lines (41 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include"types.h"
intmouse_x=512; // Start at center of 1024x768 screen
intmouse_y=384;
uint8_tmouse_bytes[3];
uint8_tmouse_cycle=0;
externvoiddraw_rect(intx, inty, intw, inth, uint32_tcolor);
/**
* @brief Handles PS/2 Mouse Interrupt (IRQ 12)
*/
voidmouse_handler(uint8_tscancode) {
switch (mouse_cycle) {
case0:
mouse_bytes[0] =scancode;
mouse_cycle++;
break;
case1:
mouse_bytes[1] =scancode;
mouse_cycle++;
break;
case2:
mouse_bytes[2] =scancode;
// Calculate relative offset
intrel_x= (int8_t)mouse_bytes[1];
intrel_y= (int8_t)mouse_bytes[2];
mouse_x+=rel_x;
mouse_y-=rel_y; // Invert Y for screen space
// Clamp mouse inside screen bounds
if (mouse_x<0) mouse_x=0;
if (mouse_y<0) mouse_y=0;
if (mouse_x>1023) mouse_x=1023;
if (mouse_y>767) mouse_y=767;
mouse_cycle=0;
break;
}
}
/**
* @brief Draws a simple $5 \times 5$ square mouse cursor
*/
voiddraw_mouse_cursor(void) {
draw_rect(mouse_x, mouse_y, 5, 5, 0x00FF0000); // Red Cursor Pointer
}