home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 029.lha / MoonMouse.asm < prev    next >
Assembly Source File  |  1987-04-02  |  8KB  |  302 lines

  1. * moonmouse.asm    Copyright 1987 by Scott Turner ALL RIGHTS RESERVED
  2. *
  3. * This program was inspired by Sunmouse 1.0 written by Scott Evernden.
  4. * However, Sunmouse was written in Aztec C. I dislike have fat and slothly C
  5. * code eat my precious ram. I like it even less when it's in a memory resident
  6. * program like Sunmouse. Also, Sunmouse required you to RUN it and then it
  7. * ate a CLI and TONS of extra ram on top of what the C code porked down.
  8. * Also, unlike Sunmouse, this program is NOT shareware. So you can use moonmouse
  9. * without developing a guilt complex. I'm disturbed by the trend of people to
  10. * slap "shareware" on everything "just in case". Especially on this genre of
  11. * "tiny" but useful programs.
  12. *
  13. * So, here I have written moonmouse. I call it moonmouse because it's like a
  14. * Surveyor moon launch, very little of the code below remains in ram. Most of it
  15. * is "staging" code to "land" the "payload" on the "moon". It is in many
  16. * respects like my DeciGEL program in that it runs and leaves some code behind
  17. * in a hunk of ram it allocates and then doesn't return.
  18. *
  19. * What this "payload" does is intercept events in the input stream. It does two
  20. * things depending on various other things. If the event is a raw mouse event
  21. * it sets a flag indicating that it has seen mouse activity. If the event is a
  22. * non-system raw key (ie doesn't have Left-Alt or Left-Amiga qualifiers) AND
  23. * the current front screen equals the workbench screen AND the mouse has "moved"
  24. * It inserts a Left mouse button down/Left mouse button up event sequence onto
  25. * the head of the event. This has the effect of pressing the left mouse button
  26. * for you to make sure that key codes go to the window the mouse is pointing
  27. * at. I kinda like it since I can just "elbow" the mouse to where I want to
  28. * send input and leave my fingers on the keyboard.
  29. *
  30. * Moonmouse is intended to be inserted into your s:Startup-Sequence file. It
  31. * should be placed as near the top as possible so that the "payload" doesn't
  32. * unduly fragment the heap. Once installed moonmouse can't be removed. But hey,
  33. * I said "Surveyor" not "Apollo" right? (grin) MoonMouse eats 172 bytes of ram.
  34. *
  35. * If you have questions/comments/requests concerning this source code, please
  36. * direct them in WRITING (no I don't mean via phone!) to:
  37. *
  38. * Scott Turner
  39. * L5 Computing
  40. * 12311 Maplewood Avenue
  41. * Edmonds, WA. 98020-1115
  42. *
  43. * I may also be reached via:
  44. *
  45. * JST on GEnie
  46. *
  47. * I am NOT releasing this source code into the public domain. However, I here
  48. * by grant a license for distribution via AmigaDOS format 3.5" diskette or via
  49. * an online telecommunications medium provided that the party charges less than
  50. * the following to do so:
  51. *
  52. * USA $10 for a copy on an AmigaDOS 3.5" disk.
  53. * USA $10 an hour for 1200 baud connection at 18:00 PST from Seattle, WA USA.
  54. *
  55. * I reserve all other rights. This source code is made available "AS IS" and I
  56. * make no warranties for it's fitness for any purpose.
  57. *
  58. *------------------------------------------------------------------------------
  59. *
  60. * I hate assembling 3,000 lines of include files. How about you?
  61. *
  62. * External EXEC references
  63. _Supervisor    EQU    -6*5
  64. _Forbid        EQU    -6*22
  65. _Permit        EQU    -6*23
  66. _AllocMem    EQU    -6*33
  67. _FindTask    EQU    -6*49
  68. _OpenLibrary    EQU    -6*68
  69. _CloseLibrary    EQU    -6*69
  70. _OpenDevice    EQU    -6*74
  71. _CloseDevice    EQU    -6*75
  72. _DOIO        EQU    -6*76
  73. *
  74. * External AmigaDOG references
  75. _Write        EQU    -6*8
  76. _Output        EQU    -6*10
  77. *
  78. * Startup code
  79.         MOVE.L    A7,D5
  80.         LEA    ThePayloadData(PC),A4
  81.         MOVEA.L    4,A6
  82. *
  83. * Call the "dog"
  84.         MOVEQ    #0,D0
  85.         LEA    DogName(PC),A1
  86.         JSR    _OpenLibrary(A6)
  87.         MOVEA.L    D0,A5
  88.         TST.L    D0
  89.         BEQ.S    FireNeutronBomb
  90. *
  91. * Open intuition
  92.         MOVEQ    #0,D0
  93.         LEA    IntuiName(PC),A1
  94.         JSR    _OpenLibrary(A6)
  95.         MOVE.L    D0,IntuiBase(A4)
  96.         TST.L    D0
  97.         BNE.S    LibrariesOpen
  98. *
  99. * We arrive here because the system is in a phrase "royally fucked". Since the
  100. * Amiga is not prone to this, some menacing outside influence must have caused
  101. * it. Fight back by dropping a "Neutron bomb" on the rascals.
  102. FireNeutronBomb    LEA    TheBomb(PC),A5
  103.         JSR    _Supervisor(A6)
  104.         DC.W    $4AFC
  105.  
  106. TheBomb        MOVE.L    #'HELP',0    ; Kiss off Ctrl-Amiga-Amiga
  107.         ADDQ.L    #1,A7    ; The ONE hole in the 680X0's protection...
  108.         RTE
  109.  
  110. *
  111. * Grab our screen's pointer from intuition.base
  112. LibrariesOpen    MOVEA.L    D0,A0
  113.         MOVE.L    60(A0),MyScreen(A4)
  114. *
  115. * Allocate ram for payload.
  116.         MOVE.L    #$10001,D1
  117.         MOVE.L    #PayloadSize,D0
  118.         JSR    _AllocMem(A6)
  119.         TST.L    D0
  120.         BEQ.S    MissedMoon
  121.         MOVEA.L    D0,A3
  122. *
  123. * Copy payload to this hunk of ram
  124.         MOVEQ    #PayloadSize/4-1,D0
  125.         MOVEA.L    A3,A1
  126.         LEA    ThePayload(PC),A0
  127. 0$        MOVE.L    (A0)+,(A1)+
  128.         DBF    D0,0$
  129. *
  130. * Init the port to use to access the input.device
  131.         SUBA.L    A1,A1
  132.         JSR    _FindTask(A6)
  133.         LEA    InputPort(PC),A2
  134.         MOVE.L    D0,16(A2)
  135. *
  136. * Open the input device
  137.         MOVEQ    #0,D1
  138.         MOVEQ    #0,D0
  139.         LEA    InputIOReq(PC),A1
  140.         LEA    InputName(PC),A0
  141.         JSR    _OpenDevice(A6)
  142.         TST.L    D0
  143.         BNE.S    MissedMoon
  144. *
  145. * Add payload to input stream
  146.         LEA    InputIOReq(PC),A1
  147.         LEA    PayloadData(A3),A0
  148.         LEA    InputIRQ(A0),A2
  149.         MOVE.L    A0,14(A2)    ; Init IRQ data pointer
  150.         MOVE.L    A3,18(A2)    ; Init IRQ code pointer
  151.         MOVE.L    A2,40(A1)    ; Pointer to Payload's IRQ
  152.         MOVE.W    #9,28(A1)
  153.         JSR    _DOIO(A6)
  154.         LEA    Logo(PC),A0
  155.         TST.L    D0
  156.         BEQ.S    Exit
  157. MissedMoon    LEA    Ooops(PC),A0
  158.  
  159. Exit        MOVEA.L    A0,A2
  160.         MOVE.L    A0,D3
  161. 0$        TST.B    (A0)+
  162.         BNE.S    0$
  163.         SUBA.L    D3,A0
  164.         MOVE.L    A0,D3
  165.         SUBQ.L    #1,D3        ;Length
  166.         MOVE.L    A2,D2        ;Buffer
  167.         JSR    _Output(A5)
  168.         MOVE.L    D0,D1        ;FileHandle
  169.         JSR    _Write(A5)
  170.  
  171.         MOVEA.L    A5,A1
  172.         JSR    _CloseLibrary(A6)
  173. *
  174. * Intuition is left open since the payload "uses" it.
  175.         LEA    InputIOReq(PC),A1
  176.         JSR    _CloseDevice(A6)
  177.         MOVEQ    #0,D0
  178.         MOVEA.L    D5,A7
  179.         RTS
  180.  
  181. *
  182. * Payload, this is the handler routine that all of the above code installs
  183. PayloadStart
  184. ThePayload    MOVEM.L    D1/A0-A2/A4/A6,-(A7)
  185. *
  186. * Setup registers
  187.         MOVEA.L    A0,A2
  188.         MOVEA.L    A1,A4
  189. *
  190. * Is this a RawMouse event?
  191.         CMPI.B    #2,4(A2)
  192.         BNE.S    0$
  193. *
  194. * Record we saw the mouse move
  195.         ST    (A4)
  196.         BRA.S    1$
  197. *
  198. * Non-mouse event
  199. *
  200. * Has the mouse moved since last time through?
  201. 0$        TST.W    (A4)
  202.         BEQ.S    1$
  203. *
  204. * Is this a raw key code?
  205.         CMPI.B    #1,4(A2)
  206.         BNE.S    1$
  207. *
  208. * Must be a key DOWN code
  209.         TST.B    7(A2)
  210.         BMI.S    1$
  211. *
  212. * Is the front screen my screen?
  213.         MOVEA.L    IntuiBase(A4),A0
  214.         MOVEA.L    60(A0),A1
  215.         CMPA.L    MyScreen(A4),A1        ; Correct screen?
  216.         BNE.S    1$
  217. *
  218. * This is a key down event, is it a non-system key?
  219.         MOVEQ    #$50,D0
  220.         AND.W    8(A2),D0
  221.         BNE.S    1$
  222. *
  223. * This key be for US. Lock out pesky task switcher.
  224.         MOVEA.L    4,A6
  225.         JSR    _Forbid(A6)
  226.         LEA    MouseUp(A4),A1
  227.         LEA    MouseDown(A4),A0
  228.         EXG    A0,A2
  229.         MOVE.L    A0,(A1)        ; Tack event after mouse up event
  230.         MOVE.L    A1,(A2)        ; Tack mouse up after mouse down
  231.         ; Return mouse down as the first event, clever eh?
  232.         SF    (A4)
  233.         JSR    _Permit(A6)
  234. 1$        MOVE.L    A2,D0
  235.         MOVEM.L    (A7)+,D1/A0-A2/A4/A6
  236.         RTS       
  237.  
  238. ThePayloadData
  239. PayloadData    EQU    *-PayloadStart
  240.         DC.W    0    ; Mouse moved variable
  241. IntuiBase    EQU    *-ThePayloadData
  242.         DC.L    0    ; Intuition base
  243. MyScreen    EQU    *-ThePayloadData
  244.         DC.L    0    ; MyScreen pointer
  245. MouseDown    EQU    *-ThePayloadData
  246.         ; Mouse down event
  247.         DC.L    0,$02000068
  248.         DC.W    $C000
  249.         DC.L    0,0,0
  250. MouseUp        EQU    *-ThePayloadData
  251.         ; Mouse up event
  252.         DC.L    0,$020000E8
  253.         DC.W    $8000
  254.         DC.L    0,0,0
  255. InputIRQ    EQU    *-ThePayloadData
  256.         ; input.device IRQ
  257.         DC.L    0,0
  258.         DC.W    $0233
  259.         DC.L    0
  260.         DC.L    0    ; Data
  261.         DC.L    0    ; Code
  262. PayloadEnd
  263. PayloadSize    EQU    PayloadEnd-PayloadStart
  264.  
  265. DogName        DC.B    'dos.library',0
  266. IntuiName    DC.B    'intuition.library',0
  267. InputName    DC.B    'input.device',0
  268. Logo        DC.B    'MoonMouse 0.1 installed. Copyright 1987 Scott Turner'
  269.         DC.B    10,0
  270. Ooops        DC.B    'Ooops, MoonMouse missed the moon, sorry.',10,0
  271.         DS.W    0
  272.  
  273. InputPort    DC.L    0    ;0
  274.         DC.L    0    ;4
  275.         DC.W    $0400    ;8
  276.         DC.L    0    ;10
  277.         DC.B    0    ;14
  278.         DC.B    31    ;15
  279.         DC.L    0    ;16    Task addr goes here
  280. LH1        DC.L    LH2    ;20
  281. LH2        DC.L    0    ;24
  282.         DC.L    LH1    ;28
  283.         DC.B    0    ;32
  284.         DC.B    0    ;33
  285. InputIOReq    DC.L    0    ;0
  286.         DC.L    0    ;4
  287.         DC.B    5    ;8
  288.         DC.B    0    ;9
  289.         DC.L    0    ;10
  290.         DC.L    InputPort ;14
  291.         DC.W    48    ;18
  292.         DC.L    0    ;20
  293.         DC.L    0    ;24
  294.         DC.W    9    ;28
  295.         DC.W    0    ;30
  296.         DC.L    0    ;32
  297.         DC.L    0    ;36
  298.         DC.L    0    ;40 IO_DATA
  299.         DC.L    0    ;44
  300.  
  301.         END
  302.