# iz80 [![Build Status](https://github.com/ivanizag/iz80/workflows/Build/badge.svg)](https://github.com/ivanizag/iz80/actions?workflow=Build) [![Crates](https://img.shields.io/crates/v/iz80.svg)](https://crates.io/crates/iz80) [![Documentation](https://docs.rs/iz80/badge.svg)](https://docs.rs/iz80) Zilog Z80 and Intel 8080 emulator library for RUST. It passes all the tests of the ZEXALL suite. Instruction based accuracy. To run the ZEXALL test suite for Zilog Z80: ```shell cargo test --release -- --nocapture --ignored --test zexall ``` To run the EX8080 test suite for Intel 8080: ```shell cargo test --release -- --nocapture --ignored --test ex8080 ``` To run Tiny Basic (from [cpuville](http://cpuville.com/Kits/Z80-kits-home.html)): ```shell cargo run --bin cpuville ``` ## Usage See [cpuville.rs](src/bin/cpuville.rs) or the CP/M 2.2 emulator [iz-cpm](https://github.com/ivanizag/iz-cpm) for more usage examples. To run this example, execute: `cargo run --bin simplest` ```rust use iz80::*; fn main() { // Prepare the device let mut machine = PlainMachine::new(); let mut cpu = Cpu::new(); // Or Cpu::new_8080() cpu.set_trace(true); // Load program inline or from a file with: // let code = include_bytes!("XXXX.rom"); let code = [0x3c, 0xc3, 0x00, 0x00]; // INC A, JP $0000 let size = code.len(); for i in 0..size { machine.poke(0x0000 + i as u16, code[i]); } // Run emulation cpu.registers().set_pc(0x0000); loop { cpu.execute_instruction(&mut machine); // Examine machine state to update the hosting device as needed. if cpu.registers().a() == 0x10 { // Let's stop break; } } } ``` ## Links - 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 hl,.... OK add hl,.......... OK add ix,.......... OK add iy,.......... OK aluop a,nn.................... OK aluop a,.. OK aluop a,..... OK aluop a,(+1)........... OK bit n,(+1)............. OK bit n,.... OK cpd........................ OK cpi........................ OK ............. OK a................... OK b................... OK bc.................. OK c................... OK d................... OK de.................. OK e................... OK h................... OK hl.................. OK ix.................. OK iy.................. OK l................... OK (hl)................ OK sp.................. OK (+1)......... OK ixh................. OK ixl................. OK iyh................. OK iyl................. OK ld ,(nnnn)............. OK ld hl,(nnnn).................. OK ld sp,(nnnn).................. OK ld ,(nnnn)............. OK ld (nnnn),............. OK ld (nnnn),hl.................. OK ld (nnnn),sp.................. OK ld (nnnn),............. OK ld ,nnnn......... OK ld ,nnnn............... OK ld a,<(bc),(de)>.............. OK ld ,nn.... OK ld (+1),nn............. OK ld ,(+1)...... OK ld ,(+1).......... OK ld a,(+1).............. OK ld ,nn....... OK ld ,........ OK ld ,........ OK ld a,(nnnn) / ld (nnnn),a..... OK ldd (1).................... OK ldd (2).................... OK ldi (1).................... OK ldi (2).................... OK neg........................... OK ..................... OK ........... OK shf/rot (+1)........... OK shf/rot .. OK n,..... OK n,(+1)....... OK ld (+1),...... OK ld (+1),.......... OK ld (+1),a.............. OK ld (),a................ OK Tests complete ``` ### 8080 instruction exerciser ``` 8080 instruction exerciser (KR580VM80A CPU) dad ................ OK aluop nn...................... OK aluop ....... OK ............. OK a................... OK b................... OK b................... OK c................... OK d................... OK d................... OK e................... OK h................... OK h................... OK l................... OK m................... OK sp.................. OK lhld nnnn..................... OK shld nnnn..................... OK lxi ,nnnn........... OK ldax .................... OK mvi ,nn...... OK mov ,....... OK sta nnnn / lda nnnn........... OK ............. OK stax .................... OK Tests complete ``` ### Pre-commit tests Note that the Zexall test suite is very long and is disabled for continuouos integration. To run it, execute: ``` cargo test --release -- --nocapture --ignored --test zexall ```