-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctional-tests.rs
58 lines (48 loc) · 1.22 KB
/
functional-tests.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use std::fs;
use std::path::Path;
extern crate mos6502;
use mos6502::cpu::CPU;
extern crate clap;
use clap::{App, Arg};
#[macro_use]
extern crate log;
extern crate env_logger;
fn main() {
env_logger::init();
let matches = App::new("MOS 6502 functional test runner")
.arg(
Arg::with_name("binary")
.short("b")
.help("Load binary file")
.index(1),
)
.get_matches();
let mut cpu = CPU::new();
let filename = matches
.value_of("binary")
.unwrap_or("6502_functional_test.bin");
if !Path::new(filename).exists() {
panic!("File {} does not exist", filename)
}
cpu.load(&fs::read(filename).unwrap(), 0);
cpu.pc = 0x400;
let mut trapped = 0;
let mut brk = false;
println!("Test started");
while !brk {
brk = cpu.step();
if cpu.memory.get(cpu.pc) == 0xD0 && cpu.memory.get(cpu.pc + 1) == 0xFE {
trapped += 1;
} else {
trapped = 0;
}
if trapped == 3 {
brk = true;
info!("possible cycle detected");
}
if cpu.pc == 3399 {
brk = true;
println!("SUCCESS");
}
}
}