Chris Wellons5 min readintermediate
A custom virtual machine for the Stars! 4X game
Summary
Stars!VM is a 32‑bit Windows executable that embeds a custom 80286 emulator and a Win16‑to‑Win32 bridge to run the 1995 4X game Stars! without any external emulators. The author adds differential fuzzing, hot‑routine patching, I/O buffering and asset compression, achieving about a 2× speedup in turn generation.
- The emulator runs x87 floating‑point directly on host hardware and is validated with a differential fuzzer that compares emulated vs. JIT‑executed instructions.
- Hot game routines (e.g., the L’Ecuyer PRNG) are identified via tracing and replaced with custom 80286 instructions, cutting turn generation time roughly in half.
- A Win16‑to‑Win32 bridge maps 16‑bit handles, marshals structs, services DOS interrupts, and implements WaveMix.dll natively, allowing the game to run as a native 32‑bit process.
- Buffered I/O and a custom LZ‑based compression reduce asset size from ~3 MB to ~1.5 MB and lower I/O overhead during turn generation.
Engineers building emulators, legacy‑API bridges, or performance‑critical VM layers can learn practical techniques for validation, hot‑code patching, and integration with modern OS services.
7/10
