1
0
mirror of https://github.com/mre/mos6502.git synced 2024-06-27 05:29:31 +00:00
mre-mos6502/tests/functional-test.rs

50 lines
1.2 KiB
Rust
Raw Normal View History

2018-11-04 22:11:41 +00:00
extern crate mos6502;
2023-04-05 20:43:19 +00:00
use env_logger::Env;
2018-11-04 22:11:41 +00:00
use std::fs::File;
use std::io::Read;
use mos6502::cpu::CPU;
2023-04-05 20:43:19 +00:00
use mos6502::memory::Bus;
use mos6502::memory::Memory;
2018-11-04 22:11:41 +00:00
const PC_START: u16 = 0x400;
// const MAX_CYCLES: usize = 100000000;
#[test]
fn functional_test() {
2023-04-05 20:43:19 +00:00
env_logger::init_from_env(Env::default().default_filter_or("mos6502=debug"));
2018-11-04 22:11:41 +00:00
let mut f = File::open("test-roms/6502_functional_test.bin").unwrap();
let mut rom = Vec::<u8>::new();
f.read_to_end(&mut rom).unwrap();
2023-04-05 20:43:19 +00:00
let mut cpu = CPU::new(Memory::<66560>::new());
2018-11-04 22:11:41 +00:00
2023-04-05 20:43:19 +00:00
cpu.memory.set_bytes(PC_START, &rom);
2018-11-04 22:11:41 +00:00
2023-04-05 20:43:19 +00:00
// cpu.run();
2018-11-04 22:11:41 +00:00
2023-04-05 20:43:19 +00:00
let mut last_pc = PC_START;
loop {
cpu.single_step();
// Prevent endless loop
// TODO: We could add cycle count to the CPU struct to check that
// if cpu.interconnect.elapsed_cycles() > MAX_CYCLES {
// assert!(false, "Took too many cycles to complete");
// }
if last_pc == cpu.registers.program_counter {
if cpu.registers.program_counter == 0x3367 {
// Success!
break;
} else {
// assert!(false, "Trap detected");
2018-11-04 22:11:41 +00:00
}
}
2023-04-05 20:43:19 +00:00
last_pc = cpu.registers.program_counter;
}
2018-11-04 22:11:41 +00:00
}