Show HN: PS2 games statically recompiled to WebAssembly
PlayStation 2 games can now be played directly in web browsers without the need for an emulator. This is achieved by translating the games' Emotion Engine machine code into C++, then compiling it to WebAssembly. The translated code is linked with a reimplementation of the PS2's operating system and hardware, which renders graphics using WebGPU.
The first game successfully played using this method is Gran Turismo 4, selected due to its demanding nature. The game runs at full speed, 50 frames per second in Chrome on a laptop's integrated GPU at double the PS2's resolution. God of War II was also successfully played using the same process. The recompilation process involves reading the game's executable, following its control flow to identify functions, and emitting C++ for them in 16 KiB units.
The output preserves the R5900's quirks, such as 128-bit registers, multimedia instructions, and the PS2's floating-point unit. A small PS2 kernel handles threads, semaphores, interrupt handlers, and the I/O processor. The disc is read over HTTP Range requests, so only the executable is downloaded initially. Vector units, responsible for most of the 3D work, are emulated with their specific pipeline delays and float rules.
Graphics are handled by WebGPU compute shaders, while sound and movies are re-implemented using the PS2's original components. The resulting framerate improvements are significant, with most of the remaining challenges arising from the browser's performance rather than the emulation itself.
Rewritten by urgent.news; may contain errors — check the original.
Source: github.com