6502 CPU仿真 [英] 6502 CPU Emulation
问题描述
今天是周末,所以我通过编写一个爱好项目来花整周的时间来放松自己。
It's the weekend, so I relax from spending all week programming by writing a hobby project.
昨天我写了一个MOS 6502 CPU仿真器的框架,寄存器,堆栈,内存和所有操作码均已实现。 (链接到下面的源代码)
I wrote the framework of a MOS 6502 CPU emulator yesterday, the registers, stack, memory and all the opcodes are implemented. (Link to source below)
我可以在编写的调试器中手动运行一系列操作,但是我想加载NES rom并仅指向程序
I can manually run a series of operations in the debugger I wrote, but I'd like to load a NES rom and just point the program counter at its instructions, I figured that this would be the fastest way to find flawed opcodes.
我写了一个快速的NES rom loader并将ROM bank加载到CPU内存中。
I wrote a quick NES rom loader and loaded the ROM banks into the CPU memory.
问题是我不知道操作码是如何编码的。我知道操作码本身遵循每个操作码一个字节的模式,可以唯一地标识操作码
The problem is that I don't know how the opcodes are encoded. I know that the opcodes themselves follow a pattern of one byte per opcode that uniquely identifies the opcode,
0 - BRK
1 - ORA (D,X)
2 - COP b
等
但是我不确定应该在哪里找到操作码参数。是紧随其后的字节吗?在绝对内存中,我想它可能不是字节,而是一个字节。
However I'm not sure where I'm supposed to find the opcode argument. Is it the the byte directly following? In absolute memory, I suppose it might not be a byte but a short.
是否有人熟悉此CPU的内存模型?
Is anyone familiar with this CPU's memory model?
编辑:我意识到这可能是在黑暗,但我希望这里有一些老派的苹果和准将黑客潜伏在这里。
I realize that this is probably shot in the dark, but I was hoping there were some oldschool Apple and Commodore hackers lurking here.
编辑::谢谢大家的帮助。在执行适当的更改以对齐每个操作之后,CPU可以加载并运行Mario Brothers。它没有做任何事情,而是循环等待开始,但是它是一个好兆头:)
Thanks for your help everyone. After I implemented the proper changes to align each operation the CPU can load and run Mario Brothers. It doesn't do anything but loop waiting for Start, but its a good sign :)
我上传了源代码:
https://archive.codeplex.com/?p=cpu6502
如果有人想知道模拟器的工作方式,那么它很容易理解。至少没有进行优化,但是接下来,我要模拟一个在2.4ghz机器上以2mhz运行的CPU:)
If anyone has ever wondered how an emulator works, its pretty easy to follow. Not optimized in the least, but then again, I'm emulating a CPU that runs at 2mhz on a 2.4ghz machine :)
推荐答案
操作码占一个字节,而操作数位于以下字节中。例如,在此处中查看字节大小列。
The opcode takes one byte, and the operands are in the following bytes. Check out the byte size column here, for instance.
这篇关于6502 CPU仿真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!