SMA

From MultimediaWiki
Jump to navigation Jump to search

This is an animation format used in the game. It employs RLE on paletted data.

File header:

 8 bits - always 0x10
 16 bits - version (always 1)
 16 bits - width
 16 bits - height
 8 bits - unknown
 32 bits - number of frames

The header is followed by frame table consisting of two 32-bit words: the first one is usually zero and the second one tells frame data size.

Frame data starts with 8-bit mode. Modes 3 and 32 are apparently used for skip frames, mode 4 is special 16-colour mode, for the other modes it is RLE-coded lines.

Conventional modes start with 16-bit right and bottom corner position (e.g. 639,479 for 640x480 animation) and segments starting with 16-bit values for the number of lines to skip and to decode. Each line starts with a byte telling its coding mode:

  • 0 - raw data
  • 1 - RLE (negative value - copy, positive value - run, zero - EOL)
  • 2 - sparse update (negative value - copy, positive value - skip, zero - EOL)
  • 3 - sparse RLE (negative value - copy, positive value - run, 0x00 0xFF - EOL, 0x00 .. - skip)
  • 4 - skip line
  • 7 - same as 2 but with 16-bit value in the beginning
  • 8 - same as 3 but with 16-bit value in the beginning

Mode 4 data starts with frame and tile dimensions coded using 16-bit variables. Each block starts with a byte telling its coding mode:

  • 0 - skip
  • 1 - raw
  • 2 - 16-colour RLE
  • 3 - skip64
  • 4 - skip16
  • 8 - skip8

RLE data starts with possible 16-colour cache update (one byte size telling the number of colours, 0xFF - don't update, followed by colour values) and nibble pair corresponding to the number of colours to copy and run correspondingly (run colour index is read before copy values). Colour values are read as nibbles corresponding to the indices in the cache.

SkipN reads N-colour cache (0xFF still tells not to update it) and uses log2(N) bits to code indices in the cache, while top bits denote the run length (0 means read skip length byte instead).