Annotation of os2sdk/demos/apps/life/mouapi.c, revision 1.1.1.2

1.1       root        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
1.1.1.2 ! root       14:  *
        !            15:  *  Created by Microsoft Corp. 1987
1.1       root       16:  */
1.1.1.2 ! root       17: #define INCL_SUB
1.1       root       18: 
1.1.1.2 ! root       19: #include <os2def.h>
        !            20: #include <bsesub.h>
1.1       root       21: 
                     22: /* defines for int33h() calls. These are the offsets for the various registers
                     23:  *     in the register array. */
                     24: #define AX 0
                     25: #define BX 1
                     26: #define CX 2
                     27: #define DX 3
                     28: 
                     29: 
1.1.1.2 ! root       30: /***   MouOpen - initializes mouse
1.1       root       31:  *
                     32:  *     Initializes mouse and returns -1 in handle if mouse is present, else
                     33:  *     if no mouse is present, returns 0 in handle and error code.
                     34:  */
1.1.1.2 ! root       35: unsigned APIENTRY
        !            36: MouOpen (name, handle)
        !            37: PSZ name;
        !            38: PHMOU handle;
1.1       root       39: {
                     40:        extern void int33h();                   /* mouse interupt caller */
                     41:        int registers[4];                       /* register array for above */
                     42: 
                     43:        registers[AX]=0;                        /* ax=0, mouse init */
                     44:        int33h (registers);                     /* do mouse call */
                     45:        if (registers[AX] == -1) {              /* was mouse present? */
                     46:                *handle=-1;                     /* if yes, give dummy handle */
                     47:                registers[AX]=15;               /* set mickey to pixel */
                     48:                registers[CX]=8;                /*      ratio to 1:1 */
                     49:                registers[DX]=8;
                     50:                int33h(registers);
                     51:                return (0);                     /* and return no error */
                     52:        }
                     53:        else {
                     54:                *handle=0;
                     55:                return (385);                   /* else, return no mouse err */
                     56:        }
                     57: }
                     58: 
                     59: 
1.1.1.2 ! root       60: /***   MouReadEventQue - get mouse event
1.1       root       61:  *
                     62:  *     Gets events like the OS/2 MouReadEventQue but this one ignores
                     63:  *     the event mask and EventType parameter, never waiting for events,
                     64:  *     just returning a 0 mask if nothing happened since last call.
                     65:  *     Returns position absolute pixel coordinates
                     66:  */
1.1.1.2 ! root       67: unsigned APIENTRY
        !            68: MouReadEventQue (buffer, type, handle)
        !            69:        PMOUEVENTINFO buffer;
        !            70:        PUSHORT type;
        !            71:        HMOU handle;
1.1       root       72: {
                     73:        extern void int33h();                   /* mouse interupt caller */
                     74:        int registers[4];                       /* register array for above */
                     75:        static lastrow;                         /* position at last call */
                     76:        static lastcol;
                     77: 
                     78:        buffer->Time=-1L;                       /* put in dummy time figure */
                     79:        registers[AX]=3;                        /* ax=3, get mouse status */
                     80:        int33h (registers);                     /* do mouse call */
1.1.1.2 ! root       81:        buffer->fs=0;                           /* first, blank button info */
1.1       root       82:        if (registers[DX]-lastrow || registers[CX]-lastcol) {
1.1.1.2 ! root       83:                buffer->row=registers[DX];      /* return row */
        !            84:                buffer->col=registers[CX];      /* return column */
1.1       root       85:                lastrow=registers[DX];          /* save for next time */
                     86:                lastcol=registers[CX];
                     87:                if (registers[BX] & 1)          /* if the left button is down*/
1.1.1.2 ! root       88:                        (buffer->fs) |= 2;      /*   then set appropriate bit*/
1.1       root       89:                if (registers[BX] & 2)          /* if the right button down*/
1.1.1.2 ! root       90:                        (buffer->fs) |= 8;      /*   then set appropriate bit*/
1.1       root       91:                else if (!(registers[BX] & 1))  /* if no buttons, but motion */
1.1.1.2 ! root       92:                        buffer->fs |= 1;        /*   then set apporpriate bit*/
1.1       root       93:        }
                     94:        if (registers[BX] & 1)          /* if the left button is down*/
1.1.1.2 ! root       95:                (buffer->fs) |= 4;      /*   then set appropriate bit*/
1.1       root       96:        if (registers[BX] & 2)          /* if the right button down*/
1.1.1.2 ! root       97:                (buffer->fs) |= 16;     /*   then set appropriate bit*/
1.1       root       98:        return (0);                             /* return no error */
                     99: }
                    100: 
                    101: 
1.1.1.2 ! root      102: /*** MouSetDevStatus - Dummy function, included for maximum compatibility
1.1       root      103:  */
1.1.1.2 ! root      104: unsigned APIENTRY
        !           105: MouSetDevStatus (status, handle)
        !           106: PUSHORT status;
        !           107: HMOU handle;
1.1       root      108: {
                    109: }
                    110: 
                    111: 
1.1.1.2 ! root      112: /*** MouGetNumQueEl - Always returns 1 in .Events
1.1       root      113: */
1.1.1.2 ! root      114: unsigned APIENTRY
        !           115: MouGetNumQueEl (info, handle)
        !           116: PMOUQUEINFO info;
        !           117: HMOU handle;
1.1       root      118: {
1.1.1.2 ! root      119:        info->cEvents = 1;
1.1       root      120: }
                    121: 
                    122: 
1.1.1.2 ! root      123: /*** MouSetPtrPos - Sets mouse pointer position
1.1       root      124: */
1.1.1.2 ! root      125: unsigned APIENTRY
        !           126: MouSetPtrPos (loc, handle)
        !           127: PPTRLOC loc;
        !           128: HMOU handle;
1.1       root      129: {
                    130:        int registers[4];                       /* for int33h() */
                    131: 
                    132:        registers[AX]=4;                        /* int 33 set position funct */
1.1.1.2 ! root      133:        registers[CX]=loc->col;                 /* new coordinates */
        !           134:        registers[DX]=loc->row;
1.1       root      135:        int33h (registers);                     /* do it */
                    136: }
1.1.1.2 ! root      137: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.