8086tiny: a free PC XT-compatible virtual machine/emulator written in C

Last week we discovered an outstanding open source project which worked out of the box on the Raspberry Pi. 8086tiny is a free PC XT-compatible virtual machine/emulator written in C.

DeluxePaint II in two whole colours. (“Graphics card?! You were lucky…” etc.)

It was created by Adrian Cable who won IOCCC last year with 4043.  We caught up with Adrian last week and this is what he had to say:

The personal computer as we know it today began in the early 80s with the release of the IBM PC – an incredibly complex machine for its time, and the result of hundreds of thousands of man-hours of development time, at a cost of hundreds of millions of dollars.

Thirty years later, I set out to answer the question of how small a highly portable, software PC emulator/virtual machine could be written, complete and accurate enough to simulate not just the Intel 8086 CPU but enough of the peripheral hardware to run software like Windows, AutoCAD, Lotus 1-2-3 and classic PC games. The answer: 4043 bytes of highly condensed C source code, which won the 2013 International Obfuscated C Code Contest.

Following the contest, widespread demand led to the release of 8086tiny, a fully documented and commented distribution of the original code, including full BIOS source code. 8086tiny, when deployed on the $25 Raspberry Pi, produces not only the world’s smallest but also the world’s cheapest PC.

Uniquely we believe for PC emulators, 8086tiny is released under the most free open source license possible, the MIT License, allowing use or redistribution for any purpose, commercial or non-commercial, with no restrictions whatsoever. I encourage anyone to use 8086tiny as a starting point for their own emulation projects.”

8086tiny is now part of the Raspbian repository and can be installed using apt-get and it comes with a pre-made mountable DOS hard disk.  Further instructions on installation and use can be found on the forums. We had a lot of fun with it last week trying to remember the keys for Word Perfect 5.1!

WordPerfect 5.1. The king of the word processors.

A project like this has the potential to allow the Raspberry Pi to replace legacy DOS systems in industrial settings. 8086tiny is under active development and in the future we hope to see the addition of new features such as a VGA card and serial/parallel port emulation. Keep up the good work Adrian!

45 comments

Avatar

Love the WP51 screen, so much time spent looking through the formatting editor view trying to work out why the documents looked wrong. And who could forget it was the master of all function keys combos!

Avatar

OK – PC Emulator for the PI?
Cold six-pack>
Copy of “Leisure Suit Larry In The Land Of The Lounge Lizards”? !!

Avatar

Grrr somethin’ ‘orrible happened to that comment – sorry.

But, I am open to suggestions as to how I could get LLITLOTLL installed and running in the emulator!!

Avatar

There is a DOS hard disk that you can mount to copy files onto. See here; http://www.raspberrypi.org/forum/viewtopic.php?p=496081#p496081

Avatar

Ohhh, I still have SOP somewhere….

Avatar

I can remember there was a DOS-Emulator (can’t remember its name right now) for the Acorn Archimedes on which I used to play “Leisure Suit Larry” probably 22 years ago…

I guess that emulator would still run on the RiscOS for the Pi…

Avatar

Wasn’t it actually an emulator of the 80186?
And no, it won’t run on the Pi – it was 24-bit code.

Avatar

OMG, where are my Wordstar disks?

Avatar

Caution, this news may be bad for your health. The last time I went into the loft to retrieve my floppies the ladder broke, I fell to the floor and cut my head open, spending the rest of the day strapped to a board in A&E whilst the medics decided whether I needed my head scanning. Will Microsoft Arcade run on it ?

Avatar

Deluxe Paint 2? Guess I’ll be installing Deluxe Paint 5 later on my Amiga 1200. :)

Avatar

Awsome, has so much potential especially if it can manage timing accurate emulation of an 8086.

Avatar

Whoo – anypone got a pinout to connect a 5.25″ floppy to gpio ? ;-)

Avatar

Funny how things got around itself! The PI really can end as a classical PC alternative for many people and businesses, esp. if someone releases a IO box for PI for providing the original IO ports of the PC (e.g. AT keyboard, serial and parallel ports, FDD, HDD). I still have around the LaserJet 4MP in perfect condition, and the 8086tiny + the proposed IO box will surely provide my nostalgia dose. :)

Avatar

Here’s how difficult graphics were to implement in hardware back then, and how much development work was required even three-and-a-half decades after the first dinosaur computers such as the ENIAC roamed the Earth: the IBM PC Monochrome Display Adapter (MDA – black-and-white graphics only, of course) had more logic circuitry than did the PC motherboard. The Color Graphics Adapter (CGA) couldn’t start being shipped for months after the PC started shipping because of the volume manufacturing and software complexity for the time (they were caught flat-footed sourcing parts for the PC products, resulting in backlogs rivaling those for the Pi in its first six months).

