Nuke unused header files
[dragonfly/port-amd64.git] / usr.bin / doscmd / mouse.c
blob2614107687ece095166927503efbccbeb8568185
1 /*
2 * Copyright (c) 1992, 1993, 1996
3 * Berkeley Software Design, Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Berkeley Software
16 * Design, Inc.
18 * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
30 * BSDI int33.c,v 2.2 1996/04/08 19:32:54 bostic Exp
32 * $FreeBSD: src/usr.bin/doscmd/mouse.c,v 1.3.2.1 2002/04/25 11:04:51 tg Exp $
33 * $DragonFly: src/usr.bin/doscmd/mouse.c,v 1.2 2003/06/17 04:29:26 dillon Exp $
36 #include "doscmd.h"
37 #include "mouse.h"
39 mouse_t mouse_status;
40 u_char *mouse_area = 0;
41 int nmice = 1;
43 static void
44 mouse_probe(void)
48 void
49 int33(regcontext_t *REGS)
51 u_long vec;
52 u_short mask;
53 int i;
55 if (!nmice) {
56 R_FLAGS |= PSL_C; /* We don't support a mouse */
57 return;
60 printf("Mouse: %02x\n", R_AX);
61 switch (R_AX) {
62 case 0x00: /* Reset Mouse */
63 printf("Installing mouse driver\n");
64 R_AX = 0xffff; /* Mouse installed */
65 R_BX = 2; /* Number of mouse buttons */
66 memset(&mouse_status, 0, sizeof(mouse_status));
67 mouse_status.installed = 1;
68 mouse_status.hardcursor = 1;
69 mouse_status.end = 16;
70 mouse_status.hmickey = 8;
71 mouse_status.vmickey = 16;
72 mouse_status.doubling = 100;
73 mouse_status.init = -1;
74 mouse_status.range.w = 8 * 80;
75 mouse_status.range.h = 16 * 25;
76 break;
78 case 0x01: /* Display Mouse Cursor */
79 if ((mouse_status.init += 1) == 0) {
80 mouse_status.show = 1;
82 break;
84 case 0x02: /* Hide Mouse Cursor */
85 if (mouse_status.init == 0)
86 mouse_status.show = 0;
87 mouse_status.init -= 1;
88 break;
90 case 0x03: /* Get cursor position/button status */
91 mouse_probe();
92 R_CX = mouse_status.x;
93 R_DX = mouse_status.y;
94 R_BX = mouse_status.buttons;
95 break;
97 case 0x04: /* Move mouse cursor */
98 /* mouse_move(GET16(sc->sc_ecx), GET16(sc->sc_edx)); */
99 break;
101 case 0x05: /* Determine number of times mouse button was active */
102 i = R_BX & 3;
103 if (i == 3)
104 i = 1;
106 R_BX = mouse_status.downs[i];
107 mouse_status.downs[i] = 0;
108 R_AX = mouse_status.buttons;
109 R_CX = mouse_status.x; /* Not quite right */
110 R_DX = mouse_status.y; /* Not quite right */
111 break;
113 case 0x06: /* Determine number of times mouse button was relsd */
114 i = R_DX & 3;
115 if (i == 3)
116 i = 1;
118 R_BX = mouse_status.ups[i];
119 mouse_status.ups[i] = 0;
120 R_AX = mouse_status.buttons;
121 R_CX = mouse_status.x; /* Not quite right */
122 R_DX = mouse_status.y; /* Not quite right */
123 break;
125 case 0x07: /* Set min/max horizontal cursor position */
126 mouse_status.range.x = R_CX;
127 mouse_status.range.w = R_DX - R_CX;
128 break;
130 case 0x08: /* Set min/max vertical cursor position */
131 mouse_status.range.y = R_CX;
132 mouse_status.range.h = R_DX - R_CX;
134 case 0x09: /* Set graphics cursor block */
135 /* BX,CX is hot spot, ES:DX is data. */
136 break;
138 case 0x0a: /* Set Text Cursor */
139 mouse_status.hardcursor = R_BX ? 1 : 0;
140 mouse_status.start = R_CX;
141 mouse_status.end = R_CX; /* XXX is this right ? */
142 break;
144 case 0x0b: /* Read Mouse Motion Counters */
145 mouse_probe();
146 R_CX = mouse_status.x - mouse_status.lastx;
147 R_DX = mouse_status.y - mouse_status.lasty;
148 break;
150 case 0x0c: /* Set event handler */
151 mouse_status.mask = R_CX;
152 mouse_status.handler = MAKEVEC(R_ES, R_DX);
153 break;
155 case 0x0d: /* Enable light pen */
156 case 0x0e: /* Disable light pen */
157 break;
159 case 0x0f: /* Set cursor speed */
160 mouse_status.hmickey = R_CX;
161 mouse_status.vmickey = R_DX;
162 break;
164 case 0x10: /* Exclusive area */
165 mouse_status.exclude.x = R_CX;
166 mouse_status.exclude.y = R_DX;
167 mouse_status.exclude.w = R_SI - R_CX;
168 mouse_status.exclude.h = R_DI - R_DX;
169 break;
171 case 0x13: /* Set maximum for mouse speed doubling */
172 break;
173 case 0x14: /* Exchange event handlers */
174 mask = mouse_status.mask;
175 vec = mouse_status.handler;
177 mouse_status.mask = R_CX;
178 mouse_status.handler = MAKEVEC(R_ES, R_DX);
179 R_CX = mask;
180 PUTVEC(R_ES, R_DX, vec);
181 break;
183 case 0x15: /* Determine mouse status buffer size */
184 R_BX = sizeof(mouse_status);
185 break;
187 case 0x16: /* Store mouse buffer */
188 memcpy((char *)MAKEPTR(R_ES, R_DX), &mouse_status,
189 sizeof(mouse_status));
190 break;
192 case 0x17: /* Restore mouse buffer */
193 memcpy(&mouse_status, (char *)MAKEPTR(R_ES, R_DX),
194 sizeof(mouse_status));
195 break;
197 case 0x18: /* Install alternate handler */
198 mask = R_CX & 0xff;
199 if ((R_CX & 0xe0) == 0x00 ||
200 mask == mouse_status.altmask[0] ||
201 mask == mouse_status.altmask[1] ||
202 mask == mouse_status.altmask[2] ||
203 (mouse_status.altmask[i = 0] &&
204 mouse_status.altmask[i = 1] &&
205 mouse_status.altmask[i = 2])) {
206 R_AX = 0xffff;
207 break;
209 mouse_status.altmask[i] = R_CX;
210 mouse_status.althandler[i] = MAKEVEC(R_ES, R_DX);
211 break;
213 case 0x19: /* Determine address of alternate event handler */
214 mask = R_CX & 0xff;
215 if (mask == mouse_status.altmask[0])
216 vec = mouse_status.althandler[0];
217 else if (mask == mouse_status.altmask[1])
218 vec = mouse_status.althandler[1];
219 else if (mask == mouse_status.altmask[2])
220 vec = mouse_status.althandler[2];
221 else
222 R_CX = 0;
223 PUTVEC(R_ES, R_DX, vec);
224 break;
226 case 0x1a: /* set mouse sensitivity */
227 mouse_status.hmickey = R_BX;
228 mouse_status.vmickey = R_CX;
229 mouse_status.doubling = R_DX;
230 break;
232 case 0x1b: /* get mouse sensitivity */
233 R_BX = mouse_status.hmickey;
234 R_CX = mouse_status.vmickey;
235 R_DX = mouse_status.doubling;
236 break;
238 case 0x1c: /* set mouse hardware rate */
239 case 0x1d: /* set display page */
240 break;
242 case 0x1e: /* get display page */
243 R_BX = 0; /* Always on display page 0 */
244 break;
246 case 0x1f: /* Disable mouse driver */
247 if (mouse_status.installed) {
248 PUTVEC(R_ES, R_DX, mouse_status.handler);
249 mouse_status.installed = 0;
250 } else {
251 R_AX = 0xffff;
253 break;
255 case 0x20: /* Enable mouse driver */
256 mouse_status.installed = 1;
257 break;
259 case 0x21: /* Reset mouse driver */
260 if (mouse_status.installed) {
261 mouse_status.show = 0;
262 mouse_status.handler = 0;
263 mouse_status.mask = 0;
264 mouse_status.cursor = 0;
265 } else {
266 R_AX = 0xffff;
268 break;
270 case 0x22: /* Specified language for mouse messages */
271 break;
273 case 0x23: /* Get language number */
274 R_BX = 0; /* Always return english */
275 break;
277 case 0x24: /* Get mouse type */
278 R_CX = 0x0400; /* PS/2 style mouse */
279 R_BX = 0x0600 + 24; /* Version 6.24 */
280 break;
282 default:
283 R_FLAGS |= PSL_C;
284 break;
288 void
289 mouse_init(void)
291 u_long vec;
293 vec = insert_softint_trampoline();
294 ivec[0x33] = vec;
295 register_callback(vec, int33, "int 33");
297 mouse_area[1] = 24;