Browse Source

* new mouse uni

Jonas Maebe 27 years ago
parent
commit
9d1f36f36a
1 changed files with 203 additions and 196 deletions
  1. 203 196
      rtl/dos/mouse.pp

+ 203 - 196
rtl/dos/mouse.pp

@@ -3,8 +3,6 @@
     This file is part of the Free Pascal run time library.
     This file is part of the Free Pascal run time library.
     Copyright (c) 1993,97 by the Free Pascal development team
     Copyright (c) 1993,97 by the Free Pascal development team
 
 
-    Mouse unit containing allmost all interrupt 33h functions
-    
     See the file COPYING.FPC, included in this distribution,
     See the file COPYING.FPC, included in this distribution,
     for details about the copyright.
     for details about the copyright.
 
 
@@ -18,63 +16,95 @@ Unit Mouse;
 Interface
 Interface
 
 
 {
 {
-  Mouse support functions and procedures,with error checking if mouse
-  isn't present then the routine ends,if you want to remove error checking
+  Mouse support functions and procedures, with error checking: if mouse
+  isn't present then the routine ends. If you want to remove error checking,
   remove the next define.
   remove the next define.
 }
 }
 
 
 {$DEFINE MOUSECHECK}
 {$DEFINE MOUSECHECK}
 
 
-{check if mouse is present and sets the mouse variable}
-  Function Check_Mouse:Boolean;
+{initializes the mouse with the default values for the current screen mode}
+  Function InitMouse:Boolean;
+
 {shows mouse pointer,text+graphics screen support}
 {shows mouse pointer,text+graphics screen support}
-  Procedure Show_Mouse;
+  Procedure ShowMouse;
+
 {hides mouse pointer}
 {hides mouse pointer}
