275. Pattern table with nes palette
Render a pattern table framebuffer using the default NES RGB palette.
Lesson 275 of 356 · tests/chapter_05_rendering_pipeline/test_275_pattern_table_with_nes_palette.py
File to update
emulator/rendering/pattern_table_renderer.pyWhy this step exists
The generic pattern table renderer already supports custom palettes
pattern_table_to_framebuffer(pattern_table_bytes, palette)That is useful for tests and debug palettes. Now that we have a default NES RGB palette approximation, we add a convenience helper:
pattern_table_to_nes_framebuffer(pattern_table_bytes)This helper keeps the default-palette path explicit without removing custom palette support.
What it should do
pattern_table_to_nes_framebuffer(pattern_table_bytes)
-> pattern_table_to_framebuffer(pattern_table_bytes, NES_PALETTE_RGB)Suggested implementation example
from emulator.rendering.nes_palette import NES_PALETTE_RGB
def pattern_table_to_nes_framebuffer(
pattern_table_bytes: bytes,
) -> Framebuffer:
return pattern_table_to_framebuffer(pattern_table_bytes, NES_PALETTE_RGB)Why not make NES_PALETTE_RGB the default argument?
This would work
def pattern_table_to_framebuffer(pattern_table_bytes, palette=NES_PALETTE_RGB):
...But a separate helper is clearer for the tutorial
pattern_table_to_framebuffer(..., palette)
custom palette path
pattern_table_to_nes_framebuffer(...)
default NES palette pathNote: This test uses synthetic CHR bytes only. Do not use commercial ROM CHR data in this test.
Out of scope
- pygame display
- writing image files
- nametable/background rendering
- PPU palette RAM lookup
- PPUMASK emphasis colors
- sprites
Run this lesson
uv run pytest tests/chapter_05_rendering_pipeline/test_275_pattern_table_with_nes_palette.py -v