⚠️ 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.

Tile Map Inspector

Date:2025-12-23 StepID:0263 State: draft

Summary

This Step instruments the PPU to inspect the Tile Map being used during rendering. Step 0262 confirmed that MBC1 is working perfectly and the ROM is reading correctly, but the screen is still blank. The hypothesis is that there is a mismatch in the PPU configuration (Tile Map vs Tile Data) or that the Tile Map is empty. This instrumentation will allow us to verify if the memory area that the PPU is using as a Tile Map contains valid tile indexes or is completely empty.

Hardware Concept

Tile Map:The Tile Map is a 32x32 byte table (1024 bytes) that contains the indexes of the tiles that must be drawn in each position of the background. The PPU reads the Tile Map to determine which tile to draw at each position on the screen.

Tile Map Settings:The LCDC register (0xFF40) controls which area of ​​VRAM is used as a Tile Map:

  • Bit 3:Background Tile Map Area (`0=9800`, `1=9C00`).
  • Bit 4:Background & Window Tile Data Area (`0=8800`, `1=8000`).

The mismatch problem:If the game uses the map at `9C00` but we look at `9800` (or vice versa), we will see white. If the game uses tiles in `8000` but we use `8800` (signed), we will see garbage or white. If the Tile Map is completely empty (all bytes are `00`), the PPU will render only tile 0, which can be white or transparent.

The Tile Map inspection:To diagnose the problem, we need to verify what the Tile Map that the PPU is using actually contains. If all bytes are `00`, the map is empty and the map has not been copied. If there are mixed bytes, the map has data and we should see something on the screen.

Fountain:Pan Docs - "LCD Control (LCDC)", "Tile Map", "Tile Data"

Implementation

The method was modifiedrender_scanline()ofPPU.cppto inspect the Tile Map only once when LY=100 (half screen). The inspector displays the LCDC value, the Tile Map base address, the Tile Data base address, and the first 16 bytes of the Tile Map.

Modified components

  • PPU::render_scanline(): Added inspection code that runs only once when LY=100, showing the PPU configuration and the first 16 bytes of the Tile Map.
  • MMU.cpp: Commented diagnostic logs[VRAM], [ROM-READ]and[MBC1]to reduce noise at the output and allow the inspector's log to be clearly seen.

Design decisions

Single inspection:The inspector is executed only once when LY=100 using a static flagmap_inspected. This avoids cluttering the logs with repeated information and allows you to see the status of the Tile Map after the game has had time to initialize.

Complete information:The inspector displays LCDC (to see the settings), the base addresses of the Tile Map and Tile Data (to check which areas are being used), and the first 16 bytes of the Tile Map (to see if it contains data or is empty).

Log cleaning:The previous diagnostic logs were commented ([VRAM], [ROM-READ], [MBC1]) to reduce noise at the output and allow the inspector log to be clearly seen. The critical log of[MBC1 CRITICAL]remains active to detect serious errors.

Affected Files

  • src/core/cpp/PPU.cpp- Modified methodrender_scanline()to inspect the Tile Map (Step 0263).
  • src/core/cpp/MMU.cpp- Commented diagnostic logs[VRAM], [ROM-READ]and[MBC1]to reduce noise (Step 0263).

Tests and Verification

To validate this instrumentation:

  1. Recompile: .\rebuild_cpp.ps1
  2. Execute: python main.py roms/pkmn.gb(Pokémon Red is ideal because it has 1024KB of ROM and requires multiple banks).
  3. Observe the logs:
    • Look for[PPU INSPECT]- Shows the PPU configuration and the first 16 bytes of the Tile Map.
    • If the map bytes are all `00`:The map is empty -> The map has not been copied. The game may be clearing VRAM before copying data, or there may be a problem in the logic of copying data to VRAM.
    • If the bytes are varied:The map has data -> We should see something on the screen. If the screen is still blank, the problem is somewhere else (possibly in the PPU rendering or Tile Data settings).

Expected validation:If the Tile Map contains various data but the screen is still empty, we need to check the Tile Data configuration (signed vs unsigned addressing) or the PPU rendering. If the Tile Map is empty, we need to wait longer or check why the game is not copying the map to VRAM.

Sources consulted

Educational Integrity

What I Understand Now

  • Tile Map:El Tile Map es una tabla de 32x32 bytes que contiene los índices de los tiles que se deben dibujar en cada posición del fondo. The PPU reads the Tile Map to determine which tile to draw.
  • LCDC Settings:The LCDC register controls which area of ​​VRAM is used as Tile Map (bit 3) and which area is used as Tile Data (bit 4). An imbalance in this setting may result in a blank screen.
  • Tile Map Diagnostics:If the Tile Map is empty (all bytes are `00`), the PPU will render only tile 0, which can be white or transparent. If the Tile Map contains data but the screen is still empty, the problem lies elsewhere.

What remains to be confirmed

  • Tile Map Content:Does the Tile Map contain valid tile indexes or is it completely empty? The logs will tell us if the map has data or if it is empty.
  • Correct configuration:Is the PPU using the same Tile Map and Tile Data settings that the game expects? The inspector will show us which areas are being used.
  • Correlation with rendering:If the Tile Map contains data but the screen is still empty, is the problem with the PPU rendering or the Tile Data settings?

Hypotheses and Assumptions

Main hypothesis:If MBC1 works (Step 0262) and the ROM is read successfully, but the screen is still blank, it is possible that:

  1. The Tile Map is empty:The game may be clearing VRAM before copying data, or there may be a problem in the logic of copying data to VRAM.
  2. Configuration mismatch:The game may be using a different Tile Map or Tile Data configuration than the PPU is using.
  3. Rendering problem:If the Tile Map contains data but the screen is still empty, the problem is with the PPU rendering or Tile Data settings.

This instrumentation will allow us to distinguish between these cases and determine where the real problem is.

Next Steps

  • [ ] Executepython main.py roms/pkmn.gband observe the inspector's log.
  • [ ] If the Tile Map is empty, check why the game is not copying the map to VRAM or wait longer.
  • [ ] If the Tile Map contains data but the screen is still empty, check the Tile Data settings or PPU rendering.
  • [ ] Correlate Tile Map content with LCDC settings to determine if there is a mismatch.
  • [ ] If necessary, also implement the reading of Tile Data to verify if the tiles are loaded correctly.