nes

package
v0.0.0-...-c3eb257 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2015 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ButtonA = iota
	ButtonB
	ButtonSelect
	ButtonStart
	ButtonUp
	ButtonDown
	ButtonLeft
	ButtonRight
)
View Source
const (
	MirrorHorizontal = 0
	MirrorVertical   = 1
	MirrorSingle0    = 2
	MirrorSingle1    = 3
	MirrorFour       = 4
)
View Source
const CPUFrequency = 1789773

Variables

View Source
var MirrorLookup = [...][4]uint16{
	{0, 0, 1, 1},
	{0, 1, 0, 1},
	{0, 0, 0, 0},
	{1, 1, 1, 1},
	{0, 1, 2, 3},
}
View Source
var Palette [64]color.RGBA

Functions

func MirrorAddress

func MirrorAddress(mode byte, address uint16) uint16

Types

type APU

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

func NewAPU

func NewAPU(console *Console) *APU

func (*APU) Step

func (apu *APU) Step()

type CPU

type CPU struct {
	Memory        // memory interface
	Cycles uint64 // number of cycles
	PC     uint16 // program counter
	SP     byte   // stack pointer
	A      byte   // accumulator
	X      byte   // x register
	Y      byte   // y register
	C      byte   // carry flag
	Z      byte   // zero flag
	I      byte   // interrupt disable flag
	D      byte   // decimal mode flag
	B      byte   // break command flag
	U      byte   // unused flag
	V      byte   // overflow flag
	N      byte   // negative flag
	// contains filtered or unexported fields
}

func NewCPU

func NewCPU(console *Console) *CPU

func (*CPU) Flags

func (cpu *CPU) Flags() byte

Flags returns the processor status flags

func (*CPU) PrintInstruction

func (cpu *CPU) PrintInstruction()

PrintInstruction prints the current CPU state

func (*CPU) Read16

func (cpu *CPU) Read16(address uint16) uint16

Read16 reads two bytes using Read to return a double-word value

func (*CPU) Reset

func (cpu *CPU) Reset()

Reset resets the CPU to its initial powerup state

func (*CPU) SetFlags

func (cpu *CPU) SetFlags(flags byte)

SetFlags sets the processor status flags

func (*CPU) Step

func (cpu *CPU) Step() int

Step executes a single CPU instruction

type Cartridge

type Cartridge struct {
	PRG     []byte // PRG-ROM banks
	CHR     []byte // CHR-ROM banks
	SRAM    []byte // Save RAM
	Mapper  byte   // mapper type
	Mirror  byte   // mirroring mode
	Battery byte   // battery present
}

func LoadNESFile

func LoadNESFile(path string) (*Cartridge, error)

LoadNESFile reads an iNES file (.nes) and returns a Cartridge on success. http://wiki.nesdev.com/w/index.php/INES http://nesdev.com/NESDoc.pdf (page 28)

func NewCartridge

func NewCartridge(prg, chr []byte, mapper, mirror, battery byte) *Cartridge

type Console

type Console struct {
	CPU         *CPU
	APU         *APU
	PPU         *PPU
	Cartridge   *Cartridge
	Controller1 *Controller
	Controller2 *Controller
	Mapper      Mapper
	RAM         []byte
}

func NewConsole

func NewConsole(path string) (*Console, error)

func (*Console) BackgroundColor

func (console *Console) BackgroundColor() color.RGBA

func (*Console) Buffer

func (console *Console) Buffer() *image.RGBA

func (*Console) Reset

func (console *Console) Reset()

func (*Console) SetAudioChannel

func (console *Console) SetAudioChannel(channel chan float32)

func (*Console) SetButtons1

func (console *Console) SetButtons1(buttons [8]bool)

func (*Console) SetButtons2

func (console *Console) SetButtons2(buttons [8]bool)

func (*Console) Step

func (console *Console) Step() int

func (*Console) StepFrame

func (console *Console) StepFrame() int

func (*Console) StepSeconds

func (console *Console) StepSeconds(seconds float64)

type Controller

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

func NewController

func NewController() *Controller

func (*Controller) Read

func (c *Controller) Read() byte

func (*Controller) SetButtons

func (c *Controller) SetButtons(buttons [8]bool)

func (*Controller) Write

func (c *Controller) Write(value byte)

type DMC

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

type Mapper

type Mapper interface {
	Read(address uint16) byte
	Write(address uint16, value byte)
	Step()
}

func NewMapper

func NewMapper(console *Console) (Mapper, error)

func NewMapper1

func NewMapper1(cartridge *Cartridge) Mapper

func NewMapper2

func NewMapper2(cartridge *Cartridge) Mapper

func NewMapper3

func NewMapper3(cartridge *Cartridge) Mapper

func NewMapper4

func NewMapper4(console *Console, cartridge *Cartridge) Mapper

func NewMapper7

func NewMapper7(cartridge *Cartridge) Mapper

type Mapper1

type Mapper1 struct {
	*Cartridge
	// contains filtered or unexported fields
}

func (*Mapper1) Read

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

func (*Mapper1) Step

func (m *Mapper1) Step()

func (*Mapper1) Write

func (m *Mapper1) Write(address uint16, value byte)

type Mapper2

type Mapper2 struct {
	*Cartridge
	// contains filtered or unexported fields
}

func (*Mapper2) Read

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

func (*Mapper2) Step

func (m *Mapper2) Step()

func (*Mapper2) Write

func (m *Mapper2) Write(address uint16, value byte)

type Mapper3

type Mapper3 struct {
	*Cartridge
	// contains filtered or unexported fields
}

func (*Mapper3) Read

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

func (*Mapper3) Step

func (m *Mapper3) Step()

func (*Mapper3) Write

func (m *Mapper3) Write(address uint16, value byte)

type Mapper4

type Mapper4 struct {
	*Cartridge
	// contains filtered or unexported fields
}

func (*Mapper4) HandleScanLine

func (m *Mapper4) HandleScanLine()

func (*Mapper4) Read

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

func (*Mapper4) Step

func (m *Mapper4) Step()

func (*Mapper4) Write

func (m *Mapper4) Write(address uint16, value byte)

type Mapper7

type Mapper7 struct {
	*Cartridge
	// contains filtered or unexported fields
}

func (*Mapper7) Read

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

func (*Mapper7) Step

func (m *Mapper7) Step()

func (*Mapper7) Write

func (m *Mapper7) Write(address uint16, value byte)

type Memory

type Memory interface {
	Read(address uint16) byte
	Write(address uint16, value byte)
}

func NewCPUMemory

func NewCPUMemory(console *Console) Memory

func NewPPUMemory

func NewPPUMemory(console *Console) Memory

type Noise

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

type PPU

type PPU struct {
	Memory // memory interface

	Cycle    int    // 0-340
	ScanLine int    // 0-261, 0-239=visible, 240=post, 241-260=vblank, 261=pre
	Frame    uint64 // frame counter
	// contains filtered or unexported fields
}

func NewPPU

func NewPPU(console *Console) *PPU

func (*PPU) Reset

func (ppu *PPU) Reset()

func (*PPU) Step

func (ppu *PPU) Step()

Step executes a single PPU cycle

type Pulse

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

type Triangle

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

Jump to

Keyboard shortcuts

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