zog

package module
v0.0.0-...-1e1738a Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: MIT Imports: 14 Imported by: 0

README

zog

Z80 diassembler/assembler/emulator in golang

Update: Sat 28 Oct 11:38:39 BST 2017

So the cpu core passes zexdoc and has a quick and dirty pass for timing correct T-states. Similarly quick and dirty Spectrum screen and keyboard support and 'z80' file format support are sufficient to:

  1. boot the original spectrum 48K ROM to basic and run the Most Important Program:

    10 PRINT "HELLO"

    20 GOTO 10

  2. Load and run Manic Miner and Jetpac at what seem to be the correct speed.

  3. Fail to run Elite, perhaps due to lacking interrupt mode support.

I think I'm unlikely to take it any further, since the world doesn't need another spectrum emulator. However, this was a lot of fun and both rewarding and challenging. I'd obviously do things quite a lot differently if I did it again, but learning is kind of the point.

If by any chance you are here looking for a spectrum emulator, you will find better ones elsewhere. If you are looking for how to code an emulator, you will almost certainly find better code elsewhere. But if you are writing your own and want to share thoughts, please let me know :-)


Z80 diassembler/assembler/emulator in golang

Just revisiting the first bit of serious programming I ever did - a Z80 disassembler.

This code currently (June 2017) implements all the instruction decode logic and has a String() representation for instructions. There is also a basic assembler (using the github.com/pointlander/peg parser), so that the emulator tests can be written in assembly rather than machine code. This gives us bytes -> string -> bytes conversions.

I had ambitions of wiring an assembler which could parse the zexall code as a test suite, but a macro assembler is a bigger undertaking than I'd like to get into prior to actually having an emulator.

Instead, the zmac assembler can be used to build zexall and next steps are actually to write the emulator.

Documentation

Index

Constants

View Source
const (
	Immediate = 2

	BCDEContents      = 5
	ImmediateContents = 6
)
View Source
const (
	F_C flag = iota
	F_N
	F_PV
	F_3
	F_H
	F_5
	F_Z
	F_S
)
View Source
const HL_RP_INDEX = 2

Variables

View Source
var EDSimpleNames []edSimpleName = []edSimpleName{
	{NEG, "NEG"},
	{RETN, "RETN"},
	{RETI, "RETI"},
	{RRD, "RRD"},
	{RLD, "RLD"},
	{IM0, "IM 0"},
	{IM1, "IM 1"},
	{IM2, "IM 2"},

	{LDI, "LDI"},
	{CPI, "CPI"},
	{LDD, "LDD"},
	{CPD, "CPD"},
	{LDIR, "LDIR"},
	{CPIR, "CPIR"},
	{LDDR, "LDDR"},
	{CPDR, "CPDR"},

	{INI, "INI"},
	{OUTI, "OUTI"},
	{IND, "IND"},
	{OUTD, "OUTD"},
	{INIR, "INIR"},
	{OTIR, "OTIR"},
	{INDR, "INDR"},
	{OTDR, "OTDR"},
}
View Source
var ErrHalted = errors.New("HALT called")
View Source
var R16Names []r16name = []r16name{
	{AF, "AF"},
	{AF_PRIME, "AF'"},
	{BC, "BC"},
	{DE, "DE"},
	{HL, "HL"},
	{IX, "IX"},
	{IY, "IY"},
	{SP, "SP"},
}
View Source
var R8Names []r8name = []r8name{
	{A, "A"},
	{F, "F"},

	{B, "B"},
	{C, "C"},

	{D, "D"},
	{E, "E"},

	{H, "H"},
	{L, "L"},

	{IXL, "IXL"},
	{IXH, "IXH"},
	{IYL, "IYL"},
	{IYH, "IYH"},

	{I, "I"},
	{R, "R"},
}

Functions

func Decode

func Decode(r io.Reader) (chan Instruction, chan error)

func Encode

func Encode(insts []Instruction) []byte

func NewAccum

func NewAccum(name string, l Loc8) *accum

func NewRot

func NewRot(name string, l Loc8, cpy Loc8) *rot

Types

type ADC16

type ADC16 struct {
	InstBin16
}

func NewADC16

func NewADC16(dst, src Loc16) *ADC16

func (*ADC16) Encode

