Skip to content

Commit

Permalink
Added Diagnostics II tests for Z80 and 8080
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanizag committed May 9, 2020
1 parent 526333e commit e91eae3
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 80 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iz80"
version = "0.3.1"
version = "0.3.2"
authors = ["Ivan Izaguirre <[email protected]>"]
edition = "2018"
license = "MIT"
Expand Down
133 changes: 133 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,136 @@ fn main() {

- The ZEXALL test suite for Z80 was taken from https://github.com/anotherlin/z80emu
- The EX8080 test suite for Intel 8080 was taken from https://github.com/begoon/i8080-core

## Test results:

### Diagnostics II by Supersoft Associates for Intel 8080

```
DIAGNOSTICS II V1.2 - CPU TEST
COPYRIGHT (C) 1981 - SUPERSOFT ASSOCIATES
ABCDEFGHIJKLMNOPQRSTUVWXYZ
CPU IS 8080/8085
BEGIN TIMING TEST
END TIMING TEST
CPU TESTS OK
```
### Diagnostics II by Supersoft Associates for Z80

```
DIAGNOSTICS II V1.2 - CPU TEST
COPYRIGHT (C) 1981 - SUPERSOFT ASSOCIATES
ABCDEFGHIJKLMNOPQRSTUVWXYZ
CPU IS Z80
BEGIN TIMING TEST
END TIMING TEST
CPU TESTS OK
```

### Z80 instruction exerciser ZEXALL

```
Z80 instruction exerciser
<adc,sbc> hl,<bc,de,hl,sp>.... OK
add hl,<bc,de,hl,sp>.......... OK
add ix,<bc,de,ix,sp>.......... OK
add iy,<bc,de,iy,sp>.......... OK
aluop a,nn.................... OK
aluop a,<b,c,d,e,h,l,(hl),a>.. OK
aluop a,<ixh,ixl,iyh,iyl>..... OK
aluop a,(<ix,iy>+1)........... OK
bit n,(<ix,iy>+1)............. OK
bit n,<b,c,d,e,h,l,(hl),a>.... OK
cpd<r>........................ OK
cpi<r>........................ OK
<daa,cpl,scf,ccf>............. OK
<inc,dec> a................... OK
<inc,dec> b................... OK
<inc,dec> bc.................. OK
<inc,dec> c................... OK
<inc,dec> d................... OK
<inc,dec> de.................. OK
<inc,dec> e................... OK
<inc,dec> h................... OK
<inc,dec> hl.................. OK
<inc,dec> ix.................. OK
<inc,dec> iy.................. OK
<inc,dec> l................... OK
<inc,dec> (hl)................ OK
<inc,dec> sp.................. OK
<inc,dec> (<ix,iy>+1)......... OK
<inc,dec> ixh................. OK
<inc,dec> ixl................. OK
<inc,dec> iyh................. OK
<inc,dec> iyl................. OK
ld <bc,de>,(nnnn)............. OK
ld hl,(nnnn).................. OK
ld sp,(nnnn).................. OK
ld <ix,iy>,(nnnn)............. OK
ld (nnnn),<bc,de>............. OK
ld (nnnn),hl.................. OK
ld (nnnn),sp.................. OK
ld (nnnn),<ix,iy>............. OK
ld <bc,de,hl,sp>,nnnn......... OK
ld <ix,iy>,nnnn............... OK
ld a,<(bc),(de)>.............. OK
ld <b,c,d,e,h,l,(hl),a>,nn.... OK
ld (<ix,iy>+1),nn............. OK
ld <b,c,d,e>,(<ix,iy>+1)...... OK
ld <h,l>,(<ix,iy>+1).......... OK
ld a,(<ix,iy>+1).............. OK
ld <ixh,ixl,iyh,iyl>,nn....... OK
ld <bcdehla>,<bcdehla>........ OK
ld <bcdexya>,<bcdexya>........ OK
ld a,(nnnn) / ld (nnnn),a..... OK
ldd<r> (1).................... OK
ldd<r> (2).................... OK
ldi<r> (1).................... OK
ldi<r> (2).................... OK
neg........................... OK
<rrd,rld>..................... OK
<rlca,rrca,rla,rra>........... OK
shf/rot (<ix,iy>+1)........... OK
shf/rot <b,c,d,e,h,l,(hl),a>.. OK
<set,res> n,<bcdehl(hl)a>..... OK
<set,res> n,(<ix,iy>+1)....... OK
ld (<ix,iy>+1),<b,c,d,e>...... OK
ld (<ix,iy>+1),<h,l>.......... OK
ld (<ix,iy>+1),a.............. OK
ld (<bc,de>),a................ OK
Tests complete
```

### 8080 instruction exerciser

```
8080 instruction exerciser (KR580VM80A CPU)
dad <b,d,h,sp>................ OK
aluop nn...................... OK
aluop <b,c,d,e,h,l,m,a>....... OK
<daa,cma,stc,cmc>............. OK
<inr,dcr> a................... OK
<inr,dcr> b................... OK
<inx,dcx> b................... OK
<inr,dcr> c................... OK
<inr,dcr> d................... OK
<inx,dcx> d................... OK
<inr,dcr> e................... OK
<inr,dcr> h................... OK
<inx,dcx> h................... OK
<inr,dcr> l................... OK
<inr,dcr> m................... OK
<inx,dcx> sp.................. OK
lhld nnnn..................... OK
shld nnnn..................... OK
lxi <b,d,h,sp>,nnnn........... OK
ldax <b,d>.................... OK
mvi <b,c,d,e,h,l,m,a>,nn...... OK
mov <bcdehla>,<bcdehla>....... OK
sta nnnn / lda nnnn........... OK
<rlc,rrc,ral,rar>............. OK
stax <b,d>.................... OK
Tests complete
```
2 changes: 1 addition & 1 deletion src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Cpu {
self.state.reg.get16(Reg16::IY),
self.state.reg.get8(Reg8::F)
);
println!(" [{:02x} {:02x} {:02x}]", sys.peek(pc+1),
println!(" [{:02x} {:02x} {:02x}]", sys.peek(pc),
sys.peek(pc+1), sys.peek(pc+2));
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/registers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ impl Registers {
if self.mode8080 && rr == Reg16::AF {
// Ensure non existent flags have proper values
self.set_flag(Flag::N);
self.clear_flag(Flag::_3);
self.clear_flag(Flag::_5);
}
}

Expand Down
72 changes: 72 additions & 0 deletions tests/cputest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use iz80::*;

// Diagnostics II, version 1.2, CPU test by Supersoft Associates

static CODE: &'static [u8] = include_bytes!("res/CPUTEST.COM");

#[test]
fn test_cpu_test_8080() {
cpu_test(Cpu::new_8080());
}

#[test]
fn test_cpu_test_z80() {
cpu_test(Cpu::new_z80());
}

fn cpu_test(mut cpu: Cpu) {
let mut machine = PlainMachine::new();

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

/*
System call 5
.org $5
ret
*/
//let code = [0xD3, 0x00, 0xC9];
let code = [0xC9];
for i in 0..code.len() {
machine.poke(5 + i as u16, code[i]);
}

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

// Avoid tracing the long loop
if cpu.registers().pc() == 0x31b3 {
cpu.set_trace(false);
} else if cpu.registers().pc() == 0x31b5 {
cpu.set_trace(trace);
}

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

if cpu.registers().pc() == 0x0005 {
match cpu.registers().get8(Reg8::C) {
2 => {
// C_WRITE
let ch = cpu.registers().get8(Reg8::E) as char;
print!("{}", ch);
msg.push(ch);
},
_ => panic!("BDOS command not implemented")
}
}
}

assert_eq!(true, msg.contains("CPU TESTS OK"));
}
42 changes: 3 additions & 39 deletions tests/ex8080.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ use iz80::*;
8080/8085 CPU Exerciser by Ian Bartholomew and Frank Cringles
*/



static CODE: &'static [u8] = include_bytes!("res/8080EX1.COM");

#[test]
#[ignore]
fn test_ex8080() {
let mut machine = ZexMachine::new();
let mut machine = PlainMachine::new();
let mut cpu = Cpu::new_8080();

// Load program
Expand Down Expand Up @@ -70,7 +68,7 @@ fn test_ex8080() {
match cpu.registers().get8(Reg8::C) {
2 => {
// C_WRITE
print!("{}", cpu.registers().get8(Reg8::E));
print!("{}", cpu.registers().get8(Reg8::E) as char);
},
9 => {
// C_WRITE_STR
Expand All @@ -92,7 +90,6 @@ fn test_ex8080() {
},
_ => panic!("BDOS command not implemented")
}
machine.bdos_called = false;
}
}

Expand All @@ -101,37 +98,4 @@ fn test_ex8080() {
} else {
assert_eq!(25, tests_passed);
}
}

struct ZexMachine {
mem: [u8; 65536],
bdos_called: bool
}

impl ZexMachine {
pub fn new() -> ZexMachine {
ZexMachine {
mem: [0; 65536],
bdos_called: false
}
}
}

impl Machine for ZexMachine {
fn peek(&self, address: u16) -> u8 {
self.mem[address as usize]
}

fn poke(&mut self, address: u16, value: u8) {
self.mem[address as usize] = value;
}

fn port_in(&mut self, _address: u16) -> u8 {
0
}

fn port_out(&mut self, _address: u16, _value: u8) {
self.bdos_called = true;
}
}

}
Binary file added tests/res/CPUTEST.COM
Binary file not shown.
42 changes: 4 additions & 38 deletions tests/zexall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ static ZEXALL: &'static [u8] = include_bytes!("res/zexall.com");
#[test]
#[ignore]
fn test_zexall() {
let mut machine = ZexMachine::new();
let mut machine = PlainMachine::new();
let mut cpu = Cpu::new();

// Load program
Expand Down Expand Up @@ -62,11 +62,11 @@ fn test_zexall() {
break;
}

if machine.bdos_called {
if cpu.registers().pc() == 0x0005 {
match cpu.registers().get8(Reg8::C) {
2 => {
// C_WRITE
print!("{}", cpu.registers().get8(Reg8::E));
print!("{}", cpu.registers().get8(Reg8::E) as char);
},
9 => {
// C_WRITE_STR
Expand All @@ -88,7 +88,6 @@ fn test_zexall() {
},
_ => panic!("BDOS command not implemented")
}
machine.bdos_called = false;
}
}

Expand All @@ -97,37 +96,4 @@ fn test_zexall() {
} else {
assert_eq!(67, tests_passed);
}
}

struct ZexMachine {
mem: [u8; 65536],
bdos_called: bool
}

impl ZexMachine {
pub fn new() -> ZexMachine {
ZexMachine {
mem: [0; 65536],
bdos_called: false
}
}
}

impl Machine for ZexMachine {
fn peek(&self, address: u16) -> u8 {
self.mem[address as usize]
}

fn poke(&mut self, address: u16, value: u8) {
self.mem[address as usize] = value;
}

fn port_in(&mut self, _address: u16) -> u8 {
0
}

fn port_out(&mut self, _address: u16, _value: u8) {
self.bdos_called = true;
}
}

}

0 comments on commit e91eae3

Please sign in to comment.