Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/pmret/papermario/llms.txt

Use this file to discover all available pages before exploring further.

The project ships a set of Python scripts that support the decompilation workflow — from snapshotting the build to comparing assembly output to generating context files. This page documents each tool, its key flags, and when to reach for it.

diff.py

diff.py is the primary tool you use during matching. It compares the original game’s MIPS assembly (left column) against the assembly produced by your C code (right column) and highlights differences.
./diff.py -mwo function_name

Key flags

FlagEffect
-mWatch mode — recompiles and refreshes the diff every time you save the .c file
-wAutomatically infers the source file to watch from the function name
-oColourises output for easier reading
-3Three-column diff: original (left), current (middle), previous saved (right)
-bThree-column diff: original (left), current (middle), version from when diff.py started (right)
-hPrint full help and all available flags

Example commands

Compare a function once and exit:
./diff.py func_DEADBEEF
Watch mode with colour while iterating:
./diff.py -mwo func_DEADBEEF
Three-column diff to track progress across saves:
./diff.py -mwo -3 func_DEADBEEF
In Visual Studio Code, Run Test Task runs diff.py and surfaces compiler warnings inline. Binding it to a key makes the edit–compile–diff loop significantly faster.

m2ctx.py

m2ctx.py generates a context file (ctx.c) by preprocessing the C source file you’re working on. This context file contains all struct definitions, typedefs, and function prototypes that mips_to_c needs to produce accurate C output.
./tools/m2ctx.py path/to/source_file.c
The script runs gcc -E with the project’s include paths and preprocessor flags, then writes the result to ctx.c in the repository root. Pass ctx.c to mips_to_c with --context ctx.c when running locally, or paste its contents into the lower box of the web version.
Run m2ctx.py from the repository root. The path you pass should be relative to the repository root as well.

make_expected.sh

make_expected.sh snapshots the current build as the reference that diff.py compares against. Run it once after you have a successful build:
./make_expected.sh
The script removes any existing ver/*/expected/ directories and then copies each version’s build/ directory into the corresponding expected/ directory:
  • ver/us/build/ver/us/expected/ver/us/
  • ver/jp/build/ver/jp/expected/ver/jp/
  • ver/ique/build/ver/ique/expected/ver/ique/
  • ver/pal/build/ver/pal/expected/ver/pal/
Re-run make_expected.sh any time you pull upstream changes that affect the build, so the reference stays current.

coverage.py

coverage.py tracks which functions have been matched. After you’ve matched a function and verified it compiles, run:
./coverage.py --delete-matched
This removes .s assembly files from ver/us/asm/nonmatchings/ (and equivalent paths for other versions) that correspond to functions now implemented in C. Removing these files keeps the nonmatchings/ directories clean and makes it easy to see how much work remains.

Other tools

The tools/ directory contains several additional scripts you may encounter:
ScriptPurpose
rename.pyRenames a function across the codebase — updates the .c file, assembly references, and symbol address files consistently
sym_info.pyLooks up information about a symbol (address, size, source file) from the build’s map file
update_symbol_addrs.pyUpdates symbol_addrs.txt after symbols are renamed or relocated
Run any of these with -h to see their full usage.

VS Code integration

The project includes VS Code task definitions for the two most common operations:
  • Run Build Task (Ctrl+Shift+B) — runs ninja and shows compiler errors and warnings in the Problems tab.
  • Run Test Task — runs diff.py for the current function and shows compiler feedback inline.
These tasks require no additional configuration; they work out of the box after cloning the repository and opening it in VS Code.

Build docs developers (and LLMs) love