home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / os2sdk / os2sdk10 / apps / life / mouapi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  3.9 KB  |  133 lines

  1. /***    mouapi.c - A library of real mode mouse calls compatable with OS/2
  2.  *
  3.  *    A subset of the OS/2 mouse api calls for real mode calls.
  4.  *    The calls and features are designed specifically for LIFE.C.
  5.  *    This is designed as a library to be linked with an application
  6.  *    using BIND.EXE to allow full compatability between real and
  7.  *    protect modes for programs using mouse calls.
  8.  *    Most are merely dummy calls because DOS 3.x doesn't care about
  9.  *    such things.
  10.  *
  11.  *    Contains subsets of:
  12.  *        MouOpen, MouReadEventQue, MouSetDevStatus,
  13.  *        MouGetNumQueEl, MouSetPtrPos
  14.  */
  15.  
  16. #include <subcalls.h>
  17.  
  18. /* defines for int33h() calls.    These are the offsets for the various registers
  19.  *     in the register array. */
  20. #define AX 0
  21. #define BX 1
  22. #define CX 2
  23. #define DX 3
  24.  
  25.  
  26. /***    MOUOPEN - initializes mouse
  27.  *
  28.  *    Initializes mouse and returns -1 in handle if mouse is present, else
  29.  *    if no mouse is present, returns 0 in handle and error code.
  30.  */
  31. unsigned far pascal
  32. MOUOPEN (name, handle)
  33. char far *name;
  34. unsigned far *handle;
  35. {
  36.     extern void int33h();            /* mouse interupt caller */
  37.     int registers[4];            /* register array for above */
  38.  
  39.     registers[AX]=0;            /* ax=0, mouse init */
  40.     int33h (registers);            /* do mouse call */
  41.     if (registers[AX] == -1) {        /* was mouse present? */
  42.         *handle=-1;            /* if yes, give dummy handle */
  43.         registers[AX]=15;        /* set mickey to pixel */
  44.         registers[CX]=8;        /*    ratio to 1:1 */
  45.         registers[DX]=8;
  46.         int33h(registers);
  47.         return (0);            /* and return no error */
  48.     }
  49.     else {
  50.         *handle=0;
  51.         return (385);            /* else, return no mouse err */
  52.     }
  53. }
  54.  
  55.  
  56. /***    MOUREADEVENTQUE - get mouse event
  57.  *
  58.  *    Gets events like the OS/2 MouReadEventQue but this one ignores
  59.  *    the event mask and EventType parameter, never waiting for events,
  60.  *    just returning a 0 mask if nothing happened since last call.
  61.  *    Returns position absolute pixel coordinates
  62.  */
  63. unsigned far pascal
  64. MOUREADEVENTQUE (buffer, type, handle)
  65.     struct EventInfo far *buffer;
  66.     unsigned far *type;
  67.     unsigned handle;
  68. {
  69.     extern void int33h();            /* mouse interupt caller */
  70.     int registers[4];            /* register array for above */
  71.     static lastrow;             /* position at last call */
  72.     static lastcol;
  73.  
  74.     buffer->Time=-1L;            /* put in dummy time figure */
  75.     registers[AX]=3;            /* ax=3, get mouse status */
  76.     int33h (registers);            /* do mouse call */
  77.     buffer->Mask=0;             /* first, blank button info */
  78.     if (registers[DX]-lastrow || registers[CX]-lastcol) {
  79.         buffer->Row=registers[DX];    /* return row */
  80.         buffer->Col=registers[CX];    /* return column */
  81.         lastrow=registers[DX];        /* save for next time */
  82.         lastcol=registers[CX];
  83.         if (registers[BX] & 1)        /* if the left button is down*/
  84.             (buffer->Mask) |= 2;    /*   then set appropriate bit*/
  85.         if (registers[BX] & 2)        /* if the right button down*/
  86.             (buffer->Mask) |= 8;    /*   then set appropriate bit*/
  87.         else if (!(registers[BX] & 1))    /* if no buttons, but motion */
  88.             buffer->Mask |= 1;    /*   then set apporpriate bit*/
  89.     }
  90.     if (registers[BX] & 1)        /* if the left button is down*/
  91.         (buffer->Mask) |= 4;    /*   then set appropriate bit*/
  92.     if (registers[BX] & 2)        /* if the right button down*/
  93.         (buffer->Mask) |= 16;    /*   then set appropriate bit*/
  94.     return (0);                /* return no error */
  95. }
  96.  
  97.  
  98. /*** MOUSETDEVSTATUS - Dummy function, included for maximum compatibility
  99.  */
  100. unsigned far pascal
  101. MOUSETDEVSTATUS (status, handle)
  102. unsigned far *status;
  103. unsigned handle;
  104. {
  105. }
  106.  
  107.  
  108. /*** MOUGETNUMQUEEL - Always returns 1 in .Events
  109. */
  110. unsigned far pascal
  111. MOUGETNUMQUEEL (info, handle)
  112. struct QueInfo far *info;
  113. unsigned handle;
  114. {
  115.     info->Events = 1;
  116. }
  117.  
  118.  
  119. /*** MOUSETPTRPOS - Sets mouse pointer position
  120. */
  121. unsigned far pascal
  122. MOUSETPTRPOS (loc, handle)
  123. struct PtrLoc far *loc;
  124. unsigned handle;
  125. {
  126.     int registers[4];            /* for int33h() */
  127.  
  128.     registers[AX]=4;            /* int 33 set position funct */
  129.     registers[CX]=loc->ColPos;        /* new coordinates */
  130.     registers[DX]=loc->RowPos;
  131.     int33h (registers);            /* do it */
  132. }
  133.