Emulators how do they work




















Your code parses this instruction and uses this information to alter processor state as specified by your processor. The core problem with interpretation is that it's very slow; each time you handle a given instruction, you have to decode it and perform the requisite operation.

With dynamic recompilation, you iterate over the code much like interpretation, but instead of just executing opcodes, you build up a list of operations. Once you reach a branch instruction, you compile this list of operations to machine code for your host platform, then you cache this compiled code and execute it. Then when you hit a given instruction group again, you only have to execute the code from the cache. BTW, most people don't actually make a list of instructions but compile them to machine code on the fly -- this makes it more difficult to optimize, but that's out of the scope of this answer, unless enough people are interested.

With static recompilation, you do the same as in dynamic recompilation, but you follow branches. You end up building a chunk of code that represents all of the code in the program, which can then be executed with no further interference. This would be a great mechanism if it weren't for the following problems:. For more information, Michael Steil has done some great research into static recompilation -- the best I've seen.

The other side to processor emulation is the way in which you interact with hardware. This really has two sides:. Certain platforms -- especially older consoles like the NES, SNES, etc -- require your emulator to have strict timing to be completely compatible. Interrupts are the primary mechanism that the CPU communicates with hardware. Generally, your hardware components will tell the CPU what interrupts it cares about. This is pretty straightforward -- when your code throws a given interrupt, you look at the interrupt handler table and call the proper callback.

Take the case of a hard-drive. This part is generally very straightforward. The actual interface of the device is a bit more complex. This is generally some combination of memory mapped registers e. For a hard-drive, you may have a memory mapped area where you place read commands, writes, etc, then read this data back.

I'd go into more detail, but there are a million ways you can go with it. If you have any specific questions here, feel free to ask and I'll add the info. I think I've given a pretty good intro here, but there are a ton of additional areas.

I'm more than happy to help with any questions; I've been very vague in most of this simply due to the immense complexity. It's been well over a year since this answer was submitted and with all the attention it's been getting, I figured it's time to update some things. Perhaps the most exciting thing in emulation right now is libcpu , started by the aforementioned Michael Steil. It's got huge potential, and I think it'll do great things for emulation.

I haven't spent much time there, but it looks like they have a lot of great resources. A guy named Victor Moya del Barrio wrote his thesis on this topic. A lot of good information on pages. You can download the PDF here. If you don't want to register with scribd , you can google for the PDF title, "Study of the techniques for emulation programming".

There are a couple of different sources for the PDF. Any processor typically has a well-written specification that describes states, interactions, etc. If you did not care about performance at all, then you could easily emulate most older processors using very elegant object oriented programs.

For example, an X86 processor would need something to maintain the state of registers easy , something to maintain the state of memory easy , and something that would take each incoming command and apply it to the current state of the machine. If you really wanted accuracy, you would also emulate memory translations, caching, etc. In fact, many microchip and CPU manufacturers test programs against an emulator of the chip and then against the chip itself, which helps them find out if there are issues in the specifications of the chip, or in the actual implementation of the chip in hardware.

For example, it is possible to write a chip specification that would result in deadlocks, and when a deadline occurs in the hardware it's important to see if it could be reproduced in the specification since that indicates a greater problem than something in the chip implementation. Of course, emulators for video games usually care about performance so they don't use naive implementations, and they also include code that interfaces with the host system's OS, for example to use drawing and sound.

In fact, it's even more amazing that you could just download a set of every SNES game ever or any Atari game ever, considering that when these systems were popular having free access to every cartridge would have been a dream come true.

I know that this question is a bit old, but I would like to add something to the discussion. Most of the answers here center around emulators interpreting the machine instructions of the systems they emulate. UltraHLE, one of the most famous emulators ever created, emulated commercial Nintendo 64 games with decent performance on home computers at a time when it was widely considered impossible to do so.

For the first time, I saw articles about emulators in print magazines where before, I had only seen them discussed on the web. The concept of UltraHLE was to make possible the impossible by emulating C library calls instead of machine level calls. Something worth taking a look at is Imran Nazar's attempt at writing a Gameboy emulator in JavaScript.

