Tech
How Super Mario 64 Conquered the PDF
PDFs have typically been used to store reports, contracts, and a plethora of tax forms, but now one of them can run a Nintendo 64 game. Simply load a 23.5-megabyte file in your browser and Super Mario 64 will launch, complete with a jumping plumber and a magnificent castle backdrop. Tobi, the developer behind this feat, converted a document viewer into a game console, but he was inspired by a previous project, the DOOM PDF.
PDFs started life pretty simple a few decades back, basically just a way to ensure that pages printed out exactly the same everywhere, but as time passed, they began to add more layers. Developers began sneaking in XML for structure and JavaScript to perform tasks such as form completion and page zooming. To handle PDFs, most browsers employ a Javascript engine called PDF.js, which was developed by Mozilla. That engine will execute any code encoded in the PDF, as long as the viewer permits it. Tobi had a brainwave and packed a complete game inside.
Super Mario 64 was a beast that pushed the limits of what the Nintendo 64 could achieve in terms of 3D environments, adversaries, and gameplay. Porting it to different systems is a big process that begins with decompilation, or converting the original code into something that people can actually read. Several years ago, a team did just that, converting the original assembly code to C. As a result, a variety of ports began to appear on PCs, watches, and other devices. Then Tobi came along and basically rearranged the parts in that decompiled base to make them work with JavaScript.
The big problem was graphics, as JavaScript does not have direct access to graphics cards, making it difficult to get the game to look as it should. So, Tobi, what did you do? He chose to depict the 3D scenes as ASCII art, which consists of text characters forming Mario, the platforms, and the Goombas. Each frame redraws the grid on the PDF page. The sound is still not working, but you may control the game via keyboard inputs that are given to JavaScript. Try it out in Chrome, and you’ll notice that the arrow keys move Mario while the other keys allow you to jump and attack.
The game runs at one or two frames per second, making Mario slide more so than sprint. Loading levels is slow because Tobi left a few flaws from his previous Apple Watch port, such as glitches in older areas of the code that he never fixed, but you can skip the long intro scene and even warp directly to the levels. To be fair, because the game is moving slowly, precision maneuvers that were previously impossible to accomplish are now trivial.
The DOOM PDF was released first, and it includes a customized DOSBox emulator, which is just another chunk of JavaScript imitating some old PC hardware from 1993, but Tobi took that idea and removed the emulator to create a more streamlined Mario experience.
[Source]