home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / pascal / 5299 < prev    next >
Encoding:
Internet Message Format  |  1992-09-10  |  33.2 KB

  1. Path: sparky!uunet!dtix!darwin.sura.net!spool.mu.edu!news.cs.indiana.edu!nstn.ns.ca!dragon.acadiau.ca!890491g
  2. From: 890491g@dragon.acadiau.ca (Don Graves)
  3. Newsgroups: comp.lang.pascal
  4. Subject: mouse unit
  5. Message-ID: <1992Sep10.183625.10867@dragon.acadiau.ca>
  6. Date: 10 Sep 92 18:36:25 GMT
  7. Organization: Acadia University
  8. Lines: 976
  9.  
  10.  
  11.     Okay, here is the mouse unit I promised everyone who asked
  12. for it.  It is not the complete version, since some things weren't really
  13. needed and/or completed.  Anyway, have fun!
  14.  
  15.  
  16. {-----------------------------------------------------------------------------}
  17. Unit MouseGeneral;  (Version 1.0)
  18. ZDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD?
  19. 3  MICROSOFT MOUSE DRIVER ROUTINES FOR TURBO PASCAL 6.0  3
  20. @DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDY
  21. By: Don Graves (don.graves@dragon.acadiau.ca OR 890491g@ace.acadiau.ca)
  22.     Acadia University
  23.     Wolfville, N.S., Canada
  24.     BOP IXO
  25. Completed: August 3, 1992
  26. {-----------------------------------------------------------------------------}
  27. The following is a brief description of the functions, procedures, variables,
  28. and constants available to the user.
  29. These routines were made available for those who want to use the mouse in
  30. their applications but want to avoid the messy details of the Microsoft Mouse
  31. Interrupts.
  32.  
  33. REMEMBER:  When you include this unit in the USES clause, make sure that you
  34. spell out the whole unit name MouseGeneral, and not just MouseGen.
  35.  
  36. This is only a first release, so there might be errors in the way the
  37. routines behave.  I don't think there are any problems, but you never know.
  38. If anyone discovers any problems, then maybe I can correct them if I'm
  39. notified.
  40.  
  41. If you find this unit useful, then I am happy.  This unit is totally free and
  42. I give no guarantees or warrantees etc.  I welcome all comments/criticisms.
  43.  
  44. -Regards
  45.                                                         Don Graves
  46. {-----------------------------------------------------------------------------}
  47.  
  48. {---------------------------------}
  49. Interface
  50. {---------------------------------}
  51. Const
  52.     button_left: Byte = 1;    { Button state values.                          }
  53.     button_right: Byte = 2;   {                                               }
  54.     button_middle: Byte = 4;  {                                               }
  55.  
  56.     mousemoves_mask: Word = 1;     {------------------------------------------}
  57.     leftpress_mask: Word = 2;      { Handler masks - can be used in handler   }
  58.     leftrelease_mask: Word = 4;    { function parameters.                     }
  59.     rightpress_mask: Word = 8;     {                                          }
  60.     rightrelease_mask: Word = 16;  { Combinations can be used:                }
  61.     middlepress_mask: Word = 32;   { e.g. mousemoves_mask + rightpress_mask   }
  62.     middlerelease_mask: Word = 64; {------------------------------------------}
  63. {---------------------------------}
  64. Var
  65.     BUTTONS: Word; { Holds value for number of buttons present reported by    }
  66.                    { initialization (reset) of MS mouse driver.               }
  67.  
  68.     MOUSE_PRESENT: Boolean; { TRUE if MS mouse driver present.  FALSE if not. }
  69.  
  70.     MAX_X: Word;  { These four variables hold the coordinates to the window   }
  71.     MAX_Y: Word;  { area that is accessible to the mouse.  MIN_X and MAX_X    }
  72.     MIN_X: Word;  { hold the leftmost and rightmost coordinates, and MIN_Y    }
  73.     MIN_Y: Word;  { and MAX_Y hold the uppermost and lowermost coordinates.   }
  74.  
  75.     leftmousepressX: Word;    { Coordinates for where the last time the       }
  76.     leftmousepressY: Word;    { cooresponding mouse button was PRESSED (NOT   }
  77.     rightmousepressX: Word;   { DEPRESSED).  These values are updated every   }
  78.     rightmousepressY: Word;   { time the X_Button_Pressed() functions are     }
  79.     middlemousepressX: Word;  { invoked.                                      }
  80.     middlemousepressY: Word;  {
  81.  
  82.     leftmousedepressX: Word;    { Coordinates for where the last time the     }
  83.     leftmousedepressY: Word;    { cooresponding mouse button was DEPRESSED    }
  84.     rightmousedepressX: Word;   { (NOT PRESSED).  These values are updated    }
  85.     rightmousedepressY: Word;   { every time the X_Button_Depressed()         }
  86.     middlemousedepressX: Word;  { functions are invoked.                      }
  87.     middlemousedepressY: Word;  {
  88.  
  89.     leftmouseclickX: Word;    { Coordinates for where the last time the       }
  90.     leftmouseclickY: Word;    { cooresponding mouse button was used (NOT      }
  91.     rightmouseclickX: Word;   { PRESSED OR DEPRESSED).  These values are      }
  92.     rightmouseclickY: Word;   { updated every time the X_Button_Clicked()     }
  93.     middlemouseclickX: Word;  { functions are invoked.  Pressing and          }
  94.     middlemouseclickY: Word;  { depressing are not a factor.                  }
  95.  
  96.     hideleft: Word;    { Coordinates for the window where the mouse is meant  }
  97.     hidetop: Word;     { to be invisible.                                     }
  98.     hideright: Word;   {                                                      }
  99.     hidebottom: Word;  {                                                      }
  100.  
  101.     Xdisable: Word;  { Coordinate for where the mouse was when it was last    }
  102.     Ydisable: Word;  { disabled.                                              }
  103.  
  104.     eventX: Word;  { Coordinates for last user interrupt call according to    }
  105.     eventY: Word;  { the default handler.                                     }
  106.         { If you write your own interrupt handler routine, you may            }
  107.         { want to manipulate these four variables within it.                  }
  108.     eventstate: Word; { Button state from last call of default handler.       }
  109.     eventhappened: Boolean; { TRUE if event occurred, FALSE otherwise.        }
  110. {---------------------------------}
  111. Function ResetMouse: Boolean;
  112.     { Resets the mouse driver.  Returns TRUE if mouse driver installed, FALSE }
  113.     { otherwise.  It also initializes all the variables (coordinate, etc.).   }
  114.     { This routine is automatically called when MouseGeneral is included in   }
  115.     { the USES clause.                                                        }
  116.  
  117. Procedure SetMouseXRange (minx, maxx: Word);
  118.     { Makes it so that the mouse will be restricted to column coordinates X   }
  119.     { where minx <= X <= maxx.                                                }
  120.  
  121. Procedure SetMouseYRange (miny, maxy: Word);
  122.     { Makes it so that the mouse will be restricted to row coordinates Y      }
  123.     { where miny <= Y <= maxY.                                                }
  124.  
  125. Procedure SetMouseWindow (left, top, right, bottom: Word);
  126.     { Bounds the mouse cursor to a window by calling SetMouseXRange and      }
  127.     { SetMouseYRange.                                                        }
  128.  
  129. Procedure ShowMouse;
  130.     { Makes the mouse cursor visible.                                        }
  131.  
  132. Procedure HideMouse;
  133.     { Makes the mouse cursor invisible.                                      }
  134.  
  135. Function WhereMouseX: Word;
  136.     { Returns current X coordinate of mouse.                                 }
  137.  
  138. Function WhereMouseY: Word;
  139.     { Returns current Y coordinate of mouse.                                 }
  140.  
  141. Function Left_Button_Clicked: Boolean;
  142.     { Returns TRUE if the left button was clicked, and FALSE otherwise.      }
  143.  
  144. Function Right_Button_Clicked: Boolean;
  145.     { Returns TRUE if the right button was clicked, and FALSE otherwise.     }
  146.  
  147. Function Middle_Button_Clicked: Boolean;
  148.     { Returns TRUE if the middle button was clicked, and FALSE otherwise.    }
  149.  
  150. Function Left_Button_Pressed: Boolean;
  151.     { Returns TRUE if the left button was pressed, and FALSE otherwise.      }
  152.  
  153. Function Right_Button_Pressed: Boolean;
  154.     { Returns TRUE if the right button was pressed, and FALSE otherwise.     }
  155.  
  156. Function Middle_Button_Pressed: Boolean;
  157.     { Returns TRUE if the middle button was pressed, and FALSE otherwise.    }
  158.  
  159. Function Left_Button_Depressed: Boolean;
  160.     { Returns TRUE if the left button was depressed, and FALSE otherwise.    }
  161.  
  162. Function Right_Button_Depressed: Boolean;
  163.     { Returns TRUE if the right button was depressed, and FALSE otherwise.   }
  164.  
  165. Function Middle_Button_Depressed: Boolean;
  166.     { Returns TRUE if the middle button was depressed, and FALSE otherwise.  }
  167.  
  168. Procedure PositionMouseCursor (x, y: Word);
  169.     { Positions the mouse on the screen at (x,y).                            }
  170.  
  171. Procedure SetMousePage (pg: Integer);
  172.     { Sets the mouse display page.                                           }
  173.  
  174. Function GetMousePage: Integer;
  175.     { Returns the current mouse display page.                                }
  176.  
  177. Function MouseMoved (fromx, fromy: Word;
  178.                      Var distanceX, distanceY: Integer): Boolean;
  179.     { Returns TRUE if the mouse is not at (fromx, fromy) and returns FALSE   }
  180.     { otherwise.  The distance between WhereMouseX and 'fromx' is returned   }
  181.     { through 'distanceX'.  The distance between WhereMouseY and 'fromy' is  }
  182.     { returned through 'distanceY'.                                          }
  183.  
  184. Procedure SetDoubleSpeedThreshold (mickeyspersecond: Word);
  185.     { Sets the double-speed threshold of the mouse in mickeys per second.    }
  186.     { The normal and default value is 64.                                    }
  187.  
  188. Procedure SetMouseSensitivity (hspeed, vspeed, dspeedthres: Word);
  189.     { Procedure to set the sensitivity of the mouse.  'hspeed' is horizontal }
  190.     { speed, 'vspeed' is vertical speed, and 'dspeedthres' is double-speed   }
  191.     { threshold.                                                             }
  192.  
  193. Procedure GetMouseSensitivity (Var hspeed, vspeed, dspeedthres: Word);
  194.     { Returns through parameters the mouse sensitivity.                      }
  195.  
  196. Procedure SetMickeyPixelRatio (hmpp, vmpp: Word);
  197.     { Sets the horizontal and vertical mickeys per pixel ratios.             }
  198.  
  199. Procedure SetSWTextMCursor (backcolor, forecolor: Byte; charac: Char);
  200.     { Changes the cursor and attributes of the mouse cursor.                 }
  201.     {                                                                        }
  202.     { SetSWTextMCursor (RED, YELLOW, 'P') will make a yellow 'P' on top of a }
  203.     { red background.                                                        }
  204.     { SetSWTextMCursor (RED, YELLOW+BLINK, will make the 'P' blink.          }
  205.  
  206. Procedure SetHWTextMCursor (startscanline, stopscanline: Word);
  207.     { Sets the hardware scanlines for the mouse.  Values are 0..7 for color  }
  208.     { adapters and 0..12 for monochrome.                                     }
  209.  
  210. Procedure NormalTextMCursor;
  211.     { Restores the normal mouse text cursor.                                 }
  212.  
  213. Procedure SetGraphicMCursor (hotx, hoty: ShortInt; mousepointerdata: Pointer);
  214.     { Sets the graphics cursor in graphics mode.  'hotx' and 'hoty'          }
  215.     { represent the part of the cursor that is relevant for defining cursor  }
  216.     { location.    (-16 - 16)                                                }
  217.     { 'mousepointerdata' is a pointer to an array of 32 words.  The first 16 }
  218.     { words represent the mouse cursor and the second 16 words represent the }
  219.     { screen mask.  Ex.:                                                     }
  220.     { SetGraphicMCursor (1, 1, @mycursor)                                    }
  221.  
  222. Procedure SetLargeGraphicMCursor (hotx, hoty: ShortInt; xsize, ysize: Word;
  223.                                   biggraphicmouse: Pointer);
  224.     { Same as above, except you can use large cursors.                       }
  225.     { 'xsize' and 'ysize' represent the rows and cols in the cursor.         }
  226.     { 'biggraphicmouse' is a pointer to a bitmap of screen and cursor maps.  }
  227.  
  228. Procedure LightPenEmulationOn;
  229.     { Turns on light pen emulation.                                          }
  230.  
  231. Procedure LightPenEmulationOff;
  232.     { Turns off light pen emulation.                                         }
  233.  
  234. Procedure DisableMouseDriver;
  235.     { Disables the mouse driver.                                             }
  236.  
  237. Procedure EnableMouseDriver;
  238.     { Enables the mouse driver and places it where it was diabled.           }
  239.  
  240. Procedure SoftwareResetMouse;
  241.     { Initializes (does not reset) the mouse driver.                         }
  242.  
  243. Function GetMouseDriverStorage: Word;
  244.     { Returns the storage requirements for the mouse driver state.           }
  245.  
  246. Procedure SaveMouseDriverState (driversize: Word; driverstate: Pointer);
  247.     { Saves the mouse driver state.  'driversize' is the size buffer size    }
  248.     { for saving the driver information in bytes.                            }
  249.     { 'driverstate' is a pointer to this buffer.                             }
  250.     { Use GetMouseDriverStorage to determine 'driversize'.                   }
  251.  
  252. Procedure RestoreMouseDriverState (driversize: Word; driverstate: Pointer);
  253.     { Restores the mouse driver state pointed to by 'driverstate'.           }
  254.  
  255. Procedure SetMouseAcceleration (accprofile: Byte);
  256.     { Sets the acceleration profile (1-4).                                   }
  257.  
  258. Procedure SetHideRegion (left, top, right, bottom: Word);
  259.     { Defines the region for the mouse to be invisible.                      }
  260.  
  261. Procedure SetInterruptHandler (mask: Word; handler: Pointer);
  262.     { Sets up an interrupt handler routine for the mouse.                    }
  263.  
  264. Procedure SetDefaultHandler (mask: Word);
  265.     { Sets the default handler.                                              }
  266.  
  267. Function GetLastEvent (Var evx, evy, evstate: Word): Boolean;
  268.     { Returns TRUE if the event handler was invoked and FALSE otherwise.     }
  269.     { It uses the EVENT variables (described above).                         }
  270.  
  271. Procedure SwapInterruptHandlers (newhandler: Pointer; newmask: Word;
  272.                                  Var oldhandler: Pointer; oldmask: Word);
  273.     { Swaps interrupt handler routines.                                      }
  274. {-----------------------------------------------------------------------------}
  275.  
  276.  
  277.  
  278.  
  279.  
  280. ------------------------------ UNIT STARTS HERE ------------------------------
  281.  
  282. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  283. Unit MouseGeneral;
  284. { By: Don Graves of Acadia University, Wolfville, N.S., Canada              }
  285. { Completed: August 3, 1992                                                 }
  286. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  287. Interface
  288. {---------------------------------}
  289. Uses Dos;
  290. {---------------------------------}
  291. Const
  292.     button_left: Byte = 1;
  293.     button_right: Byte = 2;
  294.     button_middle: Byte = 4;
  295.     mousemoves_mask: Word = 1;
  296.     leftpress_mask: Word = 2;
  297.     leftrelease_mask: Word = 4;
  298.     rightpress_mask: Word = 8;
  299.     rightrelease_mask: Word = 16;
  300.     middlepress_mask: Word = 32;
  301.     middlerelease_mask: Word = 64;
  302. {---------------------------------}
  303. Var BUTTONS: Word;
  304.     MOUSE_PRESENT: Boolean;
  305.     MAX_X, MAX_Y, MIN_X, MIN_Y: Word;
  306.     leftmousepressX, leftmousepressY: Word;
  307.     leftmouseclickX, leftmouseclickY: Word;
  308.     leftmousedepressX, leftmousedepressY: Word;
  309.     rightmousepressX, rightmousepressY: Word;
  310.     rightmouseclickX, rightmouseclickY: Word;
  311.     rightmousedepressX, rightmousedepressY: Word;
  312.     middlemousepressX, middlemousepressY: Word;
  313.     middlemouseclickX, middlemouseclickY: Word;
  314.     middlemousedepressX, middlemousedepressY: Word;
  315.     hideleft, hidetop, hideright, hidebottom: Word;
  316.     Xdisable, Ydisable: Word;
  317.     eventX, eventY: Word;
  318.     eventstate: Word;
  319.     eventhappened: Boolean;
  320. {---------------------------------}
  321. Function ResetMouse: Boolean;
  322. Procedure SetMouseXRange (minx, maxx: Word);
  323. Procedure SetMouseYRange (miny, maxy: Word);
  324. Procedure SetMouseWindow (left, top, right, bottom: Word);
  325. Procedure ShowMouse;
  326. Procedure HideMouse;
  327. Function WhereMouseX: Word;
  328. Function WhereMouseY: Word;
  329. Function MouseMoved (fromx, fromy: Word; Var distanceX, distanceY: Integer): Boolean;
  330. Function Left_Button_Clicked: Boolean;
  331. Function Right_Button_Clicked: Boolean;
  332. Function Middle_Button_Clicked: Boolean;
  333. Function Left_Button_Pressed: Boolean;
  334. Function Right_Button_Pressed: Boolean;
  335. Function Middle_Button_Pressed: Boolean;
  336. Function Left_Button_Depressed: Boolean;
  337. Function Right_Button_Depressed: Boolean;
  338. Function Middle_Button_Depressed: Boolean;
  339. Procedure PositionMouseCursor (x, y: Word);
  340. Procedure SetMousePage (pg: Integer);
  341. Function GetMousePage: Integer;
  342. Procedure SetDoubleSpeedThreshold (mickeyspersecond: Word);
  343. Procedure SetMouseSensitivity (hspeed, vspeed, dspeedthres: Word);
  344. Procedure GetMouseSensitivity (Var hspeed, vspeed, dspeedthres: Word);
  345. Procedure SetMickeyPixelRatio (hmpp, vmpp: Word);
  346. Procedure SetSWTextMCursor (backcolor, forecolor: Byte; charac: Char);
  347. Procedure SetHWTextMCursor (startscanline, stopscanline: Word);
  348. Procedure NormalTextMCursor;
  349. Procedure SetGraphicMCursor (hotx, hoty: ShortInt; mousepointerdata: Pointer);
  350. Procedure SetWatchCursor;
  351. Procedure SetNormalArrowCursor;
  352. Procedure SetUpArrowCursor;
  353. Procedure SetLeftArrowCursor;
  354. Procedure SetCheckMarkCursor;
  355. Procedure SetPointingHandCursor;
  356. Procedure SetDiagonalCrossCursor;
  357. Procedure SetRectangularCrossCursor;
  358. Procedure SetHourglassCursor;
  359. Procedure SetNewWatchCursor;
  360. Procedure SetLargeGraphicMCursor (hotx, hoty: ShortInt; xsize, ysize: Word; biggraphicmouse: Pointer);
  361. Procedure LightPenEmulationOn;
  362. Procedure LightPenEmulationOff;
  363. Procedure DisableMouseDriver;
  364. Procedure EnableMouseDriver;
  365. Procedure SoftwareResetMouse;
  366. Function GetMouseDriverStorage: Word;
  367. Procedure SaveMouseDriverState (driversize: Word; driverstate: Pointer);
  368. Procedure RestoreMouseDriverState (driversize: Word; driverstate: Pointer);
  369. Procedure SetMouseAcceleration (accprofile: Byte);
  370. Procedure SetHideRegion (left, top, right, bottom: Word);
  371. Procedure SetInterruptHandler (mask: Word; handler: Pointer);
  372. Procedure SetDefaultHandler (mask: Word);
  373. Function GetLastEvent (Var evx, evy, evstate: Word): Boolean;
  374. Procedure SwapInterruptHandlers (newhandler: Pointer; newmask: Word; Var oldhandler: Pointer; oldmask: Word);
  375. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  376. Implementation
  377. {---------------------------------}
  378. Var regs: Registers;
  379.     show_hide: Integer;
  380. {---------------------------------}
  381. Procedure SetInterruptHandler (mask: Word; handler: Pointer);
  382. Begin
  383.     If (MOUSE_PRESENT) Then
  384.     Begin
  385.         regs.ax := $000C;
  386.         regs.cx := mask;
  387.         regs.es := Seg (handler^);
  388.         regs.dx := Ofs (handler^);
  389.         Intr ($33, regs);
  390.     End;
  391. End;
  392. {---------------------------------}
  393. {$F+} Procedure DefaultHandler; assembler; {$F-}
  394. Asm
  395.     push ds; { save TP mouse driver }
  396.     mov ax, SEG @data;
  397.     mov ds, ax; { ds = TP:ds, not the driver's ds }
  398.     mov eventX, cx; { where in the x region did it occur }
  399.     mov eventY, dx;
  400.     mov eventstate, bx;
  401.     mov eventhappened, 1; { eventHapppened := true }
  402.     pop ds; { restore driver's ds }
  403.     ret;
  404. End;
  405. {---------------------------------}
  406. Procedure SetDefaultHandler (mask: Word);
  407. Begin
  408.     SetInterruptHandler (mask, @DefaultHandler);
  409. End;
  410. {---------------------------------}
  411. Function GetLastEvent (Var evx, evy, evstate: Word): Boolean;
  412. Var gle: Boolean;
  413. Begin
  414.     gle := eventhappened;
  415.     eventhappened := FALSE;
  416.     If (gle) Then
  417.     Begin
  418.         evx := eventX;
  419.         evy := eventY;
  420.         eventstate := evstate;
  421.     End;
  422.     GetLastEvent := gle;
  423. End;
  424. {---------------------------------}
  425. Procedure SwapInterruptHandlers (newhandler: Pointer; newmask: Word; Var oldhandler: Pointer; oldmask: Word);
  426. begin
  427.     If (MOUSE_PRESENT) Then
  428.     Begin
  429.         regs.ax := $0014;
  430.         regs.cx := newmask;
  431.         regs.es := Seg (newhandler^);
  432.         regs.dx := Ofs (newhandler^);
  433.         Intr ($33, regs);
  434.         oldmask := regs.cx;
  435.         oldhandler := Ptr (regs.es, regs.dx);
  436.     End;
  437. End;
  438. {---------------------------------}
  439. Procedure SetHideRegion (left, top, right, bottom: Word);
  440. Begin
  441.     If (MOUSE_PRESENT) Then
  442.     Begin
  443.         hideleft := left;
  444.         hidetop := top;
  445.         hideright := right;
  446.         hidebottom := bottom;
  447.         regs.ax := $0010;
  448.         regs.cx := left;
  449.         regs.dx := top;
  450.         regs.si := right;
  451.         regs.di := bottom;
  452.         Intr ($33, regs);
  453.     End;
  454. End;
  455. {---------------------------------}
  456. Procedure SetMouseAcceleration (accprofile: Byte);
  457. Begin
  458.     If (MOUSE_PRESENT) Then
  459.     Begin
  460.         regs.ax := $002D;
  461.         regs.bx := accprofile;
  462.         Intr ($33, regs);
  463.     End;
  464. End;
  465. {---------------------------------}
  466. Function GetMouseDriverStorage: Word;
  467. Var sz: Word;
  468. Begin
  469.     sz := 0;
  470.     If (MOUSE_PRESENT) Then
  471.     Begin
  472.         regs.ax := $0015;
  473.         Intr ($33, regs);
  474.         sz := regs.bx;
  475.     End;
  476.     GetMouseDriverStorage := sz;
  477. End;
  478. {---------------------------------}
  479. Procedure SaveMouseDriverState (driversize: Word; driverstate: Pointer);
  480. Begin
  481.     If (MOUSE_PRESENT) Then
  482.     Begin
  483.         regs.ax := $0016;
  484.         regs.bx := driversize;
  485.         regs.es := Seg (driverstate^);
  486.         regs.dx := Ofs (driverstate^);
  487.         Intr ($33, regs);
  488.     End;
  489. End;
  490. {---------------------------------}
  491. Procedure RestoreMouseDriverState (driversize: Word; driverstate: Pointer);
  492. Begin
  493.     If (MOUSE_PRESENT) Then
  494.     Begin
  495.         regs.ax := $0017;
  496.         regs.bx := driversize;
  497.         regs.es := Seg (driverstate^);
  498.         regs.dx := Ofs (driverstate^);
  499.         Intr ($33, regs);
  500.     End;
  501. End;
  502. {---------------------------------}
  503. Procedure DisableMouseDriver;
  504. Begin
  505.     If (MOUSE_PRESENT) Then
  506.     Begin
  507.         Xdisable := WhereMouseX;
  508.         Ydisable := WhereMouseY;
  509.         regs.ax := $001F;
  510.         Intr ($33, regs);
  511.     End;
  512. End;
  513. {---------------------------------}
  514. Procedure EnableMouseDriver;
  515. Begin
  516.     If (MOUSE_PRESENT) Then
  517.     Begin
  518.         regs.ax := $0020;
  519.         Intr ($33, regs);
  520.         PositionMouseCursor (Xdisable, Ydisable);
  521.     End;
  522. End;
  523. {---------------------------------}
  524. Procedure SoftwareResetMouse;
  525. Begin
  526.     If (MOUSE_PRESENT) Then
  527.     Begin
  528.         regs.ax := $0021;
  529.         Intr ($33, regs);
  530.     End;
  531. End;
  532. {---------------------------------}
  533. Procedure LightPenEmulationOn;
  534. Begin
  535.     If (MOUSE_PRESENT) Then
  536.     Begin
  537.         regs.ax := $000D;
  538.         Intr ($33, regs);
  539.     End;
  540. End;
  541. {---------------------------------}
  542. Procedure LightPenEmulationOff;
  543. Begin
  544.     If (MOUSE_PRESENT) Then
  545.     Begin
  546.         regs.ax := $000E;
  547.         Intr ($33, regs);
  548.     End;
  549. End;
  550. {---------------------------------}
  551. Procedure SetLargeGraphicMCursor (hotx, hoty: ShortInt; xsize, ysize: Word; biggraphicmouse: Pointer);
  552. Begin
  553.     If (MOUSE_PRESENT) Then
  554.     Begin
  555.         regs.ax := $0012;
  556.         regs.bh := xsize;
  557.         regs.ch := ysize;
  558.         regs.bl := hotx;
  559.         regs.cl := hoty;
  560.         regs.dx := Ofs (biggraphicmouse^);
  561.         regs.es := Seg (biggraphicmouse^);
  562.         Intr ($33, regs);
  563.     End;
  564. End;
  565. {---------------------------------}
  566. Procedure SetGraphicMCursor (hotx, hoty: ShortInt; mousepointerdata: Pointer);
  567. Begin
  568.     If (MOUSE_PRESENT) Then
  569.     Begin
  570.         regs.ax := $0009;
  571.         regs.bx := hotx;
  572.         regs.cx := hoty;
  573.         regs.dx := Ofs (mousepointerdata^);
  574.         regs.es := Seg (mousepointerdata^);
  575.         Intr ($33, regs);
  576.     End;
  577. End;
  578. {---------------------------------}
  579. Procedure SetHWTextMCursor (startscanline, stopscanline: Word);
  580. Begin
  581.     If (MOUSE_PRESENT) Then
  582.     Begin
  583.         regs.ax := $000A;
  584.         regs.bx := 1;
  585.         regs.cx := startscanline;
  586.         regs.dx := stopscanline;
  587.         Intr ($33, regs);
  588.     End;
  589. End;
  590. {---------------------------------}
  591. Procedure SetSWTextMCursor (backcolor, forecolor: Byte; charac: Char);
  592. Begin
  593.     If (MOUSE_PRESENT) Then
  594.     Begin
  595.         regs.ax := $000A;
  596.         regs.bx := 0;
  597.         regs.cl := 0;
  598.         regs.ch := 0;
  599.         regs.dh := backcolor*16+forecolor;
  600.         regs.dl := Ord (charac);
  601.         Intr ($33, regs);
  602.     End;
  603. End;
  604. {---------------------------------}
  605. Procedure NormalTextMCursor;
  606. Begin
  607.     If (MOUSE_PRESENT) Then
  608.     Begin
  609.         regs.ax := $000A;
  610.         regs.bx := 0;
  611.         regs.cl := $FF;
  612.         regs.ch := $FF;
  613.         regs.dl := $00;
  614.         regs.dh := $77;
  615.         Intr ($33, regs);
  616.      End;
  617. End;
  618. {---------------------------------}
  619. Procedure SetMickeyPixelRatio (hmpp, vmpp: Word);
  620. Begin
  621.     If ((MOUSE_PRESENT) And (hmpp > 0) And (vmpp > 0)) Then
  622.     Begin
  623.         regs.ax := $000F;
  624.         regs.cx := hmpp;
  625.         regs.dx := vmpp;
  626.         Intr ($33, regs);
  627.     End;
  628. End;
  629. {---------------------------------}
  630. Procedure SetDoubleSpeedThreshold (mickeyspersecond: Word);
  631. Begin
  632.     If (MOUSE_PRESENT) Then
  633.     Begin
  634.         regs.ax := $0013;
  635.         regs.dx := mickeyspersecond;
  636.         Intr ($33, regs);
  637.     End;
  638. End;
  639. {---------------------------------}
  640. Procedure SetMouseSensitivity (hspeed, vspeed, dspeedthres: Word);
  641. Begin
  642.     If (MOUSE_PRESENT) Then
  643.     Begin
  644.         regs.ax := $001A;
  645.         regs.bx := hspeed;
  646.         regs.cx := vspeed;
  647.         regs.dx := dspeedthres;
  648.         Intr ($33, regs);
  649.     End;
  650. End;
  651. {---------------------------------}
  652. Procedure GetMouseSensitivity (Var hspeed, vspeed, dspeedthres: Word);
  653. Begin
  654.     If (MOUSE_PRESENT) Then
  655.     Begin
  656.         regs.ax := $001B;
  657.         Intr ($33, regs);
  658.         hspeed := regs.bx;
  659.         vspeed := regs.cx;
  660.         dspeedthres := regs.dx;
  661.     End;
  662. End;
  663. {---------------------------------}
  664. Function ResetMouse: Boolean;
  665. Begin
  666.     regs.ax := $0000;
  667.     Intr ($33, regs);
  668.     BUTTONS := regs.bx;
  669.     MOUSE_PRESENT := (regs.ax = $FFFF);
  670.     show_hide := 0; {0 = mouse not displayed, 1 = mouse displayed}
  671.     MIN_X := 0;
  672.     MIN_Y := 0;
  673.     MAX_X := 79*8;
  674.     MAX_Y := 24*8;
  675.     leftmousepressX := 0;       leftmousepressY := 0;
  676.     leftmousedepressX := 0;     leftmousedepressY := 0;
  677.     middlemousepressX := 0;     middlemousepressY := 0;
  678.     middlemousedepressX := 0;   middlemousedepressY := 0;
  679.     rightmousepressX := 0;      rightmousepressY := 0;
  680.     rightmousedepressX := 0;    rightmousedepressY := 0;
  681.     leftmouseclickX := 0;       leftmouseclickY := 0;
  682.     middlemouseclickX := 0;     middlemouseclickY := 0;
  683.     rightmouseclickX := 0;      rightmouseclickY := 0;
  684.     hideleft := 0;              hidetop := 0;
  685.     hideright := 0;             hidebottom := 0;
  686.     Xdisable := 0;              Ydisable := 0;
  687.     eventX := 0;                eventY := 0;
  688.     eventstate := 0;
  689.     eventhappened := FALSE;
  690.     ResetMouse := (regs.ax = $FFFF);
  691. End;
  692. {---------------------------------}
  693. Function MouseMoved (fromx, fromy: Word; Var distanceX, distanceY: Integer): Boolean;
  694. Var mvd: Boolean;
  695.     wx, wy: Integer;
  696. Begin
  697.     mvd := FALSE;
  698.     distanceX := WhereMouseX - fromx;
  699.     distanceY := WhereMouseY - fromy;
  700.     If ((distanceX <> 0) Or (distanceY <> 0)) Then
  701.         mvd := TRUE;
  702.     MouseMoved := mvd;
  703. End;
  704. {---------------------------------}
  705. Function WhereMouseX: Word;
  706. Var wmx: Word;
  707. Begin
  708.     wmx := 0;
  709.     If (MOUSE_PRESENT) Then
  710.     Begin
  711.         regs.ax := $0003;
  712.         Intr ($33, regs);
  713.         wmx := regs.cx;
  714.     End;
  715.     WhereMouseX := wmx;
  716. End;
  717. {---------------------------------}
  718. Function WhereMouseY: Word;
  719. Var wmy: Word;
  720. Begin
  721.     wmy := 0;
  722.     If (MOUSE_PRESENT) Then
  723.     Begin
  724.         regs.ax := $0003;
  725.         Intr ($33, regs);
  726.         wmy := regs.dx;
  727.     End;
  728.     WhereMouseY := wmy;
  729. End;
  730. {---------------------------------}
  731. Function Middle_Button_Clicked: Boolean;
  732. Var mclicked: Boolean;
  733. Begin
  734.     mclicked := FALSE;
  735.     If ((MOUSE_PRESENT) And (BUTTONS = 3)) Then
  736.     Begin
  737.         regs.ax := $0003;
  738.         Intr ($33, regs);
  739.         mclicked := ((regs.bx And 4) = 4);
  740.         middlemouseclickX := regs.cx;
  741.         middlemouseclickY := regs.dx;
  742.     End;
  743.     Middle_Button_Clicked := mclicked;
  744. End;
  745. {---------------------------------}
  746. Function Left_Button_Clicked: Boolean;
  747. Var lclicked: Boolean;
  748. Begin
  749.     lclicked := FALSE;
  750.     If (MOUSE_PRESENT) Then
  751.     Begin
  752.         regs.ax := $0003;
  753.         Intr ($33, regs);
  754.         lclicked := ((regs.bx And 1) = 1);
  755.         leftmouseclickX := regs.cx;
  756.         leftmouseclickY := regs.dx;
  757.     End;
  758.     Left_Button_Clicked := lclicked;
  759. End;
  760. {---------------------------------}
  761. Function Right_Button_Clicked: Boolean;
  762. Var rclicked: Boolean;
  763. Begin
  764.     rclicked := FALSE;
  765.     If (MOUSE_PRESENT) Then
  766.     Begin
  767.         regs.ax := $0003;
  768.         Intr ($33, regs);
  769.         rclicked := ((regs.bx And 2) = 2);
  770.         rightmouseclickX := regs.cx;
  771.         rightmouseclickY := regs.dx;
  772.     End;
  773.     Right_Button_Clicked := rclicked;
  774. End;
  775. {---------------------------------}
  776. Procedure ShowMouse;
  777. Begin
  778.     If ((MOUSE_PRESENT) And (show_hide <> 1)) Then
  779.     Begin
  780.         Repeat
  781.             regs.ax := $0001;
  782.             Intr ($33, regs);
  783.             Inc (show_hide, 1);
  784.         Until (show_hide = 1);
  785.     End;
  786. End;
  787. {---------------------------------}
  788. Procedure HideMouse;
  789. Begin
  790.     If ((MOUSE_PRESENT) And (show_hide <> 0)) Then
  791.     Begin
  792.         Repeat
  793.             regs.ax := $0002;
  794.             Intr ($33, regs);
  795.             Dec (show_hide, 1);
  796.         Until (show_hide = 0);
  797.     End;
  798. End;
  799. {---------------------------------}
  800. Procedure PositionMouseCursor (x, y: Word);
  801. Begin
  802.     If ((MOUSE_PRESENT) And
  803.         (x >= MIN_X) And (x <= MAX_X) AND
  804.         (y >= MIN_Y) And (y <= MAX_Y)) Then
  805.     Begin
  806.         regs.ax := $0004;
  807.         regs.cx := x;
  808.         regs.dx := y;
  809.         Intr ($33, regs);
  810.     End;
  811. End;
  812. {---------------------------------}
  813. Procedure SetMousePage (pg: Integer);
  814. Begin
  815.     If ((MOUSE_PRESENT) And (pg >=0)) Then
  816.     Begin
  817.         regs.ax := $001D;
  818.         regs.bx := pg;
  819.         Intr ($33, regs);
  820.     End;
  821. End;
  822. {---------------------------------}
  823. Function GetMousePage: Integer;
  824. Var pg: Integer;
  825. Begin
  826.     pg := 0;
  827.     If (MOUSE_PRESENT) Then
  828.     Begin
  829.         regs.ax := $001E;
  830.         pg := regs.bx;
  831.         Intr ($33, regs);
  832.     End;
  833.     GetMousePage := pg;
  834. End;
  835. {---------------------------------}
  836. Procedure SetMouseWindow (left, top, right, bottom: Word);
  837. Begin
  838.     If (MOUSE_PRESENT) Then
  839.     Begin
  840.         SetMouseXRange (left, right);
  841.         SetMouseYRange (top, bottom);
  842.         PositionMouseCursor (MIN_X, MIN_Y);
  843.     End;
  844. End;
  845. {---------------------------------}
  846. Procedure SetMouseXRange (minx, maxx: Word);
  847. Begin
  848.     If (MOUSE_PRESENT) Then
  849.         If ((minx < maxx) And (minx >= 0)) Then
  850.         Begin
  851.             regs.ax := $0007;
  852.             regs.cx := minx;
  853.             regs.dx := maxx;
  854.             Intr ($33, regs);
  855.             MIN_X := minx;
  856.             MAX_X := maxx;
  857.         End;
  858. End;
  859. {---------------------------------}
  860. Procedure SetMouseYRange (miny, maxy: Word);
  861. Begin
  862.     If (MOUSE_PRESENT) Then
  863.         If ((miny < maxy) And (miny >= 0)) Then
  864.         Begin
  865.             regs.ax := $0008;
  866.             regs.cx := miny;
  867.             regs.dx := maxy;
  868.             Intr ($33, regs);
  869.             MIN_Y := miny;
  870.             MAX_Y := maxy;
  871.         End;
  872. End;
  873. {---------------------------------}
  874. Function Left_Button_Pressed: Boolean;
  875. Var lpressed: Boolean;
  876. Begin
  877.     lpressed := FALSE;
  878.     If (MOUSE_PRESENT) Then
  879.     Begin
  880.         regs.ax := $0005;
  881.         regs.bx := $0000;
  882.         Intr ($33, regs);
  883.         leftmousepressX := regs.cx;
  884.         leftmousepressY := regs.dx;
  885.         lpressed := ((regs.ax And button_left) = button_left);
  886.     End;
  887.     Left_Button_Pressed := lpressed;
  888. End;
  889. {---------------------------------}
  890. Function Right_Button_Pressed: Boolean;
  891. Var rpressed: Boolean;
  892. Begin
  893.     rpressed := FALSE;
  894.     If (MOUSE_PRESENT) Then
  895.     Begin
  896.         regs.ax := $0005;
  897.         regs.bx := $0001;
  898.         Intr ($33, regs);
  899.         rightmousepressX := regs.cx;
  900.         rightmousepressY := regs.dx;
  901.         rpressed := ((regs.ax And button_right) = button_right);
  902.     End;
  903.     Right_Button_Pressed := rpressed;
  904. End;
  905. {---------------------------------}
  906. Function Middle_Button_Pressed: Boolean;
  907. Var mpressed: Boolean;
  908. Begin
  909.     mpressed := FALSE;
  910.     If ((MOUSE_PRESENT) And (BUTTONS = 3)) Then
  911.     Begin
  912.         regs.ax := $0005;
  913.         regs.bx := $0002;
  914.         Intr ($33, regs);
  915.         middlemousepressX := regs.cx;
  916.         middlemousepressY := regs.dx;
  917.         mpressed := ((regs.ax And button_middle) = button_middle);
  918.     End;
  919.     Middle_Button_Pressed := mpressed;
  920. End;
  921. {---------------------------------}
  922. Function Left_Button_Depressed: Boolean;
  923. Var ldpressed: Boolean;
  924. Begin
  925.     ldpressed := FALSE;
  926.     If (MOUSE_PRESENT) Then
  927.     Begin
  928.         regs.ax := $0006;
  929.         regs.bx := $0000;
  930.         Intr ($33, regs);
  931.         leftmousedepressX := regs.cx;
  932.         leftmousedepressY := regs.dx;
  933.         ldpressed := Not ((regs.ax And button_left) = button_left);
  934.     End;
  935.     Left_Button_Depressed := ldpressed;
  936. End;
  937. {---------------------------------}
  938. Function Right_Button_Depressed: Boolean;
  939. Var rdpressed: Boolean;
  940. Begin
  941.     rdpressed := FALSE;
  942.     If (MOUSE_PRESENT) Then
  943.     Begin
  944.         regs.ax := $0006;
  945.         regs.bx := $0001;
  946.         Intr ($33, regs);
  947.         rightmousedepressX := regs.cx;
  948.         rightmousedepressY := regs.dx;
  949.         rdpressed := Not ((regs.ax And button_right) = button_right);
  950.     End;
  951.     Right_Button_Depressed := rdpressed;
  952. End;
  953. {---------------------------------}
  954. Function Middle_Button_Depressed: Boolean;
  955. Var mdpressed: Boolean;
  956. Begin
  957.     mdpressed := FALSE;
  958.     If ((MOUSE_PRESENT) And (BUTTONS = 3)) Then
  959.     Begin
  960.         regs.ax := $0006;
  961.         regs.bx := $0002;
  962.         Intr ($33, regs);
  963.         middlemousedepressX := regs.cx;
  964.         middlemousedepressY := regs.dx;
  965.         mdpressed := Not ((regs.ax And button_middle) = button_middle);
  966.     End;
  967.     Middle_Button_Depressed := mdpressed;
  968. End;
  969. {---------------------------------}
  970. { Procedure HerculesCheck; }
  971. { NOT IMPLEMENTED PROPERLY - maybe someone can do this for me }
  972. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  973. Begin
  974. {    HerculesCheck;}
  975.     MOUSE_PRESENT := ResetMouse;
  976.     HideMouse;
  977.     PositionMouseCursor (0, 0);
  978. End.
  979. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  980. ------------------------------ UNIT ENDS HERE --------------------------------
  981. -- 
  982. --
  983. Don Graves
  984. Acadia University, Wolfville, N.S. Canada
  985. don.graves@dragon.acadiau.ca || 890491g@ace.acadiau.ca
  986.