'Sun  Apr 23, 1989   2:19:17 pm     
'**********************************************************************
'This set of routines carry out different MOUSE functions. 
'**********************************************************************
DECLARE SUB getbutton ()
DECLARE SUB mousewindow (left, right, top, bottom)
DECLARE SUB mouse (m1, m2, m3, m4)
DECLARE SUB mouseon (value)
DECLARE SUB movecursor ()
DECLARE SUB waitforbutton (button)
DECLARE FUNCTION mouseinstalled ()


TYPE RegType
     ax    AS INTEGER
     bx    AS INTEGER
     cx    AS INTEGER
     dx    AS INTEGER
     bp    AS INTEGER
     si    AS INTEGER
     di    AS INTEGER
     flags AS INTEGER
END TYPE

DIM SHARED inregs AS RegType, outregs AS RegType
COMMON SHARED numbuttons, button, row, col, in$


     IF mouseinstalled = 0 THEN mouseon 0 ELSE mouseon 1
     CLS
     CALL mousewindow(0, 640, 1, 200)
     DO
          waitforbutton 0
          getbutton
          LOCATE row, col
          PRINT row; col
    LOOP UNTIL button = 2
END

SUB getbutton
     DO
          CALL mouse(3, button, x, y)
          row = INT(y / 8) + 1: col = INT(x / 8) + 1
          in$ = INKEY$
     LOOP UNTIL button <> 0 OR in$ <> ""
END SUB

SUB mouse (m1, m2, m3, m4)
DIM InRegs AS regtype, OutRegs AS regtype
     InRegs.ax = m1
     InRegs.bx = m2
     InRegs.cx = m3
     InRegs.dx = m4
     CALL INTERRUPT(51, InRegs, OutRegs)
     m1 = OutRegs.ax
     m2 = OutRegs.bx
     m3 = OutRegs.cx
     m4 = OutRegs.dx
END SUB

FUNCTION mouseinstalled
     m = 0                      ' reset function
     CALL mouse(m, n, 0, 0)     ' returns M = 0 if no mouse installed
     numbuttons = n
     mouseinstalled = m
END FUNCTION

SUB mouseon (value)
     IF value = 0 THEN m = 2 ELSE m = 1
     CALL mouse(m, 1, 0, 0)
END SUB

SUB mousewindow (left, right, top, bottom)
     CALL mouse(7, 0, left, right)
     CALL mouse(8, 0, top, bottom)
END SUB

SUB movecursor
     waitforbutton (0)
     CLS
     LOCATE 4, 1
     v = 24                       ' vertical position
     FOR h = 1 TO 400
          CALL mouse(4, x, h, v) ' position the cursor
     NEXT
END SUB

SUB waitforbutton (button)
     DO
          CALL mouse(3, b, x, y)
     LOOP UNTIL b = button
END SUB
