A full Intel 8080 CPU emulator in Rust.
This crate is now a no_std CPU core. It focuses on Intel 8080 execution only; file loading, threading, timers, host messaging and platform-specific I/O are expected to live outside the crate.
To verify the emulation, run below:
cargo run --features="cpu_diag", making sure CPU IS OPERATIONAL gets popped up.
This library is intended to be portable on different platforms: macOS, iOS, Android and (if possible) Web.
Feature flags:
cpu_diag: enables the bundled diagnosis flow and its debug output.
Create a CPU with ROM bytes and RAM, then drive it from your host loop.
- Construct
Cpu8080withCpu8080::new(rom, ram), whererom: &[u8]andram: &mut [u8]are owned by the caller. - If you need a different address-space layout, implement the
Memorytrait and build the CPU withCpu8080::with_memory(...). - Call
step()to execute one instruction, orrun()to keep executing until the CPU halts or needs host-visible I/O. - When you receive
ExecutionState::Input { port }, fetch the value from your platform and pass it back withprovide_input(value). - When you receive
ExecutionState::Output { port, value }, forward it to your platform-specific device model. - Use
interrupt()andrestart()from your host when the platform needs to inject interrupts or reset the CPU. - Use
get_ram()with the defaultSplitMemorylayout, ormemory()/memory_mut()if you are using a custom memory implementation.
use i8080emulator::{Cpu8080, ExecutionState};
let mut ram = [0; 0x4000];
let mut cpu = Cpu8080::new(rom, &mut ram);
loop {
match cpu.run()?.state {
ExecutionState::Continue => {}
ExecutionState::Input { port } => {
let value = platform_read(port);
cpu.provide_input(value)?;
}
ExecutionState::Output { port, value } => {
platform_write(port, value);
}
ExecutionState::Halted => break,
}
}The repo now also contains a thin FFI crate for Swift and other C-compatible hosts.
- Build it with
cargo build -p i8080emulator-ffi --release - The exported header is at
ffi/include/i8080emulator_ffi.h - The static library will be emitted under
target/release/
The FFI layer is now also no_std/no-allocation. The host owns CPU storage, ROM, and RAM:
i8080_cpu_size/i8080_cpu_aligni8080_init_cpu/i8080_deinit_cpui8080_run/i8080_stepi8080_provide_inputi8080_interrupti8080_restarti8080_ram_ptr/i8080_ram_len