cpu

package
v0.0.0-...-86b10a5 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2022 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Load/Store Operations
	LDA mnemonic
	LDX
	LDY
	STA
	STX
	STY
	// Register Operations
	TAX
	TSX
	TAY
	TXA
	TXS
	TYA
	// Stack instructions
	PHA
	PHP
	PLA
	PLP
	// Logical instructions
	AND
	EOR
	ORA
	BIT
	// Arithmetic instructions
	ADC
	SBC
	CMP
	CPX
	CPY
	// Increment/Decrement instructions
	INC
	INX
	INY
	DEC
	DEX
	DEY
	// Shift instructions
	ASL
	LSR
	ROL
	ROR
	// Jump instructions
	JMP
	JSR
	RTS
	RTI
	// Branch instructions
	BCC
	BCS
	BEQ
	BMI
	BNE
	BPL
	BVC
	BVS
	// Flag control instructions
	CLC
	CLD
	CLI
	CLV
	SEC
	SED
	SEI
	// Misc
	BRK
	NOP
	// Unofficial
	LAX
	SAX
	DCP
	ISB
	SLO
	RLA
	SRE
	RRA
)

Variables

This section is empty.

Functions

func Decode

func Decode(opcode uint8) instruction

Types

type Bus

type Bus interface {
	// ReadCPU read a byte by CPU.
	//
	// A location pointed of address may be one of NES component or other RAM/ROM.
	ReadCPU(addr uint16) uint8

	// WriteCPU write a byte from any component by CPU.
	//
	// A location pointed of address may be one of NES component or other RAM/ROM.
	WriteCPU(addr uint16, value uint8)
}

Bus is the abstraction of memory access seen from CPU emulator.

This interface provides a strategy of memory access to target.

type CPU

type CPU struct {

	// Accumulator, Index X/Y register
	A, X, Y uint8
	// Stack pointer
	S uint8
	// Status register
	P Status
	// Program counter
	PC uint16

	// clock cycle
	Cycles uint64
	// contains filtered or unexported fields
}

CPU emulates CPU behaviors

func New

func New(t Ticker, m Bus) *CPU

New returns new CPU emulator

func (*CPU) PowerOn

func (c *CPU) PowerOn()

PowerOn initializes CPU state on power

func (*CPU) Reset

func (c *CPU) Reset()

func (*CPU) Step

func (c *CPU) Step(intr *Interrupt)

Step emulates 1 CPU step.

func (*CPU) Trace

func (e *CPU) Trace() Trace

Trace current CPU state and return snapshot

type Interrupt

type Interrupt uint8

Interrupt Kinds of CPU interrupts

const (
	NoInterrupt Interrupt = iota
	NMI
	IRQ
)

currently supports NMI and IRQ only

type Status

type Status [6]bool

Status represents CPU Status by flags

func NewStatus

func NewStatus(b uint8) Status

func (*Status) Set

func (s *Status) Set(b uint8)

type Ticker

type Ticker interface {
	// Tick handles events on CPU ticks.
	Tick()
}

Ticker is the event handler on CPU ticks.

type Trace

type Trace struct {
	A, X, Y uint8
	S       uint8
	P       Status
	PC      uint16

	Cycles uint64

	Opcode   uint8
	Operand1 uint8
	Operand2 uint8

	Mnemonic       mnemonic
	AddressingMode addressingMode
}

Trace is a snapshot of CPU state

func (Trace) String

func (t Trace) String() string

Jump to

Keyboard shortcuts

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