func (a *ADC16) Encode() []byte

func (*ADC16) Execute

func (a *ADC16) Execute(z *Zog) error

func (*ADC16) String

func (a *ADC16) String() string

func (*ADC16) TStates

func (a *ADC16) TStates(z *Zog) int

type ADD16

type ADD16 struct {
	InstBin16
}

func NewADD16

func NewADD16(dst, src Loc16) *ADD16

func (*ADD16) Encode

func (a *ADD16) Encode() []byte

func (*ADD16) Execute

func (a *ADD16) Execute(z *Zog) error

func (*ADD16) String

func (a *ADD16) String() string

func (*ADD16) TStates

func (a *ADD16) TStates(z *Zog) int

type AccumInfo

type AccumInfo struct {
	// contains filtered or unexported fields
}

type Assembly

type Assembly struct {
	BaseAddr uint16
	Linsts   []LabelledInstruction
	Labels   map[string]int
	// contains filtered or unexported fields
}

func Assemble

func Assemble(s string) (*Assembly, error)

func (*Assembly) Encode

func (a *Assembly) Encode() ([]byte, error)

func (*Assembly) FindLabelAddr

func (a *Assembly) FindLabelAddr(name string) (uint16, error)

func (*Assembly) Init

func (a *Assembly) Init()

func (*Assembly) Instructions

func (a *Assembly) Instructions() []Instruction

func (*Assembly) ResolveAddresses

func (a *Assembly) ResolveAddresses() error

func (*Assembly) ResolveLoc16

func (a *Assembly) ResolveLoc16(l Loc16) error

func (*Assembly) ResolveLoc8

func (a *Assembly) ResolveLoc8(l Loc8) error

func (*Assembly) String

func (a *Assembly) String() string

type BIT

type BIT struct {
	InstU8
	// contains filtered or unexported fields
}

func NewBIT

func NewBIT(num byte, l Loc8) *BIT

func (*BIT) Encode

func (b *BIT) Encode() []byte

func (*BIT) Execute

func (b *BIT) Execute(z *Zog) error

func (*BIT) String

func (b *BIT) String() string

func (*BIT) TStates

func (b *BIT) TStates(z *Zog) int

type CALL

type CALL struct {
	InstU16
	// contains filtered or unexported fields
}

func NewCALL

func NewCALL(c Conditional, l Loc16) *CALL

func (*CALL) Encode

func (c *CALL) Encode() []byte

func (*CALL) Execute

func (c *CALL) Execute(z *Zog) error

func (*CALL) String

func (c *CALL) String() string

func (*CALL) TStates

func (c *CALL) TStates(z *Zog) int

type Conditional

type Conditional interface {
	String() string
	IsTrue(z *Zog) bool
}

type Contents

type Contents struct {
	// contains filtered or unexported fields
}

func (Contents) Read16

func (c Contents) Read16(z *Zog) (uint16, error)

func (Contents) Read8

func (c Contents) Read8(z *Zog) (byte, error)

func (Contents) String

func (c Contents) String() string

func (Contents) Write16

func (c Contents) Write16(z *Zog, nn uint16) error

func (Contents) Write8

func (c Contents) Write8(z *Zog, n byte) error

type Current

type Current struct {
	// contains filtered or unexported fields
}

func (*Current) Accum

func (c *Current) Accum(name string)

func (*Current) Adc16

func (c *Current) Adc16()

func (*Current) Add16

func (c *Current) Add16()

func (*Current) Bit

func (c *Current) Bit()

func (*Current) Call

func (c *Current) Call()

func (*Current) Conditional

func (c *Current) Conditional(cc Conditional)

func (*Current) Copy8

func (c *Current) Copy8()

func (*Current) Dec16

func (c *Current) Dec16()

func (*Current) Dec8

func (c *Current) Dec8()

func (*Current) DefByte

func (c *Current) DefByte()

func (*Current) DefSpace

func (c *Current) DefSpace()

func (*Current) DefWord

func (c *Current) DefWord()

func (*Current) Disp0xHex

func (c *Current) Disp0xHex(s string)

func (*Current) DispDecimal

func (c *Current) DispDecimal(s string)

func (*Current) DispHex

func (c *Current) DispHex(s string)

func (*Current) Djnz

func (c *Current) Djnz()

