# Mario Kart Arcade GP — Static Recompilation **The arcade racer that brought Mario and Pac-Man together on the same track — now ripping through your PC at native speed.** ## What Is This? This is a **static recompilation** of *Mario Kart Arcade GP* (2005) — the wild arcade-only Mario Kart built by **Namco**, running on **Sega**'s hardware, with **Nintendo**'s blessing. Three gaming giants, one insane kart racer. Instead of emulating the original hardware, we **translate the game's PowerPC machine code directly into native C**, then compile it for your PC. The result? The game runs natively — no emulator overhead, no compatibility layers, just raw speed. ### Wait, What's a Triforce? No, not *that* Triforce. The **Triforce arcade board** was a joint venture between Sega, Nintendo, and Namco (yes, really). It's basically a GameCube on steroids: | Component | GameCube | Triforce | |-----------|----------|----------| | CPU | Gekko PPC @ 486 MHz | Same Gekko @ 486 MHz | | GPU | Flipper (GX) | Same Flipper (GX) | | RAM | 24 MB | **48 MB** | | Media | Mini-DVD | GD-ROM / NAND | | Input | Controllers | Steering wheel, pedals, buttons | | Extras | Memory cards | Coin slot, card reader, JVS I/O | Same heart, bigger muscles, and an arcade cabinet wrapped around it. ## How Static Recompilation Works ``` Original Game (Triforce) Recompiled Game (PC) ======================== ==================== +-----------------+ +-----------------+ | PowerPC Machine | mka_recompiler | Native C Code | | Code (.dol) | ================> | (recomp_*.cpp) | +-----------------+ +-----------------+ | | v v +-----------------+ +-----------------+ | Gekko CPU | | Your x86/ARM | | (486 MHz PPC) | | CPU (GHz+) | +-----------------+ +-----------------+ | | v v +-----------------+ +-----------------+ | GX Graphics | | Direct3D 11 | | (Flipper ASIC) | | (GPU shaders) | +-----------------+ +-----------------+ | | v v +-----------------+ +-----------------+ | DSP Audio | | XAudio2 | | (ADPCM decode) | | (native mixing) | +-----------------+ +-----------------+ | | v v +-----------------+ +-----------------+ | JVS Arcade I/O | | Keyboard/ | | (wheel, pedals) | | Gamepad (XInput) | +-----------------+ +-----------------+ ``` Every PowerPC instruction gets translated into equivalent C code. A `lwz r3, 0x10(r1)` becomes `ctx->r[3] = mem->read32(ctx->r[1] + 0x10)`. A `bl 0x80012345` becomes `func_80012345(ctx, mem)`. The hardware — graphics, audio, input — gets reimplemented using modern APIs. The result is a native executable that produces the same output as the original game, instruction for instruction. ## Project Structure ``` mka/ +-- CMakeLists.txt # Build system +-- README.md # You are here +-- config/ | +-- mka.toml # Recompilation settings | +-- symbols.txt # Known function names/addresses +-- include/mka/ | +-- runtime.h # Core runtime types (CPU, Memory, FuncTable) | +-- hw/ | | +-- triforce_hw.h # Triforce hardware constants | | +-- os_defs.h # Dolphin OS + Triforce extensions | +-- arcade/ # Arcade-specific headers | +-- audio/ # Audio subsystem headers | +-- gx/ # Graphics headers | +-- input/ # Input mapping headers +-- src/ | +-- main.cpp # Entry point & game loop | +-- runtime/ | | +-- ppc_context.cpp # PowerPC CPU state | | +-- memory.cpp # 48 MB emulated RAM | | +-- func_table.cpp # Function dispatch & init | | +-- os_funcs.cpp # Dolphin OS HLE (timing, threads, etc.) | +-- arcade/ | +-- triforce_io.cpp # JVS arcade I/O (steering, pedals, coins) +-- tools/ | +-- recompiler/ # PPC -> C static recompiler | +-- dol_info/ # DOL file analyzer +-- lib/ | +-- gcrecomp/ # GameCube recomp toolkit (submodule) +-- recompiled/ # Generated C code (not committed) ``` ## Building ### Prerequisites - **CMake** 3.20+ - **Visual Studio 2022** (or any C++20 compiler) - **Windows SDK** (for Direct3D 11, XAudio2, XInput) - A legally obtained copy of *Mario Kart Arcade GP (USA)* (`GGPE01`) ### Build Steps ```bash # Clone with submodules git clone --recursive https://github.com/sp00nznet/mka.git cd mka # Configure cmake -B build -G "Visual Studio 17 2022" # Build cmake --build build --config Release ``` ### Running ```bash # Place your ISO in the project root, then: ./build/Release/mka_launcher.exe "Mario Kart Arcade GP (USA).iso" ``` ## Current Status **The game boots through full initialization with a D3D11 window and working GX graphics pipeline, and the Triforce media-board boot protocol has been fully reverse-engineered.** The recompilation pipeline is fully operational: - 656,200 PPC instructions disassembled at **99.73% coverage** - 12,434 functions discovered and translated to native C - 2.5 million lines of generated code compile into a 22 MB executable - Full boot: Namco framework → Dolphin OS init → DSP/ARAM → 20+ game subsystem inits - **D3D11 640×480 window** running at 60fps (VSync) with frame loop - **GX FIFO pipeline** operational: FIFO interception → command parser → TEV shader compilation → D3D11 rendering - Test triangle renders through the full GX → TEV shader → D3D11 pipeline - Disc image mounted (4,428 files) for DVD reads ### Media-board boot protocol (reverse-engineered) The game's boot is driven by a **cooperative scheduler** that idles until the Triforce **media board** delivers boot commands over an EXI/DIMM channel. That whole path has now been traced end-to-end and a replay framework built: - **Boot data path mapped:** scheduler (`func_80222724`) → idle handler → DIMM vtable (`available()`/`read()`/`send()` @ `0x8040F1B8`) → EXI Channel 2 (`0xCC006828`) → media board. - **Message format decoded:** `[big-endian length][command/scene-type @ byte 4][payload]`, copied into a per-scene ring buffer and dispatched by command code. The protocol is a **symmetric request/response handshake** — the board sends a command, the game replies with a code (e.g. `0x80`), the board sends the next command. - **Media-board HLE** (`src/arcade/mediaboard.cpp`, opt-in via `MKA_MEDIABOARD=1`) serves the `available()`/`read()`/`send()` channel from the mounted ISO and replays a scripted boot sequence (`MKA_MB_SCRIPT`), with a state machine that advances on reply or timeout. - **Scheduler keep-alive** lets the cooperative scheduler run the full multi-message handshake instead of exiting after the first round — verified driving game scene code. - **Capture tooling:** an instrumented build of Dolphin's Triforce `AMMediaboard` dumps the real board↔game conversation for replay (see `docs/mediaboard_capture.md`). - Currently working on: obtaining the firmware boot-command sequence (a clean Dolphin Triforce capture, gated on the ALL.Net/namcam2 network layer) to drive boot to the title screen. ## Roadmap - [x] Project structure and build system - [x] Triforce hardware definitions (48 MB RAM, DIMM board, JVS I/O) - [x] Runtime layer (CPU context, configurable memory, function table) - [x] Dolphin OS HLE (timing, interrupts, arena, cache, threads, mutex) - [x] Triforce arcade I/O framework (steering, pedals, coins, card reader) - [x] DOL parser and section loader - [x] PPC disassembler (150+ Gekko instructions including Paired Singles) - [x] Control flow graph analysis (4-phase function discovery) - [x] PPC -> C code generator (201 instruction cases) - [x] Symbol map loader (Dolphin .map and CSV formats) - [x] Recompiler CLI with full pipeline orchestration - [x] First successful recompilation (12,434 functions) - [x] First boot — entry point reached, game executing native code - [x] DOL sections loaded into 48 MB emulated RAM - [x] SDA bases discovered (r13=0x805BDE20, r2=0x805C14E0) - [x] BI2 boot info structure (fixed null pointer crash) - [x] HW register HLE (EXI, SI, DI, VI, PI, DSP/ARAM) - [x] Namco cooperative scheduler HLE (DIMM board bypass, task injection) - [x] GX FIFO interception and command parser (BP/CP/XF register dispatch) - [x] GX graphics → D3D11 rendering (TEV shader generation, texture decode, vertex assembly) - [x] D3D11 window + frame loop with Win32 message pump - [x] DI command interception for AM Mediaboard (Dolphin Triforce reference) - [x] Media-board boot data path reverse-engineered (scheduler → EXI Ch2 → DIMM) - [x] Boot message format decoded (length-prefixed command/response handshake) - [x] Media-board HLE + scripted boot replay (`mediaboard.cpp`, `MKA_MEDIABOARD`) - [x] Cooperative scheduler keep-alive (full multi-message handshake) - [x] Instrumented Dolphin Triforce capture tooling for the real boot sequence - [ ] Obtain firmware boot-command sequence (Dolphin capture / network unblock) - [ ] Full game boot to title screen - [ ] DSP audio → XAudio2 - [ ] JVS I/O → keyboard/gamepad input mapping - [ ] Race gameplay - [ ] Namco card reader emulation (save data) - [ ] Network play stubs ## The Game *Mario Kart Arcade GP* was released in 2005 exclusively for arcades. It was developed by Namco (now Bandai Namco) and features characters from both the *Mario* and *Pac-Man* universes: **Mario Characters:** Mario, Luigi, Peach, Toad, Donkey Kong, Wario, Bowser, Waluigi **Pac-Man Characters:** Pac-Man, Ms. Pac-Man, Blinky The game features unique items not seen in console Mario Kart titles (like the Pie Throw and the Pac-Man ghosts), a camera that takes your photo during races, and Namco-themed tracks alongside the classic Mushroom Kingdom courses. It's one of the few Mario games that Nintendo didn't develop in-house, and it's never been ported to a home console. Until now (sort of). ## Technical Details The game was built using: - **Dolphin SDK** — Nintendo's official GameCube development kit - **Namco System Libraries** — Namco's internal game framework (rendering, audio, I/O) - **Metrowerks CodeWarrior** — C/C++ compiler targeting Gekko PowerPC The DOL executable contains all game code compiled to PowerPC 750 (Gekko) instructions. Track data, textures, models, and audio are stored on the GD-ROM and streamed into the 48 MB RAM during gameplay. ## Credits & References This project builds on the work of many talented people and open-source projects: - **[gcrecomp](../../../gc/gcrecomp/)** — GameCube Static Recompilation Toolkit - **[libogc](https://github.com/devkitPro/libogc)** (zlib) — Open-source Dolphin SDK reimplementation - **[Pureikyubu / Dolwin](https://github.com/emu-russia/pureikyubu)** (CC0) — GameCube emulator, OS HLE reference - **[MAME](https://github.com/mamedev/mame)** (BSD-3) — Triforce arcade board driver - **[YAGCD](http://hitmen.c02.at/files/yagcd/)** — Yet Another GameCube Documentation - **[N64Recomp](https://github.com/N64Recomp/N64Recomp)** — Pioneering static recompilation for N64 ## Legal This project does not contain any copyrighted game code, assets, or data. You must provide your own legally obtained copy of *Mario Kart Arcade GP*. The recompilation tools and runtime libraries are original works. *Mario Kart* is a trademark of Nintendo. *Pac-Man* is a trademark of Bandai Namco. *Triforce* arcade hardware was a joint development of Sega, Nintendo, and Namco. This is an independent preservation and research project with no affiliation to any of these companies. --- *"Here we go!" — Mario, probably excited about native PC performance*