home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / MSMOUSE1.ZIP / EGA.ZIP / INCVAR.ZIP / DEMO12.C next >
Encoding:
C/C++ Source or Header  |  1989-02-10  |  3.0 KB  |  64 lines

  1. /* The following C program illustrates initialization and interraction with
  2.    the Mouse driver Function 12.  Function 12 allows extensions to be made
  3.    to the Mouse driver through the addition of a user defined subroutine.
  4.    The Mouse driver will do a FAR call to the user defined subroutine
  5.    during mouse hardware event processing contingent on the condition of
  6.    of the event and the state of Function 12's interrupt enable mask.
  7.  
  8.    Although Function 12 is designed to add additional functionality
  9.    directly to the Mouse driver, it is also desirable to have Function 12
  10.    interract directly with high level languages.  This program illustrates
  11.    how to use Function 12 to alter the contents of a variable defined
  12.    within a C program.  This is accomplished by having the Function 12
  13.    call an assembler routine which has been linked to this C main program.
  14.    In this way the assembler routine will have direct access to the C
  15.    programs variables contained within the DGROUP.
  16.  
  17.    The program initializes the mouse (Function 0), sets up the subroutine
  18.    (Function 12), and displays the mouse cursor (Function 1).  The program
  19.    remains in a loop until the left button is pressed (Function 3).  On
  20.    exit from this loop, the value of 'cvar' is displayed.  'cvar' is
  21.    incremented each time the right button is pressed.  'cvar' is initialized
  22.    to a value of 2.  On exit from the program, the cursor is hidden and
  23.    Function 12 disabled (Function 0).
  24.  
  25.    NOTE: Compile in large model - msc /AL demo12.c
  26. */
  27.  
  28. #include <stdio.h>
  29.  
  30. void pascal mousel();           /* MOUSE.LIB definition.        */
  31. void sub();                     /* External sub. to inc. cvar   */
  32.  
  33. int m1, m2, m3, m4;
  34. int cvar = 2;                           /* C variable to be incremented */
  35.  
  36. main ()
  37. {
  38.         void (*subadd)();               /* Void subroutine pointer.     */
  39.                                         /* Must reside in DGROUP!       */
  40.  
  41.         m1 = 0;                         /* Initialize mouse.            */
  42.         mousel (&m1, &m2, &m3, &m4);
  43.  
  44.         m1 = 12;                        /* Function 12 initialization   */
  45.         m3 = 8;                         /* Set mask to enable rt. but.  */
  46.         subadd = sub;                   /* Address of masm subroutine.  */
  47.         mousel (&m1, &m2, &m3, &subadd);
  48.  
  49.         m1 = 1;                         /* Display mouse cursor.        */
  50.         mousel (&m1, &m2, &m3, &m4);
  51.  
  52.         do {                            /* Loop 'til left button hit.   */
  53.                 m1 = 3;                 /* Get mouse button status.     */
  54.                 mousel (&m1, &m2, &m3, &m4);
  55.         } while (!(m2 & 1));            /* Exit on left button press.   */
  56.  
  57.         printf ("%x\n", cvar);          /* cvar is initialized to 2 and */
  58.                                         /*   can only change via the    */
  59.                                         /*   masm Fcn 12 subroutine.    */
  60.  
  61.         m1 = 0;                         /* Cursor off, disable Fcn 12.  */
  62.         mousel (&m1, &m2, &m3, &m4);
  63. }
  64.