feat: read libretro MAME's -rompath from ES-DE

ES-DE starts the libretro MAME core with a command line as its content
in 22 commands across 21 systems ("apple2e -rompath \"%GAMEDIRRAW%;
%ROMPATH%/apple2\" -flop1 ...", resources/systems/linux/es_systems.xml
at RetroDECK's 15e1b236 and EmuDeck's ES-DE v3.5.0), run through the
shell by popen (es-core/src/utils/PlatformUtil.cpp:231, 257).

At 5f5a0774 the core reads content that is no file as a command line
(retro_init.cpp:966-1008). Set_Path_Option passes its own -rompath
<content dir>;<system>/mame/bios;<system>/mame/roms (580-597), then
every word of the command line follows, -rompath included, only -rp
being dropped when mame_paths_enable is off (902-940, 914-919). MAME
keeps the later value of an option given twice at one priority
(src/lib/util/options.cpp:260-276, clifront.cpp:243). Those commands
read their sets in the folders they name, and mame/bios stays read by
every command that passes none.

The ES-DE parser records these commands in searched_by with their core,
the mame profile declares libretro_pools (-rompath and -rp stand for
mame/bios), and a set there also goes to each folder a command names
for a machine that reads it.

Manifests: EmuDeck gains 16 files below roms/ (apple2, apple2gs,
astrocde, crvision, gamate, gamecom, gmaster, intellivision, odyssey2,
scv, supracan, vectrex, videopac, vsmile). RetroDECK does not change:
its standalone MAME commands already put the same sets at the same
paths. No file leaves.
This commit is contained in:
Abdessamad Derraz committed 2026-11-11 12:30:53 +01:00
1 parent 2173ba00d9
commit 7035da1154
10 files changed
+618 -52

No files matched your search

