home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / MOUSE / MSMOUSE1.ZIP / C&QC.ZIP / MOUH_INT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-10  |  4.2 KB  |  152 lines

  1. /*******************************************************************
  2.  
  3.    MOUH_INT.C (FOR HERCULES)
  4.  
  5.       Demonstrates the most commonly used function calls in
  6.    programming the Microsoft mouse driver. This was written
  7.    in Microsoft C 5.1 using the small model. All the calls
  8.    made to the driver are made using int86x.
  9.  
  10.       Before running this program, the Hercules graphics support
  11.    utility must be loaded. Run either MSHERC.COM (included with
  12.    C 5.1) or QBHERC.COM (included with QuickBASIC 4.0).
  13.  
  14.    Written by David Tryon
  15.    Microsoft Product Support
  16.    6/15/88
  17.  
  18.    To build, type:  cl /AS mouh_int.c
  19.  
  20.    NOTE: Program assumes mouse and mouse driver are installed.
  21. *******************************************************************/
  22.  
  23. #include <graph.h>
  24. #include <dos.h>
  25. #define MOUSE 0x33
  26.  
  27. union REGS inregs, outregs;
  28. struct SREGS segregs;
  29.  
  30. main ()
  31. {
  32.     void chkdrv ();                /*  Checks if driver installed */
  33.  
  34.     char far *video_mode = (char far *) 0x00000449;
  35.     unsigned short cursor [32];    /*  Array to Contain Cursor    */
  36.  
  37.     chkdrv ();                     /*  Exit if no driver loaded   */
  38.  
  39.     *video_mode = 6;               /*  Tell BIOS it's in Graphics mode  */
  40.  
  41.     /*  Function 0:  Reset Mouse   */
  42.     inregs.x.ax = 0;
  43.     int86x (MOUSE, &inregs, &outregs, &segregs);
  44.  
  45.     /*  Define screen mask  */
  46.  
  47.     cursor [0]  = 0xE1FF;
  48.     cursor [1]  = 0xE1FF;
  49.     cursor [2]  = 0xE1FF;
  50.     cursor [3]  = 0xE1FF;
  51.     cursor [4]  = 0xE1FF;
  52.     cursor [5]  = 0xE000;
  53.     cursor [6]  = 0xE000;
  54.     cursor [7]  = 0xE000;
  55.     cursor [8]  = 0x0000;
  56.     cursor [9]  = 0x0000;
  57.     cursor [10] = 0x0000;
  58.     cursor [11] = 0x0000;
  59.     cursor [12] = 0x0000;
  60.     cursor [13] = 0x0000;
  61.     cursor [14] = 0x0000;
  62.     cursor [15] = 0x0000;
  63.  
  64.     /*  Define cursor mask  */
  65.  
  66.     cursor [16] = 0x1E00;
  67.     cursor [17] = 0x1200;
  68.     cursor [18] = 0x1200;
  69.     cursor [19] = 0x1200;
  70.     cursor [20] = 0x1200;
  71.     cursor [21] = 0x13FF;
  72.     cursor [22] = 0x1249;
  73.     cursor [23] = 0x1249;
  74.     cursor [24] = 0xF249;
  75.     cursor [25] = 0x9001;
  76.     cursor [26] = 0x9001;
  77.     cursor [27] = 0x9001;
  78.     cursor [28] = 0x8001;
  79.     cursor [29] = 0x8001;
  80.     cursor [30] = 0x8001;
  81.     cursor [31] = 0xFFFF;
  82.  
  83.     /*   Function 9:  Set Graphics Cursor Block  */
  84.     inregs.x.ax = 9;
  85.     inregs.x.bx = 5;
  86.     inregs.x.cx = 0;
  87.     inregs.x.dx = (unsigned short) cursor;
  88.     segread(&segregs);
  89.     segregs.es = segregs.ds;       /*  ES:DX => Cursor Array  */
  90.     int86x ( MOUSE, &inregs, &outregs, &segregs);
  91.     segread(&segregs);
  92.  
  93.     /*   Function 7:  Set Horizontal Limits  */
  94.     inregs.x.ax = 7;
  95.     inregs.x.cx = 100;
  96.     inregs.x.dx = 620;
  97.     int86x ( MOUSE, &inregs, &outregs, &segregs);
  98.  
  99.     /*   Function 8:  Set Vertical Limits    */
  100.     inregs.x.ax = 8;
  101.     inregs.x.cx = 50;
  102.     inregs.x.dx = 300;
  103.     int86x ( MOUSE, &inregs, &outregs, &segregs);
  104.  
  105.     _setvideomode (_HERCMONO);
  106.  
  107.     /*   Draw box showing mouse limits     */
  108.     _moveto (100, 50);
  109.     _lineto (620, 50);
  110.     _lineto (620,300);
  111.     _lineto (100,300);
  112.     _lineto (100, 50);
  113.  
  114.     /*   Function 1:  Show Cursor           */
  115.     inregs.x.ax = 1;
  116.     int86x (MOUSE, &inregs, &outregs, &segregs);
  117.  
  118.     do
  119.     {
  120.         inregs.x.ax = 3;
  121.         int86x ( MOUSE, &inregs, &outregs, &segregs);
  122.         _settextposition (1,1);
  123.         printf ("%d  \t%d     ", outregs.x.cx,outregs.x.dx);
  124.     } while (!outregs.x.bx);      /*  Loop until button pressed */
  125.  
  126.     /*  Function 2:  Hide Cursor        */
  127.     inregs.x.ax = 2;
  128.     int86x ( MOUSE, &inregs, &outregs, &segregs);
  129.  
  130.     *video_mode = 7;
  131.  
  132.     _setvideomode (_DEFAULTMODE);
  133. }
  134.  
  135. void chkdrv ()
  136. {
  137.     unsigned long address;
  138.     unsigned char first_byte;
  139.  
  140.     inregs.x.ax = 0x3533;          /* Get Interrupt Vector for 0x33 */
  141.     intdosx ( &inregs, &outregs, &segregs);
  142.     address = (((long) segregs.es) << 16) + (long) outregs.x.bx ;
  143.     first_byte = (unsigned char) * (long far *) address;
  144.  
  145.     /* Be sure vector isn't 0 and first instruction isn't iret */
  146.     if ((address == 0L) || (first_byte == 0xCF))
  147.     {
  148.         printf ("\nThe Mouse Driver must be installed to use this program");
  149.         exit ();
  150.     }
  151. }
  152.