0033130632c3546bf7bfc0d85aacd1bc2980ca5f
[dosdemo] / src / dos / mouse.c
1 #include "mouse.h"
2
3 typedef unsigned short uint16_t;
4
5 #define INTR    0x33
6
7 #define QUERY   0
8 #define SHOW    1
9 #define HIDE    2
10 #define READ    3
11 #define WRITE   4
12 #define PIXRATE 0xf
13
14 #define XLIM    7
15 #define YLIM    8
16
17 int have_mouse(void)
18 {
19         uint16_t res = 0;
20 #ifdef __WATCOMC__
21         _asm {
22                 mov eax, QUERY
23                 int INTR
24                 mov res, ax
25         }
26 #endif
27         return res;
28 }
29
30 void show_mouse(int show)
31 {
32         uint16_t cmd = show ? SHOW : HIDE;
33 #ifdef __WATCOMC__
34         _asm {
35                 mov ax, cmd
36                 int INTR
37         }
38 #endif
39 }
40
41 int read_mouse(int *xp, int *yp)
42 {
43         uint16_t x, y, state;
44 #ifdef __WATCOMC__
45         _asm {
46                 mov eax, READ
47                 int INTR
48                 mov state, bx
49                 mov x, cx
50                 mov y, dx
51         }
52 #endif
53 #ifdef __DJGPP__
54         x = y = state = 0;
55 #endif
56
57         if(xp) *xp = x;
58         if(yp) *yp = y;
59         return state;
60 }
61
62 void set_mouse(int x, int y)
63 {
64 #ifdef __WATCOMC__
65         _asm {
66                 mov eax, WRITE
67                 mov ecx, x
68                 mov edx, y
69                 int INTR
70         }
71 #endif
72 }
73
74 void set_mouse_limits(int xmin, int ymin, int xmax, int ymax)
75 {
76 #ifdef __WATCOMC__
77         _asm {
78                 mov eax, XLIM
79                 mov ecx, xmin
80                 mov edx, xmax
81                 int INTR
82                 mov eax, YLIM
83                 mov ecx, ymin
84                 mov edx, ymax
85                 int INTR
86         }
87 #endif
88 }
89
90 void set_mouse_rate(int xrate, int yrate)
91 {
92 #ifdef __WATCOMC__
93         _asm {
94                 mov ax, PIXRATE
95                 mov ecx, xrate
96                 mov edx, yrate
97                 int INTR
98         }
99 #endif
100 }
101
102 void set_mouse_mode(enum mouse_mode mode)
103 {
104         if(mode == MOUSE_GFX) {
105                 set_mouse_rate(1, 1);
106         } else {
107                 set_mouse_rate(8, 16);
108         }
109 }