Porting Cricket 07 to the browser
2026-11-25
I grew up playing EA Sports Cricket 07 on Windows XP. Twenty years later, getting a 2006 32-bit Windows game running on a Mac or a phone still meant wrestling with Wine wrappers or heavy x86 emulators. I wanted to open a URL and play a match right away.
The port is live at cricket07.dhaiwat.com (source). Since launching, it has reached 150,000 daily active players and over 6 million monthly page views.
Static recompilation instead of emulation
Emulating an x86 CPU and Windows XP inside a browser burns too much CPU and battery, especially on phones. When I inspected the Cricket 07 executable in Ghidra, it turned out to be well suited for ahead-of-time static recompilation: about 3.7 MB of MSVC 7.1 machine code loaded at a fixed base address (0x400000) with no relocations, and roughly 250 imported Windows functions across 9 DLLs. Even without debug symbols, RTTI and 539 leftover assert strings let me recover 346 C++ classes automatically.
I built a Python translator on top of Capstone that converts each x86 function into a C function (~20,400 functions and 1.05 million instructions in total). Keeping guest registers and the x87 floating-point stack in local C variables before spilling them at call boundaries let Clang optimize the generated code cleanly, cutting WebAssembly size from 42 MB to 31 MB and CPU time by a third.
The hardest bugs were subtle x86 edge cases: reversed x87 operand encodings, overlapping rep movsd copies, and precision flags that affect ball physics. Before trying to boot the game, I built a differential test harness with Unicorn Engine that ran thousands of original x86 functions side-by-side against their recompiled C counterparts on random inputs. Testing the game's statically linked zlib inflate to 33/33 byte-exact passes caught most of the translator bugs before WinMain ever ran. The one surprise at runtime came from EA's audio banks, which unpack ~3,100 instructions of x86 onto the heap and jump to them; a tiny interpreter handles those whenever VirtualProtect marks heap memory executable.
Direct3D 8 on WebGPU
Instead of porting to OpenGL first, I wrote a thin Win32, DirectInput 7, and DirectSound host layer in C and implemented Direct3D 8 directly on WebGPU. I used wgpu-native on macOS so I could debug frames natively in seconds, then compiled the same C codebase to WebAssembly with Emscripten.
The game compiles its vs.1.1 vertex shaders and ps.1.1 pixel shaders from text at startup, so the renderer intercepts and translates them to WGSL on the fly. Because WebGPU in the browser can only present frames from the main page thread while the multithreaded game runs in a Web Worker, rendering is split into a command recorder on the game thread and a WebGPU replay queue on the page thread. Once matches rendered properly, I added native 16:9 widescreen (widening camera culling while anchoring HUD panels to the screen edges), gamepad support, and touch controls.
Surviving iOS Safari and 1.1 GB of assets
Shipping to real players meant making a 1.1 GB desktop game start fast and stay alive inside mobile Safari's strict 2 GB per-tab memory ceiling:
- Streaming install and Lite mode: Game archives are split into resumable gzip parts cached in the Origin Private File System (OPFS). Cutscene videos stream in the background after boot, and a 440 MB Lite option skips commentary so players on mobile data can get into a match quickly.
- BigInt clock allocations: During intro videos, the game polls the clock millions of times in a tight loop. Crossing the Wasm-to-JS boundary via
clock_gettimeboxed 64-bit timestamps as JavaScriptBigIntobjects, bloating Safari's worker heap from 320 MB to 1.1 GB before reaching the title screen. Switching to plain-double Emscripten timers fixed it immediately. - Stalled garbage collection on WebKit: On iPhones, streaming hundreds of megabytes through
fetch()into OPFS caused WebKit's page-thread garbage collector to stall, letting per-draw WebGPU wrapper garbage pile up until iOS killed the tab four minutes into a match. Moving downloads into a disposable Worker, lazily mapping.bigarchives, and removing per-draw JS allocations kept memory flat around 500 MB.
Lockstep multiplayer and retro-port
With help from Stephan Cilliers (who ported Rugby 06 on the same engine), we added a deterministic mode with a virtual clock and fixed thread scheduler. Because two browsers given the same controller inputs compute bit-identical memory hashes frame after frame, online 1v1 matches only need to exchange tiny input packets over WebRTC and Cloudflare Durable Objects.
After finishing the port, we packaged the entire static-recompilation toolchain, Win32/D3D8 runtime, and determinism harness into retro-port, an open-source Claude Code skill for bringing other Direct3D 8 era Windows games you own to the web.