Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: how to parse MAME.XML to obtain 4 or 8 way info  (Read 872 times)

0 Members and 1 Guest are viewing this topic.

Justin

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 548
  • Last login:April 21, 2024, 11:12:11 pm
    • Centipede MAME cabinet
how to parse MAME.XML to obtain 4 or 8 way info
« on: January 26, 2023, 08:20:01 pm »
Im trying to write a BAT file that will parse the MAME.XML file and obtain the "way" of the joystick (4 or 8 way) for a given rom that I will pass on as an argument to the BAT file.
This will be used to set the motorized restrictor plate of my joystick automatically.

I have tried the well known XPATH.BAT code out there to use a simple XPATH command but it does NOT work except to match the first line of the XML file for whatever reason.  I think the XPATH.BAT is not robust as I keep getting odd results.

the XPATH command needed would be:
//machine[@name="pacman"]/control[@player="1"]/@ways

Anyone have any other ideas how to parse the XML file and obtain the joystick (4 or 8) way data for a given rom?  I need it to be scriptable, and preferably in the BAT format for compatibility with my other scripts...

"3 warps to Uranus" -- so I stopped playing!

Justin

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 548
  • Last login:April 21, 2024, 11:12:11 pm
    • Centipede MAME cabinet
Re: how to parse MAME.XML to obtain 4 or 8 way info
« Reply #1 on: January 26, 2023, 08:57:16 pm »
And here is a sample of the simplistic XML file I am parsing (it is a simplified version of mame.xml with just the 4/8 way info)

Code: [Select]
<mame build="0.251 (mame0251)" debug="no" mameconfig="10">
<machine name="005" sourcefile="sega/segag80r.cpp" sampleof="005">
<control type="joy" player="1" buttons="1" ways="4"/>
<control type="joy" player="2" buttons="1" ways="4"/>
</machine>
<machine name="10yard" sourcefile="irem/m58.cpp">
<control type="joy" player="1" buttons="2" ways="8"/>
<control type="joy" player="2" buttons="2" ways="8"/>
</machine>
<machine name="10yard85" sourcefile="irem/m58.cpp" cloneof="10yard" romof="10yard">
<control type="joy" player="1" buttons="2" ways="8"/>
<control type="joy" player="2" buttons="2" ways="8"/>
</machine>
<machine name="10yardj" sourcefile="irem/m58.cpp" cloneof="10yard" romof="10yard">
<control type="joy" player="1" buttons="2" ways="8"/>
<control type="joy" player="2" buttons="2" ways="8"/>
</machine>
</mame>
"3 warps to Uranus" -- so I stopped playing!

10yard

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 138
  • Last login:Today at 01:46:06 pm
  • L BREAK into program
    • DKAFE Frontend
Re: how to parse MAME.XML to obtain 4 or 8 way info
« Reply #2 on: January 27, 2023, 07:22:06 am »
You can use powershell to query the XML.

This command line will search your mame.xml for a machine named "10yard" and then return the control ways attribute.  This example will return the value "8" - the first of the 2 occurrences i.e. player 1 controls.

Code: [Select]
powershell "Select-Xml -Path mame.xml -XPath '/mame/machine' | ForEach-Object { if($_.Node.name -eq '10yard') {$_.Node.control.ways[0] }"}
You can pipe the result to a file or save the result to a powershell variable for use in your batch script.
Hopefully gives you a solution to work with.
Check out my Donkey Kong Arcade Frontend at https://github.com/10yard/dkafe#readme


Justin

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 548
  • Last login:April 21, 2024, 11:12:11 pm
    • Centipede MAME cabinet
Re: how to parse MAME.XML to obtain 4 or 8 way info
« Reply #3 on: January 27, 2023, 08:19:22 am »
Thanks, I was looking into powershell last night but seemed complicated.

I tried your code and get an error:


D:\mame>powershell "Select-Xml -Path mame-compact.xml -XPath '/mame/machine' | F
orEach-Object { if($_.Node.name -eq '10yard') {$_.Node.control.ways[0] }"}
Cannot index into a null array.
At line:1 char:129
+ Select-Xml -Path mame-compact.xml -XPath '/mame/machine' | ForEach-Object { i
f($_.Node.name -eq '10yard') {$_.Node.control.ways[ <<<< 0] }}
    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : NullArray


Any ideas what this may be?
"3 warps to Uranus" -- so I stopped playing!

10yard

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 138
  • Last login:Today at 01:46:06 pm
  • L BREAK into program
    • DKAFE Frontend
Re: how to parse MAME.XML to obtain 4 or 8 way info
« Reply #4 on: January 27, 2023, 08:30:24 am »
Thanks, I was looking into powershell last night but seemed complicated.

I tried your code and get an error:


D:\mame>powershell "Select-Xml -Path mame-compact.xml -XPath '/mame/machine' | F
orEach-Object { if($_.Node.name -eq '10yard') {$_.Node.control.ways[0] }"}
Cannot index into a null array.
At line:1 char:129
+ Select-Xml -Path mame-compact.xml -XPath '/mame/machine' | ForEach-Object { i
f($_.Node.name -eq '10yard') {$_.Node.control.ways[ <<<< 0] }}
    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : NullArray


Any ideas what this may be?

This worked for me when using your originally posted mame.xml.  Can you attach your mame-compact.xml?  maybe the XML structure is slightly different. 
Check out my Donkey Kong Arcade Frontend at https://github.com/10yard/dkafe#readme


Justin

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 548
  • Last login:April 21, 2024, 11:12:11 pm
    • Centipede MAME cabinet
Re: how to parse MAME.XML to obtain 4 or 8 way info
« Reply #5 on: January 27, 2023, 09:41:27 pm »
I think you are right.  The file seems to have some odd formatting.

I did end up going a different route after discovering I can request the xml file from mame for a SPECIFIC ROM.

I've finished my script now and it works flawlessly.  Thanks!

I'll post a separate thread to share the auto switching script. For those with motorized Sanwa TOS GRS and Hyperspin.
"3 warps to Uranus" -- so I stopped playing!

Justin

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 548
  • Last login:April 21, 2024, 11:12:11 pm
    • Centipede MAME cabinet
"3 warps to Uranus" -- so I stopped playing!