mos65xx

package module
v0.0.0-...-60dbe6b Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2018 License: MIT Imports: 7 Imported by: 0

README

mos65xx

💻 Golang MOS Technology 65xx CPU emulator

Documentation

Overview

Package mos65xx implements MOS Technology 65xx CPU emulation.

Index

Constants

View Source
const (
	NMIVector   = 0xfffa
	ResetVector = 0xfffc
	IRQVector   = 0xfffe
)

Vectors

View Source
const (
	C uint8 = 1 << iota // Carry flag, 1 = true
	Z                   // Zero, 1 = Result zero
	I                   // IRQ disable, 1 = disable
	D                   // Decimal mode, 1 = true
	B                   // BRK command
	U                   // Unused
	V                   // Overflow, 1 = true
	N                   // Negative, 1 = true
)

Processor status register flags

View Source
const (
	Hz  = 1
	KHz = 1000 * Hz
	MHz = 1000 * KHz
)

Frequency scale

View Source
const (
	// FormatDefault resembles neskell's output format
	FormatDefault = `` /* 126-byte string literal not displayed */

	// FormatNintendulator resembles nintendulator's output format
	FormatNintendulator = `{{printf "%04X %-9s %s %-27s A:%02X X:%02X Y:%02X P:%02X SP:%02x" .PC .RawX .Mnemonic .Operand .A .X .Y .P .S}}`
)

Instruction formats

Variables

View Source
var (
	MOS6502 = Model{
		Name:           "MOS Technology 6502",
		Frequency:      1 * MHz,
		ExternalMemory: 0x10000,
		HasBCD:         true,
		HasIRQ:         true,
		HasNMI:         true,
	}

	MOS6503 = Model{
		Name:           "MOS Technology 6503",
		Frequency:      1 * MHz,
		ExternalMemory: 0x1000,
		HasBCD:         true,
		HasIRQ:         true,
		HasNMI:         true,
	}

	MOS6504 = Model{
		Name:           "MOS Technology 6504",
		Frequency:      1 * MHz,
		ExternalMemory: 0x2000,
		HasBCD:         true,
		HasIRQ:         true,
	}

	MOS6505 = Model{
		Name:           "MOS Technology 6505",
		Frequency:      1 * MHz,
		ExternalMemory: 0x1000,
		HasBCD:         true,
		HasIRQ:         true,
		HasReady:       true,
	}

	MOS6506 = Model{
		Name:           "MOS Technology 6506",
		Frequency:      1 * MHz,
		ExternalMemory: 0x1000,
		HasBCD:         true,
		HasIRQ:         true,
	}

	MOS6507 = Model{
		Name:           "MOS Technology 6507",
		Frequency:      1 * MHz,
		ExternalMemory: 0x2000,
	}

	MOS6510 = Model{
		Name:           "MOS Technology 6510",
		Frequency:      1.023 * MHz,
		ExternalMemory: 0x10000,
		HasBCD:         true,
		HasNMI:         true,
		HasReady:       true,
	}

	MOS6510T = Model{
		Name:           "MOS Technology 6510T",
		Frequency:      1.023 * MHz,
		ExternalMemory: 0x10000,
		HasBCD:         true,
	}

	MOS7501 = Model{
		Name:           "MOS Technology 7501",
		Frequency:      1.023 * MHz,
		ExternalMemory: 0x10000,
		HasBCD:         true,
		HasReady:       true,
	}

	MOS8501 = Model{
		Name:           "MOS Technology 8501",
		Frequency:      1.023 * MHz,
		ExternalMemory: 0x10000,
		HasBCD:         true,
		HasReady:       true,
	}

	MOS8502 = Model{
		Name:           "MOS Technology 8502",
		Frequency:      2 * MHz,
		ExternalMemory: 0x10000,
		HasBCD:         true,
		HasNMI:         true,
		HasReady:       true,
	}

	// Ricoh2A03 is the 8-bit microprocessor in the Nintendo Entertainment System (NTSC version)
	Ricoh2A03 = Model{
		Name:           "Ricoh 2A03",
		Frequency:      1 * MHz,
		ExternalMemory: 0x10000,
		HasIRQ:         true,
		HasNMI:         true,
	}

	// Ricoh2A07 is the 8-bit microprocessor in the Nintendo Entertainment System (PAL version)
	Ricoh2A07 = Model{
		Name:           "Ricoh 2A07",
		Frequency:      1 * MHz,
		ExternalMemory: 0x10000,
		HasIRQ:         true,
		HasNMI:         true,
	}
)

Models

View Source
var (
	// InstructionFormat is the default instruction format
	InstructionFormat = FormatDefault
)

Functions

func FetchWord

func FetchWord(mem memory.Memory, addr uint16) uint16

FetchWord is a helper to fetch a 16-bit word from memory

func FetchWordBug

func FetchWordBug(mem memory.Memory, addr uint16) uint16

FetchWordBug is a helper to fetch a 16-bit word from memory

func StoreWord

func StoreWord(mem memory.Memory, addr, value uint16)

StoreWord is a helper to store a 16-bit word on a bus

Types

type AddressMode

type AddressMode uint8

AddressMode determines how the CPU will fetch the address

const (
	Implied AddressMode = iota
	Accumulator
	Immediate
	ZeroPage
	ZeroPageX
	ZeroPageY
	Relative
	Absolute
	AbsoluteX
	AbsoluteY
	Indirect
	IndexedIndirect
	IndirectIndexed
)

Address modes

func (AddressMode) Cycles

func (mode AddressMode) Cycles() int

Cycles to fetch the operand address

func (AddressMode) FetchPenalty

func (mode AddressMode) FetchPenalty() int

FetchPenalty is the cycle penalty for doing page cross or branch on a fetch operation.

func (AddressMode) StorePenalty

func (mode AddressMode) StorePenalty() int

StorePenalty is the cycle penalty for doing page cross on a store operation.

func (AddressMode) String

func (mode AddressMode) String() string

type CPU

type CPU interface {
	// Memory as observed by the CPU
	memory.Memory

	// Registers returns a pointer to the CPU registers
	Registers() *Registers

	// IRQ requests an interrupt
	IRQ()

	// NMI requests an non-maskable interrupt
	NMI()

	// Reset requests a cold reset
	Reset()

	// Ready
	Ready(bool)

	// Step fetches and executes the next instruction, returning the total
	// number of cycles spent on performing the operation.
	Step() int

	// Run until the CPU receives a HLT instruction, returning the total
	// number of cycles spent.
	Run() int

	// Halted returns true if the CPU received a HLT instruction
	Halted() bool

	// Attach a monitor
	Attach(Monitor)
}

CPU represents a MOS Technology 65xx Central Processing Unit

func New

func New(model Model, mem memory.Memory) CPU

New creates a new CPU for the specified model

type Instruction

type Instruction struct {
	// CPU this instruction is executed on
	CPU CPU

	// Cycles elapsed
	Cycles int

	// Mnemonic is the current operation
	Mnemonic

	// Registers state for instruction
	Registers

	// AddressMode is the addressing mode for this instruction
	AddressMode

	// Raw opcode and address bytes
	Raw []byte
}

Instruction describes an instruction that's about to be executed

func (Instruction) Addr

func (in Instruction) Addr() (addr uint16)

Addr is the operand address for the current instruction.

func (Instruction) Format

func (in Instruction) Format(format string, cpu CPU) string

Format returns a formatted string based on the format template for the referenced CPU.

type InstructionPrinter

type InstructionPrinter func(string)

InstructionPrinter will output a formatted string before execution.

func (InstructionPrinter) BeforeExecute

func (m InstructionPrinter) BeforeExecute(cpu CPU, in Instruction) bool

BeforeExecute triggers the printer function.

type Interrupt

type Interrupt uint8

Interrupt type

const (
	None Interrupt = iota //
	NMI                   // Non-Maskable interrupt
	IRQ                   // Interrupt request
)

Interrupt types

type Mnemonic

type Mnemonic uint8

Mnemonic is an instruction

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

mnemonics

func (Mnemonic) String

func (m Mnemonic) String() string

type Model

type Model struct {
	Name           string
	Frequency      float64 // Typical clock frequency in Hz
	ExternalMemory int     // External addressable memory size
	InternalMemory int     // Internal RAM size
	HasBCD         bool    // Decimal mode support
	HasIRQ         bool    // IRQ support
	HasNMI         bool    // NMI support
	HasReady       bool    // RDY support
}

Model of the MOS Technology 65xx (or compatible) CPU

type Monitor

type Monitor interface {
	// BeforeExecute gets called before instruction execution, returning false
	// will stop execution and halt the CPU.
	BeforeExecute(CPU, Instruction) bool
}

Monitor for the CPU monitors instruction executions

type Registers

type Registers struct {
	PC uint16 // Program counter
	S  uint8  // Stack pointer
	P  uint8  // Processor status register
	A  uint8  // Accumulator register
	X  uint8  // X index register
	Y  uint8  // Y index register
}

Registers are the CPU registers

func (*Registers) String

func (reg *Registers) String() string

Directories

Path Synopsis
Package memory implements access to 16-bit address space.
Package memory implements access to 16-bit address space.

Jump to

Keyboard shortcuts

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