home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MOUSE / CMOUSE2.ZIP / MICE.ASM < prev    next >
Encoding:
Assembly Source File  |  1987-05-31  |  21.0 KB  |  650 lines

  1.    TITLE   mice
  2.  
  3. ; Title   : Microsoft C language interface to the Microsoft mouse driver
  4. ; Author  : ra
  5. ; Date    : 10-30-85
  6. ; System  : Microsoft Macro Assembler
  7. ; Version : 1.00
  8.  
  9.  
  10. ; Short Explanation:
  11. ;   The Microsoft C compiler can link an object module produced by the 
  12. ;  macro assembler with its own object modules. When this interface
  13. ;  module is assembled it produces an object module which exports mouse
  14. ;  driver interface functions for use by a C program.
  15. ;   The mouse driver functions are documented in the Microsoft Mouse Driver
  16. ;  programming interface manual.
  17.  
  18. ;  Microsoft is a registered trademark of Microsoft Corporation.
  19.  
  20.  
  21. ; Naming Convention:
  22. ;   The names follow the same convention as the Logitech Modula-2 language
  23. ;  interface.
  24.  
  25. ;
  26. ; N.B. : This interface assumes the LARGE memory model - ie long (4 byte)
  27. ;        addresses for both data and subroutine calls.
  28. ;        When the user compiles the application to link with the interface
  29. ;        he/she should specify this model.On the Microsoft C compiler this
  30. ;        is done using the -Ml option, ' cc -c -Ml main.c '.
  31. ;
  32.  
  33. ; ****************************************************************
  34. ; *                                                              *
  35. ; *                  M  A  C  R  O  S                            *
  36. ; *                                                              *
  37. ; ****************************************************************
  38.  
  39. enter   MACRO
  40.         push  bp           ; standard C compiler call entry
  41.         mov   bp, sp    
  42.         push  di        
  43.         push  si 
  44.         ENDM
  45.  
  46. leave   MACRO
  47.         pop   si           ; standard call exit
  48.         pop   di      
  49.         mov   sp, bp
  50.         pop   bp      
  51.         ret
  52.         ENDM
  53.  
  54.  
  55. ; ****************************************************************
  56. ; *                                                              *
  57. ; *          A S S E M B L E R    D I R E C T I V E S            *
  58. ; *                                                              *
  59. ; ****************************************************************
  60.  
  61. _TEXT   SEGMENT  BYTE PUBLIC 'CODE'
  62. _TEXT   ENDS
  63.  
  64. CONST   SEGMENT  WORD PUBLIC 'CONST'
  65. CONST   ENDS
  66.  
  67. _BSS    SEGMENT  WORD PUBLIC 'BSS'
  68. _BSS    ENDS
  69.  
  70. _DATA   SEGMENT  WORD PUBLIC 'DATA'
  71. _DATA   ENDS
  72.  
  73. DGROUP  GROUP   CONST,  _BSS,   _DATA
  74.         ASSUME  CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
  75.  
  76. PUBLIC  _FlagReset
  77. PUBLIC  _ShowCursor
  78. PUBLIC  _HideCursor
  79. PUBLIC  _GetPosBut
  80. PUBLIC  _SetCursorPos
  81. PUBLIC  _GetButPres
  82. PUBLIC  _GetButRel
  83. PUBLIC  _SetHorizontalLimits
  84. PUBLIC  _SetVerticalLimits
  85. PUBLIC  _SetGraphicCursor
  86. PUBLIC  _ReadMotionCounters
  87. PUBLIC  _SetEventHandler
  88. PUBLIC  _LightPenOn
  89. PUBLIC  _LightPenOff
  90. PUBLIC  _SetMickeysPerPixel
  91. PUBLIC  _ConditionalOff
  92. PUBLIC  _SetSpeedThreshold 
  93.  
  94. PUBLIC _OrWithScreenOffset
  95. PUBLIC _AndWithScreenOffset
  96. PUBLIC _XorWithScreenOffset
  97. PUBLIC _SetScreenMode
  98.  
  99. _DATA   SEGMENT
  100. _DATA   ENDS
  101.  
  102. _TEXT      SEGMENT
  103.  
  104. ; ****************************************************************
  105. ; *                                                              *
  106. ; *         T H E   I N T E R F A C E   R O U T I N E S          *
  107. ; *                                                              *
  108. ; ****************************************************************
  109.  
  110.  
  111. CDataSeg  dw  DGROUP
  112.  
  113. ; ****************************************************************
  114. ; *        F U N C T I O N  0  :  F l a g R e s e t              *
  115. ; ****************************************************************
  116.  
  117. PUBLIC  _FlagReset
  118. ;
  119. ;     FlagReset( mouseStatusPtr, numberOfButtonsPtr )
  120. ;     int *mouseStatusPtr, *numberOfButtonsPtr;
  121. ;
  122.  
  123. _FlagReset      PROC FAR
  124. ;          Output: AX --> mouse status
  125. ;                   0 (FALSE): mouse hardware and software
  126. ;                              not installed
  127. ;                  -1 (TRUE) : mouse hardware and software
  128. ;                              installed
  129. ;                  BX --> number of mouse buttons
  130. ;
  131.                             enter
  132.                             mov   ax, 0        ; function 0
  133.                             int   33h          ; call mouse driver function 
  134.                             les   di, 6[bp]    ; address of mouseStatus
  135.                             mov   es:[di], ax  ; mouseStatus = ax
  136.                             les   di, 10[bp]   ; address of numberOfButtons
  137.                             mov   es:[di], bx  ; numberOfButtons = bx
  138.                             leave
  139.  
  140. _FlagReset                  ENDP
  141.  
  142.  
  143. ; ****************************************************************
  144. ; *        F U N C T I O N  1  :  
  145. ; ****************************************************************
  146.  
  147. PUBLIC _ShowCursor
  148. ;
  149. ; ShowCursor();
  150. ;
  151.  
  152. _ShowCursor  PROC FAR
  153.                             enter
  154.                             mov   ax, 1        ; function 1
  155.                             int   33h          ; call mouse driver function 
  156.                             leave
  157.  
  158. _ShowCursor                 ENDP       
  159.  
  160. ; ****************************************************************
  161. ; *        F U N C T I O N  2  :  
  162. ; ****************************************************************
  163.  
  164. PUBLIC _HideCursor
  165. ;
  166. ; HideCursor();
  167. ;
  168.  
  169. _HideCursor PROC FAR
  170.                             enter
  171.                             mov   ax, 2        ; function 2
  172.                             int   33h          ; call mouse driver function 
  173.                             leave
  174.  
  175. _HideCursor                 ENDP
  176.  
  177.  
  178. ; ****************************************************************
  179. ; *        F U N C T I O N  3  :  
  180. ; ****************************************************************
  181.  
  182. PUBLIC _GetPosBut
  183. ;
  184. ; GetPosBut ( buttonStatus, horizontal, vertical )
  185. ; struct {
  186. ;    unsigned leftButton  : 1;
  187. ;    unsigned rightButton : 1;
  188. ;        } *buttons;
  189. ; int *horizontal, *vertical;
  190. ;
  191.  
  192. _GetPosBut PROC FAR
  193.                             enter
  194.                             mov   ax, 3        ; function 3
  195.                             int   33h          ; call mouse driver function 
  196.                             les   di, 6[bp]    ; address of buttonStatus
  197.                             mov   es:[di], bx  ; buttonStatus = bx
  198.                             les   di, 10[bp]   ; address of horizontal
  199.                             mov   es:[di], cx  ; horizontal = cx
  200.                             les   di, 14[bp]   ; address of vertical
  201.                             mov   es:[di], dx  ; vertical = dx
  202.                             leave
  203. _GetPosBut ENDP
  204.  
  205.  
  206. ; ****************************************************************
  207. ; *        F U N C T I O N  4  :  
  208. ; ****************************************************************
  209.  
  210. PUBLIC _SetCursorPos
  211. ;
  212. ; SetCursorPos (horizontal, vertical)
  213. ; int horizontal, vertical;
  214. ;
  215.  
  216. _SetCursorPos PROC FAR
  217.                             enter
  218.                             mov   cx, 6[bp]    ; cx = horizontal
  219.                             mov   dx, 8[bp]    ; dx = vertical
  220.                             mov   ax, 4        ; function 4
  221.                             int   33h          ; call mouse driver function 
  222.                             leave
  223. _SetCursorPos ENDP
  224.  
  225.  
  226. ; ****************************************************************
  227. ; *        F U N C T I O N  5  :  
  228. ; ****************************************************************
  229.  
  230. PUBLIC _GetButPres
  231. ;
  232. ; GetButPres (button, buttonStatus, buttonPressCount, horizontal, vertical)
  233. ; int button, *buttonStatus, *buttonPressCount, *horizontal, *vertical;
  234. ;
  235.  
  236. _GetButPres PROC FAR
  237.                             enter
  238.                             mov   bx, 6[bp]    ; bx = button
  239.                             mov   ax, 5        ; function 5
  240.                             int   33h          ; call mouse driver function 
  241.                             les   di, 8[bp]   ; address of buttonStatus
  242.                             mov   es:[di], ax  ; buttonStatus = ax
  243.                             les   di, 12[bp]   ; address of buttonPressCount
  244.                             mov   es:[di], bx  ; buttonPressCount = bx
  245.                             les   di, 16[bp]   ; address of horizontal
  246.                             mov   es:[di], cx  ; horizontal = cx
  247.                             les   di, 20[bp]   ; address of vertical
  248.                             mov   es:[di], dx  ; vertical = dx
  249.                             leave
  250. _GetButPres ENDP
  251.  
  252.  
  253. ; ****************************************************************
  254. ; *        F U N C T I O N  6  :  
  255. ; ****************************************************************
  256.  
  257. PUBLIC _GetButRel
  258. ;
  259. ; GetButRel (button, buttonStatus, buttonReleaseCount, horizontal, vertical)
  260. ; int button, *buttonStatus, *buttonReleaseCount, *horizontal, *vertical;
  261.  
  262.  
  263. _GetButRel PROC FAR
  264.                             enter
  265.                             mov   bx, 6[bp]    ; bx = button
  266.                             mov   ax, 6        ; function 6
  267.                             int   33h          ; call mouse driver function 
  268.                             les   di, 8[bp]    ; address of buttonStatus
  269.                             mov   es:[di], ax  ; buttonStatus = ax
  270.                             les   di, 12[bp]   ; address of buttonReleaseCount
  271.                             mov   es:[di], bx  ; buttonReleaseCount = bx
  272.                             les   di, 16[bp]   ; address of horizontal
  273.                             mov   es:[di], cx  ; horizontal = cx
  274.                             les   di, 20[bp]   ; address of vertical
  275.                             mov   es:[di], dx  ; vertical = dx
  276.                             leave
  277. _GetButRel ENDP
  278.           
  279.  
  280. ; ****************************************************************
  281. ; *        F U N C T I O N  7  :  
  282. ; ****************************************************************
  283.  
  284. PUBLIC _SetHorizontalLimits
  285. ;
  286. ; SetHorizontalLimits (minPos, maxPos)
  287. ; int minPos, maxPos;
  288. ;
  289.  
  290. _SetHorizontalLimits PROC FAR
  291.                             enter
  292.                             mov   cx, 6[bp]    ; cx = minPos
  293.                             mov   dx, 8[bp]    ; dx = minPos
  294.                             mov   ax, 7        ; function 7
  295.                             int   33h          ; call mouse driver function 
  296.                             leave
  297. _SetHorizontalLimits ENDP
  298.  
  299.  
  300. ; ****************************************************************
  301. ; *        F U N C T I O N  8  :  
  302. ; ****************************************************************
  303.  
  304. PUBLIC _SetVerticalLimits
  305. ;
  306. ; SetHorizontalLimits (minPos, maxPos)
  307. ; int minPos, maxPos;
  308. ;
  309.  
  310. _SetVerticalLimits PROC FAR
  311.                             enter
  312.                             mov   cx, 6[bp]    ; cx = minPos
  313.                             mov   dx, 8[bp]    ; dx = minPos
  314.                             mov   ax, 8        ; function 8
  315.                             int   33h          ; call mouse driver function 
  316.                             leave
  317. _SetVerticalLimits ENDP
  318.  
  319.  
  320. ; ****************************************************************
  321. ; *        F U N C T I O N  9  :  
  322. ; ****************************************************************
  323.  
  324. PUBLIC _SetGraphicCursor
  325. ;
  326. ; typedef struct {
  327. ;    unsigned int screenMask[16],
  328. ;                 cursorMask[16];
  329. ;    int          hotX,
  330. ;                 hotY;
  331. ;                } GraphicCursor;
  332. ;  
  333. ; SetGraphicCursor (cursor)
  334. ; GraphicCursor *cursor;
  335. ;
  336.  
  337. _SetGraphicCursor PROC FAR
  338.                             enter
  339.                             les   di, 6[bp]     ; address of screenMask
  340.                             mov   dx, di        ; es:dx = address of screenMask
  341.                             mov   bx, es:64[di] ; bx = hotX
  342.                             mov   cx, es:66[di] ; cx = hotY
  343.                             mov   ax, 9         ; function 9
  344.                             int   33h           ; call mouse driver function 
  345.                             leave
  346. _SetGraphicCursor ENDP
  347.  
  348.  
  349.  
  350. ; ****************************************************************
  351. ; *        F U N C T I O N  10  : 
  352. ; ****************************************************************
  353.  
  354. PUBLIC _SetTextCursor
  355. ;
  356. ; SetTextCursor (selectedCursor, screenMaskORscanStart, cursorMaskORscanStop)
  357. ; unsigned int selectedCursor, 
  358. ;              screenMaskORscanStart, 
  359. ;              cursorMaskORscanStop;
  360. ;
  361.  
  362. _SetTextCursor PROC FAR
  363.                             enter
  364.                             mov   bx, 6[bp]    ; bx = selectedCursor
  365.                             mov   cx, 8[bp]    ; cx = screenMaskORscanStart
  366.                             mov   dx, 10[bp]   ; dx = cursorMaskORscanStop
  367.                             mov   ax, 10       ; function 10
  368.                             int   33h          ; call mouse driver function 
  369.                             leave
  370. _SetTextCursor ENDP
  371.  
  372.  
  373. ; ****************************************************************
  374. ; *        F U N C T I O N  11  : 
  375. ; ****************************************************************
  376.  
  377. PUBLIC _ReadMotionCounters
  378. ;
  379. ; ReadMotionCounters ( horizontal, vertical )
  380. ; int *horizontal, *vertical;
  381. ;
  382.  
  383. _ReadMotionCounters PROC FAR
  384.                             enter
  385.                             mov   ax, 11       ; function 11 
  386.                             int   33h          ; call mouse driver function 
  387.                             les   di, 6[bp]    ; address of horizontal
  388.                             mov   es:[di], cx  ; horizontal = cx
  389.                             les   di, 10[bp]   ; address of vertical
  390.                             mov   es:[di], dx  ; vertical = dx
  391.                             leave
  392. _ReadMotionCounters ENDP
  393.  
  394.  
  395. ; ****************************************************************
  396. ; *        F U N C T I O N  12  : 
  397. ; ****************************************************************
  398.  
  399. PUBLIC _SetEventHandler
  400. ;
  401. ; SetEventHandler (mask, handler)
  402. ; int mask;
  403. ; int *handler();
  404. ;
  405.  
  406. hand_offset   dw ?
  407. hand_segment  dw ?
  408. saveAX        dw ?
  409.  
  410. PrivateHandler PROC FAR
  411.  
  412. process_event:              cli               ; prevent a further interrupt
  413.                                               ; which would change registers
  414.                                               ; ax, bx, cx, dx
  415.  
  416.                             push  ds          ; save mouse driver ds
  417.                             mov   ds, cs:CDataSeg ; set up C data seg
  418.  
  419.                             push  dx          ; set up params for c function
  420.                             push  cx
  421.                             push  bx
  422.                             push  ax
  423.  
  424.                             sti               ; enable interrupts
  425.  
  426.                             call far [dword ptr cs:hand_segment]
  427.                             add  sp, 8
  428.  
  429.                             pop  ds           ; restore mouse driver ds
  430.                             ret
  431.                             
  432.                          
  433. PrivateHandler ENDP
  434.  
  435. _SetEventHandler PROC FAR
  436.                             enter
  437.                             push  es
  438.                             mov   cx, 6[bp]    ; cx = mask
  439.                             les   dx, 8[bp]    ; handler
  440.                             mov   hand_segment, es
  441.                             mov   hand_offset , dx
  442.                             push  cs
  443.                             pop   es
  444.                             mov   dx, offset cs:PrivateHandler
  445.                             mov   ax, 12       ; function 12
  446.                             int   33h          ; call mouse driver function 
  447.                             pop   es
  448.                             leave
  449. _SetEventHandler ENDP
  450.  
  451.  
  452.  
  453. ; ****************************************************************
  454. ; *        F U N C T I O N  13  : 
  455. ; ****************************************************************
  456.  
  457. PUBLIC _LightPenOn
  458. ;
  459. ; LightPenOn ();
  460. ;
  461.  
  462. _LightPenOn PROC FAR
  463.                             enter
  464.                             mov   ax, 13       ; function 13
  465.                             int   33h          ; call mouse driver function 
  466.                             leave
  467. _LightPenOn ENDP
  468.  
  469.  
  470. ; ****************************************************************
  471. ; *        F U N C T I O N  14  : 
  472. ; ****************************************************************
  473.  
  474. PUBLIC _LightPenOff
  475. ;
  476. ; LightPenOff ();
  477. ;
  478.  
  479. _LightPenOff PROC FAR
  480.                             enter
  481.                             mov   ax, 14        ; function 14
  482.                             int   33h          ; call mouse driver function 
  483.                             leave
  484. _LightPenOff ENDP
  485.  
  486.  
  487. ; ****************************************************************
  488. ; *        F U N C T I O N  15  : 
  489. ; ****************************************************************
  490.  
  491. PUBLIC _SetMickeysPerPixel
  492. ;
  493. ; SetMickeysPerPixel (horPix, verPix)
  494. ; unsigned int horPix, verPix;
  495. ;
  496.  
  497. _SetMickeysPerPixel PROC FAR
  498.                             enter
  499.                             mov   cx, 6[bp]    ; cx = horPix
  500.                             mov   dx, 8[bp]    ; dx = verPix
  501.                             mov   ax, 15       ; function 15
  502.                             int   33h          ; call mouse driver function 
  503.                             leave
  504. _SetMickeysPerPixel ENDP
  505.  
  506.  
  507. ; ****************************************************************
  508. ; *        F U N C T I O N  16  : 
  509. ; ****************************************************************
  510.  
  511. PUBLIC _ConditionalOff
  512. ;
  513. ; ConditionalOff (left, top, right, bottom)
  514. ; int left, top, right, bottom;
  515. ;
  516.  
  517. _ConditionalOff PROC FAR
  518.                             enter
  519.                             mov   cx,  6[bp]   ; cx = left
  520.                             mov   dx,  8[bp]   ; dx = top
  521.                             mov   si,  10[bp]  ; si = right
  522.                             mov   di,  12[bp]  ; di = bottom
  523.                             mov   ax, 16       ; function 16
  524.                             int   33h          ; call mouse driver function 
  525.                             leave
  526. _ConditionalOff ENDP                            
  527.  
  528.  
  529. ; ****************************************************************
  530. ; *        F U N C T I O N  19  : 
  531. ; ****************************************************************
  532.  
  533. PUBLIC _SetSpeedThreshold
  534. ;
  535. ; SetSpeedThreshold (threshold)
  536. ; unsigned int threshold;
  537. ;
  538.  
  539. _SetSpeedThreshold PROC FAR
  540.                             enter
  541.                             mov   dx, 6[bp]     ; dx = threshold
  542.                             mov   ax, 19        ; function 19
  543.                             int   33h           ; call mouse driver function 
  544.                             leave
  545. _SetSpeedThreshold ENDP
  546.  
  547. ;************************************************************************
  548.  
  549. ;
  550. ;   OrWithScreenOffset (offset, value)
  551. ;   unsigned offset;
  552. ;   char     value;
  553. ;   /* writes value to address 0xb800:offset */
  554. ;
  555. screen label dword
  556. screen_offset  dw 0
  557. screen_segment dw 0b800h
  558.  
  559. PUBLIC _OrWithScreenOffset
  560.  
  561. _OrWithScreenOffset    PROC FAR
  562.                 enter
  563.                 push  es
  564.                 push  ax
  565.                 mov   ax, 6[bp]          ; ax = offset
  566.                 mov   screen_offset, ax
  567.                 les   di, screen
  568.                 mov   al, 8[bp]
  569.                 or    es:[di], al        ; 0xb800:offset |= value
  570.                 pop   ax
  571.                 pop   es
  572.                 leave
  573. _OrWithScreenOffset    ENDP
  574.  
  575. ;************************************************************************
  576.  
  577. ;
  578. ;   AndWithScreenOffset (offset, value)
  579. ;   unsigned offset;
  580. ;   char     value;
  581. ;   /* writes value to address 0xb800:offset */
  582. ;
  583.  
  584. PUBLIC _AndWithScreenOffset
  585.  
  586. _AndWithScreenOffset    PROC FAR
  587.                 enter
  588.                 push  es
  589.                 push  ax
  590.                 mov   ax, 6[bp]          ; ax = offset
  591.                 mov   screen_offset, ax
  592.                 les   di, screen
  593.                 mov   al, 8[bp]
  594.                 and   es:[di], al        ; 0xb800:offset |= value
  595.                 pop   ax
  596.                 pop   es
  597.                 leave
  598. _AndWithScreenOffset    ENDP
  599.  
  600. ;************************************************************************
  601.  
  602. ;
  603. ;   XorWithScreenOffset (offset, value)
  604. ;   unsigned offset;
  605. ;   char     value;
  606. ;   /* writes value to address 0xb800:offset */
  607. ;
  608.  
  609. PUBLIC _XorWithScreenOffset
  610.  
  611. _XorWithScreenOffset    PROC FAR
  612.                 enter
  613.                 push  es
  614.                 push  ax
  615.                 mov   ax, 6[bp]          ; ax = offset
  616.                 mov   screen_offset, ax
  617.                 les   di, screen
  618.                 mov   al, 8[bp]
  619.                 xor   es:[di], al        ; 0xb800:offset xor value
  620.                 pop   ax
  621.                 pop   es
  622.                 leave
  623. _XorWithScreenOffset    ENDP
  624.  
  625. ;************************************************************************
  626.  
  627. ;
  628. ; SetScreenMode (mode)
  629. ; char mode;
  630. ;
  631.  
  632. PUBLIC _SetScreenMode
  633.  
  634. _SetScreenMode  PROC FAR
  635.                 enter
  636.                 push  es
  637.                 push  ax
  638.                 mov   ah, 0              ; function 0
  639.                 mov   al, 6[bp]          ; al = mode
  640.                 push  bp
  641.                 int   10h
  642.                 pop   bp
  643.                 pop   ax
  644.                 pop   es
  645.                 leave
  646. _SetScreenMode  ENDP
  647.  
  648. _TEXT   ENDS
  649. END
  650.