2 * PC/HW routine collection v1.2 for DOS/DJGPP
4 * Copyright (C) 2002 - Borca Daniel
5 * Email : dborca@yahoo.com
6 * Web : http://www.geocities.com/dborca
16 #define MOUSE_STACK_SIZE 16384
18 #define CLEAR_MICKEYS() \
20 __asm __volatile ("movw $0xb, %%ax; int $0x33":::"%eax", "%ecx", "%edx"); \
24 extern void mouse_wrapper (void);
25 extern void mouse_wrapper_end (void);
27 static MFUNC mouse_func
;
28 static void *mouse_stack
;
29 static long mouse_callback
;
30 static __dpmi_regs mouse_regs
;
32 static volatile int pc_mouse_x
, pc_mouse_y
, pc_mouse_b
;
35 static int maxx
= 319;
37 static int maxy
= 199;
42 static int emulat3
= FALSE
;
46 static void mouse (__dpmi_regs
*r
)
48 int nx
= (signed short)r
->x
.si
/ sx
;
49 int ny
= (signed short)r
->x
.di
/ sy
;
56 pc_mouse_x
= MID(minx
, pc_mouse_x
+ dx
, maxx
);
57 pc_mouse_y
= MID(miny
, pc_mouse_y
+ dy
, maxy
);
60 if ((pc_mouse_b
&3)==3) {
66 mouse_func(pc_mouse_x
, pc_mouse_y
, pc_mouse_b
);
70 void pc_remove_mouse (void)
73 pc_clexit(pc_remove_mouse
);
77 movw $0x0304, %%ax \n\
79 movw $0x000c, %%ax \n\
82 "::"d"(mouse_callback
):"%eax", "%ecx");
86 free((void *)((unsigned long)mouse_stack
-MOUSE_STACK_SIZE
));
90 int pc_install_mouse (void)
94 /* fail if already call-backed */
99 /* reset mouse and get status */
101 xorl %%eax, %%eax \n\
103 andl %%ebx, %%eax \n\
105 ":"=g" (buttons
)::"%eax", "%ebx");
111 LOCKDATA(mouse_func
);
112 LOCKDATA(mouse_stack
);
113 LOCKDATA(mouse_callback
);
114 LOCKDATA(mouse_regs
);
115 LOCKDATA(pc_mouse_x
);
116 LOCKDATA(pc_mouse_y
);
117 LOCKDATA(pc_mouse_b
);
128 LOCKFUNC(mouse_wrapper
);
130 /* grab a locked stack */
131 if ((mouse_stack
=pc_malloc(MOUSE_STACK_SIZE
))==NULL
) {
135 /* try to hook a call-back */
139 movw $0x0303, %%ax \n\
152 ":"=g"(mouse_callback
)
153 :"S" (mouse_wrapper
), "D"(&mouse_regs
)
154 :"%eax", "%ecx", "%edx");
155 if (!mouse_callback
) {
161 mouse_stack
= (void *)((unsigned long)mouse_stack
+ MOUSE_STACK_SIZE
);
163 /* install the handler */
164 mouse_regs
.x
.ax
= 0x000c;
165 mouse_regs
.x
.cx
= 0x007f;
166 mouse_regs
.x
.dx
= mouse_callback
&0xffff;
167 mouse_regs
.x
.es
= mouse_callback
>>16;
168 __dpmi_int(0x33, &mouse_regs
);
173 pc_atexit(pc_remove_mouse
);
177 MFUNC
pc_install_mouse_handler (MFUNC handler
)
181 if (!mouse_callback
&& !pc_install_mouse()) {
186 mouse_func
= handler
;
190 void pc_mouse_area (int x1
, int y1
, int x2
, int y2
)
198 void pc_mouse_speed (int xspeed
, int yspeed
)
208 int pc_query_mouse (int *x
, int *y
)
215 void pc_show_mouse (void)
217 /* not implemented */
219 void pc_scare_mouse (void)
221 /* not implemented */
223 void pc_unscare_mouse (void)
225 /* not implemented */
231 .global _mouse_wrapper \n\
235 movl %eax, %es:42(%edi) \n\
236 addw $4, %es:46(%edi) \n\
240 movl %cs:___djgpp_ds_alias, %ss \n\
241 movl %cs:_mouse_stack, %esp \n\
246 movl ___djgpp_dos_sel, %fs \n\
257 .global _mouse_wrapper_end \n\
258 _mouse_wrapper_end:");