SNES DMA (Direct Memory Access). More...
#include <snes/types.h>Go to the source code of this file.
Functions | |
| void | dmaClearVRAM (void) |
| Clear all VRAM to zero. | |
| void | dmaCopyCGram (const u8 *source, u16 startColor, u16 size) |
| Copy palette data to CGRAM (PVSnesLib compatible). | |
| void | dmaCopyOam (const u8 *source, u16 size) |
| Copy OAM data (PVSnesLib compatible). | |
| void | dmaCopyVram (const u8 *source, u16 vramAddr, u16 size) |
| Copy data to VRAM (PVSnesLib compatible). | |
| void | dmaCopyVramMode7 (const u8 *tilemap, u16 tilemapSize, const u8 *tiles, u16 tilesSize) |
| Load Mode 7 interleaved data to VRAM. | |
| void | dmaFillVRAM (u16 value, u16 dest, u16 size) |
| Set VRAM to a value. | |
| void | dmaTransfer (u8 channel, u8 mode, const u8 *src, u8 destReg, u16 size) |
| Perform generic DMA transfer. | |
Variables | |
| u16 | dma_unsafe_count |
| DMA calls that wrote with the screen on outside VBlank, started outside it or run past its end (see dmaCopyVram()): 0 on a healthy run. Wraps at 65536. | |
SNES DMA (Direct Memory Access).
Functions for fast memory transfers using DMA.
DMA allows fast transfers between:
DMA is much faster than CPU copying and should be used for all bulk transfers during VBlank.
This header claimed the opposite ("source data must be in bank $00") long after it stopped being true, and that prose is why the RPG template shipped a pointless semifree bank 0 section for its palettes — and why issue #122 carried a bank-$00 claim about dmaCopyCGram that testing then had to retract.
| void dmaClearVRAM | ( | void | ) |
Clear all VRAM to zero.
Clears all 64KB of VRAM. Should be called during force blank.
Copy palette data to CGRAM (PVSnesLib compatible).
Copies palette data from ROM or RAM to CGRAM using DMA.
| source | Source address (can be ROM or RAM) |
| startColor | Starting color index (0-255) |
| size | Number of bytes to copy (2 bytes per color) |
source's own bank byte: a palette may live in any bank. Copy OAM data (PVSnesLib compatible).
| source | Source address (544 bytes) |
| size | Number of bytes to copy (usually 544) |
Copy data to VRAM (PVSnesLib compatible).
Copies data from ROM or RAM to VRAM using DMA. This function handles 24-bit source addresses, so it works with ROM data defined via extern.
| source | Source address (can be ROM or RAM) |
| vramAddr | Destination word address in VRAM |
| size | Number of bytes to copy |
Forced blank means setScreenOff() — INIDISP bit 7.
Since this version the call tells you. A transfer made with the screen on outside VBlank — started outside it, or started inside it and still running when it ends — still runs (it always did) but is counted in dma_unsafe_count and fires WDM $02, which luna reports (--wdm-out; a manifest's wdm_empty = true fails on it). One call counts once, even dmaFillVRAM() and dmaCopyVramMode7(), which make two passes. The end is read from HVBJOY right after the transfer (the CPU is stopped while it runs), with IRQs masked for those few cycles. Not seen: a single transfer longer than the whole active display (about 38 KB) that ends in the next VBlank. The screen state is the shadow setScreenOn() / setScreenOff() keep: write REG_INIDISP yourself and the shadow is behind. Applies to dmaCopyVram(), dmaCopyCGram(), dmaCopyOam(), dmaCopyVramMode7() and dmaFillVRAM(). Cost, measured (libbench row dma, 2 KB): +276 master cycles a call, both checks. setBrightness(0) blacks the screen but leaves the PPU fetching, so it does NOT open the write window.
source's own bank byte, so the data may live in ANY bank — a SUPERFREE section, a bank you pinned yourself. Load Mode 7 interleaved data to VRAM.
Mode 7 stores tilemap in VRAM low bytes and tile pixels in VRAM high bytes. This function performs two DMA transfers with appropriate VMAIN settings:
VRAM destination is always $0000 (Mode 7 uses the full 32K word space).
| tilemap | Tilemap data source (.mp7 file, 128x128 = 16384 bytes) |
| tilemapSize | Tilemap data size in bytes |
| tiles | Tile pixel data source (.pc7 file, 256 tiles x 64 bytes) |
| tilesSize | Tile pixel data size in bytes |
Set VRAM to a value.
| value | 16-bit word to fill with (low byte to the even VRAM byte, high byte to the odd one). Until 2026-09-20 only the low byte was used, for both halves. |
| dest | Destination word address in VRAM |
| size | Number of bytes to fill, rounded up to a whole word — 0 means 65536 (the full VRAM), which is how dmaClearVRAM() uses it |
Perform generic DMA transfer.
Programs one channel and starts it at once: use it when no named helper fits (the WRAM data port, an experimental mode). The source's bank comes from the far pointer, like every other dmaCopy* call — until 0.48 this function took the bank and the 16-bit address as two arguments (the 1.0 API since 2026-10-05; a six-argument call no longer compiles, see docs/UPGRADING.md). A channel above 7 is refused.
| channel | DMA channel (0-7) |
| mode | DMA mode byte (DMAP: transfer pattern, direction, fixed source) |
| src | Source, in any bank (ROM, bank $7E RAM, FAR data) |
| destReg | Destination B-bus register (the low byte of $21xx) |
| size | Transfer size in bytes (0 = 65536) |
|
extern |
DMA calls that wrote with the screen on outside VBlank, started outside it or run past its end (see dmaCopyVram()): 0 on a healthy run. Wraps at 65536.