Documentation ¶
Index ¶
- Constants
- Variables
- func Disassemble(opcode Word, cpu *Cpu, p uint16)
- func Init(contents []byte, audioBuf func(int16), getter GetButtonFunc) (chan []uint32, error)
- func LoadGameState()
- func Pause()
- func RunSystem()
- func SaveGameState()
- func StepFrame()
- func TogglePause()
- type Anrom
- type Apu
- func (a *Apu) ComputeSample() int16
- func (a *Apu) FrameSequencerStep()
- func (a *Apu) Init(buffer func(int16))
- func (a *Apu) PushSample()
- func (a *Apu) ReadStatus() Word
- func (a *Apu) RegRead(addr int) (Word, error)
- func (a *Apu) RegWrite(v Word, addr int)
- func (a *Apu) RunHipassStrong(s int16) int16
- func (a *Apu) RunHipassWeak(s int16) int16
- func (a *Apu) Step()
- func (a *Apu) WriteControlFlags1(v Word)
- func (a *Apu) WriteControlFlags2(v Word)
- func (a *Apu) WriteDmcDirectLoad(v Word)
- func (a *Apu) WriteDmcFlags(v Word)
- func (a *Apu) WriteDmcSampleAddress(v Word)
- func (a *Apu) WriteDmcSampleLength(v Word)
- func (a *Apu) WriteNoiseBase(v Word)
- func (a *Apu) WriteNoiseLength(v Word)
- func (a *Apu) WriteNoisePeriod(v Word)
- func (a *Apu) WriteSquare1Control(v Word)
- func (a *Apu) WriteSquare1High(v Word)
- func (a *Apu) WriteSquare1Low(v Word)
- func (a *Apu) WriteSquare1Sweeps(v Word)
- func (a *Apu) WriteSquare2Control(v Word)
- func (a *Apu) WriteSquare2High(v Word)
- func (a *Apu) WriteSquare2Low(v Word)
- func (a *Apu) WriteSquare2Sweeps(v Word)
- func (a *Apu) WriteTriangleControl(v Word)
- func (a *Apu) WriteTriangleHigh(v Word)
- func (a *Apu) WriteTriangleLow(v Word)
- type Cnrom
- type Controller
- type Cpu
- func (c *Cpu) Adc(location uint16)
- func (c *Cpu) And(location uint16)
- func (c *Cpu) Asl(location uint16)
- func (c *Cpu) AslAcc()
- func (c *Cpu) Bcc()
- func (c *Cpu) Bcs()
- func (c *Cpu) Beq()
- func (c *Cpu) Bit(location uint16)
- func (c *Cpu) Bmi()
- func (c *Cpu) Bne()
- func (c *Cpu) Bpl()
- func (c *Cpu) Brk()
- func (c *Cpu) Bvc()
- func (c *Cpu) Bvs()
- func (c *Cpu) Clc()
- func (c *Cpu) Cld()
- func (c *Cpu) Cli()
- func (c *Cpu) Clv()
- func (c *Cpu) Cmp(location uint16)
- func (c *Cpu) Compare(register Word, value Word)
- func (c *Cpu) Cpx(location uint16)
- func (c *Cpu) Cpy(location uint16)
- func (c *Cpu) Dec(location uint16)
- func (c *Cpu) Dex()
- func (c *Cpu) Dey()
- func (c *Cpu) Eor(location uint16)
- func (c *Cpu) Inc(location uint16)
- func (c *Cpu) Init()
- func (c *Cpu) InstrInit()
- func (c *Cpu) Inx()
- func (c *Cpu) Iny()
- func (c *Cpu) Jmp(location uint16)
- func (c *Cpu) Jsr(location uint16)
- func (c *Cpu) Lda(location uint16)
- func (c *Cpu) Ldx(location uint16)
- func (c *Cpu) Ldy(location uint16)
- func (c *Cpu) Lsr(location uint16)
- func (c *Cpu) LsrAcc()
- func (c *Cpu) Ora(location uint16)
- func (c *Cpu) PerformIrq()
- func (c *Cpu) PerformNmi()
- func (c *Cpu) PerformReset()
- func (c *Cpu) Pha()
- func (c *Cpu) Php()
- func (c *Cpu) Pla()
- func (c *Cpu) Plp()
- func (c *Cpu) RequestInterrupt(i int)
- func (c *Cpu) Reset()
- func (c *Cpu) Rol(location uint16)
- func (c *Cpu) RolAcc()
- func (c *Cpu) Ror(location uint16)
- func (c *Cpu) RorAcc()
- func (c *Cpu) Rti()
- func (c *Cpu) Rts()
- func (c *Cpu) Sbc(location uint16)
- func (c *Cpu) Sec()
- func (c *Cpu) Sed()
- func (c *Cpu) Sei()
- func (c *Cpu) SetBranchCycleCount(a uint16)
- func (c *Cpu) SetResetVector()
- func (c *Cpu) Sta(location uint16)
- func (c *Cpu) Step() int
- func (c *Cpu) Stx(location uint16)
- func (c *Cpu) Sty(location uint16)
- func (c *Cpu) Tax()
- func (c *Cpu) Tay()
- func (c *Cpu) Tsx()
- func (c *Cpu) Txa()
- func (c *Cpu) Txs()
- func (c *Cpu) Tya()
- type Dmc
- type Envelope
- type EventHandler
- type Flags
- type GetButtonFunc
- type JsEventHandler
- type Mapper
- type Masks
- type Memory
- type MemoryError
- type Mmc1
- func (m *Mmc1) BatteryBacked() bool
- func (m *Mmc1) Read(a int) Word
- func (m *Mmc1) ReadTile(a int) []Word
- func (m *Mmc1) ReadVram(a int) Word
- func (m *Mmc1) RegisterNumber(a int) int
- func (m *Mmc1) SetRegister(reg int, v int)
- func (m *Mmc1) Write(v Word, a int)
- func (m *Mmc1) WriteVram(v Word, a int)
- type Mmc2
- func (m *Mmc2) BatteryBacked() bool
- func (m *Mmc2) ChrBankSelect(v Word, b int)
- func (m *Mmc2) LatchTrigger(a int)
- func (m *Mmc2) Load()
- func (m *Mmc2) MirroringSelect(v Word)
- func (m *Mmc2) PrgBankSelect(v Word)
- func (m *Mmc2) Read(a int) Word
- func (m *Mmc2) ReadTile(a int) []Word
- func (m *Mmc2) ReadVram(a int) Word
- func (m *Mmc2) RegisterNumber(a int) int
- func (m *Mmc2) Write(v Word, a int)
- func (m *Mmc2) WriteVram(v Word, a int)
- type Mmc3
- func (m *Mmc3) BankData(v int)
- func (m *Mmc3) BankSelect(v int)
- func (m *Mmc3) BatteryBacked() bool
- func (m *Mmc3) Hook()
- func (m *Mmc3) IrqDisable(v int)
- func (m *Mmc3) IrqEnable(v int)
- func (m *Mmc3) IrqLatch(v int)
- func (m *Mmc3) IrqReload(v int)
- func (m *Mmc3) Load()
- func (m *Mmc3) RamProtection(v int)
- func (m *Mmc3) Read(a int) Word
- func (m *Mmc3) ReadTile(a int) []Word
- func (m *Mmc3) ReadVram(a int) Word
- func (m *Mmc3) RegisterNumber(a int) int
- func (m *Mmc3) SetMirroring(v int)
- func (m *Mmc3) Write(v Word, a int)
- func (m *Mmc3) WriteVram(v Word, a int)
- type Mmc5
- func (m *Mmc5) BatteryBacked() bool
- func (m *Mmc5) Load()
- func (m *Mmc5) NotifyScanline()
- func (m *Mmc5) Read(a int) Word
- func (m *Mmc5) ReadIrqStatus() Word
- func (m *Mmc5) ReadTile(a int) []Word
- func (m *Mmc5) ReadVram(a int) Word
- func (m *Mmc5) SetNametableMapping(v Word)
- func (m *Mmc5) SwapBgVram()
- func (m *Mmc5) SwapSpriteVram()
- func (m *Mmc5) Write(v Word, a int)
- func (m *Mmc5) WriteVram(v Word, a int)
- type Nametable
- type Noise
- type NoopEventHandler
- type Nrom
- type Pixel
- type Ppu
- func (p *Ppu) Init() chan []uint32
- func (p *Ppu) ReadData() (r Word, err error)
- func (p *Ppu) ReadOamData() (Word, error)
- func (p *Ppu) ReadStatus() (s Word, e error)
- func (p *Ppu) RegRead(a int) (Word, error)
- func (p *Ppu) RegWrite(v Word, a int)
- func (p *Ppu) Step()
- func (p *Ppu) WriteAddress(v Word)
- func (p *Ppu) WriteControl(v Word)
- func (p *Ppu) WriteData(v Word)
- func (p *Ppu) WriteDma(v Word)
- func (p *Ppu) WriteMask(v Word)
- func (p *Ppu) WriteOamAddress(v Word)
- func (p *Ppu) WriteOamData(v Word)
- func (p *Ppu) WriteScroll(v Word)
- type Registers
- type SpriteData
- type Square
- type Triangle
- type Unrom
- type Word
Constants ¶
View Source
const ( InterruptNone = iota InterruptIrq InterruptReset InterruptNmi )
View Source
const ( HiPassStrong = 225574 HiPassWeak = 57593 )
View Source
const ( ButtonA = iota ButtonB ButtonSelect ButtonStart ButtonUp ButtonDown ButtonLeft ButtonRight )
View Source
const ( SaveState = iota LoadState )
View Source
const ( BankUpper = iota BankLower Size1k = 0x0400 Size2k = 0x0800 Size4k = 0x1000 Size8k = 0x2000 Size16k = 0x4000 Size32k = 0x8000 )
View Source
const ( RegisterPrgBankSelect = iota RegisterChrBank1Select RegisterChrBank2Select RegisterChrBank3Select RegisterChrBank4Select RegisterMirroringSelect )
View Source
const ( ChrBank2k0000 = 0 ChrBank2k0800 = 1 ChrBank1k1000 = 2 ChrBank1k1400 = 3 ChrBank1k1800 = 4 ChrBank1k1C00 = 5 PrgBank8k8000 = 6 PrgBank8kA000 = 7 PrgBankSwapModeLow = 0 PrgBankSwapModeHigh = 1 ChrA12InversionModeLow = 0 ChrA12InversionModeHigh = 1 RegisterBankSelect = iota RegisterBankData RegisterMirroring RegisterPrgRamProtect RegisterIrqLatch RegisterIrqReload RegisterIrqDisable RegisterIrqEnable )
View Source
const ( MirroringVertical = iota MirroringHorizontal MirroringSingleUpper MirroringSingleLower )
View Source
const ( StatusSpriteOverflow = iota StatusSprite0Hit StatusVblankStarted )
Variables ¶
View Source
var ( SquareLookup = []int{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, } TriangleLookup = []int16{ 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, } NoiseLookup = []int{ 4, 8, 16, 32, 64, 96, 128, 160, 202, 254, 380, 508, 762, 1016, 2034, 4068, } DmcFrequency = []int{ 428, 380, 340, 320, 286, 254, 226, 214, 190, 160, 142, 128, 106, 84, 72, 54, } LengthTable = []Word{ 10, 254, 20, 2, 40, 4, 80, 6, 160, 8, 60, 10, 14, 12, 26, 14, 12, 16, 24, 18, 48, 20, 96, 22, 192, 24, 72, 26, 16, 28, 32, 30, } )
View Source
var ( AudioEnabled = true GameName string SaveStateFile string BatteryRamFile string Handler EventHandler )
View Source
var (
PaletteRgb = []uint32{
0x666666, 0x002A88, 0x1412A7, 0x3B00A4, 0x5C007E,
0x6E0040, 0x6C0600, 0x561D00, 0x333500, 0x0B4800,
0x005200, 0x004F08, 0x00404D, 0x000000, 0x000000,
0x000000, 0xADADAD, 0x155FD9, 0x4240FF, 0x7527FE,
0xA01ACC, 0xB71E7B, 0xB53120, 0x994E00, 0x6B6D00,
0x388700, 0x0C9300, 0x008F32, 0x007C8D, 0x000000,
0x000000, 0x000000, 0xFFFEFF, 0x64B0FF, 0x9290FF,
0xC676FF, 0xF36AFF, 0xFE6ECC, 0xFE8170, 0xEA9E22,
0xBCBE00, 0x88D800, 0x5CE430, 0x45E082, 0x48CDDE,
0x4F4F4F, 0x000000, 0x000000, 0xFFFEFF, 0xC0DFFF,
0xD3D2FF, 0xE8C8FF, 0xFBC2FF, 0xFEC4EA, 0xFECCC5,
0xF7D8A5, 0xE4E594, 0xCFEF96, 0xBDF4AB, 0xB3F3CC,
0xB5EBF2, 0xB8B8B8, 0x000000, 0x000000,
}
)
Functions ¶
func Disassemble ¶
func Init ¶
func Init(contents []byte, audioBuf func(int16), getter GetButtonFunc) (chan []uint32, error)
func LoadGameState ¶
func LoadGameState()
func SaveGameState ¶
func SaveGameState()
func TogglePause ¶
func TogglePause()
Types ¶
type Anrom ¶
type Anrom struct { RomBanks [][]Word VromBanks [][]Word PrgBankCount int ChrRomCount int Battery bool Data []byte PrgUpperBank int PrgLowerBank int }
func (*Anrom) BatteryBacked ¶
type Apu ¶
type Apu struct { Square1 Square Square2 Square Triangle Noise Dmc IrqEnabled bool IrqActive bool HipassStrong int64 HipassWeak int64 FrameCounter int FrameTick int LastFrameTick int PulseOut []float64 TndOut [203]float64 Sample int16 Buffer func(int16) }
func (*Apu) ComputeSample ¶
func (*Apu) FrameSequencerStep ¶
func (a *Apu) FrameSequencerStep()
func (*Apu) PushSample ¶
func (a *Apu) PushSample()
func (*Apu) RunHipassStrong ¶
func (*Apu) RunHipassWeak ¶
type Cnrom ¶
type Cnrom struct { RomBanks [][]Word VromBanks [][]Word PrgBankCount int ChrRomCount int Battery bool Data []byte ActiveBank int }
func (*Cnrom) BatteryBacked ¶
type Controller ¶
type Controller struct { ButtonState [16]Word StrobeState int LastWrite Word LastYAxis [2]int LastXAxis [2]int // contains filtered or unexported fields }
func NewController ¶
func NewController(getter GetButtonFunc) *Controller
func (*Controller) KeyDown ¶
func (c *Controller) KeyDown(e interface{}, offset int)
func (*Controller) KeyUp ¶
func (c *Controller) KeyUp(e interface{}, offset int)
func (*Controller) Read ¶
func (c *Controller) Read() (r Word)
func (*Controller) SetButtonState ¶
func (c *Controller) SetButtonState(button int, v Word, offset int)
func (*Controller) Write ¶
func (c *Controller) Write(v Word)
type Cpu ¶
type Cpu struct { X Word Y Word A Word P Word CycleCount int StackPointer Word Opcode Word Verbose bool Accurate bool InstrOpcodes [0xFF]func() ProgramCounter uint16 InterruptRequested int CyclesToWait int Timestamp int }
func (*Cpu) PerformIrq ¶
func (c *Cpu) PerformIrq()
func (*Cpu) PerformNmi ¶
func (c *Cpu) PerformNmi()
func (*Cpu) PerformReset ¶
func (c *Cpu) PerformReset()
func (*Cpu) RequestInterrupt ¶
func (*Cpu) SetBranchCycleCount ¶
func (*Cpu) SetResetVector ¶
func (c *Cpu) SetResetVector()
type Dmc ¶
type Dmc struct { Enabled bool IrqEnabled bool LoopEnabled bool RateIndex int RateCounter int DirectLoad int DirectCounter int Data Word Sample int16 SampleAddress int CurrentAddress uint16 SampleLength int SampleCounter int ShiftCounter int Frequency int HasSample bool }
func (*Dmc) FillSample ¶
func (d *Dmc) FillSample()
type Envelope ¶
type Envelope struct { Volume Word Counter Word DecayRate Word DecayCounter Word DecayEnabled bool LoopEnabled bool Disabled bool Reset bool }
func (*Envelope) ClockDecay ¶
func (e *Envelope) ClockDecay()
type EventHandler ¶
type EventHandler interface {
Handle(event string)
}
type GetButtonFunc ¶
type GetButtonFunc func(interface{}) int
type JsEventHandler ¶
type JsEventHandler struct {
// contains filtered or unexported fields
}
func NewJsEventHandler ¶
func NewJsEventHandler(filename string) *JsEventHandler
func (*JsEventHandler) Handle ¶
func (handler *JsEventHandler) Handle(event string)
func (*JsEventHandler) ReloadFile ¶
func (handler *JsEventHandler) ReloadFile(filename string)
type Mapper ¶
type Memory ¶
type Memory []Word
var ( Ram Memory Pads [2]*Controller )
func (Memory) ReadMirroredRam ¶
func (Memory) WriteMirroredRam ¶
type MemoryError ¶
type MemoryError struct {
ErrorText string
}
func (MemoryError) Error ¶
func (e MemoryError) Error() string
type Mmc1 ¶
type Mmc1 struct { RomBanks [][]Word VromBanks [][]Word PrgBankCount int ChrRomCount int Battery bool Data []byte Buffer int BufferCounter uint PrgLowerBank int PrgUpperBank int PrgSwapBank int PrgBankSize int ChrBankSize int ChrLowerBank int ChrUpperBank int Mirroring int }
func (*Mmc1) BatteryBacked ¶
func (*Mmc1) RegisterNumber ¶
func (*Mmc1) SetRegister ¶
type Mmc2 ¶
type Mmc2 struct { RomBanks [][]Word VromBanks [][]Word PrgBankCount int ChrRomCount int Battery bool Data []byte LatchLow int LatchHigh int LatchFE0 int LatchFE1 int LatchFD0 int LatchFD1 int PrgUpperHighBank int PrgUpperLowBank int PrgLowerHighBank int PrgLowerLowBank int ChrHighBank int ChrLowBank int }
func (*Mmc2) BatteryBacked ¶
func (*Mmc2) ChrBankSelect ¶
func (*Mmc2) LatchTrigger ¶
func (*Mmc2) MirroringSelect ¶
func (*Mmc2) PrgBankSelect ¶
func (*Mmc2) RegisterNumber ¶
type Mmc3 ¶
type Mmc3 struct { RomBanks []Word VromBanks []Word PrgBankCount int ChrRomCount int Battery bool Data []byte BankSelection int PrgBankMode int ChrA12Inversion int AddressChanged bool IrqEnabled bool IrqLatchValue Word IrqCounter Word IrqReset bool IrqResetVbl bool PrgUpperHighBank int PrgUpperLowBank int PrgLowerHighBank int PrgLowerLowBank int Chr000Bank int Chr400Bank int Chr800Bank int ChrC00Bank int Chr1000Bank int Chr1400Bank int Chr1800Bank int Chr1C00Bank int RamProtectDest [16]int }
func (*Mmc3) BankSelect ¶
func (*Mmc3) BatteryBacked ¶
func (*Mmc3) IrqDisable ¶
func (*Mmc3) RamProtection ¶
func (*Mmc3) RegisterNumber ¶
func (*Mmc3) SetMirroring ¶
type Mmc5 ¶
type Mmc5 struct { RomBanks [][]Word VromBanks [][]Word ExtendedRam [0x400]Word PrgBankCount int ChrRomCount int Battery bool Data []byte PrgSwitchMode Word ChrSwitchMode Word ExtendedRamMode Word ChrUpperBits Word FillModeTile Word FillModeColor Word SelectedPrgRamChip Word IrqLatch int IrqCounter int IrqEnabled bool IrqStatus Word PrgUpperHighBank int PrgUpperLowBank int PrgLowerHighBank int PrgLowerLowBank int Chr000Bank int Chr400Bank int Chr800Bank int ChrC00Bank int Chr1000Bank int Chr1400Bank int Chr1800Bank int Chr1C00Bank int SpriteSwapFunc [8]func() BgSwapFunc [4]func() }
func (*Mmc5) BatteryBacked ¶
func (*Mmc5) NotifyScanline ¶
func (m *Mmc5) NotifyScanline()
func (*Mmc5) ReadIrqStatus ¶
func (*Mmc5) SetNametableMapping ¶
func (*Mmc5) SwapBgVram ¶
func (m *Mmc5) SwapBgVram()
func (*Mmc5) SwapSpriteVram ¶
func (m *Mmc5) SwapSpriteVram()
type Nametable ¶
type Nametable struct { Mirroring int LogicalTables [4]*[0x400]Word Nametable0 [0x400]Word Nametable1 [0x400]Word }
func (*Nametable) SetMirroring ¶
type Noise ¶
type Noise struct { LengthEnabled bool Enabled bool BaseEnvelope Word Mode bool Timer int TimerCount int Length Word Shift int Sample int16 Envelope }
func (*Noise) UpdateSample ¶
type NoopEventHandler ¶
type NoopEventHandler struct { }
func NewNoopEventHandler ¶
func NewNoopEventHandler() *NoopEventHandler
func (*NoopEventHandler) Handle ¶
func (handler *NoopEventHandler) Handle(event string)
type Nrom ¶
type Nrom struct { RomBanks [][]Word VromBanks [][]Word PrgBankCount int ChrRomCount int Battery bool Data []byte }
Nrom
func (*Nrom) BatteryBacked ¶
type Ppu ¶
type Ppu struct { Registers Flags Masks SpriteData Vram [0xFFFF]Word SpriteRam [0x100]Word Nametables Nametable PaletteRam [0x20]Word AttributeLocation [0x400]uint AttributeShift [0x400]uint A12High bool Palettebuffer []Pixel Framebuffer []uint32 Output chan []uint32 Cycle int Scanline int Timestamp int VblankTime int FrameCount int FrameCycles int SuppressNmi bool SuppressVbl bool OverscanEnabled bool SpriteLimitEnabled bool }
type SpriteData ¶
type Square ¶
type Square struct { Enabled bool LengthEnabled bool DutyCycle Word DutyCount Word Timer int TimerCount int Length Word LastTick int SweepEnabled bool SweepPeriod Word SweepCounter Word SweepMode Word Shift Word SweepReload bool Negative bool Sample int16 Envelope }
func (*Square) ClockSweep ¶
func (s *Square) ClockSweep()
func (*Square) UpdateSample ¶
func (*Square) WriteControl ¶
func (*Square) WriteSweeps ¶
type Triangle ¶
type Triangle struct { ReloadValue Word Control bool Enabled bool LengthEnabled bool Halt bool Timer int TimerCount int Length Word Counter int LookupCounter int Sample int16 }
func (*Triangle) ClockLinearCounter ¶
func (t *Triangle) ClockLinearCounter()
func (*Triangle) UpdateSample ¶
Click to show internal directories.
Click to hide internal directories.