Dec 172017
 
Source code for mouse manipulation in Basic, C, and Pascal.
File RODENT_3.ZIP from The Programmer’s Corner in
Category Miscellaneous Language Source Code
Source code for mouse manipulation in Basic, C, and Pascal.
File Name File Size Zip Size Zip Type
QBRODENT.BAS 3987 1300 deflated
QCRODENT.C 7196 1912 deflated
QPRODENT.PAS 3390 1105 deflated
RODENT.EXE 22900 14318 deflated
RODENT.TXT 5910 2213 deflated
TBRODENT.BAS 2849 882 deflated
TCRODENT.C 7690 2091 deflated
TPRODENT.PAS 4680 1490 deflated

Download File RODENT_3.ZIP Here

Contents of the RODENT.TXT file


This program (these programs?) is adapted from the mouse demo
program published in PC Magazine. It continuously displays the
mouse cursor location and state of the mouse buttons until the
user clicks the left button in the "Quit" box.

A variety of techniques were used in the various
implementations; the C versions and Turbo Pascal version use a
separate procedure for each mouse function, the QuickBasic
version uses a single generic mouse procedure in which the
desired function is one of the arguments passed to the
procedure, and the Turbo Basic version does all the mouse stuff inline.
The Quick Pascal version uses the Mouse unit.

The Turbo C and Turbo Pascal versions both require that the
file CGA.BGI exists in the current directory at runtime. The
Quick Basic version requires the files QB.BI and QB.QLB if run
in the integrated development environment, and requires the
files QB.BI and QB.LIB to compile. Both C versions require the
STDIO.H, DOS.H, and GRAPH.H (Microsoft) or GRAPHICS.H (Borland)
header files. The Quick Pascal version requires the MSGraph and
Mouse units (The Mouse unit is supplied with the Quick Pascal
package in source form). The Turbo Pascal version requires the
Dos and Graph units. The Turbo Basic version is a complete
standalone.

I undoubtedly could have done a better job of commenting the
code, but I think there's enough info in there to allow you to
write your own routines using these mouse functions. Rather
than try to explain all the arcane PEEKs, VARPTRs, and DEF SEG's
in the Turbo Basic version, I refer you to the Turbo Basic
manual particularly the sections on assembly interfacing and the
description of the REGS statement/function.

All mouse functions are called via interrupt 33(hex) with the
function number in the AX register. The other processor
registers are used to pass various arguments both to and from
the function. Here's a list of the functions the program uses :

Mouse Reset and Status
Input : AX = 0
Output: AX = -1 if mouse hardware & driver installed, else 0
BX = number of mouse buttons

Show Cursor
Input : AX = 1
Output : None

Hide Cursor
Input : AX = 2
Output : None

Get Button Status and Information
Input : AX = 3
Output : BX = button status (1 = left, 2 = right, and 4 =center.
If more than one button is pressed, the sum will
be returned (ie, both left and right = 3).
CX = horizontal coordinate of current mouse location
DX = vertical coordinate of current mouse location.

Set Graphics Cursor Block
Input : AX = 9
BX = Horizontal cursor hot spot
CX = vertical cursor hot spot
DX = offset address of cursor mask (32-word table)
ES = segment address of cursor mask

The hot spot is the single point where the cursor is
considered to be, relative to the upper left corner of the
graphic cursor. I used a hot spot of 7, 7 in the hourglass
cursor; this places it in the center of the cursor (where the
lines cross). Try changing this value and move the cursor to
the corners of the screen to see what happens. The range of
hotspot values is -127 to +128.

Here's a few other useful mouse functions :

Set Cursor Position
Moves the mouse cursor to the specified location.
Input : AX = 4
BX = horizontal cursor position
CX = vertical cursor position
Output : None

Get Button Press Info
Returns the number of times a button was pressed since the last
call to function 5.
Input : AX = 5
BX = which button to interrogate (0 = left, 1 = right)
Output : AX = button status of all buttons, same format as
function 3.
BX = number of presses for requested button
CX = horizontal cursor position at last button press
DX = vertical cursor position at last button press

Get Button Release Info
Returns the number of times a button was released since the last
call to function 6.
Input : AX = 6
BX = which button to interrogate
Output : AX = button status of all buttons
BX = number of releases for requested button
CX = horizontal cursor position at last button press
DX = vertical cursor position at last button press

Set Min and Max Horizontal Position
Restricts horizontal cursor movement to specified area.
Input : AX = 7
CX = Minimum horizontal position
DX = Maximum horizontal position
Output : None

Set Min and Max Vertical Position
Restricts vertical cursor movement to specified area.
Input : AX = 8
CX = Minimum vertical position
DX = Maximum vertical position

Set Text Mode Cursor
Sets mask values for text mode cursor.
Input : AX = 10
BX = Cursor select (0 = software cursor, 1 = hardware cursor)
CX = Screen mask (software) or scan line start (hardware)
DX = Cursor mask (software) or scan line stop (hardware)
Output : None
The screen location (both attribute byte and character) is ANDed
with the screen mask and XORed with the cursor mask, if software
cursor. I don't believe anybody uses the hardware cursor which
is similar to the normal text cursor.

There are a total of 30-odd mouse functions for such things
as light-pen emulation; setting, removing, and saving interrupts
for movement and button presses; and mouse speed/sensitivity
control. See the Microsoft Mouse Programmer's Reference,
published by Microsoft Press, for more information.

Note that it is generally a good idea to hide the mouse cursor
before an output to the screen which might cause the screen to
scroll and show it afterwards. Try moving the text cursor to
the bottom line of the screen (LOCATE 25, 1; GotoXY 25, 1; etc)
and print several linefeeds to see what happens to the mouse cursor.


 December 17, 2017  Add comments

Leave a Reply