Adding a mouse input 
Author Message
 Adding a mouse input

My self written Graphic User Interface for DOS based Pascal programs lacks
the ability to use a mouse. For most applications this is not a disadvantage
as mice are not ideal for use in the factory environment.

However I am now being asked to provide mouse input for a project and I
cannot get to grips with the nitty gritty of the task.  ( Been away from the
assembler area for too long. )

Using the arrow keys I can move a cursor around the graph screen and read
its location and identify what function it is sitting on. What I cannot get
to is replacing the arrow keys with mouse input.

Turbo Pascal 7 running on DOS is the system, serial mouse on Comm port is
prefered. Program may be run for real on a 286 XT ( don't ask why )

--
Bernard Green
Proprietor / Consultant
Syemon Electronic Solutions
Sharnbrook. Bedfordshire  MK44 1PS



Wed, 16 Apr 2003 06:29:09 GMT  
 Adding a mouse input
VAR  x,y:integer;
          mouse xi,mouseyi,mouseb:integer;

procedure readmouse;
begin
        asm
           mov ax,11
           int $33
           mov mousexi,cx
           mov mouseyi,dx

           mov ax,3
           int $33
           mov mouseb,bx
           end;
end;

begin
  x:=0;
  y:=0;
  repeat
        readmouse;
        inc(x,mousexi);
        inc(y,mouseyi);
   until (mouseb and 1)<>0;
end.

Any good?

Kenn ;-)


Quote:
> My self written Graphic User Interface for DOS based Pascal programs lacks
> the ability to use a mouse. For most applications this is not a
disadvantage
> as mice are not ideal for use in the factory environment.

> However I am now being asked to provide mouse input for a project and I
> cannot get to grips with the nitty gritty of the task.  ( Been away from
the
> assembler area for too long. )

> Using the arrow keys I can move a cursor around the graph screen and read
> its location and identify what function it is sitting on. What I cannot
get
> to is replacing the arrow keys with mouse input.

