Skip to content

Sprites

Marco Maccaferri edited this page Mar 31, 2018 · 7 revisions

Sprites uses 4 bytes from the sprites data area to define x and y position, the tile index and flags.

Sprite bytes

X and Y

The x and y coordinate values are 9 bits wide to allow sprites to be placed in every positions on the screen. The first two bytes defines the lowest 8 bits of the x and y position, bits 0 and 1 of the flags byte defines the 9th bit. 9 bits allows a range of 0 to 511 however the value is partially signed to allow sprites to be placed outside the left and top borders. The x values are thus ranging from -32 to 320 (hex values 1E0 to 140) and y values are ranging from -32 to 240 (hex values 1E0 to 0F0).

Examples:

+------------------------------------------------------------------------------------+
|       X        |       Y        |     Flags      |                                 |
|----------------+----------------+----------------+---------------------------------|
| 00000000 (00H) | 00000000 (00H) | 00000000 (00H) | Top-left corner                 |
|----------------+----------------+----------------+---------------------------------|
| 11111100 (FCH) | 01111000 (78H) | 00000001 (01H) | Half out of the left side       |
|----------------+----------------+----------------+---------------------------------|
| 00111100 (3CH) | 01111000 (78H) | 00000001 (01H) | Half out of the right side side |
|----------------+----------------+----------------+---------------------------------|
| 10100000 (A0H) | 11111100 (FCH) | 00000010 (02H) | Half out of the top side        |
|----------------+----------------+----------------+---------------------------------|
| 10100000 (A0H) | 11101100 (ECH) | 00000000 (00H) | Half out of the bottom side     |
+------------------------------------------------------------------------------------+

The following code can be used to convert plain coordinates into sprite-data values:

            LD      A,(XPOS)        ; X
            OUT     (PORTD),A
            LD      A,(YPOS)        ; Y
            OUT     (PORTD),A
            LD      A,00H           ; Tile
            OUT     (PORTD),A
            LD      A,(YPOS+1)      ; Y 9th bit
            AND     01H
            SLA     A
            LD      C,A
            LD      A,(XPOS+1)      ; X 9th bit
            AND     01H
            OR      C
            OR      00H             ; Sprite size
            OUT     (PORTD),A

XPOS        .DW     0               ; -32 to 320
YPOS        .DW     0               ; -32 to 240

Flags

Bit 7-6 defines the sprite width in number of tiles, where 00=1, 01=2, 10=3 and 11=4 tiles.

Bit 5-4 defines the sprite height in number of tiles, where 00=1, 01=2, 10=3 and 11=4 tiles.

Examples:

+---------------------------------+
|  Flags   | X | Y |              |
|----------+---+---+--------------|
| 00000000 | 1 | 1 | 8x8 pixels   |
| 01000000 | 2 | 1 | 16x8 pixels  |
| 00010000 | 1 | 2 | 8x16 pixels  |
| 01010000 | 2 | 2 | 16x16 pixels |
| 11110000 | 4 | 4 | 32x32 pixels |
+---------------------------------+

Bit 3 indicates, if set to 1, that the sprite is displayed flipped vertically (the top pixels are displayed at bottom).

Bit 2 indicates, if set to 1, that the sprite is displayed horizontally mirrored (left pixels column is displayed right).

Bit 1 is the 9th bit of the y coordinate.

Bit 0 is the 9th bit of the x coordinate.

Examples:

+------------------------------------------------------------------------+
|  Flags   | X | Y |                                                     |
|----------+---+---+-----------------------------------------------------|
| 01100000 | 2 | 3 | ![Jean Normal](jean_normal.png)                     |
| 01101000 | 2 | 3 | ![Jean Vertical Flip](jean_flip_vertical.png)       |
| 01100100 | 2 | 3 | ![Jean Horizontal Mirror](jean_flip_horizontal.png) |
+------------------------------------------------------------------------+
Clone this wiki locally