home *** CD-ROM | disk | FTP | other *** search
/ Prima Shareware 3 / DuCom_Prima-Shareware-3_cd1.bin / PROGRAMO / C / ATOLKIT / MOUSE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-11  |  3.8 KB  |  117 lines

  1.  
  2. #include <dos.h>                                 /* for REGS struct definitions */
  3.  
  4. #define MOLPTR (MOUSEPTR) 0             /* A TRUE NULL MOUSE POINTER */
  5. #define NULPTR  (char *) 0              /* null pointer */
  6. #define MO_LEFT   0                     /* Mouse left button used by mo_wait */
  7. #define MO_RIGHT  1                     /* Mouse right button used by mo_wait */
  8. #define MO_HDW    1                     /* Mouse hardware */
  9. #define MO_SFT    0                     /* Mouse software */
  10.  
  11. typedef struct mcb                      /* Mouse control block structure */
  12. {
  13. int exists,                             /* TRUE if MOUSE exists */
  14.     nbuts,                              /* number of buttons */
  15.     bstat,                              /* button status */
  16.     nclik,                              /* number of clicks */
  17.     col,                                /* position - column */
  18.     row,                                /* position - row */
  19.     hmove,                              /* net horizontal movement */
  20.     vmove;                              /* net vertical movement */
  21.     char *handle;                       /* my own id */
  22. } MOUSE, *MOUSEPTR;         
  23.  
  24.  
  25.  
  26. #define MOCAL  int86 (0x33, &crp, &rrp)
  27. #define MOCALX int86x(0x33, &crp, &rrp, &srp)
  28.  
  29. static MOUSE mm;                        /* mouse control block */
  30. static MOUSEPTR m = &mm;                /* our mouse (static) */
  31. static union REGS crp, rrp;             /* common hdw registers */
  32. static struct SREGS srp;                /* common segment registers */
  33.  
  34.  
  35.  
  36. /*
  37. ************
  38. * mo_reset * +
  39. ************
  40. */
  41.  
  42. MOUSEPTR mo_reset()                     /* mouse reset (initialize) */
  43. {
  44.   crp.x.ax = 0;                         /* function 0 - reset */
  45.   MOCAL;                                /* do the int */
  46.   m->exists = rrp.x.ax;                 /* to exist or not to exist!! */
  47.   m->nbuts = rrp.x.bx;                  /* number of buttons */
  48.   if(m->exists) {                       /* do I exist ? */
  49.     m->handle = (char*)m;               /* set pointer to myself */
  50.     return(m);
  51.   }
  52.   else {
  53.     m->handle = NULPTR;                 /* set handle to ozone */
  54.     return(MOLPTR);                     /* return null MOUSEPTR */
  55.   }
  56. }
  57.  
  58.  
  59. /*
  60. **********
  61. * mo_pos * +
  62. **********
  63. */
  64.  
  65. void mo_pos(m)                          /* get position and button status */
  66. MOUSEPTR m;
  67. {
  68.   if(m != (MOUSEPTR)m->handle)          /* always perform the standard */
  69.                           ;                   /* safety check */
  70.   crp.x.ax = 3;                         /* function 3 - get position */
  71.   MOCAL;                                /* fetch location */
  72.   m->bstat = rrp.x.bx;                  /* button status */
  73.   m->row = rrp.x.dx;                    /* vertical (row) location */
  74.   m->col = rrp.x.cx;                    /* horizontal (col) location */
  75. }
  76.  
  77.  
  78. /*
  79. ***********
  80. * mo_clim * +
  81. ***********
  82. */
  83.  
  84. void mo_clim(m,cmin,cmax)               /* set min/max col limits (range) */
  85. MOUSEPTR m;
  86. int cmin, cmax;
  87. {
  88.   if(m != (MOUSEPTR)m->handle)          /* always perform the standard */
  89.                             ;                  /* safety check */
  90.   crp.x.ax = 7;                         /* function 7 - col range */
  91.   crp.x.cx = cmin;                      /* lower limit */
  92.   crp.x.dx = cmax;                      /* upper limit */
  93.   MOCAL;
  94. }
  95.  
  96. /*
  97. ***********
  98. * mo_rlim * +
  99. ***********
  100. */
  101.  
  102. void mo_rlim(m,rmin,rmax)               /* set min/max row limits (range) */
  103. MOUSEPTR m;
  104. int rmin, rmax;
  105. {
  106.   if(m != (MOUSEPTR)m->handle)          /* always perform the standard */
  107.                             ;                  /* safety check */
  108.   crp.x.ax = 8;                         /* function 8 - row range */
  109.   crp.x.cx = rmin;                      /* lower limit */
  110.   crp.x.dx = rmax;                      /* upper limit */
  111.   MOCAL;
  112. }
  113.  
  114.  
  115. /* End */
  116.  
  117.