User:Andlabs/MAME Cheats

The MAME cheat engine is analogous to in-emulator Game Genie/Pro Action Replay/GameShark/etc. plugins. Though mainly intended for actual heat codes, the engine is useful for changing code or memory on the fly, making it easier to find unused content if you are doing a code analysis.

Somewhere around version 0.130, Aaron Giles rewrote the cheat engine to tie it with the debugger, allowing more intelligent cheats at the cost of introducing a third cheat format (this time based on XML) and getting rid of the ability to make cheats from within MAME. As no updated tutorial exists (outside the source comment for the cheat engine itself), this page serves as an introduction to making cheats.

Two resources to have in hand (and the way I (andlabs) started) is to take the cheat files provided by Pugsy and the documentation at the top of the MAME cheat engine source code and then just modify the example cheats. The README in the cheat pack download will tell you not to extract the cheat pack, but of course in this case you will need to. (The cheat pack can also help with reverse-engineering as the cheats will tell you what important memory and ROM locations are!)

Galaxy Force II (gforce2) will be used as an example.

Cheat files are text files with the filename form gamename.xml. For instance, the cheat file for the gforce2 set would be called gforce2.xml.

When running MAME directly, use the -cheat option to enable cheats and the -cheatpath option to tell MAME where you put these cheat files. For instance, $ ls cheats gforce2.xml $ mame64d -cheat -cheatpath cheats -window gforce2 (TODO default directory?)

The file format is mostly standard XML. There is no  directive; the files merely start with the opening tag:  ...     ... Leave the version attribute at 1 for now.

When running MAME with cheats, press Tab to open the MAME menu. You will now see a Cheat option; enter that to see your list of cheats.

Cheats consist of a series of actions that occur on a given state. There are four states: Actions are debugger statements with optional conditions.
 * on - when the cheat is turned on
 * run</tt> - while the cheat is on
 * off</tt> - when the cheat is turned off
 * change</tt> - ??????? TODO

All numbers are hexadecimal; no prefix is needed.

The format of an address is chip.ms@address where chip</tt> is the chip name (maincpu</tt>, soundcpu</tt>, etc.), m</tt> is a memory mode, s</tt> is a size, and address</tt> is the actual address. I am not entirely sure what the memory modes are (TODO) but for gforce2 m</tt> is used for ROM and p</tt> is used for everything else. Size is b</tt> for byte, w</tt> for word (2 bytes), d</tt> for doubleword (4 bytes), and q</tt> for quadword (8 bytes). (TODO example)

notes
 * cheats are irreversible by themselves