Sprites

From SpecNext official Wiki
Revision as of 01:28, 1 January 2019 by wiki>Ped7g (Removing info about port $53 (does not exist on 2.00.xx cores), and removing some plain-wrong info (not all :/ ))
Jump to: navigation, search

Sprites are 16x16 independently moving images. Each can use up to 256 colors, independently selected from a palette.

To enable sprites, bit 0 of Sprite and Layers System Register ($15) must be set. If bit 1 is set also, sprites are permitted to cross the border.

The Next supports up to 64 sprites on screen at a time. It also supports 64 "patterns" (bitmap images used for sprites). These can be independent - for example, you could have several sprites with the same pattern.

To upload a pattern, write the pattern number to Sprite Status/Slot Select ($303B / 12347). Then write the pattern, byte by byte in reading order, to Sprite Pattern Upload ($xx5B / 91). The pattern must be exactly 256 bytes long, filling the 16x16 available area. Each byte is the index into the palette of the color of that pixel. The default palette simply maps the indexes 0-255 to colors 0-255 which are decoded as in Enhanced ULA. Sprites smaller than 16x16 must pad the extra space with the Sprites Transparency Index Register ($4B). After 256 bytes are written, continuing to write will write to the next pattern number, and so on (until pattern 63 is filled, after that the behaviour is officially "undefined" and code must set the pattern slot to valid value 0..63 before next write).

To display and move sprites, write the sprite number to Sprite Status/Slot Select ($303B / 12347), then control the sprite by writing a 4 byte packet to Sprite Attribute Upload ($xx57 / 87) to which 4 byte packets are set. This sets the position of the sprite, which pattern it displays, and what effects are applied. Full details of the packet contents are given on the page for that port.

You can overwrite the standard sprite palettes by using palette registers Enhanced ULA Control Register ($43), Palette Index Register ($40), Palette Value Register ($41) and Enhanced ULA Palette Extension ($44). Since sprite "pixels" are offsets into palette, with well prepared palette (including multiple "sub-palettes" for some patterns) you can render the same sprite pattern in different colours by using offset option at Sprite Attribute Upload ($xx57 / 87).

Reading from Sprite Status/Slot Select ($303B / 12347) returns information about the currently available sprites. If bit 1 is set, more than 12 sprites are active on a line, which means that the extra are not being displayed. If bit 0 is set, two or more sprites are overlapping. It is not possible to obtain details of which sprites are overlapping, so this should be used as a signal to run more detailed collision detection.