Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Mouse in Pascal??

514 views
Skip to first unread message

93...@tayloru.edu

unread,
Nov 11, 1993, 4:10:00 AM11/11/93
to
Help!!!!!!!!!!!!!!!!!!!!!!!!!!
Does anyone know code on how to use a mouse for the user to interact

with the program? I also need to know how to read the position at

which the mouse cursor is selected. Thanx.
MARK

Tore Green

unread,
Nov 13, 1993, 7:55:24 AM11/13/93
to

93...@tayloru.edu writes:

Well... You don't state, what system you're using, but assuming it's a PC
with Turbo Pascal, here's waht to do:

Use interrupt $33 - the mouse driver.

First, check if there is a mouse driver present and initialize it, if there is:

Uses Dos;
Var R:Registers;
P:Pointer;
Begin
Getintvect($33,P);
If P=Ptr(0,0) then
{Mouse driver wasn't there}
else
Begin
R.ax:=0;
Intr($33,R);
If R.ax=0 then
{Mouse driver couldn't be initialized}
else
{Go on and use the mouse}
End
End;

You can now call different functions of intr $33. On entry, AX holds the
function number. BX, CX and DX are used for input/output.


AX BX CX DX Description
------------------------------------------------
1 Show mouse pointer
2 Hide mouse pointer
3 Buttons* X Y Get position and button status
4 X Y Place mouse pointer on (X,Y)
7 X1 X2 Set range of mouse on X-axis
8 Y1 Y2 Set range of mouse on Y-axis

* Bit 0 is set for left button, bit 1 for right button.


So, You just put function number in AX and input (if needed) i CX and DX.
Then you call intr $33, and read your output from BX,CX,DX.

I hope, this was what you needed.

Tore Green
spro...@diku.dk

Cyrus Patel

unread,
Nov 12, 1993, 12:42:00 PM11/12/93
to
.#200
9>Help!!!!!!!!!!!!!!!!!!!!!!!!!!
9>Does anyone know code on how to use a mouse for the user to
interact
9>with the program? I also need to know how to read the position at
9>which the mouse cursor is selected. Thanx.

This UNIT should help you out...

___--------------------------------------------------------------------
UNIT Mouse;

{Program: Master Mouse Routine Library}

INTERFACE

USES DOS;

CONST

{Button press definitions}

PrL = 1;
PrR = 2;
PrLr = 3;
PrM = 4;
PrLM = 5;
PrMR = 6;
PrAll = 7;
PrNone = 0;

{Button definitions}

ButtonLeft = 0;
ButtonRight = 1;
ButtonMiddle = 2;


FUNCTION ThereIsAMouse: Boolean;
FUNCTION MouseReset: Boolean;
FUNCTION GetMouseStatus
(VAR MPosX, MPosY: Byte): Byte;

PROCEDURE ClearButton (Button: Byte);
PROCEDURE MouseOn;
PROCEDURE MouseOff;
PROCEDURE SetMouseSoftCursor
(MouseChar, MouseFGColor, MouseBGColor: Byte);

IMPLEMENTATION

CONST
MouseIntr = $33;

VAR
MouseVisible : Boolean;
MHMax, MVMax, MHCell, MVCell : Word;
Regs : Registers;

PROCEDURE MouseHandler (A, B, C, D: Byte);
BEGIN
WITH Regs DO
BEGIN
ax := A;
bx := B;
cx := C;
dx := D;
Intr(MouseIntr, Regs)
END
END;

FUNCTION GetButtonUpStatus
(Button: Byte;VAR MPosX, MPosY: Word): Boolean;

BEGIN
WITH Regs DO
BEGIN
ax := 6;
bx := Button;
MouseHandler(ax, bx, 0, 0);
MPosX := cx DIV MHCell + 1;
MPosY := dx DIV MVCell + 1;
IF ax = 0 THEN
GetButtonUpStatus := TRUE
ELSE
GetButtonUpStatus := FALSE
END
END;

PROCEDURE ClearButton (Button: Byte);
VAR
MPosX,MPosY: Word;

BEGIN
REPEAT UNTIL
GetButtonUpStatus(Button, MPosX,MPosY)
END;

FUNCTION GetMouseStatus
(VAR MPosX, MPosY: Byte): Byte;
BEGIN
WITH Regs DO
BEGIN
ax := 3;
MouseHandler(ax, 0, 0, 0);
GetMouseStatus := bx;
MPosX := cx DIV MHCell + 1;
MPosY := dx DIV MVCell + 1
END
END;

PROCEDURE MouseOff;
BEGIN
IF MouseVisible THEN
BEGIN
MouseHandler(2, 0, 0, 0);
MouseVisible := FALSE
END
END;

PROCEDURE MouseOn;
BEGIN
IF NOT MouseVisible THEN
BEGIN
MouseHandler(1, 0, 0, 0);
MouseVisible := TRUE
END
END;

FUNCTION MouseReset: Boolean;
BEGIN
MHMax := 639; {Max virtual horizontal pos}
MVMax := 199; {Max virtual vertical pos}
MHCell := 8; {Mouse horizontal cell width}
MVCell := 8; {Mouse vertical cell height}
MouseHandler(0, 0, 0, 0);
IF Regs.ax = 0 THEN
MouseReset := FALSE
ELSE
MouseReset := TRUE;
MouseVisible := FALSE
END;

PROCEDURE SetMouseSoftCursor
(MouseChar, MouseFGColor, MouseBGColor: Byte);
BEGIN
MouseOn;
Regs.ax := 10;
Regs.bx := 0; {Select software cursor}
{Screen Mask Value (don't change character)}
Regs.cx := $8800;
Regs.dx := $8800 + MouseBGColor * 4096 +
MouseFGColor * 256 + MouseChar;
Intr($33,Regs);
MouseOff
END;

FUNCTION ThereIsAMouse: Boolean;
CONST
IRET = 207;
VAR
MouseSegment : Word ABSOLUTE $0000:$00CE;
MouseOffset : Word ABSOLUTE $0000:$00CC;
MouseInstruction: Byte;
BEGIN
IF (MouseSegment = 0) AND
(MouseOffset = 0) THEN
ThereIsAMouse := FALSE
ELSE
BEGIN
MouseInstruction :=
MEM[MouseSegment:MouseOffset];
IF MouseInstruction = IRET THEN
ThereIsAMouse := FALSE
ELSE
ThereIsAMouse := TRUE
END
END;

{No initialization section}

END.

___--------------------------------------------------------------------

Cyrus

-- SPEED 1.30 #666: Cursor's flashing but there's no response.

ONK...@ponton.hanse.de

unread,
Nov 14, 1993, 6:42:44 PM11/14/93
to
93...@tayloru.edu schrieb unter 'Mouse in Pascal??':

> Does anyone know code on how to use a mouse for the user to interact
> with the program? I also need to know how to read the position at
> which the mouse cursor is selected. Thanx.

I wrote a mouse handling TPU for pascal (for text video modes), that
handles the general stuff, initialisation, detection, movement, window
limiting, buttons, etc.

If we have a general interest here, email me, I am not a great newsgroup
reader and I might miss your replies, so please mail me at onk...@ponton.hanse.
de and I will mail you some source.

Thanks,

Stefan

0 new messages