-  Procedure Hide_Mouse;
-{reads mouse position in pixels,divide by 8 to get text position,and reads
-  buttons state(1-left button,2=right button,7=middle button)}
-  Procedure read_mouse (var x,y:Longint;var buttons:Longint);
-{sets mouse pointer in text mode}
-  Procedure Mouse_Cur(X,Y:Longint);
-{sets the mouse shape in text mode}
-  Procedure Mouse_Shape(BackColor,ForColor,Ascii:LongInt);
-{sets the mouse ascii in text mode}
-  Procedure Mouse_Ascii(Ascii:LongInt);
-{returns which button was pressed after last call to function}
-  Function mouse_press(var x,y:Longint;button:Longint):Longint;
-{returns which button was realeased after last call to function}
-  Function mouse_release (var x,y:Longint;button:Longint):integer;
-{set's mouse y range}
-  Procedure mouse_yrange (min,max:Longint);
-{set's mouse y range}
-  Procedure mouse_xrange (min,max:Longint);
-{set mouse speed}
-  Procedure Micky(Horizontal ,Vertical:Longint);
-{set rectangle on screen that mouse will disappear if will point on it}
-  Procedure Unseen_Mouse(x1,y1,x2,y2:Longint);
-{return if right button pressed}
-  Function IsRPressed:Boolean;
-{return if left button pressed}
-  Function IsLPressed:Boolean;
-{return if middle button pressed}
-  Function IsMPressed:Boolean;
-{return mouse X coordinate in textmode}
-  Function MouseX:longint;
-{return mouse Y coordinate in textmode}
-  Function MouseY:longint;
-{return which mouse buttons are pressed, only in bit 0-2}
-  Function MouseButtons:longint;
-{set window for mouse}
-  Procedure MWindow(x1,y1,x2,y2:Longint);
+  Procedure HideMouse;
+
+{reads mouse position in pixels (divide by 8 to get text position in standard
+ text mode) and reads the buttons state:
+    bit 1 set -> left button pressed
+    bit 2 set -> right button pressed
+    bit 3 set -> middle button pressed
+ Have a look at the example program in the manual to see how you can use this}
+  Procedure GetMouseState(var x,y, buttons :Longint);
+
+{returns true if the left button is pressed}
+  Function LPressed:Boolean;
+
+{returns true if the right button is pressed}
+  Function RPressed:Boolean;
+
+{returns true if the middle button is pressed}
+  Function MPressed:Boolean;
+
+{positions the mouse pointer}
+  Procedure SetMousePos(x,y:Longint);
+
+{returns at which position "button" was last pressed in x,y and returns the
+ number of times this button has been pressed since the last time this
+ function was called with "button" as parameter. For button you can use the
+ LButton, RButton and MButton constants for resp. the left, right and middle
+ button}
+  Function GetLastButtonPress(button:Longint;var x,y:Longint): Longint;
+
+{returns at which position "button" was last released in x,y and returns the
+ number of times this button has been re since the last time. For button
+ you can use the LButton, RButton and MButton constants for resp. the left,
+ right and middle button}
+Function GetLastButtonRelease (button : Longint; var x,y:Longint): Longint;
+
+{sets mouse's x range, with Min and Max resp. the higest and the lowest
+ column (in pixels) in between which the mouse cursor can move}
+  Procedure SetMouseXRange (Min,Max:Longint);
+
+{sets mouse's y range, with Min and Max resp. the higest and the lowest
+ row (in pixels) in between which the mouse cursor can move}
+  Procedure SetMouseYRange (Min,Max:Longint);
+
+{set the window coordinates in which the mouse cursor can move}
+  Procedure SetMouseWindow(x1,y1,x2,y2:Longint);
+
+{sets the mouse shape in text mode: background and foreground color and the
+ Ascii value with which the character on screen is XOR'ed when the cursor
+ moves over it. Set to 0 for a "transparent" cursor}
+  Procedure SetMouseShape(ForeColor,BackColor,Ascii:Byte);
+
+{sets the mouse ascii in text mode. The difference between this one and
+ SetMouseShape, is that the foreground and background colors stay the same
+ and that the Ascii code you enter is the character that you will get on
+ screen; there's no XOR'ing}
+  Procedure SetMouseAscii(Ascii:Byte);
+
+{set mouse speed in mickey's/pixel; default: horizontal: 8; vertical: 16}
+  Procedure SetMouseSpeed(Horizontal ,Vertical:Longint);
+
+{set a rectangle on screen that mouse will disappear if it is moved into}
+  Procedure SetMouseHideWindow(x1,y1,x2,y2:Longint);
+
+Const LButton = 1; {left button}
+      RButton = 2; {right button}
+      MButton = 4; {middle button}
 
 
 Var
 Var
-  MouseFound:Boolean;
+  MouseFound: Boolean;
 
 
 Implementation
 Implementation
 
 
 {$I386_ATT}
 {$I386_ATT}
 
 
-Function Check_Mouse:Boolean;
+Function InitMouse: Boolean;
 begin
 begin
   asm
   asm
         xorl    %eax,%eax
         xorl    %eax,%eax
@@ -83,13 +113,12 @@ begin
         popl    %ebp
         popl    %ebp
         cmpw    $0xffff,%ax
         cmpw    $0xffff,%ax
         setz    %al
         setz    %al
-        movb    %al,MouseFound
         movb    %al,__RESULT
         movb    %al,__RESULT
   end;
   end;
 end;
 end;
 
 
 
 
-procedure show_mouse;
+Procedure ShowMouse;
 begin
 begin
 {$IFDEF MOUSECHECK}
 {$IFDEF MOUSECHECK}
   If (Not MouseFound) Then Exit;
   If (Not MouseFound) Then Exit;
@@ -102,7 +131,7 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure hide_mouse;
+Procedure HideMouse;
 begin
 begin
 {$IFDEF MOUSECHECK}
 {$IFDEF MOUSECHECK}
   If (Not MouseFound) Then Exit;
   If (Not MouseFound) Then Exit;
@@ -115,7 +144,7 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure read_mouse (var x,y,buttons:Longint);
+Procedure GetMouseState(var x,y,buttons:Longint);
 begin
 begin
 {$IFDEF MOUSECHECK}
 {$IFDEF MOUSECHECK}
   If (Not MouseFound) Then Exit;
   If (Not MouseFound) Then Exit;
@@ -136,28 +165,95 @@ begin
   end;
   end;
 end;
 end;
 
 
-function mouse_press(var x,y:Longint;button:Longint):Longint;
-begin
+Function LPressed:Boolean;
+Begin
+{$IFDEF MOUSECHECK}
+  If (Not MouseFound) Then Exit;
+{$ENDIF}
+  asm
+        movl    $3,%eax
+        pushl   %ebp
+        int     $0x33
+        popl    %ebp
+        movl    %ebx,%eax
+        andl    $1,%eax
+        movb    %al,__RESULT
+  end;
+end;
+
+Function RPressed:Boolean;
+Begin
+{$IFDEF MOUSECHECK}
+  If (Not MouseFound) Then Exit;
+{$ENDIF}
+  asm
+        movl    $3,%eax
+        pushl   %ebp
+        int     $0x33
+        popl    %ebp
+        movl    %ebx,%eax
+        shrl    $1,%eax
+        andl    $1,%eax
+        movb    %al,__RESULT
+  end;
+end;
+
+Function MPressed:Boolean;
+Begin
+{$IFDEF MOUSECHECK}
+  If (Not MouseFound) Then Exit;
+{$ENDIF}
+  asm
+        movl    $3,%eax
+        pushl   %ebp
+        int     $0x33
+        popl    %ebp
+        movl    %ebx,%eax
+        shrl    $2,%eax
+        andl    $1,%eax
+        movb    %al,__RESULT
+  end;
+end;
+
+Procedure SetMousePos(x,y:Longint);
+Begin
+{$IFDEF MOUSECHECK}
+  If (Not MouseFound) Then Exit;
+{$ENDIF}
+  asm
+        movl    $4,%eax
+        movl    x,%ecx
+        movl    y,%edx
+        pushl   %ebp
+        int     $0x33
+        popl    %ebp
+  End;
+End;
+
+Function GetLastButtonPress(Button: Longint;var x,y:Longint):Longint;
+Begin
 {$IFDEF MOUSECHECK}
 {$IFDEF MOUSECHECK}
   If (Not MouseFound) Then Exit;
   If (Not MouseFound) Then Exit;
 {$ENDIF}
 {$ENDIF}
   asm
   asm
         movl    $5,%eax
         movl    $5,%eax
         movl    button,%ebx
         movl    button,%ebx
+        shrl    $1, %ebx        {0 = left, 1 = right, 2 = middle}
         pushl   %ebp
         pushl   %ebp
         int     $0x33
         int     $0x33
         popl    %ebp
         popl    %ebp
-        andl    $0xffff,%ecx
+        andl    $0xffff,%ebx
         andl    $0xffff,%edx
         andl    $0xffff,%edx
-        movl    x,%ebx
-        movl    %ecx,(%ebx)
-        movl    y,%ebx
-        movl    %edx,(%ebx)
-        movl    %eax,__RESULT
+        andl    $0xffff,%ecx
+        movl    %ebx, __RESULT
+        movl    x,%eax
+        movl    %ecx,(%eax)
+        movl    y,%eax
+        movl    %edx,(%eax)
   end;
   end;
 end;
 end;
 
 
-function mouse_release (var x,y:Longint;button : Longint):integer;
+Function GetLastButtonRelease (button : Longint; var x,y:Longint): Longint;
 begin
 begin
 {$IFDEF MOUSECHECK}
 {$IFDEF MOUSECHECK}
   If (Not MouseFound) Then Exit;
   If (Not MouseFound) Then Exit;
@@ -165,26 +261,28 @@ begin
   asm
   asm
         movl    $6,%eax
         movl    $6,%eax
         movl    button,%ebx
         movl    button,%ebx
+        shrl    $1, %ebx        {0 = left, 1 = right, 2 = middle}
         pushl   %ebp
         pushl   %ebp
         int     $0x33
         int     $0x33
         popl    %ebp
         popl    %ebp
+        andl    $0xffff,%ebx
         andl    $0xffff,%ecx
         andl    $0xffff,%ecx
         andl    $0xffff,%edx
         andl    $0xffff,%edx
-        movl    x,%ebx
-        movl    %ecx,(%ebx)
-        movl    y,%ebx
-        movl    %edx,(%ebx)
-        movl    %eax,__RESULT
+        movl    %ebx,__RESULT
+        movl    x,%eax
+        movl    %ecx,(%eax)
+        movl    y,%eax
+        movl    %edx,(%eax)
   end;
   end;
 end;
 end;
 
 
-procedure mouse_yrange (min,max:Longint);
+Procedure SetMouseXRange (Min,Max:Longint);
 begin
 begin
 {$IFDEF MOUSECHECK}
 {$IFDEF MOUSECHECK}
   If (Not MouseFound) Then Exit;
   If (Not MouseFound) Then Exit;
 {$ENDIF}
 {$ENDIF}
   asm
   asm
-        movl    $8,%eax
+        movl    $7,%eax
         movl    min,%ecx
         movl    min,%ecx
         movl    max,%edx
         movl    max,%edx
         pushl   %ebp
         pushl   %ebp
@@ -193,13 +291,13 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure mouse_xrange (min,max:Longint);
+Procedure SetMouseYRange (min,max:Longint);
 begin
 begin
 {$IFDEF MOUSECHECK}
 {$IFDEF MOUSECHECK}
   If (Not MouseFound) Then Exit;
   If (Not MouseFound) Then Exit;
 {$ENDIF}
 {$ENDIF}
   asm
   asm
-        movl    $7,%eax
+        movl    $8,%eax
         movl    min,%ecx
         movl    min,%ecx
         movl    max,%edx
         movl    max,%edx
         pushl   %ebp
         pushl   %ebp
@@ -208,24 +306,16 @@ begin
   end;
   end;
 end;
 end;
 
 
-Procedure Mouse_Cur(X,Y:Longint);
+Procedure SetMouseWindow(x1,y1,x2,y2:Longint);
 Begin
 Begin
 {$IFDEF MOUSECHECK}
 {$IFDEF MOUSECHECK}
   If (Not MouseFound) Then Exit;
   If (Not MouseFound) Then Exit;
 {$ENDIF}
 {$ENDIF}
-  asm
-        movl    $4,%eax
-        movl    X,%ecx
-        movl    Y,%edx
-        shll    $3,%ecx
-        shll    $3,%edx
-        pushl   %ebp
-        int     $0x33
-        popl    %ebp
-  End;
+  SetMouseXRange(x1,x2);
+  SetMouseYRange(y1,y2);
 End;
 End;
 
 
-Procedure Mouse_Shape(BackColor,ForColor,Ascii:LongInt);
+Procedure SetMouseShape(ForeColor,BackColor,Ascii:Byte);
 Begin
 Begin
 {$IFDEF MOUSECHECK}
 {$IFDEF MOUSECHECK}
   If (Not MouseFound) Then Exit;
   If (Not MouseFound) Then Exit;
@@ -233,18 +323,19 @@ Begin
   asm
   asm
         xorl    %ebx,%ebx
         xorl    %ebx,%ebx
         movl    $0xa,%eax
         movl    $0xa,%eax
-        movl    $0xff,%ecx
+        movl    $0xffff,%ecx
         xorl    %edx,%edx
         xorl    %edx,%edx
-        movb    8(%ebp),%dh
+        movb    BackColor,%dh
         shlb    $4,%dh
         shlb    $4,%dh
-        addb    ForColor,%dh
+        addb    ForeColor,%dh
+        movb    Ascii,%dl
         pushl   %ebp
         pushl   %ebp
         int     $0x33
         int     $0x33
         popl    %ebp
         popl    %ebp
   End;
   End;
 End;
 End;
 
 
-Procedure Mouse_Ascii(Ascii:LongInt);
+Procedure SetMouseAscii(Ascii:byte);
 Begin
 Begin
 {$IFDEF MOUSECHECK}
 {$IFDEF MOUSECHECK}
   If (Not MouseFound) Then Exit;
   If (Not MouseFound) Then Exit;
@@ -254,14 +345,14 @@ Begin
         movl    $0xa,%eax
         movl    $0xa,%eax
         movl    $0xff00,%ecx
         movl    $0xff00,%ecx
         xorl    %edx,%edx
         xorl    %edx,%edx
-        movb    8(%ebp),%dl
+        movb    Ascii,%dl
         pushl   %ebp
         pushl   %ebp
         int     $0x33
         int     $0x33
         popl    %ebp
         popl    %ebp
   End;
   End;
 End;
 End;
 
 
-Procedure Unseen_Mouse(x1,y1,x2,y2:Longint);
+Procedure SetMouseHideWindow(x1,y1,x2,y2:Longint);
 Begin
 Begin
 {$IFDEF MOUSECHECK}
 {$IFDEF MOUSECHECK}
   If (Not MouseFound) Then Exit;
   If (Not MouseFound) Then Exit;
@@ -278,7 +369,7 @@ Begin
   end;
   end;
 End;
 End;
 
 
-Procedure Micky(Horizontal ,Vertical:Longint);
+Procedure SetMouseSpeed(Horizontal,Vertical:Longint);
 Begin
 Begin
 {$IFDEF MOUSECHECK}
 {$IFDEF MOUSECHECK}
   If (Not MouseFound) Then Exit;
   If (Not MouseFound) Then Exit;
@@ -293,123 +384,39 @@ Begin
   end;
   end;
 End;
 End;
 
 
-Function IsRPressed:Boolean;
 Begin
 Begin
-{$IFDEF MOUSECHECK}
-  If (Not MouseFound) Then Exit;
-{$ENDIF}
-  asm
-        movl    $3,%eax
-        pushl   %ebp
-        int     $0x33
-        popl    %ebp
-        movl    %ebx,%eax
-        shrl    $1,%eax
-        andl    $1,%eax
-        movb    %al,__RESULT
-  end;
-end;
+  MouseFound := InitMouse;
+End.
+{
+  $Log$
+  Revision 1.5  1998-07-15 16:10:35  jonas
+  * new mouse uni
 
 
-Function IsLPressed:Boolean;
-Begin
-{$IFDEF MOUSECHECK}
-  If (Not MouseFound) Then Exit;
-{$ENDIF}
-  asm
-        movl    $3,%eax
-        pushl   %ebp
-        int     $0x33
-        popl    %ebp
-        movl    %ebx,%eax
-        andl    $1,%eax
-        movb    %al,__RESULT
-  end;
-end;
+  Revision 1.3  1998/04/05 13:56:54  peter
+    - fixed mouse to compile with $i386_att
+    + linux crt supports redirecting (not Esc-codes anymore)
 
 
-Function IsMPressed:Boolean;
-Begin
-{$IFDEF MOUSECHECK}
-  If (Not MouseFound) Then Exit;
-{$ENDIF}
-  asm
-        movl    $3,%eax
-        pushl   %ebp
-        int     $0x33
-        popl    %ebp
-        movl    %ebx,%eax
-        shrl    $2,%eax
-        andl    $1,%eax
-        movb    %al,__RESULT
-  end;
-end;
+  Revision 1.2  1998/03/26 12:25:22  peter
+    * integrated both mouse units
 
 
-function MouseX:longint;
-begin
-{$IFDEF MOUSECHECK}
-  If (Not MouseFound) Then Exit;
-{$ENDIF}
-  asm
-        movl    $3,%eax
-        pushl   %ebp
-        int     $0x33
-        popl    %ebp
-        movzwl  %cx,%eax
-        shrl    $3,%eax
-        incl    %eax
-        movl    %eax,__RESULT
-  end;
-end;
+  Revision 1.1.1.1  1998/03/25 11:18:41  root
+  * Restored version
 
 
-function MouseY:longint;
-begin
-{$IFDEF MOUSECHECK}
-  If (Not MouseFound) Then Exit;
-{$ENDIF}
-  asm
-        movl    $3,%eax
-        pushl   %ebp
-        int     $0x33
-        popl    %ebp
-        movzwl  %dx,%eax
-        shrl    $3,%eax
-        incl    %eax
-        movl    %eax,__RESULT
-  end;
-end;
+  Revision 1.4  1998/03/24 15:53:12  peter
+    * cleanup and doesn't give warnings when compiling
 
 
-function MouseButtons:longint;
-begin
-{$IFDEF MOUSECHECK}
-  If (Not MouseFound) Then Exit;
-{$ENDIF}
-  asm
-        movl    $3,%eax
-        pushl   %ebp
-        int     $0x33
-        popl    %ebp
-        movl    %ebx,%eax
-        andl    $7,%eax
-        movl    %eax,__RESULT
-  end;
-end;
+  Revision 1.3  1998/01/26 11:56:24  michael
+  + Added log at the end
 
 
-Procedure MWindow(x1,y1,x2,y2:Longint);
-Begin
-{$IFDEF MOUSECHECK}
-  If (Not MouseFound) Then Exit;
-{$ENDIF}
-  mouse_xrange(x1,x2);
-  mouse_yrange(y1,y2);
-End;
+  Revision 1.2
+  date: 1997/12/01 12:15:45;  author: michael;  state: Exp;  lines: +14 -12
+  + added copyright reference in header.
 
 
-Begin
-  Check_Mouse;
-End.
-{
-  $Log$
-  Revision 1.4  1998-05-22 00:39:25  peter
-    * go32v1, go32v2 recompiles with the new objects
-    * remake3 works again with go32v2
-    - removed some "optimizes" from daniel which were wrong
+  Revision 1.1
+  date: 1997/11/27 08:33:49;  author: michael;  state: Exp;
+  Initial revision
 
 
+  Revision 1.1.1.1
+  date: 1997/11/27 08:33:49;  author: michael;  state: Exp;  lines: +0 -0
+  FPC RTL CVS start
 }
 }