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 CP/M on nearly anything with more readable code.

7 thoughts on “Obfuscated C 8080 Emulator Ported

    1. “Extract CPM64.COM from the SOURCE directory, and copy it to files named A and B (these will be the disk drives). Now rename the provided c_bios.bin to C and run the emulator.” I was confused at first, but it basicly instructs you to overwrite the C file with the c_bios.bin file (which, if you tried basic, was c_basic.c at first).

      Copying all the wordstar files to a new “empty” A file worked (again, CPM64.COM copied as A) and importing the files worked. then, run WINSTALL.COM and follow the menu things (install onto A generated ws.com and now im in wordstar, a bit lost, but found http://www.bitsavers.org/pdf/microPro/Wordstar_3.3/Wordstar_3.3_Reference_Manual_1983.pdf that helped me a bit (now have a testfile saved after editing)

      Good luck :D

  1. “IOCCC — the International Obfuscated C Code Contest”

    I can’t help feeling a little disappointed at the lack of imagination in the acronym given the subject mattter!

  2. I compiled toledo2.c with no problem and ran the first part with the basic interpreter running.

    But if you running the next part with CPM part make sure the A and B files (copies of CPM64.COM) are read write so:
    chmod 664 A B

    Otherwise you get Segmentation fault (core dumped). In the gdb debugger its a failure at fseek.

    Its sound silly but may have some users like me scratching their head.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.