rp2ago3

package
v0.0.0-...-f173d61 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2019 License: GPL-2.0, GPL-2.0 Imports: 2 Imported by: 10

README

rp2ago3

An RP 2A03 simulator written in Go

Documentation

Index

Constants

View Source
const (
	LengthCounterHaltLinearCounterControl = 1 << iota
	LinearCounterLoad
	TriangleTimerLow
	TriangleLengthCounterLoad
	TriangleTimerHigh
)
View Source
const NTSCCPUClockDivisor float32 = 3
View Source
const NoPending uint32 = 0xffffffff
View Source
const PALCPUClockDivisor float32 = 3.2
View Source
const (
	UNMIRRORED uint32 = 0x10000
)

Variables

View Source
var LengthCounterLUT [32]uint8 = [32]uint8{
	0x0a, 0xfe, 0x14, 0x02,
	0x28, 0x04, 0x50, 0x06,
	0xa0, 0x08, 0x3c, 0x0a,
	0x0e, 0x0c, 0x1a, 0x0e,
	0x0c, 0x10, 0x18, 0x12,
	0x30, 0x14, 0x60, 0x16,
	0xc0, 0x18, 0x48, 0x1a,
	0x10, 0x1c, 0x20, 0x1e,
}
View Source
var SequencerLUT [8][]uint8 = [8][]uint8{
	[]uint8{0, 1, 0, 0, 0, 0, 0, 0},
	[]uint8{0, 1, 1, 0, 0, 0, 0, 0},
	[]uint8{0, 1, 1, 1, 1, 0, 0, 0},
	[]uint8{1, 0, 0, 1, 1, 1, 1, 1},
}

Functions

This section is empty.

Types

type APU

type APU struct {
	Muted     bool      `json:"-"`
	Registers Registers `json:"APURegisters"`

	Pulse1       Pulse
	Pulse2       Pulse
	Triangle     Triangle
	Noise        Noise
	DMC          DMC
	FrameCounter FrameCounter

	Cycles       uint64
	TargetCycles uint64
	StallCycles  uint16

	HipassStrong int64
	HipassWeak   int64

	Interrupt func(state bool) `json:"-"`
	// contains filtered or unexported fields
}

func NewAPU

func NewAPU(mem m65go2.Memory, targetCycles uint64, interrupt func(bool)) *APU

func (*APU) ClockEnvelopes

func (apu *APU) ClockEnvelopes()

func (*APU) ClockLengthCounters

func (apu *APU) ClockLengthCounters()

func (*APU) ClockSweepUnits

func (apu *APU) ClockSweepUnits()

func (*APU) Execute

func (apu *APU) Execute() (sample int16, haveSample bool)

func (*APU) ExecuteFrameCounter

func (apu *APU) ExecuteFrameCounter()

func (*APU) Fetch

func (apu *APU) Fetch(address uint16) (value uint8)

func (*APU) FetchUpdatedStatus

func (apu *APU) FetchUpdatedStatus() (value uint8)

func (*APU) Mappings

func (apu *APU) Mappings(which Mapping) (fetch, store []uint16)

func (*APU) Reset

func (apu *APU) Reset()

func (*APU) Sample

func (apu *APU) Sample() (sample int16)

func (*APU) Store

func (apu *APU) Store(address uint16, value uint8) (oldValue uint8)

type Control

type Control uint8

type ControlFlag

type ControlFlag uint8
const (
	EnablePulseChannel1 ControlFlag = 1 << iota
	EnablePulseChannel2
	EnableTriangle
	EnableNoise
	EnableDMC
)

type DMA

type DMA struct {
	Memory  m65go2.Memory `json:"-"`
	Pending uint32
}

func NewDMA

func NewDMA(memory m65go2.Memory) *DMA

func (*DMA) Fetch

func (dma *DMA) Fetch(address uint16) (value uint8)

func (*DMA) Mappings

func (dma *DMA) Mappings(which Mapping) (fetch, store []uint16)

func (*DMA) PerformDMA

func (dma *DMA) PerformDMA() (cycles uint16)

func (*DMA) Reset

func (dma *DMA) Reset()

func (*DMA) Store

func (dma *DMA) Store(address uint16, value uint8) (oldValue uint8)

type DMC

type DMC struct {
	Muted     bool `json:"-"`
	Enabled   bool
	Registers [4]uint8

	Interrupt func(state bool) `json:"-"`

	Memory        m65go2.Memory `json:"-"`
	Address       uint16
	LengthCounter uint16
	Buffer        uint8
	BufferEmpty   bool

	Silence       bool
	Divider       Divider
	BitsRemaining uint8
	Shift         uint8

	Output    uint8
	PeriodLUT [16]int16 `json:"-"`
}