func (*Current) Dst16

func (c *Current) Dst16()

func (*Current) Dst8

func (c *Current) Dst8()

func (*Current) EDSimple

func (c *Current) EDSimple(name string)

func (*Current) Emit

func (c *Current) Emit()

func (*Current) Ex

func (c *Current) Ex()

func (*Current) GetAssembly

func (c *Current) GetAssembly() *Assembly

func (*Current) IR16Contents

func (c *Current) IR16Contents()

func (*Current) In

func (c *Current) In()

func (*Current) Inc16

func (c *Current) Inc16()

func (*Current) Inc8

func (c *Current) Inc8()

func (*Current) Init

func (c *Current) Init()

func (*Current) Jp

func (c *Current) Jp()

func (*Current) Jr

func (c *Current) Jr()

func (*Current) LD16

func (c *Current) LD16()

func (*Current) LD8

func (c *Current) LD8()

func (*Current) LabelDefn

func (c *Current) LabelDefn(label string)

func (*Current) Loc16

func (c *Current) Loc16()

func (*Current) Loc8

func (c *Current) Loc8()

func (*Current) NNContents

func (c *Current) NNContents()

func (*Current) NNLabel

func (c *Current) NNLabel(label string)

func (*Current) NNhex

func (c *Current) NNhex(s string)

func (*Current) Ndec

func (c *Current) Ndec(s string)

func (*Current) Nhex

func (c *Current) Nhex(s string)

func (*Current) ODigit

func (c *Current) ODigit(s string)

func (*Current) Org

func (c *Current) Org()

func (*Current) Out

func (c *Current) Out()

func (*Current) Pop

func (c *Current) Pop()

func (*Current) Push

func (c *Current) Push()

func (*Current) R16

func (c *Current) R16(s string)

func (*Current) R16Contents

func (c *Current) R16Contents()

func (*Current) R8

func (c *Current) R8(s string)

func (*Current) Res

func (c *Current) Res()

func (*Current) Ret

func (c *Current) Ret()

func (*Current) Rot

func (c *Current) Rot(name string)

func (*Current) Rst

func (c *Current) Rst()

func (*Current) Sbc16

func (c *Current) Sbc16()

func (*Current) Set

func (c *Current) Set()

func (*Current) Simple

func (c *Current) Simple(name string)

func (*Current) Src16

func (c *Current) Src16()

func (*Current) Src8

func (c *Current) Src8()

type DEC16

type DEC16 struct {
	InstU16
}

func NewDEC16

func NewDEC16(l Loc16) *DEC16

func (*DEC16) Encode

func (d *DEC16) Encode() []byte

func (*DEC16) Execute

func (d *DEC16) Execute(z *Zog) error

func (*DEC16) String

func (d *DEC16) String() string

func (*DEC16) TStates

func (d *DEC16) TStates(z *Zog) int

type DEC8

type DEC8 struct {
	InstU8
}

func NewDEC8

func NewDEC8(l Loc8) *DEC8

func (*DEC8) Encode

func (d *DEC8) Encode() []byte

func (*DEC8) Execute

func (d *DEC8) Execute(z *Zog) error

func (*DEC8) String

func (d *DEC8) String() string

func (*DEC8) TStates

func (d *DEC8) TStates(z *Zog) int

type DJNZ

type DJNZ struct {
	// contains filtered or unexported fields
}

func (*DJNZ) Encode

func (d *DJNZ) Encode() []byte

func (*DJNZ) Execute

func (d *DJNZ) Execute(z *Zog) error

func (*DJNZ) Resolve

func (d *DJNZ) Resolve(a *Assembly) error

func (*DJNZ) String

func (d *DJNZ) String() string

func (*DJNZ) TStates

func (d *DJNZ) TStates(z *Zog) int

type Data

type Data struct {
	// contains filtered or unexported fields
}

func NewData

func NewData(data []byte) *Data

func (*Data) Encode

func (d *Data) Encode() []byte

func (*Data) Execute

func (d *Data) Execute(z *Zog) error

func (*Data) Resolve

func (d *Data) Resolve(a *Assembly) error

func (*Data) String

func (d *Data) String() string

func (*Data) TStates

func (d *Data) TStates(z *Zog) int

type DecodeTable

