What problems arise when emulating something like x86 architecture, compared to something like the 6502?

StackOverflow https://stackoverflow.com/questions/17911658

Currently, I'm making an NES emulator in Java. My 6502 core works for 99% except for some small issues. The thing is, I'm emulating the 6502 for the NES, but I've never been as interested in it as I've been in something like the PS1, N64 or DOS. I've always wanted to emulate a console/system that is capable of doing more than than drawing some simple 2D sprites on the screen, like the aforementioned systems.

What I want to ask is: what makes something like an x86 processor hard to emulate compared to the 6502? The only thing I can come up with, is the huge x86 instruction set, and that an x86 emulator has to be a bit more programmed towards efficiency, rather than readability of the code. I'm asking this because I've looked at the DosBox source code, and compared to pretty much any 6502 open-source emulator out there, the source of the x86 core for DosBox is not even remotely understandable to me. How come there's such a large difference in complexity when all a processor does is look up a list of opcodes and execute them systematically?

有帮助吗?

解决方案

6502 and the 8088/86 are going to be somewhat similar, both are CISC, etc. x86 has more instructions but like the 6502 just variations on a theme.

If you are talking about more than just a DOS emulator something like an 80386 or newer then yes that is a much bigger effort. Not only the processor, but also the system. A 6502 based game system doesnt have too much around it, often specific to the platform, asteroids, nes, c64, etc. Dos you are going to need to come up with a bios and then a dos, which I believe at this point are out there for free. but also the peripherals that many 8086 systems have/had, video, hard disk, etc.

Many dos apps would talk to hardware directly so you have to do more than just emulate the bios calls.

Add all of this up and the level of effort for a dos/x86 system is much more than a 6502.

You dont have to create an emulator that is design for efficiency, not anymore (for dos for example). The sources you are looking at (MAME is a good source for a bunch of processor simulators) were designed for speed most likely and many are barely readable.

x86 is a painful instruction set from any direction you look at it. If 6502 is all you have done so far I would choose something else next, unless it is obvious how to do it (which it sounds like it isnt). maybe a fixed length instruction set like arm or mips (well the fixed length versions). Or to get a sense of the scale, do a z80 and run space invaders or galaga or something on it. (hmm is space invaders an 8080?) (a z80 derivative is in the gameboy).

其他提示

As you mentioned x86 has a rather extensive instruction set. There is simply a world of difference between a tiny 8-bit microprocessor with 5 registers and 50 some odd instructions like the 6502 and an crufty, aged, CISC, 32-bit, multi-user OS supporting CPU like an x86.

x86 processors are more complicated because they:

  • are CISC meaning many instructions do complicated things that may take many cycles.

  • tend to support an FPU

  • have multi-level caching

  • have a prefetch input queue

  • have a lot of backwards compatibility support

  • support for paging

  • multiple privilege levels

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top