ppu

package
v0.0.0-...-657eaca Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PixelBGP  = 0
	PixelOBP0 = 1
	PixelOBP1 = 2
)

Pixel palettes used at display time. Will map to ppu.palettes.

View Source
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.

View Source
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?

View Source
const (
	SpritePalette = 1 << (iota + 4)
	SpriteFlipX
	SpriteFlipY
	SpritePriority
)

Sprite flags

View Source
const AddrOAM = 0xfe00

AddrOAM represents the base address of OAM RAM.

View Source
const AddrVRAM = 0x8000

AddrOAM represents the base address of OAM RAM.

Variables

View Source
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.

func (*FIFO) Clear

func (f *FIFO) Clear()

Clear and reset FIFO.

func (*FIFO) Mix

func (f *FIFO) Mix(offset int, pixel Pixel)

Mix sprite pixel data in the lower half of the FIFO. Priorities are hard to understand in most docs I've seen, so this is empirical at best.

func (*FIFO) Pop

func (f *FIFO) Pop() (pixel Pixel, err error)

Pop an item out of the FIFO.

func (*FIFO) Push

func (f *FIFO) Push(pixel Pixel) error

Push an item in the FIFO.

func (*FIFO) Size

func (f *FIFO) Size() int

Size returns the current number of items in the FIFO.

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

func NewFetcher(ppu *PPU) *Fetcher

NewFetcher creates a pixel fetcher instance that can read directly from video and OAM RAM.

func (*Fetcher) FetchSprite

func (f *Fetcher) FetchSprite(sprite Sprite, spriteOffset, spriteLine uint8)

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.

func (*Fetcher) Start

func (f *Fetcher) Start(mapAddr, dataAddr uint16, tileOffset, tileLine uint8, signedID bool)

Start fetching a line of pixels from the given tile in the given tilemap address space when Tick() is called.

func (*Fetcher) Tick

func (f *Fetcher) Tick()

Tick advances the fetcher's state machine one step.

type OAM

type OAM struct {
	*memory.RAM

	Sprites []Sprite
	// contains filtered or unexported fields
}

OAM computes a list of sprites to display for the current scanline.

func NewOAM

func NewOAM(ppu *PPU) *OAM

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

func (o *OAM) Read(addr uint16) uint8

Read overrides RAM method to restrict access to OAM to PPU modes 0 and 1. [https://gbdev.io/pandocs/Accessing_VRAM_and_OAM.html]

func (*OAM) Start

func (o *OAM) Start()

Start OAM search.

func (*OAM) Tick

func (o *OAM) Tick() (done bool)

Tick advances OAM search one step and returns true when the search is over.

func (*OAM) Write

func (o *OAM) Write(addr uint16, value uint8)

Write overrides RAM method to restrict access to OAM to PPU modes 0 and 1. DMA should bypass this method and directly call the underlying RAM object's Write method instead. [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 New

func New(display *screen.Screen) *PPU

New PPU instance.

func (*PPU) BGMap

func (p *PPU) BGMap() uint16

BGMap returns the base address of the background map in VRAM.

func (*PPU) Drop

func (p *PPU) Drop() uint8

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

func (p *PPU) Pop() uint8

Pop tries shifting a pixel out of the FIFO to the LCD and returns the number of shifted pixels (0 or 1).

func (*PPU) Read

func (p *PPU) Read(addr uint16) uint8

Read override that handles exact STAT lower bits' values at any given time.

func (*PPU) RequestLCDInterrupt

func (p *PPU) RequestLCDInterrupt(interrupt uint8)

RequestLCDInterrupt checks STAT bits when an interrupt condition occurs and requests an actual interrupt if the corresponding bit is set.

func (*PPU) String

func (p *PPU) String() string

String returns a human-readable representation of the PPU's current state.

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

func (p *PPU) TileData() (addr uint16, signedID bool)

TileData returns the base address of the background or window tile data in VRAM.

func (*PPU) WindowMap

func (p *PPU) WindowMap() uint16

WindowMap returns the base address of the window map in VRAM.

func (*PPU) Write

func (p *PPU) Write(addr uint16, value uint8)

Write override that handles read-only registers and bits.

type Pixel

type Pixel struct {
	Color     uint8
	Palette   uint8
	BGOverOBJ bool
}

Pixel holding its color index and palette to be used in our FIFO.

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

type VRAM struct {
	*memory.RAM
	// contains filtered or unexported fields
}

VRAM address space restricting access to Video RAM to modes 0, 1 and 2.

func NewVRAM

func NewVRAM(ppu *PPU) *VRAM

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

func (v *VRAM) Read(addr uint16) uint8

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]

func (*VRAM) Write

func (v *VRAM) Write(addr uint16, value uint8)

Write overrides RAM method to restrict access to OAM to PPU modes 0, 1 and 2. [https://gbdev.io/pandocs/Accessing_VRAM_and_OAM.html]

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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