type DecodeTable struct {
	// contains filtered or unexported fields
}

func NewDecodeTable

func NewDecodeTable(r io.Reader) *DecodeTable

func (*DecodeTable) LookupBLI

func (t *DecodeTable) LookupBLI(a, b byte) Instruction

func (*DecodeTable) LookupR

func (t *DecodeTable) LookupR(i byte) Loc8

func (*DecodeTable) LookupRP

func (t *DecodeTable) LookupRP(i byte) Loc16

func (*DecodeTable) LookupRP2

func (t *DecodeTable) LookupRP2(i byte) Loc16

func (*DecodeTable) ResetPrefix

func (t *DecodeTable) ResetPrefix(n byte)

type Disp

type Disp int8

func (Disp) String

func (d Disp) String() string

type EDSimple

type EDSimple byte
const (
	NEG  EDSimple = 0x44
	RETN EDSimple = 0x45
	RETI EDSimple = 0x4d

	RRD EDSimple = 0x67
	RLD EDSimple = 0x6f

	IM0 EDSimple = 0x46
	IM1 EDSimple = 0x56
	IM2 EDSimple = 0x5e

	LDI  EDSimple = 0xa0
	CPI  EDSimple = 0xa1
	LDD  EDSimple = 0xa8
	CPD  EDSimple = 0xa9
	LDIR EDSimple = 0xb0
	CPIR EDSimple = 0xb1
	LDDR EDSimple = 0xb8
	CPDR EDSimple = 0xb9

	INI  EDSimple = 0xa2
	OUTI EDSimple = 0xa3
	IND  EDSimple = 0xaa
	OUTD EDSimple = 0xab
	INIR EDSimple = 0xb2
	OTIR EDSimple = 0xb3
	INDR EDSimple = 0xba
	OTDR EDSimple = 0xbb
)

func LookupEDSimpleName

func LookupEDSimpleName(name string) EDSimple

func (EDSimple) Encode

func (s EDSimple) Encode() []byte

func (EDSimple) Execute

func (s EDSimple) Execute(z *Zog) error

func (EDSimple) Resolve

func (s EDSimple) Resolve(a *Assembly) error

func (EDSimple) String

func (s EDSimple) String() string

func (EDSimple) TStates

func (s EDSimple) TStates(z *Zog) int

type EX

type EX struct {
	InstBin16
}

func NewEX

func NewEX(dst, src Loc16) *EX

func (*EX) Encode

func (ex *EX) Encode() []byte

func (*EX) Execute

func (ex *EX) Execute(z *Zog) error

func (*EX) String

func (ex *EX) String() string

func (*EX) TStates

func (ex *EX) TStates(z *Zog) int

type FlagTest

type FlagTest int
const (
	FT_Z FlagTest = iota
	FT_C
	FT_PO
	FT_PE
	FT_P
	FT_M
)

func (FlagTest) IsTrue

func (ft FlagTest) IsTrue(z *Zog) bool

func (FlagTest) String

func (ft FlagTest) String() string

type IN

type IN struct {
	// contains filtered or unexported fields
}

func (*IN) Encode

func (i *IN) Encode() []byte

func (*IN) Execute

func (i *IN) Execute(z *Zog) error

func (*IN) Resolve

func (i *IN) Resolve(a *Assembly) error

func (*IN) String

func (i *IN) String() string

func (*IN) TStates

func (i *IN) TStates(z *Zog) int

type INC16

type INC16 struct {
	InstU16
}

func NewINC16

func NewINC16(l Loc16) *INC16

func (*INC16) Encode

func (i *INC16) Encode() []byte

func (*INC16) Execute

func (i *INC16) Execute(z *Zog) error

func (*INC16) String

func (i *INC16) String() string

func (*INC16) TStates

func (i *INC16) TStates(z *Zog) int

type INC8

type INC8 struct {
	InstU8
}

func NewINC8

func NewINC8(l Loc8) *INC8

func (*INC8) Encode

func (i *INC8) Encode() []byte

func (*INC8) Execute

func (i *INC8) Execute(z *Zog) error

func (*INC8) String

func (i *INC8) String() string

func (*INC8) TStates

func (i *INC8) TStates(z *Zog) int

type Imm16

type Imm16 uint16

func (Imm16) Read16

