home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / MOUSE.ZIP / MOUSE.ASM < prev   
Assembly Source File  |  1989-01-02  |  4KB  |  124 lines

  1.         title   MOUSE.ASM Mouse Event Handler for C Programs
  2.         page    55,132
  3.  
  4. ; MOUSE.ASM  Mouse Event Handler for C Programs
  5. ; Copyright (C) 1989 Ziff Davis Communications
  6. ; PC Magazine * Ray Duncan
  7. ;
  8. ; Assemble with:  MASM /Mx MOUSE;
  9.  
  10. args    equ     4               ; stack offset of arguments,
  11.                                 ; C small model
  12.  
  13. DGROUP  group   _DATA
  14.  
  15. _DATA   segment word public 'DATA'
  16.  
  17. mflag   dw      ?               ; offset of mouse event flag
  18. xcoord  dw      ?               ; offset of X variable
  19. ycoord  dw      ?               ; offset of Y variable
  20. buttons dw      ?               ; offset of buttons variable
  21.  
  22. _DATA   ends
  23.  
  24.  
  25. _TEXT   segment word public 'CODE'
  26.  
  27.         assume  cs:_TEXT,ds:DGROUP
  28.  
  29. ; The procedure 'mregister' is called by the C program with
  30. ; the addresses of four variables: an event flag, which is
  31. ; set to TRUE by the event handler whenever the mouse changes
  32. ; state, and three variables to receive the mouses's X and Y
  33. ; coordinates and the state of the mouse buttons.
  34. ;
  35. ; The C prototype for the function is:
  36. ;
  37. ;   void mregister(int *flag, int *x, int *y, int *buttons)
  38.  
  39.         public  _mregister
  40. _mregister proc near
  41.                                 ; parameters passed by C program
  42. foffs   equ     [bp+args]       ; offset of event flag variable
  43. xoffs   equ     foffs+2         ; offset of X variable
  44. yoffs   equ     xoffs+2         ; offset of Y variable
  45. boffs   equ     yoffs+2         ; offset of buttons variable
  46.  
  47.         push    bp              ; set up stack frame
  48.         mov     bp,sp
  49.         push    si              ; protect register variables
  50.         push    di
  51.  
  52.         mov     ax,boffs        ; save offsets of the   
  53.         mov     buttons,ax      ; C program's variables
  54.         mov     ax,yoffs
  55.         mov     ycoord,ax
  56.         mov     ax,xoffs
  57.         mov     xcoord,ax
  58.         mov     ax,foffs
  59.         mov     mflag,ax
  60.  
  61.                                 ; register mouse event handler
  62.         push    cs
  63.         pop     es              ; ES:DX = handler address
  64.         mov     dx,offset _TEXT:mhandler
  65.         mov     cx,1fh          ; CX = event mask               
  66.         mov     ax,0ch          ; function 0CH = register
  67.         int     33h             ; transfer to mouse driver
  68.  
  69.         pop     di              ; restore register variables
  70.         pop     si              ; and discard stack frame
  71.         pop     bp
  72.         ret                     ; back to caller
  73.  
  74. _mregister endp
  75.  
  76.  
  77. ; The mouse event handler is entered by a far call from the
  78. ; mouse driver whenever a mouse event occurs corresponding
  79. ; to the event mask passed in the original registration call.
  80. ; At entry to the handler, the registers are set up as follows:
  81. ;
  82. ;       AX      = mouse event flags:    
  83. ;                       bit   significance
  84. ;                       0     mouse movement
  85. ;                       1     left button pressed
  86. ;                       2     left button released
  87. ;                       3     right button pressed
  88. ;                       4     right button released
  89. ;                       5-15  reserved
  90. ;       BX      = button state          
  91. ;                       bit   significance
  92. ;                       0     left button is down
  93. ;                       1     right button is down
  94. ;                       2-15  reserved
  95. ;       CX      = X coordinate
  96. ;       DX      = Y coordinate
  97. ;       SI      = raw vertical mickey count
  98. ;       DI      = raw horizontal mickey count
  99. ;       DS      = mouse driver data segment
  100.  
  101. mhandler proc   far
  102.         
  103.         push    ds              ; save mouse driver's data segment
  104.         mov     di,DGROUP       ; make our data segment addressable     
  105.         mov     ds,di
  106.         mov     di,xcoord       ; get offset of X coordinate variable
  107.         mov     [di],cx         ; store X coordinate
  108.         mov     di,ycoord       ; get offset of Y coordinate variable
  109.         mov     [di],dx         ; store Y coordinate
  110.         mov     di,buttons      ; get offset of buttons variable
  111.         mov     [di],bx         ; store button state
  112.         mov     di,mflag        ; get offset of event flag variable
  113.         mov     word ptr [di],1 ; set the variable to TRUE
  114.         pop     ds              ; restore mouse driver's data segment
  115.         ret                     ; and return to driver
  116.  
  117. mhandler endp
  118.  
  119.  
  120. _TEXT   ends
  121.  
  122.         end
  123.  
  124.