home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_05 / 2n05044a < prev    next >
Text File  |  1991-03-27  |  2KB  |  102 lines

  1.  
  2. (*
  3.         TITLE:          Mouse Library Unit Test Driver;
  4.         FILENAME:       TRYMOUSE.PAS;
  5.         REQUIRES:       MOUSELIB.TPU;
  6.         COMPILER:       Turbo Pascal V.4.0+;
  7.  
  8.         WARNINGS:       1)  It's important to check the interrupt
  9.                         vector used by the mouse driver.  If
  10.                         you call mouse_reset and no driver is
  11.                         loaded, the machine may hang!  See the
  12.                         Boolean Function MouseDriverLoaded for
  13.                         one way to do this.
  14.  
  15.                         2)  Make sure to compile with the Boolean
  16.                         Evaluation Option set to "short-circuit"
  17.                         ( {$B-} ).
  18.  
  19. *)
  20.  
  21. Program TryMouse;
  22. {$B-}
  23. Uses Dos, Crt, MouseLib;
  24.  
  25.     Const
  26.         MouseInterrupt : Byte = $33;
  27.  
  28.     Var
  29.         Nbuttons,
  30.         x,
  31.         oldx,
  32.         y,
  33.         oldy,
  34.         count,
  35.         junk,
  36.         MouseButton,
  37.         ButtonStatus    : Integer;
  38.  
  39. Function MouseDriverLoaded : Boolean;
  40.     Var
  41.         Vector      : Pointer;
  42.         OpCode      : ^Byte;
  43.  
  44. Begin
  45.     GetIntVec(MouseInterrupt, Vector);
  46.     If (Vector = Nil) then  { if mouse vector empty then driver isn't loaded }
  47.     Begin
  48.         MouseDriverLoaded := False;
  49.         Exit;
  50.     End;
  51.     OpCode := Vector;
  52.     If OpCode^ = $CF then  { "IRET" opcode indicates no mouse driver loaded }
  53.     Begin
  54.         MouseDriverLoaded := False;
  55.         Exit;
  56.     End;
  57.     MouseDriverLoaded := True;
  58. End;
  59.  
  60. Procedure TrackMouse;
  61. Begin
  62.     MouseButton := RightMouseButton;
  63.     clrscr;
  64.     WriteLn('   ... Click Right Mouse Button or Press Any Key ...');
  65.     mouse_show;
  66.  
  67.     x := 0;
  68.     y := 0;
  69.     oldx := 0;
  70.     oldy := 0;
  71.  
  72.     Repeat
  73.         ButtonStatus := mouse_get_pos(x, y);
  74.         x := x shr 3;
  75.         y := y shr 3;
  76.         If (x <> oldx) or (y <> oldy) then
  77.         Begin
  78.             GoToXY(1, 3);
  79.             mouse_hide;
  80.             WriteLn('X = ', x:2);
  81.             WriteLn('Y = ', y:2);
  82.             mouse_show;
  83.         End;
  84.         oldx := x;
  85.         oldy := y;
  86.     Until ((mouse_button_press(x,y,count,MouseButton) and RIGHT_BUTTON <> 0)
  87.     or (KeyPressed));
  88.  
  89.     mouse_hide;
  90.     junk := mouse_reset(Nbuttons);
  91. End;
  92.  
  93.         (*  MAIN  *)
  94. Begin
  95.     If (not MouseDriverLoaded) or (mouse_reset(Nbuttons) = 0) then
  96.     Begin
  97.         WriteLn('No Mouse!');
  98.         Halt;
  99.     End;
  100.     TrackMouse;
  101. End.
  102.