Skip to main content

Module obj

Module obj 

Source
Expand description

Objects: the 40 sprites the PPU draws over the background.

Each is four bytes in OAM at 0xFE00, described by OamEntry. Position is offset so that a sprite can sit partly off screen: y of 16 and x of 8 put it at the top left corner, and either axis at zero hides it.

Object tiles always read as Base8000, whatever the background is set to. In Tall the low bit of the index is ignored and the pair is drawn as one 8 by 16 sprite. See https://gbdev.io/pandocs/OAM.html.

§What the hardware drops

Only PER_SCANLINE objects are drawn on any one scanline; the rest of that line’s are skipped. Which ones survive is by x on the original Game Boy, lower first, and by OAM index on the Game Boy Color. Nothing reports the loss.

§Writing OAM

Writing entries directly costs a blanking window per byte. The usual way is a OamShadow page in work RAM, edited whenever, handed to the hardware in one OamDma once a frame. See https://gbdev.io/pandocs/OAM_DMA_Transfer.html.

Structs§

OamDma
The transfer routine, once it is in HRAM and callable.
OamShadow
A page of entries for OamDma to hand over.

Enums§

Size
How tall an object is, from LCDC bit 2. It applies to all of them at once.

Constants§

DMA_LEN
Bytes OamDma::install needs. Keep in step with the ram_fn below.
ENTRY_COUNT
Objects OAM holds.
PER_SCANLINE
Objects the PPU draws on one scanline.
SPARE
Bytes past the entries that the alignment pays for anyway.

Functions§

enabled
Whether the PPU draws objects at all, from LCDC bit 1.
hide
Move an object off screen, which is the only way to stop it being drawn.
set
Write one entry.
set_enabled
Draw objects, or stop.
set_size
Set the size every object is drawn at.
size
The size every object is drawn at.