LJ Archive

Listing 4. Mouse Code


   vga_setmousesupport(1);


   int mouse;
   union REGS regs;

   regs.x.ax = 0;
   int86(0x33, &regs, &regs);
   mouse_on = regs.x.ax;

   if (!mouse_on) {
      printf(
"\nMouse initialization failed!\n");
      exit(1);
   }


   int mouse_x, mouse_y;
   while(1) {
      mouse_update();
      mouse_x = mouse_getx();
      mouse_y = mouse_gety();
      printf("\nCurrent mouse X: %d",
          mouse_x);
      printf("\nCurrent mouse Y: %d",
          mouse_y);
      if ((mouse_getbutton()) == 0)
         ..... ;
         /* neither mouse button is down */
      if (((mouse_getbutton() &
         MOUSE_LEFTBUTTON)) &&
      ((mouse_getbutton() &
         MOUSE_RIGHTBUTTON)))
         ..... ;
         /* both mouse buttons are down */
      if ((mouse_getbutton()) &
         MOUSE_LEFTBUTTON &&
         !(mouse_getbutton()) &
         MOUSE_RIGHTBUTTON))
         ..... ;
         /* left mouse button is down */
      if ((mouse_getbutton()) & MOUSE_RIGHTBUTTON &
         !(mouse_getbutton()) & MOUSE_LEFTBUTTON))
         ..... ;
         /* right mouse button is down */
   }


   int mouse_x, mouse_y;
   while(1) {
      get_mouse_status (&mouse_x, &mouse_y);
      printf("\nCurrent mouse X: %d", mouse_x);
      printf("\nCurrent mouse Y: %d", mouse_y);
      if ((get_buttons_mouse_status()) == 0)
         ..... ;
         /* neither mouse button is down */
      if (get_buttons_mouse_status() == 3)
         ..... ;
         /* both mouse buttons are down */
      if ((get_buttons_mouse_status()) == 1)
         ..... ;
         /* left mouse button is down */
      if ((get_buttons_mouse_status()) == 2)
         ..... ;
         /* right mouse button is down */
   }
   void get_mouse_status (int *x, int *y)
   {
           regs.x.ax = 3;
         int86(0x33, &regs, &regs);
           *x = regs.x.cx;
         *y = regs.x.dx;
   }
   int get_buttons_mouse_status(void)
   {
         regs.x.ax=3;
           int86(0x33, &regs, &regs);
         return regs.x.bx;
   }
LJ Archive