When’s a NES ROM not a NES ROM? When it’s a ZIP file. But it doesn’t have to be one or the other; you can have your ROM and uh, eat it too? Coder Vi Grey created a completely valid ROM for the Nintendo Entertainment System that you can also unzip using your archiving application of choice.
To accomplish this feat, Grey took advantage of the fact that the iNES file format, used by ROMs, includes some padding between data sections that isn’t interpreted by the console.
On the ZIP side, it’s possible to mark data as a comment, which is also ignored (usually). With somewhere in both formats to store information without corrupting the other type of file, all Grey had to do was blend them together:
If we find enough padding space in the PRG data, we can just replace the padding data with the ZIP file. For this NES ROM, I counted padding bytes from the end of the PRG data until I had enough space to embed the ZIP file, then I made note of how far into the NES ROM I started embedding the ZIP file.
I then updated all of the offsets of the ZIP file data by adding how far into the NES ROM the ZIP file started. After that, I set the ZIP File Comment Length to be the size of the rest of the NES ROM data, which is the end of the PRG data and all of the CHR data.
As for the contents of the ZIP, it’s the source code for the ROM… which you may have guessed by looking at the lead image.
So, what are the practical implications? Well, nothing really. But it’s super interesting. If you’d like to look at the source code, Grey has made it available on GitHub.