Display/Sprites

From WSdev Wiki
Jump to navigationJump to search

The display system can show up to 128 sprites at once.

Sprites are always drawn in front of Screen 1, but they can be drawn in front of or behind Screen 2.

Sprites are stored in a sprite table in the console's internal RAM. It consists of up to 128 four-byte entries, of which any sequential slice can be displayed:

 (Byte 1)   (Byte 0)
15  bit  8  7  bit  0
 ---- ----  ---- ----
 vhPi pppt  tttt tttt
 |||| ||||  |||| ||||
 |||| |||+--++++-++++- Tile index (0-511) - only tile bank 0
 |||| +++------------- Palette (0-7) - mapped to screen palettes 8-15
 |||+----------------- Window location - 0 = inside, 1 = outside
 ||+------------------ Priority - 0 = behind Screen 2, 1 = in front of Screen 2
 |+------------------- Horizontal flip
 +-------------------- Vertical flip

 (Byte 2)
 7  bit  0
 ---- ----
 yyyy yyyy
 |||| ||||
 ++++-++++- Y coordinate

 (Byte 3)
 7  bit  0
 ---- ----
 xxxx xxxx
 |||| ||||
 ++++-++++- X coordinate

There is a sprite limit of 32 per scanline. This means that for each scanline, only the first 32 sprites will be drawn. Note that this includes sprites obscured by windows or outside of visible X coordinates; this list is determined solely by the Y coordinate. Between sprites themselves, earlier sprites in the list are always drawn on top of later sprites in the list.

The sprite table is copied from the console's RAM to a SoC-internal buffer every frame on line 144; one word for every clock of the line, totaling 256 words (512 bytes) for 256 clocks. This internal buffer is then used for reading sprite data on the next frame.