home *** CD-ROM | disk | FTP | other *** search
- /*
- * Mouse routines for the Microsoft serial mouse and compatibles.
- *
- * Adapted from routines posted by john@bby-bc.UUCP in <146@bby-bc.UUCP>.
- *
- * Anthony J. Starks (ajs@mdri)
- */
- #include <fcntl.h>
- #include <errno.h>
- #include <termio.h>
- #include "smouse.h"
-
- static int mfd;
-
- MouseInit()
- {
- struct termio t;
-
- errno = 0;
- if ((mfd = open(MOUSE_DEV, O_RDONLY)) < 0)
- {
- perror("mouse open");
- return SYSERR;
- }
-
- if (ioctl(mfd,TCGETA, &t) < 0)
- {
- perror("mouse get parameter");
- return SYSERR;
- }
-
- t.c_iflag &= ~(IXON|IXOFF|ISTRIP|INLCR|IGNCR|ICRNL|IUCLC|INPCK);
- t.c_cflag = B1200 | CS8 | CLOCAL | CREAD ;
- t.c_lflag = 0;
-
- if (ioctl(mfd,TCSETA, &t) < 0)
- {
- perror("mouse set parameter");
- return SYSERR;
- }
-
- return SUCCESS;
- }
-
- MouseRead(m)
- Mouse *m;
- {
- unsigned char b;
- char coord[NCOORD];
-
- /*
- * Synchronize on a button byte
- */
- for (b=0; (b&0370) != 0200 ; )
- if (read(mfd, &b, 1) < 0) return SYSERR;
-
- /*
- * Read the coordinates
- */
- if (read(mfd, coord, NCOORD) < 0) return SYSERR;
-
- /*
- * Read button bits
- */
-
- m->button[2] = (~b) & 1;
- m->button[1] = (~(b>>1)) & 1;
- m->button[0] = (~(b>>2)) & 1;
-
- /*
- * Pack up the coordinate half-words
- */
- m->dx = (int)(coord[0] + coord[2]);
- m->dy = (int)(coord[1] + coord[3]);
-
- return SUCCESS;
-
- }
-
- MouseClose()
- {
- close(mfd);
- }
-