gb2swf recompiles Game Boy ROMs into SWF files that run in Ruffle
A new static recompiler turns Game Boy and GBC ROMs into Haxe and SWF, and checks every block against an interpreter.
A developer has released gb2swf, a static recompiler for Game Boy and Game Boy Color ROMs. It takes the SM83 code (the CPU inside the Game Boy) and turns it into Haxe, which compiles to a SWF file that runs in Ruffle. The code is MIT licensed and public on GitHub under Burg-Media. No ROMs are included.
It finds the code by running the ROM first. Most recomp projects the author knows start from symbols or an existing decomp, and gb2swf has neither. So it runs the ROM on an interpreter: once with no input, then four times with random button presses, 6000 frames each. It logs every executed instruction and jump target, which separates code from data and resolves the jp hl jump tables for everything that actually ran.
Then it checks its own output. Interpreter and recompiled code run side by side on three input sequences, one the profiler never saw. Registers and cycle count must match at every block entry, and every frame must be identical. A block that diverges goes back to the interpreter, and code the profiler never reached stays interpreted, so the game keeps running. On the open licensed homebrew games it was tested on, 79 to 98 percent of executed instructions ran recompiled.
The weak spot is coverage. Random button mashing misses rare paths. You can record your own play and feed it back with gb2swf --record. The author says it works on the tool itself, but the manual is thin.
My take: the author is right that a decomp shows all the code, while a recomp only sees what got run. The checking step, which the author compares to matching, is the part decomp people will probably recognize.