This project is educational and Open Source. No code is copied from other emulators. Implementation based solely on technical documentation and permitted tests.
Patience and Aim: Searching the Right Map
Summary
The previous autopsy showed that the CPU advances (exited the boot loop) and that the Timer works. However, the LCD is still off. We observe that `LCDC` has Bit 3 activated, which indicates that the game uses the second tilemap (`0x9C00`), not the first one (`0x9800`) we were inspecting. Adjusted autopsy to read the correct map based on game settings and increased time wait to 10 seconds to rule out slow loading.
Hardware Concept
The LCDC register (LCDC Control, address 0xFF40) controls multiple aspects of the video system of the Game Boy. Bit 3 of this register determines which region of VRAM is used as the tilemap. (Tile Map) for the background (Background):
- Bit 3 = 0:Tile Map Base = 0x9800 (range 0x9800-0x9BFF)
- Bit 3 = 1:Tile Map Base = 0x9C00 (range 0x9C00-0x9FFF)
If the game sets Bit 3 to 1 and writes data to map 0x9C00, but our diagnostic always reads from 0x9800, we will see empty data even if the game has written correctly in the correct region. This is a classic diagnostic error: inspecting the wrong memory region.
Fountain:Pan Docs - LCD Control Register (LCDC), Tile Map Addressing
Implementation
Changed the autopsy function in `viboy.py` to:
- Read LCDC dynamically:Before inspecting the Tile Map, we read the log LCDC (0xFF40) and check Bit 3.
- Select the correct map:If Bit 3 is active, we read from 0x9C00; if not, from 0x9800.
- Increase waiting time:We changed the autopsy trigger to 180 frames (3 seconds) to 600 frames (10 seconds) to give the game more time to complete its initialization.
Modified components
src/viboy.py: Enhanced autopsy function with smart Tile Map reading
Specific changes
# Before (Step 0225):
if not self._autopsy_done and self.frame_count >= 180:
#...
print(f"\nVRAM Tile Map (0x9900 - Center approx):")
map_sample = [f"{self._mmu.read(0x9900 + i):02X}" for i in range(16)]
# After (Step 0234):
if not self._autopsy_done and self.frame_count >= 600:
#...
lcdc = self._mmu.read(0xFF40)
bg_map_base = 0x9C00 if (lcdc & 0x08) else 0x9800
print(f"\nVRAM Tile Map (Base 0x{bg_map_base:04X} - according to LCDC Bit 3):")
map_sample = [f"{self._mmu.read(bg_map_base + i):02X}" for i in range(16)]
Affected Files
src/viboy.py- Modification of the autopsy function (Step 0234)
Tests and Verification
Verification will be done by running the emulator and observing the autopsy output:
- Command:
python main.py roms/tetris.gb - Expected result:After 10 seconds (600 frames), the autopsy will show:
- The LCDC value with indication of the selected map
- Tile Map data read from correct region (0x9C00 if Bit 3 is active)
- CPU status showing that the game advanced beyond the initial loop
Validation:If the Tile Map shows non-null data in the correct region, we will confirm that the game is writing correctly and that the problem could be on screen power-up (LCDC Bit 7) or rendering.
Sources consulted
- Bread Docs:LCDC Control Register
- Bread Docs:Video Display - Tile Maps
Educational Integrity
What I Understand Now
- LCDC Bit 3:Controls which VRAM region is used as the base Tile Map. It is critical to read these settings before inspecting the memory, as the game you can use either of the two available regions.
- Smart diagnosis:Diagnostic tools must be adapted to the current state of the emulated hardware, do not assume fixed values. This is especially important in systems with multiple modes of operation or alternative memory regions.
What remains to be confirmed
- Data on the correct map:Check if the Tile Map at 0x9C00 contains Valid data after 10 seconds of execution.
- LCD status:Confirm if LCDC Bit 7 (LCD Enable) is activated during the game initialization or if it remains turned off for some reason.
Hypotheses and Assumptions
Main hypothesis:The game is writing data to the correct Tile Map (0x9C00), but our previous diagnostic tool was reading from the wrong region (0x9800), showing empty data even though the game was working correctly.
Assumption:If the Tile Map shows valid data in the correct region, The problem could be in:
- LCD does not turn on (LCDC Bit 7 remains at 0)
- Rendering is not reading the correct Tile Map
- The game requires more time to complete initialization
Next Steps
- [ ] Run the emulator and observe the autopsy after 10 seconds
- [ ] Check if the Tile Map in the correct region contains data
- [ ] If there is data but the screen is still off, investigate the status of LCDC Bit 7 (LCD Enable)
- [ ] If the LCD is on but not rendering, check the PPU rendering logic