func (nn Imm16) Read16(z *Zog) (uint16, error)

func (Imm16) String

func (nn Imm16) String() string

func (Imm16) Write16

func (nn Imm16) Write16(z *Zog, n uint16) error

type Imm8

type Imm8 byte

func (Imm8) Read8

func (n Imm8) Read8(z *Zog) (byte, error)

func (Imm8) String

func (n Imm8) String() string

func (Imm8) Write8

func (n Imm8) Write8(z *Zog, tmp byte) error

type IndexedContents

type IndexedContents struct {
	// contains filtered or unexported fields
}

func (IndexedContents) Read16

func (ic IndexedContents) Read16(z *Zog) (uint16, error)

func (IndexedContents) Read8

func (ic IndexedContents) Read8(z *Zog) (byte, error)

func (IndexedContents) String

func (ic IndexedContents) String() string

func (IndexedContents) Write16

func (ic IndexedContents) Write16(z *Zog, nn uint16) error

func (IndexedContents) Write8

func (ic IndexedContents) Write8(z *Zog, n byte) error

type InstBin16

type InstBin16 struct {
	// contains filtered or unexported fields
}

func (*InstBin16) Resolve

func (i *InstBin16) Resolve(a *Assembly) error

type InstBin8

type InstBin8 struct {
	// contains filtered or unexported fields
}

func (*InstBin8) Resolve

func (i *InstBin8) Resolve(a *Assembly) error

type InstU16

type InstU16 struct {
	// contains filtered or unexported fields
}

func (*InstU16) Resolve

func (i *InstU16) Resolve(a *Assembly) error

type InstU8

type InstU8 struct {
	// contains filtered or unexported fields
}

func (*InstU8) Resolve

func (i *InstU8) Resolve(a *Assembly) error

type Instruction

type Instruction interface {
	String() string
	Encode() []byte
	Resolve(a *Assembly) error
	Execute(z *Zog) error
	TStates(z *Zog) int
}

func DecodeBytes

func DecodeBytes(buf []byte) ([]Instruction, error)

func DecodeOne

func DecodeOne(r io.Reader) (Instruction, error)

type InterruptState

type InterruptState struct {
	IFF1 bool
	IFF2 bool
	Mode byte
}

type JP

type JP struct {
	InstU16
	// contains filtered or unexported fields
}

func NewJP

func NewJP(c Conditional, l Loc16) *JP

func (*JP) Encode

func (jp *JP) Encode() []byte

func (*JP) Execute

func (jp *JP) Execute(z *Zog) error

func (*JP) String

func (jp *JP) String() string

func (*JP) TStates

func (jp *JP) TStates(z *Zog) int

type JR

type JR struct {
	// contains filtered or unexported fields
}

func (*JR) Encode

func (j *JR) Encode() []byte

func (*JR) Execute

func (j *JR) Execute(z *Zog) error

func (*JR) Resolve

func (j *JR) Resolve(a *Assembly) error

func (*JR) String

func (j *JR) String() string

func (*JR) TStates

func (j *JR) TStates(z *Zog) int

type LD16

type LD16 struct {
	InstBin16
}

func NewLD16

func NewLD16(dst, src Loc16) *LD16

func (*LD16) Encode

func (l *LD16) Encode() []byte

func (*LD16) Execute

func (l *LD16) Execute(z *Zog) error

func (*LD16) String

func (l *LD16) String() string

func (*LD16) TStates

func (i *LD16) TStates(z *Zog) int

type LD8

type LD8 struct {
	InstBin8
}

func NewLD8

func NewLD8(dst Loc8, src Loc8) *LD8

func (*LD8) Encode

func (l *LD8) Encode() []byte

func (*LD8) Execute

func (l *LD8) Execute(z *Zog) error

func (*LD8) String

func (l *LD8) String() string

func (*LD8) TStates

func (i *LD8) TStates(z *Zog) int

type Label

type Label struct {
	// Default to the zero value because we need to encode
	// this location *before* it is resolved with an address
	// so that we can calculate instruction length.
	// See assemble/ResolveAddr
	Imm16
	// contains filtered or unexported fields
}

func (Label) String

func (l Label) String() string

type LabelHolder

type LabelHolder struct{}

func (*LabelHolder) Encode