+55 -31
View File
@@ -2872,9 +2872,10 @@ CONTENT_SCOPE_TAG = "contentscope:"
# [core name, roms folder, (tree, path)]: a libretro core the platform
# launches for the games of that folder, which it reads beside.
CONTENT_FOLDER_PREFIX = "contentdir:"
# [emulator, (tree, path), system, machines, any machine, source_ref]: a
# standalone emulator handed a roms folder as its ROM search path on the
# command line of a system's launch.
# [emulator or core, (tree, path), system, machines, any machine,
# source_ref, build]: a standalone emulator, or a libretro core in the
# command line it is handed as content, given a roms folder as its ROM
# search path by a system's launch command.
ROM_SEARCH_PREFIX = "romsearch:"
# The frontend writes the BIOS it hands a core beside the content: the
# folder it gives the BIOS is the content's.
@@ -3413,7 +3414,7 @@ def _core_key(name: str) -> str:
def content_folder_tags(config: dict) -> set[str]:
"""The roms folders a platform launches each libretro core for, and the
ROM search paths its commands hand standalone emulators, as tags.
ROM search paths its commands hand emulators and cores, as tags.
A core reading its BIOS sets beside the game (MAME 2003's osd_get_path
gives FILETYPE_ROM the content directory) reads them in the folder of
@@ -3466,9 +3467,10 @@ def content_folder_tags(config: dict) -> set[str]:
for read in search.get("reads") or []:
if read in folders:
tags.add(ROM_SEARCH_PREFIX + json.dumps([
str(search["emulator"]), place(read), str(row["folder"]),
sorted(search.get("machines") or []), bool(search.get("any_machine")),
str(search.get("source_ref", "")),
str(search.get("core") or search["emulator"]), place(read),
str(row["folder"]), sorted(search.get("machines") or []),
bool(search.get("any_machine")), str(search.get("source_ref", "")),
"libretro" if search.get("core") else "standalone",
]))
return tags
@@ -3550,10 +3552,11 @@ def content_layout(
A libretro entry read beside the content (``load_from: content_dir``)
goes to the folder of each system the platform launches the core for,
and is named as read outside the BIOS folder where it knows none. A
standalone entry no launcher record places, under the root of the
layout a passed ROM search path stands for, goes to each folder a
command passes for a machine that reads it. Outside a platform (no
and is named as read outside the BIOS folder where it knows none. An
entry in the folder a passed ROM search path stands for (the root of a
standalone layout no launcher record places it in, a ``libretro_pools``
folder) goes to each folder a command passes for a machine that reads
it, a libretro one staying where it is too. Outside a platform (no
CONTENT_SCOPE_TAG) the view is left as it is.
"""
tags = [t for t in standalone_cores if t.startswith(CONTENT_TAG_PREFIXES)]
@@ -3571,6 +3574,29 @@ def content_layout(
files = view.get("files") or []
out: list = []
changed = False
searches = [
json.loads(t[len(ROM_SEARCH_PREFIX):])
for t in tags if t.startswith(ROM_SEARCH_PREFIX)
]
build = "standalone" if standalone else "libretro"
searches = [s for s in searches if _core_key(s[0]) in names and s[6] == build]
def search_reads(name: str) -> list[tuple[str, str]]:
stem = name.rsplit(".", 1)[0]
return sorted({
tuple(where) for _emu, where, system, machines, any_machine, _ref, _build in searches
if where and stem in rom_search_sets(emu_name, system, machines, any_machine)
})
def roms_entry(entry: dict, tree: str, folder: str, rel: str) -> dict:
# Below the roms root inside the install tree (EmuELEC's
# /storage/roms): a plain dest the platform prefix skips, as a
# standalone entry placed there (_placed_entry).
where: dict[str, object] = (
{"unprefixed": True} if tree == "install" else {"root": ROMS_ROOT}
)
return {**entry, **where, "path": f"{folder}/{rel}", "layout_path": rel}
if not standalone:
folders = sorted({
tuple(where) for core, _folder, where in (
@@ -3578,11 +3604,25 @@ def content_layout(
for t in tags if t.startswith(CONTENT_FOLDER_PREFIX)
) if core in names and where
})
# The folders a passed -rompath replaces the build's own search
# path with stand for these: libretro MAME hands MAME
# <system>/mame/bios unless the content's command line names
# another (retro_init.cpp Set_Path_Option, execute_game_cmd).
from launchers import pool_folders # noqa: PLC0415
pools = set(pool_folders({"standalone_pools": view.get("libretro_pools")}).values())
for f in files:
if (not isinstance(f, dict) or _content_load(f) != "content_dir"
or f.get("category") == "game_data"):
if not isinstance(f, dict):
out.append(f)
continue
if _content_load(f) != "content_dir" or f.get("category") == "game_data":
# Game data read beside the content is the game's own.
out.append(f)
parent, _, rel = str(f.get("path") or "").rpartition("/")
if searches and parent in pools and rel:
reads = search_reads(rel)
changed |= bool(reads)
out.extend(roms_entry(f, tree, folder, rel) for tree, folder in reads)
continue
changed = True
plain = _without_libretro_load(f)
@@ -3590,20 +3630,8 @@ def content_layout(
out.append({**plain, "unplaced": OUTSIDE_BIOS_FOLDER})
continue
rel = str(f.get("path") or f.get("name") or "")
for tree, folder in folders:
# Below the roms root inside the install tree (EmuELEC's
# /storage/roms): a plain dest the platform prefix skips, as
# a standalone entry placed there (_placed_entry).
where: dict[str, object] = (
{"unprefixed": True} if tree == "install" else {"root": ROMS_ROOT}
)
out.append({**plain, **where, "path": f"{folder}/{rel}", "layout_path": rel})
out.extend(roms_entry(plain, tree, folder, rel) for tree, folder in folders)
return {**view, "files": out} if changed else view
searches = [
json.loads(t[len(ROM_SEARCH_PREFIX):])
for t in tags if t.startswith(ROM_SEARCH_PREFIX)
]
searches = [s for s in searches if _core_key(s[0]) in names]
pools = {str(v).strip("/") for v in (view.get("standalone_pools") or {}).values()}
if not searches or "" not in pools:
return view
@@ -3612,11 +3640,7 @@ def content_layout(
if not layout or "/" in layout or f.get("unplaced") != OUTSIDE_BIOS_FOLDER:
out.append(f)
continue
stem = layout.rsplit(".", 1)[0]
reads = sorted({
tuple(where) for _emu, where, system, machines, any_machine, _ref in searches
if where and stem in rom_search_sets(emu_name, system, machines, any_machine)
})
reads = search_reads(layout)
if not reads:
out.append(f)
continue
+50 -14
View File
@@ -526,21 +526,55 @@ def _alternative_emulators(text: str, function: str) -> dict[str, tuple[str, int
_ROMPATH_OPTIONS = ("-rompath", "-rp")
def _core_words(command: str) -> tuple[str, list[str]] | None:
"""The core and the words of the content RetroArch hands it.
ES-DE starts the libretro MAME core with a quoted command line as its
content (`-L .../mame_libretro.so "apple2e -rompath \\"...\\" ..."`): popen
runs it through the shell (es-core/src/utils/PlatformUtil.cpp:231, 257),
and the core splits the content on spaces and quotes when it is no file
(retro_init.cpp parse_cmdline, mmain2).
"""
core = _RA_CORE.search(command)
if core is None:
return None
try:
args = shlex.split(command)
at = args.index("-L")
content = shlex.split(args[at + 2]) if at + 2 < len(args) else []
except ValueError:
return None
return core.group(1), content
def _searched_by(commands: list[tuple[str, str, int | None]], key: str, path: str) -> list[dict]:
"""The ROM folders each standalone emulator's commands pass it, by emulator.
"""The ROM folders each emulator's commands pass it, by emulator and core.
ES-DE starts standalone MAME with `-rompath %GAMEDIR%\\;%ROMPATH%/<system>`
and a machine, or %BASENAME% where the game is the machine. The command
line outranks mame.ini. %GAMEDIR% is the game's own folder, no folder a
pack fills.
line outranks mame.ini. The libretro MAME core gets the same option in
the command line it is handed as content, after the machine. %GAMEDIR%
is the game's own folder, no folder a pack fills.
"""
found: dict[str, dict] = {}
found: dict[tuple[str, str], dict] = {}
for _label, command, line in commands:
emulator = _EMULATOR.search(command)
if emulator is None or _RA_CORE.search(command):
continue
words = command.replace("\\;", ";").split()
at = next((i for i, w in enumerate(words) if w in _ROMPATH_OPTIONS), None)
libretro = _core_words(command)
if libretro is not None:
core, words = libretro
if words[:1] == [core]:
# A first word naming the core is dropped (mmain2).
words = words[1:]
name = "retroarch"
at = next((i for i, w in enumerate(words) if w in _ROMPATH_OPTIONS), None)
machine = words[0] if words and at else ""
else:
emulator = _EMULATOR.search(command)
if emulator is None:
continue
core, name = "", emulator.group(1).lower()
words = command.replace("\\;", ";").split()
at = next((i for i, w in enumerate(words) if w in _ROMPATH_OPTIONS), None)
machine = words[at + 2] if at is not None and at + 2 < len(words) else ""
if at is None or at + 1 >= len(words):
continue
reads = [
@@ -549,11 +583,10 @@ def _searched_by(commands: list[tuple[str, str, int | None]], key: str, path: st
]
if not reads:
continue
name = emulator.group(1).lower()
record = found.setdefault(name, {"emulator": name, "reads": [], "machines": [],
"any_machine": False, "lines": []})
record = found.setdefault((name, core), {"emulator": name, "core": core, "reads": [],
"machines": [], "any_machine": False,
"lines": []})
record["reads"] += [r for r in reads if r not in record["reads"]]
machine = words[at + 2] if at + 2 < len(words) else ""
if not machine or machine.startswith("%"):
record["any_machine"] = True
elif machine not in record["machines"]:
@@ -561,7 +594,10 @@ def _searched_by(commands: list[tuple[str, str, int | None]], key: str, path: st
record["lines"].append(line)
rows = []
for record in found.values():
row = {"emulator": record["emulator"], "reads": record["reads"]}
row = {"emulator": record["emulator"]}
if record["core"]:
row["core"] = record["core"]
row["reads"] = record["reads"]
if record["machines"]:
row["machines"] = record["machines"]
if record["any_machine"]: