Programming PC Emulator Getting Started Questions

Emulation of old PCs, PC hardware, or PC peripherals.

Programming PC Emulator Getting Started Questions

Postby davecom » 2019-7-24 @ 08:17

Hi All,

I am new to writing an IBM PC emulator. I have previously written a basic NES emulator successfully. I am starting by learning about how to decode 8086 instructions, what the registers are useful for, and the memory layout. So far I think I am understanding most of what I'm reading and I have been able to start laying out my code.

My eventual goal is to successfully emulate an original IBM PC 5150 that can run DOS.

So, let me ask a few questions to the veterans:

1. This is the first forum I have come across where PC emulator authors post. nesdev.com was a great resource for me when writing my NES emulator. Is there a similar community for PC emulator writers? Is this the best forum? What are the alternatives?

2. Is the best BIOS to test against the original 5150 BIOS? Is there a public domain BIOS? Are there raw 8086 test programs out there?

3. Do any tutorials exist for doing this exist?

4. What advice do you have?

Thanks in advance,
Dave
davecom
Newbie
 
Posts: 2
Joined: 2019-7-24 @ 08:10

Re: Programming PC Emulator Getting Started Questions

Postby Stenzek » 2019-7-25 @ 08:21

There's a few of us doing PC emulators in various communities, I lurk here and on the emudev discord.

A few public domain BIOSes exist for the PC/XT, you can find some of them here: http://minuszerodegrees.net/xt_clone_bi ... e_bios.htm. I've personally used this one: https://www.phatcode.net/downloads.php?id=101

Some test ROMs for the 80186 CPU can be found here: https://forum.osdev.org/viewtopic.php?p=192683#p192683 While not specifically for the 8086/8088, they cover a good chunk of the opcode space, and can be good for pinpointing errors with specific instructions. And the 186 only added a couple of additional instructions anyway. But they're not super comprensive, you'll likely need to dig through traces to figure out some bugs :) Once you get to the 286 and beyond, there aren't much in the way of automatic testing programs, I started writing some of my own at one point then got distracted by other things..

There's quite a bit of hardware you need to emulate to get an XT to boot (the CPU, PIT, PIC, floppy controller and keyboard controller, and CGA/MDA to name a few), so one option could be to high-level emulate some of these from the BIOS calls, and then move each of them to hardware emulation. The floppy controller in my opinion is probably the trickiest, followed by the display, and these can be HLE'ed initially.
Stenzek
Newbie
 
Posts: 57
Joined: 2017-12-08 @ 08:30

Re: Programming PC Emulator Getting Started Questions

Postby davecom » 2019-7-26 @ 10:52

Thanks for the reply! I’ll definitely follow your advice on the HLE. I’m executing my first couple 8086 instructions from the BIOS and I’ve now found good documentation that I like for the 8086. A couple more questions:

1. For the peripheral components like the floppy controller, CGA and timer—what is the best source of documentation?

2. I read somewhere else that cycle accuracy is not super important for most software since it generally uses the timer chip. I guess i shouldn’t worry about it. But in the Intel assembly documentation there is a range for some instructions. If no exact formula is given, how can you know where in that range it will end up?

I doubt I’ll ever get to doing the 286. If I can get to running DOS 1.0 on the IBM PC 5150 BIOS (what I’m using at present), I’ll be pretty happy.
davecom
Newbie
 
Posts: 2
Joined: 2019-7-24 @ 08:10

Re: Programming PC Emulator Getting Started Questions

Postby Stenzek » 2019-7-26 @ 11:24

The datasheets have all the commands/parameters/etc listed, and are a pretty good resource. Can also consult many of the emulators out there, although not all of them are "correct".

Cycle accuracy definitely isn't a requirement except if you want to run some very picky demos. If I recall correctly, the 5150 BIOS also requires some degree of accuracy (it might've been in the DMA test). None of the clone BIOSes I've seen have this requirement.

The cycle range is dependent on a few factors, for example the 8086/8088 is partially "pipelined" (it has a prefetch queue), so that among other things such as DMA can affect the upper bound of cycles. Other instructions such as multiply/division/shifts take a variable number of cycles due to the algorithm they use. There's some people/threads on this forum who have done considerable research into how the CPUs behave if you want to go to that level of accuracy.
Stenzek
Newbie
 
Posts: 57
Joined: 2017-12-08 @ 08:30


Return to PC Emulation

Who is online

Users browsing this forum: Silanda and 4 guests