home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8708 / 27 / smouse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-13  |  1.3 KB  |  84 lines

  1. /*
  2.  *  Mouse routines for the Microsoft serial mouse and compatibles.
  3.  *
  4.  *  Adapted from routines posted by john@bby-bc.UUCP in <146@bby-bc.UUCP>.
  5.  *
  6.  *  Anthony J. Starks (ajs@mdri)
  7.  */
  8. #include    <fcntl.h>
  9. #include    <errno.h>
  10. #include    <termio.h>
  11. #include    "smouse.h"
  12.  
  13. static int mfd;
  14.  
  15. MouseInit()
  16. {
  17.     struct termio t;
  18.     
  19.     errno = 0;
  20.     if ((mfd = open(MOUSE_DEV, O_RDONLY)) < 0) 
  21.     {
  22.         perror("mouse open");
  23.         return SYSERR;
  24.     }
  25.  
  26.     if (ioctl(mfd,TCGETA, &t) < 0)
  27.     {
  28.         perror("mouse get parameter");
  29.         return SYSERR;
  30.     }
  31.         
  32.     t.c_iflag &= ~(IXON|IXOFF|ISTRIP|INLCR|IGNCR|ICRNL|IUCLC|INPCK);
  33.     t.c_cflag = B1200 | CS8 | CLOCAL | CREAD ;
  34.     t.c_lflag = 0;
  35.  
  36.     if (ioctl(mfd,TCSETA, &t) < 0)
  37.     {
  38.         perror("mouse set parameter");
  39.         return SYSERR;
  40.     }
  41.     
  42.     return SUCCESS;
  43. }
  44.  
  45. MouseRead(m)
  46. Mouse *m;
  47. {
  48.     unsigned char    b;
  49.     char        coord[NCOORD];
  50.  
  51.     /*
  52.      *  Synchronize on a button byte
  53.      */
  54.     for (b=0; (b&0370) != 0200 ; ) 
  55.         if (read(mfd, &b, 1) < 0) return SYSERR;
  56.     
  57.     /*
  58.      *  Read the coordinates
  59.      */
  60.     if (read(mfd, coord, NCOORD) < 0) return SYSERR;
  61.     
  62.     /*
  63.      *  Read button bits
  64.      */
  65.  
  66.     m->button[2] = (~b)  & 1;
  67.     m->button[1] = (~(b>>1)) & 1;
  68.     m->button[0] = (~(b>>2)) & 1;
  69.     
  70.     /*
  71.      *  Pack up the coordinate half-words
  72.      */
  73.     m->dx  =  (int)(coord[0] + coord[2]);
  74.     m->dy  =  (int)(coord[1] + coord[3]);
  75.     
  76.     return SUCCESS;
  77.  
  78. }
  79.  
  80. MouseClose()
  81. {
  82.     close(mfd);
  83. }
  84.