Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAME custom cmd filename and format #13649

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tsankuanglee
Copy link
Contributor

a small improvement upon #13643

  • Use .mamecmd instead of libretroMAME's .cmd since they have drastically different contents and formats. This way, users still get to use both emulators.
  • tolerate leading and trailing newlines

* use .mamecmd instead of libretroMAME's .cmd since they have
  drastically different contents and formats
* tolerate leading and trailing newlines
with open(defaultCustomCmdFilepath) as f:
commandArray = f.read().splitlines() # type: ignore
commandArray = f.read().strip("\n").splitlines() # type: ignore
Copy link
Contributor

@bryanforbes bryanforbes Mar 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be using shlex.split() instead of forcing users to put each command line argument on a separate line? The file format would go from

foo
-n bar baz
ham spam

to

foo -n "bar baz" "ham spam"

Copy link
Contributor Author

@tsankuanglee tsankuanglee Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this, @bryanforbes !

I'll try to explain why I chose newline as the delimiter, but we could go either way.

  1. I was trying to save users from having to worry about quoting and escaping. Games like Spy Fox 3: "Operation Ozone" would require escaping of those double quote symbols. For shlex.split to correctly interpret this file, we'd need to do "Spy Fox 3: \\"Operation Ozone\\".chd".

  2. Standalone MAME requires a lot more parameters and it's difficult to edit when it's all on the same line.

Here's a real-world example of that game:

/usr/bin/mame/mame
-skip_gameinfo
-rompath
/userdata/roms/macintosh/Spy Fox Series;/userdata/bios/mame;/userdata/bios;/userdata/roms/mame
-bgfx_path
/usr/bin/mame/bgfx/
-fontpath
/usr/bin/mame/
-languagepath
/usr/bin/mame/language/
-pluginspath
/usr/bin/mame/plugins/;/userdata/saves/mame/plugins
-samplepath
/userdata/bios/mame/samples
-artpath
/var/run/mame_artwork/;/usr/bin/mame/artwork/;/userdata/bios/mame/artwork;/userdata/decorations
-cheat
-cheatpath
/userdata/cheats/mame
-verbose
-nvram_directory
/userdata/saves/mame/nvram
-cfg_directory
/userdata/system/configs/mame/macqd605
-input_directory
/userdata/saves/mame/input
-state_directory
/userdata/saves/mame/state
-snapshot_directory
/userdata/screenshots
-diff_directory
/userdata/saves/mame/diff
-comment_directory
/userdata/saves/mame/comments
-homepath
/userdata/saves/mame/plugins
-ctrlrpath
/userdata/system/configs/mame/ctrlr
-inipath
/userdata/system/configs/mame;/userdata/system/configs/mame/ini
-crosshairpath
/userdata/bios/mame/artwork/crosshairs
-video
auto
-resolution
1024x768
-plugins
-plugin
hiscore
-dial_device
mouse
-trackball_device
mouse
-paddle_device
mouse
-positional_device
mouse
-mouse_device
mouse
-ui_mouse
-lightgun_device
mouse
-adstick_device
mouse
macqd605
-ramsize
32M
-hard1
/userdata/roms/macintosh/mac755.chd
-cdrom
/userdata/roms/macintosh/Spy Fox Series/Spy Fox 3: "Operation Ozone".chd

as opposed to:

/usr/bin/mame/mame -skip_gameinfo -rompath "/userdata/roms/macintosh/Spy Fox Series;/userdata/bios/mame;/userdata/bios;/userdata/roms/mame" -bgfx_path /usr/bin/mame/bgfx/ -fontpath /usr/bin/mame/ -languagepath /usr/bin/mame/language/ -pluginspath /usr/bin/mame/plugins/;/userdata/saves/mame/plugins -samplepath /userdata/bios/mame/samples -artpath /var/run/mame_artwork/;/usr/bin/mame/artwork/;/userdata/bios/mame/artwork;/userdata/decorations -cheat -cheatpath /userdata/cheats/mame -verbose -nvram_directory /userdata/saves/mame/nvram -cfg_directory /userdata/system/configs/mame/macqd605 -input_directory /userdata/saves/mame/input -state_directory /userdata/saves/mame/state -snapshot_directory /userdata/screenshots -diff_directory /userdata/saves/mame/diff -comment_directory /userdata/saves/mame/comments -homepath /userdata/saves/mame/plugins -ctrlrpath /userdata/system/configs/mame/ctrlr -inipath /userdata/system/configs/mame;/userdata/system/configs/mame/ini -crosshairpath /userdata/bios/mame/artwork/crosshairs -video auto -resolution 1024x768 -plugins -plugin hiscore -dial_device mouse -trackball_device mouse -paddle_device mouse -positional_device mouse -mouse_device mouse -ui_mouse -lightgun_device mouse -adstick_device mouse macqd605 -ramsize 32M -hard1 /userdata/roms/macintosh/mac755.chd -cdrom "/userdata/roms/macintosh/Spy Fox Series/Spy Fox 3: \\"Operation Ozone\\".chd"

