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
