lib

package
v0.0.0-...-f6f1029 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Instruction_BRK              InstructionType = 0x00
	Instruction_ORA_indirect_x                   = 0x01
	Instruction_KIL_1                            = 0x02
	Instruction_SLO_indirect_x                   = 0x03
	Instruction_NOP_zero                         = 0x04
	Instruction_ORA_zero                         = 0x05
	Instruction_ASL_zero                         = 0x06
	Instruction_SLO_zero                         = 0x07
	Instruction_PHP                              = 0x08
	Instruction_ORA_immediate                    = 0x09
	Instruction_ASL_accumulator                  = 0x0a
	Instruction_ANC_immediate_1                  = 0x0b
	Instruction_NOP_absolute                     = 0x0c
	Instruction_ORA_absolute                     = 0x0d
	Instruction_ASL_absolute                     = 0x0e
	Instruction_SLO_absolute                     = 0x0f
	Instruction_BPL                              = 0x10
	Instruction_ORA_indirect_y                   = 0x11
	Instruction_KIL_2                            = 0x12
	Instruction_SLO_indirect_y                   = 0x13
	Instruction_NOP_zero_x                       = 0x14
	Instruction_ORA_zero_x                       = 0x15
	Instruction_ASL_zero_x                       = 0x16
	Instruction_SLO_zero_x                       = 0x17
	Instruction_CLC                              = 0x18
	Instruction_ORA_absolute_y                   = 0x19
	Instruction_NOP_1                            = 0x1a
	Instruction_SLO_absolute_y                   = 0x1b
	Instruction_NOP_absolute_x_1                 = 0x1c
	Instruction_ORA_absolute_x                   = 0x1d
	Instruction_ASL_absolute_x                   = 0x1e
	Instruction_SLO_absolute_x                   = 0x1f
	Instruction_JSR                              = 0x20
	Instruction_AND_indirect_x                   = 0x21
	Instruction_KIL_3                            = 0x22
	Instruction_RLA_indirect_x                   = 0x23
	Instruction_BIT_zero                         = 0x24
	Instruction_AND_zero                         = 0x25
	Instruction_ROL_zero                         = 0x26
	Instruction_RLA_zero                         = 0x27
	Instruction_PLP                              = 0x28
	Instruction_AND_immediate                    = 0x29
	Instruction_ROL_accumulator                  = 0x2a
	Instruction_ANC_immediate_2                  = 0x2b
	Instruction_BIT_absolute                     = 0x2c
	Instruction_AND_absolute                     = 0x2d
	Instruction_ROL_absolute                     = 0x2e
	Instruction_RLA_absolute                     = 0x2f
	Instruction_BMI                              = 0x30
	Instruction_AND_indirect_y                   = 0x31
	Instruction_KIL_4                            = 0x32
	Instruction_RLA_indirect_y                   = 0x33
	Instruction_NOP_zero_x_1                     = 0x34
	Instruction_AND_zero_x                       = 0x35
	Instruction_ROL_zero_x                       = 0x36
	Instruction_RLA_zero_x                       = 0x37
	Instruction_SEC                              = 0x38
	Instruction_AND_absolute_y                   = 0x39
	Instruction_NOP_2                            = 0x3a
	Instruction_RLA_absolute_y                   = 0x3b
	Instruction_NOP_absolute_x_2                 = 0x3c
	Instruction_AND_absolute_x                   = 0x3d
	Instruction_ROL_absolute_x                   = 0x3e
	Instruction_RLA_absolute_x                   = 0x3f
	Instruction_RTI                              = 0x40
	Instruction_EOR_indirect_x                   = 0x41
	Instruction_KIL_5                            = 0x42
	Instruction_SRE_indirect_x                   = 0x43
	Instruction_NOP_zero_1                       = 0x44
	Instruction_EOR_zero                         = 0x45
	Instruction_LSR_zero                         = 0x46
	Instruction_SRE_zero                         = 0x47
	Instruction_PHA                              = 0x48
	Instruction_EOR_immediate                    = 0x49
	Instruction_LSR_accumulator                  = 0x4a
	Instruction_ALR                              = 0x4b
	Instruction_JMP_absolute                     = 0x4c
	Instruction_EOR_absolute                     = 0x4d
	Instruction_LSR_absolute                     = 0x4e
	Instruction_SRE_absolute                     = 0x4f
	Instruction_BVC_relative                     = 0x50
	Instruction_EOR_indirect_y                   = 0x51
	Instruction_KIL_6                            = 0x52
	Instruction_SRE_indirect_y                   = 0x53
	Instruction_NOP_zero_x_2                     = 0x54
	Instruction_EOR_zero_x                       = 0x55
	Instruction_LSR_zero_x                       = 0x56
	Instruction_SRE_zero_x                       = 0x57
	Instruction_CLI                              = 0x58
	Instruction_EOR_absolute_y                   = 0x59
	Instruction_NOP_3                            = 0x5a
	Instruction_SRE_absolute_y                   = 0x5b
	Instruction_NOP_absolute_x_3                 = 0x5c
	Instruction_EOR_absolute_x                   = 0x5d
	Instruction_LSR_absolute_x                   = 0x5e
	Instruction_SRE_absolute_x                   = 0x5f
	Instruction_RTS                              = 0x60
	Instruction_ADC_indirect_x                   = 0x61
	Instruction_KIL_7                            = 0x62
	Instruction_RRA_indirect_x                   = 0x63
	Instruction_NOP_zero_2                       = 0x64
	Instruction_ADC_zero                         = 0x65
	Instruction_ROR_zero                         = 0x66
	Instruction_RRA_zero                         = 0x67
	Instruction_PLA                              = 0x68
	Instruction_ADC_immediate                    = 0x69
	Instruction_ROR_accumulator                  = 0x6a
	Instruction_ARR                              = 0x6b
	Instruction_JMP_indirect                     = 0x6c
	Instruction_ADC_absolute                     = 0x6d
	Instruction_ROR_absolute                     = 0x6e
	Instruction_RRA_absolute                     = 0x6f
	Instruction_BVS_relative                     = 0x70
	Instruction_ADC_indirect_y                   = 0x71
	Instruction_KIL_8                            = 0x72
	Instruction_RRA_indirect_y                   = 0x73
	Instruction_NOP_zero_x_3                     = 0x74
	Instruction_ADC_zero_x                       = 0x75
	Instruction_ROR_zero_x                       = 0x76
	Instruction_RRA_zero_x                       = 0x77
	Instruction_SEI                              = 0x78
	Instruction_ADC_absolute_y                   = 0x79
	Instruction_NOP_4                            = 0x7a
	Instruction_RRA_absolute_y                   = 0x7b
	Instruction_NOP_absolute_x_4                 = 0x7c
	Instruction_ADC_absolute_x                   = 0x7d
	Instruction_ROR_absolute_x                   = 0x7e
	Instruction_RRA_absolute_x                   = 0x7f
	Instruction_NOP_immediate                    = 0x80
	Instruction_STA_indirect_x                   = 0x81
	Instruction_NOP_immediate_2                  = 0x82
	Instruction_SAX_indirect_x                   = 0x83
	Instruction_STY_zero                         = 0x84
	Instruction_STA_zero                         = 0x85
	Instruction_STX_zero                         = 0x86
	Instruction_SAX_zero                         = 0x87
	Instruction_DEY                              = 0x88
	Instruction_TXA                              = 0x8a
	Instruction_STY_absolute                     = 0x8c
	Instruction_XAA                              = 0x8b
	Instruction_STA_absolute                     = 0x8d
	Instruction_STX_absolute                     = 0x8e
	Instruction_SAX_absolute                     = 0x8f
	Instruction_BCC_relative                     = 0x90
	Instruction_STA_indirect_y                   = 0x91
	Instruction_KIL_9                            = 0x92
	Instruction_AHX_indirect_y                   = 0x93
	Instruction_STY_zero_x                       = 0x94
	Instruction_STA_zero_x                       = 0x95
	Instruction_STX_zero_y                       = 0x96
	Instruction_SAX_zero_y                       = 0x97
	Instruction_TYA                              = 0x98
	Instruction_STA_absolute_y                   = 0x99
	Instruction_TXS                              = 0x9a
	Instruction_SHY                              = 0x9c
	Instruction_STA_absolute_x                   = 0x9d
	Instruction_SHX                              = 0x9e
	Instruction_AHX_absolute_y                   = 0x9f
	Instruction_LDY_immediate                    = 0xa0
	Instruction_LDA_indirect_x                   = 0xa1
	Instruction_LDX_immediate                    = 0xa2
	Instruction_LAX_indirect_x                   = 0xa3
	Instruction_LDY_zero                         = 0xa4
	Instruction_LDA_zero                         = 0xa5
	Instruction_LDX_zero                         = 0xa6
	Instruction_LAX_zero                         = 0xa7
	Instruction_TAY                              = 0xa8
	Instruction_LDA_immediate                    = 0xa9
	Instruction_TAX                              = 0xaa
	Instruction_LAX_immediate                    = 0xab
	Instruction_LDY_absolute                     = 0xac
	Instruction_LDA_absolute                     = 0xad
	Instruction_LDX_absolute                     = 0xae
	Instruction_LAX_absolute                     = 0xaf
	Instruction_BCS_relative                     = 0xb0
	Instruction_LDA_indirect_y                   = 0xb1
	Instruction_KIL_10                           = 0xb2
	Instruction_LAX_indirect_y                   = 0xb3
	Instruction_LDY_zero_x                       = 0xb4
	Instruction_LDA_zero_x                       = 0xb5
	Instruction_LDX_zero_y                       = 0xb6
	Instruction_LAX_zero_y                       = 0xb7
	Instruction_CLV                              = 0xb8
	Instruction_LDA_absolute_y                   = 0xb9
	Instruction_TSX                              = 0xba
	Instruction_LAS                              = 0xbb
	Instruction_LDY_absolute_x                   = 0xbc
	Instruction_LDA_absolute_x                   = 0xbd
	Instruction_LDX_absolute_y                   = 0xbe
	Instruction_LAX_absolute_y                   = 0xbf
	Instruction_CPY_immediate                    = 0xc0
	Instruction_CMP_indirect_x                   = 0xc1
	Instruction_DCP_indirect_x                   = 0xc3
	Instruction_CPY_zero                         = 0xc4
	Instruction_CMP_zero                         = 0xc5
	Instruction_DEC_zero                         = 0xc6
	Instruction_DCP_zero                         = 0xc7
	Instruction_INY                              = 0xc8
	Instruction_CMP_immediate                    = 0xc9
	Instruction_DEX                              = 0xca
	Instruction_AXS                              = 0xcb
	Instruction_CPY_absolute                     = 0xcc
	Instruction_CMP_absolute                     = 0xcd
	Instruction_DEC_absolute                     = 0xce
	Instruction_DCP_absolute                     = 0xcf
	Instruction_BNE                              = 0xd0
	Instruction_CMP_indirect_y                   = 0xd1
	Instruction_KIL_11                           = 0xd2
	Instruction_DCP_indirect_y                   = 0xd3
	Instruction_NOP_zero_x_4                     = 0xd4
	Instruction_CMP_zero_x                       = 0xd5
	Instruction_DEC_zero_x                       = 0xd6
	Instruction_DCP_zero_x                       = 0xd7
	Instruction_CLD                              = 0xd8
	Instruction_CMP_absolute_y                   = 0xd9
	Instruction_NOP_5                            = 0xda
	Instruction_DCP_absolute_y                   = 0xdb
	Instruction_NOP_absolute_x_5                 = 0xdc
	Instruction_CMP_absolute_x                   = 0xdd
	Instruction_DEC_absolute_x                   = 0xde
	Instruction_DCP_absolute_x                   = 0xdf
	Instruction_CPX_immediate                    = 0xe0
	Instruction_SBC_indirect_x                   = 0xe1
	Instruction_ISC_indirect_x                   = 0xe3
	Instruction_CPX_zero                         = 0xe4
	Instruction_SBC_zero                         = 0xe5
	Instruction_INC_zero                         = 0xe6
	Instruction_ISC_zero                         = 0xe7
	Instruction_INX                              = 0xe8
	Instruction_SBC_immediate                    = 0xe9
	Instruction_NOP_6                            = 0xea
	Instruction_SBC_immediate_1                  = 0xeb
	Instruction_CPX_absolute                     = 0xec
	Instruction_SBC_absolute                     = 0xed
	Instruction_INC_absolute                     = 0xee
	Instruction_ISC_absolute                     = 0xef
	Instruction_BEQ_relative                     = 0xf0
	Instruction_SBC_indirect_y                   = 0xf1
	Instruction_KIL_12                           = 0xf2
	Instruction_ISC_indirect_y                   = 0xf3
	Instruction_NOP_zero_x_5                     = 0xf4
	Instruction_SBC_zero_x                       = 0xf5
	Instruction_INC_zero_x                       = 0xf6
	Instruction_ISC_zero_x                       = 0xf7
	Instruction_SED                              = 0xf8
	Instruction_SBC_absolute_y                   = 0xf9
	Instruction_NOP_7                            = 0xfa
	Instruction_ISC_absolute_y                   = 0xfb
	Instruction_NOP_absolute_x_6                 = 0xfc
	Instruction_SBC_absolute_x                   = 0xfd
	Instruction_INC_absolute_x                   = 0xfe
	Instruction_ISC_absolute_x                   = 0xff
)
View Source
const (
	PPUCTRL   uint16 = 0x2000
	PPUMASK   uint16 = 0x2001
	PPUSTATUS uint16 = 0x2002
	OAMADDR   uint16 = 0x2003
	OAMDATA   uint16 = 0x2004
	PPUSCROLL uint16 = 0x2005
	PPUADDR   uint16 = 0x2006
	PPUDATA   uint16 = 0x2007
	OAMDMA    uint16 = 0x4014
)

