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

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

问题描述

我要编写一个的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.

我发现的第二件事是人人都使用每运code一个功能。这似乎是合乎逻辑的,因为它只是一个函数调用,可能比具有添加指令一个功能优化,那么你一定要找出什么寄存器被用在这里。但今天是怎么必要的?有什么事情我应该坚持还是应该相当重写我的模拟器,如果我发现另一种方式这可能是更方便的只是不削减它(或多或少现代化的游戏机跳进我的脑海现在)?

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)?

此外,它是一种士气低落写该寄存器该寄存器加上一遍又一遍的功能。有没有办法从运code地图或类似的东西自动执行?

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语句,你应该喜欢使用函数指针数组,快得多 - >更好的仿真,以及更好的code,嵌套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周期与次数最少从人们对curret架构的CPU周期,面向对象是不是从我听到在这种情况下那么好/读取。的事情之一就是性能,二是pretty多明显,仿真,正如你可能已经注意到了,真是复杂的任务,在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天全站免登陆