281. Nametable con paleta ram

Renderizar el fondo de la tabla de nombres usando la tabla de atributos y los bytes de la RAM de paleta de la PPU.

Lección 281 de 356 · tests/chapter_05_rendering_pipeline/test_281_nametable_with_palette_ram.py

Archivo a actualizar

emulator/rendering/nametable_renderer.py

Por qué existe este paso

Los pasos anteriores construyeron las piezas por separado

attribute table
    -> palette ID for each tile coordinate

palette RAM bytes
    -> four RGB background palettes

nametable + attributes + background palettes
    -> framebuffer

Este paso compone esas piezas en un único ayudante de renderizado puro

nametable_with_palette_ram_to_framebuffer(
    nametable_bytes,
    attribute_table,
    pattern_table_bytes,
    palette_ram,
)

Qué debe hacer

background_palettes = build_background_palettes_from_palette_ram(palette_ram)

return nametable_with_attributes_to_framebuffer(
    nametable_bytes,
    attribute_table,
    pattern_table_bytes,
    background_palettes,
)

Por qué es útil

Este ayudante acepta datos con una forma más cercana a las entradas reales de renderizado de la PPU, manteniéndose totalmente comprobable:

nametable visible tile bytes
attribute table bytes
pattern table CHR bytes
background palette RAM bytes

Sigue siendo datos puros

Sin lecturas del bus de la PPU, sin pygame, sin ventana, sin bucle de fotogramas.

Modelo de hardware importante

CHR pixel color index 0-3
    -> attribute table selects background palette ID 0-3
    -> palette RAM selects NES color index $00-$3F
    -> NES RGB palette converts to RGB
    -> framebuffer pixel

Ejemplo de implementación sugerida

from emulator.rendering.palette_ram import build_background_palettes_from_palette_ram


def nametable_with_palette_ram_to_framebuffer(
    nametable_bytes: bytes,
    attribute_table: bytes,
    pattern_table_bytes: bytes,
    palette_ram: bytes,
) -> Framebuffer:
    background_palettes = build_background_palettes_from_palette_ram(palette_ram)

    return nametable_with_attributes_to_framebuffer(
        nametable_bytes,
        attribute_table,
        pattern_table_bytes,
        background_palettes,
    )

Fuera de alcance

  • leer bytes de la tabla de nombres/paleta desde el bus de la PPU
  • duplicado (mirroring) de la RAM de paleta
  • scroll
  • sprites
  • OAMDMA
  • visualización con pygame

Ejecutar esta lección

uv run pytest tests/chapter_05_rendering_pipeline/test_281_nametable_with_palette_ram.py -v