'ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'³                                                                        ³
'³                           M O U S E . B A S                            ³
'³                                                                        ³
'³                   Supplementary Source Code for the                    ³
'³       The QBSCR Screen Routines for QuickBASIC 4.0+ Programmers        ³
'³                              Version 2.0                               ³
'³                                                                        ³
'³                   (C) Copyright 1992 by Tony Martin                    ³
'³                                                                        ³
'ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
'³                                                                        ³
'³  This source code is copyright 1992 by Tony Martin.  You may change    ³
'³  it to suit your programming needs, but you may not distribute any     ³
'³  modified copies of the library itself.  I retain all rights to the    ³
'³  source code and all library modules included with the QBSCR package,  ³
'³  as well as to the example programs.  You may not remove this notice   ³
'³  from any copies of the library itself you distribute.                 ³
'³                                                                        ³
'³  You are granted the right to use this source code for your own pro-   ³
'³  grams, without royalty payments or credits to me (though, if you      ³
'³  feel so inclined to give me credit, feel free to do so).  You MUST    ³
'³  register this software if you release a shareware or commercial       ³
'³  program that uses it.  You may use these routines in any type of      ³
'³  software you create, as long as it is not a programming toolbox or    ³
'³  package of routines OF ANY KIND.                                      ³
'³                                                                        ³
'³  This package is shareware.  If you find it useful or use it in any    ³
'³  software you release, you are requested to send a registration fee of ³
'³  $25.00 (U.S. funds only) to:                                          ³
'³                                                                        ³
'³                            Tony Martin                                 ³
'³                       1611 Harvest Green Ct.                           ³
'³                          Reston, VA 22094                              ³
'³                                                                        ³
'³  All registered users receive an 'official' disk set containing the    ³
'³  latest verison of the QBSCR routines.  For more information, see      ³
'³  the QBSCR documentation.                                              ³
'³                                                                        ³
'ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
'³                                                                        ³
'³  For information on using these routines and incorporating them into   ³
'³  your own programs, see the accompanying documentation.                ³
'³                                                                        ³
'ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

' ==========================================================================
' Include the mouse library CONSTants, TYPEs, and DECLAREs.
' ==========================================================================

REM $INCLUDE: 'mouse.bi'

COMMON SHARED mouseExists%, mouseState%

SUB Mouse (m1%, m2%, m3%, m4%) STATIC


	' ========================================================================
	' This routine is the routine that calls the mouse interrupt (33h).
	' All other mouse routines (with one exception) use this routine to make
	' function calls to the mouse driver.  The four parameters are standard
	' parameters sent to the mouse, the contents of which depend on the
	' function desired.  Not all parameters will have useful values.  This
	' also depends on the function desired.  In any case, you probably will
	' never have to see or call this routine.  Simply use the top-level mouse
	' routines provided in this library.
	' ========================================================================

 
	' ========================================================================
	' DIMension a pair of register objects (RegType is found in the MOUSE.BI
	' file). One is to pass in values, the other is to receive information
	' in return.
	' ========================================================================

	DIM inRegs AS RegType
	DIM outRegs AS RegType

 
	' ========================================================================
	' Assign the passed-in mouse parameters to the general purpose registers
	' in the register objects declared only nanoseconds ago.
	' ========================================================================
 
	inRegs.ax = m1%
	inRegs.bx = m2%
	inRegs.cx = m3%
	inRegs.dx = m4%
 
	' ========================================================================
	' Make the call to the mouse interrupt (33h), passing in the mouse
	' parameters, and receiving information back.
	' ========================================================================
 
	INTERRUPT &H33, inRegs, outRegs

																																							
	' ========================================================================
	' Assign returned information to the mouse parameters, so they may be
	' passed back to the calling routine.
	' ========================================================================
 
	m1% = outRegs.ax
	m2% = outRegs.bx
	m3% = outRegs.cx
	m4% = outRegs.dx

END SUB

