home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / DIVERSEN / DOS32V3B / LIB / MOUSE.ASM < prev    next >
Assembly Source File  |  1995-03-10  |  5KB  |  177 lines

  1. ;
  2. ;                        Mouse routines for DOS32
  3. ;
  4. ;                        Written by Adam Seychell
  5. ;
  6. ;
  7. ;Comments:      All mouse functions here except "MouseDriver" must not be
  8. ;               called unlease a mouse driver is installed in the system.
  9. ;
  10. ;****************************************************************************
  11. ;    Function: int MouseDriver();
  12. ; Description: Resets the mouse driver.
  13. ;      Return: nonzero if mouse driver is installed and zero if not.
  14. ;
  15. ;****************************************************************************
  16. ;    Function: void pascal SetMouseHandler(Pointer event_hanlder);
  17. ; Description: Sets the current mouse event handler and will be called when
  18. ;              the mouse is moved or a button is pressed/released.
  19. ;              When the handler is called the following external
  20. ;              varibles are set with the mouse information
  21. ;
  22. ;              integer  Micky_X              ; Horizontal micky count
  23. ;              integer  Micky_Y              ; Vertical micky count
  24. ;              byte     LeftButton           ; 1 if pressed and 0 if released
  25. ;              byte     RightButton          ; 1 if pressed and 0 if released
  26. ;
  27. ;              To free the current mouse event handler simply reset the
  28. ;              mouse driver by calling "MouseDriver"
  29. ;
  30. ;    Returns: nothing
  31. ;      Notes: When the program terminates it must reset the mouse driver
  32. ;              (by calling MosueDriver) to disable the current mouse event 
  33. ;              handler. Otherwise the mouse driver will continue calling the
  34. ;              mouse event procedure.
  35. ;****************************************************************************
  36. ;
  37. .386
  38. .Model Flat , pascal
  39.  
  40.  
  41.  
  42. Public  SetMouseHandler
  43. Public    MouseDriver
  44. Public  Micky_X
  45. Public  Micky_Y
  46. Public  LeftButton
  47. Public  RightButton
  48. Public  MiddleButton
  49.  
  50.         .CODE
  51.  
  52.  
  53. ;----------------------------------------------------------------------------
  54. MouseDriver PROC NEAR
  55.         Mov     Ax,0000h
  56.         Int     33h
  57.         Movsx   Eax,ax
  58.         Ret
  59. MouseDriver ENDP
  60.  
  61.  
  62.  
  63. ;----------------------------------------------------------------------------
  64. ;
  65. ;  Format of the Real Mode Call frame used by the DPMI service for switching
  66. ; to and from Real Mode
  67. ;
  68. Real_mode_Call_Struct STRUC
  69. RealMode_EDI         DD     ?
  70. RealMode_ESI         DD     ?
  71. RealMode_EBP         DD     ?
  72.                      DD     ?                  ; Unused
  73. RealMode_EBX         DD     ?
  74. RealMode_EDX         DD     ?
  75. RealMode_ECX         DD     ?
  76. RealMode_EAX         DD     ?
  77. RealMode_flags       DW     ?
  78. RealMode_ES          DW     ?
  79. RealMode_DS          DW     ?
  80. RealMode_FS          DW     ?
  81. RealMode_GS          DW     ?
  82. RealMode_IP          DW     ?
  83. RealMode_CS          DW     ?
  84. RealMode_SP          DW     ?
  85. RealMode_SS          DW     ?
  86. Real_mode_Call_Struct ENDS
  87.  
  88. Align 4
  89.  
  90. Micky_X                 DD      ?
  91. Micky_Y                 DD      ?
  92. Current_Event_Handler   DD      ?
  93. LeftButton              DB      ?
  94. RightButton             DB      ?
  95. MiddleButton            DB      ?
  96.  
  97.  
  98. Mouse_RM_CallStruct     Real_mode_Call_Struct <>
  99.  
  100.  
  101.  
  102. SetMouseHandler PROC  Event_HandlerPtr :Dword
  103.  
  104.         mov     eax,Event_HandlerPtr
  105.         mov     Current_Event_Handler,eax
  106.  
  107.         mov     Esi,Offset ISR_Handler
  108.         mov     Ax,0EE20h               ; Set real mode call back ( RETF )
  109.         int     31h
  110.         jc ExitError                  ; returns CX:DX -> real mode call back
  111.  
  112.         mov     BX,CX
  113.  
  114.  
  115.         Mov     ax,000Ch               ; DEFINE mouse event handler
  116.         mov     cx,01111111b
  117.                                        ; ES:DX -> handler
  118.  
  119.  
  120.         push dword ptr   0              ; set  SS:SP = 00:00
  121.         sub     esp,10                  ; ignore  CS, IP ,FS, GS, DS
  122.         push    BX
  123.         db 66h,9Ch                  ; pushf  16bit
  124.         pushad
  125.         mov     edi,esp
  126.         mov     ax,0300h
  127.         xor     cx,cx
  128.         mov     bl,33h                  ; call mouse handler
  129.         int     31h                     ; Emulate V86 interrupt
  130.         popad
  131.         db 66h,9Dh                      ; popf  16bit
  132.         lea     esp,[esp+16]            ; Ignore SS,SP,CS,IP,FS,GS,ES & DS
  133.         dec     ax
  134.         jz ExitError
  135.  
  136. okk:
  137.         mov     eax,-1
  138.         Ret
  139.  
  140. ExitError:
  141.         xor     eax,eax
  142.         Ret
  143.  
  144. SetMouseHandler ENDP
  145.  
  146.  
  147.  
  148.  
  149. ;-------------------------------------------------------------------------
  150. ;
  151. ;                        THE  MAIN  MOUSE  HANDLER
  152. ;
  153. ;-------------------------------------------------------------------------
  154. ISR_Handler PROC FAR
  155.  
  156.         Test    bl, 001b
  157.         Setne   LeftButton
  158.         Test    bl, 010b
  159.         Setne   RightButton
  160.         Test    bl, 100b
  161.         Setne   MiddleButton
  162.         Movsx   Edi,di
  163.         Movsx   Esi,si
  164.         Mov     Micky_X, esi
  165.         Mov     Micky_Y, edi
  166.  
  167.         Call    [Current_Event_Handler]
  168.  
  169.         retf
  170.  
  171. ;                       MOUSE HANDLER ENDS
  172. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  173. ISR_Handler ENDP
  174.  
  175.  
  176. End
  177.