func (lh *LabelHolder) Encode() []byte

func (*LabelHolder) Execute

func (lh *LabelHolder) Execute(z *Zog) error

func (*LabelHolder) Resolve

func (lh *LabelHolder) Resolve(a *Assembly) error

func (*LabelHolder) String

func (lh *LabelHolder) String() string

func (*LabelHolder) TStates

func (lh *LabelHolder) TStates(z *Zog) int

type LabelledInstruction

type LabelledInstruction struct {
	Label string
	Inst  Instruction
	Addr  uint16
}

type Loc

type Loc interface {
	Read8(z *Zog) (byte, error)
	Write8(z *Zog, n byte) error
	Read16(z *Zog) (uint16, error)
	Write16(z *Zog, nn uint16) error
	String() string
}

(HL), (BC), (SP) could refer to a byte addr or a word addr

type Loc16

type Loc16 interface {
	Read16(z *Zog) (uint16, error)
	Write16(z *Zog, nn uint16) error
	String() string
}

type Loc8

type Loc8 interface {
	Read8(z *Zog) (byte, error)
	Write8(z *Zog, n byte) error
	String() string
}

type Machine

type Machine interface {
	LoadAddr() uint16
	RunAddr() uint16
	Name() string
	Start() error
	Stop()
}

type Memory

type Memory struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewMemory

func NewMemory(size uint16) *Memory

func (*Memory) Clear

func (m *Memory) Clear()

func (*Memory) Copy

func (m *Memory) Copy(addr uint16, buf []byte) error

func (*Memory) Len

func (m *Memory) Len() int

func (*Memory) Peek

func (m *Memory) Peek(addr uint16) (byte, error)

func (*Memory) Peek16

func (m *Memory) Peek16(addr uint16) (uint16, error)

func (*Memory) PeekBuf

func (m *Memory) PeekBuf(addr uint16, size int) ([]byte, error)

Fetch a chunk of memory. Error if overflows end. Don't write to this please.

func (*Memory) Poke

func (m *Memory) Poke(addr uint16, n byte) error

func (*Memory) Poke16

func (m *Memory) Poke16(addr uint16, nn uint16) error

func (*Memory) SetDebug

func (m *Memory) SetDebug(debug bool)

func (*Memory) SetWatchFunc

func (m *Memory) SetWatchFunc(wf func(uint16, byte, byte))

type Not

type Not struct {
	// contains filtered or unexported fields
}

func (Not) IsTrue

func (n Not) IsTrue(z *Zog) bool

func (Not) String

func (n Not) String() string

type OUT

type OUT struct {
	// contains filtered or unexported fields
}

func (*OUT) Encode

func (o *OUT) Encode() []byte

func (*OUT) Execute

func (o *OUT) Execute(z *Zog) error

func (*OUT) Resolve

func (o *OUT) Resolve(a *Assembly) error

func (*OUT) String

func (o *OUT) String() string

func (*OUT) TStates

func (o *OUT) TStates(z *Zog) int

type POP

type POP struct {
	InstU16
}

func NewPOP

func NewPOP(l Loc16) *POP

func (*POP) Encode

func (p *POP) Encode() []byte

func (*POP) Execute

func (p *POP) Execute(z *Zog) error

func (*POP) String

func (p *POP) String() string

func (*POP) TStates

func (p *POP) TStates(z *Zog) int

type PUSH

type PUSH struct {
	InstU16
}

func NewPUSH

func NewPUSH(l Loc16) *PUSH

func (*PUSH) Encode

func (p *PUSH) Encode() []byte

func (*PUSH) Execute

func (p *PUSH) Execute(z *Zog) error

func (*PUSH) String

func (p *PUSH) String() string

func (*PUSH) TStates

func (p *PUSH) TStates(z *Zog) int

type PegAssembler

type PegAssembler struct {
	Current

	Buffer string

	Pretty bool
	// contains filtered or unexported fields
}

func (*PegAssembler) AST

func (t *PegAssembler) AST() *node32

func (*PegAssembler) Add

func (t *PegAssembler) Add(rule pegRule, begin, end, index uint32)

func (*PegAssembler) Execute

func (p *PegAssembler) Execute()

func (*PegAssembler) Init

func (p *PegAssembler) Init()

