1
0
mirror of https://github.com/mre/mos6502.git synced 2025-02-20 09:29:02 +00:00
mre-mos6502/examples/functional.rs
Matthias 23ddc109ee Add functional test and update CPU debug output
The functional test is based on
https://github.com/Klaus2m5/6502_65C02_functional_tests

It does NOT pass yet. :(
However, I think it's a good idea to have it in the repo
nonetheless, to make some incremental improvements.

This PR is based on the `asm` branch, which should be
merged first.
2023-06-19 13:34:35 +02:00

35 lines
889 B
Rust

use mos6502::cpu;
use mos6502::memory::Bus;
use mos6502::memory::Memory;
use std::fs::read;
fn main() {
// Load the binary file from disk
let program = match read("examples/asm/functional_test/6502_functional_test.bin") {
Ok(data) => data,
Err(err) => {
println!("Error reading functional test: {}", err);
return;
}
};
let mut cpu = cpu::CPU::new(Memory::new());
cpu.memory.set_bytes(0x00, &program);
cpu.registers.program_counter = 0x400;
// run step-by-step
let mut old_pc = cpu.registers.program_counter;
while cpu.registers.program_counter != 0x3468 {
cpu.single_step();
println!("{cpu:?}");
if cpu.registers.program_counter == old_pc {
println!("Infinite loop detected!");
break;
}
old_pc = cpu.registers.program_counter;
}
}