z80

package module
v0.0.0-...-34d2ab4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2023 License: MIT Imports: 6 Imported by: 0

README

koron-go/z80

PkgGoDev Actions/Go Go Report Card

Z80 emulation in Go.

Progress

Z80 instruction set exerciser (documented), passed all 67/67 (100%) tests.

You can try it with...

$ make zexdoc
  • adc16 - <adc,sbc> hl,<bc,de,hl,sp> (38,912 cycles)
  • add16 - add hl,<bc,de,hl,sp> (19,456 cycles)
  • add16x - add ix,<bc,de,ix,sp> (19,456 cycles)
  • add16y - add iy,<bc,de,iy,sp> (19,456 cycles)
  • alu8i - aluop a,nn (28,672 cycles)
  • alu8r - aluop a,<b,c,d,e,h,l,(hl),a> (753,664 cycles)
  • alu8rx - aluop a,<ixh,ixl,iyh,iyl> (376,832 cycles)
  • alu8x - aluop a,(<ix,iy>+1) (229,376 cycles)
  • bitx - bit n,(<ix,iy>+1) (2048 cycles)
  • bitz80 - bit n,<b,c,d,e,h,l,(hl),a> (49,152 cycles)
  • cpd1 - cpd<r> (1) (6144 cycles)
  • cpi1 - cpi<r> (1) (6144 cycles)
  • daaop - <daa,cpl,scf,ccf> (65,536 cycles)
  • inca - <inc,dec> a (3072 cycles)
  • incb - <inc,dec> b (3072 cycles)
  • incbc - <inc,dec> bc (1536 cycles)
  • incc - <inc,dec> c (3072 cycles)
  • incd - <inc,dec> d (3072 cycles)
  • incde - <inc,dec> de (1536 cycles)
  • ince - <inc,dec> e (3072 cycles)
  • inch - <inc,dec> h (3072 cycles)
  • inchl - <inc,dec> hl (1536 cycles)
  • incix - <inc,dec> ix (1536 cycles)
  • inciy - <inc,dec> iy (1536 cycles)
  • incl - <inc,dec> l (3072 cycles)
  • incm - <inc,dec> (hl) (3072 cycles)
  • incsp - <inc,dec> sp (1536 cycles)
  • incx - <inc,dec> (<ix,iy>+1) (6144 cycles)
  • incxh - <inc,dec> ixh (3072 cycles)
  • incxl - <inc,dec> ixl (3072 cycles)
  • incyh - <inc,dec> iyh (3072 cycles)
  • incyl - <inc,dec> iyl (3072 cycles)
  • ld161 - ld <bc,de>,(nnnn) (32 cycles)
  • ld162 - ld hl,(nnnn) (16 cycles)
  • ld163 - ld sp,(nnnn) (16 cycles)
  • ld164 - ld <ix,iy>,(nnnn) (32 cycles)
  • ld165 - ld (nnnn),<bc,de> (64 cycles)
  • ld166 - ld (nnnn),hl (16 cycles)
  • ld167 - ld (nnnn),sp (16 cycles)
  • ld168 - ld (nnnn),<ix,iy> (64 cycles)
  • ld16im - ld <bc,de,hl,sp>,nnnn (64 cycles)
  • ld16ix - ld <ix,iy>,nnnn (32 cycles)
  • ld8bd - ld a,<(bc),(de)> (44 cycles)
  • ld8im - ld <b,c,d,e,h,l,(hl),a>,nn (64 cycles)
  • ld8imx - ld (<ix,iy>+1),nn (32 cycles)
  • ld8ix1 - ld <b,c,d,e>,(<ix,iy>+1) (512 cycles)
  • ld8ix2 - ld <h,l>,(<ix,iy>+1) (256 cycles)
  • ld8ix3 - ld a,(<ix,iy>+1) (128 cycles)
  • ld8ixy - ld <ixh,ixl,iyh,iyl>,nn (32 cycles)
  • ld8rr - ld <b,c,d,e,h,l,a>,<b,c,d,e,h,l,a> (3456 cycles)
  • ld8rrx - ld <b,c,d,e,ixy,a>,<b,c,d,e,ixy,a> (6912 cycles)
  • lda - ld a,(nnnn) / ld (nnnn),a (44 cycles)
  • ldd1 - ldd<r> (1) (44 cycles)
  • ldd2 - ldd<r> (2) (44 cycles)
  • ldi1 - ldi<r> (1) (44 cycles)
  • ldi2 - ldi<r> (2) (44 cycles)
  • negop - neg (16,384 cycles)
  • rldop - <rld,rrd> (7168 cycles)
  • rot8080 - <rlca,rrca,rla,rra> (6144 cycles)
  • rotxy - shift/rotate (<ix,iy>+1) (416 cycles)
  • rotz80 - shift/rotate <b,c,d,e,h,l,(hl),a> (6784 cycles)
  • srz80 - <set,res> n,<b,c,d,e,h,l,(hl),a> (7936 cycles)
  • srzx - <set,res> n,(<ix,iy>+1) (1792 cycles)
  • st8ix1 - ld (<ix,iy>+1),<b,c,d,e> (1024 cycles)
  • st8ix2 - ld (<ix,iy>+1),<h,l> (256 cycles)
  • st8ix3 - ld (<ix,iy>+1),a (64 cycles)
  • stabd - ld (<bc,de>),a (96 cycles)

