z80

package
v0.0.0-...-47310a0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2023 License: GPL-2.0, MIT Imports: 1 Imported by: 0

README

Z80 - A Zilog Z80 emulator written in Go

This is a fork of github.com/remogatto/z80

It includes the MSX system specific timings for accurate emulation.

License

Copyright (c) 2013 Andrea Fazzi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

func Disassemble

func Disassemble(memory MemoryReader, address uint16, shift int) (string, uint16, int)

Disassemble disassembles a Z80 instruction at the given address. It returns the string containing the mnemonic form of the instruction plus arguments, the address of the next instruction, and the eventual shift opcode.

func PreviousInstruction

func PreviousInstruction(memory MemoryReader, address uint16) uint16

PreviousInstruction returns the address of the instruction prior to the one at the given address.

Types

type DebugInstruction

type DebugInstruction struct {
	Address  uint16
	Mnemonic string
}

func DisassembleN

func DisassembleN(memory MemoryReader, address uint16, n int) []DebugInstruction

DisassemleN disassembles n memory instructions starting from address.

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 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

	// Clock Cycles
	Cycles uint64
	// contains filtered or unexported fields
}

func NewZ80

func NewZ80(memory MemoryAccessor, ports PortAccessor) *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) RestoreState

func (z80 *Z80) RestoreState(backup *Z80)

func (*Z80) SP

func (z80 *Z80) SP() uint16

SP returns the SP register.

func (*Z80) SaveState

func (z80 *Z80) SaveState(backup *Z80)

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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