home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / vrac / dflt20.zip / MOUSE.C < prev    next >
Text File  |  1992-06-10  |  2KB  |  111 lines

  1. /* ------------- mouse.c ------------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. static union REGS regs;
  6. static struct SREGS sregs;
  7.  
  8. static void near mouse(int m1,int m2,int m3,int m4)
  9. {
  10.     regs.x.dx = m4;
  11.     regs.x.cx = m3;
  12.     regs.x.bx = m2;
  13.     regs.x.ax = m1;
  14.     int86x(MOUSE, ®s, ®s, &sregs);
  15. }
  16.  
  17. /* ---------- reset the mouse ---------- */
  18. void resetmouse(void)
  19. {
  20.     segread(&sregs);
  21.     mouse(0,0,0,0);
  22. }
  23.  
  24. /* ----- test to see if the mouse driver is installed ----- */
  25. BOOL mouse_installed(void)
  26. {
  27.     unsigned char far *ms;
  28.     ms = MK_FP(peek(0, MOUSE*4+2), peek(0, MOUSE*4));
  29.     return (SCREENWIDTH <= 80 && ms != NULL && *ms != 0xcf);
  30. }
  31.  
  32. /* ------ return true if mouse buttons are pressed ------- */
  33. int mousebuttons(void)
  34. {
  35.     if (mouse_installed())    {
  36.         segread(&sregs);
  37.         mouse(3,0,0,0);
  38.         return regs.x.bx & 3;
  39.     }
  40.     return 0;
  41. }
  42.  
  43. /* ---------- return mouse coordinates ---------- */
  44. void get_mouseposition(int *x, int *y)
  45. {
  46.     *x = *y = -1;
  47.     if (mouse_installed())    {
  48.         segread(&sregs);
  49.         mouse(3,0,0,0);
  50.         *x = regs.x.cx/8;
  51.         *y = regs.x.dx/8;
  52.         if (SCREENWIDTH == 40)
  53.             *x /= 2;
  54.     }
  55. }
  56.  
  57. /* -------- position the mouse cursor -------- */
  58. void set_mouseposition(int x, int y)
  59. {
  60.     if (mouse_installed())    {
  61.         segread(&sregs);
  62.         if (SCREENWIDTH == 40)
  63.             x *= 2;
  64.         mouse(4,0,x*8,y*8);
  65.     }
  66. }
  67.  
  68. /* --------- display the mouse cursor -------- */
  69. void show_mousecursor(void)
  70. {
  71.     if (mouse_installed())    {
  72.         segread(&sregs);
  73.         mouse(1,0,0,0);
  74.     }
  75. }
  76.  
  77. /* --------- hide the mouse cursor ------- */
  78. void hide_mousecursor(void)
  79. {
  80.     if (mouse_installed())    {
  81.         segread(&sregs);
  82.         mouse(2,0,0,0);
  83.     }
  84. }
  85.  
  86. /* --- return true if a mouse button has been released --- */
  87. int button_releases(void)
  88. {
  89.     if (mouse_installed())    {
  90.         segread(&sregs);
  91.         mouse(6,0,0,0);
  92.         return regs.x.bx;
  93.     }
  94.     return 0;
  95. }
  96.  
  97. /* ----- set mouse travel limits ------- */
  98. void set_mousetravel(int minx, int maxx, int miny, int maxy)
  99. {
  100.     if (mouse_installed())    {
  101.         if (SCREENWIDTH == 40)    {
  102.             minx *= 2;
  103.             maxx *= 2;
  104.         }
  105.         segread(&sregs);
  106.         mouse(7, 0, minx*8, maxx*8);
  107.         mouse(8, 0, miny*8, maxy*8);
  108.     }
  109. }
  110.  
  111.