nes

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

PPU 负责图像处理和输出,最复杂的部分

Index

Constants

View Source
const (
	ButtonA = iota
	ButtonB
	ButtonSelect
	ButtonStart
	ButtonUp
	ButtonDown
	ButtonLeft
	ButtonRight
)
View Source
const (
	// NMI中断
	NMI = 0xfffa
	// 每次启动触发
	RESET = 0xfffc
	// IRQ/BRK共用中断地址
	// 硬件/apu触发
	IRQ = 0xfffe
	// 软件触发
	BRK = 0xfffe
)

各中断的地址信息,2byte

View Source
const (
	MirrorHorizontal = 0
	MirrorVertical   = 1
	MirrorSingle0    = 2
	MirrorSingle1    = 3
	MirrorFour       = 4
)
View Source
const CPUFrequency = 1789773

CPU的时钟频率是1.79MHz,每秒1.79 * 10^6次,CPUFrequency * seconds 即可得到时钟数!

View Source
const FrameCounterRate = 240.0

帧计数器 240Hz

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 LogReg

func LogReg(cpu *CPU)

func Logger

func Logger(format string, a ...interface{})

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) ReadRegister

func (apu *APU) ReadRegister(addr uint16) byte

func (*APU) Step

func (apu *APU) Step()

type CPU

type CPU struct {
	Memory
	Cycles uint64
	PC     uint16
	SP     byte // 堆栈寄存器
	A      byte
	X      byte
	Y      byte
	C      byte // 8个状态FLAG C - 进位标志
	Z      byte // Z - 结果为零标志
	I      byte // I - 中断屏蔽
	D      byte // D - 未使用
	B      byte // BRK
	U      byte // 未使用
	V      byte // 溢出标志,计算结果产生溢出
	N      byte // 负标志,结果为负
	// contains filtered or unexported fields
}

func NewCPU

func NewCPU(console *Console) *CPU

func (*CPU) Read16

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

func (*CPU) Reset

func (cpu *CPU) Reset()

func (*CPU) Step

func (cpu *CPU) Step() int64

step执行一个指令:读指令-寻址-将数据提供给指令方法执行-计算时钟数

func (*CPU) TriggerIRQ

func (cpu *CPU) TriggerIRQ()

中断触发相关, 处理irq、nmi中断

func (*CPU) TriggerNMI

func (cpu *CPU) TriggerNMI()

type CPUMemory

type CPUMemory struct {
	RAM []byte
	// contains filtered or unexported fields
}

func (*CPUMemory) Read

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

func (*CPUMemory) Write

func (mem *CPUMemory) Write(addr uint16, value byte)

type Cartridge

type Cartridge struct {
	PRG    []byte
	CHR    []byte
	SRAM   []byte // 卡带SRAM
	Mirror byte   // 0 水平 1 垂直
	Mapper byte   // mapper种类
}

func LoadNESRom

func LoadNESRom(info []byte) (*Cartridge, error)

func NewCartridge

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

type Console

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

func NewConsole

func NewConsole(info []byte) (*Console, error)

func (*Console) Buffer

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

func (*Console) Reset

func (console *Console) Reset()

func (*Console) SetAudioOutputWork

func (console *Console) SetAudioOutputWork(callback func(float32))

将音频通过回调输出

func (*Console) SetAudioSampleRate

func (console *Console) SetAudioSampleRate(sampleRate float64)

func (*Console) SetButton1

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

func (*Console) SetButton2

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

func (*Console) Step

func (console *Console) Step() int64

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)
	// 由于Mapper4需要在PPU每条扫描线结束时更新一次计数器,这里增加Step接口
	Step()
}

func NewMapper

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

func NewMapper0

func NewMapper0(card *Cartridge) Mapper

func NewMapper1

func NewMapper1(card *Cartridge) Mapper

func NewMapper3

func NewMapper3(cartridge *Cartridge) Mapper

func NewMapper4

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

type Mapper0

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

func (*Mapper0) Read

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

func (*Mapper0) Step

func (mapper *Mapper0) Step()

func (*Mapper0) Write

func (mapper *Mapper0) Write(addr uint16, value byte)

type Mapper1

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

func (*Mapper1) Read

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

func (*Mapper1) Step

func (m *Mapper1) Step()

func (*Mapper1) Write

func (m *Mapper1) Write(addr 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 (mapper *Mapper3) Step()

func (*Mapper3) Write

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

type Mapper4

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

func (*Mapper4) Read

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

func (*Mapper4) Step

func (m *Mapper4) Step()

func (*Mapper4) StepScanLineCounter

func (m *Mapper4) StepScanLineCounter()

func (*Mapper4) Write

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

type Memory

type Memory interface {
	Write(addr uint16, value byte)
	Read(addr uint16) 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
	Cycle    int
	ScanLine int
	Frame    int

	NameTable [2048]byte
	// contains filtered or unexported fields
}

func NewPPU

func NewPPU(console *Console) *PPU

func (*PPU) ReadPalette

func (ppu *PPU) ReadPalette(addr uint16) byte

func (*PPU) Reset

func (ppu *PPU) Reset()

func (*PPU) Step

func (ppu *PPU) Step()

func (*PPU) WritePalette

func (ppu *PPU) WritePalette(addr uint16, value byte)

type PPUMemory

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

func (*PPUMemory) Read

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

func (*PPUMemory) Write

func (mem *PPUMemory) Write(addr uint16, value byte)

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