MAME Lua Debug Syntax

If you are having problems finding or using cheats for an Emulator (particularly MAME/MESS) or have found a trick that you wish to share this is the place to do it. But please read the Cheat FAQ first.
Post Reply
astrofy
Posts: 3
Joined: Thu Nov 17, 2022 5:01 am

MAME Lua Debug Syntax

Post by astrofy »

Hello,

I've been trying to figure out the correct syntax for running "wpset" and "bpset" using Lua on MAME. I have been continually crashing MAME with a "Segmentation fault: 11" and I could really use a sanity check.

I've been referencing the MAME Lua documentation and have also found some quasi examples on this forum, but I haven't had any success. If anyone could help point me in the right direction on the proper syntax for these commands, I would be extremely grateful. Thanks!

Link to the relevant MAME Lua documentation: https://docs.mamedev.org/techspecs/luareference.html?highlight=debugger#debugger

Below is the code I've been attempting to use:

Code: Select all

-- variables
cpu = manager.machine.devices[":maincpu"]
programSpace = cpu.spaces["program"]

-- bpset attempts

cpu.bpset(0x00470e, function() print("test") end) 
-- gives me the following message "error: 	[string "..."]:2: attempt to call a nil value (field 'bpset')"

cpu.debug:bpset(0x00470e, function() print("test") end)
-- crashes mame and gives me the following error "Segmentation fault: 11"

-- wpset attempts
cpu.debug.wpset(programSpace, "rw", 0x10d4bc, 1, function() print("test") end)
-- crashes mame and gives me the following error "Segmentation fault: 11"
astrofy
Posts: 3
Joined: Thu Nov 17, 2022 5:01 am

Re: MAME Lua Debug Syntax

Post by astrofy »

EDIT: I've edited this post because it wasn't accurate. MAME was crashing because I was trying to pass in a Lua function callback instead of a MAME debugger statement. For whatever reason it didn't cause MAME .245 to crash so I jumped to the wrong conclusion. I'm keeping the part about the parameters I used to run MAME, just in case it is helpful to anyone.

This is the command string I used to run MAME. $: ./mame -console -w -debug -debugger none turfmast

-console // for the lua console
-w // to run in windowed mode
-debug // run MAME in debug mode
-debugger none // this one prevents MAME's default debugger from coming up. Useful when you want to handle your responses to bp's and wp's in code
turmast // run turfmaster ROM
Last edited by astrofy on Sat Nov 19, 2022 3:32 pm, edited 3 times in total.
astrofy
Posts: 3
Joined: Thu Nov 17, 2022 5:01 am

Re: MAME Lua Debug Syntax

Post by astrofy »

I was able to get it working after talking to some people in the MAME community. For the sake of completeness, I'm going to post my findings.

The gist of it is that I was trying to run a Lua Callback function as the action instead of a MAME debug command. Also in the documentation it mentions an optional conditional parameter in addtion to the optional action paramter. I was under the assumption that these optional parameters could be passed independently; however, it turns out that if you want to utilize the optional parameters, then you must use both of them.

Here is my code.

Code: Select all

cpu = manager.machine.devices[":maincpu"]
programSpace = cpu.spaces["program"]
debug = cpu.debug

debug:wpset(programSpace, "rw", 0x10d4bc, 1, '1', 'printf "Read @ %08X\n",wpaddr ; g')
In regards to the debug:wpset command, the last two arguments need to be strings.
  • '1' <- this is the [cond] parameter, aka the conditional parameter. It must evaluate to a non-zero number, so passing in a 1 will make it always run.
  • 'printf "Read @ %08X\n",wpaddr ; g' <- the [act] parameter, aka action parameter. This is a MAME debugger statement.
Some MAME debug actions can be found at this link: https://docs.mamedev.org/debugger/watchpoint.html#debugger-watchpoints-list
Post Reply