Post by Mike Chambers » Sat Mar 29, 2014 8:39 pm

This was an absolutely terrible (in a good way) idea. I wrote an 8086 CPU emulator entirely in QuickBASIC, then added enough PC hardware support to allow it to boot DOS and run programs. It's called QB8086. I just wanted to see how well it could work.If you're not familiar with how emulation works, here's a quick overview. QB8086 runs compiled bytecode (i.e. machine language) designed to run on an 8086 CPU. It emulates the address (memory) space of an 8086 by using arrays of bytes, loads a real PC BIOS ROM binary into it, and steps through each instruction in RAM. It decodes each instruction the same way the real CPU does, but performs each operation using equivalent QuickBASIC code. It has variables to simulate the 8086's internal registers (AX, BX, ES, etc), and manipulates them as each CPU instruction is supposed to on the real processor.In this way it can run DOS, PC games, etc. that a real 8086 PC can.It is EXTREMELY slow, but it really works. There is one very short piece of ASM I wrote that I embedded in a string too. All that does is act as a new keyboard interrupt handler that toggles a flag in a QB variable that lets the emulator know a key was pressed, so it can then read the scancode from the KB port and pass it on to the emulation engine. But yes, a functional 8086 PC emulator... all in good ol' QuickBASIC.It can emulate CGA text modes, CGA graphics modes, and 320x200 8-bit MCGA graphics mode. It also forwards emulated output to the Adlib ports through to the host system's ports, so if a game being emulated uses Adlib you will actually hear the sound in DOSBox. (or a real host PC if it has an SB/Adlib)There do seem to be a few CPU bugs, but for the most part it works fairly well. It can even emulate Windows 3.0! See screenshots below.You can run QB8086 in DOSBox, but you really need to configure DOSBox with "cpu=dynamic" and "cycles=max" for any sort of useable speed... and even then it's still slow. If you can set up a VM in VirtualBox to run it instead, if you have a good host CPU (like a core i7) then it actually does reach the about speed of the original PC. A Pentium 4 will do it around half the speed in a VBox VM. I even ran it on an old 286 computer, where it worked... but it took a good 10 minutes just to finish emulating the BIOS POST. http://rubbermallet.org/qb8086/qb8086-0.14.3.28.zip " target="_blankI know some of that code isn't pretty, and some of the indentation is screwed up... sorry. I only tested this with QuickBASIC 7.1 PDS. QB45 will probably work. QBASIC and QB64 won't work.You can edit the qb8086.ini file to change configuration options. It can emulate between 368 KB and 640 KB of RAM, but any memory beyond 368 KB is simulated using disk swap... which is slow as hell, avoid it if you can. When you're running the emulator, you can press F11 to toggle on-screen update of the emulated 8086's current CS:IP registers and how many instructions have been emulated total. Press F12 to exit QB8086.And now for some neato screenshots...DOSBox is not directly emulating those games/programs... DOSBox is running QB8086 which in turn is emulating what you see. QB8086 is a rough port of a PC emu I wrote in C called Fake86