235. Ppu bus vram read write

Add basic PpuBus read/write forwarding to VRAM.

Lesson 235 of 356 · tests/chapter_03_ppu_memory_and_graphics_data/test_235_ppu_bus_vram_read_write.py

File to update

emulator/bus/ppu_bus.py

Methods to implement

PpuBus.read(addr: int) -> int
PpuBus.write(addr: int, value: int) -> None

Why this step exists

Before PPUADDR/PPUDATA can write to video memory, the PPU needs a bus-like object that can accept PPU addresses and perform memory access.

For this first read/write step, avoid testing the CHR region $0000-$1FFF. CHR will be tested separately because it involves cartridge mapper behavior.

Use non-CHR addresses such as $2000 for now:

PpuBus.write($2000, $AA)
PpuBus.read($2000) -> $AA

Suggested implementation pseudocode for the non-CHR/default region

def read(self, addr: int) -> int:
    addr = addr & PPU_ADDRESS_MASK
    return self.vram.read(addr)

def write(self, addr: int, value: int) -> None:
    addr = addr & PPU_ADDRESS_MASK
    self.vram.write(addr, value)

Later, these methods will grow sections for

  • CHR area: $0000-$1FFF
  • nametable area: $2000-$3EFF
  • palette area: $3F00-$3FFF

Run this lesson

uv run pytest tests/chapter_03_ppu_memory_and_graphics_data/test_235_ppu_bus_vram_read_write.py -v