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