Special PPU memory-mapped locations

View Source
const (
	APUPulse1DutyCycle   = 0x4000
	APUPulse1Sweep       = 0x4001
	APUPulse1Timer       = 0x4002
	APUPulse1Length      = 0x4003
	APUPulse2DutyCycle   = 0x4004
	APUPulse2Sweep       = 0x4005
	APUPulse2Timer       = 0x4006
	APUPulse2Length      = 0x4007
	APUTriangleCounter   = 0x4008
	APUTriangleIgnore    = 0x4009
	APUTriangleTimerLow  = 0x400A
	APUTriangleTimerHigh = 0x400B
	APUNoiseEnvelope     = 0x400c
	APUNoiseMode         = 0x400e
	APUNoiseIgnore       = 0x400d
	APUNoiseLength       = 0x400f
	APUDMCEnable         = 0x4010
	APUDMCLoad           = 0x4011
	APUDMCAddress        = 0x4012
	APUDMCLength         = 0x4013
	APUChannelEnable     = 0x4015
	APUFrameCounter      = 0x4017
	APUStatus            = 0x4015 // for reading
)

APU memory-mapped locations

View Source
const (
	INPUT_POLL = 0x4016
	JOYPAD1    = 0x4016
	JOYPAD2    = 0x4017
)

Input memory-mapped locations

