Live data from Hacker News

An 8086 PC emulator in 4043 bytes

ioccc.org

21–30 of 39 posts

Re: An 8086 PC emulator in 4043 bytes

#22

Here's a link to a fully functional Windows binary (built with Visual Studio 2013): http://sdrv.ms/1hodqjP Just add the bios and image files elsewhere.

Missing MSVCR120D.dll. Can you compile in release mode or include that DLL too? Installing the Visual C++ Redistributable Packages for Visual Studio 2013 didn't help.

Re: An 8086 PC emulator in 4043 bytes

#23
post #22

Here's a link to a fully functional Windows binary (built with Visual Studio 2013): http://sdrv.ms/1hodqjP Just add the bios and image files elsewhere.

Missing MSVCR120D.dll. Can you compile in release mode or include that DLL too? Installing the Visual C++ Redistributable Packages for Visual Studio 2013 didn't help.

Updated with Release-build that should use the DLL in VS2013 redist package.

Re: An 8086 PC emulator in 4043 bytes

#27
post #20

The BIOS is part of the PC, yet it's not included in the 4043 bytes.

The BIOS is replaceable software. Standard on the IBM PC, but not the "bare metal" itself. One can only emulate so much within 4096 bytes.

"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."

I agree regarding the BIOS, but this sounds like the BIOS image contains "microcode" necessary for the emulator to run, which would seem to be cheating just a little.

Re: An 8086 PC emulator in 4043 bytes

#28

Earlier quoted context omitted.

Yes, it's very old fashioned (K&R era). I think the reason for doing it this way rather than putting the type declaration alongside the parameter is then it would also demand also adding an int declaration for the BX parameter which would then cause the code to be longer. That is to say with: main(BX,char**nE){ .. it would throw an expected identifier error on the char. So you'd be putting the original: main(BX,nE)n*…

Ah, thanks for the explanation. Looks like the author did a deep, deep dive in the C language specs!

K&R predates the specs, actually. C89 codified the current C parameter convention. Compilers typically continue to support K&R style for very old C code and because it doesn't break modern C support.

Re: An 8086 PC emulator in 4043 bytes

#29
/snip This entry weighs in at a magical 4043 bytes (8086 nibbles, 28,301 bits). It manages to implement most of the hardware in a 1980’s era IBM-PC using a few hundred fewer bits than the total number of transistors used to implement the original 8086 CPU. /snip

Just a small reminder how far we have come - and what Moore's law (RIP) has done for us. Yes the original PC had few enough transistors one could actually count them. NowadAys ...

An awesome piece of work

Re: An 8086 PC emulator in 4043 bytes

#30
If you're on Linux and don't want to bother installing a VGA font, there's no need. Do Ctrl+Alt+F6 (or lower) to switch to a terminal and run it there, then do Ctrl+Alt+F7 to switch back later.

Also, if someone can tell me how to make Windows not make the emulator segfault on my machine, that'd be great.

EDIT: Oh, it works fine in a graphical terminal. I'm guessing SDL failing to init on a text terminal broke everything.

EDIT 2: ALL THIS, PLUS REVERSI! You can even play Reversi!

Post reply on HN