Post subject: TASing pinball ROMs in MAME
Joined: 4/10/2019
Posts: 5
Hi! I'm a fan of both TASes and a player of competitive pinball. I found out that MAME supports a limited subset of pinball ROMs, including games from the classic 90s era like The Addams Family and Attack From Mars. I immediately wondered about opportunities for TASing, trying to imagine the ideal set of inputs to complete some objective as fast as possible. I stopped by #tasvideos on IRC, and they suggested that I join the forum and post my progress and ask for needed help. I understand that pinball roms are not an appropriate for the actual TASvideos concept, because ultimately they are not a video game. The visual aspect is likely to be a spastic flurry of conflicting animations, definitely not something that most people would find entertaining. And because most games loop the score back to 0 when the maximum score is reached, even if all the other things were not true, it still wouldn't be eligible. With all that said, my small group of friends and I have been discussing a few different "attacks" for Lua speedrunning of pinball ROMs - High score attack (get to max score) - Wizard mode attack (complete the final "Wizard Mode" which many games feature after completing many other modes) - 100% (complete all game features) I've downloaded a recent MAME mainline and have a basic understanding that a callback occurs once every emulator frame. I'm able to write proof of concept Lua code that would eventually complete a high score attack. I'm not using MAME-rr, unfortunately, because the version it is forked from doesn't support the ROMs in question. The issue that prompts my post has to do with the interaction between the "switches" which serve as the inputs to the ROM and the emulation of the ROM. Briefly : - There is a framerate of the emulation (which is probably the frame rate of the DMD (dot matrix display) - There is the framerate of the actual ROM (which is how long a switch has to be held down in order to register a "1" state) Is there some way, possibly by examining the MAME source, that I could determine non-experimentally how to ensure that all switch presses are registered? I'm not sure of where to start, but iteratively hacking at it out of MAME ignorance is opaque enough to motivate asking for help from the experts!
Post subject: Re: TASing pinball ROMs in MAME
DrD2k9
He/Him
Editor, Judge, Expert player (2220)
Joined: 8/21/2016
Posts: 1090
Location: US
CrowdSorcerer wrote:
Hi! I'm a fan of both TASes and a player of competitive pinball. I found out that MAME supports a limited subset of pinball ROMs, including games from the classic 90s era like The Addams Family and Attack From Mars. I immediately wondered about opportunities for TASing, trying to imagine the ideal set of inputs to complete some objective as fast as possible. I stopped by #tasvideos on IRC, and they suggested that I join the forum and post my progress and ask for needed help. I understand that pinball roms are not an appropriate for the actual TASvideos concept, because ultimately they are not a video game. The visual aspect is likely to be a spastic flurry of conflicting animations, definitely not something that most people would find entertaining. And because most games loop the score back to 0 when the maximum score is reached, even if all the other things were not true, it still wouldn't be eligible. With all that said, my small group of friends and I have been discussing a few different "attacks" for Lua speedrunning of pinball ROMs - High score attack (get to max score) - Wizard mode attack (complete the final "Wizard Mode" which many games feature after completing many other modes) - 100% (complete all game features) I've downloaded a recent MAME mainline and have a basic understanding that a callback occurs once every emulator frame. I'm able to write proof of concept Lua code that would eventually complete a high score attack. I'm not using MAME-rr, unfortunately, because the version it is forked from doesn't support the ROMs in question. The issue that prompts my post has to do with the interaction between the "switches" which serve as the inputs to the ROM and the emulation of the ROM. Briefly : - There is a framerate of the emulation (which is probably the frame rate of the DMD (dot matrix display) - There is the framerate of the actual ROM (which is how long a switch has to be held down in order to register a "1" state) Is there some way, possibly by examining the MAME source, that I could determine non-experimentally how to ensure that all switch presses are registered? I'm not sure of where to start, but iteratively hacking at it out of MAME ignorance is opaque enough to motivate asking for help from the experts!
I don't have enough knowledge of MAME or Pinball machines to answer your questions, but dwangoAC may be able to help. I remember him showing interest in human speedrunning of pinball machines a while back. I think he even has a pinball machine or two of his own. Maybe he can offer some knowledge/perspective in this area. You can likely find him in Discord.
Site Admin, Skilled player (1255)
Joined: 4/17/2010
Posts: 11486
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
Your best bet is finding the code in your game (or games) that polls input, and attaching a lua hook to that code. That way every time input is about to be read, you could feed it precisely. The question is, do they even allow to attach lua functions to reading memory? I'm looking at their luaengine code and I can't tell at all. https://github.com/mamedev/mame/blob/master/src/frontend/mame/luaengine.cpp#L791 Their lua docs are known for being miser: https://docs.mamedev.org/techspecs/luaengine.html And the implementation is known for being absolutely incomprehensible, so all you have is asking crazyc, the author.
Warning: When making decisions, I try to collect as much data as possible before actually deciding. I try to abstract away and see the principles behind real world events and people's opinions. I try to generalize them and turn into something clear and reusable. I hate depending on unpredictable and having to make lottery guesses. Any problem can be solved by systems thinking and acting.
Joined: 4/10/2019
Posts: 5
Thanks all for the responses! @feos : From what I can tell, the only callbacks MAMEline Lua features are listed here - https://github.com/mamedev/mame/blob/7e623cc8862f7b04a65924a99a9ab354008e2eea/src/frontend/mame/luaengine.cpp#L735 The only one that seems usable for me is the callback at the end of the frame, so my current plan is : a) write code that does things via the end-of-frame callback b) occasionally sleeping for [x] frames c) experimentally determining values of [x] vis a vis the ROM "sampling rate"
Site Admin, Skilled player (1255)
Joined: 4/17/2010
Posts: 11486
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
Lua callbacks for memory read/write/execute, and input poll are extremely useful in TASing, so if we ever want to make use of mame for TASing in any way in future, we should request that those are implemented. Or implement them ourselves, sending a pull request. The infrastructure for memory hooking is already there, it's just a matter of exposing it to lua. Dunno about input polling, it is at least not trivial IIRC.
Warning: When making decisions, I try to collect as much data as possible before actually deciding. I try to abstract away and see the principles behind real world events and people's opinions. I try to generalize them and turn into something clear and reusable. I hate depending on unpredictable and having to make lottery guesses. Any problem can be solved by systems thinking and acting.
Joined: 4/10/2019
Posts: 5
@feos : Is there a list somewhere of functionality that mame-RR adds to MAME? A friend who has need of the Lua interface in mainline MAME is potentially willing and able to contribute patches, and so it would be good to understand how exactly mame-RR differs. Even a list of all of the novel callbacks exposed via its lua interface would be a good starting point. Edit : I found https://github.com/TASVideos/mame-rr/wiki/Lua-scripting-functions, but the general question stands!
Site Admin, Skilled player (1255)
Joined: 4/17/2010
Posts: 11486
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
Warning: When making decisions, I try to collect as much data as possible before actually deciding. I try to abstract away and see the principles behind real world events and people's opinions. I try to generalize them and turn into something clear and reusable. I hate depending on unpredictable and having to make lottery guesses. Any problem can be solved by systems thinking and acting.
Joined: 4/10/2019
Posts: 5
My friend points out "memory_registerwrite" ... :)
Site Admin, Skilled player (1255)
Joined: 4/17/2010
Posts: 11486
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
That's weird, no execute or write hooks... Here's how it's done in FBA, no idea if it helps: https://github.com/TASVideos/fbarr/blob/master/fbarr/src/burner/luaengine.cpp#L1044 Your wiki link gets killed by the comma that goes after.
Warning: When making decisions, I try to collect as much data as possible before actually deciding. I try to abstract away and see the principles behind real world events and people's opinions. I try to generalize them and turn into something clear and reusable. I hate depending on unpredictable and having to make lottery guesses. Any problem can be solved by systems thinking and acting.
Skilled player (1672)
Joined: 7/1/2013
Posts: 448
CrowdSorcerer, are you familiar with PinMAME?
Joined: 4/10/2019
Posts: 5
£e Nécroyeur wrote:
CrowdSorcerer, are you familiar with PinMAME?
Yes, but unfortunately it's not suitable for this project. The only API/interface is a windows COM interface, which right off the top seems to be inappropriate for TAS usage. I don't actually need any of the table modeling or scripting to do what I want, I "just" need a modern version of MAME with a set of callbacks in the Lua interface similar to what mame-RR does.
Site Admin, Skilled player (1255)
Joined: 4/17/2010
Posts: 11486
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
I provided a few hints here, subscribing to all reads should be quite possible: https://github.com/mamedev/mame/issues/3649#issuecomment-491249964 See if you can make it pass the address (and value if needed) over to lua. Hook without arguments works, I tested on exec.
Warning: When making decisions, I try to collect as much data as possible before actually deciding. I try to abstract away and see the principles behind real world events and people's opinions. I try to generalize them and turn into something clear and reusable. I hate depending on unpredictable and having to make lottery guesses. Any problem can be solved by systems thinking and acting.