home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_12 / 8n12062a < prev    next >
Text File  |  1990-10-18  |  4KB  |  147 lines

  1.  
  2.     Comment         #
  3.  
  4.     extern void far handler(void);  /* a mouse event handler */
  5.     ------------------------------
  6.     Version:        1.0
  7.     Date:           1/13/90
  8.     Author:         Michael Kelly
  9.  
  10.     Environment:
  11.  
  12.     Specific to mice compatible with the Microsoft Mouse Driver Interface
  13.  
  14.     External Variables:     _head, _tail: near pointers to links
  15.                 in a circular queue.  Each link has the
  16.                 form mirrored by the event_q struc defined
  17.                 below.
  18.  
  19.     even                    ;use word data alignment
  20.     event_q struc           ;mirrors EVENT link defined in mouseq.h
  21.     xc      dw      ?       ;x mouse coordinate
  22.     yc      dw      ?       ;y mouse coordinate
  23.     butstat dw      ?       ;mouse button status
  24.     evmask  dw      ?       ;event mask ( active events at time of entry )
  25.     vflag   dw      ?       ;"valid" flag
  26.     nextptr dw      ?       ;pointer to next link
  27.     event_q ends
  28.  
  29.  
  30.                 _head and _tail are defined in mouseq.h
  31.                 and iniitialized in the file mouseq.c,
  32.                 which is responsible for the creation and
  33.                 destruction of the queue.
  34.  
  35.     ------------------------------
  36.  
  37.     Mouse Event Handler called as a far function from the mouse driver
  38.     when it senses an event for which the event mask has a bit set.
  39.  
  40.  
  41.     Designed to be linked to a Small Memory Model C Program
  42.  
  43.     This example uses Turbo C V. 2.0
  44.  
  45.     ****************************************
  46.     On Entry:
  47.         AX = bit mask for current events
  48.          where  a 1 in bit position:
  49.             0   =   mouse cursor movement
  50.             1   =   left button press
  51.             2   =   right button press
  52.             3   =   left button release
  53.             4   =   right button release
  54.             5 - 15: unused
  55.         BX = button status
  56.         CX = X mouse coordinate
  57.         DX = Y mouse coordinate
  58.     ****************************************
  59.  
  60.     #
  61.  
  62.  
  63.  
  64.     name    _handler
  65.  
  66.  
  67. _TEXT    segment    byte public 'CODE'
  68. DGROUP    group    _DATA,_BSS
  69.     assume  cs:_TEXT,ds:DGROUP
  70. _TEXT    ends
  71. _DATA   segment word public 'DATA'
  72.     extrn   _head:word,_tail:word
  73.  
  74. even                    ;use word data alignment
  75. event_q struc
  76. xc      dw      ?
  77. yc      dw      ?
  78. butstat dw      ?
  79. evmask  dw      ?
  80. vflag   dw      ?
  81. nextptr dw      ?
  82. event_q ends
  83.  
  84. sav_ax  dw      ?
  85. _DATA    ends
  86. _BSS    segment word public 'BSS'
  87. _b@    label    byte
  88. _BSS    ends
  89. _TEXT   segment byte public 'CODE'
  90.  
  91.     ;***********
  92.     ;Entry Point
  93.     ;***********
  94.  
  95.  _handler       proc    far
  96.     cli                     ;disable interrupts to avoid re-entry
  97.     push    ds              ;save registers
  98.     push    di
  99.     mov     di,DGROUP       ;point DS to application's data segment
  100.     mov     ds,di
  101.     mov     sav_ax,ax       ;we're called from inside the mouse driver
  102.                 ;so keep stack pushes to a minimum
  103.  
  104.     mov     di,_tail
  105.     mov     ax,[di].nextptr         ;get tail->next pointer
  106.     mov     di,_head
  107.     cmp     ax,[di]         ;if it equals head then queue is full
  108.     jne     hndlr1
  109.     jmp     handl_exit      ;exit if queue is full
  110.  
  111.  hndlr1:
  112.     mov     di,_tail        ;we sacrifice one slot in queue to simplify
  113.                 ;code, similar to PC BIOS keyboard buffer
  114.                 ;routine
  115.  
  116.     ;***********************************
  117.     ;store mouse event info in the queue
  118.     ;***********************************
  119.  
  120.     mov     [di].xc,cx              ;x mouse coordinate from CX reg
  121.     mov     [di].yc,dx              ;y mouse coordinate from DX reg
  122.     mov     [di].butstat,bx         ;mouse button status from BX reg
  123.     mov     ax,sav_ax               ;event mask from AX reg
  124.     mov     [di].evmask,ax
  125.     mov     [di].vflag,1            ;mark queue entry "valid"
  126.     mov     ax,[di].nextptr
  127.     mov     _tail,ax                ;bump tail pointer
  128.  
  129.     ;******************
  130.     ;Handler Exit Point
  131.     ;******************
  132.  
  133.  handl_exit:
  134.     pop     di                      ;restore registers
  135.     pop     ds
  136.     sti                             ;enable interrupts
  137.     ret                             ;far return to mouse driver
  138.  _handler       endp
  139. _TEXT    ends
  140. _DATA   segment word public 'DATA'
  141. _s@    label    byte
  142. _DATA    ends
  143. _TEXT    segment    byte public 'CODE'
  144.     public   _handler
  145. _TEXT    ends
  146.     end
  147.