func (*PegAssembler) Parse

func (p *PegAssembler) Parse(rule ...int) error

func (*PegAssembler) PrettyPrintSyntaxTree

func (t *PegAssembler) PrettyPrintSyntaxTree(buffer string)

func (*PegAssembler) Print

func (t *PegAssembler) Print()

func (*PegAssembler) PrintSyntaxTree

func (p *PegAssembler) PrintSyntaxTree()

func (*PegAssembler) Reset

func (p *PegAssembler) Reset()

func (*PegAssembler) Tokens

func (t *PegAssembler) Tokens() []token32

func (*PegAssembler) Trim

func (t *PegAssembler) Trim(length uint32)

type R16

type R16 int
const (
	AF R16 = iota
	BC
	DE
	HL
	IX
	IY
	SP
	PC
	AF_PRIME
	BC_PRIME
	DE_PRIME
	HL_PRIME
)

func LookupR16Name

func LookupR16Name(name string) R16

func (R16) Read16

func (r R16) Read16(z *Zog) (uint16, error)

func (R16) String

func (r R16) String() string

func (R16) Write16

func (r R16) Write16(z *Zog, nn uint16) error

type R8

type R8 int
const (
	A R8 = iota
	F
	B
	C
	D
	E
	H
	L
	IXL
	IXH
	IYL
	IYH
	I
	R
)

func LookupR8Name

func LookupR8Name(name string) R8

func (R8) Read8

func (r R8) Read8(z *Zog) (byte, error)

func (R8) String

func (r R8) String() string

func (R8) Write8

func (r R8) Write8(z *Zog, n byte) error

type RES

type RES struct {
	InstU8
	// contains filtered or unexported fields
}

func NewRES

func NewRES(num byte, l Loc8, cpy Loc8) *RES

func (*RES) Encode

func (r *RES) Encode() []byte

func (*RES) Execute

func (r *RES) Execute(z *Zog) error

func (*RES) String

func (r *RES) String() string

func (*RES) TStates

func (r *RES) TStates(z *Zog) int

type RET

type RET struct {
	// contains filtered or unexported fields
}

func (*RET) Encode

func (r *RET) Encode() []byte

func (*RET) Execute

func (r *RET) Execute(z *Zog) error

func (*RET) Resolve

func (r *RET) Resolve(a *Assembly) error

func (*RET) String

func (r *RET) String() string

func (*RET) TStates

func (r *RET) TStates(z *Zog) int

type RST

type RST struct {
	// contains filtered or unexported fields
}

func (*RST) Encode

func (r *RST) Encode() []byte

func (*RST) Execute

func (r *RST) Execute(z *Zog) error

func (*RST) Resolve

func (r *RST) Resolve(a *Assembly) error

func (*RST) String

func (r *RST) String() string

func (*RST) TStates

func (r *RST) TStates(z *Zog) int

type Region

type Region struct {
	// contains filtered or unexported fields
}

func NewRegion

func NewRegion(start, end uint16) Region

func (Region) String

func (r Region) String() string

type Regions

type Regions []Region

func ParseRegions

func ParseRegions(s string) (Regions, error)

func (Regions) String

func (rs Regions) String() string

type Registers

type Registers struct {
	A, F byte
	B, C byte
	D, E byte
	H, L byte

	IXH, IXL byte
	IYH, IYL byte

	I, R byte

	// Alternate register set
	A_PRIME, F_PRIME byte
	B_PRIME, C_PRIME byte
	D_PRIME, E_PRIME byte
	H_PRIME, L_PRIME byte

	SP uint16
	PC uint16
}

func (*Registers) Read16

func (r *Registers) Read16(l R16) uint16

func (*Registers) Read8

func (r *Registers) Read8(l R8) byte

func (Registers) String

func (r Registers) String() string

func (Registers) Summary

func (r Registers) Summary() string

func (*Registers) Write16

func (r *Registers) Write16(l R16, nn uint16)

func (*Registers) Write8

func (r *Registers) Write8(l R8, n byte)

type RotInfo

type RotInfo struct {
	// contains filtered or unexported fields
}

type SBC16

type SBC16 struct {
	InstBin16
}

func NewSBC16

func NewSBC16(dst, src Loc16) *SBC16

func (*SBC16) Encode

