go8080

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2020 License: MIT Imports: 2 Imported by: 0

README

Go 8080 GoDoc License Go Report Card

An Intel 8080 emulator implemented in Go

Resources that made this possible:

Usage

Using this package as part of a machine emulation project is very simple. You only need to pass in a single dependency, which is the memory that the CPU will interact with.

c := cpu.NewIntel8080(mem)

Your memory dependency must implement the MemReadWriter interface.

See the GoDoc for more information on the other options you can pass when instantiating the CPU.

Testing

This package is configured to run a number of test ROMs that exercise the full suite of 8080 functionality. These tests are taken from Altair Clone.

In order to run the tests you must first download the test roms:

$ go generate testdata/generate.go

You can then run the tests like so:

$ go test

*******************
8080 Preliminary tests complete
*******************

*******************
MICROCOSM ASSOCIATES 8080/8085 CPU DIAGNOSTIC
 VERSION 1.0  (C) 1980

 CPU IS OPERATIONAL
*******************

*******************

DIAGNOSTICS II V1.2 - CPU TEST
COPYRIGHT (C) 1981 - SUPERSOFT ASSOCIATES

ABCDEFGHIJKLMNOPQRSTUVWXYZ
CPU IS 8080/8085
BEGIN TIMING TEST
END TIMING TEST
CPU TESTS OK

*******************

*******************
8080 instruction exerciser
dad <b,d,h,sp>................  PASS! crc is:14474ba6
aluop nn......................  PASS! crc is:9e922f9e
aluop <b,c,d,e,h,l,m,a>.......  PASS! crc is:cf762c86
<daa,cma,stc,cmc>.............  PASS! crc is:bb3f030c
<inr,dcr> a...................  PASS! crc is:adb6460e
<inr,dcr> b...................  PASS! crc is:83ed1345
<inx,dcx> b...................  PASS! crc is:f79287cd
<inr,dcr> c...................  PASS! crc is:e5f6721b
<inr,dcr> d...................  PASS! crc is:15b5579a
<inx,dcx> d...................  PASS! crc is:7f4e2501
<inr,dcr> e...................  PASS! crc is:cf2ab396
<inr,dcr> h...................  PASS! crc is:12b2952c
<inx,dcx> h...................  PASS! crc is:9f2b23c0
<inr,dcr> l...................  PASS! crc is:ff57d356
<inr,dcr> m...................  PASS! crc is:92e963bd
<inx,dcx> sp..................  PASS! crc is:d5702fab
lhld nnnn.....................  PASS! crc is:a9c3d5cb
shld nnnn.....................  PASS! crc is:e8864f26
lxi <b,d,h,sp>,nnnn...........  PASS! crc is:fcf46e12
ldax <b,d>....................  PASS! crc is:2b821d5f
mvi <b,c,d,e,h,l,m,a>,nn......  PASS! crc is:eaa72044
mov <bcdehla>,<bcdehla>.......  PASS! crc is:10b58cee
sta nnnn / lda nnnn...........  PASS! crc is:ed57af72
<rlc,rrc,ral,rar>.............  PASS! crc is:e0d89235
stax <b,d>....................  PASS! crc is:2b0471e9
Tests complete
*******************
PASS

Documentation

Index

Constants

View Source
const (
	// Define the named working registers.
	B = iota
	C
	D
	E
	H
	L

	A
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Intel8080

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

Intel8080 represents the Intel 8080 CPU.

func NewIntel8080

func NewIntel8080(mem MemReadWriter, opts ...Option) *Intel8080

NewIntel8080 returns an instantiated Intel 8080.

func (*Intel8080) Accumulator

func (i *Intel8080) Accumulator() byte

Accumulator returns the current state of the accumulator.

func (*Intel8080) Cycles

func (i *Intel8080) Cycles() uint32

Cycles returns the current cycle count.

func (*Intel8080) Interrupt

func (i *Intel8080) Interrupt(addr uint16)

Interrupt sets the interrupt address which will be handled on the next step.

func (*Intel8080) Running

func (i *Intel8080) Running() bool

Running returns true if the CPU is running.

func (*Intel8080) Step

func (i *Intel8080) Step() error

Step emulates exactly one instruction on the Intel 8080.

type MemReadWriter

type MemReadWriter interface {
	MemReader
	MemWriter
}

MemReadWriter is the interface that groups the basic Read and Write methods.

type MemReader

type MemReader interface {
	Read(addr uint16) byte
	ReadAll() []byte
}

MemReader is the interface that wraps the basic Read and ReadAll methods.

Read returns the value from memory at the given address.

ReadAll returns the full memory contents.

type MemWriter

type MemWriter interface {
	Write(addr uint16, v byte)
}

MemWriter is the interface that wraps the basic Write method.

Write writes the value v into memory at the given address.

type Option

type Option func(*Intel8080)

Option is a functional option that modifies a field on the CPU.

func WithDebugEnabled

func WithDebugEnabled() Option

WithDebugEnabled enables debug mode on the machine.

func WithInput

func WithInput(input ifn) Option

WithInput sets input as the input handler function.

func WithOutput

func WithOutput(output ofn) Option

WithOutput sets output as the output handler function.

Jump to

Keyboard shortcuts

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