The Compress compression/decompression module

This module provides general compression/decompression facilities of a
lossless nature through an SWI interface. The intended algorithm is LZW,
however, no guarantee is made that this will be so in the future. It provides
all combinations of input and output as either store or file, with input
checking (where relevant) and output bound checking (again where relevant),
plus a high performance, unchecked store to store version for those who
require it and are prepared to suffer the consequences of providing faulty
input or insufficient output space.

Some of these interfaces are restartable. The restartability is available for
exhaustion of the compressed form, ie insufficient output space for
compression or insufficient input for decompression. Where restartability is
available, the input and output pointers must be updated before recalling.
Also the output size must be the total available for the entire operation,
including that already used. For second or subsequent calls to compress, the
input size is ignored, the value being acquired from within the workspace.
For second or subsequent calls to decompress, the input must contain, and the
size reflect, any input not used by the preceding call.

Errors will be generated for insufficient workspace (assuming r1 not zero),
for buffer overflow on output and inconsistent state within the workspace.

Store to store compression, with checking. Restartable.
Workspace requirement 31k
SWI: Compress_CompressStoreStore
Input:-  r0 Workspace
         r1 Workspace size
         r2 Input address
         r3 Input size
         r4 Output address
         r5 Output size available
         r6 0 => start from scratch
            1 => continue from data held within workspace
Output:- r0 = 0 => compression complete
         r0 = 1 => compression incomplete
         r1 Workspace required for this call if input r1 = 0
         r3 Input size used
         r5 Output size used

Store to store decompression, with checking. Restartable.
Workspace requirement 17k
SWI: Compress_DecompressStoreStore
Input:-  r0 Workspace
         r1 Workspace size
         r2 Input address
         r3 Input size
         r4 Output address
         r5 Output size available
         r6 0 => Start from scratch, terminate when run out of input
            1 => Start from scratch, request more when run out of input
            2 => Continue from data within workspace, terminate when run out
                 of input
            3 => Continue from data within workspace, request more when run
                 out of input
Output:- r0 = 0 => decompression complete
         r0 = 1 => decompression incomplete
         r1 Workspace required for this call if input r1 = 0
         r3 Input remaining (if input r6 = 1 or 3)
         r5 Output size used

Store to file compression, with checking
Workspace requirement 31k
SWI: Compress_CompressStoreFile
Input:-  r0 Workspace
         r1 Workspace size
         r2 Input address
         r3 Input size
         r4 Output file handle
         r6 Must be zero
Output:- r1 Workspace required for this call if input r1 = 0

Store to file decompression, with checking. Restartable.
Workspace requirement 17k
SWI: Compress_DecompressStoreFile
Input:-  r0 Workspace
         r1 Workspace size
         r2 Input address
         r3 Input size
         r4 Output file handle
         r5 Unused
         r6 0 => Start from scratch, terminate when run out of input
            1 => Start from scratch, request more when run out of input
            2 => Continue from data within workspace, terminate when run out
                 of input
            3 => Continue from data within workspace, request more when run
                 out of input
Output:- r0 = 0 => decompression complete
         r0 = 1 => decompression incomplete
         r1 Workspace required for this call if input r1 = 0
         r3 Input remaining (if input r6 = 1 or 3)

File to store compression, with checking. Restartable.
Workspace requirement 31k
SWI: Compress_CompressFileStore
Input:-  r0 Workspace
         r1 Workspace size
         r2 Input file handle
         r3 Unused
         r4 Output address
         r5 Output size available
         r6 0 => start from scratch
            1 => continue from data held within workspace
Output:- r0 = 0 => compression complete
         r0 = 1 => compression incomplete
         r1 Workspace required for this call if input r1 = 0
         r5 Output size used

File to store decompression, with checking
Workspace requirement 17k
SWI: Compress_DecompressFileStore
Input:-  r0 Workspace
         r1 Workspace size
         r2 Input file handle
         r3 Unused
         r4 Output address
         r5 Output size available
         r6 Must be zero
Output:- r1 Workspace required for this call if input r1 = 0
         r5 Output size used

File to file compression, with checking
Workspace requirement 31k
SWI: Compress_CompressFileFile
Input:-  r0 Workspace
         r1 Workspace size
         r2 Input file handle
         r3 Unused
         r4 Output file handle
         r6 Must be zero
Output:- r1 Workspace required for this call if input r1 = 0

File to file decompression, with checking
Workspace requirement 17k
SWI: Compress_DecompressFileFile
Input:-  r0 Workspace
         r1 Workspace size
         r2 Input file handle
         r3 Unused
         r4 Output file handle
         r6 Must be zero
Output:- r1 Workspace required for this call if input r1 = 0

Store to store compression, without checking
Workspace requirement 21k
SWI: Compress_CompressStoreStoreFast
Input:-  r0 Workspace
         r1 Workspace size
         r2 Input address
         r3 Input size
         r4 Output address
         r5 Output size available
         r6 Must be zero
Output:- r1 Workspace required for this call if input r1 = 0
         r5 Output size used

Store to store decompression, without checking
Workspace requirement 16k
SWI: Compress_DecompressStoreStoreFast
Input:-  r0 Workspace
         r1 Workspace size
         r2 Input address
         r3 Input size
         r4 Output address
         r5 Output size available
         r6 Must be zero
Output:- r1 Workspace required for this call if input r1 = 0
         r5 Output size used

All compression/decompression will use a maximum of 12 bit codes. The output
is compatible with the output of unix compress using 12 bits
(compress -b 12 ...). The maximum output size for compressed data is
12 + 3*input size/2 in the worst case. The workspace requirements are 21k for
compression and 16k for decompression for the unchecked methods, 31k for
checked compression, and 17k for checked decompression.

The expected performance for an 8Mhz A420 with ARM2 is as follows:-

Store to store slow
Compression    24 kbytes per second 
Decompression  48 kbytes per second

Store to store fast
Compression    68 kbytes per second 
Decompression 280 kbytes per second

The expected module size is between 20k and 30k.
