home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / advmsdos / chap05 / moudemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-01  |  2.2 KB  |  83 lines

  1.  /*
  2.     Simple Demo of Int 33H Mouse Driver
  3.     (C) 1988 Ray Duncan
  4.  
  5.     Compile with: CL MOUDEMO.C
  6.  
  7.     Usage:   MOUDEMO  (press both mouse buttons to exit)
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <dos.h>
  12.  
  13. union REGS regs;
  14.  
  15. void cls(void);                     /* function prototypes */
  16. void gotoxy(int, int);
  17.  
  18. main(int argc, char *argv[])
  19. {
  20.     int x,y,buttons;                /* some scratch variables */
  21.                                     /* for the mouse state */
  22.  
  23.     regs.x.ax = 0;                  /* reset mouse driver */
  24.     int86(0x33, ®s, ®s);      /* and check status */
  25.    
  26.     if(regs.x.ax == 0)              /* exit if no mouse */
  27.     {   printf("\nMouse not available\n");
  28.         exit(1);
  29.     }
  30.  
  31.     cls();                          /* clear the screen */  
  32.     gotoxy(45,0);                   /* and show help info */
  33.     puts("Press Both Mouse Buttons To Exit");
  34.  
  35.     regs.x.ax = 1;                  /* display mouse cursor */
  36.     int86(0x33, ®s, ®s);
  37.    
  38.     do {
  39.         regs.x.ax = 3;              /* get mouse position */    
  40.         int86(0x33, ®s, ®s);  /* and button status */
  41.         buttons = regs.x.bx & 3;
  42.         x = regs.x.cx;
  43.         y = regs.x.dx;
  44.     
  45.         gotoxy(0,0);                /* display mouse position */
  46.         printf("X = %3d  Y = %3d", x, y);
  47.         
  48.     } while(buttons != 3);          /* exit if both buttons down */
  49.  
  50.     regs.x.ax = 2;                  /* hide mouse cursor */
  51.     int86(0x33, ®s, ®s);
  52.    
  53.     cls();                          /* display message and exit */
  54.     gotoxy(0,0);
  55.     puts("Have a Mice Day!");
  56. }
  57.  
  58. /*
  59.     Clear the screen 
  60. */
  61. void cls(void)
  62. {
  63.     regs.x.ax = 0x0600;             /* ROM BIOS video driver */
  64.     regs.h.bh = 7;                  /* Int 10H Function 6 */
  65.     regs.x.cx = 0;                  /* initializes a window */
  66.     regs.h.dh = 24;
  67.     regs.h.dl = 79;
  68.     int86(0x10, ®s, ®s);
  69. }
  70.  
  71. /*
  72.     Position cursor to (x,y)
  73. */
  74. void gotoxy(int x, int y)
  75. {
  76.     regs.h.dl = x;                  /* ROM BIOS video driver */
  77.     regs.h.dh = y;                  /* Int 10H Function 2 */
  78.     regs.h.bh = 0;                  /* positions the cursor */
  79.     regs.h.ah = 2;
  80.     int86(0x10, ®s, ®s);
  81. }
  82.  
  83.