View Source
const (
	NametableMirrorVertical = iota
	NametableMirrorHorizontal
	NametableMirrorScreenA
	NametableMirrorScreenB
)
View Source
const (
	SpriteSize8x16 = iota
	SpriteSize8x8
)
View Source
const BRKVector uint16 = 0xfffe
View Source
const CPUSpeed float64 = 1.789773e6

http://wiki.nesdev.org/w/index.php/Cycle_reference_chart#Clock_rates * NTSC 2c0c clock speed is 21.47~ MHz ÷ 12 = 1.789773 MHz * Every second we should run this many cycles

View Source
const IRQVector uint16 = 0xfffe
View Source
const NMIVector uint16 = 0xfffa
View Source
const (
	NSFActionTogglePause = iota
)
View Source
const OverscanPixels = 8

The number of pixels to hide on the top and bottom. Note * that the total visible height is VideoHeight-OverscanPixels*2

View Source
const ResetVector uint16 = 0xfffc
View Source
const VideoHeight = 240
View Source
const VideoWidth = 256

The standard size that the PPU will output

Variables

View Source
var ApuDebug int = 0
View Source
var MaxCyclesReached error = errors.New("maximum cycles reached")
View Source
var TriangleWaveForm []byte = []byte{
	15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
	0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
}

Functions

func ButtonName

func ButtonName(button Button) string

func IsNESFile

func IsNESFile(path string) bool

func IsNSFFile

func IsNSFFile(path string) bool

func NewMemory

func NewMemory(size int) []byte

func PlayNSF

func PlayNSF(nsf NSFFile, track byte, audioOut chan []float32, sampleRate float32, actions chan NSFActions, mainQuit context.Context) error

https://wiki.nesdev.org/w/index.php/NSF

Types

type APUState

type APUState struct {
	/* APU cycles, 1 apu cycle for every 2 cpu cycles */
	Cycles float64 `json:"cycles"`
	/* frame sequencer clock, ticks at 240hz */
	Clock uint64 `json:"clock"`
	/* if true then apu is in 4-step mode that generates interrupts
	 * otherwise if false then apu is in 5-step mode with no interrupts
	 */
	FrameMode           bool    `json:"framemode"`
	UpdatedFrameCounter float64 `json:"framecounter"`
	InterruptInhibit    bool    `json:"interruptinhibit"`
	FrameIRQAsserted    bool    `json:"frameirq"`

	SampleCycles   float64   `json:"samplecycles"`
	SampleBuffer   []float32 `json:"samplebuffer"`
	SamplePosition int       `json:"sampleposition"`

	Pulse1   Pulse    `json:"pulse1"`
	Pulse2   Pulse    `json:"pulse2"`
	Triangle Triangle `json:"triangle"`
	Noise    Noise    `json:"noise"`
	DMC      DMC      `json:"dmc"`

	EnableNoise    bool `json:"enablenoise"`
	EnableTriangle bool `json:"enabletriangle"`
	EnablePulse2   bool `json:"enablepulse2"`
	EnablePulse1   bool `json:"enablepulse1"`
}

func MakeAPU

func MakeAPU() APUState

func (*APUState) Copy

func (apu *APUState) Copy() APUState

func (*APUState) GenerateSample

func (apu *APUState) GenerateSample() float32

func (*APUState) HalfFrame

func (apu *APUState) HalfFrame()

Half frame actions: length counters and sweep units

func (*APUState) IsIRQAsserted

func (apu *APUState) IsIRQAsserted() bool

func (*APUState) QuarterFrame

func (apu *APUState) QuarterFrame()

Quarter frame actions: envelope and triangle's linear counter

func (*APUState) ReadStatus

func (apu *APUState) ReadStatus() byte

func (*APUState) Run

func (apu *APUState) Run(apuCycles float64, cyclesPerSample float64, cpu *CPUState) []float32

func (*APUState) WriteChannelEnable

func (apu *APUState) WriteChannelEnable(value byte, cpu *CPUState)

func (*APUState) WriteDMCAddress

func (apu *APUState) WriteDMCAddress(value byte)

func (*APUState) WriteDMCEnable

func (apu *APUState) WriteDMCEnable(value byte)

func (*APUState) WriteDMCLength

func (apu *APUState) WriteDMCLength(value byte)

func (*APUState) WriteDMCLoad

func (apu *APUState) WriteDMCLoad(value byte)

func (*APUState) WriteFrameCounter

func (apu *APUState) WriteFrameCounter(value byte)

func (*APUState) WriteNoiseEnvelope

func (apu *APUState) WriteNoiseEnvelope(value byte)

func (*APUState) WriteNoiseLength

func (apu *APUState) WriteNoiseLength(value byte)

func (*APUState) WriteNoiseMode

func (apu *APUState) WriteNoiseMode(value byte)

func (*APUState) WritePulse1Duty

func (apu *APUState) WritePulse1Duty(value byte)

func (*APUState) WritePulse1Length

func (apu *APUState) WritePulse1Length(value byte)

func (*APUState) WritePulse1Sweep

func (apu *APUState) WritePulse1Sweep(value byte)

func (*APUState) WritePulse1Timer

func (apu *APUState) WritePulse1Timer(value byte)

func (*APUState) WritePulse2Duty

func (apu *APUState) WritePulse2Duty(value byte)

func (*APUState) WritePulse2Length

func (apu *APUState) WritePulse2Length(value byte)

func (*APUState) WritePulse2Sweep

func (apu *APUState) WritePulse2Sweep(value byte)

func (*APUState) WritePulse2Timer

func (apu *APUState) WritePulse2Timer(value byte)

func (*APUState) WriteTriangleCounter

func (apu *APUState) WriteTriangleCounter(value byte)

func (*APUState) WriteTriangleTimerHigh