> Turbo Pascal 7 running on DOS is the system, serial mouse on Comm port is
> prefered. Program may be run for real on a 286 XT ( don't ask why )

> --
> Bernard Green
> Proprietor / Consultant
> Syemon Electronic Solutions
> Sharnbrook. Bedfordshire  MK44 1PS



Sat, 19 Apr 2003 02:19:04 GMT  
 Adding a mouse input


Quote:
>However I am now being asked to provide mouse input for a project and I
>cannot get to grips with the nitty gritty of the task.  ( Been away from the
>assembler area for too long. )

mlmouse.tpu should do the trick. Download mlmouse.pas also for clues on
how to use.

  www.ntos.demon.co.uk/programs

There's some rubbish on there as well - please ignore.




Sun, 20 Apr 2003 10:22:32 GMT  
 Adding a mouse input

Quote:

> My self written Graphic User Interface for DOS based Pascal programs lacks
> the ability to use a mouse. For most applications this is not a disadvantage
> as mice are not ideal for use in the factory environment.

> However I am now being asked to provide mouse input for a project and I
> cannot get to grips with the nitty gritty of the task.  ( Been away from the
> assembler area for too long. )

> Using the arrow keys I can move a cursor around the graph screen and read
> its location and identify what function it is sitting on. What I cannot get
> to is replacing the arrow keys with mouse input.

> Turbo Pascal 7 running on DOS is the system, serial mouse on Comm port is
> prefered. Program may be run for real on a 286 XT ( don't ask why )

> --
> Bernard Green
> Proprietor / Consultant
> Syemon Electronic Solutions
> Sharnbrook. Bedfordshire  MK44 1PS

The attached source can be used to create a Unit which will provide you with all
the functions you should need for adding mouse functions to your programs.

--
Val Mehling - anti-spam in effect.

http://home.earthlink.net/~valjm/
Libertarian for Bush * Cheney

[ Mices2.pas 16K ]
{ Turbo Pascal 7.0 Unit Mices.TPU Source Code (Pronounced Meeses)
  Copyright 1993 by Val Mehling                                 }

Unit Mices2 ;

Interface

procedure If_Mouse( var Number_of_Buttons : word ;
                    var Is_Mouse : Boolean) ;

procedure Show_Cursor;

procedure Hide_Cursor;

procedure Position_and_Status( var Button_Status       : integer;
                               var Horizontal_Position : integer;
                               var Vertical_Position   : integer  );

function LeftButton : Boolean ;

function MidButton : Boolean ;

function RightButton : Boolean ;

procedure Get_XY(var X_Pos, Y_Pos : integer) ;

procedure Set_Cursor_Position( New_Horizonatal,New_Vertical : integer );

procedure Get_Button_Press_Info( Button_Number : integer;
                                 var Button_Status : integer;
                                 var Presses_Count : integer;
                                 var X_Loc_at_Last : integer;
                                 var Y_Loc_at_Last : integer   );

procedure Get_Button_Release_Info( Button_number : integer;
                                   var Button_Status : integer;
                                   var Release_Count : integer;
                                   var X_Loc_at_Last : integer;
                                   var Y_Loc_at_Last : integer   );

procedure MWindow(x,y,xx,yy : integer) ;

Implementation

Uses Dos ;

var Reg : Registers ;

{ ------------------------------ }

   {*******************************************************************}
   {* The following procedures demonstrate how the low level mouse    *}
   {* functions could be implemented in Pascal. Consult your MOUSE    *}
   {* manual for more information on the low level mouse functions.   *}
   {*******************************************************************}

   {*-----------------------------------------------------------------*}
   {                                                                   }
   {  Mouse Status                                                     }
   {                                                                   }
   {  Function  0: Mouse Installed Flag and Driver Reset.              }
   {                                                                   }
   {  Description: Indicates the presence of the MOUSE driver,         }
   {               returns FFFFh if the driver is present and 0        }
   {               if not. If present the driver is Reset.             }
   {                                                                   }
   {  Input: Ax = 0                                                    }
   {                                                                   }
   {  Output: Ax = FFFFh or 0                                          }
   {          Bx = Number of mouse buttons                             }
   {                                                                   }
   {*-----------------------------------------------------------------*}

   procedure If_Mouse( var Number_of_Buttons : word ;
                       var Is_Mouse : boolean);
   var  M_Stat : word ;

   begin
     reg.ax := $00 ;
     intr($33,Reg) ;
     M_stat := reg.ax ;
     number_of_buttons := reg.bx ;
     If (M_Stat=0)
       then Is_Mouse := False
       else Is_Mouse := True ;
   end ;

   {*-----------------------------------------------------------------*}
   {                                                                   }
   {  Show Cursor                                                      }
   {                                                                   }
   {  Function  1: Increment the Cursor flag.                          }
   {                                                                   }
   {  Description: Increments the Cursor flag. If the flag reaches     }
   {               zero, the cursor is displayed. A text cursor is     }
   {               displayed in text screen modes, a graphics cursor   }
   {               in the graphics modes.                              }
   {                                                                   }
   {  Input: Ax = 1                                                    }
   {                                                                   }
   {  Output: none                                                     }
   {                                                                   }
   {*-----------------------------------------------------------------*}

   procedure Show_Cursor;

   begin
     asm
         mov Ax,$01
         Int $33
     end ; { asm }
   end;

   {*-----------------------------------------------------------------*}
   {                                                                   }
   {  Hide Cursor                                                      }
   {                                                                   }
   {  Function  2: Removes the cursor from the screen.                 }
   {                                                                   }
   {  Description: Removes the screen cursor and decrements the        }
   {               the cursor flag.                                    }
   {                                                                   }
   {  Input: Ax = 2                                                    }
   {                                                                   }
   {  Output: none                                                     }
   {                                                                   }
   {*-----------------------------------------------------------------*}

   procedure Hide_Cursor;
   begin
     asm
     mov Ax,$02
     int $33
     end ; { asm }
   end;

   {*-----------------------------------------------------------------*}
   {                                                                   }
   {  Position and Status                                              }
   {                                                                   }
   {  Function  3: Get mouse cursor position and button status.        }
   {                                                                   }
   {  Description: Returns the horizontal and vertical postion         }
   {               of the cursor, and the current button status.       }
   {                                                                   }
   {  Input: Ax = 3                                                    }
   {                                                                   }
   {  Output: Bx = Button Status, uses bits 0,1, & 2 of Bx register.   }
   {               If a button is pressed then the corresponding bit   }
   {               is a 1 otherwise it is a 0.                         }
   {                                                                   }
   {               bit 0 = left mouse button.                          }
   {               bit 1 = right mouse button.                         }
   {               bit 2 = middle mouse button.                        }
   {                                                                   }
   {          Cx = Horizontal cursor position.                         }
   {          Dx = Vertical cursor position.                           }
   {                                                                   }
   {  * * Note: Horizontal and Vertical position values are auto-      }
   {            matically adjusted for the current screen mode.        }
   {                                                                   }
   {*-----------------------------------------------------------------*}

   procedure Position_and_Status( var Button_Status       : integer;
                                  var Horizontal_Position : integer;
                                  var Vertical_Position   : integer  );

   begin
     Reg.Ax := $03 ;
     Intr($33,Reg) ;
     with Reg do
       begin
         Button_Status := Bx;
         Horizontal_Position := Cx;
         Vertical_Position := Dx;
       end;
   end;

   {*-----------------------------------------------------------------*}

   procedure Get_XY(var X_Pos, Y_Pos : integer) ;
     var B_Stat, H_Pos, V_Pos : Integer ;
     begin
     Position_and_Status(B_Stat,H_Pos,V_Pos) ;
     X_Pos := H_Pos ;
     Y_Pos := V_Pos ;
     end ; { Get_XY }

  {*-----------------------------------------------------------------*}

   function LeftButton : boolean ;
     var B_Stat, H_Pos, V_Pos : Integer ;
     begin
     Position_and_Status(B_Stat,H_Pos,V_Pos) ;
     If ((B_Stat and 1)=1)
       then LeftButton := True
       else LeftButton := False ;
     end ; { LeftButton }

   {*-----------------------------------------------------------------*}

   function MidButton : boolean ;
     var B_Stat, H_Pos, V_Pos : Integer ;
     begin
     Position_and_Status(B_Stat,H_Pos,V_Pos) ;
     If ((B_Stat and 2)=2)
       then MidButton := True
       else MidButton := False ;
     end ; { MidButton }

   {*-----------------------------------------------------------------*}

   function RightButton : boolean ;
     var B_Stat, H_Pos, V_Pos : Integer ;
     begin
     Position_and_Status(B_Stat,H_Pos,V_Pos) ;
     If ((B_Stat and 4)=4)
       then RightButton := True
       else RightButton := False ;
     end ; { RightButton }

   {*-----------------------------------------------------------------*}
   {                                                                   }
   {  Set Cursor Position                                              }
   {                                                                   }
   {  Function  4: Set the screen cursor position.                     }
   {                                                                   }
   {  Description: Set the horizontal and vertical componets of        }
   {               the screen cursor postion.                          }
   {                                                                
...

read more »



Tue, 06 May 2003 12:30:53 GMT  
 Adding a mouse input


Quote:

>   procedure If_Mouse( var Number_of_Buttons : word ;
>                       var Is_Mouse : boolean);
>   var  M_Stat : word ;

>   begin
>     reg.ax := $00 ;
>     intr($33,Reg) ;
>     M_stat := reg.ax ;
>     number_of_buttons := reg.bx ;
>     If (M_Stat=0)
>       then Is_Mouse := False
>       else Is_Mouse := True ;
>   end ;

Do not call an interrupt vector before checking it is it nil.

Add

var p:pointer;

Getintvec($33,p);
if p=nil then begin
   Is_Mouse:=false;
   exit;
End;

to the beginning, or you could wrap the intr() to make sure that it does
not call nil:

function Intr(n:word; var rg:registers);
const int33:pointer=nil;
Begin
  if (n=$33) and (int33=nil) then begin
        getint($33,int33);
        if int33=nil then exit;
  End;
  Dos.Intr(n,rg);
End;

That way it would not be locked even if one called any of the functions
without driver.



Wed, 07 May 2003 08:04:29 GMT  
 Adding a mouse input

Quote:



> >   procedure If_Mouse( var Number_of_Buttons : word ;
> >                       var Is_Mouse : boolean);
> >   var  M_Stat : word ;

> >   begin
> >     reg.ax := $00 ;
> >     intr($33,Reg) ;
> >     M_stat := reg.ax ;
> >     number_of_buttons := reg.bx ;
> >     If (M_Stat=0)
> >       then Is_Mouse := False
> >       else Is_Mouse := True ;
> >   end ;

> Do not call an interrupt vector before checking it is it nil.

> Add

> var p:pointer;

> Getintvec($33,p);
> if p=nil then begin
>    Is_Mouse:=false;
>    exit;
> End;

> to the beginning, or you could wrap the intr() to make sure that it does
> not call nil:

> function Intr(n:word; var rg:registers);
> const int33:pointer=nil;
> Begin
>   if (n=$33) and (int33=nil) then begin
>         getint($33,int33);
>         if int33=nil then exit;
>   End;
>   Dos.Intr(n,rg);
> End;

> That way it would not be locked even if one called any of the functions
> without driver.

Thanks. I have added this to my notes.

--
Val Mehling - anti-spam in effect.

http://home.earthlink.net/~valjm/
Libertarian for Bush * Cheney



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Mouse input

2. mouse...need mouse!!

3. Mouse Button and Color of mouse

4. input fractions

5. Input truncated to 1 characters

6. DATE INPUT IN UK ENGLISH FORMAT IN DELPHI 1

7. PalmTop Input

8. DBGrids and input constraints

9. Accept Chinese Input

10. Accepting input from DBLookupComboBox

11. SQL - conversion from user input

12. keyboard input

 

 
Powered by phpBB® Forum Software