FilePack

Description

FilePack is simply a tool that can compress any kind of data. It typically perform a 50% compression ratio on code and graphics.

Utilisation

FilePack can compress files, but also restore files that have been compressed.

To compress a file:

	%OSDK%\bin\FilePack -p source_file compressed_file 

To decompress a file:

	%OSDK%\bin\FilePack -u compressed_file destination file 
Switches
  • The -u switch is used to decompress a file: Note that only files packed with a header (-p1 or -p2) can be unpacked (and you need to pass the correct -m0/-m1 values matching the one used when compressing the data)

    -p0 => No header
    -p1 => Save with short header [default]
    -p2 => Save with long header
    See below for the explanation regarding how this switch changes the format.

  • The -p switch defines the packing mode:

    -p0 => No header
    -p1 => Save with short header [default]
    -p2 => Save with long header
    See below for the explanation regarding how this switch changes the format.

  • The -m switch selects the meaning of the bits in the encoding mask
    -m0 => 0=copy bytes / 1=new byte [default]
    -m1 => 0=new byte   / 1=copy bytes
    This is just to allow code optimization, some platforms are more comfortable branching on true, some prefer to branch on false. Just make sure the code handles that when depacking.
Packed file format

The format of packed files is actually very simple, and is mostly based on a 8 bytes header followed by compressed data.

	+0	'L'
	+1	'Z'
	+2	'7'
	+3	'7'
	+4	Unpacked size (low byte)
	+5	Unpacked size (high byte)
	+6	Packed size (low byte) 
	+7	Packed size (high byte)
	+8	Compressed data starts here

Please note that this header is present only when packed in default mode (-p1), if you pack in -p0 mode the header is not present. In place of the header you will find a text file having the same name that your "program.s", looking like this:

	#define run_adress $600 	; Come from original TAP executable
	#define unpacked_size $1000	; Come from original TAP executable
Depacking

For depacking a file, you can simply use the corresponding library routine:

	void file_unpack(void *ptr_dst,void *ptr_src);

Please note that this routine expect the data to get a header, so it will not work for files packed in -p0 mode. To unpack these files you need to use another routine.

You can also look at the following source code for help:
  • lz_pack.cpp (FilePack actual packing/depacking routine)
  • depack.s (68000 assembler Atari ST routine used in the "Save The Earth" demo)
  • unpack.s (6502 assembler routine used in the OSDK)
Important: The 'size' parameter used by the depacking routine is the final size of the decompressed data, not the compressed size.


Known issues


No known problem - please signal any issue on the Cross development tools forum.

comments powered by Disqus
Coverity Scan Build Status
History
Version 0.5
  • Added the -mn and -p2 options
Version 0.4
  • Added p0/p1 mode to pack a file without appending the header.
    Very usefull when you want to spare a maximum of bytes in a size compo.
Version 0.1-0.3
  • First released versions.