No description
  • C 75.1%
  • Python 21.6%
  • JavaScript 2.6%
  • CMake 0.6%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-29 04:36:51 -04:00
asm Initial commit (history reinitialized 2026-08-30): full working tree 2026-08-30 20:56:57 -04:00
assets Finish manager initializer and reconcile verified untracked backlog 2026-09-17 14:07:21 -04:00
config/arm9 Wave 1014 recovery: bank the CP15 c6 register file split out of FUN_0202df9c 2026-10-05 06:14:00 -04:00
docs/dsd Initial commit (history reinitialized 2026-08-30): full working tree 2026-08-30 20:56:57 -04:00
drafts Merge pull request 'WIP: PSZ Mini native/browser port — playable checkpoint and fidelity roadmap' (#16) from kion/pszm-native-visible-checkpoint into main 2026-10-29 04:36:51 -04:00
extracted Initial commit (history reinitialized 2026-08-30): full working tree 2026-08-30 20:56:57 -04:00
include Initial commit (history reinitialized 2026-08-30): full working tree 2026-08-30 20:56:57 -04:00
match Merge pull request 'WIP: PSZ Mini native/browser port — playable checkpoint and fidelity roadmap' (#16) from kion/pszm-native-visible-checkpoint into main 2026-10-29 04:36:51 -04:00
native Bind original configuration-gated scene update prelude 2026-10-26 23:38:48 -05:00
notes Merge pull request 'WIP: PSZ Mini native/browser port — playable checkpoint and fidelity roadmap' (#16) from kion/pszm-native-visible-checkpoint into main 2026-10-29 04:36:51 -04:00
progress permuter bake-off record: FUN_0200f308 incumbent progress csv (12 iters, no winner) 2026-10-24 18:13:02 -04:00
scratch Merge pull request 'WIP: PSZ Mini native/browser port — playable checkpoint and fidelity roadmap' (#16) from kion/pszm-native-visible-checkpoint into main 2026-10-29 04:36:51 -04:00
src overlay bruteforce pass (2026-10-24, owner go): byte-identity scan (25/699, tool + artifact in notes/reference) + twin.py --relax campaign chunked (1 chunk = 1 skeleton twin); 2 banks landed (src/ov001 +2 files: 021a6ae4 = the banked FUN_0201c168 identity respell, 0219f738 = twin of FUN_0203dcd4), overlay banked set 3 -> 5; port/README overlay section + ledger row; chunk 2 (ov004/ov005) = 0 skeleton hits in the arm9 index; runtime liveness remains queued (user static-first choice); always verify at funcs.py true_size - the gate caught guessed spans twice 2026-10-24 19:26:49 -04:00
src-readable/arm9 R56: the corpus-wide re-evaluation wave (the owner's order) 2026-10-19 14:54:32 -04:00
src-tu/arm9 header split for both TU units: unit.h carries exactly the pre-split declarations (typedefs + reconciled externs), unit.c keeps the marker block + #include; proven byte-neutral (build_all 9 modules identical, audit 1479/1479, linkcheck 19+63 slots unchanged); measured fact banked: mwccarm resolves quoted includes only via -I/MWCINCLUDES (not includer dir, not cwd) so units carry -Isrc-tu/arm9 in markers; tu_compose.py now regenerates any landed unit (landed file = the record) and always emits the split form 2026-10-23 20:10:42 -04:00
tools overlay bruteforce pass (2026-10-24, owner go): byte-identity scan (25/699, tool + artifact in notes/reference) + twin.py --relax campaign chunked (1 chunk = 1 skeleton twin); 2 banks landed (src/ov001 +2 files: 021a6ae4 = the banked FUN_0201c168 identity respell, 0219f738 = twin of FUN_0203dcd4), overlay banked set 3 -> 5; port/README overlay section + ledger row; chunk 2 (ov004/ov005) = 0 skeleton hits in the arm9 index; runtime liveness remains queued (user static-first choice); always verify at funcs.py true_size - the gate caught guessed spans twice 2026-10-24 19:26:49 -04:00
.gitattributes Initial commit (history reinitialized 2026-08-30): full working tree 2026-08-30 20:56:57 -04:00
.gitignore Merge pull request 'WIP: PSZ Mini native/browser port — playable checkpoint and fidelity roadmap' (#16) from kion/pszm-native-visible-checkpoint into main 2026-10-29 04:36:51 -04:00
AGENTS.md Merge pull request 'WIP: PSZ Mini native/browser port — playable checkpoint and fidelity roadmap' (#16) from kion/pszm-native-visible-checkpoint into main 2026-10-29 04:36:51 -04:00
build.bat build_near.bat: near-test ROM with the parked near-miss candidates live 2026-09-06 21:17:51 -04:00
build_near.bat build_near.bat: near-test ROM with the parked near-miss candidates live 2026-09-06 21:17:51 -04:00
build_readable.bat R57: the tooling/workflow wave - the R56 improvement list implemented 2026-10-19 15:30:12 -04:00
LICENSE Docs: describe tracked-content reality (option C), annotate retired hashes 2026-08-30 20:57:57 -04:00
README.md Establish faithful native-port direction and first Linux x86 build 2026-10-23 16:14:51 -05:00

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; md5 a23cde3e…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 with tools/patch_rom_for_dsd.py and delete it afterwards (patches documented in notes/DSi_extraction_findings.md §8). Bootable-ROM building needs no patched copy (tools/splice_rom.py works 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 at tools/mwccarm/ (the default lookup in tools/match.py) or keep them anywhere and set MWCCARM_DIR (notes/compiler-identification.md). The compilers are Windows exes; on Linux, drive them via wine: MWCCARM_LAUNCHER=wine (compilers) and MWLDARM_LAUNCHER=wine (linker) — see notes/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 produced extracted/ (committed — fresh clones get it from git; keep it backed up anyway) and is used by tools/build_all.py for the whole-project delink+relink (notes/whole-project-build.md). The dsd file-format docs are vendored in docs/dsd/ so config/ 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), != 0 bool-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), then tools/build_readable_rom.py — relinks the whole arm9 from src-readable/ + the carved delinked objects and splices match/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.

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 of tools/ (see LICENSE).
  • 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.