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 |                                 |
|-----+-----+-------+---------------------------------|
| 00H | 00H |  00H  | Top-left corner                 |
|-----+-----+-------+---------------------------------|
| FCH | 78H |  01H  | Half out of the left side       |
|-----+-----+-------+---------------------------------|
| 3CH | 78H |  01H  | Half out of the right side side |
|-----+-----+-------+---------------------------------|
| A0H | FCH |  02H  | Half out of the top side        |
|-----+-----+-------+---------------------------------|
| A0H | ECH |  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:

  • 60H = 01100000 = 2x3 tiles, normal display
    Jean Normal

  • 64H = 01100100 = 2x3 tiles, horizontal mirror
    Jean Horizontal Mirror

  • 68H = 01101000 = 2x3 tiles, vertical flip
    Jean Vertical Flip

Tile display mapping

When a sprite requires more than one tile to display, each tile is read sequentially from top to bottom and left to right starting from the index specified with the sprite data.

Examples:

3x2 tiles (24x16 pixels):

sprites-map-horizontal

2x3 tiles (16x24 pixels):

sprites-map-vertical

Clone this wiki locally