func (s *SBC16) Encode() []byte

func (*SBC16) Execute

func (s *SBC16) Execute(z *Zog) error

func (*SBC16) String

func (s *SBC16) String() string

func (*SBC16) TStates

func (s *SBC16) TStates(z *Zog) int

type SET

type SET struct {
	InstU8
	// contains filtered or unexported fields
}

func NewSET

func NewSET(num byte, l Loc8, cpy Loc8) *SET

func (*SET) Encode

func (s *SET) Encode() []byte

func (*SET) Execute

func (s *SET) Execute(z *Zog) error

func (*SET) String

func (s *SET) String() string

func (*SET) TStates

func (s *SET) TStates(z *Zog) int

type Simple

type Simple byte
const (
	NOP Simple = 0x00

	HALT Simple = 0x76

	RLCA Simple = 0x07
	RRCA Simple = 0x0f
	RLA  Simple = 0x17
	RRA  Simple = 0x1f
	DAA  Simple = 0x27
	CPL  Simple = 0x2f
	SCF  Simple = 0x37
	CCF  Simple = 0x3f

	EXX Simple = 0xd9

	DI Simple = 0xf3
	EI Simple = 0xfb
)

func LookupSimpleName

func LookupSimpleName(name string) Simple

func (Simple) Encode

func (s Simple) Encode() []byte

func (Simple) Execute

func (s Simple) Execute(z *Zog) error

func (Simple) Resolve

func (s Simple) Resolve(a *Assembly) error

func (Simple) String

func (s Simple) String() string

func (Simple) TStates

func (s Simple) TStates(z *Zog) int

type TrueLogicConstant

type TrueLogicConstant struct{}

func (TrueLogicConstant) IsTrue

func (l TrueLogicConstant) IsTrue(z *Zog) bool

func (TrueLogicConstant) String

func (l TrueLogicConstant) String() string

type Zog

type Zog struct {
	Mem *Memory
	// contains filtered or unexported fields
}

func New

func New(memSize uint16) *Zog

func (*Zog) Clear

func (z *Zog) Clear()

func (*Zog) DoInterrupt

func (z *Zog) DoInterrupt()

func (*Zog) FlagString

func (z *Zog) FlagString() string

func (*Zog) GetFlag

func (z *Zog) GetFlag(f flag) bool

func (*Zog) GetRegisters

func (z *Zog) GetRegisters() Registers

func (*Zog) InterruptEnabled

func (z *Zog) InterruptEnabled() bool

func (*Zog) Load

func (z *Zog) Load(a *Assembly) error

func (*Zog) LoadBytes

func (z *Zog) LoadBytes(addr uint16, buf []byte) error

func (*Zog) LoadFile

func (z *Zog) LoadFile(addr uint16, fname string, readonly bool) error

func (*Zog) LoadInterruptState

func (z *Zog) LoadInterruptState(is InterruptState)

func (*Zog) LoadROMFile

func (z *Zog) LoadROMFile(addr uint16, fname string) error

func (*Zog) LoadRegisters

func (z *Zog) LoadRegisters(reg Registers)

func (*Zog) Read

func (z *Zog) Read(buf []byte) (int, error)

Implement io.Reader

func (*Zog) RegisterInputHandler

func (z *Zog) RegisterInputHandler(handler func(uint16) byte) error

func (*Zog) RegisterOutputHandler

func (z *Zog) RegisterOutputHandler(addr uint16, handler func(n byte)) error

func (*Zog) Run

func (z *Zog) Run() (errRet error)

func (*Zog) RunAssembly

func (z *Zog) RunAssembly(a *Assembly) error

func (*Zog) RunBytes

func (z *Zog) RunBytes(loadAddr uint16, buf []byte, runAddr uint16) error

func (*Zog) SetFlag

func (z *Zog) SetFlag(f flag, new bool)

func (*Zog) State

func (z *Zog) State() string

func (*Zog) TraceOnHalt

func (z *Zog) TraceOnHalt(numHaltTraces int)

func (*Zog) TraceRegions

func (z *Zog) TraceRegions(regions Regions) error

func (*Zog) WatchRegions

func (z *Zog) WatchRegions(regions Regions) error

Directories

Path Synopsis
cmd
zog

Jump to

Keyboard shortcuts

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