Simple Operating System
mouse.h
Go to the documentation of this file.
1 
7 #ifndef MOUSE_HPP
8 #define MOUSE_HPP
9 
10 #include <types.h>
11 #include <errno.h>
12 
13 #define HW_EQUIP_PS2 4
14 #define MOUSE_PKT_BYTES 3
15 #define MOUSE_RESOLUTION 3
16 
17 typedef enum {NothingPress = 8, LeftPress = 9, RightPress = 10} MouseStatus;
18 
22 struct Mouse {
23  short x, y, status;
24 } mouse;
25 
30 void mouseHandler() {
31  char dx, dy;
32  asm("pushw ds\n"
33  "pushw cs\n"
34  "popw ds\n");
35 
36  asm("mov ax, [ebp+10]\n"
37  "mov bx, [ebp+12]\n"
38  "mov cx, [ebp+14]":"=a"(dy), "=b"(dx), "=c"(mouse.status));
39  mouse.x += dx;
40  mouse.y -= dy;
41 
42  asm("popw ds\n"
43  "leave\n"
44  "retfw");
45 }
46 
50 void mouseDisable() {
51  asm("int 0x15\n"::"a"(0xc200), "b"(0));//Disable
52 
53  //clear callback function
54  asm("pushw es\n"
55  "mov es, bx\n"
56  "int 0x15\n"
57  "popw es"::"a"(0xc207), "b"(0x0000));
58 }
59 
63 void mouseEnable() {
64  mouseDisable();
65 
66  //set callback function
67  asm("pushw es\n"
68  "pushw cs\n"
69  "popw es\n"
70  "int 0x15\n"
71  "popw es"::"a"(0xc207), "b"(mouseHandler));
72  asm("int 0x15\n"::"a"(0xc200), "b"(0x100));//Enable
73 }
74 
81  short installedDevices;
82  asm("int 0x11":"=a"(installedDevices));
83  if((installedDevices & HW_EQUIP_PS2) == 0)
84  return -ENODEV;
85 
86  asm("int 0x15\n"
87  "jnc exit%=\n"
88  "mov ax, -1\n"
89  "exit%=:\n"
90  :"=a"(installedDevices):"a"(0xc205), "b"(MOUSE_PKT_BYTES<<8));
91  if(installedDevices < 0)
92  return -ENODEV;
93 
94  asm("int 0x15\n"
95  "jnc exit%=\n"
96  "mov ax, -1\n"
97  "exit%=:\n"
98  :"=a"(installedDevices):"a"(0xc203), "b"(MOUSE_RESOLUTION<<8));
99  if(installedDevices < 0)
100  return -ENODEV;
101 
102  mouseEnable();
103  return 0;
104 }
105 
106 #endif //MOUSE_HPP
int mouseInitialize()
Initialize mouse, by default mouse in enabled.
Definition: mouse.h:80
void mouseDisable()
Disable mouse.
Definition: mouse.h:50
void mouseHandler()
Handler for mouse device.
Definition: mouse.h:30
void mouseEnable()
Enable mouse.
Definition: mouse.h:63
Mouse values, changed by handler when mouse is enabled.
Definition: mouse.h:22
useful macros, definitions, enums etc.