nes

package
v0.0.0-...-093dcb0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2018 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BA      = iota // K
	BB             // J
	BSelect        // F
	BStart         // H
	BUp            // W
	BDown          // S
	BLeft          // A
	BRight         // D
)

Controllers

View Source
const (
	MirrorHorizontal = iota
	MirrorVertical
	MirrorSingle0
	MirrorSingle1
	MirrorFour
)
View Source
const CPUFrequency = 1789773 // From http://wiki.nesdev.com/w/index.php/CPU
View Source
const NESMagicMumber = 0x1a53454e //"NES^Z"
View Source
const NESMagicNumber = 0x1a53454e // "NES^Z"
View Source
const Tmpdir = "tmp"
View Source
const ZIPMagicNumber = 0x04034B50 // "PK.."

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

func ReadFile

func ReadFile(path string) (string, bool)

func ReadMagicNumber

func ReadMagicNumber(w io.Reader) (uint32, error)

func RemoveDir

func RemoveDir(path string) error

func Zip

func Zip(path string) string

Types

type APU

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

func NewAPU

func NewAPU(nes *NES) *APU

func (*APU) ReadRegister

func (a *APU) ReadRegister(address uint16) byte

func (*APU) Run

func (a *APU) Run()

func (*APU) WriteRegister

func (a *APU) WriteRegister(address uint16, val byte)

type CPU

type CPU struct {
	Cycles uint64 // Should be big enough
	PC     uint16 // Program counter
	SP     byte   // Stack pointer
	A      byte   // Accumulator
	X      byte   // Index Register X
	Y      byte   // Index Register Y
	C      byte   // Carry FLag
	Z      byte   // Zero Flag
	I      byte   // Interrupt Disable
	D      byte   // Decimal Mode
	B      byte   // Break Command
	U      byte   // Ignored FLag
	V      byte   // Overflow Flag
	N      byte   // Negative Flag

	Memory //Memory Interface
	// contains filtered or unexported fields
}

func NewCPU

func NewCPU(memory Memory) *CPU

func (*CPU) DebugPrint

func (c *CPU) DebugPrint()

For Debug

func (*CPU) Read16

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

func (*CPU) ReadFlags

func (c *CPU) ReadFlags() byte

func (*CPU) Reset

func (c *CPU) Reset()

func (*CPU) Run

func (c *CPU) Run() int

func (*CPU) SetFlags

func (c *CPU) SetFlags(flags byte)

type CPUMemory

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

CPU

func (*CPUMemory) Read

func (mem *CPUMemory) Read(address uint16) byte

func (*CPUMemory) Read16

func (mem *CPUMemory) Read16(address uint16) uint16

func (*CPUMemory) Write

func (mem *CPUMemory) Write(address uint16, val byte)

type Cartridge

type Cartridge struct {
	PRG     []byte
	CHR     []byte
	SRAM    []byte
	Mapper  byte
	Mirror  byte
	Battery byte
	// contains filtered or unexported fields
}

func LoadNES

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

* LoadNES function reads an iNES file from the given path and return a Cartidge * if success.

func NewCartridge

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

func (*Cartridge) Read

func (c *Cartridge) Read(address uint16) byte

func (*Cartridge) Write

func (c *Cartridge) Write(address uint16, val byte)

type Controller

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

func NewController

func NewController() *Controller

func (*Controller) Press

func (c *Controller) Press(button int)

func (*Controller) Read

func (c *Controller) Read() byte

func (*Controller) Release

func (c *Controller) Release(button int)

func (*Controller) SetPressed

func (c *Controller) SetPressed(button int, pressed bool)

func (*Controller) Write

func (c *Controller) Write(val byte)

type DMC

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

type Filter

type Filter interface {
	Run(x float32) float32
}

func HPassFilter

func HPassFilter(sampleRate float32, cutoffFreq float32) Filter

func LPassFilter

func LPassFilter(sampleRate float32, cutoffFreq float32) Filter

type FilterChain

type FilterChain []Filter

