fractal effect is cooking
[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         _asm {
21                 mov eax, QUERY
22                 int INTR
23                 mov res, ax
24         }
25         return res;
26 }
27
28 void show_mouse(int show)
29 {
30         uint16_t cmd = show ? SHOW : HIDE;
31         _asm {
32                 mov ax, cmd
33                 int INTR
34         }
35 }
36
37 int read_mouse(int *xp, int *yp)
38 {
39         uint16_t x, y, state;
40         _asm {
41                 mov eax, READ
42                 int INTR
43                 mov state, bx
44                 mov x, cx
45                 mov y, dx
46         }
47
48         if(xp) *xp = x;
49         if(yp) *yp = y;
50         return state;
51 }
52
53 void set_mouse(int x, int y)
54 {
55         _asm {
56                 mov eax, WRITE
57                 mov ecx, x
58                 mov edx, y
59                 int INTR
60         }
61 }
62
63 void set_mouse_limits(int xmin, int ymin, int xmax, int ymax)
64 {
65         _asm {
66                 mov eax, XLIM
67                 mov ecx, xmin
68                 mov edx, xmax
69                 int INTR
70                 mov eax, YLIM
71                 mov ecx, ymin
72                 mov edx, ymax
73                 int INTR
74         }
75 }
76
77 void set_mouse_rate(int xrate, int yrate)
78 {
79         _asm {
80                 mov ax, PIXRATE
81                 mov ecx, xrate
82                 mov edx, yrate
83                 int INTR
84         }
85 }
86
87 void set_mouse_mode(enum mouse_mode mode)
88 {
89         if(mode == MOUSE_GFX) {
90                 set_mouse_rate(1, 1);
91         } else {
92                 set_mouse_rate(8, 16);
93         }
94 }