242. Ppudata writes through ppu bus
Implement PPUDATA ($2007) writes through PpuBus.
Lesson 242 of 356 · tests/chapter_03_ppu_memory_and_graphics_data/test_242_ppudata_writes_through_ppu_bus.py
Reference
https://www.nesdev.org/wiki/PPU_registers#PPUDATAFile to update
emulator/ppu/ppu.pyMethod to update
PPU.write_register(addr, value)Why this step exists
PPUDATA is the CPU-visible register at $2007. The CPU writes to $2007, but the actual PPU memory address written is not CPU address $2007. The actual target is the PPU's internal VRAM address:
vram_addrThat address is set by PPUADDR ($2006), then PPUDATA ($2007) writes through the
PPU-side bus
PPU.write_register($2007, value)
-> ppu_bus.write(vram_addr, value)
-> increment vram_addrImportant future-compatibility choices in this test
- Use non-CHR addresses such as $2000, not $0000-$1FFF.
CHR writes will later involve mapper.write_chr / CHR RAM behavior.
- Test increment-by-1 only when PPUCTRL increment mode is clear.
Later, PPUCTRL bit 2 may select increment-by-32. These tests should not
block that future behavior.Suggested implementation pseudocode for the current stage
case 0x2007:
self.data = value
self.ppu_bus.write(self.vram_addr, value)
self.vram_addr = (self.vram_addr + 1) & 0x3FFFFuture implementation note
Later, the increment may become
increment = 32 if self.ctrl & VRAM_INCREMENT_BY_32 else 1
self.vram_addr = (self.vram_addr + increment) & 0x3FFFOut of scope
- PPUDATA reads
- PPUDATA read buffering
- palette read exceptions
- CHR RAM writes
- PPUCTRL increment-by-32 behavior
Run this lesson
uv run pytest tests/chapter_03_ppu_memory_and_graphics_data/test_242_ppudata_writes_through_ppu_bus.py -v