home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MOUSE / CMOUSE2.ZIP / MOUSE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-21  |  4.9 KB  |  243 lines

  1. /*
  2.     mouse.c -
  3.     Mouse routines adapted from 'The C Gazette', March and Summer 1988.
  4.     For Microsoft C5.1.
  5. */
  6.  
  7. #define MOUSE_LIB
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <dos.h>
  12. #include <mouse.h>
  13.  
  14. int int_flag = 0;
  15. int far _mouseInstalled = 0;
  16. MOUSETRAP far *trap_data;
  17.  
  18. /*
  19.     InitMouse() -
  20.     Checks for the presense of a 2 or 3 button mouse. If present installs
  21.     the mouse interrupt handler to trap button depressions and movement.
  22.     Returns: 0 if no mouse installed, number of buttons if mouse present.
  23. */
  24. int
  25. InitMouse(mask)
  26. int mask;
  27.     {
  28.     int buttons;
  29.     extern void far handler();
  30.     extern void far MouseData();
  31.     void InstallTrap();
  32.     int CheckMouse();
  33.  
  34.     trap_data = (MOUSETRAP far *)MouseData;
  35.     trap_data->what = 0;
  36.     if((buttons = CheckMouse()) == NO_MOUSE)
  37.         return(0);
  38.  
  39.     InstallTrap(mask,    (unsigned)((long) handler >> 16), (unsigned) handler);
  40.     return(buttons);
  41.     }
  42.  
  43. int 
  44. CheckMouse()                        /* returns # mouse buttons        */
  45.     {                                    /* 0 = no mouse                    */
  46.     union REGS inregs;
  47.  
  48.     inregs.x.ax = 0;
  49.     callMDD;
  50.  
  51.     if(!inregs.x.ax)                /* AX = 0, no; AX = -1, yes    */
  52.         return(NO_MOUSE);
  53.     else
  54.         return(inregs.x.bx);    /* BX = # of buttons                */
  55.     }
  56.  
  57. void
  58. CloseMouse()
  59.     {                                    /* just to reset mouse status */
  60.     union REGS inregs;
  61.  
  62.     inregs.x.ax = 0;
  63.     callMDD;
  64.     }
  65.  
  66. void
  67. DisplayMCursor(mode)                /* toggle the display of mouse cursor */
  68. int mode;
  69.     {
  70.     union REGS inregs;
  71.  
  72.     inregs.x.ax = mode;
  73.     callMDD;
  74.     }
  75.  
  76. int
  77. CheckPosition(p_x, p_y)            /* Checks buttons pressed and position */
  78. int *p_x,                            /* of mouse. It is passed pointers to    */
  79.      *p_y;                            /* update coordinates and returns a        */
  80.     {                                    /* binary sum of buttons pressed.        */
  81.     union REGS inregs;
  82.  
  83.     inregs.x.ax = 3;
  84.     callMDD;
  85.     *p_x = inregs.x.cx;
  86.     *p_y = inregs.x.dx;
  87.     return(inregs.x.bx);
  88.     }
  89.  
  90. void
  91. PositionMCursor(x, y)            /* Position mouse cursor at x, y.        */
  92. int x, y;
  93.     {
  94.     union REGS inregs;
  95.  
  96.     inregs.x.ax = 4;
  97.     inregs.x.cx = x;
  98.     inregs.x.dx = y;
  99.     callMDD;
  100.     }
  101.  
  102. void
  103. GetPress(button, p_x, p_y, p_presses)    /* Get # of presses and pos.    */
  104. int button;                                        /* Left 0, Ctr 4, Right 2        */
  105. int *p_x, *p_y,
  106.      *p_presses;                                /* # presses since last call    */
  107.     {
  108.     union REGS inregs;
  109.  
  110.     inregs.x.ax = 5;
  111.     inregs.x.bx = button;
  112.     callMDD;
  113.     *p_x = inregs.x.cx;
  114.     *p_y = inregs.x.dx;
  115.     *p_presses = inregs.x.bx;
  116.     }
  117.  
  118. void
  119. GetRelease(button, p_x, p_y, p_presses)    /* Get # presses and pos.    */
  120. int button;                                            /* Left 0, Ctr 4, Right 2    */
  121. int *p_x, *p_y,
  122.      *p_presses;                                    /* Releases since last call*/
  123.     {
  124.     union REGS inregs;
  125.  
  126.     inregs.x.ax = 6;
  127.     inregs.x.bx = button;
  128.     callMDD;
  129.     *p_x = inregs.x.cx;
  130.     *p_y = inregs.x.dx;
  131.     *p_presses = inregs.x.bx;
  132.     }
  133.  
  134. void
  135. LimitCursor(direction, lo, hi)                /* Limit cursor's range of motion */
  136. int direction,                                        /* Vertical or Horizontal             */
  137.      lo, hi;                                            /* Bounds.                                 */
  138.     {
  139.     union REGS inregs;
  140.  
  141.     inregs.x.cx = lo;
  142.     inregs.x.dx = hi;
  143.     switch(direction)
  144.         {
  145.         case (HORIZ):
  146.             inregs.x.ax = 7;
  147.             break;
  148.         case (VERT):
  149.             inregs.x.ax = 8;
  150.             break;
  151.         default:
  152.             return;
  153.         }
  154.     callMDD;
  155.     }
  156.  
  157. void GraphicCursor(hot_x, hot_y, mask)    /* Define grahic cursor & hot spot */
  158. int hot_x, hot_y;            /* Coordinates of hot spot       */
  159. unsigned far *mask;            /* Ptr to array of unsigned ints   */
  160. {                    /* (double words)           */
  161.     union REGS inregs;
  162.     struct SREGS segregs;
  163.  
  164.     inregs.x.ax = 9;
  165.     inregs.x.bx = hot_x;
  166.     inregs.x.cx = hot_y;
  167.     inregs.x.dx = FP_OFF(mask);
  168. /* 19-Jun-90: NB - Bugfix: changed "ds" to "es" */
  169.     segregs.es = FP_SEG(mask);
  170.     int86x(0x33, &inregs, &inregs, &segregs);
  171.     }
  172.  
  173. void
  174. TextCursor(type, b1, b2)                /* Sets text cursor type & look        */
  175. int type;                                    /* Hardware or software                    */
  176. unsigned int b1, b2;                        /* Cursor parms                            */
  177.     {
  178.     union REGS inregs;
  179.  
  180.     inregs.x.ax = 10;
  181.     inregs.x.bx = type;                    /* soft = 0, hard = 1                    */
  182.     inregs.x.cx = b1;                        /* scan lines if type = 1,                */
  183.     inregs.x.dx = b2;                        /*    else they are masks                */
  184.     callMDD;
  185.     }
  186.  
  187. void
  188. GetMickeys(p_x, p_y)                        /* Get motion in mickeys since        */
  189. int *p_x, *p_y;                            /* the last call. Mickey = 1/200"    */
  190.     {
  191.     union REGS inregs;
  192.  
  193.     inregs.x.ax = 11;
  194.     callMDD;
  195.     *p_x = inregs.x.cx;                    /* Left < 0, Right > 0                    */
  196.     *p_y = inregs.x.dx;                    /* Down < 0, Up > 0                        */
  197.     }
  198.  
  199. void
  200. InstallTrap(mask, trap_seg, trap_offset)
  201. unsigned mask, trap_seg, trap_offset;
  202.     {
  203.     union REGS inregs;
  204.     struct SREGS segregs;
  205.  
  206.     inregs.x.ax = 12;
  207.     inregs.x.cx = mask;
  208.     inregs.x.dx = trap_offset;
  209.     segregs.es = trap_seg;
  210.     int86x(0x33, &inregs, &inregs, &segregs);
  211.     }
  212.  
  213. void
  214. LightPenOn()
  215.     {
  216.     union REGS inregs;
  217.  
  218.     inregs.x.ax = 13;
  219.     callMDD;
  220.     }
  221.  
  222. void
  223. LightPenOff()
  224.     {
  225.     union REGS inregs;
  226.  
  227.     inregs.x.ax = 14;
  228.     callMDD;
  229.     }
  230.  
  231. void
  232. SetMickeysPerPixel(horz, vert)
  233. int horz, vert;
  234.     {
  235.     union REGS inregs;
  236.  
  237.     inregs.x.ax = 15;
  238.     inregs.x.cx = horz;
  239.     inregs.x.dx = vert;
  240.     callMDD;
  241.     }
  242.  
  243.