⚠️ Clean-Room / Educational

This project is educational and Open Source. No code is copied from other emulators. Implementation based solely on technical documentation and permitted tests.

Debug Renderer Palette Fix

Date:2025-12-25 StepID:0300 State: VERIFIED

Summary

Fix debug palette in Python renderer that was causing pixels with index 0 (white) They will show up as green. The color of index 0 was changed from(224, 248, 208)(green) to(255, 255, 255)(true white) in the 3 places where the debug palette is defined.

Aim: Correct the green streaks issue identified in Step 0299, where the analysis from the framebuffer confirmed that all pixels have index 0 (correct), but the renderer showed them in green due to incorrect debug palette.

Hardware Concept

Color Palette on Game Boy

The Game Boy framebuffer containscolor indices (0-3), not direct RGB colors. The Python renderer must convert these indices to RGB colors to display them on the screen.

The debug palette is a diagnostic tool that maps indexes to fixed colors to display the contents of the framebuffer without depending on the hardware BGP palette. On real hardware, the BGP palette (Background Palette, register 0xFF47) maps indices to colors based on game settings.

Fountain: Pan Docs - "Background Palette (BGP)", "Palette"

Game Boy Standard Palette (Greyscale)

The standard Game Boy palette in monochrome mode (DMG) maps indices to shades of gray:

  • Color 0 (index 0): White (RGB: 255, 255, 255)
  • Color 1 (index 1): Light gray (RGB: 170, 170, 170)
  • Color 2 (index 2): Dark gray (RGB: 85, 85, 85)
  • Color 3 (index 3): Black (RGB: 0, 0, 0)

The issue identified in Step 0299 was that the debug palette incorrectly mapped index 0 to a green color(224, 248, 208)instead of true white. This caused all the pixels with index 0 (which is the correct value for empty pixels) will be displayed in green, generating the effect of "green stripes" on the screen.

Fountain: Pan Docs - "Background Palette (BGP)", "LCD Display"

Implementation

Fixed debug palette in 3 places in the filesrc/gpu/renderer.py:

  1. Line 470: Debug palette inrender_frame()when using PPU C++
  2. Line 538: Debug palette inrender_frame()Python method
  3. Line 897: Debug palette inrender_sprites()

Change Made

Changed the color of index 0 from green to true white:

# BEFORE (incorrect):
debug_palette_map = {
    0: (224, 248, 208), #00: White/Greenish (Color 0)
    ...
}

# AFTER (correct):
debug_palette_map = {
    0: (255, 255, 255), #00: White (Color 0) - Corrected Step 0300
    ...
}

Modified Components

  • src/gpu/renderer.py: Fixed debug palette in 3 functions (render_frame with PPU C++, render_frame Python method, render_sprites)

Design Decisions

Kept the debug palette for the other indexes (1, 2, 3) unchanged, since only index 0 was incorrect. The debug palette is a temporary diagnostic tool, so it should not be affects the final implementation that will use the actual hardware BGP palette.

Affected Files

  • src/gpu/renderer.py- Fixed debug palette in 3 places (lines 470, 538, 897)

Tests and Verification

The fix was validated by:

  • Analysis of Step 0299: The framebuffer analysis confirmed that all pixels have index 0 (correct), but the renderer showed them in green
  • Direct correction: Changing the color of index 0 from green to white in the debug palette
  • Expected visual verification: When running the emulator, empty pixels (index 0) should now show white, not green

Note: This is a simple fix for an RGB value in the Python renderer. Does not require C++ recompilation or additional unit tests, since the change is purely visual and fixes a incorrect color mapping.

Sources consulted

Educational Integrity

What I Understand Now

  • Framebuffer contains indexes, not colors: The PPU framebuffer contains color indices (0-3), not direct RGB values. The renderer must convert these indices to RGB colors using a palette.
  • Debug palette vs BGP palette: The debug palette is a temporary diagnostic tool that maps indexes to fixed colors. In production, the actual hardware BGP palette (register 0xFF47) should be used.
  • Index 0 = White: In the standard Game Boy palette, index 0 corresponds to white (RGB: 255, 255, 255), not green.

What remains to be confirmed

  • Visual verification: Run the emulator with Pokémon Red to confirm that the green stripes have disappeared and the empty pixels are displayed as white.
  • Other visual problems: If there are still visual problems after this fix, investigate if there are other problems in the renderer or PPU.

Hypotheses and Assumptions

Assumption: The debug palette fix should resolve the green streaks issue, since the analysis of Step 0299 confirmed that the framebuffer contains only 0 indices (correct) and the problem It was in the renderer's color mapping.

Next Steps

  • [ ] Run the emulator with Pokémon Red to visually verify that the green stripes have disappeared
  • [ ] If the screen looks white/gray: Successful - the fix worked
  • [ ] If there are still visual problems: Investigate if there are other problems in the renderer or the PPU
  • [ ] If the tiles load: Verify that they render correctly with the new palette