'===========================================================================
' Subject: QBASIC MOUSE ROUTINES              Date: 02-15-97 (16:30)       
'  Author: Dan Campbell                       Code: QB, QBasic, PDS        
'  Origin: dm.campbell@ns.sympatico.ca      Packet: MOUSE.ABC
'===========================================================================
'ÉÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍ»
'º MOUSE.BAS º Feb. 1997 º
'ÌÍÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
'º This is an easy way to get a mouse element into your program. To actually º
'º put in a button i've found that you need to get rid of the fancy cursor.  º
'º                                                                           º
'º Thanks to Claude Gagn‚ for the shell of the mouse program, wherever he    º
'º got it from. If anyone has a use for a Novell Netware look-alike shell.   º
'º (the login screen) they can e-mail me at Eebert@HoTMaiL.com               º
'º                                                                           º
'ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼

DEFINT A-Z
DECLARE SUB getmouse (mode%)
DECLARE SUB initmouse ()
DECLARE SUB mouse (OnOff%)
DECLARE SUB readdata ()
DECLARE FUNCTION Interupt% (Num%, ax%, bx%, cx%, dx%)
DIM SHARED XCoord%, YCoord%, Click%
DIM SHARED ml%(45)


SCREEN 12   'Rem this out if you like the QBasic mouse design...
readdata
initmouse
getmouse mode%
mouse 1
DO
getmouse 0
LOCATE 1, 1: COLOR 7: PRINT "Mouse XCoord% = "; XCoord%  'Print X coordinates
LOCATE 2, 1: COLOR 7: PRINT "Mouse YCoord% = "; YCoord%  'Print Y coordinates
IF Click% = 1 THEN LOCATE 3, 1: COLOR 7: PRINT "Left mouse button clicked "  'Check if buttons are clicked
IF Click% = 2 THEN LOCATE 3, 1: COLOR 7: PRINT "Right mouse button clicked"

LOOP UNTIL INKEY$ = CHR$(27)

MS.Data:               '<!--- WARNING - Do not change this... ---!>
 DATA 55,8b,ec,56,57        
 DATA 8b,76,0c,8b,04         
 DATA 8b,76,0a,8b,1c
 DATA 8b,76,08,8b,0c
 DATA 8b,76,06,8b,14
 DATA cd,21                 
 DATA 8b,76,0c,89,04         
 DATA 8b,76,0a,89,1c
 DATA 8b,76,08,89,0c
 DATA 8b,76,06,89,14
 DATA 5f,5e,5d               
 DATA ca,08,00               
 DATA #

SUB getmouse (mode%)

  R% = Interupt%(&H33, 3, bx%, cx%, dx%)

  Click% = bx%

  IF mode% THEN
   XCoord% = cx% / 16 + 1
   YCoord% = dx% / 16 + 1
  ELSE
   XCoord% = cx%
   YCoord% = dx%
  END IF


END SUB

SUB initmouse

'Calls mouse interrupts...

 R% = Interupt%(&H33, 0, bx%, cx%, dx%)

END SUB

FUNCTION Interupt% (Num%, ax%, bx%, cx%, dx%)

 IF ml%(0) = 0 THEN   'Error, no MS.Data statment...
 BEEP
 BEEP
 END
 END IF

 DEF SEG = VARSEG(ml%(0))
 POKE VARPTR(ml%(0)) + 26, Num%

 CALL ABSOLUTE(ax%, bx%, cx%, dx%, VARPTR(ml%(0)))

 Interupt% = ax%


END FUNCTION

SUB mouse (OnOff%)

 IF OnOff% = 0 THEN OnOff% = 2 ELSE OnOff% = 1
 R% = Interupt%(&H33, OnOff%, bx%, cx%, dx%)

END SUB

SUB readdata

'Reads machine language thingy MS.Data...

RESTORE MS.Data
 DEF SEG = VARSEG(ml%(0))

 FOR i% = 0 TO 99
  READ Octet$
  IF Octet$ = "#" THEN EXIT FOR
  POKE VARPTR(ml%(0)) + i%, VAL("&H" + Octet$)
 NEXT i%

END SUB