func (apu *APUState) WriteTriangleTimerHigh(value byte)

func (*APUState) WriteTriangleTimerLow

func (apu *APUState) WriteTriangleTimerLow(value byte)

type Button

type Button int
const (
	ButtonIndexA      Button = 0
	ButtonIndexB      Button = 1
	ButtonIndexSelect Button = 2
	ButtonIndexStart  Button = 3
	ButtonIndexUp     Button = 4
	ButtonIndexDown   Button = 5
	ButtonIndexLeft   Button = 6
	ButtonIndexRight  Button = 7
)

func AllButtons

func AllButtons() []Button

func NameToButton

func NameToButton(name string) Button

type ButtonMapping

type ButtonMapping map[Button]bool

type CPUState

type CPUState struct {
	A      byte   `json:"a"`
	X      byte   `json:"x"`
	Y      byte   `json:"y"`
	SP     byte   `json:"sp"`
	PC     uint16 `json:"pc"`
	Status byte   `json:"status"`

	Cycle uint64 `json:"cycle"`

	/* holds a reference to the 2k ram the cpu can directly access.
	 * this memory is mapped into Maps[] as well. Maps[] is redundant,
	 * and can be removed at some point.
	 */
	Ram       []byte   `json:"ram,omitempty"`
	Maps      [][]byte `json:"-"`
	StackBase uint16   `json:"stackbase"`

	PPU         PPUState `json:"ppu"`
	APU         APUState `json:"apu"`
	Debug       uint     `json:"debug,omitempty"`
	StallCycles int      `json:"stallcycles,omitempty"`

	/* controller input */
	Input *Input `json:"-"`

	Mapper MapperState `json:"mapper"`
}

func (*CPUState) BRK

func (cpu *CPUState) BRK()

func (*CPUState) Compare

func (cpu *CPUState) Compare(other *CPUState) error

func (*CPUState) ComputeIndirectX

func (cpu *CPUState) ComputeIndirectX(relative byte) uint16

func (*CPUState) ComputeIndirectY

func (cpu *CPUState) ComputeIndirectY(relative byte) (uint16, bool)

returns a new address and whether a page boundary was crossed

func (*CPUState) Copy

func (cpu *CPUState) Copy() CPUState

func (*CPUState) Equals

func (cpu *CPUState) Equals(other CPUState) bool

func (*CPUState) Execute

func (cpu *CPUState) Execute(instruction Instruction) error

func (*CPUState) Fetch

func (cpu *CPUState) Fetch(table InstructionTable) (Instruction, error)

func (*CPUState) GetCarryFlag

func (cpu *CPUState) GetCarryFlag() bool

func (*CPUState) GetDecimalFlag

func (cpu *CPUState) GetDecimalFlag() bool

func (*CPUState) GetInterruptDisableFlag

func (cpu *CPUState) GetInterruptDisableFlag() bool

func (*CPUState) GetMemoryPage

func (cpu *CPUState) GetMemoryPage(address uint16) []byte

func (*CPUState) GetNegativeFlag

func (cpu *CPUState) GetNegativeFlag() bool

func (*CPUState) GetOverflowFlag

func (cpu *CPUState) GetOverflowFlag() bool

func (*CPUState) GetZeroFlag

func (cpu *CPUState) GetZeroFlag() bool

func (*CPUState) Interrupt

func (cpu *CPUState) Interrupt()

func (*CPUState) IsIRQAsserted

func (cpu *CPUState) IsIRQAsserted() bool

func (*CPUState) Load

func (cpu *CPUState) Load(other *CPUState)

func (*CPUState) LoadMemory

func (cpu *CPUState) LoadMemory(address uint16) byte

func (*CPUState) LoadStack

func (cpu *CPUState) LoadStack(where byte) byte

func (*CPUState) MapMemory

func (cpu *CPUState) MapMemory(location uint16, memory []byte) error

func (*CPUState) NMI

func (cpu *CPUState) NMI()

NMI was set, so jump to the NMI routine

func (*CPUState) PopStack

func (cpu *CPUState) PopStack() byte

func (*CPUState) PushStack

func (cpu *CPUState) PushStack(value byte)

func (*CPUState) Reset

func (cpu *CPUState) Reset()

func (*CPUState) Run

func (cpu *CPUState) Run(table InstructionTable) error

func (*CPUState) SetBreakFlag

func (cpu *CPUState) SetBreakFlag(set bool)

func (*CPUState) SetCarryFlag

func (cpu *CPUState) SetCarryFlag(set bool)

func (*CPUState) SetDecimalFlag

func (cpu *CPUState) SetDecimalFlag(set bool)

func (*CPUState) SetInterruptDisableFlag

func (cpu *CPUState) SetInterruptDisableFlag(set bool)

func (*CPUState) SetMapper

func (cpu *CPUState) SetMapper(mapper Mapper)

func (*CPUState) SetNegativeFlag

func (cpu *CPUState) SetNegativeFlag(set bool)

func (*CPUState) SetOverflowFlag

func (cpu *CPUState) SetOverflowFlag(set bool)

func (*CPUState) SetStack

func (cpu *CPUState) SetStack(location uint16)

func (*CPUState) SetZeroFlag

func (cpu *CPUState) SetZeroFlag(zero bool)

func (*CPUState) Stall

func (cpu *CPUState) Stall(cycles int)

func (*CPUState) StoreMemory

func (cpu *CPUState) StoreMemory(address uint16, value byte)

func (*CPUState) StoreStack

func (cpu *CPUState) StoreStack(where byte, value byte)

func (*CPUState) String

func (cpu *CPUState) String() string

func (*CPUState) UnmapAllProgramMemory

func (cpu *CPUState) UnmapAllProgramMemory()

unmap the 32k block starting at 0x8000

func (*CPUState) UnmapMemory

func (cpu *CPUState) UnmapMemory(address uint16, length uint16) error

type DMC

type DMC struct {
	Irq             bool    `json:"irq"`
	Loop            bool    `json:"loop"`
	Frequency       float64 `json:"frequency"`
	Counter         float64 `json:"counter"`
	StartingAddress uint16  `json:"startingaddress"`
	Address         uint16  `json:"address"`
	Length          uint16  `json:"length"`
	BytesRemaining  uint16  `json:"bytesremaining"`
	OutputLevel     byte    `json:"outputlevel"`

	IRQAsserted bool `json:"irqasserted"`

	Silence bool `json:"silence"`

	ShiftRegister byte `json:"shift"`
	BitsRemaining byte `json:"bitsremaining"`

	SampleBuffer byte `json:"samplebuffer"`
}

func (*DMC) Copy

func (dmc *DMC) Copy() DMC

func (*DMC) GenerateSample

func (dmc *DMC) GenerateSample() byte

func (*DMC) LoadSample

func (dmc *DMC) LoadSample(cpu *CPUState)

func (*DMC) Reset

func (dmc *DMC) Reset()

func (*DMC) Run

func (dmc *DMC) Run(cycles float64, cpu *CPUState)

type Divider

