Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanizag committed Jun 4, 2020
1 parent e91eae3 commit 396dc91
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl <'a> Environment<'_> {
}

pub fn load_displacement_forced(&mut self) {
// For DDCB and FDCB we allways have to load the
// For DDCB and FDCB we always have to load the
// displacement. Even before decoding the opcode
self.state.displacement = self.advance_pc() as i8;
self.state.displacement_loaded = true;
Expand All @@ -109,7 +109,7 @@ impl <'a> Environment<'_> {
pub fn load_displacement(&mut self, reg: Reg8) {
/*
The displacement byte is a signed 8-bit integer (-128..+127) used
in some instructions to specifiy a displacement added to a given
in some instructions to specify a displacement added to a given
memory address. Its presence or absence depends on the instruction
at hand, therefore, after reading the prefix and opcode, one has
enough information to figure out whether to expect a displacement
Expand Down
Binary file added tests/res/z80ccf.out
Binary file not shown.
Binary file added tests/res/z80doc.out
Binary file not shown.
Binary file added tests/res/z80docflags.out
Binary file not shown.
Binary file added tests/res/z80flags.out
Binary file not shown.
Binary file added tests/res/z80full.out
Binary file not shown.
Binary file added tests/res/z80memptr.out
Binary file not shown.
73 changes: 73 additions & 0 deletions tests/z80test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
use iz80::*;

// From https://github.com/raxoft/z80test
// Not passing

//static CODE: &'static [u8] = include_bytes!("res/z80doc.out");
//static CODE: &'static [u8] = include_bytes!("res/z80ccf.out");
//static CODE: &'static [u8] = include_bytes!("res/z80docflags.out");
//static CODE: &'static [u8] = include_bytes!("res/z80flags.out");
//static CODE: &'static [u8] = include_bytes!("res/z80memptr.out");
static CODE: &'static [u8] = include_bytes!("res/z80full.out");

const START: u16 = 0x8000;

#[test]
#[ignore]
fn z80test() {
let mut cpu = Cpu::new_z80();
let mut machine = PlainMachine::new();

// Load program
let code = CODE;
let size = code.len();
for i in 0..size {
machine.poke(START + i as u16, code[i]);
}

// Do nothing on 0x1601 and RST 0x10
machine.poke(0x1601, 0xc9); // RET
machine.poke(0x0010, 0xc9); // RET

// Patch to run a single test
let run_single_test = false;
let single_test = 148;
if run_single_test {
machine.poke16(0x802b, single_test); // ld bc, 0 to ld bc, test
let mut test_start = machine.peek16(0x802e);
println!("Test table {:x}", test_start);
test_start += single_test*2;
println!("Test table {:x}", test_start);
machine.poke16(0x802e, test_start); // Move start
machine.poke16(test_start + 2 , 0); // NUL terminate test
}

cpu.registers().set_pc(START);
let trace = false;
cpu.set_trace(trace);
let mut msg = String::new();
loop {
cpu.execute_instruction(&mut machine);

if cpu.registers().pc() == 0x0000 {
println!("");
break;
}

if cpu.registers().pc() == 0x0010 {
let mut ch = cpu.registers().get8(Reg8::A) as char;
if ch == '\r' {
ch = '\n'
} else if ch as u8 == 23 {
ch = ' '
} else if ch as u8 == 26 {
ch = ' '
}
//print!("{}[{}]", ch, ch as u8);
print!("{}", ch);
msg.push(ch);
}
}

assert_eq!(true, msg.contains("CPU TESTS OK"));
}

0 comments on commit 396dc91

Please sign in to comment.