模拟器是如何工作的?当我看到NES/SNES或C64模拟器时,我很震惊。

您是否必须通过解释特定的组装指令来模拟这些机器的处理器?还有什么?它们通常是如何设计的?

你能给那些对编写模拟器(特别是游戏系统)感兴趣的人一些建议吗?


当前回答

值得一看的是Imran Nazar尝试用JavaScript编写Gameboy模拟器。

其他回答

是的,你必须“手工”解释整个二进制机器码的混乱。不仅如此,大多数情况下,您还必须模拟一些在目标机器上没有等效硬件的外来硬件。

简单的方法是一个接一个地解释指令。这工作得很好,但是很慢。一种更快的方法是重新编译——将源机器码转换为目标机器码。这比较复杂,因为大多数指令都不是一对一映射的。相反,您将不得不制定涉及额外代码的详细变通方案。但最终还是要快得多。大多数现代模拟器都是这样做的。

一个叫维克多·莫亚·德尔·巴里奥的人写了一篇关于这个主题的论文。152页里有很多有用的信息。你可以在这里下载PDF文件。

如果您不想注册scribd,您可以谷歌获取PDF标题,“模拟编程技术的研究”。PDF文档有几个不同的来源。

我将如何开始模仿。

1.买一些关于低级编程的书籍,你将需要它来“模拟”任天堂的操作系统……游戏的男孩……

2.专门找一些模拟方面的书,也许还有操作系统开发方面的。(你不会做一个操作系统,但最接近它。

3.看看一些开源仿真器,特别是那些您想为其创建仿真器的系统。

4.将更复杂的代码片段复制到IDE/编译器中。这将节省编写长代码的时间。这就是我为操作系统开发所做的,使用linux的一个区域

值得一看的是Imran Nazar尝试用JavaScript编写Gameboy模拟器。

在创建了我自己的80年代BBC微型计算机模拟器(类型VBeeb到谷歌)后,有许多事情要知道。

You're not emulating the real thing as such, that would be a replica. Instead, you're emulating State. A good example is a calculator, the real thing has buttons, screen, case etc. But to emulate a calculator you only need to emulate whether buttons are up or down, which segments of LCD are on, etc. Basically, a set of numbers representing all the possible combinations of things that can change in a calculator. You only need the interface of the emulator to appear and behave like the real thing. The more convincing this is the closer the emulation is. What goes on behind the scenes can be anything you like. But, for ease of writing an emulator, there is a mental mapping that happens between the real system, i.e. chips, displays, keyboards, circuit boards, and the abstract computer code. To emulate a computer system, it's easiest to break it up into smaller chunks and emulate those chunks individually. Then string the whole lot together for the finished product. Much like a set of black boxes with inputs and outputs, which lends itself beautifully to object oriented programming. You can further subdivide these chunks to make life easier.

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!