rayzor

view src/mouse.c @ 0:2a5340a6eee4

rayzor first commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 05 Apr 2014 08:46:27 +0300
parents
children a826bf0fb169
line source
1 /* TODO: try NOT using the v8086 interrupts to avoid the overhead */
2 #include "mouse.h"
3 #include "inttypes.h"
4 #include "dpmi.h"
6 #define INTR 0x33
8 #define QUERY 0
9 #define SHOW 1
10 #define HIDE 2
11 #define READ 3
12 #define WRITE 4
14 #define XLIM 7
15 #define YLIM 8
17 int have_mouse(void)
18 {
19 struct dpmi_real_regs regs;
20 memset(&regs, 0, sizeof regs);
21 regs.eax = QUERY;
22 dpmi_real_int(INTR, &regs);
23 return regs.eax & 0xffff;
24 }
26 void show_mouse(int show)
27 {
28 struct dpmi_real_regs regs;
29 memset(&regs, 0, sizeof regs);
30 regs.eax = show ? SHOW : HIDE;
31 dpmi_real_int(INTR, &regs);
32 }
34 int read_mouse(int *xp, int *yp)
35 {
36 struct dpmi_real_regs regs;
37 memset(&regs, 0, sizeof regs);
39 regs.eax = READ;
40 dpmi_real_int(INTR, &regs);
42 if(xp) *xp = regs.ecx & 0xffff;
43 if(yp) *yp = regs.edx & 0xffff;
44 return regs.ebx & 0xffff;
45 }
47 void set_mouse(int x, int y)
48 {
49 struct dpmi_real_regs regs;
50 memset(&regs, 0, sizeof regs);
52 regs.eax = WRITE;
53 regs.ecx = x;
54 regs.edx = y;
55 dpmi_real_int(INTR, &regs);
56 }
58 void set_mouse_limits(int xmin, int ymin, int xmax, int ymax)
59 {
60 struct dpmi_real_regs regs;
61 memset(&regs, 0, sizeof regs);
62 regs.eax = XLIM;
63 regs.ecx = xmin;
64 regs.edx = xmax;
65 dpmi_real_int(INTR, &regs);
67 memset(&regs, 0, sizeof regs);
68 regs.eax = YLIM;
69 regs.ecx = ymin;
70 regs.edx = ymax;
71 dpmi_real_int(INTR, &regs);
72 }