Sprite mapping format thoughts
Published on 2024-oct-13
mdtiler
can generate sprite mappings (manually) using the
sprite
instruction, which both reads tiles and generates a
sprite mapping entry in one go. The format used by mdtiler
looks like this:
- 2 bytes: X coordinate
- 2 bytes: Y coordinate
- 2 bytes: Tile ID and flags
- 2 bytes: Sprite size
And the list is ended with $8000
.
But in hindsight, it's kinda wasteful: the upper 12 bits of the sprite
size are never used (always 0). Even if you want to cram in flags in the
unused space of the sprite table, the upper 8 bits are never used at
all. Also, to check the end of the list, you need to check if X =
$8000
, which wastes cycles.
Probably a better idea would have been to do this:
- 2 bytes: Sprite size
- 2 bytes: X coordinate
- 2 bytes: Y coordinate
- 2 bytes: Tile ID and flags
And again the list ends with $8000
(or larger). Then the
"end of list" condition comes for free when reading the sprite
size since the sign flag will be set, avoiding wasting cycles on a
cmp
instruction.
Maybe one day I'll update mdtiler
to support the new
format, or even custom formats (where you specify the order of each entry).