Mouse Coordinates in SVGA


Typical rodent drivers don't read the screen coordinates correctly in SVGA modes and so the correspondence between rodent coordinates ("mickies") and screen coordinates gets mixed up. This is a routine I wrote to correct for that.


'
' This subroutine calculates the horizontal (MDX) and vertical (MDY)
' (MDY) cursor motion scale factors in the current video mode. (There
' are MDX mouse movement pixels (or "mickeys") for each horizontal screen
' pixel and MDY mouse mickyes for each vertical screen pixel. The primary
' use of this routine is with an SVGA video mode, since the standard
' rodent driver has a problem diagnosing SVGA video characterteristics.
'
' The way you'd use the outputs depends on what you're doing. If you're
' using one of the rodent functions (3 or 5, for example) to read the
' mouse coordinates and you want to get the corresponding screen
' coordinates, you'd use MDX and MDY. Let's say X and Y are the
' horizontal and vertical coordinates returned by your mouse function.
' The screen coordinates are INT(X / MDX) and INT(Y / MDY). (You
' shouldn't really need the INT functions; I'm just "being safe.")
'
' If you want to use the mouse functions that set the mouse position or
' constrain it's motion and you want to calculate the setting or
' constraints based on *screen* coordinates X and Y, you would also use
' MDX and MDY. This time, however, you multiply: mouse horizontal
' coordinate = X * MDX and mouse vertical coordinate = Y * MDY.
'
' (The routine makes the ludicrous allowance for there to be up to 8000
' mickeys per horizontal screen pixel and 5000 per vertical pixel. Feel
' free to drastically decrease those numbers in the FOR/NEXT loops.)
'
SUB MICKEY(MDX AS INTEGER,MDY AS INTEGER)
DIM I AS INTEGER,KX AS INTEGER,KY AS INTEGER,MXMAX AS INTEGER,MYMAX AS INTEGER
'
' Set up machine code.
'
DIM RODCODE(1 TO 10) AS LONG,OS AS INTEGER,CX AS INTEGER,DX AS INTEGER
DEF SEG=VARSEG(RODCODE(1))
OS=VARPTR(RODCODE(1))
POKE OS,&HB8 : POKE OS+1,&H00 : POKE OS+2,0 'MOV AX,0
POKE OS+3,&HCD : POKE OS+4,&H33 'INT 33
POKE OS+5,&HCB 'RETF
POKE OS+6,&H55 'PUSH BP
POKE OS+7,&H89 : POKE OS+8,&HE5 'MOV BP,SP
POKE OS+9,&HB8 : POKE OS+10,4 : POKE OS+11,0 'MOV AX,4
POKE OS+12,&HB9 : POKE OS+13,&HBB : POKE OS+14,&HAA 'MOV CX,[RODENT X]
POKE OS+15,&HBA : POKE OS+16,&HDD : POKE OS+17,&HCC 'MOV DX,[RODENT Y]
POKE OS+18,&HCD : POKE OS+19,&H33 'INT 33
POKE OS+20,&HB8 : POKE OS+21,3 : POKE OS+22,0 'MOV AX,3
POKE OS+23,&HCD : POKE OS+24,&H33 'INT 33
POKE OS+25,&H8B : POKE OS+26,&H5E : POKE OS+27,6 'MOV BX,[BP+6]
POKE OS+28,&H89 : POKE OS+29,&H17 'MOV [BX],DX
POKE OS+30,&H8B : POKE OS+31,&H5E : POKE OS+32,8 'MOV BX,[BP+8]
POKE OS+33,&H89 : POKE OS+34,&HF 'MOV [BX],CX
POKE OS+35,&H5D 'POP BP
POKE OS+36,&HCA : POKE OS+37,4 : POKE OS+38,0 'RETF 4
'
' Initialize rodent before doing anything.
'
CALL ABSOLUTE(OS)
'
' For 8001 successive mouse mickeys, attempt to set the horizontal
' position and then read that position. When the detected position fails
' to agree with what it was set to, the horizontal limit on the mouse
' motion must have been found.
'
MXMAX=0
KX=0
FOR I=0 TO 8000
POKE OS+13,I AND &HFF : POKE OS+14,(I AND &HFF00&)/256
POKE OS+16,0 : POKE OS+17,0
CALL ABSOLUTE(CX,DX,OS+6)
IF CX=I THEN
KX=KX+1
MXMAX=I
END IF
NEXT I
'
' Repeat above process to find the vertical limit.
'
MYMAX=0
KY=0
FOR I=0 TO 5000
POKE OS+13,0 : POKE OS+14,0
POKE OS+16,I AND &HFF : POKE OS+17,(I AND &HFF00&)/256
CALL ABSOLUTE(CX,DX,OS+6)
IF DX=I THEN
KY=KY+1
MYMAX=I
END IF
NEXT I
DEF SEG
'
' Get mickey/screen pixel ratio. (First set default, possibly erroneous,
' values in case above process screwed up for some reason.)
'
MDX=1 : MDY=1
IF KX>1 THEN MDX=CSNG(MXMAX)/(KX-1)
IF KY>1 THEN MDY=CSNG(MYMAX)/(KY-1)
END SUB


AyOma(?)

Orig. Posted in [ http://forum.qbasicnews.com ] by Glenn.


MouseCoordinatesInSvga - page last edited 2004-02-17 12:09:48 by 217.217.62.217 (home) (edit)
Blast WIKI - by RoboticBoy - edited and tweaked for our evil purposes by Hexadecimal Disaster