Practically speaking, you're generally looking to write for speed and fidelity of emulation. This is because software on the target system will may run more slowly than the original hardware on the source system. That may constrain the choice of programming language, compilers, target system etc. Further to that you have to circumscribe what you're prepared to emulate, for example its not necessary to emulate the voltage state of transistors in a microprocessor, but its probably necessary to emulate the state of the register set of the microprocessor.

Generally speaking the smaller the level of detail of emulation, the more fidelity you'll get to the original system. Finally, information for older systems may be incomplete or non-existent. So getting hold of original equipment is essential, or at least prising apart another good emulator that someone else has written!

Yes, you have to interpret the whole binary machine code mess "by hand". Not only that, most of the time you also have to simulate some exotic hardware that doesn't have an equivalent on the target machine. The simple approach is to interpret the instructions one-by-one. That works well, but it's slow. A faster approach is recompilation - translating the source machine code to target machine code. This is more complicated, as most instructions will not map one-to-one.

Instead you will have to make elaborate work-arounds that involve additional code. But in the end it's much faster. Most modern emulators do this. When you develop an emulator you are interpreting the processor assembly that the system is working on Z80, , PS CPU, etc.

You should start writing emulators for the simpe systems like the good old Game Boy that use a Z80 processor, am I not not mistaking OR for C Emulator are very hard to create since there are many hacks as in unusual effects , timing issues, etc that you need to simulate. Also check out Darek Mihocka's Emulators.

I've never done anything so fancy as to emulate a game console but I did take a course once where the assignment was to write an emulator for the machine described in Andrew Tanenbaums Structured Computer Organization.

That was fun an gave me a lot of aha moments. You might want to pick that book up before diving in to writing a real emulator. Look up the regulations surrounding emulated programs in your country before downloading them. The two most common uses for emulators are ones for playing video games, and ones for running other operating systems. Here's a few examples of the most popular emulators around. There are also various game emulators that run on Android phones.

For you. World globe An icon of the world globe, indicating different international options. Get the Insider App. Click here to learn more. A leading-edge research firm focused on digital transformation. Good Subscriber Account active since Shortcuts. Account icon An icon in the shape of a person's head and shoulders.

It often indicates a user profile. Log out. Smart Home. Social Media. More Button Icon Circle with three vertical dots. It indicates a way to see more nav menu items inside the site menu by triggering the side menu to open and close. Dave Johnson and William Antonelli. An emulator is typically a program that lets you run software from a completely different device on your computer.

The most common uses for emulators are to play video games and run different operating systems — for example, you can put a Mac operating system on your Windows computer. There is no need to emulate an entire system to get things working because bit programs are similar in design already. Because of this, the process is extremely fast. The latest consoles are very difficult to emulate. Although the PlayStation 3 hit the markets in , it is still difficult to emulate a large proportion of games for the console.

The emulation situation for the Xbox lags even further behind. Still, emulators exist for heaps of older video game consoles, including many of the best consoles of the 90s. There is a bonus to running the old video game emulators on modern hardware.

The old games receive a performance boost on modern hardware. Depending on the emulator, you can use HD or even 4K graphics, making use of the extra computing power to play games at far higher levels than their native resolution.

You can even run video game emulators on your Android device , letting you retro game on the go. Usually, if you want to try out a new operating system, you'll need to install it on your hard drive. Emulation lets you run a separate operating system right on your current operating system using a virtual machine.

There are several reasons why you'd want to do this. You won't have to worry if your installation misbehaves since it's restrained to a virtual environment. It might also be your only option if you want to try out an operating system that is incompatible with your computer hardware. The Windows Sub-system for Linux is a good example.

You now understand more about why emulation is tricky. Emulating a video game console is a complex processand this article only covers the basics. However, now you understand more about the process of emulation and the development of emulators, you'll know exactly why it's a little slow next time you use one. If you want to start delving into your back catalog of video games, here's how you play PS2 games on your PC. Alternatively, head back a little further in gaming history and learn how to play PS1 games on your PC , instead.

Here are the most amazing apps for Android that will change how you use and interact with your device on a daily basis. He enjoys copious amounts of tea, board games, and football. Emulation Hardware Makes a Difference Let's think about what affects emulation performance using a real-world example. Share Share Tweet Email. Gavin Phillips Articles Published. Subscribe to our newsletter Join our newsletter for tech tips, reviews, free ebooks, and exclusive deals! Click here to subscribe.



0コメント

  • 1000 / 1000