From: AA Acero (ace3@quads.uchicago.edu)
Date: 02/12/93


From: ace3@quads.uchicago.edu (AA Acero (Tony))
Subject: Re: X386 and Trackman's 3rd button
Date: 12 Feb 1993 17:33:04 GMT

The following solution is ugly, temporary, and will probably be
superceded when the next version of Xfree86 is released; in other words,
it is a bad hack, but I just couldn't stand it anymore. And, it works
(for me). I tried patching Xlinux.8514 (with emacs!) but I couldn't find
the correct offsets to fix up the middle button press/release codes for
the US Logitech Trackman (0x21/0x01 instead of 0x20/0x00).

        1. Hack mconv.c (nic.funet.fi:pub/OS/Linux/tools) so that it acts
like a filter -- converts the 4th byte from 0x21 -> 0x20 or 0x01 -> 0x00.
Apply first patch below and then:
        patch -p0 < mconv.patch
        gcc -O2 -m486 -o mconv mconv.c
        mv mconv /usr/X386/bin

        2. Hack mouse.c in the /usr/X386/tst/mouse to initialize the
mouse port; apply the second patch below, and then:
        cp mouse.c mouseinit.c
        patch -p0 < mouseinit.patch
        gcc -O2 -m486 -o mouseinit mouseinit.c
        mv mouseinit /usr/X386/bin

        3. Add the following lines to /etc/rc.local (or /etc/rc if you
don't have /etc/rc.local) replacing '/dev/ttys0' with the serial port of
your Trackman:
        /usr/X386/bin/mouseinit Microsoft /dev/ttys0
        /usr/X386/bin/mconv /dev/ttys0 /dev/mouse&

        Note: I realize I should have merged mouseinit and mconv, but
think of the nano-bytes of memory we're saving by not including the
initialization code in mconv?! :-)

        4. Create the mouse fifo with the command:
        mkfifo -m 666 /dev/mouse

        5. Edit the Xconfig file so that the mouse driver line is as
follows:
        Microsoft "/dev/mouse"

        6. Reboot, or source the /etc/rc.local file (if it's safe to do
so), to load mconv.

        7. And, finally
        startx

        Some words of caution -- this has not been debugged. There
appears to be some slight slow-down of the other serial ports -- I can't
tell if it's real or if it's in my head, but it's something to keep in
mind.

Enjoy!

Tony Acero

Tony Acero \ "If I have seen further, it is because I have stood /U Chicago
ICS: LLama \ on the shoulders of giants." Isaac Newton /chem grad
'a coy tenor'\____________________________________________________/ '93? :-)
  ace3@quads.uchicago.edu | (312)702-8214 (work) | (312)752-5464 (home)

Patch 1: for mconv.c
*** mconv.c.orig Fri Feb 12 10:44:58 1993
--- mlogi.c Fri Feb 12 08:42:15 1993
***************
*** 85,107 ****
  {
    unsigned char byte1, byte2, byte3, out[3], outbyte;
    int ret;
  
    while (1) {
      byte1 = getbyte();
! if (byte1 & 0xc0)
        continue; /* Resynchronize */
! byte2 = getbyte();
! byte3 = getbyte();
! byte3 = -byte3;
! outbyte = 0x40;
! outbyte |= ((byte2 >> 6)&0x03);
! outbyte |= ((byte3 >> 4)&0x0c);
! outbyte |= (byte1&0x01) << 5; /* Left button */
! outbyte |= (byte1&0x02) << 3; /* Right button */
! out[0] = outbyte;
! out[1] = (byte2)&0x3f;
! out[2] = (byte3)&0x3f;
      ret = write(fifo, out, 3);
      if (ret < 0 && errno != EPIPE)
        return;
    }
--- 85,110 ----
  {
    unsigned char byte1, byte2, byte3, out[3], outbyte;
    int ret;
+ static int release_flag=0;
  
    while (1) {
      byte1 = getbyte();
! if (release_flag){
! release_flag = 0;
! if (byte1 == 0x21 || byte1 == 0x01) {
! out[0] = byte1 - 1;
! ret = write(fifo, out, 1);
! continue;
! }
! }
!
! if (byte1 == 'M' || byte1 == 33)
        continue; /* Resynchronize */
! out[0] = byte1;
! out[1] = getbyte();
! out[2] = getbyte();
      ret = write(fifo, out, 3);
+ if ( out[0] == 0x40 && out[1] == 0 && out[2] == 0) release_flag = 1;
      if (ret < 0 && errno != EPIPE)
        return;
    }

Patch 2: for mouseinit.c
*** mouseinit.c.orig Fri Feb 12 11:22:29 1993
--- mouseinit.c Fri Feb 12 09:01:12 1993
***************
*** 341,353 ****
    x386MseProc(DEVICE_ON);
  /* outb (0x03fb, 0x03); */
  
! signal(SIGINT, stopit);
! fprintf(stderr, "Play with the mouse - hit ctrl-c to stop\n");
    for (;;) {
      if (stop)
            break;
      x386MseEvents();
    }
    x386MseProc(DEVICE_CLOSE);
- fprintf(stderr, "finished.\n");
  }
--- 341,353 ----
    x386MseProc(DEVICE_ON);
  /* outb (0x03fb, 0x03); */
  
! /* signal(SIGINT, stopit);*/
! /* fprintf(stderr, "Play with the mouse - hit ctrl-c to stop\n");
    for (;;) {
      if (stop)
            break;
      x386MseEvents();
    }
+ */
    x386MseProc(DEVICE_CLOSE);
  }

-- 
Tony Acero \  "If I have seen further, it is because I have stood   /U Chicago 
ICS: LLama  \  on the shoulders of giants."  Isaac Newton          /chem grad
'a coy tenor'\____________________________________________________/ '93? :-)
  ace3@quads.uchicago.edu  |  (312)702-8214 (work)  |  (312)752-5464 (home)