Fake86: an 8086 PC emulator project

  • (2 Pages)
  • +
  • 1
  • 2

25 Replies - 10909 Views - Last Post: 30 December 2011 - 07:10 PM

#1 Mike Chambers  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 59
  • Joined: 30-March 09

Fake86: an 8086 PC emulator project

Posted 11 May 2011 - 02:27 PM

*
POPULAR

Hi, D.I.C. heads... This is a project I started about 5 or 6 months ago, and while it's very far from being completed, it's in a pretty usable state. There are lots of rough edges, but I wanted to get some opinions on it.

It's written in FreeBASIC, but I'm about 90% done with porting it to C and getting that to the same point as this. Switching to C because I want it to be as fast as possible, but the FB version is plenty fast on a modern computer. When the C version is done, I will release the source but this version's code is too ugly looking for me to give out. :P

Every line of code in this I wrote myself, not based off of any other software.

Main features so far:
-Complete 8086 CPU emulation core, which also supports almost all 80186 instructions. I've been working very hard on this part, and at this point I'm pretty convinced there are no bugs left in the core.
-Hard drive and floppy image file support. (It comes with a 50 MB hard drive image including DOS and few programs to try out)
-Hercules, CGA, and VGA emulation. (EGA support isn't working yet)
-Full Disney Sound Source emulation.
-PC speaker emulation. (But it sounds terrible, I'm working on it)

Still to do:
-EGA support.
-Sound Blaster and Adlib support.
-On-the-fly floppy disk image switching.
-Finish 320x200 VGA emulation (it's nearly done.. 95%+ of MCGA/VGA programs will work fine on it now)
-Implement 640x480 16-color VGA emulation.
-Mouse emulation
-Some sort of UI. Right now, everything is controlled from a .ini file.
-And a TON more!

A few screenshots showing what it can do...

Posted Image

Posted Image

Posted Image
^ Ultima 6... if you want to play this game in it, use GAME.EXE not ULTIMA6.EXE... ULTIMA6.EXE shows the title sequence animations, and much of that tries to use VGA register tricks my emulator doesn't support yet.

Posted Image

Posted Image

Posted Image

Posted Image



If you're interested in trying it, out here's the download link:
http://rubbermallet....6-0.11.5.11.rar

It's pre-configured, so just extract it somewhere and run fake86.exe

I would love feedback! Thanks. :)

This post has been edited by Mike Chambers: 11 May 2011 - 02:31 PM


Is This A Good Question/Topic? 9
  • +

Replies To: Fake86: an 8086 PC emulator project

#2 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Fake86: an 8086 PC emulator project

Posted 11 May 2011 - 02:53 PM

How long did it take you to built this? Amazing! I can't wait to try it out.
Was This Post Helpful? 0
  • +
  • -

#3 Mike Chambers  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 59
  • Joined: 30-March 09

Re: Fake86: an 8086 PC emulator project

Posted 11 May 2011 - 03:01 PM

View PostAmrykid, on 11 May 2011 - 03:53 PM, said:

How long did it take you to built this? Amazing! I can't wait to try it out.


Thanks! Yeah I'm pretty happy with how it's turning out. I started working on it in November or December 2010. I wrote a NES emulator first to get my feet wet in the subject, then I moved on to making this. My biggest reason for writing it was to learn x86 assembly, and I figured what better way than write an 8086 CPU emu core?

I've always wanted to write one of these anyway, programs like QEMU have always amazed me. This is probably the toughest program I've ever written. I've spent many nights with like hundreds of pages of x86 tech docs printed out to reference, lol. It was pretty brutal at times. Lots of hair got pulled out.


EDIT: I should mention, if anybody wants to manually add files to the hard drive image you will need to use UltraISO. For some unknown reason, every other image editor I've tried using corrupts the partition in it. My guess is they're trying to use the wrong disk geometry... Floppy disk images can be edited in any editor though. I usually use WinImage for them.

This post has been edited by Mike Chambers: 11 May 2011 - 03:08 PM

Was This Post Helpful? 0
  • +
  • -

#4 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Fake86: an 8086 PC emulator project

Posted 11 May 2011 - 03:14 PM

View PostMike Chambers, on 11 May 2011 - 05:01 PM, said:

View PostAmrykid, on 11 May 2011 - 03:53 PM, said:

How long did it take you to built this? Amazing! I can't wait to try it out.


Thanks! Yeah I'm pretty happy with how it's turning out. I started working on it in November or December 2010. I wrote a NES emulator first to get my feet wet in the subject, then I moved on to making this. My biggest reason for writing it was to learn x86 assembly, and I figured what better way than write an 8086 CPU emu core?

I've always wanted to write one of these anyway, programs like QEMU have always amazed me. This is probably the toughest program I've ever written. I've spent many nights with like hundreds of pages of x86 tech docs printed out to reference, lol. It was pretty brutal at times. Lots of hair got pulled out.


EDIT: I should mention, if anybody wants to manually add files to the hard drive image you will need to use UltraISO. For some unknown reason, every other image editor I've tried using corrupts the partition in it. My guess is they're trying to use the wrong disk geometry... Floppy disk images can be edited in any editor though. I usually use WinImage for them.


I see a dos folder, does that mean you have some sort of dos installed on the image? How do I play one of the games above?

EDIT: Never mind, got pacman to work although its very slow. :(

When will we get a chance to view the source code?

This post has been edited by Amrykid: 11 May 2011 - 03:20 PM

Was This Post Helpful? 0
  • +
  • -

#5 Mike Chambers  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 59
  • Joined: 30-March 09

Re: Fake86: an 8086 PC emulator project

Posted 11 May 2011 - 03:21 PM

Are you familiar with using a DOS computer at all? I included a few free programs in the disk image, and it has DR-DOS installed (which is freeware now), Turbo C++ 1.01 (also freeware now), and a few other things.

If you want to add any old games, you could copy them into the image file with UltraISO then run Fake86, and play. Be warned, being coded in FreeBASIC, it emulates most games pretty slowly unless you're using a fast computer. Any decent Core 2 Duo or equivalent/better should be fine for most stuff.

Also keep in mind a lot of DOS games require 386 or newer CPUs and they won't run since I am only emulating an 8086/80186.

Edit: Pacman is slow? What kind of processor are you using? On my C2D here at work and my Phenom II X4 at home even Wolf 3D plays very smoothly. Hmm. And as far as source code, I will actually try to get it uploaded tonight but I need a few hours to clean it up. It's a bit ugly and hard to read at the moment.

This post has been edited by Mike Chambers: 11 May 2011 - 03:23 PM

Was This Post Helpful? 0
  • +
  • -

#6 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Fake86: an 8086 PC emulator project

Posted 11 May 2011 - 03:28 PM

View PostMike Chambers, on 11 May 2011 - 05:21 PM, said:

Are you familiar with using a DOS computer at all? I included a few free programs in the disk image, and it has DR-DOS installed (which is freeware now), Turbo C++ 1.01 (also freeware now), and a few other things.

If you want to add any old games, you could copy them into the image file with UltraISO then run Fake86, and play. Be warned, being coded in FreeBASIC, it emulates most games pretty slowly unless you're using a fast computer. Any decent Core 2 Duo or equivalent/better should be fine for most stuff.

Also keep in mind a lot of DOS games require 386 or newer CPUs and they won't run since I am only emulating an 8086/80186.

Edit: Pacman is slow? What kind of processor are you using? On my C2D here at work and my Phenom II X4 at home even Wolf 3D plays very smoothly. Hmm. And as far as source code, I will actually try to get it uploaded tonight but I need a few hours to clean it up. It's a bit ugly and hard to read at the moment.


DOS? I am and I'm not. I wasn't even born until Windows 95 was released. Only experience I have is through the commandline.

Well, this is older pc, so that maybe be the issue.

Another thing I spotted was the first time I ran it, it was running smoothly and then the second time, it was printing out the chars just about one at a time. Porting this to C like you said would speed this up a little bit.

I am going to continue playing around with this cause it's fun.
Was This Post Helpful? 0
  • +
  • -

#7 Mike Chambers  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 59
  • Joined: 30-March 09

Re: Fake86: an 8086 PC emulator project

Posted 11 May 2011 - 03:33 PM

Maybe I should post the source to what I have done of the C version instead of this one, even though it's not as far along. Compared to the FB version I uploaded, the C version is lacking a few things like VGA support is not as complete, no sound source emulation yet, and I think there are still a couple bugs in the C version's 8086 core that I need to iron out still. However, it does boot DOS and many programs will run in it.

And yeah, it's probably slow because of your computer. Even high-end Pentium 4 machines don't run this very well.
Was This Post Helpful? 0
  • +
  • -

#8 Mike Chambers  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 59
  • Joined: 30-March 09

Re: Fake86: an 8086 PC emulator project

Posted 11 May 2011 - 04:12 PM

Here you go, this is my code for the C version:

http://rubbermallet....11.5.11-src.rar

I really need to add some comments throughout it, so people can understand what each part is doing if they can't figure it out. I tried to write the code as easy to follow as I could! Everybody, if you have questions about stuff in it don't hesitate to ask about it.

There is still a TON of work to do in it, it even has the drive image filename hardcoded in at the moment, for my testing purposes.

This post has been edited by Mike Chambers: 11 May 2011 - 04:13 PM

Was This Post Helpful? 1
  • +
  • -

#9 chuckb  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 211
  • Joined: 29-May 09

Re: Fake86: an 8086 PC emulator project

Posted 14 May 2011 - 12:02 PM

Mike,
Absolutely brilliant!

I ran this DOS sequence
COPY CON TEST.BAT
DIR
^Z


It worked like a champ.

PC-13 Profound Carnage :gun_bandana:

I ran Windows 3.0.
I ran Windows 3.0.
I ran Windows 3.0.
I never did that before. I went from DOS 5/6.2 to Win3.1.

Did Windows 3.0 have mouse support? It didn't work for me in this case.

I couldn't run Wolf3D in Win3.0...windows crashed. :surrender: It worked fine outside of windows.

Yes it was very slow. It'll be interesting to see if you can speed it up with a compiled C program in lieu of an interpreted language (I assume FreeBasic is interpreted).

Awesome job!! I'm familiar with these x86 docs you would have spent a lot of time with.

I'm curious, why did you choose this project?

Regards,
Chuck
Was This Post Helpful? 1
  • +
  • -

#10 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 614
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: Fake86: an 8086 PC emulator project

Posted 14 May 2011 - 02:44 PM

Excellent, this would be very useful to OS devers. Attempting to load my kernel I get an error from GRUB, the bootloader I'm using.

Quote

Geom Error


Obviously I don't expect you to debug my implementation, but it does boot on real hardware and with other emulators like BOCHS. Here is the ini file that I edit, my kernel is "kernel.img".

loadbin,&hFE000,xtbios.bin
loadbin,&hC0000,et4000.bin
#disk,0,floppy0.img
#disk,1,floppy1.img
disk,&h80,kernel.img
#disk,&h81,drive2.raw
bootdisk,&h80
#mouseemu
#mda
#verbose
#textbase,&hB0000
#clockmult,20
samplerate,44100
soundbuffer,4096
#nosound


Any ideas as to how I could get this booting, your VGA emulation would be very useful.
Was This Post Helpful? 0
  • +
  • -

#11 Mike Chambers  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 59
  • Joined: 30-March 09

Re: Fake86: an 8086 PC emulator project

Posted 14 May 2011 - 07:37 PM

View Postchuckb, on 14 May 2011 - 01:02 PM, said:

Mike,
Absolutely brilliant!

I ran this DOS sequence
COPY CON TEST.BAT
DIR
^Z


It worked like a champ.

PC-13 Profound Carnage :gun_bandana:

I ran Windows 3.0.
I ran Windows 3.0.
I ran Windows 3.0.
I never did that before. I went from DOS 5/6.2 to Win3.1.

Did Windows 3.0 have mouse support? It didn't work for me in this case.

I couldn't run Wolf3D in Win3.0...windows crashed. :surrender: It worked fine outside of windows.

Yes it was very slow. It'll be interesting to see if you can speed it up with a compiled C program in lieu of an interpreted language (I assume FreeBasic is interpreted).

Awesome job!! I'm familiar with these x86 docs you would have spent a lot of time with.

I'm curious, why did you choose this project?

Regards,
Chuck


Thanks, Chuck! Yeah, my mouse emulation is really really flakey. The way I'm doing it is intercepting interrupt 33h (iirc) which is what standard mouse drivers for DOS. It works in some programs, and not very well. Windows tries to directly access the serial port to talk to the mouse, so I'm going to have to re-implement it that way.

Also, FreeBASIC is actually a compiler. It's a pretty powerful extension of the old QB and VB6 syntax. It supports pointers, unions, inline assembly, and all that fun stuff but speed wise it still can't hold a candle to a high quality C compiler. I probably should have just started it with C.

A lot of times I'll use BASIC just to play around with ideas because it's nice and quick to put stuff together, and with this project I was into it pretty deep before I knew it so I just kept going in FB. :)

As for why I did it, I don't know I thought it would be a good learning experience, and I've always been amazed with emulators like QEMU and Bochs.. wanted to see if I could pull off writing a similar app. Obviously, QEMU/Bochs are far more advanced. I don't even support 386 stuff, but maybe down the road I'll get to that.
Was This Post Helpful? 0
  • +
  • -

#12 Mike Chambers  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 59
  • Joined: 30-March 09

Re: Fake86: an 8086 PC emulator project

Posted 14 May 2011 - 07:42 PM

View PostAphex19, on 14 May 2011 - 03:44 PM, said:

Excellent, this would be very useful to OS devers. Attempting to load my kernel I get an error from GRUB, the bootloader I'm using.

Quote

Geom Error


Obviously I don't expect you to debug my implementation, but it does boot on real hardware and with other emulators like BOCHS. Here is the ini file that I edit, my kernel is "kernel.img".

loadbin,&hFE000,xtbios.bin
loadbin,&hC0000,et4000.bin
#disk,0,floppy0.img
#disk,1,floppy1.img
disk,&h80,kernel.img
#disk,&h81,drive2.raw
bootdisk,&h80
#mouseemu
#mda
#verbose
#textbase,&hB0000
#clockmult,20
samplerate,44100
soundbuffer,4096
#nosound


Any ideas as to how I could get this booting, your VGA emulation would be very useful.


Hrm... can you post your kernel image to a site where I can download it? I'll definitely have a peek and see if I can get it to do something. What is the geometry of your disk image? Fake86 is coded to automatically assume 16 heads and 63 sectors/track, then calculate cylinder count from that and the file size.

Also, keep in mind that if your kernel uses any 286 or newer opcodes my emulator won't understand those. It can only handle up to the 80186.

How long have you been working on an OS, btw? How far along is it? Last year, I started work on a 16-bit multitasking kernel with multiple virtual terminals (like *nix) and while the kernel was working very well as far as the terminals and task-switcher (CPU context-switching code I hooked to int 8h timer) ... but I kind of stopped working on it in the middle of writing the FAT16 driver. I was having issues I couldn't figure out. :(
Was This Post Helpful? 0
  • +
  • -

#13 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 614
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: Fake86: an 8086 PC emulator project

Posted 15 May 2011 - 06:29 AM

View PostMike Chambers, on 14 May 2011 - 08:42 PM, said:

View PostAphex19, on 14 May 2011 - 03:44 PM, said:

Excellent, this would be very useful to OS devers. Attempting to load my kernel I get an error from GRUB, the bootloader I'm using.

Quote

Geom Error


Obviously I don't expect you to debug my implementation, but it does boot on real hardware and with other emulators like BOCHS. Here is the ini file that I edit, my kernel is "kernel.img".

loadbin,&hFE000,xtbios.bin
loadbin,&hC0000,et4000.bin
#disk,0,floppy0.img
#disk,1,floppy1.img
disk,&h80,kernel.img
#disk,&h81,drive2.raw
bootdisk,&h80
#mouseemu
#mda
#verbose
#textbase,&hB0000
#clockmult,20
samplerate,44100
soundbuffer,4096
#nosound


Any ideas as to how I could get this booting, your VGA emulation would be very useful.


Hrm... can you post your kernel image to a site where I can download it? I'll definitely have a peek and see if I can get it to do something. What is the geometry of your disk image? Fake86 is coded to automatically assume 16 heads and 63 sectors/track, then calculate cylinder count from that and the file size.

Also, keep in mind that if your kernel uses any 286 or newer opcodes my emulator won't understand those. It can only handle up to the 80186.

How long have you been working on an OS, btw? How far along is it? Last year, I started work on a 16-bit multitasking kernel with multiple virtual terminals (like *nix) and while the kernel was working very well as far as the terminals and task-switcher (CPU context-switching code I hooked to int 8h timer) ... but I kind of stopped working on it in the middle of writing the FAT16 driver. I was having issues I couldn't figure out. :(


Yeah sure, here it is. To boot the kernel, when the GRUB prompt loads you type.

kernel 200+50


If it loads correctly, then you should be able to boot it using.
boot


I have been developing it for quite a while but it's not the only project I've been working on, far from it, so it's not very... mature should I say. It's a simple protected mode kernel written in C but it doesn't use any file system right now and at face value doesn't really do much of interest other than tell the user the memory in their system, the time/date, and CPU installed, amongst other things. At the moment I've only written a driver for the 80x24 character VGA text mode as well so it has a long way to go visually.

Oh, and here's some more information about the geom error.

Quote

"Geom Error"

This error message will occur if the location of the Stage 2 or Stage 1.5 is not in the area supported by reading the disk with the BIOS directly. This could occur because the BIOS translated geometry has been changed by the user or the disk is moved to another machine or controller after installation, or GRUB was not installed using itself (if it was, the Stage 2 version of this error would have been seen during that process and it would not have completed the install).

This post has been edited by Aphex19: 15 May 2011 - 06:31 AM

Was This Post Helpful? 0
  • +
  • -

#14 Mike Chambers  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 59
  • Joined: 30-March 09

Re: Fake86: an 8086 PC emulator project

Posted 15 May 2011 - 01:44 PM

ah, yeah it looks like your kernel is 32-bit code. that's not going to work on an 8086 class CPU.
Was This Post Helpful? 0
  • +
  • -

#15 Mike Chambers  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 59
  • Joined: 30-March 09

Re: Fake86: an 8086 PC emulator project

Posted 15 May 2011 - 09:16 PM

looks like it's too late to edit my last post but i just noticed a mistake in the way you changed the .ini file. since its a floppy disk image you'll want to do it on the disk,0 or disk,1 lines. it still won't work though because of the 32-bit code.

i probably should have commented the ini file a bit, i know it's confusing.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2