Obfuscated C 8080 Emulator Ported

Obfuscated C 8080 Emulator Ported

[Oscar] is no stranger to writing hard-to-read C code. While most of us do that by accident, there are those who strive to write the most unreadable code and enter it in the IOCCC — the International Obfuscated C Code Contest. One of his winning entries was a single C function that emulates an 8080. With a few support files, the plucky little emulator will run CP/M.


The emulator won best in show, but that was in 2006. Things have changed a bit and [Oscar] has updated the code so that you can continue to try it if you want to give yourself a headache reading code. The portability isn’t a CPU issue — modern CPUs will happily run code from 2006. The problem is the compiler and operating system. Compilers are much stricter these days, and Linux needs a little extra coaxing to give access to the input stream the way the faux computer needs it.



If you want to puzzle out the code, don’t read any further. Spoilers ahead! The code has an array of 64K representing all the memory an 8080 can use without some bank-switching scheme. After that, a loop simply has to read the array, determine the opcode, and perform the operation. The registers are in the o array. Why o? Well, it is supposed to be obfuscated, remember?


The emulator needs two binary files: one containing a stripped-down BIOS system and the other  Tiny Basic. Alternatively, you can download a file that will run CP/M, including Wordstar.


If you prefer running on real hardware, slip one of these in your pocket. If obfuscation isn’t your thing, run obfuscated emulator ported