288. Apu audio register noop

Add explicit APU/audio no-op register behavior on CpuBus.

Lesson 288 of 356 · tests/chapter_06_rom_startup_preparation/test_288_apu_audio_register_noop.py

File to update

emulator/bus/cpu_bus.py

Why this step exists

Real NES ROMs commonly touch APU/audio registers during startup. Audio is outside this tutorial's current scope, but crashing on every audio register access makes manual ROM experiments stop before we can observe CPU/PPU/controller behavior.

This step teaches an intentional no-op

recognized address + documented out-of-scope behavior

not a broad fake hardware implementation.

What is the APU? The APU, or Audio Processing Unit, is the NES hardware block responsible for sound generation. The CPU controls it through memory-mapped registers.

Minimal example

CPU writes $4000
    real NES: configure pulse channel audio
    this tutorial for now: accept the write and produce no sound

Common misconception

"If the emulator accepts APU writes, APU is implemented."

No. In this step, APU/audio is explicitly recognized as out of scope. The emulator only avoids crashing on those addresses.

Suggested implementation example

def read(self, addr: int) -> int:
    ...

    # APU/audio registers are intentionally out of scope.
    if 0x4000 <= addr <= 0x4013:
        return 0
    if addr == 0x4015:
        return 0

    # Controller port 2 / expansion input is also out of scope for now.
    # Returning 0 means "no controller-2 buttons pressed" in this simplified model.
    if addr == 0x4017:
        return 0

    ...

def write(self, addr: int, value: int) -> None:
    ...

    # APU/audio registers are intentionally out of scope.
    if 0x4000 <= addr <= 0x4013:
        return
    if addr == 0x4015:
        return

    # $4017 writes control the APU frame counter on the NES.
    # Audio/APU timing is intentionally out of scope, so this is a no-op.
    if addr == 0x4017:
        return

    ...

Why these addresses

$4000-$4013
    APU sound-channel registers

$4015
    APU status/control register

$4017
    Writes: APU frame counter register, intentionally no-op for now.
    Reads: controller port 2 / expansion input, intentionally returns 0 for now.

Important exclusions

$4014 is OAMDMA, not audio.
    Writing $02 to $4014 should later copy CPU $0200-$02FF into PPU OAM.
    Do not swallow it as an APU no-op.

$4016 is controller port 1, not audio.
    It will be implemented intentionally in the controller chapter.
    Do not fake it by returning 0 here.

Out of scope

  • actual sound generation
  • APU timers/envelopes/sweep/length counters
  • IRQ/frame-counter timing
  • OAMDMA $4014
  • controller $4016
  • controller port 2 / expansion input reads from $4017
  • broad catch-all handling for all unsupported I/O addresses

Run this lesson

uv run pytest tests/chapter_06_rom_startup_preparation/test_288_apu_audio_register_noop.py -v