← Alle prosjekter

Paratrooper – Machine Code to C

IBM PC-spillet Paratrooper fra 1982, portert ved å automatisk oversette alle 2 010 maskinkodeinstruksjoner til C, verifisert mot originalen over 400 000 BIOS-kall, med et nytt lag av HD-grafikk på toppen.

Overview

Paratrooper is a 1982 IBM PC game by Greg Kuperberg. Instead of rewriting it from scratch, I wrote a translator that converts the original machine code into C. Every one of the 2,010 instructions in the original PARA.COM became a few lines of C, so the game logic, the speed and even the small quirks are exactly the original's.

On top of that, a new front end draws the game in high resolution, without changing a single line of the translated game code.

The challenge

A remake that only looks like the original is easy. A port that behaves exactly like it is not: timing, collision rules, random numbers and edge cases all live in 8086 machine code written more than 40 years ago. The goal was to carry all of that over automatically, and to prove that nothing was lost.

How it works

original/PARA.COM ──translate.py──► game.c   (one block of C per 8086 instruction)
                                 └► image.c  (graphics, text and tables)

Proving it is identical

A verification tool runs the original PARA.COM on the Unicorn CPU emulator, with the same BIOS code and the same scripted keypresses as the C version. Both write a log line for every BIOS call, with all registers and flags, plus a checksum of the data segment and video memory every 64 calls.

The result: identical for 400,000 BIOS calls, including 6,250 memory checksums, across the title screen, several games, game over and a new high score.

HD graphics without touching the game

The game draws its objects by copying fixed bitmaps into CGA video memory. Every frame, the new front end searches the screen for these known bitmaps (helicopters, paratroopers, soldiers, the gun in 21 angles and the bunker). Where it finds one, it hides the original pixels and draws a high-resolution version on top, together with a night-sky background.

The translated game code still runs exactly as in 1982. It has no idea that it now looks different.

Tech

Teknologier