Code Golf masterclass: fitting a whole bootable CDROM game into a tweet

Alok Menghrajani is a master player of the game of Code Golf, in which you challenge yourself to do something useful in as few characters as possible; his latest triumph is fitting a bootable CDROM image including a fun little retro game into a single tweet.

The tweet is the result of Menghrajani's investigations into the El Torito extensions to ISO 9660, which defines the CDROM format (the El Torito extensions are named after a chain of Mexican restaurants in Silicon Valley where the standards committee liked to eat). Menghrajani is not a fan of El Torito (he calls it "poorly written").

The game it boots into is "a mixture of Tron and Snake" -- you can play it by burning the disc image or by running it inside a virtual machine.

Menghrajani is a security engineer at Square who describes himself as having "put the 's' in https at Facebook" when he worked there.

Previous daring code stunts from Menghrajani include fitting a QR code inside a QR code and fitting a bootable floppy image and a retro game inside a 140-character tweet.

To handcraft a CD disk image, you must first get a basic understanding of ISO 9660. ISO standards unfortunately are usually expensive. ISO 9660 is however the same as ECMA 119, which means you can read the specification for free.

ISO 9660 has many extensions, such as UDF, El Torito, RockRidge, Joliet, etc. For bootable images, we only care about El Torito. The El Torito specification is, in my opinion, poorly written. There are mistakes (e.g. figure 7, last row), it's easy to forget that values are hex (no 0x prefixes), the figures aren't sorted in an intuitive order, etc. Thankfully, the document is fairly short.

To create a bootable disk, we start by writing 17 empty sectors followed by the Volume Descriptor Set. A sector is 2048 bytes.

Note: The ISO-9660 specification says the Volume Descriptor Set starts at sector 16. The El Torito specification calls for the Boot Record to live at sector 17. Technically, we should put a dummy Volume Descriptor in sector 16, but things seem to work fine without.

This Coder Fit a Bootable CD and Video Game Into a Tweet [Michael Gaynor/Motherboard]

Bootable CD + retro game in a tweet [Alok Menghrajani/Quaxio]

perl -E 'say"A"x46422,"BDRDAwMQFFTCBUT1JJVE8gU1BFQ0lGSUNBVElPTg","A"x54,"Ew","A"x2634,"/0NEMDAxAQ","A"x2721,"BAAAAYQ","A"x30,"SVVVqogAAAAAAAEAF","A"x2676,"LMBaACgB76gfbgTAM0Qv8D4uYAI86qqgcc+AXP45GA8SHIRPFB3DTeYSEhyBSwCa8CwicMB3rSGtkDNFSYwJHvc68MA","VapVqlWq"x330'|base64 -D>cd.iso [@alokmenghrajani/Twitter]