cpu

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Carry = 1 << iota
	Zero
	InterruptDisable
	Decimal
	Break
	Unused
	Overflow
	Negative
)
View Source
const StackAddr = 0x100

StackAddr is the memory address of the stack

Variables

View Source
var ErrUnsupportedOpcode = errors.New("unsupported opcode")

ErrUnsupportedOpcode indicates an unsupported opcode was evaluated.

Functions

This section is empty.

Types

type AddressingMode

type AddressingMode uint8

AddressingMode defines opcode addressing modes.

See 6502 Addressing Mode.

const (
	Implicit AddressingMode = iota
	Accumulator
	Immediate
	ZeroPage
	ZeroPageX
	ZeroPageY
	Relative
	Absolute
	AbsoluteX
	AbsoluteY
	Indirect
	IndirectX
	IndirectY
)

func (AddressingMode) String

func (i AddressingMode) String() string

type CPU

type CPU struct {
	// ProgramCounter Program Counter
	ProgramCounter uint16

	// StackPointer Stack Pointer
	StackPointer byte

	// Status Processor Status
	Status Status

	// Accumulator Register A
	Accumulator byte

	// RegisterX Register X
	RegisterX byte

	// RegisterY Register Y
	RegisterY byte

	Cycles uint

	NMIPending bool `msgpack:"alias:NmiPending"`
	IRQPending bool `msgpack:"alias:IrqPending"`

	Stall uint16

	StepErr error `msgpack:"-"`
	// contains filtered or unexported fields
}

CPU implements the NES CPU.

See 6502 Guide.

func New

func New(b memory.ReadSafeWrite) *CPU

func (*CPU) AddNMI

func (c *CPU) AddNMI()

func (*CPU) AddStall

func (c *CPU) AddStall(stall uint16)

func (*CPU) GetCycles

func (c *CPU) GetCycles() uint

func (*CPU) ReadMem

func (c *CPU) ReadMem(addr uint16) byte

ReadMem reads byte from memory.

func (*CPU) ReadMem16

func (c *CPU) ReadMem16(addr uint16) uint16

ReadMem16 reads two bytes from memory.

func (*CPU) ReadMem16Bug

func (c *CPU) ReadMem16Bug(addr uint16) uint16

ReadMem16Bug reads two bytes from memory, emulating a 6502 bug.

JMP ($xxyy), or JMP indirect, does not advance pages if the lower eight bits of the specified address is $FF; the upper eight bits are fetched from $xx00, 255 bytes earlier, instead of the expected following byte.

See [JMP Instruction Reference] and [NESdev CPU Errata].

[JMP Instruction Reference]: https://www.nesdev.org/obelisk-6502-guide/reference.html#JMP [NESDev CPU Errata]:https://www.nesdev.org/wiki/Errata#CPU

func (*CPU) Reset

func (c *CPU) Reset()

Reset resets the CPU and sets ProgramCounter to the value of the [Reset] Vector.

func (*CPU) Step

func (c *CPU) Step() uint

Step steps through the next instruction

func (*CPU) Trace

func (c *CPU) Trace() string

func (*CPU) WriteMem

func (c *CPU) WriteMem(addr uint16, data byte)

WriteMem writes byte to memory.

func (*CPU) WriteMem16

func (c *CPU) WriteMem16(addr uint16, data uint16)

WriteMem16 writes two bytes to memory.

type Instruction

type Instruction func(c *CPU, mode AddressingMode)

type InstructionName added in v0.1.0

type InstructionName uint8
const (
	BRK InstructionName = iota
	ORA
	SLO
	NOP
	ASL
	PHP
	ANC
	BPL
	CLC
	JSR
	AND
	RLA
	BIT
	ROL
	PLP
	BMI
	SEC
	RTI
	EOR
	SRE
	LSR
	PHA
	ALR
	JMP
	BVC
	CLI
	RTS
	ADC
	RRA
	ROR
	PLA
	ARR
	BVS
	SEI
	STA
	SAX
	STY
	STX
	DEY
	TXA
	XAA
	BCC
	AHX
	TYA
	TXS
	TAS
	SHY
	SHX
	LDY
	LDA
	LDX
	LAX
	TAY
	TAX
	LXA
	BCS
	CLV
	TSX
	LAS
	CPY
	CMP
	DCP
	DEC
	INY
	DEX
	AXS
	BNE
	CLD
	CPX
	SBC
	ISB
	INC
	INX
	BEQ
	SED
)

func (InstructionName) String added in v0.1.0

func (i InstructionName) String() string

type OpCode

type OpCode struct {
	Name         InstructionName
	Len          uint8
	Cycles       uint8
	Mode         AddressingMode
	Exec         Instruction
	Undocumented bool
}

OpCode defines an opcode and its parameters.

See 6502 Instruction Reference.

func (*OpCode) Code

func (o *OpCode) Code() int

func (*OpCode) String

func (o *OpCode) String() string

type Status

type Status struct {
	Carry            bool
	Zero             bool
	InterruptDisable bool
	Decimal          bool
	Break            bool
	Overflow         bool
	Negative         bool
}

func (*Status) Get

func (s *Status) Get() byte

func (*Status) Set

func (s *Status) Set(data byte)

Jump to

Keyboard shortcuts

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