-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmouse.c
More file actions
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"
int mouse_x = 512; // Start at center of 1024x768 screen
int mouse_y = 384;
uint8_t mouse_bytes[3];
uint8_t mouse_cycle = 0;
extern void draw_rect(int x, int y, int w, int h, uint32_t color);
/**
* @brief Handles PS/2 Mouse Interrupt (IRQ 12)
*/
void mouse_handler(uint8_t scancode) {
switch (mouse_cycle) {
case 0:
mouse_bytes[0] = scancode;
mouse_cycle++;
break;
case 1:
mouse_bytes[1] = scancode;
mouse_cycle++;
break;
case 2:
mouse_bytes[2] = scancode;
// Calculate relative offset
int rel_x = (int8_t)mouse_bytes[1];
int rel_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
*/
void draw_mouse_cursor(void) {
draw_rect(mouse_x, mouse_y, 5, 5, 0x00FF0000); // Red Cursor Pointer
}