type Divider struct {
	/* how many input clocks must pass before an output clock is generated */
	ClockPeriod uint16 `json:"period"`
	Count       int16  `json:"count"`
}

func (*Divider) Clock

func (divider *Divider) Clock() bool

returns true if an output clock was generated

func (*Divider) Reset

func (divider *Divider) Reset()

type EnvelopeGenerator

type EnvelopeGenerator struct {
	Divider Divider `json:"divider"`
	Loop    bool    `json:"loop"`
	Disable bool    `json:"disable"`
	Value   byte    `json:"value"`
	Counter byte    `json:"counter"`
}

func (*EnvelopeGenerator) Reset

func (envelope *EnvelopeGenerator) Reset()

func (*EnvelopeGenerator) Set

func (envelope *EnvelopeGenerator) Set(loop bool, disable bool, value byte)

func (*EnvelopeGenerator) Tick

func (envelope *EnvelopeGenerator) Tick()

func (*EnvelopeGenerator) Volume

func (envelope *EnvelopeGenerator) Volume() byte

type HostInput

type HostInput interface {
	Get() ButtonMapping
}

type Input

type Input struct {
	Buttons  []bool
	NextRead byte
	Host     HostInput

	LastButtons   []bool
	RecordInput   bool
	RecordedInput chan RecordInput
}

func MakeInput

func MakeInput(host HostInput) *Input

func (*Input) Read

func (input *Input) Read() byte

func (*Input) Reset

func (input *Input) Reset()

type Instruction

type Instruction struct {
	Name     string
	Kind     InstructionType
	Operands []byte
}

func (*Instruction) Equals

func (instruction *Instruction) Equals(other Instruction) bool

func (*Instruction) Length

func (instruction *Instruction) Length() uint16

func (*Instruction) OperandByte

func (instruction *Instruction) OperandByte() (byte, error)

func (*Instruction) OperandWord

func (instruction *Instruction) OperandWord() (uint16, error)

func (*Instruction) String

func (instruction *Instruction) String() string

type InstructionDescription

type InstructionDescription struct {
	Name     string
	Operands byte
}

type InstructionReader

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

func NewInstructionReader

func NewInstructionReader(data []byte) *InstructionReader

func (*InstructionReader) ReadInstruction

func (reader *InstructionReader) ReadInstruction() (Instruction, error)

instructions can vary in their size

type InstructionTable

type InstructionTable map[InstructionType]InstructionDescription

func MakeInstructionDescriptiontable

func MakeInstructionDescriptiontable() InstructionTable

type InstructionType

type InstructionType int

type JustKind

type JustKind struct {
	Kind int `json:"kind"`
}

type LengthCounter

type LengthCounter struct {
	Halt   bool `json:"halt"`
	Length byte `json:"length"`
}

func (*LengthCounter) Clear

func (length *LengthCounter) Clear()

func (*LengthCounter) SetLength

func (length *LengthCounter) SetLength(index byte)

func (*LengthCounter) Tick

func (length *LengthCounter) Tick()

type Mapper

type Mapper interface {
	// Write a value to the mapper address space
	Write(cpu *CPUState, address uint16, value byte) error
	// Read a value from the mapper address space
	Read(address uint16) byte
	// True if the irq line is asserted
	IsIRQAsserted() bool
	// Make a deep copy of this object
	Copy() Mapper
	// Return an int that identifies this type of mapper
	Kind() int
	// Return an error that describes any difference to another mapper, or nil if
	// there are no differences
	Compare(Mapper) error
}

func MakeMapper

func MakeMapper(mapper uint32, programRom []byte, chrMemory []byte) (Mapper, error)

func MakeMapper0

func MakeMapper0(bankMemory []byte) Mapper

func MakeMapper1

func MakeMapper1(bankMemory []byte, chrMemory []byte) Mapper

func MakeMapper2

func MakeMapper2(bankMemory []byte) Mapper

func MakeMapper3

func MakeMapper3(programRom []byte, chrMemory []byte) Mapper

func MakeMapper4

func MakeMapper4(programRom []byte, chrMemory []byte) Mapper

func MakeMapper7

func MakeMapper7(programRom []byte, chrMemory []byte) Mapper

func MakeMapper9

func MakeMapper9(programRom []byte, chrMemory []byte) Mapper

func MakeNSFMapper

func MakeNSFMapper(data []byte, loadAddress uint16) Mapper

type Mapper0

type Mapper0 struct {
	BankMemory []byte `json:"bank"`
}

func (*Mapper0) Compare

func (mapper *Mapper0) Compare(other Mapper) error

func (*Mapper0) Copy

func (mapper *Mapper0) Copy() Mapper

func (*Mapper0) IsIRQAsserted

func (mapper *Mapper0) IsIRQAsserted() bool

func (*Mapper0) Kind

func (mapper *Mapper0) Kind() int

func (*Mapper0) Read

func (mapper *Mapper0) Read(address uint16) byte

func (*Mapper0) Write

func (mapper *Mapper0) Write(cpu *CPUState, address uint16, value byte) error

type Mapper1

type Mapper1 struct {
	BankMemory      []byte `json:"bankmemory"`
	CharacterMemory []byte `json:"charmemory"`
	Last4kBank      int    `json:"last4kbank"`
	/* how many bits to left shift the next value */
	Shift int `json:"shift"`
	/* the value to pass to the mmc */
	Register uint8 `json:"register"`

	Mirror      byte `json:"mirror"`
	PrgBankMode byte `json:"prgbankmode"`
	ChrBankMode byte `json:"chrbankmode"`
	PrgBank     byte `json:"prgbank"`

	/* FIXME: this might get mapped from the bank memory, not sure */
	PRGRam []byte `json:"prgram"`
}

http://wiki.nesdev.org/w/index.php/MMC1

func (*Mapper1) Compare

func (mapper *Mapper1) Compare(other Mapper) error

func (*Mapper1) Copy

func (mapper *Mapper1) Copy() Mapper

func (*Mapper1) IsIRQAsserted

func (mapper *Mapper1) IsIRQAsserted() bool

func (*Mapper1) Kind

func (mapper *Mapper1) Kind() int

func (*Mapper1) Read

func (mapper *Mapper1) Read(address uint16) byte

func (*Mapper1) ReadBank

func (mapper *Mapper1) ReadBank(pageSize uint16, bank int, offset uint16) byte

Read at address 'offset' within the 32k bank given by 'bank'. * When bank = 0, the starting address is 0x0000 * When bank = 1, the starting address is 0x8000 * etc.

func (*Mapper1) Write

func (mapper *Mapper1) Write(cpu *CPUState, address uint16, value byte) error

type Mapper2

type Mapper2 struct {
	BankMemory      []byte `json:"bankmemory"`
	SaveRam         []byte `json:"saveram"`
	LastBankAddress uint32 `json:"lastaddress"`
	Bank            byte   `json:"bank"`
}

func (*Mapper2) Compare

func (mapper *Mapper2) Compare(other Mapper) error

func (*Mapper2) Copy

func (mapper *Mapper2) Copy() Mapper

