home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377b.lha / devices / input / inputhandler.a next >
Encoding:
Text File  |  1980-02-03  |  4.5 KB  |  124 lines

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