Code: Select all
<mamecheat version="1">
<cheat desc="Stop Screen Flash on Shooting">
<script state="on">
<action>temp0 =maincpu.pb@8005550f</action>
</script>
<script state="run">
<action>maincpu.pb@8005550f=14</action>
</script>
<script state="off">
<action>maincpu.pb@8005550f=temp0</action>
</script>
</cheat>
</mamecheat>
Story Time
Because it is my first ever MAME cheat, I would like to write a bit about the discovery hopefully to help others in the future write similar cheats.
First step was figuring out more or less where the relevant instructions were, this was done by tracing using the debugger:
Code: Select all
trace tracefile.txt,0,noloop
Code: Select all
trace off
But It was still a hefty file at ~500k instructions, so I had to go through it programatically.
I wrote a Python script that found all the lines that appeared 5 times, this amounted to only 1779 lines of instructions.
Going through 1779 lines of assembly code is a hassle to say the least. So I would rather find an easier solution.
I hypothesized that the flash would happen in some kind of conditional, e.g. an if-statement. And with the MIPS instruction set, this is done using the
Code: Select all
beq # Branch on equal
Code: Select all
bne # Branch on not equal
First step was looking up how many of these statements there were, and this amounted to 102 such statements. Only a 102 statements! It should be possible to go through these by hand.
So I changed the python script to output a cheat file containing one cheat for every such statement, changing it from a beq to a bne or the other way around. This was the python code I ended up with:
Code: Select all
import collections
print("<mamecheat version=\"1\">")
with open("trace.txt","r") as trace:
lines = trace.readlines()
dupl = collections.defaultdict(list)
for i, e in enumerate(lines):
dupl[e].append(i)
bneqcounter = 0
for k, v in dupl.items():
if len(v) == 5:
hexval = k.split(":")[0]
if ("beq" in k or "bne" in k):
bneqcounter += 1
location = hex(int(hexval, 16) + 3)[2:]
print(" <cheat desc=\"" + str(bneqcounter) + "\">")
print(" <script state=\"run\">")
if ("beq" in k):
print(" <action>maincpu.pb@" + location + "=14</action>")
else:
print(" <action>maincpu.pb@" + location + "=10</action>")
print(" </script>")
print(" </cheat>")
print("</mamecheat>")
Remember, what I just outlined was the succesful route, there were many unsuccesful ones on the path to this one.
I hope this helps someone in the future write a cheat for another lightgun game, or any game at all.