mirror of
https://github.com/mre/mos6502.git
synced 2024-11-28 07:49:19 +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:
parent
dbfa32b5c2
commit
23ddc109ee
BIN
examples/asm/functional_test/6502_functional_test.bin
Normal file
BIN
examples/asm/functional_test/6502_functional_test.bin
Normal file
Binary file not shown.
1
examples/asm/functional_test/README.md
Normal file
1
examples/asm/functional_test/README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
From https://github.com/Klaus2m5/6502_65C02_functional_tests
|
34
examples/functional.rs
Normal file
34
examples/functional.rs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -988,11 +988,7 @@ impl<M: Bus> CPU<M> {
|
|||||||
|
|
||||||
impl<M: Bus> core::fmt::Debug for CPU<M> {
|
impl<M: Bus> core::fmt::Debug for CPU<M> {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||||
write!(
|
write!(f, "CPU {{ registers: {:?}", self.registers)
|
||||||
f,
|
|
||||||
"CPU Dump:\n\nAccumulator: {}",
|
|
||||||
self.registers.accumulator
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user