[AD] Linux patch -- MS mouse support |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
This patch adds support for MS-compatible mice. You won't be
able to use it though until the setup program supports mouse
configuration, because Allegro will always detect the PS/2
driver in preference to this one, even if you don't have a PS/2
mouse. If you like, you can change the driver ordering so that
the MS driver gets detected first for you, but this is not a
real solution.
Please Cc any replies to me. Thanks.
--
George
diff -urN allegro-3.9.24-6/include/allegro/alunix.h allegro-3.9.24-7/include/allegro/alunix.h
--- allegro-3.9.24-6/include/allegro/alunix.h Tue Jul 20 23:38:14 1999
+++ allegro-3.9.24-7/include/allegro/alunix.h Sat Jul 24 23:50:14 1999
@@ -140,6 +140,9 @@
#define MOUSEDRV_LINUX_GPMDATA AL_ID('G','P','M','D')
AL_VAR(MOUSE_DRIVER, mousedrv_linux_gpmdata);
+#define MOUSEDRV_LINUX_MS AL_ID('M','S',' ',' ')
+AL_VAR(MOUSE_DRIVER, mousedrv_linux_ms);
+
#define JOY_TYPE_LINUX_ANALOGUE AL_ID('L','N','X','A')
AL_VAR(JOYSTICK_DRIVER, joystick_linux_analogue);
diff -urN allegro-3.9.24-6/makefile.lst allegro-3.9.24-7/makefile.lst
--- allegro-3.9.24-6/makefile.lst Tue Jul 20 23:38:14 1999
+++ allegro-3.9.24-7/makefile.lst Sat Jul 24 23:57:18 1999
@@ -209,6 +209,7 @@
src/linux/lmouse.c \
src/linux/lmsedrv.c \
src/linux/lmsegpmd.c \
+ src/linux/lmsems.c \
src/linux/lmseps2.c \
src/linux/lstddrv.c \
src/linux/lsystem.c \
diff -urN allegro-3.9.24-6/src/linux/lmsedrv.c allegro-3.9.24-7/src/linux/lmsedrv.c
--- allegro-3.9.24-6/src/linux/lmsedrv.c Tue Jul 20 23:38:14 1999
+++ allegro-3.9.24-7/src/linux/lmsedrv.c Sat Jul 24 23:48:57 1999
@@ -23,6 +23,7 @@
/* list the available drivers */
_DRIVER_INFO _linux_mouse_driver_list[] =
{
{ MOUSEDRV_LINUX_GPMDATA, &mousedrv_linux_gpmdata, TRUE },
{ MOUSEDRV_LINUX_PS2, &mousedrv_linux_ps2, TRUE },
+ { MOUSEDRV_LINUX_MS, &mousedrv_linux_ms, TRUE },
{ 0, NULL, 0 }
diff -urN allegro-3.9.24-6/src/linux/lmsems.c allegro-3.9.24-7/src/linux/lmsems.c
--- allegro-3.9.24-6/src/linux/lmsems.c Thu Jan 1 01:00:00 1970
+++ allegro-3.9.24-7/src/linux/lmsems.c Sun Jul 25 00:03:14 1999
@@ -0,0 +1,143 @@
+/* ______ ___ ___
+ * /\ _ \ /\_ \ /\_ \
+ * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
+ * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
+ * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
+ * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
+ * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
+ * /\____/
+ * \_/__/
+ *
+ * Linux console internal mouse driver for Microsoft mouse.
+ *
+ * By George Foot.
+ *
+ * See readme.txt for copyright information.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <termios.h>
+
+#include "allegro.h"
+#include "allegro/aintern.h"
+#include "allegro/aintunix.h"
+#include "linalleg.h"
+
+
+#define ASCII_NAME "Linux MS mouse"
+#define DEVICE_FILENAME "/dev/mouse"
+
+
+/* processor:
+ * Processes the first packet in the buffer, if any, returning the number
+ * of bytes eaten.
+ *
+ * Microsoft protocol has only seven data bits. The top bit is set in
+ * the first byte of the packet, clear in the other two. The next two
+ * bits in the header are the button state. The next two are the top
+ * bits of the Y offset (second data byte), and the last two are the
+ * top bits of the X offset (first data byte).
+ */
+static int processor (unsigned char *buf, int buf_size, struct mouse_info *info)
+{
+ info->updated = 0;
+ if (buf_size < 3) return 0; /* not enough data, spit it out for now */
+ if (!(buf[0] & 0x40)) return 1; /* invalid byte, eat it */
+ if (buf[1] & 0x40) return 1; /* first data byte is actually a header */
+ if (buf[2] & 0x40) return 2; /* second data byte is actually a header */
+
+ info->l = !!(buf[0] & 0x20);
+ info->r = !!(buf[0] & 0x10);
+ info->m = 0;
+
+ info->x = (signed char) (((buf[0] & 0x03) << 6) | (buf[1] & 0x3F));
+ info->y = -(signed char) (((buf[0] & 0x0C) << 4) | (buf[2] & 0x3F));
+
+ info->updated = 1;
+ return 3; /* yum */
+}
+
+static INTERNAL_MOUSE_DRIVER intdrv = {
+ -1,
+ processor,
+ 2
+};
+
+/* sync_mouse:
+ * To find the start of a packet, we just read all the data that's
+ * waiting. This isn't a particularly good way, obviously. :)
+ */
+static void sync_mouse (int fd)
+{
+ fd_set set;
+ int result;
+ struct timeval tv;
+ char bitbucket;
+
+ do {
+ FD_ZERO (&set);
+ FD_SET (fd, &set);
+ tv.tv_sec = tv.tv_usec = 0;
+ result = select (FD_SETSIZE, &set, NULL, NULL, &tv);
+ if (result > 0) read (fd, &bitbucket, 1);
+ } while (result > 0);
+}
+
+/* mouse_init:
+ * Here we open the mouse device, initialise anything that needs it,
+ * and chain to the framework init routine.
+ */
+static int mouse_init (void)
+{
+ char tmp[80];
+ struct termios t;
+
+ /* Open mouse device. Devices are cool. */
+ intdrv.device = open (DEVICE_FILENAME, O_RDONLY | O_NONBLOCK);
+ if (intdrv.device < 0) {
+ usprintf (allegro_error, get_config_text ("Unable to open %s: %s"), uconvert_ascii (DEVICE_FILENAME, tmp), ustrerror (errno));
+ return -1;
+ }
+
+ /* Set parameters */
+ tcgetattr (intdrv.device, &t);
+ t.c_iflag = IGNBRK | IGNPAR;
+ t.c_oflag = t.c_lflag = t.c_line = 0;
+ t.c_cflag = CS7 | CREAD | CLOCAL | HUPCL | B1200;
+ tcsetattr (intdrv.device, TCSAFLUSH, &t);
+
+ /* Discard any garbage, so the next thing we read is a packet header */
+ sync_mouse (intdrv.device);
+
+ return __al_linux_mouse_init (&intdrv);
+}
+
+/* mouse_exit:
+ * Chain to the framework, then uninitialise things.
+ */
+static void mouse_exit (void)
+{
+ __al_linux_mouse_exit();
+ close (intdrv.device);
+}
+
+MOUSE_DRIVER mousedrv_linux_ms =
+{
+ MOUSEDRV_LINUX_MS,
+ empty_string,
+ empty_string,
+ ASCII_NAME,
+ mouse_init,
+ mouse_exit,
+ NULL, /* poll() */
+ NULL, /* timer_poll() */
+ __al_linux_mouse_position,
+ __al_linux_mouse_set_range,
+ __al_linux_mouse_set_speed,
+ __al_linux_mouse_get_mickeys
+};
+