- C 75.1%
- Python 21.6%
- JavaScript 2.6%
- CMake 0.6%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| asm | ||
| assets | ||
| config/arm9 | ||
| docs/dsd | ||
| drafts | ||
| extracted | ||
| include | ||
| match | ||
| native | ||
| notes | ||
| progress | ||
| scratch | ||
| src | ||
| src-readable/arm9 | ||
| src-tu/arm9 | ||
| tools | ||
| .gitattributes | ||
| .gitignore | ||
| AGENTS.md | ||
| build.bat | ||
| build_near.bat | ||
| build_readable.bat | ||
| LICENSE | ||
| README.md | ||
PSZ Mini Decompilation (pszm-jp)
A from-scratch decompilation of Phantasy Star Zero Mini (KPSJ, Sega's first DSiWare title, released 2009-03-25 in Japan) into matching C.
The deliverable is a faithful native port, initially on Linux. The owner's Godot fan game is separate. See native build and milestones for the host build; the ARM matching pipeline remains the reference.
Framework and conventions ported from
tangOS-decomps/pictochat-decomp
(MIT) — same matching standard (sm64ds-decomp lineage), same per-function
workflow. The dsd toolkit (AetiasHax/ds-decomp) is used for extraction
only; its init analyzer panics on this title's TWL memory layout, so
function boundaries/symbols are tracked per pictochat's approach (Ghidra
export → config/arm9/*.txt) instead of dsd init.
Status: see python tools/status.py (banked files vs the 2,214-function
usable live set; excludes the junk Ghidra tail symbol FUN_020d2054),
AGENTS.md (project contract and priorities), and
notes/parked-ledger.md (parked work).
Batch/session history: notes/match-ledger.md, notes/sessions/.
What "matching" means
Source that, compiled with the pinned mwccarm version and flags, produces
object code byte-identical to the real binary — every instruction word, and
every relocation slot pointing at the correct destination. Nothing is
"close enough". Full standard + workflow: notes/matching-style.md.
Compiler pin (settled by byte evidence, notes/compiler-identification.md):
dsi/1.1 (Freescale CodeWarrior 4.0 family) for the majority; a stale-object
minority matches only under the 2.0 line (CW 3.0) and carries a per-file
// version: marker. If a function resists all spelling levers, sweep
tools/match.py --all / --versions 2.0/base,2.0/sp2,1.2/sp4 before
respelling.
Starting flags (pictochat/sm64ds convention):
-O4,p -enum int -lang c99 -char signed -interworking -thumb -proc arm946e -gccext,on -msgstyle gcc
ARM-mode functions carry // flags: -noThumb (half the corpus — detect
before iterating; fdiff defaults to Thumb decode).
Layout
assets/ your dumps: pszm-jp.nds + bios7.bin (tracked; private repo)
extracted/ dsd output (tracked; private repo): the decomp's ground truth - keep it backed up
src/arm9/ matched C, one function per file - THE actual deliverable
src/ov*/ overlay functions (same convention)
src/arm9/stale/ dead-but-byte-verified evidence files (do not delete)
src-readable/ readable source reconstruction of src/ (byte-verified + lint-clean per file; see notes/readable-layer.md)
include/ shared headers
config/ per-module symbol/relocation config (dsd-format; Ghidra-derived)
drafts/ work-in-progress candidates; drafts/near/ = parked near-misses (rescoreable)
scratch/ throwaway probes, sweeps, logs (tracked; low-value by design)
tools/ match.py (per-function byte-match) + the rest (see AGENTS.md)
match/ dsd project + delink/link artifacts (generated; committed for reproducibility)
notes/ analysis notes (one topic per file; sessions/ = narratives)
docs/ vendored dsd file-format docs (MIT, AetiasHax/ds-decomp) + lcf template
progress/ reachability outputs + permuter evidence
asm/ reference disassembly (regenerable, gitignored)
Setup
Linux: see Linux setup for Wine, an isolated Python environment, and the full build commands.
pip install pyelftools capstone pyyaml
assets/pszm-jp.nds— the untouched retail card (ground truth; md5a23cde3e…a690db). All tools default to it and open it read-only. The one exception is dsd's extractor, which cannot read the card as-is: for that, produce a patched copy on demand withtools/patch_rom_for_dsd.pyand delete it afterwards (patches documented innotes/DSi_extraction_findings.md§8). Bootable-ROM building needs no patched copy (tools/splice_rom.pyworks directly on the retail card).assets/bios7.bin— ARM7 BIOS dump (needed to decrypt the secure area)tools/mwccarm/— proprietary compilers, supplied separately (tracked; private repo). Drop them attools/mwccarm/(the default lookup intools/match.py) or keep them anywhere and setMWCCARM_DIR(notes/compiler-identification.md). The compilers are Windows exes; on Linux, drive them via wine:MWCCARM_LAUNCHER=wine(compilers) andMWLDARM_LAUNCHER=wine(linker) — seenotes/project-setup.md.tools/bin/dsd/or$DSD_DIR— the dsd extraction tool (AetiasHax/ds-decomp 0.12.0), not needed for matching work; it producedextracted/(committed — fresh clones get it from git; keep it backed up anyway) and is used bytools/build_all.pyfor the whole-project delink+relink (notes/whole-project-build.md). The dsd file-format docs are vendored indocs/dsd/soconfig/files can be maintained without a dsd checkout.
Re-extract (only if needed; Windows shown, Linux: ./tools/bin/dsd/dsd-linux-x86_64):
# dsd's extractor cannot read the retail card as-is; build a patched COPY
# on demand (the card in assets/ is never modified; the copy is not kept):
python tools/patch_rom_for_dsd.py assets/pszm-jp.nds match/build/PSZERO-MINI-patched-for-dsd.nds
tools/bin/dsd/dsd-windows-x86_64.exe rom extract --rom match/build/PSZERO-MINI-patched-for-dsd.nds \
--arm7-bios assets/bios7.bin --output-path extracted/
Matching workflow (short version)
python tools/match.py --c src/arm9/FUN_02004800.c --func func_02004800 \
--addr 0x02004800 --size 0x40 --module arm9 --brief --all
tools/match.py compiles the candidate with each mwccarm build, extracts
the function's code + relocations from the ELF object, wildcards reloc
slots, word-compares against the real bytes, and verifies that
address-named symbols (FUN_02004abc-style) point where the ROM says they
should. Iteration helpers and the full recipe: matching-style.md §Workflow
(fdiff.py, frame_search.py, match_advisor.py, twin.py,
twin_cluster.py, levers.py --arch thumb).
Target selection: game-logic functions first (rank unmatched functions by
banked-caller count — scratch/shortlist_p7.py pattern), park hard
near-misses rather than sinking sessions. Parked functions get one canonical
file in drafts/near/arm9/ with a // near: status header; build.bat near (or python tools/near_audit.py) re-derives every parked function's
real ndiff/size from the ROM in seconds, so revisiting a wall never means
re-deriving its state — and when a session discovers a new compiler lever,
one rescore shows whether any parked function became PROMOTABLE (0
mismatches + clean relocs → promote via the normal gate path).
Gates
Two one-click entry points:
build.bat— full chain below + the normal bootable ROM (match/build/PSZERO-MINI-built.nds), stop on first failure.build_near.bat— same chain, then a near-test ROM (match/build/PSZERO-MINI-near-test.nds) with every parked near-miss candidate's compiled bytes swapped in live: play it in melonDS to test the candidates in-game (a crash/glitch localizes the failing candidate; a clean run = the residual is benign). Tool:tools/build_near_rom.py.build_readable.bat— the readable-layer chain:lint_readable.py(the readable source must be free of decompiler-artifact shapes — casts/goto/select machine shapes AND meaning shapes: machine vocabulary (arg0,p4),!= 0bool-noise conditions, single-letter result temps;note:-marked compiler-required shapes and evidence-cited per-file waivers are the only exemptions),audit_readable.py(the readable file must compile byte-identical to its twin: code bytes + relocations), thentools/build_readable_rom.py— relinks the whole arm9 fromsrc-readable/+ the carved delinked objects and splicesmatch/build/PSZERO-MINI-readable.nds, which is REQUIRED byte-identical to the retail card (the readable layer's executable proof,build_near_rom.py's architecture with the readable sources as payloads) — then the status census. Conventions:notes/readable-layer.md.
| Command | Proves |
|---|---|
python tools/probes/audit_all_src.py |
every banked file recompiles + re-matches (word compare + relocs) |
python tools/build_all.py |
whole image delinks, relinks, stays byte-identical (all 9 modules) |
python tools/linkcheck.py |
every wildcarded reloc slot points where the ROM does (closes the wildcard blind spot) |
python tools/probes/verify_c_link.py |
our compiled objects slot into the real link (swap-in relink; occasional) |
python tools/probes/audit_doclinks.py |
every doc reference resolves |
python tools/status.py |
banked-vs-live-set census (the only place the progress number lives) |
python tools/near_audit.py |
parked near-misses rescored; PROMOTABLE flagged |
Bootable ROM
dsd rom build cannot rebuild this title (its banner builder predates DSi
animated banners), so a bootable ROM is produced by splicing:
tools/splice_rom.py writes the freshly linked module binaries into a copy
of the card image at fixed offsets, re-encrypts the ARM9 secure area
(Blowfish scheme ported from ds-rom 0.8.0, assets/bios7.bin key) and
recomputes both header CRCs. Everything else stays byte-identical to the card.
python tools/splice_rom.py --self-test # validate crypto vs real card bytes
PSZ_BUILD_ROM=1 python tools/build_all.py # splice as build step [7]
python tools/splice_rom.py --diff-against assets/pszm-jp.nds # exits 0 when modules match
With unchanged modules the splice is byte-identical to the real card (proven
2026-08-29). See notes/repo-independence-audit.md for why dsd rom build
is not usable here.
Legal
Private project (currently two developers); licensing chosen so nothing blocks a future public release:
- MIT for this repo's original work: hand-written matching C in
src/, notes, and the original portions oftools/(seeLICENSE). - Third-party pieces that were ported or vendored in (pictochat-decomp
tooling, sm64ds-decomp's swarm.py rules, AetiasHax's ds-decomp docs)
remain MIT under their own notices — attributed in
LICENSE. - The ROM, its extracted assets, the BIOS dumps, and the proprietary compiler are tracked in this private repository by decision of 2026-08-30 (the former .gitignore was retired; the repo is not public). None of them are licensed by this repo. You supply your own dumps.