Video summary

Gameboy Emulator Development - Part 13

Main summary

Key takeaways

Technology

What this video implements (Game Boy emulator, PPU Part 13)

  • Builds the Pixel FIFO pipeline to render the background (and later sprites).
  • Introduces an internal pipeline state machine that:
    • Fetches background/window tile indices and tile data bytes
    • Buffers pixels in a FIFO
    • Pushes pixels to a video buffer (screen framebuffer)
    • Then waits/loops according to PPU timing

Pixel FIFO concept + states

The Pixel FIFO is described as an internal state machine with ~5 steps (implemented as a simplified version):

  1. Get/Fetch tile
  2. Get tile data low bit
  3. Get tile data high bit
  4. Idle
  5. Push

It fetches a row of 8 background/window pixels. Later, these will be mixed with sprite pixels (sprite work is deferred to a later part of the series).

Tile data fetching details

  • Uses LCDC flags to determine whether background and/or window fetching is enabled.
  • Reads tile map location using:
    • map_x = fetch_x + scroll_x
    • map_y = (ly + scroll_y) (and later tile y applies modulus with tile size)

For each tile:

  • Tile index is read from the tile map.
  • The tile index selects a tile in tile data memory:
    • tile data low/high bytes are fetched from tile_y and tile_y + 1
    • tile data offsets use tile * 16 since a tile is 16 bytes
  • The color index is formed by combining the two bitplanes:
    • low bit + high bit → values 0–3 representing tile colors

FIFO structure and behavior

The FIFO is implemented as a simple linked-list style queue:

  • Each FIFO entry contains:
    • next pointer
    • u32 value storing the pixel color

In the PPU context, it tracks:

  • FIFO head/tail/size
  • fetch/push timing counters (e.g., current fetch position and current pushed x)
  • temporary variables for tile/sprite fetch bookkeeping (sprite-related fetch data exists, but sprites aren’t rendered in this part)

Timing rules: when pushing pixels happens

  • The pipeline process is called from the PPU state machine during active rendering/execution of the pipeline stage.
  • Pixels are pushed only when the FIFO is sufficiently filled:
    • If fifo size > 8, it starts popping and writing to the video buffer.
  • Push cadence:
    • Pipeline fetch happens every other tick (based on checking a bit of line_ticks)
    • Pixel pushing happens every tick once FIFO is ready
  • Stops pushing when horizontal resolution is reached:
    • When all pixels for a line are pushed, the PPU transitions toward H-blank

Functions added (internal pipeline logic)

  • pipeline_fetch
    • The main pipeline state machine driving: tile → data low → data high → idle → push
  • pipeline_push_pixel
    • Pops pixel colors from FIFO and writes them into the video buffer at the correct screen x position
  • pipeline_fifo_add / pop logic
    • add pushes colors into FIFO; if FIFO is full, the pipeline stays in the push state until it can add safely
  • pipeline_fifo_reset
    • Clears FIFO at the end of the pipeline/render phase (during H-blank transition)

Video output / integration (UI/display)

  • Updates SDL rendering by:
    • Creating rectangles per pixel (scaled)
    • Filling from the emulator’s video buffer
    • Updating an SDL texture and presenting it

Review / tutorial results mentioned (testing outcomes)

Verified rendering works by running ROMs/test suites:

  • General test ROM
    • Background rendered successfully
  • CPU test “special” state
    • Debug output indicates tests pass (prints test name and passed/failed)
  • Dr. Mario
    • Background appears (startup screen)
    • Sprites not shown initially (notes that missing pieces are controlled by sprites)
    • Later sprites appear when they move
  • Asteroids
    • Background and scene transitions (“fading to next screen”) work
  • DMG Acid2 (PPU test)
    • Compares emulator output to a known reference image
    • Results are “pretty close,” but not perfect yet
    • Missing sections indicate unimplemented/incorrect PPU sub-features

Current conclusion and next steps

Concludes background rendering via pixel FIFO is working. Next steps are:

  1. Sprites rendering
  2. Implement window object (scrollable window / tile map region)

Main speaker/source

  • The creator/host of the “low-level dev” Game Boy emulator series (speaking directly throughout; no other named sources).

Original video