Hacker News new | past | comments | ask | show | jobs | submit login
4043 byte PC emulator (2013) (ioccc.org)
126 points by luu 5 months ago | hide | past | web | favorite | 22 comments

Oddly, megalith.co.uk, specified in both the OP page and on the github header, is now "for sale".

Edit: 8086tiny.freeforums.net is functional and has had a few recent posts.

The Internet Archive has a working copy: https://web.archive.org/web/20150424213422/http://www.megali...

This is awesome!

I would love to see a version of it written to be as readable as possible. (If there is such a thing already out there, pointers are welcome, thanks!)

Here is the fully commented, non obfuscated version of this same emulator: https://github.com/adriancable/8086tiny


That is some nice code, many thanks for the link.

Link to the IOCCC source code:


There are some nice easter eggs in the source

That's gotta be generated with a tool, right?

Uh, not really? I'm pretty sure that identifiers are automatically replaced somehow with conventional editors but a general minification to the degree required by IOCCC is never automatic.

If you are interested in an actual minification process of a winning IOCCC entry, Don Yang [1], who has eight (!) winning entries, has put a compressed screencast alongside with recent winning entries (example: [2] is a screencast for [3]). My experience (I too have one winning entry) had been similar.

[1] http://uguu.org/

[2] http://ioccc.org/2018/yang/spoiler.html

[3] http://ioccc.org/2018/yang/prog.c

That screencast helped remove some of the mystery behind the method, but I am even more amazed now.

Actually I do think Yang's screencast is kind of unusual, as he seems to start with a very clear vision and the vision seems to remain intact throughout the process. (Or the screencast may have simply omitted experimentation processes...) By comparison, this [1] is my version of notes towards my winning entry [2], which contains a lot of failed approaches and mistakes :-)

[1] https://gist.github.com/lifthrasiir/3909337

[2] https://www.ioccc.org/2012/kang/kang.c

This is AMAZING! Thank you for sharing.

Possibly there were some assisting tools, but most likely nothing more complicated than search-and-replace. Handcrafting these things is the whole art of the IOCCC.

Many years ago I wrote some obfuscated Perl, assisted by the fact that the language is pretty obfuscated to start with. https://flatline.org.uk/snowflake.pl.txt - I think I may have had a tool to help it fit the template, but since you can't have a space in the middle of an operator restructuring the program to make the operators fit the snowflake was a major part of the effort.

While there's an "unobfuscated" version of the emulator program in this thread, it's clearly not the same program - there's no "switch/case" in the obfuscated version.

You can turn a switch statement into a series of ? :

switch(a) { case x: do1(); break; case y: do2(); break; default do3(); break; }


   a == x ? do1() : a == y ? do2() : do3();
These structures can be seen in the minimized version (and a few other IOCCC winners :-).

This code likely doesn't optimize quite as well. Several cute things you can do with switch statements cannot be translated so easily.

Aha, found a partially-deobfuscated version: https://gist.github.com/slacka/8306176

The instruction decode mechanism is a chain of "e--||(expression), e--|| ..." expressions. At the point where e-- is zero the expression will be evaluated.

The program makes heavy use of the equivalence between "index[pointer]" and "pointer[index]", presumably to save brackets.

Very true || !false. The 3rd, 4th and 5th ways to encode a switch can be done using <disconnected>

Not necessarily. The first part is clearly hand-edited at minimum, if not completely handwritten:

    I n t,e,l[80186],*E,m,u,L,a,T,o,r

My 2012 entry similarly started with the self documenting

       Int L[A],m,b,*D=A,
requiring compile time defs -DInt=int/long -DA=500000.

But it did include its own Basic I/O System in the source:



I think this “cheats” a bit by putting quite a bit of emulator functionality in the custom bios image. Nevertheless very impressive.

The "cheats" are 1879 bytes of table data stored in the bios image :-).

If you liked this, I also suggest take a look at Christopher Mills entry from 2018, which is a PDP-7 emulator, which doesn't use the BIOS tables trick.


[disclaimer: I am an IOCCC Judge]

I didn't get it until I read the page. 4043 bytes, 8086 nibbles!

Code golfing taken to its extreme can be as scary as other extremists.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact