z80

package
v0.0.0-...-4374a33 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2020 License: MIT, MIT Imports: 1 Imported by: 0

Documentation

Overview

The z80 package implements a Zilog Z80 emulator.

Index

Constants

View Source
const FLAG_3 = 0x08
View Source
const FLAG_5 = 0x20
View Source
const FLAG_C = 0x01

The flags

View Source
const FLAG_H = 0x10
View Source
const FLAG_N = 0x02
View Source
const FLAG_P = 0x04
View Source
const FLAG_S = 0x80
View Source
const FLAG_V = FLAG_P
View Source
const FLAG_Z = 0x40
View Source
const SHIFT_0xCB = 256
View Source
const SHIFT_0xDD = 768
View Source
const SHIFT_0xDDCB = 1024
View Source
const SHIFT_0xED = 512
View Source
const SHIFT_0xFD = 1280
View Source
const SHIFT_0xFDCB = 1024

Variables

View Source
var (
	OpcodesMap    [1536]func(z80 *Z80)
	OpcodesDisMap [1536]func(memory MemoryReader, address uint16, shift int) (string, uint16, int)
)

Functions

This section is empty.

Types

type MemoryAccessor

type MemoryAccessor interface {
	// ReadByte reads a byte from address taking into account
	// contention.
	ReadByte(address uint16) byte

	// ReadByteInternal reads a byte from address without taking
	// into account contention.
	ReadByteInternal(address uint16) byte

	// WriteByte writes a byte at address taking into account
	// contention.
	WriteByte(address uint16, value byte)

	// WriteByteInternal writes a byte at address without taking
	// into account contention.
	WriteByteInternal(address uint16, value byte)

	// ContendRead increments the Tstates counter by time as a
	// result of a memory read at the given address.
	ContendRead(address uint16, time int)

	ContendReadNoMreq(address uint16, time int)
	ContendReadNoMreq_loop(address uint16, time int, count uint)

	ContendWriteNoMreq(address uint16, time int)
	ContendWriteNoMreq_loop(address uint16, time int, count uint)

	Read(address uint16) byte
	Write(address uint16, value byte, protectROM bool)

	// Data returns the memory content.
	Data() []byte
}

MemoryAccessor is an interface to access memory addressed by the Z80. It defines four read/write method for accessing memory, taking into account contention when needed. In systems where memory contention is not an issue ReadByte and WriteByte should simply call ReadByteInternal and WriteByteInternal.

type MemoryReader

type MemoryReader interface {
	ReadByte(address uint16) byte
}

MemoryReader is a simple interface that defines only a ReadByte method. It's used mainly by the disassembler.

type NextRegisterAccessor

type NextRegisterAccessor interface {
	ReadRegister(reg uint8) byte
	WriteRegister(reg uint8, b byte)
}

NextRegisterAccessor provides an interface to read and write ZX spectrum next hardware registers.

type PortAccessor

type PortAccessor interface {
	ReadPort(address uint16) byte
	WritePort(address uint16, b byte)
	ReadPortInternal(address uint16, contend bool) byte
	WritePortInternal(address uint16, b byte, contend bool)
	ContendPortPreio(address uint16)
	ContendPortPostio(address uint16)
}

type Z80

type Z80 struct {
	A, F, B, C, D, E, H, L         byte
	A_, F_, B_, C_, D_, E_, H_, L_ byte
	IXH, IXL, IYH, IYL             byte
	I, IFF1, IFF2, IM              byte

	// The highest bit (bit 7) of the R register
	R7 byte

	// The low 7 bits of the R register. 16 bits long so it can
	// also act as an RZX instruction counter.
	R uint16

	EventNextEvent int

	// Number of tstates since the beginning of the last frame.
	// The value of this variable is usually smaller than TStatesPerFrame,
	// but in some unlikely circumstances it may be >= than that.
	Tstates int

	Halted bool
	// contains filtered or unexported fields
}

func NewZ80