func (FilterChain) Run

func (fc FilterChain) Run(x float32) float32

type FirstOrderFilter

type FirstOrderFilter struct {
	B0 float32
	B1 float32
	A1 float32
	// contains filtered or unexported fields
}

func (*FirstOrderFilter) Run

func (f *FirstOrderFilter) Run(x float32) float32

type Mapper

type Mapper interface {
	Read(address uint16) byte
	Write(address uint16, val byte)
	Run()
}

func NewMapper

func NewMapper(nes *NES) (Mapper, error)

func NewMapper1

func NewMapper1(c *Cartridge) Mapper

func NewMapper2

func NewMapper2(c *Cartridge) Mapper

func NewMapper3

func NewMapper3(cartridge *Cartridge) Mapper

func NewMapper4

func NewMapper4(nes *NES, 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) Run

func (m *Mapper1) Run()

func (*Mapper1) Write

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

type Mapper2

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

func (*Mapper2) Read

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

func (*Mapper2) Run

func (m *Mapper2) Run()

func (*Mapper2) Write

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

type Mapper3

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

func (*Mapper3) Read

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

func (*Mapper3) Run

func (m *Mapper3) Run()

func (*Mapper3) Write

func (m *Mapper3) Write(address uint16, val 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) Run

func (m *Mapper4) Run()

func (*Mapper4) Write

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

type Mapper7

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

func (*Mapper7) Read

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

func (*Mapper7) Run

func (m *Mapper7) Run()

func (*Mapper7) Write

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

type Memory

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

func NewCPUMemory

func NewCPUMemory(nes *NES) Memory

func NewPPUMemory

func NewPPUMemory(nes *NES) Memory

type NES

type NES struct {
	FileName    string
	APU         *APU
	Cartridge   *Cartridge
	Controller1 *Controller
	Controller2 *Controller
	CPU         *CPU
	PPU         *PPU
	RAM         []byte
	Mapper      Mapper
	CPUMemory   Memory
	PPUMemory   Memory
}

func NewNES

func NewNES(path string) (*NES, error)

func (*NES) Buffer

func (n *NES) Buffer() *image.RGBA

func (*NES) Reset

func (n *NES) Reset()

func (*NES) Run

func (nes *NES) Run() int

func (*NES) RunSeconds

func (n *NES) RunSeconds(second float64)

func (*NES) SetAPUChannel

func (n *NES) SetAPUChannel(channel chan float32)

func (*NES) SetAPUSRate

func (n *NES) SetAPUSRate(sRate float64)

func (*NES) SetKeyPressed

func (n *NES) SetKeyPressed(controller, btn int, press bool)

type NESFileHeader

type NESFileHeader struct {
	MagicNumber uint32 // NES Magic Number,must be 0x1a53454e
	PRGNum      byte   // PRG-ROM banks number
	CHRNum      byte   // CHR-ROM banks number
	Ctrl1       byte   // Control
	Ctrl2       byte   // Control too
	RAMNum      byte   // RAM number (8KB each)
	// contains filtered or unexported fields
}

type Noise

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

type PPU

type PPU struct {
	Memory // memory interface
	NES    *NES

	Cycle    int // 0-340
	ScanLine int // 0-261
	Frame    uint64
	// contains filtered or unexported fields
}

func NewPPU

func NewPPU(nes *NES) *PPU

func (*PPU) ReadRegister

func (p *PPU) ReadRegister(address uint16) byte

func (*PPU) Reset

func (p *PPU) Reset()

func (*PPU) Run

func (p *PPU) Run()

Run runs the ppu.

func (*PPU) WriteRegister

func (p *PPU) WriteRegister(address uint16, val byte)

type PPUMemory

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

func (*PPUMemory) Read

func (mem *PPUMemory) Read(address uint16) byte

func (*PPUMemory) Read16

func (mem *PPUMemory) Read16(address uint16) uint16

func (*PPUMemory) Write

func (mem *PPUMemory) Write(address uint16, val byte)

type Square

type Square 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