func (*DMC) ClockDivider

func (dmc *DMC) ClockDivider() (stallCycles uint16)

func (*DMC) Reset

func (dmc *DMC) Reset()

func (*DMC) Restart

func (dmc *DMC) Restart()

func (*DMC) Sample

func (dmc *DMC) Sample() (sample int16)

func (*DMC) SetEnabled

func (dmc *DMC) SetEnabled(enabled bool)

func (*DMC) Store

func (dmc *DMC) Store(index uint16, value uint8) (oldValue uint8)

type DMCFlag

type DMCFlag uint32
const (
	IRQEnable DMCFlag = 1 << iota
	Loop
	Frequency
	LoadCounter
	SampleAddress
	SampleLength
)

type Divider

type Divider struct {
	Counter  int16
	Period   int16
	PlusOne  bool
	TimesTwo bool
}

func (*Divider) Clock

func (divider *Divider) Clock() (output bool)

func (*Divider) Reload

func (divider *Divider) Reload()

func (*Divider) Reset

func (divider *Divider) Reset()

type Envelope

type Envelope struct {
	Start   bool
	Loop    bool
	Divider Divider
	Counter uint8
}

func (*Envelope) Clock

func (envelope *Envelope) Clock()

func (*Envelope) Reset

func (envelope *Envelope) Reset()

type FrameCounter

type FrameCounter struct {
	Register uint8
	Step     uint8
	Cycles   float64
}

func (*FrameCounter) Clock

func (frameCounter *FrameCounter) Clock() (changed bool, newStep uint8)

func (*FrameCounter) Reset

func (frameCounter *FrameCounter) Reset()

func (*FrameCounter) Store

func (frameCounter *FrameCounter) Store(value uint8) (oldValue uint8, executeFrameCounter bool)

type FrameCounterFlag

type FrameCounterFlag uint8
const (
	IRQInhibit FrameCounterFlag = 1 << iota
	Mode
)

type LinearCounter

type LinearCounter struct {
	Control     bool
	Halt        bool
	ReloadValue uint8
	Counter     uint8
}

func (*LinearCounter) Clock

func (linearCounter *LinearCounter) Clock() (counter uint8)

func (*LinearCounter) Reset

func (linearCounter *LinearCounter) Reset()

type MappableMemory

type MappableMemory interface {
	m65go2.Memory
	Mappings(which Mapping) (fetch, store []uint16)
}

type MappedMemory

type MappedMemory struct {
	m65go2.Memory
	// contains filtered or unexported fields
}

func NewMappedMemory

func NewMappedMemory(base m65go2.Memory) *MappedMemory

func (*MappedMemory) AddMappings

func (mem *MappedMemory) AddMappings(mappable MappableMemory, which Mapping) (err error)

func (*MappedMemory) AddMirrors

func (mem *MappedMemory) AddMirrors(mirrors map[uint32]uint32) (err error)

func (*MappedMemory) Fetch

func (mem *MappedMemory) Fetch(address uint16) (value uint8)

func (*MappedMemory) Reset

func (mem *MappedMemory) Reset()

func (*MappedMemory) Store

func (mem *MappedMemory) Store(address uint16, value uint8) (oldValue uint8)

type Mapping

type Mapping uint8
const (
	CPU Mapping = iota
	PPU
)

type Noise

type Noise struct {
	Muted     bool `json:"-"`
	Enabled   bool
	Registers [3]uint8

	Envelope         Envelope
	Divider          Divider
	Shift            uint16
	LengthCounter    uint8
	LengthCounterLUT [32]uint8 `json:"-"`
	PeriodLUT        [16]int16 `json:"-"`
}

func (*Noise) ClockDivider

func (noise *Noise) ClockDivider()

func (*Noise) ClockEnvelope

func (noise *Noise) ClockEnvelope()

func (*Noise) ClockLengthCounter

func (noise *Noise) ClockLengthCounter()

func (*Noise) Reset

func (noise *Noise) Reset()

func (*Noise) Sample

func (noise *Noise) Sample() (sample int16)

func (*Noise) SetEnabled

func (noise *Noise) SetEnabled(enabled bool)

func (*Noise) Store

func (noise *Noise) Store(index uint16, value uint8) (oldValue uint8)

type NoiseFlag

type NoiseFlag uint32
const (
	NoiseEnvelopeLoopLengthCounterHalt NoiseFlag = 1 << iota
	NoiseConstantVolume
	NoiseVolumeEnvelope
	LoopNoise
	NoisePeriod
	NoiseLengthCounterLoad
)

