Spectrum Sprites
The Spectrum has no sprite hardware. Everything that moves is a software sprite: a small bitmap the program draws into the display file by hand, then erases and redraws each frame. The format and the techniques all follow from that.
Overview
Because there is no hardware sprite system, a sprite is just pixel data plus, usually, a mask. The program pokes it straight into screen memory at the right address, works out that address from the interleaved layout, and restores the background underneath when the sprite moves. All the cost is in the CPU, so sprite size and count trade against frame rate.
Sprite format
A sprite is stored as rows of bytes, eight pixels per byte, the top bit leftmost, exactly like the display file. A sprite w cells wide and h pixels tall is w × h bytes, held row by row. A sprite with a mask stores two bytes per cell per row: the mask that clears the background and the data that draws the shape.
| Field | Layout |
|---|---|
| Pixel row | 1 byte per 8 pixels, MSB left, 1 = ink |
| Mask row | 1 byte per 8 pixels, 0 where the sprite is solid |
| Order | Top row to bottom, left byte to right |
Masks and drawing
To place a sprite over a background without a black box around it, each screen byte is combined with the sprite in two steps: AND with the mask to punch a hole, then OR with the data to fill the shape. In Z80 terms, screen = (screen AND mask) OR data. The mask has zero bits where the sprite is opaque and one bits where the background should show through.
To move a sprite the program first restores the pixels it covered, either by saving them before drawing or by redrawing the background, then draws the sprite at the new position. Both the data and mask advance down the screen using the interleaved address rules.
Pre-shifting
A sprite drawn at any x that is not a multiple of eight straddles two bytes, so each source byte must be shifted and split across a byte boundary. Shifting on the fly is slow, so fast games store several pre-shifted copies of a sprite, one for each of the eight pixel offsets, each already spread across an extra byte of width. This trades memory for speed: eight copies, but no run-time shifting.
Colour and clash
A sprite's own bytes carry no colour. Colour comes from the attribute of whichever cell each pixel falls in, so a moving sprite takes on the two colours already set for the cells it crosses. Games handle this in a few ways: leave the background a plain paper colour so sprites read cleanly, write attributes along with the sprite to recolour its cells, or design the playfield so sprites and background never need different colours in the same cell.