# WWF No Mercy (decompilation) A matching decompilation of WWF No Mercy for the Nintendo 64: C source that the game's own compiler (KMC GCC 2.7.2) turns back into exactly the original machine code. All 3466 functions build from C files: the main program and the five overlays. 3426 of them (98.8%, 99.5% of the code by size) are C that the compiler turns into exactly the original code. The other 40 were written in assembly in the original; their files hold those instructions in an `asm()` block (see Notes). `build.py` rebuilds the game from this tree and checks it against your original, byte for byte. The project was started with [decompdecomp](https://github.com/n-delic/decompdecomp), which split the game and matched the first functions. The matching work is now carried on and will be finished by Claude (Anthropic's AI model), working function by function in this repository. decompdecomp is no longer used to match; the build still borrows its compiler, binutils and Python packages (see Build). ## Build 1. Put your own copy of the game here as `baserom.z64` (it is in `.gitignore`; never commit it). The tree matches the copy with SHA-1 `91cee3d096f4a76644d8b35b9aead6448909abd1`. 2. `python3 build.py`. It uses decompdecomp's pinned period compiler (KMC GCC 2.7.2), its binutils and its Python packages (`decompnet`), so decompdecomp must be installed. The system `python3` does not have those packages, so `build.py` re-runs itself under decompdecomp's own Python. It finds that Python from the `decomp` command (the first line of `~/.local/bin/decomp`, or the `python` it launches) and, if `decomp` isn't on `PATH`, from the `uv tool install` location `~/.local/share/uv/tools/decompnet/bin/python`. If neither exists it stops with "install decompdecomp first". If `build.py` can't find decompdecomp's Python, run it with that interpreter directly, for example `~/.local/share/uv/tools/decompnet/bin/python build.py`. ## The game's parts The game is a main program plus five overlays. An overlay is a block of code and data that stays on the cartridge until the game needs it, and is then copied into memory. **Why the game has them.** The console has 4 MB of memory (8 MB with the Expansion Pak), and the game's code alone is about 1.4 MB, before any wrestler, arena or sound is loaded. So only main, with the code every part of the game needs, is always in memory. The rest is loaded for the part of the game that is running, and the next part's code is later loaded over the same memory. **Why they matter here.** Because overlays take turns in the same memory, two functions in different overlays can have the same address. A tool that reads the game as one flat program gets this wrong: it files one overlay's code under another's addresses and cuts functions in pieces. The map below comes from the game's own table of overlays (ROM offset 0x539A0), and every function is built and checked inside its own overlay. | Part | ROM | Loads at | Functions | In C | | :-- | :-- | :-- | --: | --: | | main | 0x001060-0x057270 | 0x80000460 | 966 | 926, and 40 in `asm()` | | overlay 1 | 0x057310-0x081210 | 0x800D9960 | 404 | 404 | | overlay 2 | 0x081210-0x0AE390 | 0x80106760 | 213 | 213 | | overlay 3 | 0x0AE390-0x0FD250 | 0x80106760 | 656 | 656 | | overlay 5 | 0x0FD250-0x144BE0 | 0x80106760 | 327 | 327 | | overlay 4 | 0x144BE0-0x1BD150 | 0x800D9960 | 900 | 900 | There are two memory slots. Overlay 1 sits in the first (0x800D9960) and is loaded together with one of overlays 2, 3 or 5, which share the second (0x80106760). Overlay 4 is large and takes the place of both. ### What each part does This is read from the decompiled code and from the text each part holds. Some of it is still inferred, and most functions are still named only by their address. | Part | What it does | What shows it | | :-- | :-- | :-- | | main | Always in memory. Holds the code the other parts share, and the loop that chooses the next overlay. | `func_80026888` is the loop, `func_8000073C` loads an overlay, `func_800007AC` starts it. | | overlay 1 | The front end's framework. It runs the frame loop for whichever of overlays 2, 3 or 5 is loaded beside it, draws text, loads textures, and holds the shared wording (match types, championships, options, records). | `func_800D997C_ovl1` sets up, then runs `func_800DAAE8_ovl1` until that returns something other than 0. Each pass calls 0x80106798, where overlays 2, 3 and 5 each have a function. `func_800DCB14_ovl1` draws text. | | overlay 2 | The opening, and the scenes between matches (story and entrance scenes). It is the first to run at power-on and makes the power-on checks. | `func_80106944_ovl2` reads the console's TV type and reset type and tests whether Start is held. The text has wrestler names and the Rock's catchphrase. | | overlay 3 | The menus, the results page and the tournament brackets. It decides whether a match, a scene or the editor comes next. | `func_80108C54_ovl3` runs the menus (`D_800457A4` is the current one) and turns the exit code `D_800457A0` into the flags below. `func_80126624_ovl3` draws the bracket page. | | overlay 5 | Create-a-superstar (appearance, moves, parameters), the shop, and save data: the Controller Pak, and the Transfer Pak with the Game Boy version. | Its text names all of these. When it closes it hands back to the menus (`func_80106818_ovl5`). | | overlay 4 | The match itself, with the computer-controlled wrestlers. It has no text of its own. | `D_80159990` holds the wrestlers (0x358 bytes each) and `D_801596C0` a "brain" for each (0xB0 bytes). | **How the next overlay is chosen.** The main loop goes round forever. Each time, it loads overlay 1 and then looks at the flags in `D_800A10B0`, which the part that ran last has set. They are tested in this order: | Flag | Effect | | :-- | :-- | | 0x01 clear | run overlay 2 | | 0x08 clear | run overlay 3 | | 0x40 set | run overlay 5 | | 0x02 clear | run overlay 4 | The flags start at 0, so overlay 2 comes first at power-on. The menus (overlay 3) then leave one of these: | Value | What follows | | :-- | :-- | | 0x01 | the match, then the menus | | 0x18 | the match, then overlay 2 | | 0x02, 0x06, 0x12, 0x22 | overlay 2 (0x12: overlay 2, the match, and overlay 2 again) | | 0x40 | overlay 5, then the menus | | 0x03 | the menus again | **How a computer-controlled wrestler works.** `func_800F03F0` fills in what the brain knows (the distance and angle to the opponent, the distance to each corner, both wrestlers' states) and then calls one of the routines in the table `D_80145A10` (145 entries). The routine answers with button presses: `func_8010838C`, for example, walks toward the opponent by pressing the directional pad. `func_80118368` copies those presses to the place where the match code looks for the controller. `func_800FCEB4` starts another routine, and timers return a brain that is stuck to routine 0. A function in main or overlay 4 is named `func_
`. In the other overlays the name ends in `_ovl