References

Documentation

Overview

Package z80 emulates Zilog's Z80 CPU.

Index

Constants

This section is empty.

Variables

View Source
var ErrBreakPoint = errors.New("break point reached")

ErrBreakPoint shows PC is reached to one of break points.

Functions

This section is empty.

Types

type CPU

type CPU struct {
	States

	Memory Memory
	IO     IO
	INT    INT
	NMI    NMI
	IMon   InterruptMonitor

	Debug       bool
	BreakPoints map[uint16]struct{}

	LastOpCycles int
}

CPU is Z80 emulator.

func Build

func Build(options ...Option) *CPU

Build builds a Z80 CPU emulator with given options.

func (*CPU) Run

func (cpu *CPU) Run(ctx context.Context) error

Run executes instructions till HALT or error.

func (*CPU) Step

func (cpu *CPU) Step()

Step executes an instruction.

type DumbIO

type DumbIO []uint8

DumbIO provides IO interface as wrapper of []uint8

func (DumbIO) In

func (dio DumbIO) In(addr uint8) uint8

In gets a byte at addr of IO

func (DumbIO) Out

func (dio DumbIO) Out(addr uint8, value uint8)

Out sets a byte at addr of IO

type DumbMemory

type DumbMemory []uint8

DumbMemory provides Memory interface as wrapper of []uint8

func (DumbMemory) Get

func (dm DumbMemory) Get(addr uint16) uint8

Get gets a byte at addr of memory.

func (DumbMemory) Put

func (dm DumbMemory) Put(addr uint16, data ...uint8) DumbMemory

Put puts "data" block from addr.

func (DumbMemory) Set

func (dm DumbMemory) Set(addr uint16, value uint8)

Set sets a byte at addr of memory.

type GPR

type GPR struct {
	AF Register
	BC Register
	DE Register
	HL Register
}

GPR is general purpose reigsters, pair of four registers AF, BC, DE and HL.

type INT

type INT interface {
	// CheckINT should return valid interruption data if maskable interruption
	// made. The data is used for interruption codes or as a vector depending
	// on interruption mode.
	CheckINT() []uint8

	// ReturnINT is called when "RETI" op is executed.
	ReturnINT()
}

INT is interface for maskable interrupt.

type IO

type IO interface {
	In(addr uint8) uint8
	Out(addr uint8, value uint8)
}

IO is requirements interface for I/O.

type InterruptMonitor

type InterruptMonitor interface {
	OnInterrupt(maskable bool, oldPC, newPC uint16)
}

InterruptMonitor monitors interruptions.

type MapMemory

type MapMemory map[uint16]uint8

MapMemory implements Memory interface with a map.

func (MapMemory) Clear

func (mm MapMemory) Clear()

Clear removes all.

func (MapMemory) Clone

func (mm MapMemory) Clone() MapMemory

Clone creates a clone of this.

func (MapMemory) Equal

func (mm MapMemory) Equal(a0 interface{}) bool

Equal checks two MapMemory same or not.

func (MapMemory) Get

func (mm MapMemory) Get(addr uint16) uint8

Get gets a byte at addr of memory.

func (MapMemory) Put

func (mm MapMemory) Put(addr uint16, data ...uint8) MapMemory

Put puts "data" block from addr.

func (MapMemory) Set

func (mm MapMemory) Set(addr uint16, v uint8)

Set sets a byte at addr of memory.

type Memory

type Memory interface {
	Get(addr uint16) uint8
	Set(addr uint16, value uint8)
}

Memory is requirements interface for memory.

type NMI

type NMI interface {
	// CheckNMI should return true if non-maskable interruption made.
	CheckNMI() bool
}

NMI is interruption for non-maskable interrupt.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is an optional element for Build.

func WithINT

func WithINT(v INT) Option

WithINT is an option to setup with INT.

func WithIO

func WithIO(v IO) Option

WithIO is an option to setup with IO.

func WithInterruptMonitor

func WithInterruptMonitor(v InterruptMonitor) Option

WithInterruptMonitor is an option to setup with InterruptMonitor.

func WithMemory

func WithMemory(v Memory) Option

WithMemory is an option to setup with Memory.

func WithNMI

func WithNMI(v NMI) Option

WithNMI is an option to setup with NMI.

type Register

type Register struct {
	Hi uint8
	Lo uint8
}

Register is 16 bits register.

func (*Register) SetU16

func (r *Register) SetU16(v uint16)

SetU16 updates 16 bits value of this register.

func (Register) U16

func (r Register) U16() uint16

U16 gets 16 bits value of this register.

type SPR

type SPR struct {
	IR Register
	IX uint16
	IY uint16
	SP uint16
	PC uint16
}

SPR is special purpose registers.

type States

type States struct {
	GPR
	SPR

	Alternate GPR

	IFF1 bool
	IFF2 bool
	IM   int

	HALT  bool
	InNMI bool
}

States is collection of Z80's internal state.

Directories

Path Synopsis
cmd
internal
tinycpm
Package tinycpm provides minimal CP/M compatible BIOS to run Z80 Exerciser tests.
Package tinycpm provides minimal CP/M compatible BIOS to run Z80 Exerciser tests.
zex
Package zex provides test cases of Z80 Exerciser.
Package zex provides test cases of Z80 Exerciser.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL