unit Mouse;

interface

function  InitMouse:boolean;

procedure ShowMouse;
procedure HideMouse;

procedure SetMouseXY(X,Y:word);
function  GetMouseX:word;
function  GetMouseY:word;
function  GetMouseRelX:word;
function  GetMouseRelY:word;

function  ReturnPressedButton:word;
function  ButtonDown:boolean;
function  ButtonUp:boolean;

procedure SetMouseSensitivity(x,y:word);
procedure SetMouseMinMaxX(MinX,MaxX:word);
procedure SetMouseMinMaxY(MinY,MaxY:word);
procedure SetMouseStep(StepX,StepY:word);
procedure SetMouseMaxSpeed(Speed:word);

implementation

function InitMouse:boolean;
var Temp,Result:word;
begin
 asm
  MOV AX,00H
  INT 33H
  MOV [Result],AX
  MOV [Temp],BX
 end; {asm}
 if Result=$FFFF then InitMouse:=true else InitMouse:=false;
end; {InitMouse}

    procedure ShowMouse;
    begin
    	asm
        	mov ax,01h
            int 33h
        end; {asm}
    end; {ShowMouse}

	procedure HideMouse;
    begin
    	asm
        	mov ax,02h
            int 33h
        end; {asm}
    end; {HideMouse}

    procedure SetMouseXY(X,Y:word);
    begin
     X:=X*8;
     Y:=Y*8;
     asm
      MOV AX,0004H
      MOV CX,X
      MOV DX,Y
      INT 33H
     end;
    end;

    function GetMouseX:word;
    var
     Temp:word;
    begin
     asm
      mov ax,03h
      int 33h
      mov [Temp],cx
     end; {asm}
     GetMouseX:=trunc(Temp/8);
    end; {GetMouseX}

	function GetMouseY:word;
    var
    	Temp:word;
    begin
    	asm
        	mov ax,03h
            int 33h
            mov [Temp],dx
        end; {asm}
     GetMouseY:=trunc(Temp/8);
    end; {GetMouseY}

    function GetMouseRelX:word;
    var
    	Temp:word;
    begin
    	asm
        	mov ax,0Bh
            int 33h
            mov [Temp],cx
        end; {asm}
        GetMouseRelX:=Temp;
    end; {GetMouseRelX}

	function GetMouseRelY:word;
    var
    	Temp:word;
    begin
     asm
      mov ax,0Bh
      int 33h
      mov [Temp],dx
     end; {asm}
     GetMouseRelY:=Temp;
    end; {GetMouseRelY}

	function ReturnPressedButton:word;
	var
    	Temp:word;
	begin
		asm
        	mov ax,03h
			int 33h
			mov [Temp],bx
        end; {asm}
        ReturnPressedButton:=Temp;
    end; {ReturnPressedButton}

    function ButtonDown:boolean;
    begin
		ButtonDown:=ReturnPressedButton<>0;
    end; {ButtonDown}

    function ButtonUp:boolean;
    begin
    	ButtonUp:=ReturnPressedButton=0;
    end; {ButtonUp}

    procedure SetMouseSensitivity(x,y:word);
    begin
        asm
         mov ax,1ah
         mov bx,[x]
         mov cx,[y]
         mov dx,1
         int 33h
        end; {asm}
    end; {SetMouseSensitivity}

    procedure SetMouseMinMaxX(MinX,MaxX:word);
    begin
     MinX:=MinX*8;
     MaxX:=MaxX*8;
     asm
      MOV AX,0007H
      MOV CX,MinX
      MOV DX,MaxX
      INT 33H
     end;
    end;

    procedure SetMouseMinMaxY(MinY,MaxY:word);
    begin
     MinY:=MinY*8;
     MaxY:=MaxY*8;
     asm
      MOV AX,0008H
      MOV CX,MinY
      MOV DX,MaxY
      INT 33H
     end;
    end;

    procedure SetMouseStep(StepX,StepY:word);
    begin
     asm
      MOV AX,000FH
      MOV CX,StepX
      MOV DX,StepY
      INT 33H
     end;
    end;

    procedure SetMouseMaxSpeed(Speed:word);
    begin
     asm
      MOV AX,0013H
      MOV DX,Speed
      INT 33H
     end;
    end;

end. {Mouse}