home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MOUSE / MOUSE.ZIP / MOUSE.C next >
Encoding:
C/C++ Source or Header  |  1985-09-10  |  13.0 KB  |  330 lines

  1. /* mouse.c   - Mouse interface routines for DeSmet C.
  2.  
  3.            A library of the functions available on the MICROSOFT
  4.            mouse via interrupt #51.  These are the functions 0-15
  5.            which are described in the MS mouse documentation on pages
  6.            49-85.  Each function has been defined so that it can be
  7.            called directly from the DeSmet "C" compiler.  The code
  8.            itself is not difficult to understand.  In fact, each call
  9.            is nothing more than an assignment of the proper values
  10.            to the 8088 registers and subsequent execution of DOS
  11.            interrupt #51.  The DeSmet compiler uses a function called
  12.            _doint() to accomplish the interrupt request.  The original mouse interface routines used the Lattice int86() function do perform an interrupt, so a marco was used to change the call to the proper DeSmet function.  This function
  13.            makes use of global variables _rax, _rbx, etc to represent
  14.            the microprocessor registers.  Adapting this code to other
  15.            compilers should thus be a relatively easy task since all
  16.            that needs to be done is to replace the calls to int86()
  17.            with sysint() or whatever your compiler calls the routine.
  18.  
  19.           In order to guarantee that outside subroutines would
  20.            have access to the results of these functions, and to make
  21.            function calls as simple as possible, I had to make use of
  22.            a large number of external variables.  Their names are
  23.            listed here so that they will not conflict with any of the
  24.            variables within the scope of the calling functions:
  25.  
  26.            TYPE  -      NAME    -     PURPOSE
  27.            ************************************************************
  28.            int      mse_xin    x-input coordinate
  29.            int      mse_yin    y-input coordinate
  30.            int      prscnt[2]    array for count of button presses
  31.            int      x_lstprs[2]    array of x-coords at last press
  32.            int      y_lstprs[2]    array of y-coords at last press
  33.            int      rlscnt[2]    array for count of button releases
  34.            int      x_lstrls[2]    array of x-coords at last release
  35.            int      y_lstrls[2]    array of y-coords at last release
  36.            int      h_micks    horizontal motion counter
  37.            int      v_micks    vertical motion counters
  38.  
  39.  
  40.           That's it for external variables.  You will need to use
  41.            these names in your own programs to get the results of the
  42.            various function calls.    I have tried to document each of
  43.            the functions well enough that the user will not be confused
  44.            about which external variables are needed.
  45.  
  46.           The following is a list of the functions included at this
  47.            point:
  48.  m_installed()           - Returns 1 if a mouse is installed, NULL if none.
  49.                 NOTE:  This routine is NOT portable.  It is
  50.                 very sensitive to the operating environment.
  51.                 Please let me know if you come up with a better
  52.                 way of checking for the mouse driver software.
  53.  m_reset()           - Reset mouse driver and return current status
  54.  m_showcur()           - Increment cursor flag and display cursor
  55.  m_hidecur()           - Decrement cursor flag and hide cursor
  56.  m_readloc()           - Read cursor position and status
  57.  m_setloc()           - Set cursor position
  58.  m_keyprs(button)      - Get mouse button press information
  59.  m_keyrls(button)      - Get mouse button release information
  60.  m_setxlim(xmin, xmax) - Set horizontal minimum and maximum
  61.  m_setylim(ymin, ymax) - Set vertical minimum and maximum
  62.  m_defgcur(hot_x, hot_y, curshape)     - Define graphics cursor
  63.  m_deftcur(cur_type, scr_msk, cur_msk) - Define text cursor
  64.  m_mickeys()           - Read mouse motion counters
  65.  m_inpmsk()           - Set user-defined subroutine call mask
  66.  m_penon()           - Turn light-pen emulation on
  67.  m_penoff()           - Turn light-pen emulation off
  68.  m_setasp()           - Set horizontal and vertical motion sensitivity
  69.  
  70. The original Lattice functions were modified on 3-2-85 for use with DeSmet C.
  71.  
  72.  On to the functions! */
  73.  
  74. /*************************************************************************/
  75.  
  76. #define LEFT  0
  77. #define RIGHT 1
  78. #define int86(x)        _doint(x)
  79.  
  80. int mse_xin, mse_yin;
  81. int prscnt[2], x_lstprs[2], y_lstprs[2];
  82. int rlscnt[2], x_lstrls[2], y_lstrls[2];
  83. int h_micks, v_micks;
  84.  
  85. extern int _rax, _rbx, _rcx, _rdx;
  86.  
  87. m_installed()        /* see if mouse driver software is installed */
  88. {
  89.     /*    This is a TERRIBLE way to check for the driver software.  Please */
  90.     /*    send FidoMail to Jeff Porter on Fido 103/1985, 103/50, or 103/91 */
  91.     /*    if you discover a better way of checking.  Thanks! */
  92.  
  93.     int seg, off;
  94.  
  95.     off = _peek(51*4, 0);    /* low byte of int. vector offset */
  96.     off += _peek(51*4+1, 0)<<8; /* high byte of int. vector offset */
  97.     seg = _peek(51*4+2, 0);    /* low byte of int. vector segment */
  98.     seg += _peek(51*4+3, 0)<<8; /* high byte of int. vector segment */
  99.  
  100.     if ( off == 0 && seg == 0 ) /* vector is not set */
  101.     return(0);
  102.     if ( _peek( off, seg ) != 0xeb )    /* check byte of mouse driver */
  103.     return(0);
  104.     if ( _peek( off+1, seg ) != 0x64 )    /* next byte */ /* modified 7-1-85 */
  105.     return(0);
  106.     if ( _peek( off+2, seg ) != 0x55 )    /* and next */
  107.     return(0);
  108.     if ( _peek( off+3, seg ) != 0x8b )    /* and the next */
  109.     return(0);
  110.     return(1);                /* four bytes ok, assume it is loaded */
  111. }
  112.  
  113. /***************************************************************/
  114.  
  115. m_reset()     /* reset mouse driver and return status of mouse */
  116. {
  117.    _rax = 0;            /* set mouse function call 0 */
  118.    int86( 51 );         /* execute mouse interrupt */
  119.    return(_rbx);        /* return status code */
  120. }
  121.  
  122. /****************************************************************/
  123.  
  124. m_showcur()    /* increment internal cursor flag and display cursor */
  125. {
  126.  
  127.    _rax = 1;            /* set mouse function call 1 */
  128.    int86( 51 );         /* execute mouse interrupt */
  129.    return(0);            /* no output from function */
  130. }
  131.  
  132.  
  133. /****************************************************************/
  134.  
  135. m_hidecur()    /* decrement internal cursor flag and hide cursor */
  136. {
  137.  
  138.    _rax = 2;            /* set mouse function call 2 */
  139.    int86( 51 );         /* execute mouse interrupt */
  140.    return(0);            /* no output from function */
  141. }
  142.  
  143.  
  144. /****************************************************************/
  145.  
  146. m_readloc()    /* get cursor position and button status */
  147. {
  148.    extern int mse_xin;      /* global integer x-coordinate */
  149.    extern int mse_yin;      /* global integer y-coordinate */
  150.  
  151.    _rax = 3;            /* set mouse function call 3 */
  152.    int86( 51 );         /* execute mouse interrupt */
  153.    mse_xin = _rcx;        /* store new x-coordinate */
  154.    mse_yin = _rdx;        /* store new y-coordinate */
  155.    return(_rbx);        /* return button status */
  156. }
  157.  
  158. /****************************************************************/
  159.  
  160. m_setloc(x, y)      /* set mouse cursor location */
  161. int x;          /* integer x-coordinate parameter */
  162. int y;          /* integer y-coordinate parameter */
  163. {
  164.  
  165.    _rax = 4;              /* set mouse function call 4 */
  166.    _rcx = x;              /* assign new x-coordinate */
  167.    _rdx = y;              /* assign new y-coordinate */
  168.    int86( 51 );           /* execute mouse interrupt */
  169.    return(0);              /* no function output */
  170. }
  171.  
  172. /******************************************************************/
  173.  
  174. m_keyprs(button)    /* get button press information */
  175. int button;        /* parameter for left or right button */
  176. {
  177.    extern int prscnt[];      /* array for count of button presses */
  178.    extern int x_lstprs[];     /* array for x-coordinate at last press */
  179.    extern int y_lstprs[];     /* array for y-coordinate at last press */
  180.  
  181.    _rax = 5;        /* set mouse function call 5 */
  182.    _rbx = button;    /* pass parameter for left or right button */
  183.    int86( 51 );     /* execute mouse interrupt */
  184.    prscnt[button] = _rbx;    /* store updated press count */
  185.    x_lstprs[button] = _rcx;  /* x-coordinate at last press */
  186.    y_lstprs[button] = _rdx;  /* y-coordinate at last press */
  187.    return(_rax);         /* return button status */
  188. }
  189.  
  190. /******************************************************************/
  191.  
  192. m_keyrls(button)    /* get button release information */
  193. int button;        /* parameter for left or right button */
  194. {
  195.    extern int rlscnt[];      /* array for count of button releases */
  196.    extern int x_lstrls[];     /* array for x-coordinate at last release */
  197.    extern int y_lstrls[];     /* array for y-coordinate at last release */
  198.  
  199.    _rax = 6;        /* set mouse function call 6 */
  200.    _rbx = button;    /* pass parameter for left or right button */
  201.    int86( 51 );     /* execute mouse interrupt */
  202.    rlscnt[button] = _rbx;    /* store updated release count */
  203.    x_lstrls[button] = _rcx;  /* x-coordinate at last release */
  204.    y_lstrls[button] = _rdx;  /* y-coordinate at last release */
  205.    return(_rax);         /* return button status */
  206. }
  207.  
  208. /******************************************************************/
  209.  
  210. m_setxlim( xmin, xmax)    /* set horizontal minimum and maximum coordinates */
  211. int xmin;        /* minimum x-coordinate for mouse activity */
  212. int xmax;        /* maximum x-coordinate for mouse activity */
  213. {
  214.  
  215.    _rax = 7;        /* set mouse function call 7 */
  216.    _rcx = xmin;     /* load horizontal minimum parameter */
  217.    _rdx = xmax;     /* load horizontal maximum parameter */
  218.    int86( 51 );     /* execute mouse interrupt */
  219.    return(0);        /* no function output */
  220. }
  221.  
  222. /******************************************************************/
  223.  
  224. m_setylim( ymin, ymax)    /* set vertical minimum and maximum coordinates */
  225. int ymin;        /* minimum y-coordinate for mouse activity */
  226. int ymax;        /* maximum y-coordinate for mouse activity */
  227. {
  228.  
  229.    _rax = 8;        /* set mouse function call 8 */
  230.    _rcx = ymin;     /* load vertical minimum parameter */
  231.    _rdx = ymax;     /* load vertical maximum parameter */
  232.    int86( 51 );     /* execute mouse interrupt */
  233.    return(0);        /* no function output */
  234. }
  235.  
  236. /******************************************************************/
  237.  
  238. m_defgcur( hot_x, hot_y, cur_shape)   /* define graphics cursor attributes */
  239. int hot_x;             /* cursor field x-coordinate hot-spot */
  240. int hot_y;             /* cursor field y-coordinate hot-spot */
  241. int cur_shape;             /* pointer to array of cursor and screen masks */
  242. {
  243.  
  244.    _rax = 9;        /* set mouse function call 9 */
  245.    _rbx = hot_x;    /* load horizontal hot-spot */
  246.    _rcx = hot_y;    /* load vertical hot-spot */
  247.    _rdx = cur_shape;    /* load cursor array pointer address */
  248.    int86( 51 );     /* execute mouse interrupt */
  249.    return(0);        /* no function output */
  250. }
  251.  
  252. /******************************************************************/
  253.  
  254. m_deftcur( cur_type, scr_msk, cur_msk)    /* define text cursor type and masks */
  255. int cur_type;              /* parameter for software or hardware cursor */
  256. int scr_msk;              /* screen mask value - scan line start */
  257. int cur_msk;              /* cursor mask value - scan line stop  */
  258. {
  259.  
  260.    _rax = 10;        /* set mouse function call 10 */
  261.    _rbx = cur_type;    /* load cursor type parameter */
  262.    _rcx = scr_msk;    /* load screen mask value */
  263.    _rdx = cur_msk;    /* load cursor mask value */
  264.    int86( 51 );     /* execute mouse interrupt */
  265.    return(0);        /* no function output */
  266. }
  267.  
  268. /******************************************************************/
  269.  
  270. m_mickeys()             /* read mouse motion counters */
  271. {
  272.    extern int h_micks;         /* horizontal motion units accumulator */
  273.    extern int v_micks;         /* vertical motion units accumulator */
  274.  
  275.    _rax = 11;        /* set mouse function call 11 */
  276.    int86( 51 );     /* execute mouse interrupt */
  277.    h_micks = _rcx;    /* store horizontal motion units */
  278.    v_micks = _rdx;    /* store vertical motion units */
  279.    return(0);        /* no function output */
  280. }
  281.  
  282. /******************************************************************/
  283.  
  284. m_inpmsk( call_msk, offset)     /* set user defined subroutine and mask */
  285. int call_msk;             /* call mask - defines interrupt condition */
  286. int offset;             /* address offset to user subroutine */
  287. {
  288.  
  289.    _rax = 12;        /* set mouse function call 12 */
  290.    _rcx = call_msk;    /* load call mask value */
  291.    _rdx = offset;    /* load user subroutine address */
  292.    int86( 51 );     /* execute mouse interrupt */
  293.    return(0);        /* no function output */
  294. }
  295.  
  296. /*****************************************************************/
  297.  
  298. m_penon()        /* turn light-pen emulation on */
  299. {
  300.  
  301.    _rax = 13;        /* set mouse function call 13 */
  302.    int86( 51 );     /* execute mouse interrupt */
  303.    return(0);        /* no function output */
  304. }
  305.  
  306. /*****************************************************************/
  307.  
  308. m_penoff()             /* turn light-pen emulation off */
  309. {
  310.  
  311.    _rax = 14;        /* set mouse function call 14 */
  312.    int86( 51 );     /* execute mouse interrupt */
  313.    return(0);        /* no function output */
  314. }
  315.  
  316. /*****************************************************************/
  317.  
  318. m_setasp( h_ratio, v_ratio)     /* set cursor motion counter sensitivity */
  319. int h_ratio;             /* horizontal mickey:pixel ratio */
  320. int v_ratio;             /* vertical mickey:pixel ratio */
  321. {
  322.  
  323.    _rax = 15;        /* set mouse function call 15 */
  324.    _rcx = h_ratio;    /* load horizontal ratio value */
  325.    _rdx = v_ratio;    /* load vertical ratio value */
  326.    int86( 51 );     /* execute mouse interrupt */
  327.    return(0);        /* no function output */
  328. }
  329.  
  330.