1 个不稳定版本
0.1.0 | 2023年4月1日 |
---|
#274 in 模拟器
79KB
1.5K SLoC
用于模拟 MOS6502 处理器的 crate。适用于使用此芯片或类似芯片的系统(如 NES 或 Commodore 64)的模拟器。
使用 dg6502 首先需要构建一个 CPU 存储对象,该对象将被 CPU 用于读取和写入内存,然后构建 CPU 对象。可以通过调用 CPU 的 step() 函数执行指令。
尚不支持将其作为可执行文件使用:当前 main.rs 代码只是运行 nestest。
基本示例
use dg6502::{Cpu, BasicCPUMemory, CpuConfig, JamBehavior, IllegalBehavior}
// Load a program from a file into memory, starting at 0x0.
let memory = BasicCPUMemory::from_file(&String::from("my_file.bin"), 0x0)?;
// Configure our CPU and our starting status register.
let config = CpuConfig::default()
.bcd_support(true) // allow BCD arithmetic
.jam_behavior(JamBehavior::Nop) // treat JAMs as NOPs
.illegal_behavior(IllegalBehavior::Execute); // run illegal instructions
let status = StatusRegister::default();
// Initialize CPU and set our program counter to 0x0
// (set to 0x0 by default, this is just for example)
let mut cpu = Cpu::new(memory, config, status);
// Run!
loop {
let result = cpu.step();
// do other stuff...
}
dg6502 实现了合法和非法操作码。通过单个操作码测试 (~10,000 个操作码/操作码) 和通过 NEStest 进行端到端测试对 dg6502 进行单元测试。如果需要,[Cpu] 的所有字段都是公开的,您可以读取和写入。
实现 CPUMemory
如果 BasicCPUMemory 不满足您的需求(例如,您需要镜像或内存映射),则需要在您的内存结构上实现 CPUMemory 特性。
实现 CPUMemory 非常简单,因为它只包含两个方法。read() 接收一个 u16 地址并返回一个 u8,write() 接收一个 u8 操作数和一个 u16 地址来写入。放手去做吧!
设计
我使用这个项目来完成我的 IB 班级的 IA 作业。那个作业要求我写关于这个模拟器的设计,如果您想阅读,可以在这里找到(即将推出)。
支持
如果您有任何错误、反馈、问题、问题、建议等,请随时向 dg6502 存储库提交问题。
依赖项
~2–MB
~107K SLoC