我正在用C编写我的第一个NES仿真器。目标是让它易于理解并且循环准确(不一定必须是代码效率),以便在正常的“硬件'的速度。在深入挖掘6502的技术参考资料时,看起来指令消耗的CPU周期不止一个 - 并且根据给定的条件(如分支)也有不同的周期。我的计划是创建读写功能,并通过使用switch
寻址模式对操作码进行分组。6502每个指令的周期时间
的问题是:当我有一个多周期指令,如BRK
,我需要效仿在每个周期中究竟发生了什么:
#Method 1
cycle - action
1 - read BRK opcode
2 - read padding byte (ignored)
3 - store high byte of PC
4 - store low byte of PC
5 - store status flags with B flag set
6 - low byte of target address
7 - high byte of target address
...或者我能不能执行在一个“周期”(一个switch
case
)中的所有必需操作,并在剩余的周期中不做任何事情?
#Method 2
1 - read BRK opcode,
read padding byte (ignored),
store high byte of PC,
store low byte of PC,
store status flags with B flag set,
low byte of target address,
high byte of target address
2 - do nothing
3 - do nothing
4 - do nothing
5 - do nothing
6 - do nothing
7 - do nothing
由于两种方法都消耗了所需的7个周期,两者之间是否没有差异? (精度明智)
我个人认为方法1的方式是对去解决,但是我想不出来实现它......一个适当的,简单的方法(请帮助!)
它不会有所作为,当你只** **模拟CPU。但考虑一下外设访问与“STA”指令相同的内存 - 当存储单元正好改变时,这可能很重要。所以,去选项1. –
至于如何,你将需要一个状态机 –
你知道任何好的C实例或来源,实现方法1吗?我所能找到的都是非C模拟器,有些在当前级别上太复杂:( –