Crate rz80

Source
Expand description

rz80 is a Z80 chip family emulation library written in Rust which can be used as basis for writing a full Z80-based computer emulator.

§Overview

The rz80 library provides chip emulators for the Z80 CPU, PIO (parallel in/out), CTC (counter/timer channels) and a Bus trait which defines how the chips are wired together in a specific emulated system.

Writing a home computer emulator usually involves the following steps

  • import the required chips
  • import ROM dumps using the include_bytes! macro
  • define a State struct which holds emulator state required in addition to the chip state
  • define a System struct which embeds all chips and the State struct wrapped in RefCells
  • write a System::poweron() function which initializes the embedded chips and state objects, initializes the memory map and sets the CPU PC register to the ROM dump start address
  • write a video-decoder function which generates a linear RGBA8 framebuffer each frame
  • implement the Bus trait on the System struct, this usually involves:
    • the keyboard emulation
    • memory bank switching
    • forward interrupt requests between the various hardware components
    • sound generation
  • implement the main loop which creates a window, forwards keyboard input, and steps the chips emulators forward

Very simple 8-bit home computer systems (similar to the ZX81) don’t require any additional code, more complex home computers will require additional custom chips emulations that are not part of the rz80 library.

Check out the two included example emulators:

> cargo run --release --example z1013
> cargo run --release --example kc87

Structs§

CPU
Z80 CPU emulation
CTC
Z80 CTC emulation
Daisychain
interrupt controller daisychain
Memory
memory access
PIO
Z80 PIO emulation
Registers
CPU register access

Constants§

CF
CPU carry flag
CTC_0
CTC channel 0
CTC_1
CTC channel 1
CTC_2
CTC channel 2
CTC_3
CTC channel 3
HF
CPU half carry flag
NF
CPU add/subtract flag
PF
CPU parity flag (same as overflow)
PIO_A
PIO channel A
PIO_B
PIO channel B
SF
CPU sign flag
VF
CPU overflow flag (same as parity)
XF
CPU undocumented ‘X’ flag
YF
CPU undocumented ‘Y’ flag
ZF
CPU zero flag

Traits§

Bus
system bus trait

Type Aliases§

RegT
generic integer type for 8- and 16-bit values