func (*Mapper2) IsIRQAsserted

func (mapper *Mapper2) IsIRQAsserted() bool

func (*Mapper2) Kind

func (mapper *Mapper2) Kind() int

func (*Mapper2) Read

func (mapper *Mapper2) Read(address uint16) byte

func (*Mapper2) Write

func (mapper *Mapper2) Write(cpu *CPUState, address uint16, value byte) error

type Mapper3

type Mapper3 struct {
	ProgramRom []byte `json:"programrom"`
	BankMemory []byte `json:"bankmemory"`
}

func (*Mapper3) Compare

func (mapper *Mapper3) Compare(other Mapper) error

func (*Mapper3) Copy

func (mapper *Mapper3) Copy() Mapper

func (*Mapper3) IsIRQAsserted

func (mapper *Mapper3) IsIRQAsserted() bool

func (*Mapper3) Kind

func (mapper *Mapper3) Kind() int

func (*Mapper3) Read

func (mapper *Mapper3) Read(address uint16) byte

func (*Mapper3) Write

func (mapper *Mapper3) Write(cpu *CPUState, address uint16, value byte) error

type Mapper4

type Mapper4 struct {
	ProgramRom   []byte `json:"programrom"`
	CharacterRom []byte `json:"characterrom"`
	SaveRam      []byte `json:"saveram"`

	LastBank int `json:"lastbank"`

	IrqEnabled bool `json:"irqenabled"`
	IrqReload  byte `json:"irqreload"`
	IrqCounter byte `json:"irqcounter"`
	IrqPending bool `json:"irqpending"`

	WramEnabled bool `json:"wramenabled"`
	WramWrite   bool `json:"wramwrite"`

	ChrMode byte `json:"chrmode"`
	PrgMode byte `json:"prgmode"`
	/* used to select which of the chrRegister/prgRegister to write to */
	RegisterIndex byte `json:"register"`

	ChrRegister [6]byte `json:"chrregister"`
	PrgRegister [2]byte `json:"prgregister"`
}

func (*Mapper4) CharacterBlock

func (mapper *Mapper4) CharacterBlock(length uint32, page byte) []byte

func (*Mapper4) Compare

func (mapper *Mapper4) Compare(other Mapper) error

func (*Mapper4) Copy

func (mapper *Mapper4) Copy() Mapper

func (*Mapper4) IsIRQAsserted

func (mapper *Mapper4) IsIRQAsserted() bool

func (*Mapper4) Kind

func (mapper *Mapper4) Kind() int

func (*Mapper4) ProgramBlock

func (mapper *Mapper4) ProgramBlock(page byte) ([]byte, error)

func (*Mapper4) Read

func (mapper *Mapper4) Read(address uint16) byte

func (*Mapper4) ReadBank

func (mapper *Mapper4) ReadBank(offset uint16, bank int) byte

func (*Mapper4) Scanline

func (mapper *Mapper4) Scanline()

func (*Mapper4) SetChrBank

func (mapper *Mapper4) SetChrBank(ppu *PPUState) error

func (*Mapper4) Write

func (mapper *Mapper4) Write(cpu *CPUState, address uint16, value byte) error

type Mapper7

type Mapper7 struct {
	ProgramRom   []byte `json:"programrom"`
	CharacterRom []byte `json:"characterrom"`
	Bank         int    `json:"bank"`   // 0-7
	Mirror       int    `json:"mirror"` // 0=1ScA, 1=1ScB
}

func (*Mapper7) Compare

func (mapper *Mapper7) Compare(other Mapper) error

func (*Mapper7) Copy

func (mapper *Mapper7) Copy() Mapper

func (*Mapper7) IsIRQAsserted

func (mapper *Mapper7) IsIRQAsserted() bool

func (*Mapper7) Kind

func (mapper *Mapper7) Kind() int

func (*Mapper7) Read

func (mapper *Mapper7) Read(address uint16) byte

func (*Mapper7) ReadBank

func (mapper *Mapper7) ReadBank(address uint16, bank int) byte

func (*Mapper7) Write

func (mapper *Mapper7) Write(cpu *CPUState, address uint16, value byte) error

type Mapper9

type Mapper9 struct {
	ProgramRom   []byte `json:"programrom"`
	CharacterRom []byte `json:"characterrom"`
	Pages        int    `json:"pages"`

	PrgRegister byte    `json:"prg"`
	ChrRegister [4]byte `json:"chr"`
}

func (*Mapper9) CharacterBlock

func (mapper *Mapper9) CharacterBlock(pageSize uint16, register byte) []byte

func (*Mapper9) Compare

func (mapper *Mapper9) Compare(other Mapper) error

func (*Mapper9) Copy

func (mapper *Mapper9) Copy() Mapper

func (*Mapper9) IsIRQAsserted

func (mapper *Mapper9) IsIRQAsserted() bool

func (*Mapper9) Kind

func (mapper *Mapper9) Kind() int

func (*Mapper9) Read

func (mapper *Mapper9) Read(address uint16) byte

func (*Mapper9) ReadBank

func (mapper *Mapper9) ReadBank(offset uint16, bank int) byte

func (*Mapper9) SetChrBank

func (mapper *Mapper9) SetChrBank(ppu *PPUState)

func (*Mapper9) Write

func (mapper *Mapper9) Write(cpu *CPUState, address uint16, value byte) error

type MapperState

type MapperState struct {
	Kind   int    `json:"kind"`
	Mapper Mapper `json:"mapper"`
}

func (*MapperState) Compare

func (state *MapperState) Compare(other MapperState) error

func (*MapperState) Copy

func (state *MapperState) Copy() MapperState

func (*MapperState) Set

func (state *MapperState) Set(mapper Mapper)

func (*MapperState) UnmarshalJSON

func (state *MapperState) UnmarshalJSON(data []byte) error

type Memory

type Memory struct {
	Data []byte
}

func NewMemory2

func NewMemory2(size int) Memory

func (*Memory) Load

func (memory *Memory) Load(address uint16) byte

func (*Memory) Store

func (memory *Memory) Store(address uint16, value byte)

type NESFile

type NESFile struct {
	ProgramRom       []byte
	CharacterRom     []byte
	Mapper           uint32
	HorizontalMirror bool
	VerticalMirror   bool
	Path             string
}

func ParseNesFile

func ParseNesFile(path string, debug bool) (NESFile, error)

type NSFActions

type NSFActions int

type NSFFile

type NSFFile struct {
	LoadAddress  uint16
	InitAddress  uint16
	PlayAddress  uint16
	TotalSongs   byte
	StartingSong byte
	NTSCSpeed    uint16
	SongName     string
	Artist       string
	Copyright    string
	Data         []byte
}

func LoadNSF

func LoadNSF(path string) (NSFFile, error)

type NSFMapper

type NSFMapper struct {
	Data        []byte
	LoadAddress uint16
}

func (*NSFMapper) Compare

func (mapper *NSFMapper) Compare(other Mapper) error

func (*NSFMapper) Copy

func (mapper *NSFMapper) Copy() Mapper

