home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / c / rkrm / input / inputhandler.a next >
Text File  |  1992-09-03  |  6KB  |  135 lines

  1. *
  2. * Copyright (c) 1992 Commodore-Amiga, Inc.
  3. * This example is provided in electronic form by Commodore-Amiga, Inc. for  
  4. * use with the "Amiga ROM Kernel Reference Manual: Devices", 3rd Edition, 
  5. * published by Addison-Wesley (ISBN 0-201-56775-X).
  6. * The "Amiga ROM Kernel Reference Manual: Devices" contains additional 
  7. * information on the correct usage of the techniques and operating system 
  8. * functions presented in these examples.  The source and executable code 
  9. * of these examples may only be distributed in free electronic form, via 
  10. * bulletin board or as part of a fully non-commercial and freely 
  11. * redistributable diskette.  Both the source and executable code (including 
  12. * comments) must be included, without modification, in any copy.  This 
  13. * example may not be published in printed form or distributed with any
  14. * commercial product.  However, the programming techniques and support
  15. * routines set forth in these examples may be used in the development
  16. * of original executable software products for Commodore Amiga computers.
  17. * All other rights reserved.
  18. * This example is provided "as-is" and is subject to change; no
  19. * warranties are made.  All use is at your own risk. No liability or
  20. * responsibility is assumed.
  21. *
  22. ****************************************************************************
  23. *
  24. *       InputHandler.a
  25. *
  26. * InputHandler that does a Left/Right mouse button swap...
  27. *
  28. *
  29. * See Swap_Buttons.c for details on how to compile/assemble/link...
  30. *
  31. ************************************************************************
  32. *
  33. * Required includes...
  34. *
  35. *       CSECT   InputHandler             ;SAS/Lattice ASM command requires this
  36. *
  37.         INCDIR  "include:"               ;HX68 requires this
  38.         INCLUDE "exec/types.i"
  39.         INCLUDE "exec/io.i"
  40.         INCLUDE "devices/inputevent.i"
  41. *
  42. ************************************************************************
  43. *
  44. * Make the entry point external...
  45. *
  46.         xdef    _ButtonSwap
  47. *
  48. ************************************************************************
  49. *
  50. * This is the input handler that will swap the
  51. * mouse buttons for left handed use.
  52. *
  53. * The event list gets passed to you in  a0.
  54. * The is_Data field is passed to you in a1.
  55. * This example does not use the is_Data field...
  56. *
  57. * On exit you must return the event list in d0.  In this way
  58. * you could add or remove items from the event list.
  59. *
  60. ************************************************************************
  61. *
  62. * The handler gets called here...
  63. *
  64. _ButtonSwap:    move.l  a0,-(sp)        ; Save the event list
  65. *
  66. * Since the event list could be a linked list, we start a loop
  67. * here to handle all of the events passed to us.
  68. *
  69. CheckLoop:      move.w  ie_Qualifier(a0),d1             ; Get qualifiers...
  70.                 move.w  d1,d0                           ; Two places...
  71. *
  72. * Since we are changing left and right mouse buttons, we need to make
  73. * sure that we change the qualifiers on all of the messages.  The
  74. * left and right mouse buttons are tracked in the message qualifiers
  75. * for use in such things as dragging.  To make sure that we continue
  76. * to drag correctly, we change the qualifiers.
  77. *
  78. CheckRight:     btst    #IEQUALIFIERB_RBUTTON,d1        ; Check for right
  79.                 beq.s   NoRight
  80.                 bset    #IEQUALIFIERB_LEFTBUTTON,d0     ; Set the left...
  81.                 beq.s   CheckLeft
  82. NoRight:        bclr    #IEQUALIFIERB_LEFTBUTTON,d0     ; Clear the left...
  83. *
  84. CheckLeft:      btst    #IEQUALIFIERB_LEFTBUTTON,d1     ; Check for left
  85.                 beq.s   NoLeft
  86.                 bset    #IEQUALIFIERB_RBUTTON,d0        ; Set the right...
  87.                 beq.s   SaveQual
  88. NoLeft:         bclr    #IEQUALIFIERB_RBUTTON,d0        ; Clear the right...
  89. *
  90. SaveQual:       move.w  d0,ie_Qualifier(a0)             ; Save back...
  91. *
  92. * The actual button up/down events are transmitted as the
  93. * code field in RAWMOUSE events.  The code field must the be
  94. * checked and modified when needed on RAWMOUSE events.  If the
  95. * event is not a RAWMOUSE, we are done with it.
  96. *
  97.                 cmp.b   #IECLASS_RAWMOUSE,ie_Class(a0)  ; Check for mouse
  98.                 bne.s   NextEvent                       ; If not, next...
  99. *
  100.                 move.w  ie_Code(a0),d0                  ; Get code...
  101.                 move.w  d0,d1                           ; Save...
  102.                 and.w   #$7F,d0                         ; Mask UP_PREFIX
  103.                 cmp.w   #IECODE_LBUTTON,d0              ; Check for Left...
  104.                 beq.s   SwapThem                        ; If so, swap...
  105.                 cmp.w   #IECODE_RBUTTON,d0              ; Check for Right...
  106.                 bne.s   NextEvent                       ; If not, next...
  107. *
  108. SwapThem:       eor.w   #1,d1                           ; Flip bottom bit
  109.                 move.w  d1,ie_Code(a0)                  ; Save it...
  110. *
  111. * The event list is linked via a pointer to the next event
  112. * in the first element of the structure.  That is why it is not
  113. * nessesary to use:  move.l ie_NextEvent(a0),d0
  114. *
  115. * The reason I move to d0 first is that this also checks for zero.
  116. * The last event in the list will have a NULL ie_NextEvent field.
  117. * This is NOT as standard EXEC list where the node after the last
  118. * node is NULL.  Input events are single-linked for performance.
  119. *
  120. NextEvent:      move.l  (a0),d0                         ; Get next event
  121.                 move.l  d0,a0                           ; into a0...
  122.                 bne.s   CheckLoop                       ; Do some more.
  123. *
  124. * All done, just return the event list...  (in d0)
  125. *
  126.                 move.l  (sp)+,d0        ; Get event list back...
  127.                 rts                     ; return from handler...
  128. *
  129. *                                       ; SAS/Lattice ASM command requires this
  130. *               END
  131.