Last modified on 19 September 2010, at 16:31

Programming:Amstrad CPC plus sprite format

Revision as of 16:31, 19 September 2010 by Redbox (Talk | contribs) (moved Amstrad CPC plus sprite format to Programming:Amstrad CPC plus sprite format: Update to Programming tag)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

A great feature of the Amstrad CPC plus is hardware sprites. Hardware sprites are handled by the ASIC. The ASIC can handle up to 16 sprites per scanline, each hardware sprite is always 16 x 16 pixels of size.

The data

Each sprite can display 15 distinct colours, the pixel colours are indexed #0 - #F.

Index #0 is always transparency, whereas index #1 - #F is the colour index in the sprite palette.

To define a sprite in the ASIC. 16 x 16 (256) bytes must be transferred to the ASIC.

The format of the data is straight forward. The data is organized in a linear manner. Each sprite pixel uses a single byte, the upper nibble is ignored by the ASIC.

The colour palette

The ASIC can handle 4096(16x16x16) colours. Each colour is defined as values of red, green and blue. Each value is handled as 4bit values.

The hardware code send to the ASIC is #0grb.

In the below example changing the palette index colour 1 to value #0F00 gives a green Pac sprite.

Green pac.png

changing the palette index colour 1 to value #00F0 gives a red Pac sprite.

Red pac.png

and finally changing the palette index colour 1 to value #000F gives a blue Pac sprite.

Blue pac.png

Example

Below is shown an example of how a sprite is organized into raw data. To transfer the sprite data to the ASIC look here: Transfer to ASIC

Cpcplussprite.png

<geshi lang=Z80> .pac_sprite

The raw sprite data - to be transfered to the ASIC

db #00,#00,#00,#00,#00,#00,#00,#00,#00,#00,#00,#00,#00,#00,#00,#00 db #00,#00,#00,#00,#00,#00,#01,#01,#01,#01,#00,#00,#00,#00,#00,#00 db #00,#00,#00,#00,#01,#01,#01,#01,#01,#01,#01,#01,#00,#00,#00,#00 db #00,#00,#00,#01,#01,#01,#01,#01,#01,#01,#01,#01,#01,#00,#00,#00 db #00,#00,#01,#01,#01,#01,#01,#01,#01,#01,#01,#01,#01,#01,#00,#00 db #00,#00,#01,#01,#03,#03,#01,#01,#01,#01,#03,#03,#01,#01,#00,#00 db #00,#00,#01,#03,#03,#03,#03,#01,#01,#03,#03,#03,#03,#01,#00,#00 db #00,#01,#01,#03,#03,#03,#03,#01,#01,#03,#03,#03,#03,#01,#01,#00 db #00,#01,#01,#03,#02,#02,#03,#01,#01,#03,#02,#02,#03,#01,#01,#00 db #00,#01,#01,#01,#02,#02,#01,#01,#01,#01,#02,#02,#01,#01,#01,#00 db #00,#01,#01,#01,#01,#01,#01,#01,#01,#01,#01,#01,#01,#01,#01,#00 db #00,#01,#01,#01,#01,#01,#01,#01,#01,#01,#01,#01,#01,#01,#01,#00 db #00,#01,#01,#01,#00,#01,#01,#01,#01,#01,#01,#00,#01,#01,#01,#00 db #00,#00,#01,#00,#00,#00,#01,#01,#01,#01,#00,#00,#00,#01,#00,#00 db #00,#00,#00,#00,#00,#00,#00,#00,#00,#00,#00,#00,#00,#00,#00,#00 db #00,#00,#00,#00,#00,#00,#00,#00,#00,#00,#00,#00,#00,#00,#00,#00

Compressed data

db #00,#00,#00,#00,#00,#00,#00,#00 db #00,#00,#00,#11,#11,#00,#00,#00 db #00,#00,#11,#11,#11,#11,#00,#00 db #00,#01,#11,#11,#11,#11,#10,#00 db #00,#11,#11,#11,#11,#11,#11,#00 db #00,#11,#33,#11,#11,#33,#11,#00 db #00,#13,#33,#31,#13,#33,#31,#00 db #01,#13,#33,#31,#13,#33,#31,#10 db #01,#13,#22,#31,#13,#22,#31,#10 db #01,#11,#22,#11,#11,#22,#11,#10 db #01,#11,#11,#11,#11,#11,#11,#10 db #01,#11,#11,#11,#11,#11,#11,#10 db #01,#11,#01,#11,#11,#10,#11,#10 db #00,#10,#00,#11,#11,#00,#01,#00 db #00,#00,#00,#00,#00,#00,#00,#00 db #00,#00,#00,#00,#00,#00,#00,#00

.pac_sprite_palette

Sprite ink 1

dw #0CDF  ; Red = #D Green = #C Blue = #F ; The gray body

Sprite ink 2

dw #0000  ; Red = #0 Green = #0 Blue = #0 ; The black in the PAC's eyes

Sprite ink 3

dw #0FFF  ; Red = #F Green = #F Blue = #F ; The white in the PAC's eyes </geshi>

See also