home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / turbopas / pstui100.zip / PTUIMSE.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-01  |  9KB  |  379 lines

  1. {
  2.  
  3.                                                       ╔══════════════════╗
  4.                                                       ║    PTUI Text     ║
  5.                                                       ║    Mouse Unit    ║
  6.                                                       ║    Rev.  1.00    ║
  7.                                                       ╚══════════════════╝
  8.  
  9. }
  10.  
  11. {$F+} {$O-} {$A+} {$G+}
  12. {$V-} {$B-} {$X-} {$N+} {$E+}
  13.  
  14. {$I FINAL.PAS}
  15.  
  16. {$IFDEF FINAL}
  17.   {$I-} {$R-}
  18.   {$D-} {$L-} {$S-}
  19. {$ENDIF}
  20.  
  21. Unit PTUIMSE;
  22.  
  23. Interface
  24.  
  25. Uses CRT,Dos,PTUIMDef;
  26.  
  27. Procedure Init         (Installed:Boolean);
  28. Procedure Show;
  29. Procedure Hide;
  30. Procedure SetSpeed     (Mousems:Byte);
  31. Procedure SetXY        (X,Y:Word);
  32. Procedure SetBounds    (X1,Y1,X2,Y2:Word);
  33. Procedure GetPresses   (Var X,Y:Word;Var Button:Byte;Var Held:Boolean;
  34.                         Var NumTimes:Word);
  35. Procedure GetXY        (Var X,Y:Word);
  36. Procedure GetStatus    (Var X,Y:Word;Var Left,Right,Middle:Boolean);
  37. Procedure GetClick     (Var X1, Y1, X2, Y2:Word; Var MouseButton:Byte;
  38.                         Var Held,Doubled:Boolean);
  39.  
  40.  
  41. Implementation
  42.  
  43. Var
  44.   OldMouseChar:Word;
  45.  
  46. Procedure Init(Installed:Boolean);
  47. Begin
  48.   If Not Installed Then
  49.     Installed:=False
  50.   Else
  51.   Asm
  52.     xor   ax, ax
  53.     int   33h
  54.     and   ax, 1         {ax = $FFFF if installed, Else 0}
  55.     mov   Installed, al
  56.   End;
  57.   Active:=Installed;
  58.   If Installed Then SetSpeed(25);
  59. End;
  60.  
  61. Procedure Show; Assembler;
  62.  
  63. { ╔════════════════════════════════════════════════════════════════════════╗ }
  64. { ║  Show mouse on screen.                                                 ║ }
  65. { ╚════════════════════════════════════════════════════════════════════════╝ }
  66.  
  67. Asm
  68.   mov ax, 1
  69.   int 33h
  70. End;
  71.  
  72. Procedure Hide; Assembler;
  73.  
  74. { ╔════════════════════════════════════════════════════════════════════════╗ }
  75. { ║  Mouse still active but hidden, not on screen.                         ║ }
  76. { ╚════════════════════════════════════════════════════════════════════════╝ }
  77.  
  78. Asm
  79.   mov ax, 2
  80.   int 33h
  81. End;
  82.  
  83. Procedure SetSpeed(Mousems:Byte);
  84.  
  85. { ╔════════════════════════════════════════════════════════════════════════╗ }
  86. { ║  Sets up the ComputerSpeed variable for mouse double click speed.      ║ }
  87. { ╚════════════════════════════════════════════════════════════════════════╝ }
  88.  
  89. Var
  90.    MBC       :0..2;
  91.    H,M,S,S100:Word;
  92.    LoopAmount,
  93.    Counter,
  94.    Total100b,
  95.    Total100  :LongInt;
  96.    Regs      :Registers;
  97.    C         :Char;
  98.    Fraction  :Real;
  99.  
  100. Begin
  101.   If Not Active Then
  102.   Begin
  103.     ComputerSpeed:=1000;
  104.     Exit;
  105.   End;
  106.  
  107.   LoopAmount:=9000;
  108.   Repeat
  109.     Inc(LoopAmount,1000);
  110.     GetTime(H,M,S,S100);
  111.     Total100:=S100;
  112.     Inc(Total100,S*100);
  113.     Inc(Total100,LongInt(M)*60*100);
  114.     Inc(Total100,LongInt(H)*60*60*100);
  115.     MBC:=0;
  116.     For Counter:=1 to LoopAmount do
  117.     Begin                                   {Waste Time Approx time for Mouse Check}
  118.       Regs.AX:=5;
  119.       Regs.BX:=MBC;
  120.       Intr($33,Regs);
  121.       If MBC=2 Then MBC:=0 Else Inc(MBC);
  122.       If (Regs.BX<>0) Then ;                {The Until Equivalent}
  123.       If KeyPressed Then C:=ReadKey;
  124.     End;
  125.     GetTime(H,M,S,S100);
  126.     Total100b:=S100;
  127.     Inc(Total100b,S*100);
  128.     Inc(Total100b,LongInt(M)*60*100);
  129.     Inc(Total100b,LongInt(H)*60*60*100);
  130.  
  131.     If LoopAmount>2100000000 Then
  132.     Begin
  133.       WriteLn('Unable to set Mouse Double Click Timer.');
  134.       Halt(0);
  135.     End;
  136.   Until (Total100b>Total100+10);
  137.  
  138.   Total100:=Total100b-Total100;   {Time Taken to do loop}
  139.   Fraction:=Mousems/Total100;     {We want time to be Mousems ms}
  140.   ComputerSpeed:=Round(Fraction*LoopAmount);
  141. End;
  142.  
  143. Procedure SetXY(X,Y:Word); Assembler;
  144.  
  145. { ╔════════════════════════════════════════════════════════════════════════╗ }
  146. { ║  Mouse the mouse to a VGA co-ordinate on the screen.                   ║ }
  147. { ╚════════════════════════════════════════════════════════════════════════╝ }
  148.  
  149. Asm
  150.   mov  ax,4
  151.   mov  cx,X
  152.   mov  dx,Y
  153.   int  33h
  154. End;
  155.  
  156. Procedure SetBounds(X1,Y1,X2,Y2:Word); Assembler;
  157.  
  158. { ╔════════════════════════════════════════════════════════════════════════╗ }
  159. { ║  Lock the mouse in a rectangle of the screen.                          ║ }
  160. { ╚════════════════════════════════════════════════════════════════════════╝ }
  161.  
  162. Asm
  163.   mov  ax,7
  164.   mov  cx,X1
  165.   mov  dx,X2
  166.   int  33h
  167.   mov  ax,8
  168.   mov  cx,Y1
  169.   mov  dx,Y2
  170.   int  33h
  171. End;
  172.  
  173. Procedure GetPresses(Var X,Y:Word;Var Button:Byte;Var Held:Boolean;Var NumTimes:Word); Assembler;
  174.  
  175. { ╔════════════════════════════════════════════════════════════════════════╗ }
  176. { ║                                                                        ║ }
  177. { ║ Returns the Co-Ordinate of Last Button Press For Buttons.              ║ }
  178. { ║ Returns which button was pressed (0..2) or 255 if no button has been   ║ }
  179. { ║ pressed.                                                               ║ }
  180. { ║ Returns Held True if the button is still being held down.              ║ }
  181. { ║                                                                        ║ }
  182. { ╚════════════════════════════════════════════════════════════════════════╝ }
  183.  
  184. Label EndOfCheck,NotHeld,NoButtons,EndOfSub,
  185.       Button0,Button1,Button2,VeryEndOfSub;
  186.  
  187. Asm
  188.   mov  ax,5
  189.   mov  bx,0
  190.   mov  si,1
  191.   int  33h
  192.   cmp  bx,0             {Test Button 0}
  193.   jne  EndOfCheck
  194.  
  195.   mov  ax,5
  196.   mov  bx,1
  197.   mov  si,2
  198.   int  33h
  199.   cmp  bx,0             {Test Button 1}
  200.   jne  EndOfCheck
  201.  
  202.   mov  ax,5
  203.   mov  bx,2
  204.   mov  si,4
  205.   int  33h
  206.   cmp  bx,0             {Test Button 2}
  207.   jne  EndOfCheck
  208.  
  209.   jmp  NoButtons
  210.  
  211. EndOfCheck:
  212.  
  213.   les  di,NumTimes
  214.   mov  es:[di],bx
  215.   les  di,X
  216.   mov  es:[di],cx
  217.   les  di,Y
  218.   mov  es:[di],dx
  219.  
  220.   les  di,Held
  221.   and  ax,si
  222.   cmp  ax,0
  223.   je   NotHeld
  224.  
  225.   mov  al,1
  226.   jmp  EndOfSub
  227.  
  228. NotHeld:
  229.  
  230.   mov  al,0
  231.   jmp  EndOfSub
  232.  
  233. NoButtons:
  234.  
  235.   mov  si,0
  236.   mov  ax,0
  237.   les  di,NumTimes
  238.   mov  es:[di],ax
  239.   les  di,X
  240.   mov  es:[di],ax
  241.   les  di,Y
  242.   mov  es:[di],ax
  243.   les  di,Held
  244.   mov  al,0
  245.  
  246. EndOfSub:
  247.  
  248.   mov  es:[di],al       {Move value into Held}
  249.  
  250.   les  di,Button
  251.   cmp  si,1
  252.   je   Button0
  253.   cmp  si,2
  254.   je   Button1
  255.   cmp  si,4
  256.   je   Button2
  257.  
  258.   mov  al,0ffh            {No Button}
  259.  
  260.   jmp  VeryEndOfSub
  261.  
  262. Button0:
  263.  
  264.   mov  al,0
  265.   jmp  VeryEndOfSub
  266.  
  267. Button1:
  268.  
  269.   mov  al,1
  270.   jmp  VeryEndOfSub
  271.  
  272. Button2:
  273.  
  274.   mov  al,2
  275.  
  276. VeryEndOfSub:
  277.  
  278.   mov  es:[di],al               {Move a value into Button}
  279.  
  280. End;
  281.  
  282. Procedure GetXY(Var X,Y:Word); Assembler;
  283. Asm
  284.   mov  ax,3
  285.   int  33h
  286.   les  di,X
  287.   mov  es:[di],cx
  288.   les  di,Y
  289.   mov  es:[di],dx
  290. End;
  291.  
  292. Procedure GetStatus(Var X,Y:Word;Var Left,Right,Middle:Boolean); Assembler;
  293. Asm
  294.   mov  ax,3
  295.   int  33h
  296.   les  di,X
  297.   mov  es:[di],cx
  298.   les  di,Y
  299.   mov  es:[di],dx
  300.  
  301.   mov  ax,bx
  302.   and  ax,1
  303.   les  di,Left
  304.   mov  es:[di],al
  305.  
  306.   mov  ax,bx
  307.   and  ax,2
  308.   shr  ax,1
  309.   les  di,Right
  310.   mov  es:[di],al
  311.  
  312.   mov  ax,bx
  313.   and  ax,4
  314.   shr  ax,1
  315.   shr  ax,1
  316.   les  di,Middle
  317.   mov  es:[di],al
  318. End;
  319.  
  320. Procedure GetClick(Var X1, Y1, X2, Y2:Word;
  321.                    Var MouseButton:Byte;
  322.                    Var Held,Doubled:Boolean);
  323.  
  324. { ╔════════════════════════════════════════════════════════════════════════╗ }
  325. { ║  Return the VGA co-ordinate of the mouse once a key or mouse button    ║ }
  326. { ║  has been pressed.  Double set True for a Double Click.                ║ }
  327. { ║  Also returns which button is being pressed or held.                   ║ }
  328. { ╚════════════════════════════════════════════════════════════════════════╝ }
  329.  
  330. Var
  331.   Button2    :Byte;
  332.   NumPresses :Word;
  333.   X          :LongInt;
  334.   HeldA,
  335.   HeldB,
  336.   HeldC      :Boolean;
  337.  
  338. Begin
  339.   Doubled:=False;
  340.   Held:=False;
  341.  
  342.   If Active Then
  343.   Begin
  344.     Repeat
  345.       GetPresses(X1,Y1,MouseButton,Held,NumPresses);
  346.     Until (MouseButton<>255) Or KeyPressed;
  347.  
  348.     X:=0;
  349.     Repeat
  350.       GetPresses(X2,Y2,Button2,Held,NumPresses);
  351.       Inc(X);
  352.     Until (Button2<>255) Or KeyPressed Or (X>ComputerSpeed);
  353.  
  354.     If (X<=ComputerSpeed) Then
  355.       Doubled:=True
  356.     Else
  357.     Begin
  358.       GetStatus(X2,Y2,HeldA,HeldB,HeldC);
  359.       Held:=HeldA Or HeldB Or HeldC;
  360.       X2:=0;             {No Double Click}
  361.       Y2:=0;
  362.     End;
  363.   End
  364.   Else  {No Mouse}
  365.   Begin
  366.     X1:=0;
  367.     Y1:=0;
  368.     X2:=0;
  369.     Y2:=0;
  370.     Doubled:=True;
  371.     MouseButton:=1;
  372.   End;
  373.   If Doubled Then Held:=False;
  374. End;
  375.  
  376. End.
  377.  
  378. { Copyright 1993, Michael Gallias }
  379.