Documentation ¶
Index ¶
- Constants
- Variables
- type FIFO
- type Fetcher
- type OAM
- type PPU
- func (p *PPU) BGMap() uint16
- func (p *PPU) Drop() uint8
- func (p *PPU) Pop() uint8
- func (p *PPU) Read(addr uint16) uint8
- func (p *PPU) RequestLCDInterrupt(interrupt uint8)
- func (p *PPU) String() string
- func (p *PPU) Tick()
- func (p *PPU) TileData() (addr uint16, signedID bool)
- func (p *PPU) WindowMap() uint16
- func (p *PPU) Write(addr uint16, value uint8)
- type Pixel
- type Sprite
- type VRAM
Constants ¶
const ( PixelBGP = 0 PixelOBP0 = 1 PixelOBP1 = 2 )
Pixel palettes used at display time. Will map to ppu.palettes.
const ( AddrLCDC = 0xff40 AddrSTAT = 0xff41 AddrSCY = 0xff42 AddrSCX = 0xff43 AddrLY = 0xff44 AddrLYC = 0xff45 AddrBGP = 0xff47 AddrOBP0 = 0xff48 AddrOBP1 = 0xff49 AddrWY = 0xff4a AddrWX = 0xff4b )
Register addresses.
const ( // Bit 0 - BG/Window Display/Priority (0=Off, 1=On) LCDCBGDisplay uint8 = 1 << iota // Bit 1 - OBJ (Sprite) Display Enable (0=Off, 1=On) LCDCSpriteDisplayEnable // Bit 2 - OBJ (Sprite) Size (0=8x8, 1=8x16) LCDCSpriteSize // Bit 3 - BG Tile Map Display Select (0=9800-9BFF, 1=9C00-9FFF) LCDCBGTileMapDisplayeSelect // Bit 4 - BG & Window Tile Data Select (0=8800-97FF, 1=8000-8FFF) LCDCBGWindowTileDataSelect // Bit 5 - Window Display Enable (0=Off, 1=On) LCDCWindowDisplayEnable // Bit 6 - Window Tile Map Display Select (0=9800-9BFF, 1=9C00-9FFF) LCDCWindowTileMapDisplayeSelect // Bit 7 - LCD Display Enable (0=Off, 1=On) LCDCDisplayEnable )
LCDC flags. XXX: Move to subpackage lcdc for nicer namespacing?
const ( SpritePalette = 1 << (iota + 4) SpriteFlipX SpriteFlipY SpritePriority )
Sprite flags
const AddrOAM = 0xfe00
AddrOAM represents the base address of OAM RAM.
const AddrVRAM = 0x8000
AddrOAM represents the base address of OAM RAM.
Variables ¶
var ClockFactor = 2
ClockFactor representing the number of ticks taken by each step (base is 4). Used in Fetcher's Tick() method.
Functions ¶
This section is empty.
Types ¶
type FIFO ¶
type FIFO struct {
// contains filtered or unexported fields
}
FIFO holds the PPU's pixel FIFO shifting out pixels to the display with the guarantee that there will always be 8 pixels available to mix sprites in.
type Fetcher ¶
type Fetcher struct { Enabled bool // contains filtered or unexported fields }
Fetcher reads tile data from VRAM and pushes pixels to PPU FIFO.
func NewFetcher ¶
NewFetcher creates a pixel fetcher instance that can read directly from video and OAM RAM.
func (*Fetcher) FetchSprite ¶
FetchSprite pauses the current fetching state to read sprite data and mix it in the pixel FIFO.
func (*Fetcher) ReadTileLine ¶
func (f *Fetcher) ReadTileLine(bitPlane uint8, tileDataAddr uint16, tileID uint8, signedID bool, tileLine uint8, flags uint8, data *[8]uint8)
ReadTileLine updates internal pixel buffer with LSB or MSB tile line depending on current state.
type OAM ¶
OAM computes a list of sprites to display for the current scanline.
func NewOAM ¶
NewOAM creates an OAM address space. Takes a reference to a PPU instance so it can access the LY and LCDC registers.
func (*OAM) Read ¶
Read overrides RAM method to restrict access to OAM to PPU modes 0 and 1. [https://gbdev.io/pandocs/Accessing_VRAM_and_OAM.html]
type PPU ¶
type PPU struct { *memory.MMU *Fetcher FIFO VRAM *VRAM OAM *OAM Interrupts *interrupts.Interrupts Cycle int LCD *screen.Screen LCDC uint8 STAT uint8 SCY, SCX uint8 LY uint8 LYC uint8 WY, WX uint8 BGP uint8 OBP0, OBP1 uint8 // contains filtered or unexported fields }
PPU address space handling video RAM and display.
func (*PPU) Drop ¶
Drop tries taking a pixel out of the FIFO and discarding it to account for SCX. It returns the number of dropped pixels (0 or 1).
func (*PPU) Pop ¶
Pop tries shifting a pixel out of the FIFO to the LCD and returns the number of shifted pixels (0 or 1).
func (*PPU) RequestLCDInterrupt ¶
RequestLCDInterrupt checks STAT bits when an interrupt condition occurs and requests an actual interrupt if the corresponding bit is set.
func (*PPU) Tick ¶
func (p *PPU) Tick()
Tick advances the CPU state one step. Return whether we reached VBlank so that event polling can happen then.
func (*PPU) TileData ¶
TileData returns the base address of the background or window tile data in VRAM.
type Sprite ¶
type Sprite struct {
X, Y uint8
Address uint16
Fetched bool // Set to true after this sprite was treated for a given line.
}
Sprite type holds (x,y) coordinates of the current pixel of a sprite in the current scanline as well as its address in OAM RAM.
type VRAM ¶
VRAM address space restricting access to Video RAM to modes 0, 1 and 2.
func NewVRAM ¶
NewOAM creates an OAM address space. Takes a reference to a PPU instance so it can access the LY and LCDC registers.
func (*VRAM) Read ¶
Read overrides RAM method to restrict access to OAM to PPU modes 0, 1 and 2. [https://gbdev.io/pandocs/Accessing_VRAM_and_OAM.html]