Unit CoolMice;

                        INTERFACE
Type
 TMouseState = record
   Buttons : Integer;
   X,Y     : Integer;
 end;
 PMouseState = ^TMouseState;

Function  InitMouse(var aMS:PMouseState):boolean;
Procedure ShowMouse;
Procedure HideMouse;
Procedure GetMouseState(var aMS:TMouseState);
Procedure SetMouseClip(x1,y1,x2,y2:integer);
Procedure SetMouseShape(HotX,HotY : byte; Data:Pointer);
Procedure DoneMouse;
                        IMPLEMENTATION
var
 MS : TMouseState;

Procedure MouseHandler;far;assembler;
asm
  mov MS.Buttons, bx
  mov MS.X,       CX
  mov MS.Y,       DX
ENd;

Procedure SetMouseHandler(EventMask:Word; Handler:Pointer);assembler;
asm
  mov ax, 000cH
  mov cx, word ptr EventMask

  mov bx, word ptr [Handler+2]
  mov es, bx
  mov dx, word ptr [Handler]

  int 33h
ENd;

Procedure CloseMouseHandler(Handler:Pointer);assembler;
asm
  mov ax, 000cH
  mov cx, 0

  mov bx, word ptr [Handler+2]
  mov es, bx
  mov dx, word ptr [Handler]

  int 33h
ENd;

Function InitMouse(var aMS:PMouseState):boolean;
begin
  asm
    mov ax, 0
    int 33h
  end;
  aMS := @MS;
{  SetMouseHandler($7F,@MouseHandler);}
  InitMouse:=true;
ENd;

Procedure GetMouseState(var aMS:TMouseState);
var 
 b,x,y : integer;
begin
  asm
   mov ax, 3
   int 33h
   mov word ptr b, bx
   mov word ptr x, cx
   mov word ptr y, dx
  end;
  aMs.Buttons := B;
  aMs.X := X;
  aMs.Y := Y;
end;

Procedure DoneMouse;
begin
{ CloseMouseHandler(@MouseHandler);}
end;

Procedure ShowMouse;assembler;
asm
  mov ax, 0001h
  int 33h
ENd;

Procedure HideMouse;assembler;
asm
  mov ax, 0002h
  int 33h
ENd;

Procedure SetMouseClip(x1,y1,x2,y2:integer);assembler;
asm
 mov ax, 07h
 mov cx, [x1]
 mov dx, [x2]
 int 33h

 mov ax, 08d
 mov cx, [y1]
 mov dx, [y2]
 int 33h
end;

Procedure SetMouseShape(HotX,HotY : byte; Data:Pointer);assembler;
asm
  mov ax, 09h
  mov bx, word ptr [Data+2]
  mov es, bx
  mov dx, word ptr [Data]

  mov bx, word ptr [HotX]
  mov cx, word ptr [HotY]
  int 33h
end;
END.