1
0
mirror of https://github.com/mre/mos6502.git synced 2024-11-25 02:33:26 +00:00

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.
This commit is contained in:
Matthias 2023-06-19 13:34:35 +02:00
parent dbfa32b5c2
commit 23ddc109ee
4 changed files with 36 additions and 5 deletions

Binary file not shown.

View File

@ -0,0 +1 @@
From https://github.com/Klaus2m5/6502_65C02_functional_tests

34
examples/functional.rs Normal file
View File

@ -0,0 +1,34 @@
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;
}
}

View File

@ -988,11 +988,7 @@ impl<M: Bus> CPU<M> {
impl<M: Bus> core::fmt::Debug for CPU<M> {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(
f,
"CPU Dump:\n\nAccumulator: {}",
self.registers.accumulator
)
write!(f, "CPU {{ registers: {:?}", self.registers)
}
}