home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / ega / egapaint.arc / MOUSE.C < prev    next >
Text File  |  1988-05-26  |  10KB  |  287 lines

  1. /* mouse.c   - Mouse interface routines for Turbo C */
  2.  
  3. #define LEFT  0
  4. #define RIGHT 1
  5.  
  6. #include <dos.h>
  7.  
  8. unsigned m_reset(void);                 /* reset mouse driver and return status of mouse   */
  9. void m_showcur(void);             /* Increment cursor flag and display cursor        */
  10. void m_hidecur(void);             /* Decrement cursor flag and hide cursor           */
  11. unsigned m_readloc(void);             /* get cursor position and button status             */
  12. void m_setloc(unsigned x, unsigned y);     /* set mouse cursor location                         */
  13. unsigned m_keyprs(unsigned button);         /* get button press information                     */
  14. unsigned m_keyrls(unsigned button);         /* get button release information                 */
  15. void m_setxlim(unsigned xmin,unsigned xmax);    /* set horizontal minimum and maximum coordinates      */
  16. void m_setylim(unsigned ymin,unsigned ymax);    /* set vertical minimum and maximum coordinates        */
  17. void m_defgcur(unsigned hot_x,unsigned hot_y,unsigned cur_shape);    /* define graphics cursor attributes */
  18. void m_deftcur(unsigned cur_type,unsigned scr_msk,unsigned cur_msk); /* define text cursor type and masks */
  19. void m_mickeys(void);                      /* read mouse motion counters                 */
  20. void m_inpmsk(unsigned call_msk, unsigned offset); /* set user defined subroutine and mask    */
  21. void m_penon(void);                             /* Turn light-pen emulation on             */
  22. void m_penoff(void);                        /* Turn light-pen emulation off            */
  23. void m_setasp(unsigned h_ratio,unsigned v_ratio);     /* set cursor motion counter sensitivity   */
  24.  
  25.  
  26. unsigned mse_xin, mse_yin;
  27. static unsigned prscnt[3];           /* array for count of button presses */
  28. static unsigned x_lstprs[3];          /* array for x-coordinate at last press */
  29. static unsigned y_lstprs[3];          /* array for y-coordinate at last press */
  30. static unsigned rlscnt[3];      /* array for count of button releases */
  31. static unsigned x_lstrls[3];     /* array for x-coordinate at last release */
  32. static unsigned y_lstrls[3];     /* array for y-coordinate at last release */
  33. unsigned h_micks, v_micks;
  34.  
  35. union REGS r;
  36.  
  37. void cmouses(unsigned *func, unsigned *arg2, unsigned *arg3, unsigned *arg4)
  38. {
  39.     switch(*func) {
  40.         case 0:
  41.             *func = m_reset();
  42.             break;
  43.         case 1:
  44.             m_showcur();
  45.             break;
  46.         case 2:
  47.             m_hidecur();
  48.             break;
  49.         case 3:
  50.             *arg2 = m_readloc();
  51.             *arg3 = mse_xin;
  52.             *arg4 = mse_yin;
  53.             break;
  54.         case 4:
  55.             m_setloc(*arg3, *arg4);
  56.             break;
  57.         case 5:
  58.             *func = m_keyprs(*arg2);
  59.             *arg3 = x_lstprs[*arg2];
  60.             *arg4 = y_lstprs[*arg2];
  61.             *arg2 = prscnt[*arg2];
  62.             break;
  63.         case 6:
  64.             *func = m_keyrls(*arg2);
  65.             *arg3 = x_lstprs[*arg2];
  66.             *arg4 = y_lstprs[*arg2];
  67.             *arg2 = prscnt[*arg2];
  68.             break;
  69.         case 7:
  70.             m_setxlim(*arg3, *arg4);
  71.             break;
  72.         case 8:
  73.             m_setylim(*arg3, *arg4);
  74.             break;
  75.         case 9:
  76.             m_defgcur(*arg3, *arg4, *arg2);
  77.             break;
  78.         case 10:
  79.             m_deftcur(*arg2, *arg3, *arg4);
  80.             break;
  81.         case 11:
  82.             m_mickeys();
  83.             *arg4 = h_micks;
  84.             *arg3 = v_micks;
  85.             break;
  86.         case 12:
  87.             m_inpmsk(*arg3, *arg4);
  88.             break;
  89.         case 13:
  90.             m_penon();
  91.             break;
  92.         case 14:
  93.             m_penoff();
  94.             break;
  95.         case 15:
  96.             m_setasp(*arg3, *arg4);
  97.             break;
  98.         default: break;
  99.     }
  100. }
  101.  
  102.  
  103. /***************************************************************/
  104.  
  105. unsigned m_reset(void)     /* reset mouse driver and return status of mouse */
  106. {
  107.    r.x.ax = 0;            /* set mouse function call 0 */
  108.    int86(51, &r, &r );         /* execute mouse interrupt */
  109.    return(r.x.bx);        /* return status code */
  110. }
  111.  
  112. /****************************************************************/
  113.  
  114. void m_showcur(void)    /* increment internal cursor flag and display cursor */
  115. {
  116.     return;                /* no function  */
  117. }
  118.  
  119. /****************************************************************/
  120.  
  121. void m_hidecur(void)    /* decrement internal cursor flag and hide cursor */
  122. {
  123.     return;
  124. }
  125.  
  126. /****************************************************************/
  127.  
  128. unsigned m_readloc(void)    /* get cursor position and button status */
  129. {
  130.    r.x.ax = 3;            /* set mouse function call 3 */
  131.    int86( 51, &r, &r );         /* execute mouse interrupt */
  132.    mse_xin = r.x.cx;        /* store new x-coordinate */
  133.    mse_yin = r.x.dx;        /* store new y-coordinate */
  134.    return(r.x.bx);        /* return button status */
  135. }
  136.  
  137. /****************************************************************/
  138.  
  139. void m_setloc(unsigned x, unsigned y)      /* set mouse cursor location */
  140. {
  141.  
  142.    r.x.ax = 4;              /* set mouse function call 4 */
  143.    r.x.cx = x;              /* assign new x-coordinate */
  144.    r.x.dx = y;              /* assign new y-coordinate */
  145.    int86( 51, &r, &r );           /* execute mouse interrupt */
  146. }
  147.  
  148. /******************************************************************/
  149.  
  150. unsigned m_keyprs(unsigned button)    /* get button press information */
  151.                         /* button is parameter for left or right button */
  152. {
  153.  
  154.    r.x.ax = 5;        /* set mouse function call 5 */
  155.    r.x.bx = button;    /* pass parameter for left or right button */
  156.    int86( 51, &r, &r );     /* execute mouse interrupt */
  157.    prscnt[button] = r.x.bx;    /* store updated press count */
  158.    x_lstprs[button] = r.x.cx;  /* x-coordinate at last press */
  159.    y_lstprs[button] = r.x.dx;  /* y-coordinate at last press */
  160.    return(r.x.ax);         /* return button status */
  161. }
  162.  
  163. /******************************************************************/
  164.  
  165. unsigned m_keyrls(unsigned button)    /* get button release information */
  166. {
  167.  
  168.    r.x.ax = 6;        /* set mouse function call 6 */
  169.    r.x.bx = button;    /* pass parameter for left or right button */
  170.    int86( 51, &r, &r );     /* execute mouse interrupt */
  171.    rlscnt[button] = r.x.bx;    /* store updated release count */
  172.    x_lstrls[button] = r.x.cx;  /* x-coordinate at last release */
  173.    y_lstrls[button] = r.x.dx;  /* y-coordinate at last release */
  174.    return(r.x.ax);         /* return button status */
  175. }
  176.  
  177. /******************************************************************/
  178.  
  179. void m_setxlim(unsigned xmin,unsigned xmax)    /* set horizontal minimum and maximum coordinates */
  180. /* xmin = minimum x-coordinate for mouse activity */
  181. /* xmax = maximum x-coordinate for mouse activity */
  182. {
  183.  
  184.    r.x.ax = 7;        /* set mouse function call 7 */
  185.    r.x.cx = xmin;     /* load horizontal minimum parameter */
  186.    r.x.dx = xmax;     /* load horizontal maximum parameter */
  187.    int86( 51, &r, &r );     /* execute mouse interrupt */
  188. }
  189.  
  190. /******************************************************************/
  191.  
  192. void m_setylim(unsigned ymin,unsigned ymax)    /* set vertical minimum and maximum coordinates */
  193. /* ymin = minimum y-coordinate for mouse activity */
  194. /* ymax = maximum y-coordinate for mouse activity */
  195. {
  196.  
  197.    r.x.ax = 8;        /* set mouse function call 8 */
  198.    r.x.cx = ymin;     /* load vertical minimum parameter */
  199.    r.x.dx = ymax;     /* load vertical maximum parameter */
  200.    int86( 51, &r, &r );     /* execute mouse interrupt */
  201. }
  202.  
  203. /******************************************************************/
  204.  
  205. void m_defgcur(unsigned hot_x,unsigned hot_y,unsigned cur_shape)   /* define graphics cursor attributes */
  206. /* hot_x     = cursor field x-coordinate hot-spot */
  207. /* hot_y     = cursor field y-coordinate hot-spot */
  208. /* cur_shape = pointer to array of cursor and screen masks */
  209. {
  210.  
  211.    r.x.ax = 9;        /* set mouse function call 9 */
  212.    r.x.bx = hot_x;    /* load horizontal hot-spot */
  213.    r.x.cx = hot_y;    /* load vertical hot-spot */
  214.    r.x.dx = cur_shape;    /* load cursor array pointer address */
  215.    int86( 51, &r, &r );     /* execute mouse interrupt */
  216. }
  217.  
  218. /******************************************************************/
  219.  
  220. void m_deftcur(unsigned cur_type,unsigned scr_msk,unsigned cur_msk)    /* define text cursor type and masks */
  221. /* cur_type = parameter for software or hardware cursor */
  222. /* scr_msk  = screen mask value - scan line start */
  223. /* cur_msk  = cursor mask value - scan line stop  */
  224. {
  225.  
  226.    r.x.ax = 10;        /* set mouse function call 10 */
  227.    r.x.bx = cur_type;    /* load cursor type parameter */
  228.    r.x.cx = scr_msk;    /* load screen mask value */
  229.    r.x.dx = cur_msk;    /* load cursor mask value */
  230.    int86( 51, &r, &r );     /* execute mouse interrupt */
  231. }
  232.  
  233. /******************************************************************/
  234.  
  235. void m_mickeys(void)             /* read mouse motion counters */
  236. {
  237.    r.x.ax = 11;        /* set mouse function call 11 */
  238.    int86( 51, &r, &r );     /* execute mouse interrupt */
  239.    h_micks = r.x.cx;    /* store horizontal motion units */
  240.    v_micks = r.x.dx;    /* store vertical motion units */
  241. }
  242.  
  243. /******************************************************************/
  244.  
  245. void m_inpmsk(unsigned call_msk, unsigned offset)     /* set user defined subroutine and mask */
  246. /* call_msk = call mask - defines interrupt condition */
  247. /* offset   = address offset to user subroutine */
  248. {
  249.  
  250.    r.x.ax = 12;        /* set mouse function call 12 */
  251.    r.x.cx = call_msk;    /* load call mask value */
  252.    r.x.dx = offset;    /* load user subroutine address */
  253.    int86( 51, &r, &r );     /* execute mouse interrupt */
  254. }
  255.  
  256. /*****************************************************************/
  257.  
  258. void m_penon(void)        /* turn light-pen emulation on */
  259. {
  260.  
  261.    r.x.ax = 13;        /* set mouse function call 13 */
  262.    int86( 51, &r, &r );     /* execute mouse interrupt */
  263. }
  264.  
  265. /*****************************************************************/
  266.  
  267. void m_penoff(void)             /* turn light-pen emulation off */
  268. {
  269.  
  270.    r.x.ax = 14;        /* set mouse function call 14 */
  271.    int86( 51, &r, &r );     /* execute mouse interrupt */
  272. }
  273.  
  274. /*****************************************************************/
  275.  
  276. void m_setasp(unsigned h_ratio,unsigned v_ratio)     /* set cursor motion counter sensitivity */
  277. /* h_ratio = horizontal mickey:pixel ratio */
  278. /* v_ratio = vertical mickey:pixel ratio */
  279. {
  280.  
  281.    r.x.ax = 15;        /* set mouse function call 15 */
  282.    r.x.cx = h_ratio;    /* load horizontal ratio value */
  283.    r.x.dx = v_ratio;    /* load vertical ratio value */
  284.    int86( 51, &r, &r );     /* execute mouse interrupt */
  285. }
  286.  
  287.