SUB MouseButtonPressInfo (button%, numPresses%, x%, y%)
 
 
	' ========================================================================
	' This function returns the number of presses for the specified button
	' (left=0, right=1, center=2) since the last call to this function, as
	' well as the x and y virtual screen coordinates of the mouse at the time
	' of the last press.
	'
	' Parameters:
	' -----------
	'   button%       the button to be checked (0=left, 1=right, 2=center) *
	'   numPresses%   returns the number of presses since last call
	'   x%            mouse virtual x-coordinate at last button press
	'   y%            mouse virtual y-coordinate at last button press
	'
	'   * NOTE: In the MOUSE.BI file, there are constants named LEFTBUTTON,
	'           RIGHTBUTTON, and CENTERBUTTON, that have respective values of
	'           0, 1, and 2.  You may use these instead of the constants 0, 1,
	'           2 to make your programs more readable.
	' ========================================================================

 
	' ========================================================================
	' Assign parameters for call to Mouse interrupt sub.  m1% contains the
	' mouse function we want to use, in this case function 5, Get Button
	' Press Information.  m2% contains the button to check.  Call the mouse
	' interrupt sub.
	' ========================================================================
 
	m1% = 5
	m2% = button%
	Mouse m1%, m2%, m3%, m4%

 
	' ========================================================================
	' Prepare data for return to calling routine.  m2% returns the number of
	' button presses since the last call to the function; m3% contains the
	' x-coordinate of the mouse at the last button press, and m4% contains the
	' y-coordinate of the mouse at the last button press.
	' ========================================================================
 
	numPresses% = m2%
	x% = m3%
	y% = m4%


END SUB

SUB MouseButtonReleaseInfo (button%, numReleases%, x%, y%)


	' ========================================================================
	' This routine returns the number of time the specified button (left=0,
	' right=1, center=2) was released since the alst call to this function.
	' Also returned are the x and y coordinates of the virtual screen where
	' the last release occurred.
	'
	' Parameters:
	' -----------
	'   button%       the button to be checked (0=left, 1=right, 2=center) *
	'   numReleases%  returns the number of releases since last call
	'   x%            mouse virtual x-coordinate at last button release
	'   y%            mouse virtual y-coordinate at last button release
	'
	'   * NOTE: In the MOUSE.BI file, there are constants named LEFTBUTTON,
	'           RIGHTBUTTON, and CENTERBUTTON, that have respective values of
	'           0, 1, and 2.  You may use these instead of the constants 0, 1,
	'           2 to make your programs more readable.
	' ========================================================================


	' ========================================================================
	' Assign parameters for call to Mouse interrupt sub.  m1% contains the
	' mouse function we want to use, in this case function 6, Get Button
	' Release Information.  m2% contains the button to check.  Call the mouse
	' interrupt sub.
	' ========================================================================
 
	m1% = 6
	m2% = button%
	Mouse m1%, m2%, m3%, m4%


	' ========================================================================
	' Prepare data for return to calling routine.  m2% returns the number of
	' button releases since the last call to the function; m3% contains the
	' x-coordinate of the mouse at the last button release, and m4% contains
	' the y-coordinate of the mouse at the last button release.
	' ========================================================================
 
	numReleases% = m2%
	x% = m3%
	y% = m4%


END SUB