IBM thought that PCs weren’t really serious computing platforms (and they actually weren’t, in the beginning) and thought that they would just eventually be used as data terminals connected to their mainframes (System 360, 370 … 3090) and office systems (e.g., AS/400). As such, they were developed and manufactured by the IBM Data Entry Systems Division – the folks responsible for keyboards and displays, i.e., data terminals. They were so confident of this that they offered a Token Ring Adapter card, for connection of PCs to their “real” computers, before the CGA was made available and didn’t think about developing a modem card. However, they weren’t aware of the rapidly-growing popularity of modem-accessed on-line services such as the Well, Compuserve, GEnie, etc., used by hobbyists and small businesses via S-100 and Apple ][ customers. They were also so unconvinced that the PC would be a big seller that they contracted out development of PC-DOS to Microsoft, giving the option for Microsoft to develop its own version, MS-DOS, which was unheard of within IBM up to that time, as they always controlled every aspect of their commercial products.

Just be careful Out There – you’ll have to cram everything into 640K (minus space for hardware drivers), even if Bill Gates never said “640KB ought to be enough memory for anyone”, or words not to that effect ;)

Avatar

mmm I wonder if I can fit a PI in the original IBM keyboard?

Avatar

Yes, I believe this has been done already. There are plenty to choose from, like:
The RaspCherry Pi

Avatar

In 1996, Chuck Moore (Forth) developed a computer-on-a-chip that fit into a mouse. It was called Sh-boom and it was designed for a product called iTV, long before the “i” prefix was was even thought of by Apple.

For some reasons that never went ahead, but iTV lives on in another form.

Chuck now makes 144-computers-on-a-chip for US$20 each, but you have to buy 10 at a time, and the is a once only development board that goes with their programming which from memory is something like $245

the green arrays ( 12×12 ) chip could fit into a mouse once programmed

Avatar

It was Jeff Fox who did the computer in the mouse using the F21 chip designed by Chuck Moore, which was very different from Sh-boom which was his previous design.

http://www.ultratechnology.com/scope.htm

Avatar

Now the Pi has finally completed the pass to the dark side ! Its features, software and feelings reminds me my early days when I was trying to figure out what I can do with my first real PC-clone. Nights spent on Borland (or MS) C compiler, new programming languages, x86 assembler for graph stuff, hacking games, dos hidden keys and esoteric tools, ICE, my first dual-head (hercules+cga), norton commander/pc tools and stuff like that. All these things and skills learned in those days (mostly nights…) are a part of my first tech background and were a starting point for the job that still gives me a regular salary after nearly 20-25 years; today there’re different things involved in my activities but that’s where everything started (for me)

Go team pi !
… and a really big thank you to Adrian Cable

Avatar

Wonder where I have a copy of the venerable Borland Turbo.Pascal 3,0, it was so easy to use, one of the first IDE:s. I may even have some code somewhere.

Avatar

And now I know why I still hang onto all that PCjr software (as well as the PCjr itself).

Avatar

Cool. In October 1981, I bought an IBM PC for about $3000. Without any floppy drives or other data storage, and 16KB of RAM.

Avatar

As somebody who grew up on the “Amiga side” rather than the “PC side”, could somebody explain the differences between 8086tiny, DOSemu and QEMU ?

Avatar

I’m going to be more pedantic than you need Andrew, for the benefit of others who may not be as experienced as you are. DOSemu and qemu are built on a thicker stack of emulator code than 8086tiny in that they call Linux libraries that were developed for more general-purpose tasks without much optimization (if any) specifically for emulation of an IBM PC. DOSemu can only be run on x86 and derivative processor family Linux systems, and so can’t be run on an ARM-based processor such as that in the Pi’s system-on-a-chip (SoC). qemu is a generalized emulation engine that can emulate any processor and associated support circuitry/code (memory management, I/O, firmware, etc.) for which profile code has been developed for both the target (8088/8086, in this case) and the host hardware (ARM11v6 in the case of the Pi). 8086tiny was developed specifically to emulate only 8088/8086 processors, support circuitry, I/O devices, firmware, etc., found in the early IBM PC models. As anyone who has tried running old PC code on the Pi via emulation of a 16-bit 4.77 MHz 8088/86 can attest, even a 700 MHz 32-bit RISC processor can be taxed when trying to execute a thick enough emulation stack. 8086tiny is also probably optimized to emulate the timing of system execution (not just CPU execution) of an IBM PC so that all of the peripherals operate identically to what would be experienced on the native hardware (an original IBM PC). It will be interesting to run timing tests on 8086tiny and the other emulators on the Pi to see how they compare in faithful reproduction of system operation.

I forgot to mention in my original post, hats off to Adrian Cable, as this was a lot of hard work!

Avatar