func (*NSFMapper) IsIRQAsserted

func (mapper *NSFMapper) IsIRQAsserted() bool

func (*NSFMapper) Kind

func (mapper *NSFMapper) Kind() int

func (*NSFMapper) Read

func (mapper *NSFMapper) Read(address uint16) byte

func (*NSFMapper) Write

func (mapper *NSFMapper) Write(cpu *CPUState, address uint16, value byte) error

type NametableMirrorConfiguration

type NametableMirrorConfiguration int

func (NametableMirrorConfiguration) String

func (mirror NametableMirrorConfiguration) String() string

type NoInput

type NoInput struct {
}

func (*NoInput) Get

func (buttons *NoInput) Get() ButtonMapping

type Noise

type Noise struct {
	Length        LengthCounter     `json:"length"`
	Envelope      EnvelopeGenerator `json:"envelope"`
	Mode          byte              `json:"mode"`
	Timer         Timer             `json:"timer"`
	ShiftRegister uint16            `json:"shift"`
}

func (*Noise) Copy

func (noise *Noise) Copy() Noise

func (*Noise) GenerateSample

func (noise *Noise) GenerateSample() byte

func (*Noise) Run

func (noise *Noise) Run(cycles float64)

type PPUState

type PPUState struct {
	Flags byte `json:"flags"`
	Mask  byte `json:"mask"`
	/* http://wiki.nesdev.org/w/index.php/PPU_registers#PPUSTATUS */
	Status byte `json:"status"`

	/* counts in the y direction during rendering, from 0-262 */
	Scanline int `json:"scanline"`
	/* counts in the x direction during rendering, from 0-340 */
	ScanlineCycle         int    `json:"scanlinecycle"`
	TemporaryVideoAddress uint16 `json:"t_register"`   /* the t register */
	VideoAddress          uint16 `json:"videoaddress"` /* the v register */
	WriteState            byte   `json:"writestate"`   /* for writing to the video address or the t register */

	NametableMirror NametableMirrorConfiguration `json:"nametablemirror"`

	/* for scrolling */
	FineX byte `json:"finex"`

	/* maps an nes integer 0-256 to an RGB value */
	Palette [][]uint8 `json:"palette"`

	/* current sprites that will render on this scanline. a bit of a hack */
	CurrentSprites []Sprite `json:"sprites"`

	VideoMemory []byte `json:"videomemory"`

	/* the 2kb SRAM stored on the NES board.
	 * use nametable mirroring to map addresses to these ranges
	 * Nametable[0:0x400] should appear at 0x2000 and 0x2800 in vertical mirroring
	 * and 0x2000 and 0x2400 in horizontal mirroring.
	 * Nametable[0x400:0x800] should appear at 0x2400 and 0x2c00 in vertical mirroring
	 * and 0x2800 and 0x2c00 in horizontal mirroring.
	 *
	 * http://wiki.nesdev.org/w/index.php/PPU_nametables
	 */
	NametableMemory []byte `json:"nametablememory"`

	/* sprite memory */
	OAM        []byte `json:"oam"`
	OAMAddress int    `json:"oamaddress"`

	/* makes the ppu print stuff via log.Printf if set to a value > 0 */
	Debug uint8 `json:"-"`

	InternalVideoBuffer byte `json:"videobuffer"`

	/* how many times to shift out of the BackgroundPixels before needing to load a new tile */
	Shifts byte `json:"shifts"`

	/* each pixel is 4 bits, each tile is 8 pixels
	 * so first 32 bits is the first tile
	 * and second 32 bits is the next tile.
	 * As each pixel is rendered, the entire
	 * thing is shifted 4 pixels to the right.
	 * After 8 pixels are rendered, a new tile
	 * is read from memory, its pixels computed, and
	 * loaded into the upper 32 its of BackgroundPixels
	 */
	BackgroundPixels    uint64 `json:"backgroundpixels"`
	RawBackgroundPixels uint32 `json:"rawbackgroundpixels"`

	/* not sure if this is needed */
	HasSetSprite0 bool `json:"sprite0"`
}

func MakePPU

func MakePPU() PPUState

func (*PPUState) ConstructVideoAddress

func (ppu *PPUState) ConstructVideoAddress(fineY byte, nametable byte, coarseY byte, coarseX byte) uint16

func (*PPUState) ControlString

func (ppu *PPUState) ControlString() string

func (*PPUState) Copy

func (ppu *PPUState) Copy() PPUState

func (*PPUState) CopyCharacterRom

func (ppu *PPUState) CopyCharacterRom(base uint32, data []byte)

func (*PPUState) CopyOAM

func (ppu *PPUState) CopyOAM(data []byte)

func (*PPUState) DeconstructVideoAddress

func (ppu *PPUState) DeconstructVideoAddress() (byte, byte, byte, byte)

Returns fineY, nametable, coarseY, coarseX

func (*PPUState) GetBackgroundPatternTableBase

func (ppu *PPUState) GetBackgroundPatternTableBase() uint16

func (*PPUState) GetNMIOutput

func (ppu *PPUState) GetNMIOutput() bool

func (*PPUState) GetNameTableBaseAddress

func (ppu *PPUState) GetNameTableBaseAddress(index byte) uint16

func (*PPUState) GetNameTableIndex

func (ppu *PPUState) GetNameTableIndex() byte

func (*PPUState) GetSpritePatternTableBase

func (ppu *PPUState) GetSpritePatternTableBase() uint16

func (*PPUState) GetSpriteSize

func (ppu *PPUState) GetSpriteSize() SpriteSize

func (*PPUState) GetSpriteZeroHit

func (ppu *PPUState) GetSpriteZeroHit() bool

func (*PPUState) GetSprites

func (ppu *PPUState) GetSprites() []Sprite

func (*PPUState) GetVRamIncrement

func (ppu *PPUState) GetVRamIncrement() uint16

func (*PPUState) IncrementHorizontalAddress

func (ppu *PPUState) IncrementHorizontalAddress()

func (*PPUState) IncrementVerticalPosition

func (ppu *PPUState) IncrementVerticalPosition()

Bump the y scroll, wrapping the nametable if necessary

func (*PPUState) IsBackgroundEnabled

func (ppu *PPUState) IsBackgroundEnabled() bool

func (*PPUState) IsSpriteEnabled

func (ppu *PPUState) IsSpriteEnabled() bool

func (*PPUState) IsVerticalBlankFlagSet

func (ppu *PPUState) IsVerticalBlankFlagSet() bool

func (*PPUState) LoadBackgroundTile

func (ppu *PPUState) LoadBackgroundTile()

func (*PPUState) LoadNametableMemory

func (ppu *PPUState) LoadNametableMemory(address uint16) byte

func (*PPUState) MaskString

func (ppu *PPUState) MaskString() string

func (*PPUState) PreloadTiles

func (ppu *PPUState) PreloadTiles()

Load the first two tiles for the scanline

func (*PPUState) ReadOAM

func (ppu *PPUState) ReadOAM(address byte) byte

func (*PPUState) ReadStatus

