硬件仿真的正确实现是什么? [英] What's the proper implementation for hardware emulation?

查看:30
本文介绍了硬件仿真的正确实现是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将编写一个 Game Boy 模拟器(Z80 是 CPU,以防有人不熟悉它),在我进行研究时,我发现了一些东西我不太确定.

I'm going to programme a Game Boy emulator (Z80 is the CPU in case somebody is not familiar with it), and while I was doing my research, I've found some things I'm not so sure about.

第一个是 C 是这里选择的编程语言.这不是什么大问题,但我想从今天的角度听听你的意见.甚至不推荐使用 C++.

The first one was that C is the programming language to choose here. That's not so much of a problem, but I'd like to hear your opinion from today's point of view. Even C++ was not recommended.

我发现的第二件事是每个人每个操作码都使用一个函数.这似乎是合乎逻辑的,因为它只是一个函数调用,并且可能比为ADD"指令使用一个函数更好地优化,然后您必须找出此处使用的寄存器.但今天这有多大必要?如果我注意到另一种可能更方便的方法并没有削减它,我应该坚持使用它还是应该重写我的模拟器(现在或多或少现代游戏机出现在我的脑海中)?

The second thing I found out was that everybody was using one function per opcode. That seems logical since it's just one function call and probably better optimised than having one function for the "ADD" instruction and then you've got to find out what registers are used here. But how necessary is that today? Is it something I should stick to or should I rather rewrite my emulator if I notice that another way which might be more convenient just doesn't cut it (more or less modern gaming consoles pop into my mind right now)?

此外,一遍又一遍地编写将该寄存器添加到该寄存器"的函数有点令人沮丧.有没有办法从操作码映射或类似的东西中自动化?

Also, it's kind of demotivating to write a function for "add that register to this register" over and over again. Is there a way to automate that from an opcode map or something like that?

推荐答案

第一个建议,你不应该使用嵌套的 switch 语句,你应该使用函数指针数组,速度更快 -> 更好的仿真和更好的代码,嵌套switch-es 也可能有点乱,这里有一些链接,您可以在其中阅读有关这些数组的更多信息
http://www.newty.de/fpt/fpt.html
http://www.multigesture.net/wp-content/uploads/mirror/zenogais/FunctionPointers.htm

First suggestion, you shouldn't use nested switch statements, you should rather use array of function pointers, alot faster -> better emulation, and nicer code, nested switch-es can also get a bit messy, here are some links where you can read more about these arrays
http://www.newty.de/fpt/fpt.html
http://www.multigesture.net/wp-content/uploads/mirror/zenogais/FunctionPointers.htm

第二个建议,是的,您可以在 C#、Java、C++ 中进行,但是由于您希望 CPU 周期的每一位都尽可能地进行模拟 - 以最少的数量模拟目标架构的一个 CPU 周期当前架构上的 CPU 周期,从我从人们那里听到/读到的,在这种情况下,OOP 并不是那么好.一件事是性能,第二件事非常明显,正如您可能注意到的那样,仿真是非常复杂的任务,将其包装在 OOP 中可能会带来不必要的痛苦.

Second suggestion, Yes you can do it in C#, Java, C++, but since you want every single bit of your CPU cycles so you can get as close emulation as possible - emulating one CPU cycle of target architecture with least number of CPU cycles on curret architecture, and OOP isn't so good in this case from what I heard/read from people. One of the things is performance, and second is pretty much obvious, emulation is, as you probably noticed, really complex task and wraping it in OOP can be unnecessary pain in the neck.

这篇关于硬件仿真的正确实现是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