-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouse.c
39 lines (35 loc) · 951 Bytes
/
mouse.c
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
#include "ps2.h"
#include "mouse.h"
char bytePosition = -1;
unsigned char flagByte;
unsigned char xByte;
unsigned char yByte;
void (*mouseData)(unsigned char flags, short x, short y);
void mouseHandler(unsigned char byte) {
if (bytePosition == -1 && byte == 0xfa) {
bytePosition = 0;
return;
}
if (bytePosition == 0) {
flagByte = byte;
bytePosition = 1;
return;
}
if (bytePosition == 1) {
xByte = byte;
bytePosition = 2;
return;
}
if (bytePosition == 2) {
yByte = byte;
bytePosition = 0;
mouseData(flagByte, (short)xByte - (((short)flagByte << 4) & 0x100), (((short)flagByte << 3) & 0x100) - (short)yByte);
return;
}
}
void initMouse(void (*mouseDataHandler)(unsigned char flags, short x, short y)) {
mouseData = mouseDataHandler;
init_ps2_2(mouseHandler);
// enable data reporting
write_ps2_2(0xf4);
}