home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / SNIP9404.ZIP / MOUSE.C < prev    next >
C/C++ Source or Header  |  1994-04-03  |  9KB  |  353 lines

  1. /*
  2. ** A series of routines to provide access to MicroSoft (and compatible)
  3. ** mice.  Consult your mouse documentation for detailed information regarding
  4. ** each mouse driver function.
  5. **
  6. ** by Bob Jarvis w/ modifications by Bob Stout
  7. */
  8.  
  9. #include <dos.h>
  10. #include "mouse.h"
  11.  
  12. int mouse_present = 0;  /* globally visible */
  13.  
  14. /*
  15. ** Uses driver function 0 to initialize the mouse software to its default
  16. ** settings.  If no mouse is present it returns 0.  If a mouse is present, it
  17. ** returns -1, and places the value of the mouse type (2 = MicroSoft,
  18. ** 3 = Mouse Systems, other values are possible) in *mousetype.  Also
  19. ** initializes the global variable mouse_present (0 = no mouse, !0 = mouse
  20. ** is available).
  21. */
  22.  
  23. int ms_reset(int *mousetype)
  24. {
  25.       union REGS workregs;
  26.       struct SREGS sregs;
  27.  
  28.       /* check the vector     */
  29.  
  30.       segread (&sregs);
  31.       workregs.h.ah = 0x35;     /* DOS get vector */
  32.       workregs.h.al = 0x33;     /* mouse vector   */
  33.       intdosx(0x21, &workregs, &workregs, &sregs);
  34.  
  35.       /* ES:BX now contains the pointer to the interrupt handler */
  36.  
  37.       if (sregs.es == 0 && inregs.x.bx == 0)
  38.             return mouse_present = 0;
  39.  
  40.       workregs.x.ax = 0;
  41.       int86(MSMOUSE,&workregs,&workregs);
  42.       *mousetype = workregs.x.bx;
  43.       mouse_present = workregs.x.ax;
  44.       return(mouse_present);
  45. }
  46.  
  47. /*
  48. ** Makes the mouse cursor visible.
  49. */
  50.  
  51. void ms_show_cursor(void)
  52. {
  53.       union REGS workregs;
  54.  
  55.       workregs.x.ax = 1;
  56.       int86(MSMOUSE,&workregs,&workregs);
  57. }
  58.  
  59. /*
  60. ** Hides the mouse cursor.  Should be called before changing any portion of
  61. ** the screen under the mouse cursor.
  62. */
  63.  
  64. void ms_hide_cursor(void)
  65. {
  66.       union REGS workregs;
  67.  
  68.       workregs.x.ax = 2;
  69.       int86(MSMOUSE,&workregs,&workregs);
  70. }
  71.  
  72. /*
  73. ** Obtains information about the mouse position and button status.
  74. ** Places the current horizontal and vertical positions in *horizpos and
  75. ** *vertpos, respectively.  Returns the mouse button status, which is
  76. ** mapped at the bit level as follows:
  77. **    Bit 0 - left button    \
  78. **    Bit 1 - right button    >-- 0 = button up, 1 = button down
  79. **    Bit 2 - middle button  /
  80. */
  81.  
  82. int ms_get_mouse_pos(int *horizpos, int *vertpos) /* Returns button status */
  83. {
  84.       union REGS workregs;
  85.  
  86.       workregs.x.ax = 3;
  87.       int86(MSMOUSE,&workregs,&workregs);
  88.       *horizpos = workregs.x.cx;
  89.       *vertpos  = workregs.x.dx;
  90.       return(workregs.x.bx);
  91. }
  92.  
  93. /*
  94. ** Moves the mouse cursor to a new position.
  95. */
  96.  
  97. void ms_set_mouse_pos(int horizpos, int vertpos)
  98. {
  99.       union REGS workregs;
  100.  
  101.       workregs.x.ax = 4;
  102.       workregs.x.cx = horizpos;
  103.       workregs.x.dx = vertpos;
  104.       int86(MSMOUSE,&workregs,&workregs);
  105. }
  106.  
  107. /*
  108. ** Obtains information about the last time the specified button
  109. ** (0 = left, 1 = right, 2 = middle) was pressed.  Returns the current
  110. ** button status (same format as return from ms_get_mouse_pos() above).
  111. */
  112.  
  113. int ms_button_press_status(int  button,
  114.                            int *press_count,
  115.                            int *column,
  116.                            int *row)
  117. {
  118.       union REGS workregs;
  119.  
  120.       workregs.x.ax = 5;
  121.       workregs.x.bx = button;
  122.       int86(MSMOUSE,&workregs,&workregs);
  123.       *press_count = workregs.x.bx;
  124.       *column = workregs.x.cx;
  125.       *row = workregs.x.dx;
  126.       return(workregs.x.ax);
  127. }
  128.  
  129. /*
  130. ** Similar to above but obtains information about the last release of the
  131. ** specified button.
  132. */
  133.  
  134. int ms_button_release_status(int  button,
  135.                              int *release_count,
  136.                              int *column,
  137.                              int *row)
  138. {
  139.       union REGS workregs;
  140.  
  141.       workregs.x.ax = 6;
  142.       workregs.x.bx = button;
  143.       int86(MSMOUSE,&workregs,&workregs);
  144.       *release_count = workregs.x.bx;
  145.       *column = workregs.x.cx;
  146.       *row = workregs.x.dx;
  147.       return(workregs.x.ax);
  148. }
  149.  
  150. /*
  151. ** Forces the mouse cursor to remain within the range specified.
  152. */
  153.  
  154. void ms_restrict_horiz(int min, int max)
  155. {
  156.       union REGS workregs;
  157.  
  158.       workregs.x.ax = 7;
  159.       workregs.x.cx = min;
  160.       workregs.x.dx = max;
  161.       int86(MSMOUSE,&workregs,&workregs);
  162. }
  163.  
  164. /*
  165. ** Forces the mouse cursor to remain within the range specified.
  166. */
  167.  
  168. void ms_restrict_vert(int min, int max)
  169. {
  170.       union REGS workregs;
  171.  
  172.       workregs.x.ax = 8;
  173.       workregs.x.cx = min;
  174.       workregs.x.dx = max;
  175.       int86(MSMOUSE,&workregs,&workregs);
  176. }
  177.  
  178. void ms_define_window(int left, int top, int right, int bottom)
  179. {
  180.       ms_restrict_horiz(left,right);
  181.       ms_restrict_vert(top,bottom);
  182. }
  183.  
  184. /*
  185. ** Allows the user to set the graphics cursor to a new shape.  Check your
  186. ** mouse reference manual for full information about the use of this function.
  187. */
  188.  
  189. void ms_set_graphics_cursor(int      horiz_hotspot,
  190.                             int      vert_hotspot,
  191.                             unsigned seg_shape_tables,
  192.                             unsigned offset_shape_tables)
  193. {
  194.       union REGS workregs;
  195.       struct SREGS segregs;
  196.  
  197.       workregs.x.ax = 9;
  198.       workregs.x.bx = horiz_hotspot;
  199.       workregs.x.cx = vert_hotspot;
  200.       workregs.x.dx = offset_shape_tables;
  201.       segregs.es  = seg_shape_tables;
  202.       int86x(MSMOUSE,&workregs,&workregs,&segregs);
  203. }
  204.  
  205. /*
  206. ** Selects either the software or hardware cursor and sets the start and stop
  207. ** scan lines (for the hardware cursor) or the screen and cursor masks (for
  208. ** the software cursor).  Consult your mouse reference for more information.
  209. */
  210.  
  211. void ms_set_text_cursor(int type, int screen_mask, int cursor_mask)
  212. {
  213.       union REGS workregs;
  214.  
  215.       workregs.x.ax = 10;
  216.       workregs.x.bx = type;
  217.       workregs.x.cx = screen_mask;
  218.       workregs.x.dx = cursor_mask;
  219.       int86(MSMOUSE,&workregs,&workregs);
  220. }
  221.  
  222. /*
  223. ** Obtains the horizontal and vertical raw motion counts since the last
  224. ** request.
  225. */
  226.  
  227. void ms_read_motion_counters(int *horiz, int *vert)
  228. {
  229.       union REGS workregs;
  230.  
  231.       workregs.x.ax = 11;
  232.       int86(MSMOUSE,&workregs,&workregs);
  233.       *horiz = workregs.x.cx;
  234.       *vert  = workregs.x.dx;
  235. }
  236.  
  237. /*
  238. ** Sets up a subroutine to be called when a given event occurs.
  239. ** NOTE: Use with extreme care.  The function whose address is provided MUST
  240. **    terminate with a far return (i.e. must be compiled using large model).
  241. **    Also, no DOS or BIOS services may be used, as the user-defined function
  242. **    is (in effect) an extension to an interrupt service routine.
  243. */
  244.  
  245. void ms_set_event_subroutine(int      mask,
  246.                              unsigned seg_routine,
  247.                              unsigned offset_routine)
  248. {
  249.       union REGS workregs;
  250.       struct SREGS segregs;
  251.  
  252.       workregs.x.ax = 12;
  253.       workregs.x.cx = mask;
  254.       workregs.x.dx = offset_routine;
  255.       segregs.es  = seg_routine;
  256.       int86x(MSMOUSE,&workregs,&workregs,&segregs);
  257. }
  258.  
  259. /*
  260. ** Turns light pen emulation mode on.
  261. */
  262.  
  263. void ms_light_pen_on(void)
  264. {
  265.       union REGS workregs;
  266.  
  267.       workregs.x.ax = 13;
  268.       int86(MSMOUSE,&workregs,&workregs);
  269. }
  270.  
  271. /*
  272. ** turns light pen emulation mode off.
  273. */
  274.  
  275. void ms_light_pen_off(void)
  276. {
  277.       union REGS workregs;
  278.  
  279.       workregs.x.ax = 14;
  280.       int86(MSMOUSE,&workregs,&workregs);
  281. }
  282.  
  283. /*
  284. ** Sets the sensitivity of the mouse.  Defaults are 8 and 16 for horizontal
  285. ** and vertical sensitivity (respectively).
  286. */
  287.  
  288. void ms_set_sensitivity(int horiz, int vert)
  289. {
  290.       union REGS workregs;
  291.  
  292.       workregs.x.ax = 15;
  293.       workregs.x.cx = horiz;
  294.       workregs.x.dx = vert;
  295.       int86(MSMOUSE,&workregs,&workregs);
  296. }
  297.  
  298. /*
  299. ** Sets up a region of the screen inside of which the mouse cursor will
  300. ** automatically be 'hidden'.
  301. */
  302.  
  303. void ms_protect_area(int left, int top, int right, int bottom)
  304. {
  305.       union REGS workregs;
  306.  
  307.       workregs.x.ax = 16;
  308.       workregs.x.cx = left;
  309.       workregs.x.dx = top;
  310.       workregs.x.si = right;
  311.       workregs.x.di = bottom;
  312.       int86(MSMOUSE,&workregs,&workregs);
  313. }
  314.  
  315. /*
  316. * Similar to ms_set_graphics_cursor() but allows a larger cursor.  Consult
  317. ** your mouse documentation for information on how to use this function.
  318. */
  319.  
  320. int ms_set_large_graphics_cursor(int      width,
  321.                                  int      height,
  322.                                  int      horiz_hotspot,
  323.                                  int      vert_hotspot,
  324.                                  unsigned seg_shape_tables,
  325.                                  unsigned offset_shape_tables)
  326. {
  327.       union REGS workregs;
  328.       struct SREGS segregs;
  329.  
  330.       workregs.x.ax = 18;
  331.       workregs.x.bx = (width << 8) + horiz_hotspot;
  332.       workregs.x.cx = (height << 8) + vert_hotspot;
  333.       workregs.x.dx = offset_shape_tables;
  334.       segregs.es  = seg_shape_tables;
  335.       int86x(MSMOUSE,&workregs,&workregs,&segregs);
  336.       if(workregs.x.ax == -1)
  337.             return(workregs.x.ax); /* Return -1 if function 18 supported */
  338.       else  return(0);             /* else return 0                      */
  339. }
  340.  
  341. /*
  342. ** Sets the threshold value for doubling cursor motion.  Default value is 64.
  343. */
  344.  
  345. void ms_set_doublespeed_threshold(int speed)
  346. {
  347.       union REGS workregs;
  348.  
  349.       workregs.x.ax = 19;
  350.       workregs.x.dx = speed;
  351.       int86(MSMOUSE,&workregs,&workregs);
  352. }
  353.