liveBook · Manning

Direct memory access

As explained in Classic Game Programming on the NES: Make your own retro video game

A hardware-supported transfer mechanism that moves data between memory regions without requiring the CPU to copy each byte.

A DMA engine transfers a complete block of data between memory areas without making the CPU copy each byte. On the NES, the NMI routine uses DMA to move the sprite OAM table from CPU memory to the PPU's sprite data area. section 5.13

Configure a sprite DMA transfer in three steps:

  • Set the PPU sprite-memory address to zero. section 5.13
  • Load the high byte of the OAM table address into the A register; for an OAM address of $0200, this value is $02. section 5.13
  • Store that byte in the sprite DMA register, triggering transfer of all 256 OAM bytes to the PPU. section 5.13

Placing the transfer in the NMI routine allows it to run whenever rendering should occur. Palette data still requires ordinary CPU writes to VRAM because no second DMA transfer is available. section 5.13

Listing 5.20 Transferring the sprite table to video memory (example.s)
                   #1
    ldx #0
    stx PPU_SPRRAM_ADDRESS
    lda #>oam
    sta SPRITE_DMA

Inspect the assembly fragment that initializes sprite memory, extracts the OAM address high byte, and triggers DMA. section 5.13

How Classic Game Programming on the NES: Make your own retro video game covers it

How deep it goes
Explains the register trigger, address high byte, and 256-byte transfer, but not DMA hardware internals.
Examples
Uses an OAM table at $0200 and an assembly listing that writes its high byte to the sprite DMA register.
What it assumes
Assumes basic assembly registers and labels while explaining 16-bit addresses and 8-bit register loading.
What you can do after
Operate/configure NES sprite transfers by loading an OAM page address and writing it to the DMA register.
How it connects
Connects NMI routines, sprite OAM, PPU video memory, and VRAM palette updates.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Game Programming on the NES: Make your own retro video game. The section links point to the parts of the book it draws on.