summaryrefslogtreecommitdiff
path: root/src/glut/dos/PC_HW/pc_mouse.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/glut/dos/PC_HW/pc_mouse.c')
-rw-r--r--src/glut/dos/PC_HW/pc_mouse.c269
1 files changed, 142 insertions, 127 deletions
diff --git a/src/glut/dos/PC_HW/pc_mouse.c b/src/glut/dos/PC_HW/pc_mouse.c
index fc0902ce81..5bf99d367f 100644
--- a/src/glut/dos/PC_HW/pc_mouse.c
+++ b/src/glut/dos/PC_HW/pc_mouse.c
@@ -1,7 +1,7 @@
/*
* PC/HW routine collection v1.3 for DOS/DJGPP
*
- * Copyright (C) 2002 - Borca Daniel
+ * Copyright (C) 2002 - Daniel Borca
* Email : dborca@yahoo.com
* Web : http://www.geocities.com/dborca
*/
@@ -14,16 +14,15 @@
#include "pc_hw.h"
-
#define PC_CUTE_WHEEL 1 /* CuteMouse WheelAPI */
#define MOUSE_STACK_SIZE 16384
#define CLEAR_MICKEYS() \
- do { \
- __asm __volatile ("movw $0xb, %%ax; int $0x33":::"%eax", "%ecx", "%edx"); \
- ox = oy = 0; \
- } while (0)
+ do { \
+ __asm __volatile ("movw $0xb, %%ax; int $0x33":::"%eax", "%ecx", "%edx"); \
+ ox = oy = 0; \
+ } while (0)
extern void mouse_wrap (void);
extern int mouse_wrap_end[];
@@ -33,7 +32,7 @@ static long mouse_callback;
static __dpmi_regs mouse_regs;
static volatile struct {
- volatile int x, y, z, b;
+ volatile int x, y, z, b;
} pc_mouse;
static int minx = 0;
@@ -51,41 +50,44 @@ static int emulat3 = FALSE;
static int ox, oy;
-static void mouse (__dpmi_regs *r)
+static void
+mouse (__dpmi_regs *r)
{
- int nx = (signed short)r->x.si / sx;
- int ny = (signed short)r->x.di / sy;
- int dx = nx - ox;
- int dy = ny - oy;
+ int nx = (signed short)r->x.si / sx;
+ int ny = (signed short)r->x.di / sy;
+ int dx = nx - ox;
+ int dy = ny - oy;
#if PC_CUTE_WHEEL
- int dz = (signed char)r->h.bh;
+ int dz = (signed char)r->h.bh;
#endif
- ox = nx;
- oy = ny;
+ ox = nx;
+ oy = ny;
- pc_mouse.b = r->h.bl;
- pc_mouse.x = MID(minx, pc_mouse.x + dx, maxx);
- pc_mouse.y = MID(miny, pc_mouse.y + dy, maxy);
+ pc_mouse.b = r->h.bl;
+ pc_mouse.x = MID(minx, pc_mouse.x + dx, maxx);
+ pc_mouse.y = MID(miny, pc_mouse.y + dy, maxy);
#if PC_CUTE_WHEEL
- pc_mouse.z = MID(minz, pc_mouse.z + dz, maxz);
+ pc_mouse.z = MID(minz, pc_mouse.z + dz, maxz);
#endif
- if (emulat3) {
- if ((pc_mouse.b&3)==3) {
- pc_mouse.b = 4;
- }
- }
+ if (emulat3) {
+ if ((pc_mouse.b & 3) == 3) {
+ pc_mouse.b = 4;
+ }
+ }
- if (mouse_func) {
- mouse_func(pc_mouse.x, pc_mouse.y, pc_mouse.z, pc_mouse.b);
- }
+ if (mouse_func) {
+ mouse_func(pc_mouse.x, pc_mouse.y, pc_mouse.z, pc_mouse.b);
+ }
} ENDOFUNC(mouse)
-void pc_remove_mouse (void)
+
+void
+pc_remove_mouse (void)
{
- if (mouse_callback) {
- pc_clexit(pc_remove_mouse);
- __asm("\n\
+ if (mouse_callback) {
+ pc_clexit(pc_remove_mouse);
+ __asm("\n\
movl %%edx, %%ecx \n\
shrl $16, %%ecx \n\
movw $0x0304, %%ax \n\
@@ -93,61 +95,63 @@ void pc_remove_mouse (void)
movw $0x000c, %%ax \n\
xorl %%ecx, %%ecx \n\
int $0x33 \n\
- "::"d"(mouse_callback):"%eax", "%ecx");
+ "::"d"(mouse_callback):"%eax", "%ecx");
- mouse_callback = 0;
+ mouse_callback = 0;
- free((void *)(mouse_wrap_end[0] - MOUSE_STACK_SIZE));
- }
+ free((void *)(mouse_wrap_end[0] - MOUSE_STACK_SIZE));
+ }
}
-int pc_install_mouse (void)
+
+int
+pc_install_mouse (void)
{
- int buttons;
+ int buttons;
- /* fail if already call-backed */
- if (mouse_callback) {
- return 0;
- }
+ /* fail if already call-backed */
+ if (mouse_callback) {
+ return 0;
+ }
- /* reset mouse and get status */
- __asm("\n\
+ /* reset mouse and get status */
+ __asm("\n\
xorl %%eax, %%eax \n\
int $0x33 \n\
andl %%ebx, %%eax \n\
movl %%eax, %0 \n\
- ":"=g" (buttons)::"%eax", "%ebx");
- if (!buttons) {
- return 0;
- }
-
- /* lock wrapper */
- LOCKDATA(mouse_func);
- LOCKDATA(mouse_callback);
- LOCKDATA(mouse_regs);
- LOCKDATA(pc_mouse);
- LOCKDATA(minx);
- LOCKDATA(maxx);
- LOCKDATA(miny);
- LOCKDATA(maxy);
- LOCKDATA(minz);
- LOCKDATA(maxz);
- LOCKDATA(sx);
- LOCKDATA(sy);
- LOCKDATA(emulat3);
- LOCKDATA(ox);
- LOCKDATA(oy);
- LOCKFUNC(mouse);
- LOCKFUNC(mouse_wrap);
-
- mouse_wrap_end[1] = __djgpp_ds_alias;
- /* grab a locked stack */
- if ((mouse_wrap_end[0] = (int)pc_malloc(MOUSE_STACK_SIZE)) == NULL) {
- return 0;
- }
-
- /* try to hook a call-back */
- __asm("\n\
+ ":"=g" (buttons)::"%eax", "%ebx");
+ if (!buttons) {
+ return 0;
+ }
+
+ /* lock wrapper */
+ LOCKDATA(mouse_func);
+ LOCKDATA(mouse_callback);
+ LOCKDATA(mouse_regs);
+ LOCKDATA(pc_mouse);
+ LOCKDATA(minx);
+ LOCKDATA(maxx);
+ LOCKDATA(miny);
+ LOCKDATA(maxy);
+ LOCKDATA(minz);
+ LOCKDATA(maxz);
+ LOCKDATA(sx);
+ LOCKDATA(sy);
+ LOCKDATA(emulat3);
+ LOCKDATA(ox);
+ LOCKDATA(oy);
+ LOCKFUNC(mouse);
+ LOCKFUNC(mouse_wrap);
+
+ mouse_wrap_end[1] = __djgpp_ds_alias;
+ /* grab a locked stack */
+ if ((mouse_wrap_end[0] = (int)pc_malloc(MOUSE_STACK_SIZE)) == NULL) {
+ return 0;
+ }
+
+ /* try to hook a call-back */
+ __asm("\n\
pushl %%ds \n\
pushl %%es \n\
movw $0x0303, %%ax \n\
@@ -163,86 +167,97 @@ int pc_install_mouse (void)
movw %%dx, %%cx \n\
movl %%ecx, %0 \n\
0: \n\
- ":"=g"(mouse_callback)
- :"S" (mouse_wrap), "D"(&mouse_regs)
- :"%eax", "%ecx", "%edx");
- if (!mouse_callback) {
- free((void *)mouse_wrap_end[0]);
- return 0;
- }
-
- /* adjust stack */
- mouse_wrap_end[0] += MOUSE_STACK_SIZE;
-
- /* install the handler */
- mouse_regs.x.ax = 0x000c;
+ ":"=g"(mouse_callback)
+ :"S" (mouse_wrap), "D"(&mouse_regs)
+ :"%eax", "%ecx", "%edx");
+ if (!mouse_callback) {
+ free((void *)mouse_wrap_end[0]);
+ return 0;
+ }
+
+ /* adjust stack */
+ mouse_wrap_end[0] += MOUSE_STACK_SIZE;
+
+ /* install the handler */
+ mouse_regs.x.ax = 0x000c;
#if PC_CUTE_WHEEL
- mouse_regs.x.cx = 0x7f | 0x80;
+ mouse_regs.x.cx = 0x7f | 0x80;
#else
- mouse_regs.x.cx = 0x7f;
+ mouse_regs.x.cx = 0x7f;
#endif
- mouse_regs.x.dx = mouse_callback&0xffff;
- mouse_regs.x.es = mouse_callback>>16;
- __dpmi_int(0x33, &mouse_regs);
+ mouse_regs.x.dx = mouse_callback & 0xffff;
+ mouse_regs.x.es = mouse_callback >> 16;
+ __dpmi_int(0x33, &mouse_regs);
- CLEAR_MICKEYS();
+ CLEAR_MICKEYS();
- emulat3 = buttons<3;
- pc_atexit(pc_remove_mouse);
- return buttons;
+ emulat3 = (buttons < 3);
+ pc_atexit(pc_remove_mouse);
+ return buttons;
}
-MFUNC pc_install_mouse_handler (MFUNC handler)
+
+MFUNC
+pc_install_mouse_handler (MFUNC handler)
{
- MFUNC old;
+ MFUNC old;
- if (!mouse_callback && !pc_install_mouse()) {
- return NULL;
- }
+ if (!mouse_callback && !pc_install_mouse()) {
+ return NULL;
+ }
- old = mouse_func;
- mouse_func = handler;
- return old;
+ old = mouse_func;
+ mouse_func = handler;
+ return old;
}
-void pc_mouse_area (int x1, int y1, int x2, int y2)
+
+void
+pc_mouse_area (int x1, int y1, int x2, int y2)
{
- minx = x1;
- maxx = x2;
- miny = y1;
- maxy = y2;
+ minx = x1;
+ maxx = x2;
+ miny = y1;
+ maxy = y2;
}
-void pc_mouse_speed (int xspeed, int yspeed)
+
+void
+pc_mouse_speed (int xspeed, int yspeed)
{
- DISABLE();
+ DISABLE();
- sx = MAX(1, xspeed);
- sy = MAX(1, yspeed);
+ sx = MAX(1, xspeed);
+ sy = MAX(1, yspeed);
- ENABLE();
+ ENABLE();
}
-int pc_query_mouse (int *x, int *y, int *z)
+
+int
+pc_query_mouse (int *x, int *y, int *z)
{
- *x = pc_mouse.x;
- *y = pc_mouse.y;
- *z = pc_mouse.z;
- return pc_mouse.b;
+ *x = pc_mouse.x;
+ *y = pc_mouse.y;
+ *z = pc_mouse.z;
+ return pc_mouse.b;
}
-void pc_warp_mouse (int x, int y)
+
+void
+pc_warp_mouse (int x, int y)
{
- CLEAR_MICKEYS();
+ CLEAR_MICKEYS();
- pc_mouse.x = MID(minx, x, maxx);
- pc_mouse.y = MID(miny, y, maxy);
+ pc_mouse.x = MID(minx, x, maxx);
+ pc_mouse.y = MID(miny, y, maxy);
- if (mouse_func) {
- mouse_func(pc_mouse.x, pc_mouse.y, pc_mouse.z, pc_mouse.b);
- }
+ if (mouse_func) {
+ mouse_func(pc_mouse.x, pc_mouse.y, pc_mouse.z, pc_mouse.b);
+ }
}
+
/* Hack alert:
* `mouse_wrap_end' actually holds the
* address of stack in a safe data selector.