home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / doom_i / program / deu52gcc.exe / SOURCE.ZIP / MOUSE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-06  |  3.4 KB  |  213 lines

  1. /*
  2.    Mouse interface by RaphaĆ«l Quinet <quinet@montefiore.ulg.ac.be>
  3.  
  4.    You are allowed to use any parts of this code in another program, as
  5.    long as you give credits to the authors in the documentation and in
  6.    the program itself.  Read the file README.1ST for more information.
  7.  
  8.    This program comes with absolutely no warranty.
  9.  
  10.    MOUSE.C - Mouse driver routines.
  11. */
  12.  
  13. /* the includes */
  14. #include "deu.h"
  15. #include <dos.h>
  16.  
  17. /* mouse interrupt number */
  18. #define MOUSE 0x33
  19.  
  20. /* the global data */
  21. Bool UseMouse;            /* is there a mouse driver? */
  22.  
  23.  
  24. /*
  25.    initialize the mouse driver
  26. */
  27.  
  28. #if defined(__TURBOC__)
  29.  
  30. void CheckMouseDriver()
  31. {
  32.    union REGS regs;
  33.  
  34.    regs.x.ax = 0x0000;
  35.    int86(MOUSE, ®s, ®s);
  36.    if (regs.x.ax == 0xffff)
  37.       UseMouse = TRUE; /* mouse */
  38.    else
  39.       UseMouse = FALSE; /* no mouse */
  40. }
  41.  
  42.  
  43.  
  44. /*
  45.    show the pointer
  46. */
  47.  
  48. void ShowMousePointer()
  49. {
  50.    union REGS regs;
  51.  
  52.    regs.x.ax = 0x0001;
  53.    int86(MOUSE, ®s, ®s);
  54. }
  55.  
  56.  
  57.  
  58. /*
  59.    hide the pointer
  60. */
  61.  
  62. void HideMousePointer()
  63. {
  64.    union REGS regs;
  65.  
  66.    regs.x.ax = 0x0002;
  67.    int86(MOUSE, ®s, ®s);
  68. }
  69.  
  70.  
  71. /*
  72.    read pointer coordinates
  73. */
  74.  
  75. void GetMouseCoords(BCINT *x, BCINT *y, BCINT *buttons)
  76. {
  77.    union REGS regs;
  78.  
  79.    regs.x.ax = 0x0003;
  80.    int86(MOUSE, ®s, ®s);
  81.    if (x != NULL)
  82.       *x = regs.x.cx;
  83.    if (y != NULL)
  84.       *y = regs.x.dx;
  85.    if (buttons)
  86.       *buttons = regs.x.bx;
  87. }
  88.  
  89.  
  90. /*
  91.    change pointer coordinates
  92. */
  93.  
  94. void SetMouseCoords( BCINT x, BCINT y)
  95. {
  96.    union REGS regs;
  97.  
  98.    regs.x.ax = 0x0004;
  99.    regs.x.cx = (UBCINT) x;
  100.    regs.x.dx = (UBCINT) y;
  101.    int86(MOUSE, ®s, ®s);
  102. }
  103.  
  104.  
  105.  
  106. /*
  107.    set horizontal and vertical limits (constrain pointer in a box)
  108. */
  109.  
  110. void SetMouseLimits( BCINT x0, BCINT y0, BCINT x1, BCINT y1)
  111. {
  112.    union REGS regs;
  113.  
  114.    regs.x.ax = 0x0007;
  115.    regs.x.cx = (UBCINT) x0;
  116.    regs.x.dx = (UBCINT) x1;
  117.    int86(MOUSE, ®s, ®s);
  118.    regs.x.ax = 0x0008;
  119.    regs.x.cx = (UBCINT) y0;
  120.    regs.x.dx = (UBCINT) y1;
  121.    int86(MOUSE, ®s, ®s);
  122. }
  123.  
  124.                       
  125.  
  126. /*
  127.    reset horizontal and vertical limits
  128. */
  129.  
  130. void ResetMouseLimits()
  131. {
  132.    union REGS regs;
  133.  
  134.    regs.x.ax = 0x0007;
  135.    regs.x.cx = (UBCINT) 0;
  136.    regs.x.dx = (UBCINT) ScrMaxX;
  137.    int86(MOUSE, ®s, ®s);
  138.    regs.x.ax = 0x0008;
  139.    regs.x.cx = (UBCINT) 0;
  140.    regs.x.dx = (UBCINT) ScrMaxY;
  141.    int86(MOUSE, ®s, ®s);
  142. }
  143.  
  144. #elif defined(__GNUC__)
  145.  
  146. #include <mousex.h>
  147.  
  148. void CheckMouseDriver()
  149. {
  150.    if (MouseDetect())
  151.    {
  152.       UseMouse = TRUE;
  153.       MouseEventMode(0);
  154.       MouseInit();
  155.       MouseSetColors(TranslateToDoomColor(WHITE),GrNOCOLOR);
  156.    }
  157.    else
  158.    {
  159.       UseMouse = FALSE;
  160.    }
  161. }
  162.  
  163.  
  164. void ShowMousePointer()
  165. {
  166.    MouseDisplayCursor();
  167.    MouseEventEnable(0,1);
  168.  
  169. }
  170.  
  171.  
  172.  
  173. void HideMousePointer()
  174. {
  175.    MouseEraseCursor();
  176.    MouseEventEnable(0,0);
  177. }
  178.  
  179.  
  180. void GetMouseCoords(BCINT *x, BCINT *y, BCINT *buttons)
  181. {
  182.    MouseEvent mevent;
  183.    MouseGetEvent(M_POLL|M_BUTTON_DOWN|M_BUTTON_UP,&mevent);
  184.    *x = mevent.x;
  185.    *y = mevent.y;
  186.    *buttons = mevent.buttons;
  187. }
  188.  
  189.  
  190.  
  191. void SetMouseCoords( BCINT x, BCINT y)
  192. {
  193.    MouseWarp(x,y);
  194. }
  195.  
  196.  
  197.  
  198. void SetMouseLimits( BCINT x0, BCINT y0, BCINT x1, BCINT y1)
  199. {
  200.    MouseSetLimits(x0,y0,x1,y1);
  201. }
  202.  
  203.  
  204.  
  205. void ResetMouseLimits()
  206. {
  207.    MouseSetLimits(0,0,ScrMaxX,ScrMaxY);
  208. }
  209.  
  210. #endif
  211.  
  212. /* end of file */
  213.