home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 1.ddi / MOUSE.ZIP / M_INIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-11  |  1.3 KB  |  68 lines

  1. /*
  2.  *    m_init.c
  3.  *
  4.  *    Public Domain (p) March 1990 By Rodney Loos
  5.  *    Syntax modified by S. Sampson
  6.  */
  7.  
  8. #define    MAIN
  9.  
  10. #include <dos.h>
  11. #include <alloc.h>
  12. #include "mouse.h"
  13.  
  14. M_POS    *__Mptr;
  15. Param    *__Mpar;
  16.  
  17. int m_init(void)
  18. {
  19.     union    REGS    mreg;
  20.     struct    SREGS    segs;
  21.  
  22.     /* User needs DOS 2 or higher to use these routines */
  23.  
  24.     if (_osmajor < 2)
  25.         return(2);
  26.  
  27.     __Mpar = (Param *) malloc(sizeof(Param));
  28.     __Mptr = (M_POS *) malloc(sizeof(M_POS));
  29.  
  30.     /* initialize variables to 0 */
  31.  
  32.     __Mpar->m1 = __Mpar->m2 = __Mpar->m3 = __Mpar->m4 = 0;
  33.  
  34.     /* status returned in __Mpar->m1, if 0 then not installed */
  35.  
  36.     if (_osmajor >= 3)
  37.         mouse(__Mpar);
  38.     else  {                /* it's version 2 */
  39.         mreg.h.ah = 0x35;    /* Function to get interrupt vector */
  40.          mreg.h.al = 0x33;    /* mouse interrupt number */
  41.         intdosx(&mreg, &mreg, &segs);
  42.  
  43.         if (segs.es == 0 && mreg.x.bx == 0)
  44.             __Mpar->m1 = 0;    /* if vector points to 0000:0000,
  45.                                 mouse not in */
  46.         else
  47.             mouse(__Mpar);    /* initialize mouse */
  48.     }
  49.  
  50.     return (__Mpar->m1);
  51. }
  52.  
  53. void mouse(Param *mptr)
  54. {
  55.     union    REGS    mousreg;
  56.  
  57.     mousreg.x.ax = mptr->m1;
  58.     mousreg.x.bx = mptr->m2;
  59.     mousreg.x.cx = mptr->m3;
  60.     mousreg.x.dx = mptr->m4;
  61.     int86(0x33, &mousreg, &mousreg);    /* mouse interrupt */
  62.  
  63.     mptr->m1 = mousreg.x.ax;
  64.     mptr->m2 = mousreg.x.bx;
  65.     mptr->m3 = mousreg.x.cx;
  66.     mptr->m4 = mousreg.x.dx;
  67. }
  68.