Repository navigation
tpm, mgs: memory cards (the games' own saves survive firmware updates) - #13
Merged
Merged
Conversation
The Phantom Menace and Metal Gear Solid save to a memory card in port 1: saves/tpm_card1.mcd and saves/mgs_card1.mcd, raw 128 KB card images as PC emulators use, made the first time the game looks. Unlike save states, which hold raw memory and load only into the build that wrote them, these survive firmware updates. - tpm-decomp fea7648..d51af21: libmcrd natively on the card image (tested on the desktop and the board: a save from one build loaded into another); recomp.py treats a jr to the function's own return address as a return (the save screen's bit packer returns through $a3) - psyz 3245d54: mcd, the card image and the BIOS's buXX: device - mgs_reversing 6d58e9f: the port's bu00: device and memcard.c on it (the game finds the card at boot) - Cart::get_memory_card_path names the image after the game's directory Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY
ESP-IDF Size Report for 'Tab5 Emu'
FLASH uses app .bin size or json2 flash sum. RAM sums DRAM+IRAM via idf_size. Percentages shown when totals are available. |
There was a problem hiding this comment.
🟡 Changes recommended
The unconditional psyz/mcd.h include breaks engine-disabled builds because its include directory is added only when CONFIG_MGS_ENGINE is enabled.
1 open issue
What changed in this PR
This PR connects TPM and MGS to persistent PlayStation memory-card images on the SD card, allowing in-game saves to survive firmware updates independently of save states.
Changes:
- Derives card-image paths from each game’s folder and passes them through the game configs.
- Connects TPM and MGS to memory-card support and adds the TPM card-image source to its build.
- Documents card locations, image format, and save-state compatibility.
| File | Description |
|---|---|
| README.md | Documents memory-card images in the SD-card layout. |
| main/tpm_cart.hpp | Passes the card path to TPM. |
| main/mgs_cart.hpp | Passes the card path to MGS. |
| main/cart.hpp | Generates per-game memory-card paths. |
| components/tpm/src/tpm.cpp | Forwards the card path to the engine. |
| components/tpm/src/tpm_engine.hpp | Extends engine initialization to accept a card path. |
| components/tpm/src/tpm_engine.cpp | Stores and exposes the port-1 card path. |
| components/tpm/README.md | Documents card saves and firmware compatibility. |
| components/tpm/include/tpm.hpp | Adds the memory-card configuration field. |
| components/tpm/CMakeLists.txt | Includes the card-image implementation in the runtime build. |
| components/mgs/src/mgs.cpp | Configures the port-1 card image through psyz. |
| components/mgs/README.md | Documents card saves and their location. |
| components/mgs/include/mgs.hpp | Adds the memory-card configuration field. |
Review effort: Balanced
| #include <vector> | ||
|
|
||
| #include "../mgs_reversing/port/mgs_snapshot.h" | ||
| #include <psyz/mcd.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The Phantom Menace and Metal Gear Solid can now save to a memory card in port 1. Each card is a raw 128 KB image on the SD card:
saves/tpm_card1.mcdsaves/mgs_card1.mcdThese are the same files PC emulators like DuckStation and ePSXe use, and the game makes one the first time it looks for a card.
Save states hold raw memory full of addresses, so they only load into the firmware build that wrote them (TPM) or one with the same layout (MGS). Card saves are the game's own data, so they survive any rebuild.
Changes
fea7648,d51af21):recomp.pynow treats ajrto the function's own return address as a return. The save screen's bit packer (0x80054D44) keeps its return address in$a3, and that path ended in a fatal "not a function" error.--memcard FILEandRT_PRESS_HOLD; the menus need holds of about 20 vblanks.3245d54ontpm):mcd, a card image layer (format, list, create, delete, read, write) plus the BIOS'sbuXX:file device.6d58e9fonesp32p4):bu00:to the card.memcard.c's card hardware calls are answered at once, through the handlers the BIOS events would have called.Cart::get_memory_card_path()names the file after the game's folder.Testing
bu00:device in the waymemcard.cuses it.SCheader with the title "PM00:02:Trade Federation Ship".🤖 Generated with Claude Code
https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY