nes

package
v0.0.0-...-891855f Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ButtonA = (1 << iota)
	ButtonB
	ButtonSelect
	ButtonStart
	ButtonUP
	ButtonDown
	ButtonLeft
	ButtonRight
)

https://www.nesdev.org/wiki/Controller_reading_code

View Source
const (
	ScreenWidth  = 256
	ScreenHeight = 240
)
View Source
const (
	// ref: https://www.nesdev.org/wiki/CPU#Frequencies
	// NTSC
	CPUClockFrequency = 1789773
)

Variables

View Source
var Palette [64]color.Color

Functions

This section is empty.

Types

type APU

type APU struct {
	// contains filtered or unexported fields
}

func NewAPU

func NewAPU(irqLine *IRQInterruptLine, p Player, dma *DMA) *APU

func (*APU) FetchFrameIRQFlag

func (apu *APU) FetchFrameIRQFlag() bool

func (*APU) FetchFrameMode

func (apu *APU) FetchFrameMode() int

func (*APU) FetchFrameStep

func (apu *APU) FetchFrameStep() int

debug

func (*APU) FetchNewFrameCounterVal

func (apu *APU) FetchNewFrameCounterVal() int

func (*APU) FetchPulse1LC

func (apu *APU) FetchPulse1LC() int

func (*APU) FetchWriteDelayFC

func (apu *APU) FetchWriteDelayFC() byte

func (*APU) PeekStatus

func (apu *APU) PeekStatus() byte

PeekStatus is used for debugging

func (*APU) PowerUp

func (apu *APU) PowerUp()

func (*APU) Reset

func (apu *APU) Reset()

func (*APU) Step

func (apu *APU) Step()

type CPU

type CPU struct {
	// registers
	A  byte   // Accumulator
	X  byte   // Index
	Y  byte   // Index
	PC uint16 // Program Counter
	S  byte   // Stack Pointer
	P  processorStatus
	// contains filtered or unexported fields
}

func NewCPU

func NewCPU(bus *CPUBus, nmiLine *NMIInterruptLine, irqLine *IRQInterruptLine, opts ...CPUOption) *CPU

func (*CPU) FetchCycles

func (cpu *CPU) FetchCycles() int

debug

func (*CPU) PowerUp

func (cpu *CPU) PowerUp()

ref: http://users.telenet.be/kim1-6502/6502/proman.html#92

Cycles   Address Bus   Data Bus    External Operation     Internal Operation
1           ?           ?        Don't Care             Hold During Reset
2         ? + 1         ?        Don't Care             First Start State
3        0100 + SP      ?        Don't Care             Second Start State
4        0100 + SP-1    ?        Don't Care             Third Start State
5        0100 + SP-2    ?        Don't Care             Fourth Start State
6        FFFC        Start PCL   Fetch First Vector
7        FFFD        Start PCH   Fetch Second Vector    Hold PCL
8        PCH PCL     First       Load First OP CODE

func (*CPU) Read

func (cpu *CPU) Read(addr uint16) byte

func (*CPU) Reset

func (cpu *CPU) Reset()

func (*CPU) Step

func (cpu *CPU) Step()

func (*CPU) Write

func (cpu *CPU) Write(addr uint16, val byte)

type CPUBus

type CPUBus struct {
	// contains filtered or unexported fields
}

func NewCPUBus

func NewCPUBus(ppu *PPU, apu *APU, mapper Mapper, joypad *Joypad, dma *DMA) *CPUBus

func (*CPUBus) Peek

func (bus *CPUBus) Peek(addr uint16) byte

Peek is used for debugging

func (*CPUBus) RunDMAIfOccurred

func (bus *CPUBus) RunDMAIfOccurred(readCycle bool)

type CPUOption

type CPUOption func(*CPU)

func WithTracer

func WithTracer(tracer *Trace) CPUOption

type Cassette

type Cassette struct {
	PRG    []byte
	CHR    []byte
	Mapper byte
	Mirror MirroringType
	// contains filtered or unexported fields
}