func (ppu *PPUState) ReadStatus() byte

func (*PPUState) ReadVideoMemory

func (ppu *PPUState) ReadVideoMemory() byte

func (*PPUState) RenderPixel

func (ppu *PPUState) RenderPixel(scanLine int, cycle int, sprites []Sprite, screen *VirtualScreen) bool

Returns true for a sprite 0 hit

func (*PPUState) ResetHorizontalPosition

func (ppu *PPUState) ResetHorizontalPosition()

func (*PPUState) Run

func (ppu *PPUState) Run(cycles uint64, screen VirtualScreen, mapper Mapper) (bool, bool)

func (*PPUState) SetControllerFlags

func (ppu *PPUState) SetControllerFlags(value byte)

func (*PPUState) SetHorizontalMirror

func (ppu *PPUState) SetHorizontalMirror()

func (*PPUState) SetMask

func (ppu *PPUState) SetMask(value byte)

func (*PPUState) SetOAMAddress

func (ppu *PPUState) SetOAMAddress(value byte)

func (*PPUState) SetScreenAMirror

func (ppu *PPUState) SetScreenAMirror()

func (*PPUState) SetScreenBMirror

func (ppu *PPUState) SetScreenBMirror()

func (*PPUState) SetSpriteZeroHit

func (ppu *PPUState) SetSpriteZeroHit(on bool)

func (*PPUState) SetVerticalBlankFlag

func (ppu *PPUState) SetVerticalBlankFlag(on bool)

func (*PPUState) SetVerticalMirror

func (ppu *PPUState) SetVerticalMirror()

func (*PPUState) StoreNametableMemory

func (ppu *PPUState) StoreNametableMemory(address uint16, value byte)

func (*PPUState) ToggleDebug

func (ppu *PPUState) ToggleDebug()

func (*PPUState) UpdateMapper4Scanline

func (ppu *PPUState) UpdateMapper4Scanline(mapper Mapper)

A bit of a hack, maybe make this more elegant later

func (*PPUState) WriteAddress

func (ppu *PPUState) WriteAddress(value byte)

func (*PPUState) WriteOAM

func (ppu *PPUState) WriteOAM(value byte)

func (*PPUState) WriteScroll

func (ppu *PPUState) WriteScroll(value byte)

func (*PPUState) WriteVideoMemory

func (ppu *PPUState) WriteVideoMemory(value byte)

type Pulse

type Pulse struct {
	Name      string            `json:"name"`
	Sweep     Sweep             `json:"sweep"`
	Timer     Timer             `json:"timer"`
	Envelope  EnvelopeGenerator `json:"envelope"`
	Length    LengthCounter     `json:"length"`
	Frequency float32           `json:"frequency"`
	Phase     float32           `json:"phase"`
	Duty      byte              `json:"duty"`
	Sequencer SquareSequencer   `json:"sequencer"`
}

func (*Pulse) Copy

func (pulse *Pulse) Copy() Pulse

func (*Pulse) GenerateSample

func (pulse *Pulse) GenerateSample() byte

func (*Pulse) ParseSweep

func (pulse *Pulse) ParseSweep(value byte)

func (*Pulse) Run

func (pulse *Pulse) Run(cycles float64)

func (*Pulse) SetDuty

func (pulse *Pulse) SetDuty(duty byte)

type RecordInput

type RecordInput struct {
	Cycle      uint64
	Difference map[Button]bool
}

type Sprite

type Sprite struct {
	Tile            byte `json:"tile"`
	X               byte `json:"x"`
	Y               byte `json:"y"`
	Flip_horizontal bool `json:"fliphorizontal"`
	Flip_vertical   bool `json:"flipvertical"`
	Palette         byte `json:"palette"`
	Priority        byte `json:"priority"`
	Sprite0         bool `json:"sprite0"`
}

type SpriteSize

type SpriteSize int

type SquareSequencer

type SquareSequencer struct {
	Duty     byte `json:"duty"`
	Position byte `json:"position"`
}

func (*SquareSequencer) Run

func (sequencer *SquareSequencer) Run(clocks int)

func (*SquareSequencer) SetDuty

func (sequencer *SquareSequencer) SetDuty(duty byte)

func (*SquareSequencer) Value

func (sequencer *SquareSequencer) Value() byte

type Sweep

type Sweep struct {
	Divider    Divider `json:"divider"`
	Enabled    bool    `json:"enabled"`
	Negate     bool    `json:"negate"` // false is add to period, true is subtract from period
	ShiftCount byte    `json:"shift"`
}

func (*Sweep) Tick

func (sweep *Sweep) Tick(pulse1 bool, timer *Timer)

type Timer

type Timer struct {
	Divider Divider `json:"divider"`
	Cycles  float64 `json:"cycles"`
	Low     uint16  `json:"low"`
	High    uint16  `json:"high"`
}

func (*Timer) Period

func (timer *Timer) Period() uint16

func (*Timer) Reset

func (timer *Timer) Reset()

func (*Timer) Run

func (timer *Timer) Run(cycles float64) int

func (*Timer) SetPeriod

func (timer *Timer) SetPeriod(value uint16)

type Triangle

type Triangle struct {
	Timer                   Timer         `json:"timer"`
	Phase                   int           `json:"phase"`
	Length                  LengthCounter `json:"length"`
	ControlFlag             bool          `json:"control"`
	LinearCounterReloadFlag bool          `json:"linearcounterreloadflag"`
	LinearCounterReload     int           `json:"linearcounterreload"`
	LinearCounter           int           `json:"linearcounter"`
}

func (*Triangle) Copy

func (triangle *Triangle) Copy() Triangle

func (*Triangle) GenerateSample

func (triangle *Triangle) GenerateSample() byte

func (*Triangle) Run

func (triangle *Triangle) Run(cycles float64)

func (*Triangle) TickLengthCounter

func (triangle *Triangle) TickLengthCounter()

func (*Triangle) TickLinearCounter

func (triangle *Triangle) TickLinearCounter()

type VirtualScreen

type VirtualScreen struct {
	Width  int
	Height int
	Buffer []uint32
}

func MakeVirtualScreen

func MakeVirtualScreen(width int, height int) VirtualScreen

func (*VirtualScreen) Area

func (screen *VirtualScreen) Area() int

func (*VirtualScreen) Clear

func (screen *VirtualScreen) Clear()

func (*VirtualScreen) ClearToColor

func (screen *VirtualScreen) ClearToColor(red uint8, green uint8, blue uint8)

func (*VirtualScreen) Copy

func (screen *VirtualScreen) Copy() VirtualScreen

func (*VirtualScreen) CopyFrom

func (screen *VirtualScreen) CopyFrom(copyFrom *VirtualScreen)

func (*VirtualScreen) DrawPoint

func (screen *VirtualScreen) DrawPoint(x int32, y int32, rgb []uint8)

func (*VirtualScreen) GetRGBA

func (screen *VirtualScreen) GetRGBA(x int, y int) (uint8, uint8, uint8, uint8)

Jump to

Keyboard shortcuts

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