type Pulse

type Pulse struct {
	Muted     bool `json:"-"`
	Enabled   bool
	MinusOne  bool
	Registers [4]uint8

	Envelope         Envelope
	SweepUnit        SweepUnit
	Divider          Divider
	Sequencer        Sequencer
	SequencerLUT     [8][]uint8 `json:"-"`
	LengthCounter    uint8
	LengthCounterLUT [32]uint8 `json:"-"`
}

func (*Pulse) ClockDivider

func (pulse *Pulse) ClockDivider()

func (*Pulse) ClockEnvelope

func (pulse *Pulse) ClockEnvelope()

func (*Pulse) ClockLengthCounter

func (pulse *Pulse) ClockLengthCounter()

func (*Pulse) ClockSequencer

func (pulse *Pulse) ClockSequencer()

func (*Pulse) ClockSweepUnit

func (pulse *Pulse) ClockSweepUnit()

func (*Pulse) Reset

func (pulse *Pulse) Reset()

func (*Pulse) Sample

func (pulse *Pulse) Sample() (sample int16)

func (*Pulse) SetEnabled

func (pulse *Pulse) SetEnabled(enabled bool)

func (*Pulse) Store

func (pulse *Pulse) Store(index uint16, value uint8) (oldValue uint8)

func (*Pulse) TargetPeriod

func (pulse *Pulse) TargetPeriod() (target int16)

type PulseFlag

type PulseFlag uint32
const (
	Duty PulseFlag = 1 << iota
	PulseEnvelopeLoopLengthCounterHalt
	PulseConstantVolume
	PulseVolumeEnvelope
	SweepEnabled
	SweepPeriod
	SweepNegate
	SweepShift
	PulseTimerLow
	PulseLengthCounterLoad
	PulseTimerHigh
)

type RP2A03

type RP2A03 struct {
	*m65go2.M6502
	*APU
	DMA    *DMA
	Memory *MappedMemory `json:"RP2A03Memory"`
}

func NewRP2A03

func NewRP2A03(apuFrequency int) *RP2A03

func (*RP2A03) Execute

func (cpu *RP2A03) Execute() (cycles uint16, err error)

func (*RP2A03) Reset

func (cpu *RP2A03) Reset()

func (*RP2A03) Run

func (cpu *RP2A03) Run() (err error)

type Registers

type Registers struct {
	Control Control
	Status  Status
}

type Sequencer

type Sequencer struct {
	Values []uint8
	Index  int
	Output uint8
}

func (*Sequencer) Clock

func (sequencer *Sequencer) Clock() (output uint8)

func (*Sequencer) Reset

func (sequencer *Sequencer) Reset()

type Status

type Status uint8

type StatusFlag

type StatusFlag uint8
const (
	Pulse1LengthCounterNotZero StatusFlag = 1 << iota
	Pulse2LengthCounterNotZero
	TriangleLengthCounterNotZero
	NoiseLengthCounterNotZero
	DMCActive

	FrameInterrupt
	DMCInterrupt
)

type SweepUnit

type SweepUnit struct {
	Enabled bool
	Reload  bool
	Divider Divider
}

func (*SweepUnit) Clock

func (sweepUnit *SweepUnit) Clock() (adjustPeriod bool)

func (*SweepUnit) Reset

func (sweepUnit *SweepUnit) Reset()

type Triangle

type Triangle struct {
	Muted     bool `json:"-"`
	Enabled   bool
	Registers [3]uint8

	Divider          Divider
	LinearCounter    LinearCounter
	Sequencer        Sequencer
	LengthCounter    uint8
	LengthCounterLUT [32]uint8 `json:"-"`
}

func (*Triangle) ClockDivider

func (triangle *Triangle) ClockDivider()

func (*Triangle) ClockLengthCounter

func (triangle *Triangle) ClockLengthCounter()

func (*Triangle) ClockLinearCounter

func (triangle *Triangle) ClockLinearCounter()

func (*Triangle) ClockSequencer

func (triangle *Triangle) ClockSequencer()

func (*Triangle) Reset

func (triangle *Triangle) Reset()

func (*Triangle) Sample

func (triangle *Triangle) Sample() (sample int16)

func (*Triangle) SetEnabled

func (triangle *Triangle) SetEnabled(enabled bool)

func (*Triangle) Store

func (triangle *Triangle) Store(index uint16, value uint8) (oldValue uint8)

type TriangleFlag

type TriangleFlag uint32

Jump to

Keyboard shortcuts

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