Spectrum 512 Extended file format

From Atari Wiki
Jump to navigation Jump to search
Spectrum 512 Extended    *.SPX

SPX files are extended Spectrum files with more than 200 lines in the picture, 
designed by Gizmo of Electronic Images. With a SPX creator like SPXCRT14.PRG 
multiple spectrum pictures can be attached to become one big .SPX file. There 
are two known versions of the format. Version 2 files of the format can be 
packed as a whole (including the header) with either Ice 2.10 or Atomik 3.5.

3  bytes        'SPX', SPX magic header
1  byte         version (01 or 02)
1  byte         graphics compression flag, 0 = unpacked
1  byte         palette compression flag, 0 = unpacked
1  byte         number of 32000 byte screens
3  bytes        reserved
?? bytes        NULL terminated author string
?? bytes        NULL terminated description string
4  bytes        size of (packed) graphics data in bytes
4  bytes        size of (packed) palette data in bytes
?? bytes        (packed) graphics data
?? bytes        (packed) palette data

The number of lines in the picture can be calculated by deviding the size of 
the unpacked graphics data by 160. The unpacked SPX picture can be treated as a 
Spectrum screen with more than 200 lines.

In version 1 when a compression flag is set the data is packed with Ice 2.10.

In version 2 a special packer is used, graphics and palettes are packed in one chunk.
4 bytes         depacked size
4 bytes         packed size
Like the Ice packer data is packed from end of file to start. The depakcer starts
to read data from packed data start+packed size and to write data to 
depacked data start+depacked size. A long is read form packed data into a bitbuffer, 
when the bitbuffer is empty it is refilled with a new long from the packed file. 
With getbits(n) the n most significat bytes are read from the bitbuffer.
while(bytes read<depacked size)
    0 : literals
        len = getbits(4*(getbits(2)+1))
        read len bytes with getbits(8) and write them to the destination
        if(len<>$ffff) do a ptr_len
    1 : ptr_len
        ptr = getbits(4*(getbits(2)+1))
        len = getbits(4*(getbits(2)+1))
        copy len+3 bytes from ptr
Note: after a literal there is always a ptr_len except when len was $ffff.

See also Spectrum 512 file format

Back to ST Picture Formats