mirror of
https://github.com/rommapp/romm.git
synced 2026-11-29 10:01:00 +01:00
* feat(saves): convert Nintendo DS saves through sigil Sigil now converts a DS save between melonDS's raw file and DeSmuME's .dsv, so a download with core= gets the file that emulator reads instead of the stored one as is. DS moves from the native list to the platforms sigil restores; like Saturn and Sega CD it carries no title id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(saves): accept a single-file neutral unit as sigil names it, for DS and Game Boy Sigil names a cart's single-file unit after the content, `{stem}.srm`, and sets the unit format; the neutral check only took `save.raw` for DS and `save.sram` for Game Boy, so a client pushing sigil's own unit got a 422. A SINGLE unit's one file may now carry sigil's name on those platforms; multi-file units and every other platform keep their names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(saves): name DS among the cartridges that take no companions Sigil refuses companions on every cartridge platform, DS included now that it converts DS saves, so the refusal says so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(saves): convert Mega Drive, 32X, Master System and Game Gear saves through sigil genesis_plus_gx and picodrive keep these carts' save RAM at the same offsets but fill and size it differently. With sigil converting between them, the four platforms move from NATIVE_SAVE_PLATFORM_SLUGS to SIGIL_RESTORE_PLATFORM_SLUGS (sigil slugs genesis, 32x, sms, gamegear), so a download with core= gets the file that core keeps. The companion refusal message names the new cartridges. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(saves): accept the Sega cartridges' single-file neutral unit as sigil names it Sigil names a Mega Drive, 32X, Master System or Game Gear unit after the content, `{stem}.srm`. A SINGLE unit's one file may now carry that name, as DS and Game Boy's may; RomM's `save.sram` still passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(saves): convert Game Boy Advance saves between emulators with sigil GBA moves from the native-save platforms to the ones sigil reads at scan time and restores for a core. The stored file doesn't load everywhere: VBA Next keeps an EEPROM save at 128 KiB into a 136 KiB file, gpSP pads every save to 128 KiB, and standalone mGBA appends the cart clock. The scan stores the cart's save chip and clock in sigil_features, which sigil uses to size a padded save. The tests that used GBA as their native example now use SNES. Needs a sigil pin with GBA collect and restore. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(saves): accept a single-file GBA neutral unit as sigil names it Sigil names a GBA cart's unit as it does a Game Boy's: the save alone as `{stem}.srm`, or a clock cart's zip of `save.sram` and `clock.rtc`. GBA now takes Game Boy's form, so the single file may carry sigil's name. The clock-only form had no other platform left and goes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(saves): pin sigil at the DS merge, and take only a plain file name as its single unit Both SIGIL_VERSION pins move to baa96b8 (rommapp/argosy-sigil#22), the first sigil commit with DS. _SIGIL_SINGLE is [^/]+\.srm, so a single unit named with a folder in it is refused; test_neutral.py checks it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(deps): pin sigil at the GBA merge rommapp/argosy-sigil#24 is merged as 4980f69. Both SIGIL_VERSION pins (Dockerfile, docker/Dockerfile) move from baa96b8 to that commit on sigil's main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(deps): pin sigil at the Mega Drive merge rommapp/argosy-sigil#23 is merged as be0809d. Both SIGIL_VERSION pins (Dockerfile, docker/Dockerfile) move from baa96b8 to that commit on sigil's main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(deps): pin sigil at 650b265 Both SIGIL_VERSION pins (Dockerfile, docker/Dockerfile) move from be0809d to 650b265, sigil's main. It holds rommapp/argosy-sigil#23 (be0809d) and is the commit rommapp/romm#5758 pins, so the two pull requests set the same value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(deps): pin sigil at 650b265 Both SIGIL_VERSION pins (Dockerfile, docker/Dockerfile) move from baa96b8 to 650b265, sigil's main. It holds rommapp/argosy-sigil#22 (baa96b8) and is the commit rommapp/romm#5758 pins, so the two pull requests set the same value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(deps): pin sigil at 650b265 Both SIGIL_VERSION pins (Dockerfile, docker/Dockerfile) move from 4980f69 to 650b265, sigil's main. It holds rommapp/argosy-sigil#24 (4980f69) and is the commit rommapp/romm#5758 pins, so the two pull requests set the same value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(saves): name no systems in the companion refusal The message listed the cartridges that take no companions, so each platform added to sigil's restores edited it, and the open save PRs (#5643 to #5647) each edited it differently. It now says what holds for every platform: companions go only on memory cards and volumes. All five carry the same line, so they merge in any order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(saves): name no systems in the companion refusal The message listed the cartridges that take no companions, so each platform added to sigil's restores edited it, and the open save PRs (#5643 to #5647) each edited it differently. It now says what holds for every platform: companions go only on memory cards and volumes. All five carry the same line, so they merge in any order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(saves): name no systems in the companion refusal The message listed the cartridges that take no companions, so each platform added to sigil's restores edited it, and the open save PRs (#5643 to #5647) each edited it differently. It now says what holds for every platform: companions go only on memory cards and volumes. All five carry the same line, so they merge in any order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(saves): restore Sega cart saves through RomM's platform map and binding From review: the Mega Drive, 32X, Master System and Game Gear tests mock the binding, so a slug sigil doesn't take would still pass. A ROM on each RomM platform now goes through stored_game and the real binding, and the restored file is checked in the form sigil's genesis.md gives the core: genesis_plus_gx without trailing 0xFF, picodrive's 32 KiB for Master System and Game Gear. rom_game is the same helper in #5643 to #5647. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(saves): restore a DS save through RomM's platform map and the binding From review: the DS tests mock the binding, so a slug sigil doesn't take for DS would still pass. A ROM on RomM's nds platform now goes through stored_game and the real binding, and the restored file is checked in the form sigil's nds.md gives each core: DeSmuME's .dsv ends in its 122-byte footer, melonDS's .sav is the save. rom_game is the same helper in #5643 to #5647. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(saves): restore a GBA save through RomM's platform map and the binding From review: the GBA tests mock the binding, so a slug sigil doesn't take for GBA would still pass. A ROM on RomM's gba platform now goes through stored_game and the real binding, and the restored file is checked at the size sigil's gba.md gives each core: gpSP 128 KiB padded with 0xFF, VBA Next 136 KiB, mGBA the chip. rom_game is the same helper in #5643 to #5647. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(deps): pin sigil at ef9b51e Both SIGIL_VERSION pins move from 650b265 to ef9b51e, sigil's main since rommapp/argosy-sigil#30 merged, the commit rommapp/romm#5758 pins now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(deps): pin sigil at ef9b51e Both SIGIL_VERSION pins move from 650b265 to ef9b51e, sigil's main since rommapp/argosy-sigil#30 merged, the commit rommapp/romm#5758 pins now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(deps): pin sigil at ef9b51e Both SIGIL_VERSION pins move from 650b265 to ef9b51e, sigil's main since rommapp/argosy-sigil#30 merged, the commit rommapp/romm#5758 pins now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: MMagTech <mmagtech@Mac.home> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
115 lines
3.6 KiB
Python
115 lines
3.6 KiB
Python
"""The member names a neutral save unit may hold, per platform."""
|
|
|
|
import re
|
|
from collections.abc import Collection
|
|
from dataclasses import dataclass
|
|
from typing import Final
|
|
|
|
from models.assets import SaveShape
|
|
from utils.platform_slugs import UniversalPlatformSlug as UPS
|
|
|
|
|
|
class NeutralUnitRejected(ValueError):
|
|
"""A unit labelled neutral that doesn't hold the platform's neutral form."""
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class _Form:
|
|
allowed: re.Pattern[str]
|
|
# At least one present member must match this; `allowed` when unset.
|
|
required: re.Pattern[str] | None = None
|
|
# Another name a SINGLE unit's one file may carry: sigil names a cart's
|
|
# single-file unit after the content, `{stem}.srm`.
|
|
single: re.Pattern[str] | None = None
|
|
|
|
@property
|
|
def primary(self) -> re.Pattern[str]:
|
|
return self.required or self.allowed
|
|
|
|
def single_name(self, name: str, shape: SaveShape) -> bool:
|
|
return bool(
|
|
shape == SaveShape.SINGLE and self.single and self.single.fullmatch(name)
|
|
)
|
|
|
|
|
|
def _names(*names: str) -> re.Pattern[str]:
|
|
return re.compile("|".join(re.escape(name) for name in names))
|
|
|
|
|
|
_SIGIL_SINGLE = re.compile(r"[^/]+\.srm")
|
|
|
|
_BATTERY = _Form(_names("save.sram"))
|
|
_SEGA_CART = _Form(_names("save.sram"), single=_SIGIL_SINGLE)
|
|
_GAME_BOY = _Form(
|
|
_names("save.sram", "clock.rtc"), _names("save.sram"), single=_SIGIL_SINGLE
|
|
)
|
|
_RAW = _Form(_names("save.raw"))
|
|
_DS = _Form(_names("save.raw"), single=_SIGIL_SINGLE)
|
|
_BACKUP_RAM = _Form(_names("backup.ram", "cart.ram"))
|
|
|
|
NEUTRAL_FORMS: Final[dict[str, _Form]] = {
|
|
UPS.NES: _BATTERY,
|
|
UPS.FAMICOM: _BATTERY,
|
|
UPS.SNES: _BATTERY,
|
|
UPS.SFAM: _BATTERY,
|
|
UPS.GENESIS: _SEGA_CART,
|
|
UPS.SMS: _SEGA_CART,
|
|
UPS.GAMEGEAR: _SEGA_CART,
|
|
UPS.SEGA32: _SEGA_CART,
|
|
UPS.GB: _GAME_BOY,
|
|
UPS.GBC: _GAME_BOY,
|
|
UPS.GBA: _GAME_BOY,
|
|
UPS.N64: _Form(_names("eeprom", "pak1", "pak2", "pak3", "pak4", "sram", "flash")),
|
|
UPS.NDS: _DS,
|
|
UPS.JAGUAR: _RAW,
|
|
UPS.LYNX: _RAW,
|
|
UPS.NEO_GEO_POCKET: _RAW,
|
|
UPS.NEO_GEO_POCKET_COLOR: _RAW,
|
|
UPS.WONDERSWAN: _RAW,
|
|
UPS.WONDERSWAN_COLOR: _RAW,
|
|
UPS.POKEMON_MINI: _RAW,
|
|
UPS.SEGACD: _BACKUP_RAM,
|
|
UPS.SATURN: _BACKUP_RAM,
|
|
UPS.DC: _Form(re.compile(r"vmu_[A-D][1-2]\.bin")),
|
|
}
|
|
|
|
# Platforms with no neutral form defined yet; they sync natively.
|
|
NO_NEUTRAL_FORM: Final = frozenset({UPS.FDS, UPS.ARCADE})
|
|
|
|
|
|
def check_neutral_unit(
|
|
platform_slug: str, shape: SaveShape, members: Collection[str]
|
|
) -> None:
|
|
"""Refuse a neutral unit whose members aren't the platform's neutral names.
|
|
|
|
Args:
|
|
members: the archive's file entries, or the raw part's file name for a
|
|
`SINGLE` unit.
|
|
|
|
Raises:
|
|
NeutralUnitRejected: with the reason a client can show.
|
|
"""
|
|
if platform_slug in NO_NEUTRAL_FORM:
|
|
raise NeutralUnitRejected(
|
|
f"{platform_slug} has no neutral form yet; push it as native"
|
|
)
|
|
form = NEUTRAL_FORMS.get(platform_slug)
|
|
if form is None:
|
|
return
|
|
strays = sorted(
|
|
name
|
|
for name in members
|
|
if not form.allowed.fullmatch(name) and not form.single_name(name, shape)
|
|
)
|
|
if strays:
|
|
raise NeutralUnitRejected(
|
|
f"{', '.join(strays)} isn't a neutral member name for {platform_slug}"
|
|
)
|
|
if not any(
|
|
form.primary.fullmatch(name) or form.single_name(name, shape)
|
|
for name in members
|
|
):
|
|
raise NeutralUnitRejected(f"the unit holds no save for {platform_slug}")
|
|
if shape == SaveShape.SINGLE and len(members) != 1:
|
|
raise NeutralUnitRejected("a SINGLE unit holds exactly one member")
|