SUB MouseButtonStatus (bl%, br%, bc%)

 
	' ========================================================================
	' This function returns the state (up=0, down=1) of each mouse button.
	' If there is no third button on the mouse, then you can ignore the value
	' returned by bc% (there isn't one).
	'
	' Parameters:
	' -----------
	'   bl%   Returns the state of the left button (0=up, 1=down)
	'   br%   Returns the state of the right button (0=up, 1=down)
	'   bc%   Returns the state of the center button (0=up, 1=down)
	'
	'   Note 1:  None of these parameters need values when the sub is
	'            called.  They will be filled with values so you may use
	'            them when this sub returns.
	'
	'   Note 2:  The file MOUSE.BI contains two constants, UP and DOWN,
	'            which contain the values 0 and 1, respectively.  You may
	'            use these in place of 0 and 1 to make your programs more
	'            readable.
	' ========================================================================
	

	' ========================================================================
	' Call mouse function 3, Get Button Status, to obtain (you guessed it) the
	' status of the mouse buttons.
	' ========================================================================
 
	m1% = 3
	Mouse m1%, m2%, m3%, m4%

 
	' ========================================================================
	' The mouse function called above returns the status of all the mouse
	' buttons in one parameter (m2%).  The first bit position (least-
	' significant) contains the status for the left button.  The second bit
	' position contains the status for the right button, and the third bit
	' position contains the status for the center button.  If the bit at
	' the correct position is off (0), the button is up; if it is on (1),
	' the button is down.
	'
	' To extract these bit values from a single number (stored in m2%), we
	' must mask the value.  A discussion of bit masking is beyond the scope
	' of software documentation, but it suffices to say that if any button
	' is up (off), a value of 0 will be returned.  The values for down vary
	' depending on the button (left=1, right=2, center=4).  As long as the
	' value is not 0, the button is down.
	'
	' The next step is to extract the button statuses by masking the single
	' returned value.  The object leftButtonMask%, rightButtonMask%, and
	' centerButtonMask% can be found in the MOUSE.BI file.
	' ========================================================================

	bl% = m2% AND leftButtonMask%
	br% = m2% AND rightButtonMask%
	bc% = m2% AND centerButtonMask%

 
	' ========================================================================
	' Since (as mentioned above) the values for buttons being down can vary,
	' and we cannot have three different values for the DOWN object, we now
	' go thourgh each button status obtained and if the status is not 0
	' (we know it is down) and set the status value to DOWN.
	' ========================================================================
 
	IF bl% <> 0 THEN   ' Left button is DOWN
		bl% = BUTTONDOWN
	ELSE               ' Left button is UP
		bl% = BUTTONUP
	END IF


	IF br% <> 0 THEN   ' Right button is DOWN
		br% = BUTTONDOWN
	ELSE               ' Right button is UP
		br% = BUTTONUP
	END IF


	IF bc% <> 0 THEN   ' Center button is DOWN
		bc% = BUTTONDOWN
	ELSE               ' Center button is UP
		bc% = BUTTONUP
	END IF


END SUB

SUB MouseGetSensitivity (x%, y%, doubleSpeed%)

	' ========================================================================
	' This routine allows you to get the current mouse sensitivity for the x
	' and y directions, as well as set the double speed threshold.  Values
	' for all these parameters range from 1 to 100, 100 being the most
	' sensitive.
	'
	' Parameters:
	' -----------
	'   x%             horizontal mouse sensitivity
	'   y%             vertical mouse sensitivity
	'   doubleSpeed%   Specifies the threshold for mouse double speed
	'
	'   Note:  These parameters do not require values when the sub is called.
	'          They will contain the requested information when this function
	'          ends and returns to the calling function.
	' ========================================================================
	
 
	' ========================================================================
	' Make the call to the mouse function, asking for driver function 27,
	' Get Mouse Sensitivity.
	' ========================================================================

	m1% = 27
	Mouse m1%, m2%, m3%, m4%

 
	' ========================================================================
	' Return the mouse sensitivy values, as well as the double speed thresh-
	' hold, in the supplied variables.
	' ========================================================================

	x% = m2%
	y% = m3%
	doubleSpeed% = m4%


END SUB

SUB MouseHide

 
	' ========================================================================
	' This function turns the mouse cursor off.  There are no parameters - it
	' simply turns off the mouse cursor.
	' ========================================================================
 

	' ========================================================================
	' Make the call to the mouse function, requesting driver function 2,
	' Hide Mouse Cursor.
	' ========================================================================

	IF mouseState% <> MOUSEOFF THEN
		m1% = 2
		Mouse m1%, m2%, m3%, m4%
		mouseState% = MOUSEOFF
	END IF

END SUB

SUB MouseInfo (driverVersion$, mouseType%, IRQ%)


	' ========================================================================
	' This routine allows you to obtain the version of the mouse driver
	' currently installed, the type of mouse, and the IRQ in use by the
	' mouse.  Note that the number in the mouse driver version are hex
	' values.
	'
	'The mouse type returns the following values:
	'
	'               Value      Mouse type
	'               --------------------------------------
	'                 1        Bus mouse
	'                 2        Serial mouse
	'                 3        InPort mouse
	'                 4        PS/2 mouse
	'                 5        Hewlett Packard mouse
	'
	' Parameters:
	' -----------
	'   driverVersion$   Contains the version of the mouse driver software
	'   mouseType%       Contains the type of mouse installed, as detailed
	'                    above
	'   IRQ%             Contains the IRQ port in use by the mouse.
	'
	'   Note: The values for the mouse type are stored in named constants in
	'         the file MOUSE.BI.  The names are BUSMOUSE, SERIALMOUSE,
	'         INPORTMOUSE, PS2MOUSE, and HEWLETTPACKARDMOUSE.
	' ========================================================================
 

	' ========================================================================
	' Make the call to the mouse sub, requesting driver function 36, Get
	' Driver Version, Mouse Type, and IRQ Number.
	' ========================================================================

	m1% = 36
	Mouse m1%, m2%, m3%, m4%
 
 
	' ========================================================================
	' Extract the information from the returned data.  m3% contains the mouse
	' type in the low byte, and the IRQ port in the high byte.  The driver
	' major version (the left side of the decimal) is stored in the high byte
	' of m2%, and the minor version (right of decimal) is stored in the low
	' byte of m2%.
	' ========================================================================
 
	mouseType% = m3% \ 256
	IRQ% = m3% AND &HFF
	driverVersion$ = LTRIM$(RTRIM$(HEX$(m2% \ 256))) + "." + LTRIM$(RTRIM$(HEX$(m2% AND &HFF)))


END SUB

FUNCTION MouseInit%

	' ========================================================================
	' If mouse is present, this function returns the number of buttons
	' the mouse has.  If not, it returns a zero (0).  It also sets the
	' following mouse values:
	'
	'        Cursor Position: Center of screen
	'           Cursor State: OFF
	'  Graphics Cursor Shape: Arrow
	'            Text Cursor: Reverse Video
	' Double-speed threshold: 64
	' ========================================================================

 
	' ========================================================================
	' Make a call to the mouse sub, requesting driver function 0, Mouse
	' Initialize.
	' ========================================================================
	m1% = 0
	Mouse m1%, m2%, m3%, m4%

 
	' ========================================================================
	' The m1% parameter returns 0 if no mouse available, or -1 if one was
	' found.  If m1% is not zero (if it is TRUE), then m2% will contain the
	' number of buttons on the mouse.
	' ========================================================================
 
	IF m1% <> 0 THEN
		MouseInit% = m2%
	ELSE
		MouseInit% = 0
	END IF

	mouseState% = MOUSEOFF

END FUNCTION

SUB MouseMickeyCount (x%, y%)

	' ========================================================================
	' This function returns the number of mickeys moved in the x and y
	' directions since the last call to this function.  A positive value
	' indicates a movement either to the right or down. A negative value
	' indicates a movement either to the left or up.  One mickey equals
	' 1/200th of an inch.
	'
	' Parameters:
	' -----------
	'   x%   The number of horizontal mickeys
	'   y%   The number of vertical mickeys
	' ========================================================================


	' ========================================================================
	' Make a call to the mouse sub requesting driver function 11, Read Mouse
	' Motion Counters.
	' ========================================================================
 
	m1% = 11
	Mouse m1%, m2%, m3%, m4%

 
	' ========================================================================
	' The m3% parameter contains the number of horizontal mickeys, and the
	' m4% parameter contains the number of vertical mickeys.
	' ========================================================================
 
	x% = m3%
	y% = m4%


END SUB

SUB MouseOrKeyboardPause

	' ========================================================================
	' This function waits until either a key is pressed or any mouse button
	' is pressed.  When this is done, the function will exit.
	'
	' Parameters:
	' -----------
	'   None.
	'
	'   * NOTE: This routine assumes a mouse exists.
	'
	' ========================================================================


	' ========================================================================
	' Clear out all keyboard and mouse button presses that may be sitting in
	' buffers out there somewhere.
	' ========================================================================
		' Keyboard
		WHILE INKEY$ <> ""
		WEND
	 
		' Mouse
		MouseButtonPressInfo LEFTBUTTON, lmCnt%, mx%, my%
		MouseButtonPressInfo RIGHTBUTTON, rmCnt%, mx%, my%
		MouseButtonPressInfo CENTERBUTTON, cmCnt%, mx%, my%

	' ========================================================================
	' Wait for either a mouse or keyboard press.
	' ========================================================================
	done% = FALSE
	DO
	 
		mCnt% = 0
		key$ = ""
	 
		' Check mouse for button activity.
		MouseButtonPressInfo LEFTBUTTON, lmCnt%, mx%, my%
		MouseButtonPressInfo RIGHTBUTTON, rmCnt%, mx%, my%
		MouseButtonPressInfo CENTERBUTTON, cmCnt%, mx%, my%

		IF (lmCnt%) OR (rmCnt%) OR (cmCnt%) THEN
			done% = TRUE
		END IF

		' Check keyboard for activity.
		IF (INKEY$ <> "") THEN
			done% = TRUE
		END IF

	LOOP UNTIL done%


END SUB

SUB MousePosition (x%, y%)

	' ========================================================================
	' This routine returns the current position of the mouse on the virtual
	' screen in x and y.
	'
	' Parameters:
	' -----------
	'   x%   The mouse x-coordinate on the virtual screen
	'   y%   The mouse y-coordinate on the virtual screen
	' ========================================================================


	' ========================================================================
	' Make a call to the mouse sub requesting driver function 3, Get Button
	' Status and Mouse Position.
	' ========================================================================

	m1% = 3
	Mouse m1%, m2%, m3%, m4%

 
	' ========================================================================
	' Mouse parameter m3% contains the x-coordinate, while m4% contains the
	' y-coordinate.
	' ========================================================================
 
	x% = m3%
	y% = m4%


END SUB

SUB MouseSelectTextCursor (cursorType%, topScan%, botScan%, scrMask%, curMask%)


	' ========================================================================
	' This function allows you to select one of two types of mouse text
	' cursors.  The hardware cursor (cursorType%=1) will let you also
	' specify the top and bottom scan lines of the cursor.  The software
	' cursor (cursorType%=0) instead allows you to specify the screen and
	' cursor masks.  See the documentation for more details on this.
	'
	' Parameters:
	' -----------
	'   cursorType%   Type of mouse cursor (0=software, 1=hardware)
	'   topScan%      Top scan line for hardware cursor
	'   botScan%      Bottom scan line for hardware cursor
	'   scrMask%      Screen mask for software cursor
	'   curMask%      Cursor mask for software cursor
	'
	'   Note: If you are specifying a hardware cursor, then only the botScan%
	'         and topScan% parameters need meaningful values.  If you select
	'         a software cursor, then only the scrMask% and curMask% need
	'         meaningful values.  You must still pass in all the parameters,
	'         but only need to place real values in the parameters relevant
	'         to the type of cursor you are selecting.
	' ========================================================================


	' ========================================================================
	' Set parameters in preparation for the call to the mouse sub.  The m2%
	' parameter contains the type of cursor requested (0=software, 1=hardware)
	' ========================================================================
 
	m1% = 10
	m2% = cursorType%


	' ========================================================================
	' If you are requesting a hardware cursor, then the m3% parameter contains
	' the topScan% value and the m4% parameter contains the botScan% value.
	' If you are requesting a software cursor, then m3% contains the scrMask%
	' value and m4% contains the curMask% value.
	' ========================================================================

	IF cursorType% = 1 THEN      ' Hardware cursor
		m3% = topScan%
		m4% = botScan%
	ELSE                         ' Software cursor
		m3% = scrMask%
		m4% = curMask%
	END IF
 
 
	' ========================================================================
	' Make the call to the mouse sub with the preset parameters.
	' ========================================================================
 
	Mouse m1%, m2%, m3%, m4%


END SUB

SUB MouseSetMinMaxX (minX%, maxX%)

 
	' ========================================================================
	' This routine allows you to specify the minimum and maximum horizontal
	' coordinates of the virtual screen on which the mouse cursor is allowed
	' to move.
	'
	' Parameters:
	' -----------
	'   minX%   The left-most x-coordinate in which the mouse can move
	'   maxX%   The right-most x-coordinate in which the mouse can move
	' ========================================================================


	' ========================================================================
	' Make a call to the mouse sub requesting driver function 7, Set Min/Max
	' Horizontal Cursor Position.  The m3% parameter contains the minimum
	' x passed in, and m4% contains the maximum x.  There is no return value.
	' ========================================================================
 
	m1% = 7
	m3% = minX%
	m4% = maxX%
	Mouse m1%, m2%, m3%, m4%


END SUB

SUB MouseSetMinMaxY (minY%, maxY%)

	' ========================================================================
	' This routine allows you to specify the minimum and maximum vertical
	' coordinates of the virtual screen on which the mouse cursor is allowed
	' to move.
	'
	' Parameters:
	' -----------
	'   minY%   The left-most y-coordinate in which the mouse can move
	'   maxY%   The right-most y-coordinate in which the mouse can move
	' ========================================================================


	' ========================================================================
	' Make a call to the mouse sub requesting driver function 8, Set Min/Max
	' Vertical Cursor Position.  The m3% parameter contains the minimum y
	' passed in, and m4% contains the maximum y.  There is no return value.
	' ========================================================================

	m1% = 8
	m3% = minY%
	m4% = maxY%
	Mouse m1%, m2%, m3%, m4%


END SUB

SUB MouseSetPosition (x%, y%)
	 
 
	' ========================================================================
	' This routine allows you to place the mouse cursor on the virtual
	' screen at coordinates x% and y%.
	'
	' Parameters:
	' -----------
	'   x%   The x-coordinate where the mouse cursor will be placed
	'   y%   The y-coordinate where the mouse cursor will be placed
	' ========================================================================


	' ========================================================================
	' Make a call to the mouse sub requesting driver function 4, Set Mouse
	' Cursor Position.  The m3% parameter contains the x coordinate, while
	' the m4% parameter contains the y-coordinate.
	' ========================================================================

	m1% = 4
	m3% = x%
	m4% = y%
	Mouse m1%, m2%, m3%, m4%


END SUB

SUB MouseSetSensitivity (x%, y%, doubleSpeed%)

	' ========================================================================
	' This routine allows you to set the mouse sensitivity for the x and y
	' directions, as well as set the double speed threshold.  Values for
	' all these parameters range from 1 to 100, 100 being the most sensitive.
	'
	' Parameters:
	' -----------
	'   x%             horizontal mouse sensitivity
	'   y%             vertical mouse sensitivity
	'   doubleSpeed%   Specifies the threshold for mouse double speed
	' ========================================================================


	' ========================================================================
	' Make a call to the mouse sub requesting driver function 26, Set Mouse
	' Sensitivity.
	' ========================================================================
 
	m1% = 26
	m2% = x%
	m3% = y%
	m4% = doubleSpeed%
	Mouse m1%, m2%, m3%, m4%


END SUB

SUB MouseShow STATIC
											
 
	' ========================================================================
	' This sub displays the mouse cursor.  There are no parameters.
	' ========================================================================

 
	' ========================================================================
	' Make a call to the mouse sub requesting driver function 1, Show Cursor.
	' ========================================================================

	IF mouseState% <> MOUSEON THEN
		m1% = 1
		Mouse m1%, m2%, m3%, m4%
		mouseState% = MOUSEON
	END IF

END SUB

