home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 31 / CDASC_31_1996_juillet_aout.iso / internet / rnr214.zip / MOUSE.PAS < prev    next >
Pascal/Delphi Source File  |  1994-10-09  |  7KB  |  229 lines

  1. Unit mouse;
  2.  
  3. {------------------------------------------------------------}
  4. { For Turbo Pascal Release 4.n. Won't work with older levels }
  5. { IMplements calls to mouse device driver.  Works with the   }
  6. { Logitech and Microsoft mice, and anything else compatible. }
  7. {                                                            }
  8. {                           NOTE!!!                          }
  9. {      COMPILER OPTIONS MUST BE SET TO FORCE FAR CALLS!      }
  10. {      If not, user defined task installed by minstTask      }
  11. {                   will crash the system.                   }
  12. {------------------------------------------------------------}
  13.  
  14. Interface
  15.  
  16. Uses DOS;                     { For interrupts and registers }
  17.  
  18. Const
  19.   MDD = $33;             { Interrupt for mouse device driver }
  20.  
  21. Type
  22.   resetRec = record        { Initialized by mouse function 0 }
  23.     exists   : Boolean;           { TRUE if mouse is present }
  24.     nButtons : integer;                 { # buttons on mouse }
  25.   End;
  26.  
  27.   locRec = record    { Initialized by mouse fcns 3, 5, and 6 }
  28.     buttonStatus,    { bits 0-2 on if corresp button is down }
  29.     opCount,               { # times button has been clicked }
  30.                              { opCount not returned by fcn 3 }
  31.     column,                                       { position }
  32.     row      : integer;
  33.   End;
  34.  
  35.   moveRec = record             { Initialized by mouse fcn 11 }
  36.     hCount,                        { net horizontal movement }
  37.     vCount : integer;                { net vertical movement }
  38.  End;
  39.  
  40. Var  Reg : Registers;
  41.  
  42. { These are the Microsoft mouse functions }
  43. Procedure mReset (var mouse : resetRec);       { function  0 }
  44. Procedure mShow;                               { function  1 }
  45. Procedure mHide;                               { function  2 }
  46. Procedure mPos (var mouse : locRec);           { function  3 }
  47. Procedure mMoveto (col, row : integer);        { function  4 }
  48. Procedure mPressed (button : integer;
  49.                     var mouse : locRec);       { function  5 }
  50. Procedure mReleased (button : integer;
  51.                     var mouse : locRec);       { function  6 }
  52. Procedure mColRange (min, max : integer);      { function  7 }
  53. Procedure mRowRange (min, max : integer);      { function  8 }
  54. Procedure mGraphCursor (hHot, vHot : integer;
  55.                    maskSeg, maskOfs : word);   { function  9 }
  56. Procedure mTextCursor (ctype, p1, p2 : word);  { function 10 }
  57. Procedure mMotion (var moved : moveRec);       { function 11 }
  58. Procedure mInstTask (mask,
  59.                      taskSeg, taskOfs : word); { function 12 }
  60. Procedure mLpenOn;                             { function 13 }
  61. Procedure mLpenOff;                            { function 14 }
  62. Procedure mRatio (horiz, vert : integer);      { function 15 }
  63. {------------------------------------------------------------}
  64.  
  65. IMPLEMENTATION
  66.  
  67. Function lower (n1, n2 : integer) : integer;  { Local to unit}
  68. Begin
  69.   If n1 < n2 then lower := n1
  70.   Else lower := n2;
  71. End;
  72.  
  73. Function upper (n1, n2 : integer) : integer;  { Local to unit}
  74. Begin
  75.   If n1 > n2 then upper := n1
  76.   Else upper := n2;
  77. End;
  78. { --------------------------- }
  79. Procedure mReset;        { Resets mouse to default condition }
  80. Begin
  81.   reg.ax := 0;
  82.   intr (MDD, reg);
  83.   if reg.ax <> 0 then
  84.     mouse.exists := TRUE
  85.   else
  86.     mouse.exists := FALSE;
  87.   mouse.nButtons := reg.bx;
  88. End;
  89. { --------------------------- }
  90. Procedure mShow;                 { Make mouse cursor visible }
  91. Begin
  92.   reg.ax := 1;
  93.   intr (MDD, reg);
  94. End;
  95. { --------------------------- }
  96. Procedure mHide;               { Make mouse cursor invisible }
  97. Begin
  98.   reg.ax := 2;
  99.   intr (MDD, reg);
  100. End;
  101. { --------------------------- }
  102. Procedure mPos;              { Get mouse status and position }
  103. Begin
  104.   reg.ax := 3;
  105.   intr (MDD, reg);
  106.   mouse.buttonStatus := reg.bx;
  107.   mouse.column := reg.cx;
  108.   mouse.row := reg.dx;
  109. End;
  110. { --------------------------- }
  111. Procedure mMoveto;       { Move mouse cursor to new location }
  112. Begin
  113.   reg.ax := 4;
  114.   reg.cx := col;
  115.   reg.dx := row;
  116.   intr (MDD, reg);
  117. End;
  118. { --------------------------- }
  119. Procedure mPressed;  { Get pressed info about a given button }
  120. Begin
  121.   reg.ax := 5;
  122.   reg.bx := button;
  123.   intr (MDD, reg);
  124.   mouse.buttonStatus := reg.ax;
  125.   mouse.opCount := reg.bx;
  126.   mouse.column := reg.cx;
  127.   mouse.row := reg.dx;
  128. End;
  129. { --------------------------- }
  130. Procedure mReleased;      { Get released info about a button }
  131. Begin
  132.   reg.ax := 6;
  133.   reg.bx := button;
  134.   intr (MDD, reg);
  135.   mouse.buttonStatus := reg.ax;
  136.   mouse.opCount := reg.bx;
  137.   mouse.column := reg.cx;
  138.   mouse.row := reg.dx;
  139. End;
  140. { --------------------------- }
  141. Procedure mColRange;            { Set column range for mouse }
  142. Begin
  143.   reg.ax := 7;
  144.   reg.cx := lower(min,max);
  145.   reg.dx := upper(min,max);
  146.   intr (MDD, reg);
  147. End;
  148. { --------------------------- }
  149. Procedure mRowRange;               { Set row range for mouse }
  150. Begin
  151.   reg.ax := 8;
  152.   reg.cx := lower(min,max);
  153.   reg.dx := upper(min,max);
  154.   intr (MDD, reg);
  155. End;
  156. { --------------------------- }
  157. Procedure mGraphCursor;          { Set mouse graphics cursor }
  158. Begin
  159.   reg.ax := 9;
  160.   reg.bx := hHot;
  161.   reg.cx := vHot;
  162.   reg.dx := maskOfs;
  163.   reg.es := maskSeg;
  164.   intr (MDD, reg);
  165. End;
  166. { --------------------------- }
  167. Procedure mTextCursor;               { Set mouse text cursor }
  168.  
  169.    { NOTES:                                            }
  170.    { Type 0 is the software cursor. When specified, p1 }
  171.    {   and p2 are the screen and cursor masks.         }
  172.    { Type 1 is the hardware cursor. When specified, p1 }
  173.    {   and p2 are the start and stop scan lines, i.e.  }
  174.    {   the cursor shape.                               }
  175.  
  176. Begin
  177.   reg.ax := 10;
  178.   reg.bx := ctype;
  179.   reg.cx := p1;
  180.   reg.dx := p2;
  181.   intr (MDD, reg);
  182. End;
  183. { --------------------------- }
  184. Procedure mMotion;   { Net movement of mouse since last call }
  185.                              { Expressed in mickeys (1/100") }
  186. Begin
  187.   reg.ax := 11;
  188.   intr (MDD, reg);
  189.   moved.hCount := reg.cx;
  190.   moved.vCount := reg.dx;
  191. End;
  192. { --------------------------- }
  193. Procedure mInstTask;             { Install user-defined task }
  194. Begin
  195.   reg.ax := 12;
  196.   reg.cx := mask;
  197.   reg.dx := taskOfs;
  198.   reg.es := taskSeg;
  199.   intr (MDD, reg);
  200. End;
  201. { --------------------------- }
  202. Procedure mLpenOn;   { Turn on light pen emulation (default) }
  203. Begin
  204.   reg.ax := 13;
  205.   intr (MDD, reg);
  206. End;
  207. { --------------------------- }
  208. Procedure mLpenOff;           { Turn off light pen emulation }
  209. Begin
  210.   reg.ax := 14;
  211.   intr (MDD, reg);
  212. End;
  213. { --------------------------- }
  214. Procedure mRatio;                { Set mickey to pixel ratio }
  215. Begin
  216.  
  217.    { NOTES:                                       }
  218.    { Ratios are R/8.                              }
  219.    { Default is 16 for vertical, 8 for horizontal }
  220.  
  221.   reg.ax := 15;
  222.   reg.cx := horiz;
  223.   reg.dx := vert;
  224.   intr (MDD, reg);
  225. End;
  226. { --------------------------- }
  227.  
  228. End.
  229.