DMA registers

The SNES's DMA (Direct Memory Access) unit allows a game to copy graphics, palettes, OAM and more at a much higher speed than the CPU can accomplish alone. This allows a game to make better use of the limited amount of time it has in vblank to change graphical memory.

The SNES has two address buses - consisting of the A bus (which contains cartridge ROM, cartridge RAM, and the SNES's RAM) and the B bus (anything in the $2100-$21ff range, including PPU registers and APU registers). DMA always involves copying something from one of these two buses to something on the other bus.

DMA cannot copy from one area of the SNES's RAM to another, even if RAM is specified as both the source and destination. For that, the  and   instructions are probably the best available choice.

The SNES also features HDMA which runs in the background and can be set up to automatically write values to hardware registers at specific scanlines, allowing for effects.

These registers are always accessed at 3.58 MHz! That means that any channels that are not currently in use can have their registers repurposed for a small amount of fast RAM.

DMA channels
The SNES contains 8 separate DMA "channels" - each one contains a set of parameters to configure a DMA transfers. They are configured with registers in the $4300-$437f range, where the first 16 addresses correspond to the first register, the second 16 addresses correspond to the next, and so on.

MDMAEN - Start DMA transfer ($420B write)
7 bit  0 7654 3210 +- Channel 7 select
 * |||+- Channel 0 select
 * ||+-- Channel 1 select
 * |+--- Channel 2 select
 * + Channel 3 select
 * +-- Channel 4 select
 * +--- Channel 5 select
 * + Channel 6 select
 * + Channel 6 select

Upon writing to this register, a DMA transfer is started for each bit that was set, starting with the lowest selected channel number up toward the highest. The CPU is stopped until all transfers have completed. If an HDMA transfer happens while the DMA transfer is going, the DMA transfer will be temporarily paused to allow the HDMA transfer to happen.

HDMAEN - Enable HDMA transfers ($420C write)
7 bit  0 7654 3210 +- Channel 7 HDMA enable
 * |||+- Channel 0 HDMA enable
 * ||+-- Channel 1 HDMA enable
 * |+--- Channel 2 HDMA enable
 * + Channel 3 HDMA enable
 * +-- Channel 4 HDMA enable
 * +--- Channel 5 HDMA enable
 * + Channel 6 HDMA enable
 * + Channel 6 HDMA enable

This register enables HDMA for the selected channels.

DMAPx - DMA/HDMA parameters ($43x0 read/write)
7 bit  0 DI.F FPPP |||| |||| || | |+++- Pattern || +-+ 0:  Increment A bus address after copy ||        1/3: Fixed ||        2:   Decrement A bus address after copy ||        (These two bits affect DMA only, not HDMA) |+ Indirect (HDMA only) +- Direction: 0=Copy from A to B, 1=Copy from B to A

The "pattern" affects how many bytes are transferred each scanline in HDMA. For DMA, it allows copying to VRAM, which requires writing to two alternating addresses.

BBADx - B-bus address ($43x1 read/write)
7 bit  0 AAAA AAAA |||| |||| ++++-++++- Selects a hardware register to read or write from, in the $2100-$21ff range

UNUSEDx - Unused byte ($43xB and 43xF read/write)
7 bit  0 NNNN NNNN |||| |||| ++++-++++- Unused byte available at two different addresses

Seems to have no effect on DMA or HDMA, and this register cannot be used as a source for a DMA fill.

A1TxL, A1TxH, DMA Current Address ($43x2, $43x3 read/write)
A1TxH      A1TxL $43x3      $43x2 7 bit  0   7  bit  0 HHHH HHHH  LLLL LLLL |||| ||||  |||| |||| ++++-++++---++++-++++- Low 16 bits of the address on the A bus

These registers change as the DMA happens.

A1Bx - DMA Current Address (bank) ($43x4 read/write)
7 bit  0 BBBB BBBB |||| |||| ++++-++++- Bank byte for the A bus address

This register does not change during DMA. DMA can not cross banks.

DASxL, DASxH - DMA Byte-Counter ($43x5, $43x6 read/write)
DASxH      DASxL $43x6      $43x5 7 bit  0   7  bit  0 HHHH HHHH  LLLL LLLL |||| ||||  |||| |||| ++++-++++---++++-++++- 16-bit number that indicates how many bytes to transfer

A byte count of zero means 65536 bytes. This byte count is not affected by the DMA pattern. The SNES will stop before a pattern is completed if it runs out of bytes. Once the DMA finishes, these registers will be zero.

A1TxL, A1TxH, A1Bx - HDMA Table Start Address ($43x2, $43x3, $43x4 read/write)
A1Bx       A1TxH       A1TxL $43x4      $43x3       $43x2 7 bit  0   7  bit  0   7  bit  0 BBBB BBBB  HHHH HHHH   LLLL LLLL |||| ||||  |||| ||||   |||| |||| ++++-++++---++++-++++---++++-++++- 24-bit little-endian address on the A bus

These registers control where the channel's HDMA table is. This address gets copied into $43x8 and $43x9 every frame.

Other HDMA registers
These keep track of each channel's state as HDMA is happening.

DASxL, DASxH - Indirect HDMA Address ($43x5, $43x6 read/write)
DASxH      DASxL $43x6      $43x5 7 bit  0   7  bit  0 HHHH HHHH  LLLL LLLL |||| ||||  |||| |||| ++++-++++---++++-++++- Low 16 bits of the current indirect DMA address.

With indirect HDMA, if the repeat bit is set in the table entry, then the SNES will continue to read increasing addresses starting from the one given in the table, using these registers to keep track of where it currently is.

DASBx - Indirect HDMA Address (bank) ($43x7 read/write)
7 bit  0 BBBB BBBB |||| |||| ++++-++++- Bank number used for all indirect DMA addresses on this channel

This register must be set manually by the program.

A2AxL, A2AxH - HDMA Table Current Address ($43x8, $43x9 read/write)
A2AxH      A2AxL $43x9      $43x8 7 bit  0   7  bit  0 HHHH HHHH  LLLL LLLL |||| ||||  |||| |||| ++++-++++---++++-++++- Low 16 bits of the current address within the HDMA table

Bank byte is taken from $43x4 as it does not change.

NTRLx - HDMA Line-Counter ($43xA read/write)
7 bit  0 RLLL LLLL |||| |||| |+++-++++- Number of scanlines left +- Repeat flag

Automatically loaded from the table. Scanline count is decremented every scanline until it hits zero.

HDMA table format
HDMA tables specify what values to write to the selected B bus register, as well as which scanlines to write the values on. The tables can either directly contain the values (Direct mode) or specify 16-bit pointers that are then used to get the values (Indirect mode).

Direct HDMA table entries
1 byte - Line count, and repeat mode N bytes - Data

The number of bytes in each Data section is determined by the pattern chosen for the channel in register $43x0.


 * If repeat mode is off, one pattern's worth of bytes are written, then the SNES waits for the specified number of scanlines before continuing onto the next table entry.
 * If repeat mode is on, then the total size of the data section is the number of scanlines multiplied by the number of bytes in the pattern. One pattern's worth of bytes are written for however many scanlines indicated in the table.

Indirect HDMA table entries
1 byte - Line count, and repeat mode 2 bytes - Pointer to access the data through


 * If repeat mode is off, one pattern's worth of bytes are written from an address starting from the pointer given.
 * If repeat mode is on, the SNES continues to progress through the bytes that the pointer points to, for however many scanlines are indicated in the table.

Line count, repeat mode byte
Possible values for the "Line count, and repeat mode" byte are as follows:
 * $00: Stop processing HDMA on that channel for the rest of the frame.
 * $01-$80: Write once, then wait for X-1 scanlines
 * $81-$FF: Write every scanline for X-$80 scanlines, repeat mode