func NewZ80(memory MemoryAccessor, ports PortAccessor, registers NextRegisterAccessor) *Z80

NewZ80 creates a new Z80 instance.

func (*Z80) BC

func (z80 *Z80) BC() uint16

func (*Z80) BC_

func (z80 *Z80) BC_() uint16

func (*Z80) DE

func (z80 *Z80) DE() uint16

func (*Z80) DE_

func (z80 *Z80) DE_() uint16

func (*Z80) DecBC

func (z80 *Z80) DecBC()

func (*Z80) DecBC_

func (z80 *Z80) DecBC_()

func (*Z80) DecDE

func (z80 *Z80) DecDE()

func (*Z80) DecDE_

func (z80 *Z80) DecDE_()

func (*Z80) DecHL

func (z80 *Z80) DecHL()

func (*Z80) DecHL_

func (z80 *Z80) DecHL_()

func (*Z80) DecIX

func (z80 *Z80) DecIX()

func (*Z80) DecIY

func (z80 *Z80) DecIY()

func (*Z80) DecPC

func (z80 *Z80) DecPC(value uint16)

IncPC decrements the program counter.

func (*Z80) DecSP

func (z80 *Z80) DecSP()

DecSP decrements the SP register.

func (*Z80) DoOpcode

func (z80 *Z80) DoOpcode()

Execute a single instruction at the program counter.

func (*Z80) HL

func (z80 *Z80) HL() uint16

func (*Z80) HL_

func (z80 *Z80) HL_() uint16

func (*Z80) IR

func (z80 *Z80) IR() uint16

IR returns the IR register.

func (*Z80) IX

func (z80 *Z80) IX() uint16

func (*Z80) IY

func (z80 *Z80) IY() uint16

func (*Z80) IncBC

func (z80 *Z80) IncBC()

func (*Z80) IncBC_

func (z80 *Z80) IncBC_()

func (*Z80) IncDE

func (z80 *Z80) IncDE()

func (*Z80) IncDE_

func (z80 *Z80) IncDE_()

func (*Z80) IncHL

func (z80 *Z80) IncHL()

func (*Z80) IncHL_

func (z80 *Z80) IncHL_()

func (*Z80) IncIX

func (z80 *Z80) IncIX()

func (*Z80) IncIY

func (z80 *Z80) IncIY()

func (*Z80) IncPC

func (z80 *Z80) IncPC(value uint16)

IncPC increments the program counter.

func (*Z80) IncSP

func (z80 *Z80) IncSP()

IncSP increments the SP register.

func (*Z80) Interrupt

func (z80 *Z80) Interrupt()

Interrupt process a Z80 maskable interrupt

func (*Z80) NonMaskableInterrupt

func (z80 *Z80) NonMaskableInterrupt()

Process a Z80 non-maskable interrupt.

func (*Z80) PC

func (z80 *Z80) PC() uint16

PC returns the program counter.

func (*Z80) Reset

func (z80 *Z80) Reset()

Reset resets the Z80.

func (*Z80) SP

func (z80 *Z80) SP() uint16

SP returns the SP register.

func (*Z80) SetBC

func (z80 *Z80) SetBC(value uint16)

func (*Z80) SetBC_

func (z80 *Z80) SetBC_(value uint16)

func (*Z80) SetDE

func (z80 *Z80) SetDE(value uint16)

func (*Z80) SetDE_

func (z80 *Z80) SetDE_(value uint16)

func (*Z80) SetHL

func (z80 *Z80) SetHL(value uint16)

func (*Z80) SetHL_

func (z80 *Z80) SetHL_(value uint16)

func (*Z80) SetIX

func (z80 *Z80) SetIX(value uint16)

func (*Z80) SetIY

func (z80 *Z80) SetIY(value uint16)

func (*Z80) SetPC

func (z80 *Z80) SetPC(value uint16)

SetPC sets the program counter.

func (*Z80) SetSP

func (z80 *Z80) SetSP(value uint16)

SetSP sets the SP register.

Jump to

Keyboard shortcuts

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