2 * PC/HW routine collection v1.3 for DOS/DJGPP
4 * Copyright (C) 2002 - Daniel Borca
5 * Email : dborca@yahoo.com
6 * Web : http://www.geocities.com/dborca
11 #include <sys/exceptn.h>
12 #include <sys/segments.h>
17 #define PC_CUTE_WHEEL 1 /* CuteMouse WheelAPI */
19 #define MOUSE_STACK_SIZE 16384
21 #define CLEAR_MICKEYS() \
23 __asm __volatile ("movw $0xb, %%ax; int $0x33":::"%eax", "%ecx", "%edx"); \
27 extern void mouse_wrap (void);
28 extern int mouse_wrap_end
[];
30 static MFUNC mouse_func
;
31 static long mouse_callback
;
32 static __dpmi_regs mouse_regs
;
34 static volatile struct {
35 volatile int x
, y
, z
, b
;
39 static int maxx
= 319;
41 static int maxy
= 199;
43 static int maxz
= 255;
48 static int emulat3
= FALSE
;
54 mouse (__dpmi_regs
*r
)
56 int nx
= (signed short)r
->x
.si
/ sx
;
57 int ny
= (signed short)r
->x
.di
/ sy
;
61 int dz
= (signed char)r
->h
.bh
;
67 pc_mouse
.x
= MID(minx
, pc_mouse
.x
+ dx
, maxx
);
68 pc_mouse
.y
= MID(miny
, pc_mouse
.y
+ dy
, maxy
);
70 pc_mouse
.z
= MID(minz
, pc_mouse
.z
+ dz
, maxz
);
74 if ((pc_mouse
.b
& 3) == 3) {
80 mouse_func(pc_mouse
.x
, pc_mouse
.y
, pc_mouse
.z
, pc_mouse
.b
);
86 pc_remove_mouse (void)
89 pc_clexit(pc_remove_mouse
);
93 movw $0x0304, %%ax \n\
95 movw $0x000c, %%ax \n\
98 "::"d"(mouse_callback
):"%eax", "%ecx");
102 free((void *)(mouse_wrap_end
[0] - MOUSE_STACK_SIZE
));
108 pc_install_mouse (void)
112 /* fail if already call-backed */
113 if (mouse_callback
) {
117 /* reset mouse and get status */
119 xorl %%eax, %%eax \n\
121 andl %%ebx, %%eax \n\
123 ":"=g" (buttons
)::"%eax", "%ebx");
129 LOCKDATA(mouse_func
);
130 LOCKDATA(mouse_callback
);
131 LOCKDATA(mouse_regs
);
145 LOCKFUNC(mouse_wrap
);
147 mouse_wrap_end
[1] = __djgpp_ds_alias
;
148 /* grab a locked stack */
149 if ((mouse_wrap_end
[0] = (int)pc_malloc(MOUSE_STACK_SIZE
)) == NULL
) {
153 /* try to hook a call-back */
157 movw $0x0303, %%ax \n\
170 ":"=g"(mouse_callback
)
171 :"S" (mouse_wrap
), "D"(&mouse_regs
)
172 :"%eax", "%ecx", "%edx");
173 if (!mouse_callback
) {
174 free((void *)mouse_wrap_end
[0]);
179 mouse_wrap_end
[0] += MOUSE_STACK_SIZE
;
181 /* install the handler */
182 mouse_regs
.x
.ax
= 0x000c;
184 mouse_regs
.x
.cx
= 0x7f | 0x80;
186 mouse_regs
.x
.cx
= 0x7f;
188 mouse_regs
.x
.dx
= mouse_callback
& 0xffff;
189 mouse_regs
.x
.es
= mouse_callback
>> 16;
190 __dpmi_int(0x33, &mouse_regs
);
194 emulat3
= (buttons
< 3);
195 pc_atexit(pc_remove_mouse
);
201 pc_install_mouse_handler (MFUNC handler
)
205 if (!mouse_callback
&& !pc_install_mouse()) {
210 mouse_func
= handler
;
216 pc_mouse_area (int x1
, int y1
, int x2
, int y2
)
226 pc_mouse_speed (int xspeed
, int yspeed
)
238 pc_query_mouse (int *x
, int *y
, int *z
)
248 pc_warp_mouse (int x
, int y
)
252 pc_mouse
.x
= MID(minx
, x
, maxx
);
253 pc_mouse
.y
= MID(miny
, y
, maxy
);
256 mouse_func(pc_mouse
.x
, pc_mouse
.y
, pc_mouse
.z
, pc_mouse
.b
);
262 * `mouse_wrap_end' actually holds the
263 * address of stack in a safe data selector.
268 .global _mouse_wrap \n\
272 movl %eax, %es:42(%edi) \n\
273 addw $4, %es:46(%edi) \n\
277 lss %cs:_mouse_wrap_end, %esp\n\
282 movl ___djgpp_dos_sel, %fs \n\
292 .global _mouse_wrap_end \n\
293 _mouse_wrap_end:.long 0, 0");