func NewCassette

func NewCassette(r io.Reader) (*Cassette, error)

func (*Cassette) MirroingType

func (c *Cassette) MirroingType() MirroringType

type DMA

type DMA struct {
	// contains filtered or unexported fields
}

func (*DMA) TriggerOnDMCLoad

func (d *DMA) TriggerOnDMCLoad(addr uint16)

func (*DMA) TriggerOnDMCReload

func (d *DMA) TriggerOnDMCReload(addr uint16)

func (*DMA) TriggerOnOAM

func (d *DMA) TriggerOnOAM(addr uint16)

type DMCDMAState

type DMCDMAState int
const (
	DMCDMANoneState DMCDMAState = iota
	DMCDMAHaltState
	DMCDMADummyState
	DMCDMAAlignmentState
	DMCDMARunState
)

type IRQInterruptLine

type IRQInterruptLine int

func (*IRQInterruptLine) IsHigh

func (i *IRQInterruptLine) IsHigh() bool

func (*IRQInterruptLine) IsLow

func (i *IRQInterruptLine) IsLow() bool

func (*IRQInterruptLine) SetHigh

func (i *IRQInterruptLine) SetHigh(src IRQSource)

func (*IRQInterruptLine) SetLow

func (i *IRQInterruptLine) SetLow(src IRQSource)

type IRQSource

type IRQSource int
const (
	IRQSourceFrameCounter IRQSource = (1 << iota)
	IRQSourceDMC
)

type Joypad

type Joypad struct {
	Strobe       bool
	ButtonIndex  byte
	ButtonStatus byte
	// contains filtered or unexported fields
}

func NewJoypad

func NewJoypad() *Joypad

func (*Joypad) Peek

func (j *Joypad) Peek() byte

Peek is used for debugging

func (*Joypad) Read

func (j *Joypad) Read() byte

func (*Joypad) SetButtonStatus

func (j *Joypad) SetButtonStatus(b byte, pressed bool)

func (*Joypad) Write

func (j *Joypad) Write(v byte)

type Mapper

type Mapper interface {
	Read(addr uint16) byte
	Write(addr uint16, val byte)
	MirroingType() MirroringType
	String() string
	Reset()
}

func NewMapper

func NewMapper(r io.Reader) (Mapper, error)

func NewMapperFromCassette

func NewMapperFromCassette(c *Cassette) Mapper

type MirroringType

type MirroringType int
const (
	MirroringVertical MirroringType = iota
	MirroringHorizontal
	MirroringFourScreen
)

func (*MirroringType) IsFourScreen

func (m *MirroringType) IsFourScreen() bool

func (*MirroringType) IsHorizontal

func (m *MirroringType) IsHorizontal() bool

func (*MirroringType) IsVertical

func (m *MirroringType) IsVertical() bool

type Mnemonic

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

func (Mnemonic) String

func (m Mnemonic) String() string

type NES

type NES struct {
	// contains filtered or unexported fields
}

func New

func New(mapper Mapper, renderer Renderer, player Player) *NES

func (*NES) Close

func (n *NES) Close()

func (*NES) PeekMemory

func (n *NES) PeekMemory(addr uint16) byte

func (*NES) PowerUp

func (n *NES) PowerUp()

func (*NES) Reset

func (n *NES) Reset()

func (*NES) Run

func (n *NES) Run()

func (*NES) SetButtonStatus

func (n *NES) SetButtonStatus(b byte, pressed bool)

func (*NES) SetCPUPC

func (n *NES) SetCPUPC(pc uint16)

func (*NES) Step

func (n *NES) Step()

type NMIInterruptLine

type NMIInterruptLine int

func (*NMIInterruptLine) IsHigh

func (i *NMIInterruptLine) IsHigh() bool

func (*NMIInterruptLine) IsLow

func (i *NMIInterruptLine) IsLow() bool

func (*NMIInterruptLine) SetHigh

func (i *NMIInterruptLine) SetHigh()

func (*NMIInterruptLine) SetLow

func (i *NMIInterruptLine) SetLow()

type OAMDMAState

type OAMDMAState int
const (
	OAMDMANoneState OAMDMAState = iota
	OAMDMAHaltState
	OAMDMAAlignmentState
	OAMDMAReadState
	OAMDMAWriteState
)

type PPU

type PPU struct {
	Scanline int
	Cycle    int

	Clock int
	// contains filtered or unexported fields
}

func NewPPU

func NewPPU(renderer Renderer, mapper Mapper, mirror MirroringType, nmiLine *NMIInterruptLine) *PPU

func (*PPU) FetchBuffer

func (ppu *PPU) FetchBuffer() byte

func (*PPU) FetchV

func (ppu *PPU) FetchV() uint16

func (*PPU) FetchVBlankStarted

func (ppu *PPU) FetchVBlankStarted() bool

func (*PPU) PeekRegister

func (ppu *PPU) PeekRegister(addr uint16) byte

func (*PPU) PowerUp

func (ppu *PPU) PowerUp()

func (*PPU) ReadRegister

func (ppu *PPU) ReadRegister(addr uint16) byte

ReadRegister is called from CPU Memory Mapped I/O

func (*PPU) Reset

func (ppu *PPU) Reset()

func (*PPU) Step

func (ppu *PPU) Step()

ref: http://wiki.nesdev.com/w/images/4/4f/Ppu.svg

func (*PPU) WriteRegister

func (ppu *PPU) WriteRegister(addr uint16, val byte)

WriteRegister is called from CPU Memory Mapped I/O

type Player

type Player interface {
	Sample(float32)
	SampleRate() float64
}

type Renderer

type Renderer interface {
	Render(x, y int, c color.Color)
	Refresh()
}

type SpriteEvaluationState

type SpriteEvaluationState byte
const (
	InitAndScanPrimaryOAMState SpriteEvaluationState = iota
	ScanPrimaryOAMState
	CopySpriteState
	CheckSpriteOverflowState
	DoneSpriteEvaluationState
)

type Trace

type Trace struct {
	A                   byte
	X                   byte
	Y                   byte
	PC                  uint16
	S                   byte
	P                   byte
	ByteCode            []byte
	Opcode              opcode
	AddressingResult    string
	InstructionReadByte *byte
	Cycle               int
	PPUX                uint16
	PPUY                uint16
	PPUVBlankState      bool
}

func (*Trace) AddCPUByteCode

func (t *Trace) AddCPUByteCode(v byte)

func (*Trace) AddCPUCycle

func (t *Trace) AddCPUCycle(v int)

func (*Trace) NESTestString

func (t *Trace) NESTestString() string

func (*Trace) Reset

func (t *Trace) Reset()

func (*Trace) SetCPUAddressingResult

func (t *Trace) SetCPUAddressingResult(v string)

func (*Trace) SetCPUInstructionReadByte

func (t *Trace) SetCPUInstructionReadByte(v *byte)

func (*Trace) SetCPUOpcode

func (t *Trace) SetCPUOpcode(v opcode)

func (*Trace) SetCPURegisterA

func (t *Trace) SetCPURegisterA(v byte)

func (*Trace) SetCPURegisterP

func (t *Trace) SetCPURegisterP(v byte)

func (*Trace) SetCPURegisterPC

func (t *Trace) SetCPURegisterPC(v uint16)

func (*Trace) SetCPURegisterS

func (t *Trace) SetCPURegisterS(v byte)

func (*Trace) SetCPURegisterX

func (t *Trace) SetCPURegisterX(v byte)

func (*Trace) SetCPURegisterY

func (t *Trace) SetCPURegisterY(v byte)

func (*Trace) SetPPUVBlankState

func (t *Trace) SetPPUVBlankState(v bool)

func (*Trace) SetPPUX

func (t *Trace) SetPPUX(v uint16)

func (*Trace) SetPPUY

func (t *Trace) SetPPUY(v uint16)

Jump to

Keyboard shortcuts

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