Live data from Hacker News

An 8086 PC emulator in 4043 bytes

ioccc.org

1–10 of 39 posts

Re: An 8086 PC emulator in 4043 bytes

#6

The source itself: http://ioccc.org/2013/cable3/cable3.c Or after running through preprocessing (not a huge help I found, sadly): https://gist.github.com/peterc/8259713

Did you do this by hand? Line 38 looks weird: main(BX,nE)char nE; {

That's an old-school C function declaration. Note that the function return type are parameter types are implicitly int. nE is then explicitly declared to be a char pointer pointer.

Re: An 8086 PC emulator in 4043 bytes

#7
post #6

Earlier quoted context omitted.

Did you do this by hand? Line 38 looks weird: main(BX,nE)char nE; {

That's an old-school C function declaration. Note that the function return type are parameter types are implicitly int. nE is then explicitly declared to be a char pointer pointer.

But the char is outside of the declaration and before the opening brace - is this legal? And especially, why isn't it written like main(BX,charnE)? Doesn't save any bytes,it rather adds one semicolon...

Re: An 8086 PC emulator in 4043 bytes

#8

The source itself: http://ioccc.org/2013/cable3/cable3.c Or after running through preprocessing (not a huge help I found, sadly): https://gist.github.com/peterc/8259713

Did you do this by hand? Line 38 looks weird: main(BX,nE)char nE; {

No, just passed through gcc -E which essentially preprocesses the file only (in this case in order to unpack all the defines) without fully compiling.

Re: An 8086 PC emulator in 4043 bytes

#9
Neat, the linked hd.img file contains windows, Simcity, AutoCAD, etc. Has anyone compiled this for Windows? If so, would you kindly post the binary? It'd be fun to play with this old software again.

Re: An 8086 PC emulator in 4043 bytes

#10
This is interesting, though it might be a bit of a cheat. He's put some data in the BIOS image to assist in decoding instructions (not to take away from how amazing this is!):

"CPU supports the full 8086/186 instruction set. Due to the complexities of the 8086’s arbitrary-length instruction decoding and flags, 8086 instructions are first converted to a simpler intermediate format before being executed. This conversion, along with instruction lengths and how each instruction modifies the flags, is assisted by some lookup tables which form part of the BIOS binary."

With that in mind, the BIOS is _hand-written_ and about 12kB (gzips to <4kB), so that's also a fantastic achievement. All-in-all, this is a wonderful entry.

Post reply on HN