FreeBASIC  0.91.0
io_mouse.c
Go to the documentation of this file.
1 /* console mode mouse functions */
2 
3 #include "../fb.h"
4 #include "fb_private_console.h"
5 #include <dpmi.h>
6 
7 static int inited = -1;
8 static int wheel_ok = FALSE;
9 static int wheel_pos;
10 static __dpmi_regs regs;
11 
12 int fb_ConsoleGetMouse( int *x, int *y, int *z, int *buttons, int *clip )
13 {
14  if (inited == -1) {
15  regs.x.ax = 0x0; /* detect mouse driver and mouse existence */
16  __dpmi_int(0x33, &regs);
17  inited = (regs.x.ax == 0) ? 0 : 1;
18 
19  regs.x.ax = 0x11; /* detect CuteMouse 2.0+ wheel api */
20  __dpmi_int(0x33, &regs);
21  wheel_ok = ((regs.x.ax == 0x574D) && (regs.x.cx & 1));
22 
23  wheel_pos = 0;
24  }
25 
26  if (inited == 0) {
27  if (x) *x = -1;
28  if (y) *y = -1;
29  if (z) *z = -1;
30  if (buttons) *buttons = -1;
32  }
33 
34  regs.x.ax = 0x3;
35  __dpmi_int(0x33, &regs);
36 
37  if (wheel_ok) wheel_pos -= *(signed char *)(&regs.h.bh);
38 
39  if (x) *x = regs.x.cx / 8; /* char width is 8 pixels */
40  if (y) *y = regs.x.dx / 8; /* char height is 8 pixels */
41  if (z) *z = wheel_pos;
42  if (buttons) *buttons = regs.h.bl;
43  if (clip) *clip = 0;
44 
45  return FB_RTERROR_OK;
46 }
47 
48 int fb_ConsoleSetMouse( int x, int y, int cursor, int clip )
49 {
50  int mx, my;
51 
52  fb_ConsoleGetMouse(&mx, &my, NULL, NULL, NULL);
53 
55 
56  if (x >= 0) mx = x * 8;
57  if (y >= 0) my = y * 8;
58 
59  regs.x.ax = 0x4;
60  regs.x.cx = mx;
61  regs.x.dx = my;
62  __dpmi_int(0x33, &regs);
63 
64  return FB_RTERROR_OK;
65 }