Thanks for the info Jim :)
So I guess DOSemu is kinda like the DOS version of WINE?

Avatar

No. It is a virtual machine. Rather than emulate a whole chip it allows the guest OS to run on the host chip but with some exceptions set.

All the non-contentious stuff can run on the naked host chip at full speed. The relatively few instructions throw an interrupt which gets executed by the VM’s code. This allows it to run at near-ish to native speed.

Some of the peripheral boards do need some DOS drivers to be added to the guest OS.

The guest OS is otherwise unaware that it’s not running on a real 386 PC.

Avatar

So does this thing include a JIT translator to turn the x86 code to ARM? Or does in interpret 8086 code? Or is there something else happening via an intermediate instruction set?

Avatar

Get the serial port running and I can fly this :-)

Well, if DOS was good enough for Robocop it’s good enough for a weather balloon tracker :-)

Avatar

Just make sure you don’t load it with the ED209 version of the software.

Avatar

DOS is much easier to write graphics programs for than, for instance bare Linux. I still have graphics library primitives made after reading zen graphics book by Michael Abrash just in case ;)
Network side in DOS is not so good as in Linux to say the least. Yet you can always try IPX/SPX, as if this is good enough for DOOM and Netware, it may good enough for everything :)

eben

Wow. Abrash Zen books. Those were the days. Zen of Code Optimization was out of print by the time I came to x86 assembly programming, and I had a dog-eared copy that I’d liberated from somewhere. U-pipe, V-pipe, U-pipe, V-pipe, aargh, 3-cycle AGI! Happy days.

Avatar

What I’d like to see now is a shoot out between this PC emulator running Windows 3.1 and the Apple Mac emulator that was demonstrated a while back – let’s re-enact the Microsoft vs Apple battle on the Pi!

Avatar

There might be a new life for my copy of Visual Basic For DOS with this.

Avatar

Have people been able to write to the C: drive after it is mounted? I can’t see how to get permission to do this. (Sorry to post here instead of in the forum but I have had no response in there…) I have some DOS stuff I an impatient to try.

Avatar

Michael,
Sorry you’re having problems with the HD emulation. If you post some more details on your issue (how you have prepared the HD image, what errors you are getting etc.) on the official 8086tiny forums (8086tiny.freeforums.net) then I will be very happy to help.

-Adrian

Avatar

if you use the package in the raspbian repos the builder has included two scripts to mount and unmount the hd image so that you can write to the hd image with normal linux command commands. I personally have idiological problems with it having to be sudo & the mountpoint but that’s just me. if you don’t want to install the repo version then here they are below

mount
———
#!/bin/bash
losetup /dev/loop0 hd.img -o $((63 * 512))
file -s /dev/loop0
mount /dev/loop0 /mnt -o rw
echo /mnt

unmount
————
#!/bin/bash
umount /mnt
losetup -d /dev/loop0

Avatar

Is it coincidence or intended that the final file size (4043) was half of 8086?

Avatar

There are no coincidences in life!

-Adrian

Avatar

Oh I loved WP5.1 I was given a copy of the windows version by WP to beta on the first windows. I loved making macros to print out and create the forms that we used at the council saved us a fortune in sending off for specific forms when I could just design the forms and macros for the office staff to use still have it somewhere on 3.5″ floppies. What about SmartWare ?

Avatar

Maybe 8086tiny could emulate the Amstrad PC1512 (documented at http://www.seasip.info/AmstradXT/1512tech/ ). It had an extended CGA-mode with 16 simultaneous colors. PC1512 was my second computer but I soon replaced the Intel 8086 with a NEC V30 CPU (similar to 80186 but also with 8080-mode) and added 128KB RAM, 30MB HDD, 720KB FDD, and 1200BPS modem.

Avatar

Hi, 8086tiny ran very slowly on my computer:

CPU: intel Core 2 duo E8500
RAM: 2GB ddr2
GPU: Nvidia GTX 470
OS: Ubuntu 10.04 LTS

It took 5 minutes (maybe more) to load FreeDos then it freezed ( i could not type in and excute commands)

Do you know why it was slow? Please help.

Avatar

Linh,
How are you running it? You need to use the runme script to set the terminal up correctly via stty.

If you run 8086tiny without stty then something like this will happen …

-Adrian

Avatar

And I only just got around to throwing out a WP5.1 keyboard overlay a couple of weeks ago…..

Avatar

Hmm. Wonder if a mouse body could be made for the Pi.

Avatar

A few people are wondering the same thing I am. Is it possible to somehow attach an ISA backplane to the Raspberry Pi so that you can add cards to this system. I realize this is an emulator, thus emulated hardware, but what would it take to connect physical hardware and get 8086tiny to recognize it?

Leave a Comment

Comments are closed