cpu

package
v0.3.0-beta Latest Latest
Warning

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

Go to latest
Published: May 28, 2019 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SP_BASE uint16 = 0x100
)

Variables

View Source
var InstructionInfos = [256]InstructionInfo{}/* 256 elements not displayed */

Functions

This section is empty.

Types

type Accumulator

type Accumulator = uint8

The accumulator is the main register for arithmetic and logic

operations. Unlike the index registers X and Y, it has a direct
connection to the Arithmetic and Logic Unit (ALU). This is why
many operations are only available for the accumulator, not the
index registers.

type AddressingMode

type AddressingMode int
const (
	IMP AddressingMode = iota
	IMM
	ZP
	ZPX
	ZPY
	IZX
	IZY
	ABS
	ABX
	ABY
	IND
	REL
)

func Decode

func Decode(opcode byte) (string, AddressingMode)

func (AddressingMode) GetArgumentCount

func (i AddressingMode) GetArgumentCount() uint16

type Cpu

type Cpu struct {
	// registers
	PC   ProgramCounter
	P    ProcessorStatus
	SP   StackPointer
	A    Accumulator
	X, Y IndexRegister
	// memory
	Memory memory.Memory
	// interrupts
	NMI bool
	IRQ bool
	// waitCycles
	Wait int
}

func NewCpu

func NewCpu(memory memory.Memory) *Cpu

func (*Cpu) AddressAbX

func (cpu *Cpu) AddressAbX() (memory.Ptr, int)

func (*Cpu) AddressAbY

func (cpu *Cpu) AddressAbY() (memory.Ptr, int)

func (*Cpu) AddressAbs

func (cpu *Cpu) AddressAbs() (memory.Ptr, int)

func (*Cpu) AddressImm

func (cpu *Cpu) AddressImm() (memory.Ptr, int)

func (*Cpu) AddressInd

func (cpu *Cpu) AddressInd() (memory.Ptr, int)

func (*Cpu) AddressIzx

func (cpu *Cpu) AddressIzx() (memory.Ptr, int)

func (*Cpu) AddressIzy

func (cpu *Cpu) AddressIzy() (memory.Ptr, int)

func (*Cpu) AddressOperand

func (cpu *Cpu) AddressOperand(am AddressingMode) (memory.Ptr, int)

func (*Cpu) AddressRel

func (cpu *Cpu) AddressRel() (memory.Ptr, int)

func (*Cpu) AddressZP

func (cpu *Cpu) AddressZP() (memory.Ptr, int)

func (*Cpu) AddressZPX

func (cpu *Cpu) AddressZPX() (memory.Ptr, int)

func (*Cpu) AddressZPY

func (cpu *Cpu) AddressZPY() (memory.Ptr, int)

func (*Cpu) ExecADC

func (cpu *Cpu) ExecADC(operandAddr memory.Ptr) int

func (*Cpu) ExecAND

func (cpu *Cpu) ExecAND(operandAddr memory.Ptr) int

func (*Cpu) ExecASL

func (cpu *Cpu) ExecASL(operandAddr memory.Ptr) int

func (*Cpu) ExecASLA

func (cpu *Cpu) ExecASLA(operandAddr memory.Ptr) int

func (*Cpu) ExecBCC

func (cpu *Cpu) ExecBCC(operandAddr memory.Ptr) int

func (*Cpu) ExecBCS

func (cpu *Cpu) ExecBCS(operandAddr memory.Ptr) int

func (*Cpu) ExecBEQ

func (cpu *Cpu) ExecBEQ(operandAddr memory.Ptr) int

func (*Cpu) ExecBIT

func (cpu *Cpu) ExecBIT(operandAddr memory.Ptr) int

func (*Cpu) ExecBMI

func (cpu *Cpu) ExecBMI(operandAddr memory.Ptr) int

func (*Cpu) ExecBNE

func (cpu *Cpu) ExecBNE(operandAddr memory.Ptr) int

func (*Cpu) ExecBPL

func (cpu *Cpu) ExecBPL(operandAddr memory.Ptr) int

func (*Cpu) ExecBRK

func (cpu *Cpu) ExecBRK(operandAddr memory.Ptr) int

func (*Cpu) ExecBVC

func (cpu *Cpu) ExecBVC(operandAddr memory.Ptr) int

func (*Cpu) ExecBVS

func (cpu *Cpu) ExecBVS(operandAddr memory.Ptr) int

func (*Cpu) ExecCLC

func (cpu *Cpu) ExecCLC(operandAddr memory.Ptr) int

func (*Cpu) ExecCLD

func (cpu *Cpu) ExecCLD(operandAddr memory.Ptr) int

func (*Cpu) ExecCLI

func (cpu *Cpu) ExecCLI(operandAddr memory.Ptr) int

func (*Cpu) ExecCLV

func (cpu *Cpu) ExecCLV(operandAddr memory.Ptr) int

func (*Cpu) ExecCMP

func (cpu *Cpu) ExecCMP(operandAddr memory.Ptr) int

func (*Cpu) ExecCPX

func (cpu *Cpu) ExecCPX(operandAddr memory.Ptr) int

func (*Cpu) ExecCPY

func (cpu *Cpu) ExecCPY(operandAddr memory.Ptr) int

func (*Cpu) ExecDEC

func (cpu *Cpu) ExecDEC(operandAddr memory.Ptr) int

func (*Cpu) ExecDEX

func (cpu *Cpu) ExecDEX(operandAddr memory.Ptr) int

func (*Cpu) ExecDEY

func (cpu *Cpu) ExecDEY(operandAddr memory.Ptr) int

func (*Cpu) ExecEOR

func (cpu *Cpu) ExecEOR(operandAddr memory.Ptr) int

func (*Cpu) ExecINC

func (cpu *Cpu) ExecINC(operandAddr memory.Ptr) int

func (*Cpu) ExecINX

func (cpu *Cpu) ExecINX(operandAddr memory.Ptr) int

func (*Cpu) ExecINY

func (cpu *Cpu) ExecINY(operandAddr memory.Ptr) int

func (*Cpu) ExecIRQ

func (cpu *Cpu) ExecIRQ()

func (*Cpu) ExecJMP

func (cpu *Cpu) ExecJMP(operandAddr memory.Ptr) int

func (*Cpu) ExecJSR

func (cpu *Cpu) ExecJSR(operandAddr memory.Ptr) int

func (*Cpu) ExecLDA

func (cpu *Cpu) ExecLDA(operandAddr memory.Ptr) int

func (*Cpu) ExecLDX

func (cpu *Cpu) ExecLDX(operandAddr memory.Ptr) int

func (*Cpu) ExecLDY

func (cpu *Cpu) ExecLDY(operandAddr memory.Ptr) int

func (*Cpu) ExecLSR

func (cpu *Cpu) ExecLSR(operandAddr memory.Ptr) int

func (*Cpu) ExecLSRA

func (cpu *Cpu) ExecLSRA(operandAddr memory.Ptr) int

func (*Cpu) ExecNMI

func (cpu *Cpu) ExecNMI()

func (*Cpu) ExecNOP

func (cpu *Cpu) ExecNOP(operandAddr memory.Ptr) int

func (*Cpu) ExecORA

func (cpu *Cpu) ExecORA(operandAddr memory.Ptr) int

func (*Cpu) ExecOneInstruction

func (cpu *Cpu) ExecOneInstruction() (cycles int)

func (*Cpu) ExecPHA

func (cpu *Cpu) ExecPHA(operandAddr memory.Ptr) int

func (*Cpu) ExecPHP

func (cpu *Cpu) ExecPHP(operandAddr memory.Ptr) int

func (*Cpu) ExecPLA

func (cpu *Cpu) ExecPLA(operandAddr memory.Ptr) int

func (*Cpu) ExecPLP

func (cpu *Cpu) ExecPLP(operandAddr memory.Ptr) int

func (*Cpu) ExecROL

func (cpu *Cpu) ExecROL(operandAddr memory.Ptr) int

func (*Cpu) ExecROLA

func (cpu *Cpu) ExecROLA(operandAddr memory.Ptr) int

func (*Cpu) ExecROR

func (cpu *Cpu) ExecROR(operandAddr memory.Ptr) int

func (*Cpu) ExecRORA

func (cpu *Cpu) ExecRORA(operandAddr memory.Ptr) int

func (*Cpu) ExecRTI

func (cpu *Cpu) ExecRTI(operandAddr memory.Ptr) int

func (*Cpu) ExecRTS

func (cpu *Cpu) ExecRTS(operandAddr memory.Ptr) int

func (*Cpu) ExecSBC

func (cpu *Cpu) ExecSBC(operandAddr memory.Ptr) int

func (*Cpu) ExecSEC

func (cpu *Cpu) ExecSEC(operandAddr memory.Ptr) int

func (*Cpu) ExecSED

