cpu

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Opcodes [256]Instruction
)

Functions

This section is empty.

Types

type AddrMode

type AddrMode uint8
const (
	AddrModeImp AddrMode = iota + 1
	AddrModeAcc
	AddrModeImm
	AddrModeZp
	AddrModeZpX
	AddrModeZpY
	AddrModeAbs
	AddrModeAbsX
	AddrModeAbsY
	AddrModeInd
	AddrModeIndX
	AddrModeIndY
	AddrModeRel
)

type CPU

type CPU struct {
	X  uint8  // X register
	Y  uint8  // Y register
	A  uint8  // Accumulator
	P  Flags  // Status flags
	SP uint8  // Stack pointer
	PC uint16 // Program counter

	Cycles uint64 // Number of cycles executed
	Halt   int    // Number of cycles to wait
	// contains filtered or unexported fields
}

func New

func New() *CPU

func (*CPU) LoadState

func (cpu *CPU) LoadState(r *binario.Reader) error

func (*CPU) Reset

func (cpu *CPU) Reset(mem Memory)

Reset resets the CPU to its initial state. To match the behaviour of the real CPU, the next 6 cycles are skipped after a reset.

func (*CPU) SaveState

func (cpu *CPU) SaveState(w *binario.Writer) error

func (*CPU) Tick

func (cpu *CPU) Tick(mem Memory) bool

Tick executes a single CPU cycle, returning true if the CPU has finished executing the current instruction.

func (*CPU) TriggerIRQ

func (cpu *CPU) TriggerIRQ()

TriggerIRQ triggers an interrupt on the next CPU cycle. If the interrupt flag is set, the interrupt is ignored.

func (*CPU) TriggerNMI

func (cpu *CPU) TriggerNMI()

TriggerNMI triggers a non-maskable interrupt on the next CPU cycle.

type Flags

type Flags = uint8

type Instruction

type Instruction struct {
	Name     string
	Opcode   uint8
	AddrMode AddrMode
	Size     int
	Cycles   int
	// contains filtered or unexported fields
}

type Interrupt

type Interrupt = uint8

type Memory

type Memory interface {
	Read(addr uint16) uint8
	Write(addr uint16, data uint8)
}

Jump to

Keyboard shortcuts

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