cc3396cb213d9559d44bcb76939f94ae6e861b8f
2 * PC/HW routine collection v0.1 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 extern void mouse_wrapper (void);
19 extern void mouse_wrapper_end (void);
21 static MFUNC mouse_func
;
22 static void *mouse_stack
;
23 static long mouse_callback
;
24 static __dpmi_regs mouse_regs
;
26 volatile int pc_mouse_x
, pc_mouse_y
, pc_mouse_b
;
29 static int maxx
= 319;
31 static int maxy
= 199;
36 static int emulat3
= FALSE
;
40 static void mouse (__dpmi_regs
*r
)
42 int nx
= (signed short)r
->x
.si
/ sx
;
43 int ny
= (signed short)r
->x
.di
/ sy
;
50 pc_mouse_x
= MID(minx
, pc_mouse_x
+ dx
, maxx
);
51 pc_mouse_y
= MID(miny
, pc_mouse_y
+ dy
, maxy
);
54 if ((pc_mouse_b
&3)==3) {
60 mouse_func(pc_mouse_x
, pc_mouse_y
, pc_mouse_b
);
64 void pc_remove_mouse (void)
67 pc_clexit(pc_remove_mouse
);
71 movw $0x0304, %%ax \n\
73 movw $0x000c, %%ax \n\
76 "::"d"(mouse_callback
):"%eax", "%ecx");
80 free((void *)((unsigned long)mouse_stack
-MOUSE_STACK_SIZE
));
84 int pc_install_mouse (void)
88 /* fail if already call-backed */
93 /* reset mouse and get status */
99 ":"=g" (buttons
)::"%eax", "%ebx");
105 LOCKDATA(mouse_func
);
106 LOCKDATA(mouse_stack
);
107 LOCKDATA(mouse_callback
);
108 LOCKDATA(mouse_regs
);
109 LOCKDATA(pc_mouse_x
);
110 LOCKDATA(pc_mouse_y
);
111 LOCKDATA(pc_mouse_b
);
122 LOCKFUNC(mouse_wrapper
);
124 /* grab a locked stack */
125 if ((mouse_stack
=pc_malloc(MOUSE_STACK_SIZE
))==NULL
) {
129 /* try to hook a call-back */
133 movw $0x0303, %%ax \n\
146 ":"=g"(mouse_callback
)
147 :"S" (mouse_wrapper
), "D"(&mouse_regs
)
148 :"%eax", "%ecx", "%edx");
149 if (!mouse_callback
) {
155 mouse_stack
= (void *)((unsigned long)mouse_stack
+ MOUSE_STACK_SIZE
);
157 /* install the handler */
158 mouse_regs
.x
.ax
= 0x000c;
159 mouse_regs
.x
.cx
= 0x007f;
160 mouse_regs
.x
.dx
= mouse_callback
&0xffff;
161 mouse_regs
.x
.es
= mouse_callback
>>16;
162 __dpmi_int(0x33, &mouse_regs
);
165 pc_atexit(pc_remove_mouse
);
169 MFUNC
pc_install_mouse_handler (MFUNC handler
)
173 if (!mouse_callback
&& !pc_install_mouse()) {
178 mouse_func
= handler
;
182 void pc_mouse_area (int x1
, int y1
, int x2
, int y2
)
190 void pc_mouse_speed (int xspeed
, int yspeed
)
200 void pc_show_mouse (void)
202 /* not implemented */
204 void pc_scare_mouse (void)
206 /* not implemented */
208 void pc_unscare_mouse (void)
210 /* not implemented */
215 .global _mouse_wrapper \n\
219 movl %eax, %es:42(%edi) \n\
220 addw $4, %es:46(%edi) \n\
224 movl %cs:___djgpp_ds_alias, %ss \n\
225 movl %cs:_mouse_stack, %esp \n\
230 movl ___djgpp_dos_sel, %fs \n\
242 .global _mouse_wrapper_end \n\
243 _mouse_wrapper_end:");