From: troyer@saifr00.cfsat.honeywell.com (Dean Troyer)
Subject: Re: PS/2 mouse recognized, but not working (0.98 SLS)
Organization: Honeywell Air Transport Systems Division
Date: Thu, 15 Oct 92 17:19:27 GMT

In article <1992Oct15.154545.51633@watson.ibm.com> heeb@watson.ibm.com (Hansruedi Heeb) writes:
>I have problems getting a PS/2 mouse to work under 0.98 SLS.
>After applying Dean Troyer's patch to the kernel my PS/2
>mouse is installed at boot time (I hope that patch makes it
>into the "official" sources, Linus are you listening ?).
>
>Unfortunately I cannot get it to work under X no matter what I put
>into 'Xconfig'. What is the correct entry for a PS/2 mouse ?
>'sthomas@worldbank.org' reported a similar problem with a 
>Logitech busmouse. So there seems to be something wrong.
>Any clues ?

You need to convert the PS/2 protocol to Microsoft protocol (or anything
else supported by X).  BTW, I think a future version of Xfree86 will
support the Ps/2 protocol directly.

Here's the mconv program that will do the conversion to Microsoft for you.
It's very straightforward to use, as explained in the comments.

----------begin----------
/*
 * Microsoft serial mouse emulator for PS/2 mouse.
 *
 * This program converts the byte stream generated by a PS/2 mouse to
 * the corresponding Microsoft serial mouse byte stream.
 *
 * Give as an argument the master side of a free pseudo tty, for
 * instance:
 *
 * mconv /dev/ptyp1 &
 *
 * Specify the corresponding slave pty as the mouse device in Xconfig:
 *
 * Microsoft "/dev/ttyp1"
 *
 * This is an ugly hack; PS/2 mouse support should be added to X386.
 *
 * 
 * Johan Myreen
 * jem@cs.hut.fi
 */


#include <fcntl.h>
#include <stdio.h>
#include <signal.h>

#define MOUSE "/dev/psaux"

extern int errno;

static int pty, mouse;

void handler()
{
  fprintf(stderr, "\nMouse killed!\n");
  close(pty);
  close(mouse);
  exit(0);
}

unsigned char getbyte(void)
{
  static unsigned char buf[1024];
  static unsigned char *bp = buf, *ep = buf;
  int n;

  if (bp == ep) {
    bp = ep = buf;
    n = read(mouse, buf, 1024);
    if (n>0) {
      ep += n;
    }
  }
  return *bp++;
}


void track_mouse(void)
{
  unsigned char byte1, byte2, byte3, out[3], outbyte;

  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;
    if (write(pty, out, 3) < 0)
      return;
  }
}


int main(int argc, char **argv)
{

  if (argc < 2) {
    fprintf(stderr, "Usage: %s /dev/ptypX, where X = 0..9 or a..f.\n", argv[0]);
    exit(1);
  }

  pty = open(argv[1], O_RDWR);

  if (pty < 0) {
    fprintf(stderr, "Error %d opening pty. Exiting.\n", errno);
    exit(1);
  }

  mouse = open(MOUSE, O_RDWR);

  if (mouse < 0) {
    fprintf(stderr, "Error %d opening mouse. Exiting.\n", errno);
    close(pty);
    exit(1);
  }

  signal(SIGTERM, handler);
  signal(SIGINT, handler);
  signal(SIGHUP, handler);

  track_mouse();

  fprintf(stderr, "Error %d reading or writing.\n", errno);
  close(pty);
  close(mouse);
}
----------end----------

dt

-- 
Dean Troyer                               troyer@saifr00.cfsat.Honeywell.COM
Honeywell Commercial Flight Systems       72240.3152@compuserve.com
Phoenix AZ
(602) 436-3613
Newsgroups: comp.os.linux