/usr/share/doc/allegro4-doc/html/packfile.html is in allegro4-doc 2:4.4.2-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><title>
Packfile format
</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="stylesheet" title="Default" type="text/css" href="allegro.css"></head><body bgcolor=white text=black link="#0000ee" alink="#ff0000" vlink="#551a8b">
<center><h1><b>
Packfile format information.
</b></h1></center>
<hr>
<p><br>
<h1><a name="Contents">Contents</a></h1>
<p>
<ul>
<li><a href="#Introduction and scope">Introduction and scope</a>
<li><a href="#Packfile signature">Packfile signature</a>
<li><a href="#Format and decompression algorithm">Format and decompression algorithm</a>
<li><a href="#Summary">Summary</a>
</ul>
<p><br>
<h1><a name="Introduction and scope">Introduction and scope</a></h1>
<p>
This document describes the format of Allegro's packfiles from a
decompression point of view. It does not describe how to do the
compression (read the source, or ask Google about LZSS).
<p>
file.c says "This compression algorithm is based on the ideas of Lempel
and Ziv, with the modifications suggested by Storer and Szymanski.", if
that means anything to you.
<p><br>
<h1><a name="Packfile signature">Packfile signature</a></h1>
<p>
All compressed packfiles begin with a four byte signature "slh!" (ASCII),
which in hexadecimal is 0x73, 0x6C, 0x68, 0x21 (in that order).
<p>
Another form of packfiles are uncompressed packfiles, which begin with the
four byte signature "slh." (ASCII), in hexadecimal 0x73, 0x6C, 0x68, 0x2B.
The rest of the file is then completely raw. Uncompressed packfiles will
not be discussed further.
<p><br>
<h1><a name="Format and decompression algorithm">Format and decompression algorithm</a></h1>
<p>
Decompression requires a ring buffer of 4096 bytes and a ring index (which
indexes into the ring buffer). The ring index starts at 4078, assuming
0-based indices. New bytes may be stored into in the position in the ring
buffer that the index points to. When a byte is stored, the index is
incremented by one, wrapping around to zero as necessary.
<p>
Packfiles must be decompressed sequentially. The first byte following the
signature in the packfile is the "flags" byte, which determines how the
following "tokens" in the file are to be interpreted.
<p>
Bit 1 (the least significant bit) corresponds to the first token following
the flags byte. Bit 2 corresponds to the second token, etc. After every
eight tokens, there is another flag byte and another eight tokens, and so
on, until the end of file.
<p>
If the bit I of the flags byte is set, then token I is a single byte to be
sent to the output. In addition, it must put onto the ring buffer and the
ring index incremented.
<p>
Otherwise, if bit I of the flags byte is not set, then token I is a two
byte sequence containing an index and a length. The index is the first
byte OR'd together with the higher 4 bits of the second byte as the higher
order bits, thus making a 12-bit unsigned number (0-4095). The length is
the lower 4 bits of the second byte, plus 3.
In less hand-wavy C syntax:
<blockquote class="code"><pre>
index = byte1 | ((byte2 & 0xF0) << 4);
length = (byte2 & 0x0F) + 3;
</pre></blockquote>
Then, "length" number of bytes from the ring buffer, starting at "index",
are to be sent to the output. In addition, all these bytes must be put
onto the ring buffer, and the ring buffer incremented accordingly.
<p>
Decompression ends at the end of the file. There is no end-of-file
marker. If the number of tokens is not a multiple of eight, the unused
bits in the latest flags byte are always zero.
<p><br>
<h1><a name="Summary">Summary</a></h1>
<p>
In brief, compressed packfiles take the form:
<blockquote class="text"><pre>
signature -- 4 bytes
flags -- 1 byte
token 1 -- each token 1 or 2 bytes
token 2
...
token 8
flags
...
(repeat flags and tokens 1-8 until EOF)
</pre></blockquote>
</body>
</html>
|