func (cpu *Cpu) ExecSED(operandAddr memory.Ptr) int

func (*Cpu) ExecSEI

func (cpu *Cpu) ExecSEI(operandAddr memory.Ptr) int

func (*Cpu) ExecSTA

func (cpu *Cpu) ExecSTA(operandAddr memory.Ptr) int

func (*Cpu) ExecSTX

func (cpu *Cpu) ExecSTX(operandAddr memory.Ptr) int

func (*Cpu) ExecSTY

func (cpu *Cpu) ExecSTY(operandAddr memory.Ptr) int

func (*Cpu) ExecTAX

func (cpu *Cpu) ExecTAX(operandAddr memory.Ptr) int

func (*Cpu) ExecTAY

func (cpu *Cpu) ExecTAY(operandAddr memory.Ptr) int

func (*Cpu) ExecTSX

func (cpu *Cpu) ExecTSX(operandAddr memory.Ptr) int

func (*Cpu) ExecTXA

func (cpu *Cpu) ExecTXA(operandAddr memory.Ptr) int

func (*Cpu) ExecTXS

func (cpu *Cpu) ExecTXS(operandAddr memory.Ptr) int

func (*Cpu) ExecTYA

func (cpu *Cpu) ExecTYA(operandAddr memory.Ptr) int

func (*Cpu) Pop

func (cpu *Cpu) Pop() byte

func (*Cpu) PopW

func (cpu *Cpu) PopW() uint16

func (*Cpu) PowerUp

func (cpu *Cpu) PowerUp()

func (*Cpu) Push

func (cpu *Cpu) Push(b byte)

func (*Cpu) PushW

func (cpu *Cpu) PushW(w uint16)

func (*Cpu) ReadInterruptVector

func (cpu *Cpu) ReadInterruptVector(iv InterruptVector) memory.Ptr

func (*Cpu) Reset

func (cpu *Cpu) Reset()

func (*Cpu) Test

func (cpu *Cpu) Test()

type IndexRegister

type IndexRegister = uint8

Register for addressing data with indices

type InstructionExecutor

type InstructionExecutor func(cpu *Cpu, operandAddr memory.Ptr) (cyclesTook int)

type InstructionHandler

type InstructionHandler struct {
	Executor       InstructionExecutor
	AddressingMode AddressingMode
}

type InstructionInfo

type InstructionInfo struct {
	OpCode         byte
	Nemonics       string
	AddressingMode AddressingMode
	Cycles         int
	VariableCycles bool
}

type InterruptVector

type InterruptVector memory.Ptr
const (
	IV_NMI   InterruptVector = 0xFFFA
	IV_RESET InterruptVector = 0xFFFC
	IV_IRQ   InterruptVector = 0xFFFE
	IV_BRK   InterruptVector = 0xFFFE
)

type ProcessorStatus

type ProcessorStatus uint8

This 8-bit register stores the state of the processor. The bits in

this register are called flags. Most of the flags have something
to do with arithmetic operations.
const (
	// Carry flag
	PFLAG_C ProcessorStatus = 1 << iota
	// Zero flag
	PFLAG_Z
	// Interrupt disable flag
	PFLAG_I
	// Decimal mode flag.
	// 2A03 does not support BCD mode so although the flag can be set, its value will be ignored.
	PFLAG_D
	// Break flag
	PFLAG_B
	// unused flag, alway 1
	PFLAG_UNUSED
	// oVerflow flag
	PFLAG_V
	// Negative flag
	PFLAG_N
)

func (*ProcessorStatus) Set

func (p *ProcessorStatus) Set(flag ProcessorStatus, val bool)

func (ProcessorStatus) String

func (p ProcessorStatus) String() string

type ProgramCounter

type ProgramCounter = uint16

This register points the address from which the next instruction

byte (opcode or parameter) will be fetched. Unlike other
registers, this one is 16 bits in length. The low and high 8-bit
halves of the register are called PCL and PCH, respectively. The
Program Counter may be read by pushing its value on the stack.
This can be done either by jumping to a subroutine or by causing
an interrupt.

type StackPointer

type StackPointer = uint8

The NMOS 65xx processors have 256 bytes of stack memory, ranging

from $0100 to $01FF. The S register is a 8-bit offset to the stack
page. In other words, whenever anything is being pushed on the
stack, it will be stored to the address $0100+S.

The Stack pointer can be read and written by transfering its value
to or from the index register X (see below) with the TSX and TXS
instructions.

Jump to

Keyboard shortcuts

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