Skip to content

Commit 92e7068

Browse files
committed
enhanced docs
1 parent 3ddde47 commit 92e7068

File tree

5 files changed

+55
-9
lines changed

5 files changed

+55
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
[workspace]
2-
members = [
3-
]
41
[package]
52
name = "z80"
63
authors = ["Kirjava"]
7-
version = "0.0.1"
4+
version = "1.0.0"
85
edition = "2021"
96
license = "MIT"
7+
description = "z80 emulator"
8+
readme = "README.md"
9+
documentation = "https://docs.rs/z80"
10+
repository = "https://github.com/kirjavascript/z80"
1011

1112
[lib]
1213
name = "z80"
@@ -17,3 +18,7 @@ crate-type = ["staticlib", "rlib"]
1718

1819
[profile.test]
1920
opt-level = 3
21+
22+
[workspace]
23+
members = [
24+
]

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
A fast and accurate instruction-stepped Z80 emulator written in C11 and ported to Rust with c2rust and manual refactoring.
44

5-
The Rust version appears to run about 25% faster than the C version when benchmarked on my machine.
5+
The Rust version appears to run about 25% faster than the C version when benchmarked on my machine.
6+
7+
It still uses unsafe (for now).
68

79
This emulator passes both the ZEXDOC and ZEXALL Z80 instruction tests. It has also been verified correct against VisualZ80, and is known to run the entire ColecoVision, SG-1000, Master System, and Game Gear libraries. Additionally, it has been successfully integrated into Mega Drive/Genesis and Neo Geo emulators with unknown (but likely high or perfect) compatibility.
810

lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,40 @@
33
#![allow(unused_assignments)]
44
#![allow(unused_mut)]
55

6+
//! A fast and accurate instruction-stepped Z80 emulator written in C11 and ported to Rust
7+
//!
8+
//! Basic usage:
9+
//! ```rust
10+
//!use z80::{Z80, Z80_io};
11+
//!
12+
//!struct IO {
13+
//! pub mem: [u8; 0x10000],
14+
//!}
15+
//!
16+
//!impl Z80_io for IO {
17+
//! fn read_byte(&self, addr: u16) -> u8 {
18+
//! self.mem[addr as usize]
19+
//! }
20+
//!
21+
//! fn write_byte(&mut self, addr: u16, value: u8) {
22+
//! self.mem[addr as usize] = value;
23+
//! }
24+
//! fn port_in(&self, _addr: u16) -> u8 { 0xff }
25+
//! fn port_out(&mut self, _addr: u16, _value: u8) { }
26+
//!}
27+
//!
28+
//!let mut cpu = Z80::new(IO {
29+
//! mem: [0; 0x10000],
30+
//!});
31+
//!
32+
//!for (i, byte) in rom.iter().enumerate() {
33+
//! cpu.write_byte(i, *byte);
34+
//!}
35+
//!
36+
//!loop {
37+
//! cpu.step();
38+
//!}
39+
//!```
640
741
mod z80;
842
pub use self::z80::*;

z80.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,15 @@ type uint32_t = u32;
3535
const ASSERT: u32 = 2;
3636
const PULSE: u32 = 1;
3737

38+
/// Trait for controlling IO behaviour
3839
pub trait Z80_io {
3940
fn read_byte(&self, addr: u16) -> u8;
4041
fn write_byte(&mut self, addr: u16, value: u8);
4142
fn port_in(&self, addr: u16) -> u8;
4243
fn port_out(&mut self, addr: u16, value: u8);
4344
}
4445

45-
// pub struct Z80 <T: z80Ctrl>{
46-
// pub ctrl: T,
47-
46+
/// Z80 CPU
4847
pub struct Z80 <T: Z80_io> {
4948
pub ctrl: T,
5049
pub pc: uint16_t,
@@ -180,6 +179,12 @@ impl<T: Z80_io> Z80<T> {
180179
}
181180
self.ctrl.port_out(addr, value);
182181
}
182+
pub fn read_byte(&self, addr: u16) -> u8 {
183+
self.ctrl.read_byte(addr)
184+
}
185+
pub fn write_byte(&mut self, addr: u16, value: u8) {
186+
self.ctrl.write_byte(addr, value);
187+
}
183188
pub fn step(&mut self) -> u32 {
184189
unsafe { step_s(self) }
185190
}

0 commit comments

Comments
 (0)