home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / pascal / JMICK11.ZIP / MOUSE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-12-20  |  2.5 KB  |  95 lines

  1. UNIT Mouse;
  2.  
  3. { TP5.5 unit for interface to mouse system }
  4.  
  5. INTERFACE
  6.   Type
  7.     MouseButtons = (NonePressed,      { No Buttons pressed }
  8.                     LeftPressed,      { Left Button Only Pressed }
  9.                     RightPressed,     { Right button only }
  10.                     MiddlePressed);   { Middle Button Only }
  11.  
  12.   Procedure ShowMouseCursor;  { Enables mouse cursor }
  13.   Procedure HideMouseCursor;  { Disables Mouse Cursor }
  14.   Procedure GetTextMouseLocation(VAR Row,Col : WORD); { Return text location of mouse }
  15.   Procedure SetTextMouseLocation(Row,Col : WORD); { Set cursor for mouse }
  16.   Function  GetMouseButtonStatus : MouseButtons;
  17.  
  18.  
  19.  
  20. IMPLEMENTATION
  21.   uses Dos,Crt;
  22.  
  23.   var
  24.     Regs : Registers; { Used by initialization and all the procs }
  25.  
  26.  
  27.   Procedure ShowMouseCursor;
  28.  
  29.     Begin
  30.       Regs.AX := 1;
  31.       Intr($33,Regs);
  32.     End;
  33.  
  34.  
  35.  
  36.   Procedure HideMouseCursor;
  37.  
  38.     Begin
  39.       Regs.AX := 2;
  40.       Intr($33,Regs);
  41.     End;
  42.  
  43.  
  44.   Procedure GetTextMouseLocation(VAR Row, Col : WORD);
  45.  
  46.     Begin
  47.       Regs.AX := 3;
  48.       Intr($33,Regs);
  49.       Col := (Regs.CX shr 3) + 1;  { Adjust for scan lines }
  50.       Row := (Regs.DX shr 3) + 1;  { Adjust for scan lines }
  51.     End;
  52.  
  53.  
  54.   Procedure SetTextMouseLocation(Row, Col : WORD);
  55.  
  56.     Begin
  57.       Regs.AX := 4;
  58.       Regs.CX := (Col-1) shl 3;  { Convert to CGA scan lines }
  59.       Regs.DX := (Row-1) shl 3;
  60.       Intr($33,Regs);
  61.     End;
  62.  
  63.  
  64.   Function GetMouseButtonStatus : MouseButtons;
  65.     Var
  66.       LeftCount, RightCount, MiddleCount : WORD;
  67.       RetStat : MouseButtons;
  68.  
  69.     Begin
  70.       Regs.AX := 5;  Regs.BX := 4; Intr($33,Regs);  LeftCount := Regs.BX;
  71.       Regs.AX := 5;  Regs.BX := 1; Intr($33,Regs);  RightCount := Regs.BX;
  72.       Regs.AX := 5;  Regs.BX := 2; Intr($33,Regs);  MiddleCount := Regs.BX;
  73.       If (LeftCount > RightCount) and
  74.          (LeftCount > MiddleCount)
  75.         Then RetStat := LeftPressed
  76.         Else If (RightCount > MiddleCount)
  77.                Then RetStat := RightPressed
  78.                Else If (MiddleCount > 0)
  79.                       Then RetStat := MiddlePressed
  80.                       Else RetStat := NonePressed;
  81.       GetMouseButtonStatus := RetStat;
  82.     End;
  83.  
  84.  
  85.   Begin {Mouse unit initialization}
  86.     Regs.AX := 0;  { Call the mouse interrupt initialize }
  87.     Intr($33,Regs); { Do the Interrupt }
  88.     If Regs.AX <> $FFFF
  89.       Then begin
  90.              Writeln('ERROR 1 - No Mouse Driver Present.');
  91.              Halt(1);
  92.            end;
  93.     ShowMouseCursor; { Do this }
  94.   End.
  95.