home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 26 / CD_ASCQ_26_1295.iso / vrac / user_int.zip / MHANDLER.CPP < prev    next >
C/C++ Source or Header  |  1995-08-25  |  2KB  |  91 lines

  1.  
  2. #include <dos.h>
  3.  
  4. /*-- Mouse software interrupt --*/
  5. #define  MOUSEINT  geninterrupt(0x33)
  6.  
  7. /*-- Mouse button status macros --*/
  8. #define  L_DOWN       (M_buttonstatus & 0x01)
  9. #define  R_DOWN       (M_buttonstatus & 0x02)
  10.  
  11. #define  HANDLER_EXIT_PROCESSING()  \
  12.   __emit__( (unsigned char) 0x5D,   \
  13.         (unsigned char) 0x5F,   \
  14.         (unsigned char) 0x5E,   \
  15.         (unsigned char) 0x1F,   \
  16.         (unsigned char) 0x07,   \
  17.         (unsigned char) 0x5A,   \
  18.         (unsigned char) 0x59,   \
  19.         (unsigned char) 0x5B,   \
  20.         (unsigned char) 0x58,   \
  21.         (unsigned char) 0xCB  ) ;
  22.  
  23. /*-- Global mouse status variables --*/
  24. int  M_xpos, M_ypos,  /* cursor location in 1,1,80,25 screen coordinates */
  25.      M_buttonstatus,  /* bits 0-2 ON if button is down */
  26.      M_event;         /* flags a mouse event */
  27.  
  28. /*-- Reset mouse - returns # of buttons or 0 if problems --*/
  29. int Mreset(void)
  30. {
  31.    _AX = 0;
  32.    MOUSEINT;
  33.    return(_AX ? _BX : _AX);
  34.  }
  35.  
  36. /*-- Show mouse cursor --*/
  37. void Mshow(void)
  38. {
  39.    _AX = 1;
  40.    MOUSEINT;
  41.  }
  42.  
  43. /*-- Hide mouse cursor --*/
  44. void Mhide(void)
  45. {
  46.    _AX = 2;
  47.    MOUSEINT;
  48.  }
  49.  
  50. /*-- Trap mouse cursor within screen coordinates --*/
  51. void Mtrap(int leftx, int upy, int rightx, int downy)
  52. {
  53.    int cx, dx;
  54.  
  55.    cx=(leftx-1)*8;   /* all converted to 1,1,80,25 screen coordinates */
  56.    dx=(rightx-1)*8;
  57.    _AX = 7;
  58.    _CX = cx;
  59.    _DX = dx;
  60.    MOUSEINT;
  61.    cx=(upy-1)*8;
  62.    dx=(downy-1)*8;
  63.    _AX = 8;
  64.    _CX = cx;
  65.    _DX = dx;
  66.    MOUSEINT;
  67.  }
  68.  
  69. /*-- Mouse event handler to update mouse information --*/
  70. void interrupt mousehandler(void)
  71. {
  72.    M_event = _AX;
  73.    M_buttonstatus = _BX;
  74.    M_xpos = _CX/8+1;    /* all converted to 1,1,80,25 screen coordinates */
  75.    M_ypos = _DX/8+1;
  76.    HANDLER_EXIT_PROCESSING();
  77.  }
  78.  
  79. /*-- Installs mouse handler --*/
  80. void Minsthandler(void)
  81. {
  82.    union REGS   reg;
  83.    struct SREGS seg;
  84.  
  85.    reg.x.ax = 20;
  86.    reg.x.cx = 0x1|0x2|0x4|0x8|0x10;   /* track move, click, or release */
  87.    reg.x.dx = FP_OFF(mousehandler);
  88.    seg.es = FP_SEG(mousehandler);
  89.    int86x(0x33, ®, ®, &seg);
  90.  }
  91.