home *** CD-ROM | disk | FTP | other *** search
/ Dream 44 / Amiga_Dream_44.iso / RiscPc / jeux / cheats / appdha.arc / TechDocs / 01WriteExt next >
Text File  |  1997-01-25  |  15KB  |  319 lines

  1. Writing external tasks for Desktop Hacker
  2. Document d01/22 AjC
  3. =============================================================================
  4.  
  5.  The old external code system used by The Hacker is no longer supported.
  6. Instead, you should code a normal WIMP task, and use Desktop Hacker's SWIs
  7. and messages to communicate. This has the advantage that you don't need to
  8. program in ARM code - you can use C, BASIC, or any other language. Create
  9. yourself an application with a Desktop Hacker axe somewhere in the icon;
  10. ideally, the application name should begin !dH, but this may not always be
  11. appropriate.
  12.  
  13.  There are two parts to Desktop Hacker: the actual DesktopHacker module task,
  14. which provides all the hacking facilities that the user uses; and the SWIVe
  15. code (so named because it works by claiming the SWI hardware vector), which,
  16. when the hot-keys are pressed, stops the game and starts a WIMP task. SWIVe
  17. sends WIMP messages to Desktop Hacker (and external tasks; it is a broadcast
  18. message) when the game is stopped, restarted, or quit. Desktop Hacker sends
  19. a message to SWIVe telling it to continue when the Continue button is
  20. clicked, or when Select is clicked on the icon bar icon, or whatever. Desktop
  21. Hacker may also send a Message_Quit (0) telling SWIVe to shut the game down
  22. entirely. Other external tasks (including the Task Manager) may send messages
  23. to SWIVe. SWIVe will appear in the Task Display either as 'Desktop Hacker
  24. Game' if the program interrupted did not call Wimp_Initialise, or the real
  25. name of the stopped task if it did.
  26.  
  27.  Apart from the memory of the SWIVe task, there are a few other details
  28. Desktop Hacker holds. The only directly readable one is the environment
  29. variable dHacker$Obey$Dir, which holds what Obey$Dir held when the hot-keys
  30. were pressed.
  31.  
  32. ---------+-------------------------------------------------- WIMP messages --
  33.          |
  34.          |                                                 Message_HackerTask
  35.          |                                                     Message &82740
  36.          |
  37.  Purpose | This message is broadcast by SWIVe to inform Desktop Hacker and
  38.          | any external tasks of a hacking session starting/ending. No
  39.          | parameters are passed using the message; external tasks should
  40.          | call the SWI DesktopHacker_ReadState to find out the current
  41.          | state.
  42.          |
  43.          | SWIVe sends this message when:
  44.          |
  45.          | (a) The hotkeys have been pressed (or dHacker has been activated
  46.          |     by a hackpoint) and the task is initialising.
  47.          | (b) SWIVe has been told to continue by Desktop Hacker, or an
  48.          |     external task, and the task is ending.
  49.          | (c) SWIVe has been told to quit by Desktop Hacker, an external
  50.          |     task, or the Task Manager, and the task is ending.
  51.          | (d) SWIVe has been told to load a game file; this has been done
  52.          |     successfully, and a completely new game position is
  53.          |     established.
  54.          |
  55. ---------+-------------------------------------------------------------------
  56.          |
  57.          |                                             Message_HackerContinue
  58.          |                                                     Message &82741
  59.          |
  60.  Purpose | This message is sent by Desktop Hacker, or any other task, to
  61.          | tell the SWIVe code to restart the stopped program. No parameters
  62.          | are passed.
  63.          |
  64. ---------+-------------------------------------------------------------------
  65.          |
  66.          |                                             Message_HackerGameFile
  67.          |                                                     Message &82742
  68.          |
  69.  Purpose | This message is sent by Desktop Hacker, or any other task, to
  70.          | tell the SWIVe code to load in the game file whose path is
  71.          | specified.
  72.          |
  73.   Format | +12 = 0 (this is never a reply)
  74.          | +16 = &82742 (Message_HackerGameFile)
  75.          | +20 = unused
  76.          | +24 = unused
  77.          | +28 = unused
  78.          | +32 = unused
  79.          | +36 = unused
  80.          | +40 = unused
  81.          | +44 = null-terminated filename of game file to load
  82.          |
  83. ---------+-------------------------------------------------------------------
  84.          |
  85.          |                                              Message_HackerAltered
  86.          |                                                     Message &82743
  87.          |
  88.  Purpose | This message is broadcast by Desktop Hacker whenever the memory
  89.          | of the stopped task has been altered, either by the user, or by
  90.          | certain DesktopHacker_MemoryAccess calls. External tasks that
  91.          | display details in a window that depend on the contents of the
  92.          | stopped game's application memory should rescan and redraw where
  93.          | necessary when this message is received. No parameters are passed.
  94.          |
  95.          | Note that this message is not broadcast when a game file is loaded
  96.          | which changes the application memory contents completely; instead
  97.          | the SWIVe code broadcasts Message_HackerTask.
  98.          |
  99. ---------+----------------------------------------------------------- SWIs --
  100.          |
  101.          |                                            DesktopHacker_ReadState
  102.          |                                                         SWI &82740
  103.          |
  104.  Purpose | This SWI allows external tasks to read information about Desktop
  105.          | Hacker which may be needed to perform their function.
  106.          |
  107. On entry | -
  108.          |
  109.  On exit | R0=0 if Desktop Hacker is idling or running a single-tasking task
  110.          | R0=1 if Desktop Hacker is running a task that's called Wimp_Init
  111.          | R0=2 if Desktop Hacker has interrupted a task
  112.          | R1=task handle of hacked task if R0=1 or 2, else preserved
  113.          |
  114.      Use | If your task requires the application memory of a hacked game,
  115.          | you should only allow use of the task when R0=2.
  116.          |
  117.          | Note that the task specified in R1 does not have the same in it
  118.          | when stopped as when it is running. See the document "GameFormat"
  119.          | (d02) for details of what is in the application area when stopped.
  120.          | If you just want to access the main application area, though, and
  121.          | not the full info bundles, you should use the SWI DesktopHacker_
  122.          | MemoryAccess.
  123.          |
  124.          | If you do access Desktop Hacker or its game's WimpSlot directly
  125.          | using Wimp_TransferBlock, be aware that there is a bug in RISC OS
  126.          | 3.7's implementation of the SWI affecting use of the call twice
  127.          | or more in a row between code synchronisations. To combat this,
  128.          | you should call OS_SynchroniseCodeAreas once after each call to
  129.          | TransferBlock. Failure to do so will result in things going wrong
  130.          | in inexplicable ways - you have been warned.
  131.          |
  132. ---------+-------------------------------------------------------------------
  133.          |
  134.          |                                         DesktopHacker_MemoryAccess
  135.          |                                                         SWI &82741
  136.          |
  137.          | This SWI loads and stores data to and from the game's WimpSlot.
  138.          | You should always use this SWI to access the game's application
  139.          | memory, rather than using Wimp_TransferBlock, as (a) this SWI
  140.          | automatically re-maps the word at &8000, and (b) it uses a cache
  141.          | in RMA to make access much quicker (Wimp_TransferBlock is very,
  142.          | very slow). At present, the cache is 8K long, but this may change.
  143.          | (For performance reasons the cache may not exceed 32K.) If you do
  144.          | poke the game using Wimp_TransferBlock, you must call
  145.          | DesktopHacker_MemoryAccess 4 to invalidate the cache, or other
  146.          | users of the cache may not like it.
  147.          |
  148.          | Note, if you're searching through memory, you will find it is much
  149.          | quicker to search forwards rather than backwards, due to the
  150.          | rather simplistic cache algorithm. Another point to note is that
  151.          | at this point only read-buffering is performed, not
  152.          | write-buffering.
  153.          |
  154.          | No MemoryAccess operation may be used when the game is not being
  155.          | hacked (R0 on exit from DesktopHacker_ReadState <> 2).
  156.          |
  157. On entry | R0=reason code
  158.          | other registers dependent on reason code
  159.          |
  160.  On exit | dependent on reason code
  161.          |
  162.          |                                       DesktopHacker_MemoryAccess 0
  163.          |
  164.          | Load one word
  165.          |
  166. On entry | R0=0 (reason code)
  167.          | R1=address
  168.          |
  169.  On exit | R0=value
  170.          | R1 preserved
  171.          |
  172.          |                                       DesktopHacker_MemoryAccess 1
  173.          |
  174.          | Store one word
  175.          |
  176. On entry | R0=1 (reason code)
  177.          | R1=address
  178.          | R2=value
  179.          |
  180.  On exit | R0 corrupted
  181.          | R1, R2 preserved
  182.          |
  183.          |                                       DesktopHacker_MemoryAccess 2
  184.          |
  185.          | Load block
  186.          |
  187. On entry | R0=2 (reason code)
  188.          | R1=start address (game)
  189.          | R2=length
  190.          | R3=buffer (in your memory)
  191.          |
  192.  On exit | R0-R3 preserved
  193.          |
  194.          |                                       DesktopHacker_MemoryAccess 3
  195.          |
  196.          | Store block
  197.          |
  198. On entry | R0=3 (reason code)
  199.          | R1=start address (game)
  200.          | R2=length
  201.          | R3=buffer (in your memory)
  202.          | R4=your task handle, or -1 if in unpaged memory such as RMA
  203.          |
  204.  On exit | R0-R4 preserved
  205.          |
  206.      Use | Note that the buffer must be paged in when the SWI is used,
  207.          | despite the fact that you pass the task handle. The task handle
  208.          | is needed by Wimp_TransferBlock for efficient transfer.
  209.          |
  210.          |                                       DesktopHacker_MemoryAccess 4
  211.          |
  212.          | Invalidate cache
  213.          |
  214. On entry | R0=4 (reason code)
  215.          |
  216.  On exit | R0 preserved
  217.          |
  218.          | Under Desktop Hacker 1.05 or later, invalidating the cache also
  219.          | ensures that its contents are zeroed. This is to make sure that
  220.          | programs like dHMusic don't find portions of the game's memory in
  221.          | the RMA and generate false alarms.
  222.          |
  223.          |                                       DesktopHacker_MemoryAccess 5
  224.          |
  225.          | Find length of game
  226.          |
  227. On entry | R0=5 (reason code)
  228.          |
  229.  On exit | R0=length of game's real WimpSlot in bytes
  230.          |
  231.   Errors | MemoryAccess cannot be used as no game is hacking (&82760)
  232.          | Bad DesktopHacker_MemoryAccess address (&8275F)
  233.          | Unknown DesktopHacker_MemoryAccess reason code (&82750)
  234.          | Any errors returned by Wimp_TransferBlock
  235.          |
  236. ---------+-------------------------------------------------------------------
  237.          |
  238.          |                                             DesktopHacker_ReadList
  239.          |                                                         SWI &82742
  240.          |
  241. On entry | R0=list number
  242.          |
  243.  On exit | R0=Desktop Hacker's task handle
  244.          | R1=pointer to list block
  245.          | R2=length of list block
  246.          |
  247.      Use | On exit R1 points to a list, as specified by 'ListFormat' (d03),
  248.          | - the only difference being that the first four bytes are an
  249.          | offset to the first byte after the end of the list, rather than
  250.          | the header "List".
  251.          |
  252.          | Note that the pointer is in Desktop Hacker's application space.
  253.          | If you want to read the contents of the list you will need to use
  254.          | Wimp_TransferBlock with the R0 and R1 supplied by this SWI, and
  255.          | the length of block to transfer as R2.
  256.          |
  257.          | There is no SWI provided to alter lists - doing so would be very
  258.          | slow as very many calls to Wimp_TransferBlock would be needed,
  259.          | along, perhaps, with resizing of the WimpSlot which is not
  260.          | possible as Desktop Hacker is not paged in. If you do want to send
  261.          | a list to Desktop Hacker, simply use the data transfer protocol -
  262.          | make up a Wimp message block as if a list file was dragged to
  263.          | Desktop Hacker (use the icon bar (-2) as the destination window
  264.          | handle; the destination icon handle is unimportant), using
  265.          | Message_DataSave. Data transfer will be conducted as normal, and
  266.          | the window containing the list will be opened. Note that Desktop
  267.          | Hacker does not yet support RAMTransfer, but it is very likely
  268.          | that it will do in future, so please support it if you can!
  269.          |
  270.   Errors | Invalid list number (&8275E)
  271.          | Any errors returned by Wimp_TransferBlock
  272.          |
  273. ---------+-------------------------------------------------------------------
  274.          |
  275.          |                                           DesktopHacker_BreakPoint
  276.          |                                                         SWI &82743
  277.          |
  278. On entry | -
  279.          |
  280.  On exit | Registers preserved
  281.          |
  282.      Use | This SWI sets a flag which tells Desktop Hacker to interrupt as
  283.          | soon as possible. Usually, this will be immediately, but it may
  284.          | be called later if IRQs or FIQs are disabled, or the processor is
  285.          | in IRQ or FIQ mode. Of course it will also only interrupt if you
  286.          | are the current hacking task.
  287.          |
  288.          | In order to get all the registers for the Game Info window, not
  289.          | just R0-R8, this SWI is trapped in the SWIVe code; the actual
  290.          | SWI command code does nothing. You will not receive an error if
  291.          | the situation isn't suitable for a BreakPoint. Instead, just the
  292.          | SWI command code is called, and so nothing will happen.
  293.          |
  294.          | This SWI only does anything useful on Desktop Hacker 1.06 and
  295.          | above.
  296.          |
  297. ---------+----------------------------------------------------- * commands --
  298.          |
  299.          |                                           *DesktopHacker <command>
  300.          |
  301.  Purpose | Start a new task or game file to be hacked
  302.          |
  303.      Use | This command is used by Desktop Hacker when a game is dragged to
  304.          | it. It cannot be used from the command line. However, there is no
  305.          | reason why external tasks should not use it, if they need to. It
  306.          | should only be used by being passed to Wimp_StartTask, and to
  307.          | be sure of compatibility with special fields, you should surround
  308.          | the parameter of a Run command (if that's what you're using) with
  309.          | quotes. For example, for BASIC:
  310.          |
  311.          | SYS "Wimp_StartTask","DesktopHacker Run ""CFS#adfs::HD.$.File"""
  312.          |
  313. ---------+-------------------------------------------------------------------
  314.          |
  315.          |                                                    *Desktop_Hacker
  316.          |
  317.  Purpose | This is just the command used to start the Desktop Hacker WIMP
  318.          | task, as is needed by module tasks. Don't use it!
  319.          |