Documentation ¶
Index ¶
- Constants
- type APU
- type CPU
- type Cartridge
- type Console
- type DMC
- type Filter
- type FilterChain
- type FirstOrderFilter
- type Joypad
- type Mapper
- type Mapper0
- type Mapper1
- type Mapper2
- type Mapper4
- type MirrorType
- type Noise
- type PPU
- func (p *PPU) ReadData() byte
- func (p *PPU) ReadSPR() byte
- func (p *PPU) SetControlRegister(value byte)
- func (p *PPU) SetMaskRegister(value byte)
- func (p *PPU) SetSPRAddress(address byte)
- func (p *PPU) StatusRegister() byte
- func (p *PPU) Step() (uint64, *image.RGBA)
- func (p *PPU) String() string
- func (p *PPU) WriteData(value byte)
- func (p *PPU) WriteDataAddress(value byte)
- func (p *PPU) WriteSPR(value byte)
- func (p *PPU) WriteScroll(value byte)
- type Pulse
- type Triangle
Constants ¶
const CPUFrequency = 1789773
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CPU ¶
type CPU struct { Console *Console RAM [2048]byte NumCycles uint64 PC uint16 SP byte A byte X byte Y byte // contains filtered or unexported fields }
CPU emulates a NES 6502 CPU.
https://web.archive.org/web/20110320213225/http://www.obelisk.demon.co.uk/6502/
type Cartridge ¶
type Cartridge struct { Mirror MirrorType Mapper Mapper PRG [][]byte // [bank][byte], 16k banks. CHR [][]byte // [bank][byte], 8k banks. SRAM [][]byte // [bank][byte], 8k banks. }
A Cartridge represents a physical game cartridge.
func LoadCartridge ¶
LoadCartridge opens and reads an iNES format ROM file.
cart, err := LoadCartridge("test.rom")
func NewCartridge ¶
NewCartridge constructs an empty Cartridge with the given memory bank sizes.
PRG banks are 16k bytes, CHR and SRAM banks are both 8k bytes. No mapper is set.
func ReadCartridge ¶
ReadCartridge reads an iNES v1.0 ROM file from file.
func (*Cartridge) IRQ ¶
IRQ returns true if the Cartridge has any outstanding interrupt requests (IRQs). IRQs are typically generated by Mappers performing scanline counting.
Any outstanding IRQs are reset.
type Console ¶
type Console struct { Cart *Cartridge CPU *CPU PPU *PPU APU *APU Joypads [2]*Joypad // contains filtered or unexported fields }
Console represents a NES console and its main hardware components (the cartridge, CPU, PPU, and joypads).
func NewConsole ¶
NewConsole returns a Console initialised with cart.
func (*Console) SetAudioChannel ¶
func (*Console) SetAudioSampleRate ¶
func (*Console) Step ¶
Step runs the Console for 1 CPU instruction. The PPU runs at the same time.
Call Step() repeatedly to simulate the Console. For the majority of calls, Step() returns a nil *image.RGBA. Approximately 60 times a second the PPU emits a new image frame, and a non-nil *image.RGBA is returned. The image is 256x240px.
To regulate emulation speed, Step() may sleep when emitting an image. It sleeps to regulate the output to around 60 frames per second (as per NTSC).
type FilterChain ¶
type FilterChain []Filter
func (FilterChain) Step ¶
func (fc FilterChain) Step(x float32) float32
type FirstOrderFilter ¶
type FirstOrderFilter struct { B0 float32 B1 float32 A1 float32 // contains filtered or unexported fields }
func (*FirstOrderFilter) Step ¶
func (f *FirstOrderFilter) Step(x float32) float32
type Joypad ¶
type Joypad struct { A bool B bool Select bool Start bool Up bool Down bool Left bool Right bool // contains filtered or unexported fields }
Joypad represents the state of a standard game controller.
A standard controller has the buttons: A, B, Select, Start, Up, Down, Left, and Right.
http://wiki.nesdev.com/w/index.php/Standard_controller
func NewJoypad ¶
func NewJoypad() *Joypad
NewJoypad returns a new Joypad.
Joypad does not perform any IO. Call SetReadKeysCallback() to provide a function to update the Joypad's state from the physical input device (keyboard/USB controller/etc).
func (*Joypad) SetReadKeysCallback ¶
func (j *Joypad) SetReadKeysCallback(callback func())
SetReadKeysCallback sets a callback function used to update the Joypad's button press state.
The callback function should update j.{A,B,Select,Start,Up,Down,Left,Right} to match the physical input device.
type Mapper ¶
type Mapper interface { Read(address uint16, isPPU bool) byte Write(address uint16, value byte, isPPU bool) IRQ() bool // contains filtered or unexported methods }
A Mapper sits between a cartridge and the console.
Mappers provide functions such as memory bank switching (as a cartridge can contain more memory than the NES's address space allows), and scanline counting.
http://wiki.nesdev.com/w/index.php/Mapper
func NewMapper ¶
NewMapper returns a mapper of type id for cart.
Each cartridge requires a specific mapper id, which is stated in the iNES file header.
The following mappers are currently implemented: - 0 (NROM) - 1 (MMC1) - 2 (UNROM) - 4 (MMC3)
An error is returned if the requested mapper id is not implemented.
type Mapper0 ¶
type Mapper0 struct { *Cartridge // contains filtered or unexported fields }
Mapper0 implements the NROM mapper.
type Mapper1 ¶
type Mapper1 struct { *Cartridge // contains filtered or unexported fields }
Mapper1 implements the MMC1 mapper.
type Mapper2 ¶
type Mapper2 struct { *Cartridge // contains filtered or unexported fields }
Mapper2 implements the UNROM mapper.
type Mapper4 ¶
type Mapper4 struct { *Cartridge // contains filtered or unexported fields }
Mapper4 implements the MMC3 mapper.
The MMC3 mapper implements PRG/CHG bank switching and scanline counting.
type MirrorType ¶
type MirrorType int
MirrorType determines a cartridge's nametable mirroring arrangement.
type PPU ¶
type PPU struct { Console *Console // Scanline (0-261). Scanline int // Tick (0-340). Tick int // Frame counter. Frame uint64 // contains filtered or unexported fields }
PPU implements the NES Picture Processing Unit.
func (*PPU) SetControlRegister ¶
SetControlRegister sets the value of the control register ($2000).
func (*PPU) SetMaskRegister ¶
SetMaskRegister sets the value of the mask register ($2001).
func (*PPU) SetSPRAddress ¶
SetSPRAddress sets the value of the sprite address register ($2003).
func (*PPU) StatusRegister ¶
StatusRegister returns the value of the status register ($2002).
func (*PPU) Step ¶
Step runs the PPU for one cycle.
Returns the total number of cycles run in the PPU's lifetime. An image is returned when the screen is to be updated.
func (*PPU) WriteDataAddress ¶
WriteDataAddress ($2006): Data address write register (two values).
func (*PPU) WriteSPR ¶
WriteSPR writes a byte to the sprite memory at the current sprite address. The sprite address is then incremented.
func (*PPU) WriteScroll ¶
WriteScroll ($2005): Scroll position write register (two values).