Skip to main content

Module hdma

Module hdma 

Source
Available on crate feature cgb only.
Expand description

The Game Boy Color’s copier into video memory.

The quickest way to put data in video memory. There are two, and what separates them is not speed but what the program may do meanwhile. See https://gbdev.io/pandocs/CGB_Registers.html#ff51ff52--hdma1-hdma2-cgb-mode-only-vram-dma-source-high-low-write-only.

copy stops the CPU until the whole block has moved, so nothing else runs and there is nothing to get wrong. One of the largest size roughly fills a VBlank, which is most of a tileset.

stream moves one block per HBlank and lets the program run in between, reaching a comparable amount over a frame. What it costs is listed on Stream, and the list is long: it holds the video memory bank and the source bank still for its whole life, and a sleeping CPU stops it. It suits a stretch where nothing else touches video memory, a loading screen rather than a scrolling level.

Neither reaches an original Game Boy, which has no such hardware: the write that would start a transfer goes nowhere, and the call returns having moved nothing.

Structs§

Source
Storage the copier can read, aligned as it needs.
Stream
A stream under way, one block per HBlank.

Constants§

BLOCK_LEN
Bytes one transfer step moves, and the granularity of everything here.
MAX_LEN
Bytes the largest transfer carries.

Functions§

copy
Copy src to dst in video memory, stopping the CPU until it is done.
stream
Start moving src to dst sixteen bytes at a time, one step per HBlank.