Documentation
¶
Overview ¶
PPU 负责图像处理和输出,最复杂的部分
Index ¶
- Constants
- Variables
- func LogReg(cpu *CPU)
- func Logger(format string, a ...interface{})
- func MirrorAddress(mode byte, address uint16) uint16
- type APU
- type CPU
- type CPUMemory
- type Cartridge
- type Console
- func (console *Console) Buffer() *image.RGBA
- func (console *Console) Reset()
- func (console *Console) SetAudioOutputWork(callback func(float32))
- func (console *Console) SetAudioSampleRate(sampleRate float64)
- func (console *Console) SetButton1(buttons [8]bool)
- func (console *Console) SetButton2(buttons [8]bool)
- func (console *Console) Step() int64
- func (console *Console) StepSeconds(seconds float64)
- type Controller
- type DMC
- type Mapper
- type Mapper0
- type Mapper1
- type Mapper3
- type Mapper4
- type Memory
- type Noise
- type PPU
- type PPUMemory
- type Pulse
- type Triangle
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 MirrorAddress ¶
Types ¶
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 (*CPU) TriggerNMI ¶
func (cpu *CPU) TriggerNMI()
type Cartridge ¶
type Cartridge struct {
PRG []byte
CHR []byte
SRAM []byte // 卡带SRAM
Mirror byte // 0 水平 1 垂直
Mapper byte // mapper种类
}
func LoadNESRom ¶
type Console ¶
type Console struct {
CPU *CPU
APU *APU
PPU *PPU
Card *Cartridge
Controller1 *Controller
Controller2 *Controller
Mapper Mapper
RAM []byte
}
func NewConsole ¶
func (*Console) SetAudioOutputWork ¶
将音频通过回调输出
func (*Console) SetAudioSampleRate ¶
func (*Console) SetButton1 ¶
func (*Console) SetButton2 ¶
func (*Console) StepSeconds ¶
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 Mapper ¶
type Mapper interface {
Read(address uint16) byte
Write(address uint16, value byte)
// 由于Mapper4需要在PPU每条扫描线结束时更新一次计数器,这里增加Step接口
Step()
}
func NewMapper0 ¶
func NewMapper1 ¶
func NewMapper3 ¶
func NewMapper4 ¶
type Mapper4 ¶
type Mapper4 struct {
// contains filtered or unexported fields
}
func (*Mapper4) StepScanLineCounter ¶
func (m *Mapper4) StepScanLineCounter()
type PPU ¶
type PPU struct {
Memory
Cycle int
ScanLine int
Frame int
NameTable [2048]byte
// contains filtered or unexported fields
}
func (*PPU) ReadPalette ¶
func (*PPU) WritePalette ¶
Click to show internal directories.
Click to hide internal directories.