I found split lines and not having to escape special symbols easier to edit, but this could be just a preference thing. I can go either way.

Thoughts?

crcerror added a commit to crcerror/batocera.linux that referenced this pull request Mar 3, 2025
Use doppel quotes if pathes/filenames contains spaces
thanks @bryanforbes and his comment to batocera-linux#13649
Helped me out here
crcerror added a commit to crcerror/batocera.linux that referenced this pull request Mar 3, 2025
If your path or filename contains spaces, then use doppelquotes. This allows the generator to read the whole string as one argument.

```
Wolfenstein (HD).ecwolf
"./Wolfenstein (full version)" -data wl6
```

Thanks to @bryanforbes for the idea, helped me alot. It came from the discussion from batocera-linux#13649
@tsankuanglee tsankuanglee requested a review from bryanforbes March 4, 2025 07:24
@crcerror
Copy link
Contributor

crcerror commented Mar 4, 2025

@tsankuanglee I am not the expert of MAME here but I assume that 90% of the parameters can be unchanged for evey rom. What about following idea:
You have a "master-file", where most of the parameters are presetted, the forms (newline, and so on does not matter).
Then you load your .mamecmd-file if any parameter needs to be overwritten then it is taken out from that file.... and then the long setup per ROM is merged to maybe two or three arguments....

This has the big plus that it's very userfriendly and if pathes are changing then you have to alter likely simply the "master-file" only. I setted the file in quotes because you can manage this directly in the py-generator to as a list.

If I'm wrong here then please tell me
BR ;)


I removed -video -resolution -hd1 and -cdrom from here and the rest should be "equal" to whole romset... I hope

/usr/bin/mame/mame
-skip_gameinfo
-rompath
/userdata/roms/macintosh/Spy Fox Series;/userdata/bios/mame;/userdata/bios;/userdata/roms/mame
-bgfx_path
/usr/bin/mame/bgfx/
-fontpath
/usr/bin/mame/
-languagepath
/usr/bin/mame/language/
-pluginspath
/usr/bin/mame/plugins/;/userdata/saves/mame/plugins
-samplepath
/userdata/bios/mame/samples
-artpath
/var/run/mame_artwork/;/usr/bin/mame/artwork/;/userdata/bios/mame/artwork;/userdata/decorations
-cheat
-cheatpath
/userdata/cheats/mame
-verbose
-nvram_directory
/userdata/saves/mame/nvram
-cfg_directory
/userdata/system/configs/mame/macqd605
-input_directory
/userdata/saves/mame/input
-state_directory
/userdata/saves/mame/state
-snapshot_directory
/userdata/screenshots
-diff_directory
/userdata/saves/mame/diff
-comment_directory
/userdata/saves/mame/comments
-homepath
/userdata/saves/mame/plugins
-ctrlrpath
/userdata/system/configs/mame/ctrlr
-inipath
/userdata/system/configs/mame;/userdata/system/configs/mame/ini
-crosshairpath
/userdata/bios/mame/artwork/crosshairs
-plugins
-plugin
hiscore
-dial_device
mouse
-trackball_device
mouse
-paddle_device
mouse
-positional_device
mouse
-mouse_device
mouse
-ui_mouse
-lightgun_device
mouse
-adstick_device
mouse
macqd605
-ramsize
32M

@tsankuanglee
Copy link
Contributor Author

@crcerror Thank you for the suggestion. You are definitely not wrong. Each approach has its own pros and cons.

I appreciate your idea of having the base template saves repetition. Since different MAME machines require different parameters, we could have a base template for each MAME system at /userdata/roms/macintosh/mamecmd.template for each /userdata/roms/macintosh/*/.mamecmd to build upon. This way, each game's .mamecmd file can have minimal number of lines. We can even let users override some options in the template for games that require special treatment.

However, for now, I'm leaning toward the simpler approach: one game, one file, and that file is complete on its own; its contents are nearly identical to how MAME is launched universally.

The motivation for these .mamecmd files is to have a stable, simple, and flexible fall-back solution to where it's too costly for UI to handle.

  • It's stable because these files will work through various Batocera version changes without users updating them.
  • It's simple because they are almost identical to what the standalone MAME needs.
  • It's flexible because users can have full control over how they want to launch MAME (e.g. for Game A we want to use the joystick as the dial, but with a high threshold; for Game B, we want to use mouse as the dial, but reverse direction; for Game C, we want to start with a lower volume, and open port 60000, etc.)

@crcerror
Copy link
Contributor

crcerror commented Mar 5, 2025

@tsankuanglee It is okay for me - my intention was to make things more portable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants