The NEW Build Your Own Arcade Controls

Main => Software Forum => Topic started by: wrybreadsf on April 04, 2018, 05:14:03 pm

Title: Possible to get joystick mode of game from command line?
Post by: wrybreadsf on April 04, 2018, 05:14:03 pm
I'm trying to find out if a game uses a 4-way or 8-way joystick from command line. The front end I'm using (Attract Mode) has lines in its romlist files, so if all else fails I can get it from that. The lines look like this:

mrtnt;Mr. TNT;mame;;1983;Techstar (Telko license);;2;90;joystick (4-way),joystick (4-way);good;1;raster;;;;
mspacmat;Ms. Pac Attack;mame;mspacman;1981;hack;;2;90;joystick (4-way),joystick (4-way);good;1;raster;mspacman;;;
mspacman;Ms. Pac-Man;mame;;1981;Midway / General Computer Corporation;;2;90;joystick (4-way),joystick (4-way);good;1;raster;;;;
mspacmab;Ms. Pac-Man (bootleg);mame;mspacman;1981;bootleg;;2;90;joystick (4-way),joystick (4-way);good;1;raster;mspacman;;;
mspacmbe;Ms. Pac-Man (bootleg, encrypted);mame;mspacman;1981;bootleg;;2;90;joystick (4-way),joystick (4-way);good;1;raster;mspacman;;;
mspacmnf;Ms. Pac-Man (fast!);mame;mspacman;1981;hack;;2;90;joystick (4-way),joystick (4-way);good;1;raster;mspacman;;;

But I'm wondering if there's some way to query the ROM from commandline to get this info? I've been looking through the manual and google for awhile now and don't see it. Apologies if it's obvious and I missed something.
Title: Re: Possible to get joystick mode of game from command line?
Post by: Howard_Casto on April 04, 2018, 11:30:13 pm
The closest you can do is "mame.exe -lx rom" where rom is the romname for the game in question.  That'll give you the entire list xml entry for the game though, not just control info.  Of course controls.dat is more suited for this kind of thing, but it's sadly outdated an imcomplete. 
Title: Re: Possible to get joystick mode of game from command line?
Post by: ZoOl007 on April 05, 2018, 03:41:27 am
Hi your best bet on windows is to use powershell to pipe (eg the | ) the output of the command above
mame.exe -lx dkong | regexLikePowerShellThingHere

regex
(?<=ways=")(.*)(?="\/\>)
yields output
4
with this input
<control type="joy" player="1" buttons="1" ways="4"/> 
Title: Re: Possible to get joystick mode of game from command line?
Post by: wrybreadsf on April 05, 2018, 03:43:16 pm
Awesome and thanks!

For those on Linux or (I think) Mac:

./mame -lx dkong | grep -oP -m 1 '(?<=ways=")(.*)(?="\/\>)'

(This outputs "4")

Note the -P flag, which tells grep that it's a Perl Regex. That little detail got me pretty confused.

The -o flag tells grep to just show the found text, as opposed to the entire line.

And the -m 1 tells it to just show the first result. Otherwise it'll show each player's joystick orientation which, I think, is always the same.

Can also make a bash script called joystick.sh or whatever:

Code: [Select]
#!/bin/bash

rom=$1

mame -lx $rom | grep -oP -m 1 '(?<=ways=")(.*)(?="\/\>)'

joystick.sh shinobi

(outputs "8")

Other options:

Code: [Select]
(?<=ways=")\d+
(?<=ways=")[^"]
Title: Re: Possible to get joystick mode of game from command line?
Post by: nexusmtz on April 06, 2018, 05:11:04 am
Hi your best bet on windows is to use powershell to pipe (eg the | ) the output of the command above
mame.exe -lx dkong | regexLikePowerShellThingHere

regex
(?<=ways=")(.*)(?="\/\>)
yields output
4
with this input
<control type="joy" player="1" buttons="1" ways="4"/>
I know it's moot for Wry, but in case someone else wants to do this in powershell the regex way, it's:
Code: [Select]
(.\mame64.exe -lx dkong | select-string '(?<=ways=")(.*)(?="\/\>)').matches[0].value
But to use powershell's xml abilities, it would be:
Code: [Select]
([xml](.\mame64.exe -lx dkong)).mame.machine.input.control.ways[0]
The second method won't get thrown off if 'ways' appears under something other than 'control'.