<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://moddingwiki.shikadi.net/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=CarlKenner</id>
	<title>ModdingWiki - User contributions [en-gb]</title>
	<link rel="self" type="application/atom+xml" href="https://moddingwiki.shikadi.net/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=CarlKenner"/>
	<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/wiki/Special:Contributions/CarlKenner"/>
	<updated>2026-05-14T04:21:38Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.11</generator>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=GameMaps_Format&amp;diff=3600</id>
		<title>GameMaps Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=GameMaps_Format&amp;diff=3600"/>
		<updated>2011-09-02T10:16:36Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* Location of internal files */ Catacomb Apocalypse and Armageddon&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The GameMaps format is how the levels in a number of [[Id Software]] games is stored. The filenames and compression varies somewhat across different games but all files stored in this format were produced by the program [[TED5]] or a close analogue.&lt;br /&gt;
&lt;br /&gt;
There are three main varieties of the GameMaps format, uncompressed, [[Carmack compression||carmackized]], and  [[Huffman Compression|huffman compressed]]. Each variation has its own file naming scheme  and pattern of external\internal files.&lt;br /&gt;
&lt;br /&gt;
There are two main components to the format, the game maps proper, which contain the game level data and the map headers, which contain both the locations of the start of level data in the game maps file and the tile info for the game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Structure of uncompressed data ==&lt;br /&gt;
&lt;br /&gt;
The uncompressed format is used by several games including [[Bio Menace]] and [[Wolfenstein 3D]]. In this format map data is stored in &amp;lt;tt&amp;gt;MAPTEMP.xxx&amp;lt;tt&amp;gt; and map headers in &amp;lt;tt&amp;gt;MAPTHEAD.xxx&amp;lt;/tt&amp;gt; this is the format saved by [[TED5]] when maps are being edited and can be directly accessed and edited by this utility, allowing changes to be made to the game.&lt;br /&gt;
&lt;br /&gt;
Note that filenames differ and that Wolfenstein 3D uses &amp;lt;tt&amp;gt;GAMEMAPS.WLx&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;MAPHEAD.xxx&amp;lt;/tt&amp;gt; files to store data. The main indicator of this format being used is that in the unaltered game the map header file is external.&lt;br /&gt;
&lt;br /&gt;
Only the latest Id Software games lacked compression, when file size was no longer an issue.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Map headers ===&lt;br /&gt;
&lt;br /&gt;
 0    2    Magic word       Magic word for [[RLEW compression]]&lt;br /&gt;
 2    400  Level ptr        100 4-byte pointers to start of level 0-99 data in game maps file&lt;br /&gt;
 402  ???  Tileinfo         Tileinfo data&lt;br /&gt;
&lt;br /&gt;
The map header file is of varying length and contains three main types of data. The first is the magic word or flag used for RLEW compression, it is always $ABCD. The second is 100 level pointers which give the location of the start of level data in the game maps file, relative to the start of that file. A value of 0 indicates no level. The third is the tileinfo data, tile properties for each tile used in level creation. (These are masked and unmasked and either 8x8, 16x16 or 32x32)&lt;br /&gt;
&lt;br /&gt;
Many programs treat the tileinfo as a separate file from the maphead and it is possible to modify a game in this manner. Indeed, some games, such as Wolfenstein 3D do not have any tileinfo data at all in the map header file (Giving a total file length of 402 bytes.) However TED5 works with any tileinfo data in the maphead.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game maps ===&lt;br /&gt;
&lt;br /&gt;
The game maps file consists of the string &#039;TED5v1.0.&#039; and a number of RLEW compressed chunks of varying length. Each level in GameMaps will have from two to four chunks (usually four), depending on game, with all levels in a given game having the same number of chunks. These are the level header and 1-3 planes (Foreground, background and sprite or info.) The chunks are in no particular order and it is possible to read through the entire file decompressing chunks as they&#039;re found.&lt;br /&gt;
&lt;br /&gt;
Chunks are ordered by the map header file, which will point to the level header chunks which in turn contain pointers to the other chunks used by that level. It is possible the string at the start of the file is to avoid the possibility of a level header at the start of the file which would be read as not existing.&lt;br /&gt;
&lt;br /&gt;
All data in game maps file is in the form of words (Or in the case of pointers, dwords.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Level headers ===&lt;br /&gt;
&lt;br /&gt;
The header for each level that is pointed to by MAPHEAD is 42 bytes long and RLEW compressed, though this is difficult to see since the data is so short and nonrepetitive. For the offsets to level planes a value of 0 indicates the plane does not exist.&lt;br /&gt;
&lt;br /&gt;
Plane 1 is background using unmasked tiles, plane 2 is foreground and uses masked tiles. Plane 3 is sprite or info. Levels must contain c background plane and usually an infoplane.&lt;br /&gt;
&lt;br /&gt;
 0   4    Offset in GAMEMAPS to beginning of compressed plane 0 data&lt;br /&gt;
 4   4    Offset in GAMEMAPS to beginning of compressed plane 1 data&lt;br /&gt;
 8   4    Offset in GAMEMAPS to beginning of compressed plane 2 data&lt;br /&gt;
 12  2    Length of compressed plane 0 data (in bytes)&lt;br /&gt;
 14  2    Length of compressed plane 1 data (in bytes)&lt;br /&gt;
 16  2    Length of compressed plane 2 data (in bytes)&lt;br /&gt;
 18  2    Width of level (in tiles)&lt;br /&gt;
 20  2    Height of level (in tiles)&lt;br /&gt;
 22  16   Internal name for level (used only by editor, not displayed in-game. null-terminated)&lt;br /&gt;
&lt;br /&gt;
== Carmack compression ==&lt;br /&gt;
&lt;br /&gt;
[[Carmack compression]] is the method used to compress later Id Software games, when file size was an issue. It is the most efficient and complex compression method and was created specifically to work with the word structure of the game maps file. The compression is detailed on its [[Carmack compression|own page.]]&lt;br /&gt;
&lt;br /&gt;
Carmackized game maps files are external &amp;lt;tt&amp;gt;GAMEMAPS.xxx&amp;lt;/tt&amp;gt; files and the map header is stored internally in the executable. The map header must be extracted and the game maps decompressed before TED5 can access them. TED5 itself can produce carmackized files and external &amp;lt;tt&amp;gt;MAPHEAD.xxx&amp;lt;/tt&amp;gt; files. Carmackization does not replace the RLEW compression used in uncompressed data, but compresses this data, that is, the data is doubly compressed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Huffman compression ==&lt;br /&gt;
&lt;br /&gt;
Huffman compression was used by earlier versions of TED5 (possibly not TED5 at all.) before carmackization was created. It uses the same method to compress its data as is used by Id Software games to compress their graphics and sounds. Again this compression method works with RLEW compressed data and has its [[Huffman Compression|own page.]]&lt;br /&gt;
&lt;br /&gt;
Huffman compression is easily detected since it works on the bit level and thus disrupts the word structure of the game data. This is easily seen in a hex editor. Compressed data will not contain the string $00 $00 or indeed even $00 very often (In contrast even carmackized data contains both strings hundreds of times.)&lt;br /&gt;
&lt;br /&gt;
There will be two internal files for this format, the map header and the huffman dictionary (which is always the first dictionary in the executable.) The map header format is also slightly different, being 502 bytes long, the extra 100 bytes being the length of the compressed level headers in the game maps data (These can be ignored when decompressing since huffman data can be read until the decompressed level header&#039;s fixed size is reached.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Location of internal files ==&lt;br /&gt;
&lt;br /&gt;
Game maps are always external, but in the case of compression the map header file is stored internally in the executable. Executables are themselves compressed wither with LZEXE or PKLite. Once decompressed it is a trivial task to find the map header file as it will start with the word $ABCD For level editing purposes only the first 402 (or 502) bytes of the file needs to be extracted, though it is possible to read the maphead file to calculate its length.&lt;br /&gt;
&lt;br /&gt;
The following addresses are in the locations in the decompressed executables for the start of the Map header files. Values are different for different versions.&lt;br /&gt;
&lt;br /&gt;
TODO: Add all known versions of all games.&lt;br /&gt;
&lt;br /&gt;
External files&lt;br /&gt;
 Biomenace&lt;br /&gt;
 Blake Stone 2: Planet Strike&lt;br /&gt;
 Corridor 7 Demo&lt;br /&gt;
 Noahs Ark 3D&lt;br /&gt;
 Operation Body Count&lt;br /&gt;
 Spear of Destiny&lt;br /&gt;
 Wolfenstein 3D&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Internal files:&lt;br /&gt;
  Catacomb 3-D (1.00): $1C570 from start of file CAT3D.EXE (after file is UNLZEXE)&lt;br /&gt;
  Catacomb 4 Abyss (1.13): $1C510 from start of file CATABYSS.EXE (after file is UNLZEXE)&lt;br /&gt;
  Catacomb 5 Armageddon (1.01a): $1D900 from start of file CATARMA.EXE (after file is UNLZEXE)&lt;br /&gt;
  Catacomb 6 Apocalypse (1.00b): $1DD50 from start of file CATAPOC.EXE (after file is UNLZEXE)&lt;br /&gt;
  Corridor 7 CD (): $30D50 from start of file CORR7CD.EXE (file is not compressed)&lt;br /&gt;
  Corridor 7 Floppy (): $24BF0 from start of file C7.EXE (file is not compressed)&lt;br /&gt;
  Keen 4 (Special Demo): (file is PKLite compressed)&lt;br /&gt;
  Keen 4 (1.4): $24830&lt;br /&gt;
  Keen 5 (1.4): $25990&lt;br /&gt;
  Keen 6 (1.4): $25080&lt;br /&gt;
 (Keen D (1.13): $1FA50)&lt;br /&gt;
&lt;br /&gt;
== Utilities ==&lt;br /&gt;
&lt;br /&gt;
[[TED5]] This program can edit the &amp;lt;tt&amp;gt;GAMEMAPS&amp;lt;/tt&amp;gt; format of any games that use it. It is the original editor used to crate these files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
This format was reverse engineered by Andrew Durdin (adurdin).&lt;br /&gt;
&lt;br /&gt;
The format is used by other games as well, including [[Bio Menace]], [[Blake Stone]], [[Catacomb 3D]], [[Catacomb Abyss]], [[Corridor 7]], [[Dangerous Dave 3]], [[Dave Goes Nutz]], [[Noah&#039;s Ark 3D]], [[Operation Body Count]], [[Spear of Destiny]], and [[Wolfenstein 3D]].&lt;br /&gt;
&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Map Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3599</id>
		<title>EGAGraph Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3599"/>
		<updated>2011-09-02T04:35:44Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* EGA Head (EGAHEAD.xxx) */ Catacomb Apocalypse&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;EGAGraph&#039;&#039;&#039;, short for &#039;EGA graphics library&#039; is the format used to store graphics, demos, fonts, game texts and more in many early [[:Category:Id Software|id Software]] games.&lt;br /&gt;
&lt;br /&gt;
The basic format is that of a number of [[Huffman Compression]] compressed sub-files (Chunks) stored in a similar manner to the [[AudioT Format]]. Like this format it has three main files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt;and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is notable that while the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; are stored in the game executable, they need to be extracted for [[TED5]] to edit levels.&lt;br /&gt;
&lt;br /&gt;
This article may contain errors as some formats have not been worked out completely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= File formats =&lt;br /&gt;
&lt;br /&gt;
== EGA Head (EGAHEAD.xxx) ==&lt;br /&gt;
There are two versions of this format. The first version, used in [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], is an array of 4-byte little-endian values. The second version, used in all later EGA games, is an array of 3-byte unsigned little-endian values.&lt;br /&gt;
&lt;br /&gt;
This header file may be present as an external file (eg. [[Bio Menace]]), or it may be included in the EXE file (eg. [[Catacomb 3D]]). The last entry in the header is always the size of the EGAGRAPH.xxx file, and the first entry in the header is always 00 00 00. To find the end, you can search for filesize(EGAGRAPH.xxx) as a 3-byte (little-endian) value in the EXE. Then to find the start, go back 3 bytes at a time until you get to 00 000 00. Or use the fact that entries always get smaller as you go back, unless the entry is $FFFFFF. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] v1.00 &amp;lt;tt&amp;gt;EGAHEAD.C3D&amp;lt;/tt&amp;gt; is at $1BFD0 from the start of the decompressed ([[unlzexe]]) EXE file, and is 1437 bytes long, or 479 3-byte entries (for 478 chunks). It is then followed by 3 zero bytes (padding to multiple of 16?) 00 00 00, then the &amp;lt;tt&amp;gt;MAPHEAD.C3D&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb Abyss]] v1.13 &amp;lt;tt&amp;gt;EGAHEAD.ABS&amp;lt;/tt&amp;gt; is at $1BDB0 from the start of the decompressed ([[unlzexe]]) EXE file, and 1881 bytes long and has 626 chunks.&lt;br /&gt;
&lt;br /&gt;
In [[Catacomb Apocalypse]] v1.00b &amp;lt;tt&amp;gt;EGAHEAD.APC&amp;lt;/tt&amp;gt; is at $1E270 from the start of the decompressed ([[unlzexe]]) EXE file, and 2049 bytes long and has 682 chunks.&lt;br /&gt;
&lt;br /&gt;
This header file stores the offsets (relative to the start of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file) for each sub file.  The format is trivial, in that the header file is simply an array of 3 or 4 byte variables.  (Each variable is a &amp;quot;slot&amp;quot;, as the game refers to files by index.) Most games use the more compact 3-byte variables, since the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is never larger than $FFFFFF. However games based on older engines, notably [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], use 4-byte vales as these are easier to deal with.&lt;br /&gt;
&lt;br /&gt;
It is important to note that not every &#039;slot&#039; will be in use. Tiles especially if blank (All black) will be considered &#039;empty&#039; and not worth adding to the file. (A blank 16x16 tile takes up 12 bytes of space if compressed, and there can be hundreds.) There are two ways of dealing with this; by default the games set all empty slot headers to -1, but many programs compress the graphics anyway and use a normal header value for them.&lt;br /&gt;
&lt;br /&gt;
The last offset in the file will be an offset to the end of the main &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file.  (So this should be ignored when reading the file to prevent a zero-byte file appearing last.) The total size of the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; divided by 3 (Or 4) will also give the number of &#039;slots&#039; the game uses. This varies, but is usually about 10,000.&lt;br /&gt;
&lt;br /&gt;
Unlike [[AudioT Format]] files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; is always compressed. However the header and dictionary may be external (E.g [[Bio Menace]])&lt;br /&gt;
&lt;br /&gt;
== Dictionary (EGADICT.xxx) ==&lt;br /&gt;
&lt;br /&gt;
The same [[Huffman Compression]] scheme used elsewhere in the [[Commander Keen]] series is used.  When reading compressed chunks out of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, the first four bytes located at the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; offset are a UINT32LE specifying the file&#039;s decompressed size (which is required for the decompression algorithm.)  The compressed data then follows, EXCEPT for 16x16 masked and unmasked tiles. Since these all have a similar decompressed size (128 bytes for unmasked, 256 bytes for masked) it is a waste of space to include these (Since tiles make up the bulk of graphics slots.) The decompressed size is hard coded, as are the start and finish of the unmasked and masked tile slots.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; file is not often obvious, usually being embedded in the main exe file. It is possible to locate it by looking for the string &amp;lt;tt&amp;gt;$FD $01 $00 $00 $00 $00&amp;lt;/tt&amp;gt;, which appears at the end of nearly all Huffman dictionaries. They are the last 6 bytes out of 1024 (256*2*2), so add 6 and subtract 1024 to get the start (pointer to the head node).&lt;br /&gt;
&lt;br /&gt;
Executables usually contain two or more dictionaries, but the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; is usually &#039;&#039;&#039;the second one&#039;&#039;&#039;, except in the case of early games like Keen Dreams, where it is the first of THREE. (A simple check of whether it decompresses the data sensibly works.)&lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] &amp;lt;tt&amp;gt;EGADICT.C3D&amp;lt;/tt&amp;gt; is at offset $24464 from the start of the decompressed CAT3D.EXE, which is the second Huffman dictionary and comes immediately after the first Huffman Dictionary.&lt;br /&gt;
&lt;br /&gt;
In [[Catacomb Abyss]] v1.13 &amp;lt;tt&amp;gt;EGADICT.ABS&amp;lt;/tt&amp;gt; is at offset $2734C from the start of the decompressed CATABYSS.EXE, which is the second Huffman dictionary.&lt;br /&gt;
&lt;br /&gt;
In [[Catacomb Apocalypse]] v1.00b &amp;lt;tt&amp;gt;EGADICT.APC&amp;lt;/tt&amp;gt; is at offset $26B24 from the start of the decompressed CATAPOC.EXE, which is the second Huffman dictionary.&lt;br /&gt;
&lt;br /&gt;
== Main file (EGAGRAPH.xxx) ==&lt;br /&gt;
&lt;br /&gt;
This file is simply an array of data files.  Each file starts at the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, and as there are no filenames each file is referred to by its index/slot number.  Slots containing dummy values in the header are treated as if they don&#039;t exist in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file. Each file within the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is individually compressed.  A file can be read by opening the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, seeking to the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, reading a UINT32LE for the decompressed file size, and then decompressing the data from that point onwards using standard Huffman decompression techniques.&lt;br /&gt;
&lt;br /&gt;
Note that in early games such as Keen Dreams, the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file may have another name. (Such as &amp;lt;tt&amp;gt;KDREAM.EGA&amp;lt;/tt&amp;gt; in that case.) in which case it is always the largest non-executable file.&lt;br /&gt;
&lt;br /&gt;
=== Chunks ===&lt;br /&gt;
&lt;br /&gt;
Each sub file or chunk is a separate graphic, ordered in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file in a specific way, much again like the [[AudioT Format]].  Chunks are labeled starting at 0. The game executable is hard coded for the start and finish of various chunk types. For example, Keen 4 has chunks 124-520 as sprites and will treat any chunk between these two numbers as a sprite. (Note that the game refers to chunk number, not sprite number.) The usual order of chunks is:&lt;br /&gt;
&lt;br /&gt;
 Picture table&lt;br /&gt;
 Masked picture table&lt;br /&gt;
 Sprite table&lt;br /&gt;
 Fonts&lt;br /&gt;
 Pictures (Unmasked bitmaps)&lt;br /&gt;
 Masked pictures&lt;br /&gt;
 8x8 unmasked tiles (Single chunk)&lt;br /&gt;
 8x8 masked tiles (Single chunk)&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 16x16 masked tiles&lt;br /&gt;
 32x32 unmasked tiles (Optional)&lt;br /&gt;
 32x32 masked tiles (Optional)&lt;br /&gt;
 Misc graphics (Optional)&lt;br /&gt;
 Game texts&lt;br /&gt;
 Demo files (Optional)&lt;br /&gt;
 Misc data (Optional)&lt;br /&gt;
&lt;br /&gt;
== Chunk formats ==&lt;br /&gt;
&lt;br /&gt;
When compressed each chunk consists of a dword giving the decompressed size followed by the compressed data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the first chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying picture chunks.&lt;br /&gt;
&lt;br /&gt;
Divide the decompressed size by 4 to get numpics.&lt;br /&gt;
&lt;br /&gt;
=== Masked picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the second chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying masked picture chunks. This table is often quite small.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprite table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the third chunk, the picture table is 16 * numspr bytes long, consisting of eight words for each sprite image (Width\8, Height, x offset, y offset and clipping rectangle left, top, right and bottom; all in that order.) used when displaying sprite chunks. This is what Modkeen exports as its notoriously hard to use xSPRITES.txt file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fonts ===&lt;br /&gt;
&lt;br /&gt;
Always present and always starting at the fourth chunk. (Chunk 3!) Each chunk is a single monochrome font, containing all the entries from 0-255 for that font. Each &#039;letter&#039; is stored separately and consecutively. A game will have at least one, and usually 3 fonts. The format is version two of [[EGA Font format]]&lt;br /&gt;
&lt;br /&gt;
Fonts are used in the game for game texts. They can be stretched or colored and are always transparent, meaning they look strange when not over a single-color background.&lt;br /&gt;
&lt;br /&gt;
=== Pictures (Bitmaps) ===&lt;br /&gt;
These follow game fonts. You need to know how many fonts there are before it to know how what chunk number the first picture is (3+NumFonts). In [[Catacomb 3D]] there are 2 fonts.&lt;br /&gt;
&lt;br /&gt;
Bitmaps are stored as standard [[Raw EGA data]], the size of each plane being the decompressed chunk size \ 4. In order to be displayed properly these need information from chunk 0, the picture table. Note that unlike fonts, data does not wrap, so a 4x4 sprite will consist of four planes of four bytes in size, the same as an 8x4 sprite.&lt;br /&gt;
&lt;br /&gt;
Pictures are used for things such as title screens or pictures in game texts. Most of the main menu will consist of pictures. They are also used for the wall textures in EGA FPS games like [[Catacomb 3D]], in which case the wall textures come near the end of the picture list (starting from chunk 137 in [[Catacomb 3D]]).&lt;br /&gt;
&lt;br /&gt;
The number of picture chunks is given in chunk 0, the picture table.&lt;br /&gt;
&lt;br /&gt;
=== Masked pictures (Masked bitmaps) ===&lt;br /&gt;
&lt;br /&gt;
These follow Pictures. You need to know how many fonts there are, to know how what chunk number the first Masked picture is (3+NumFonts+numpics).&lt;br /&gt;
&lt;br /&gt;
These are identical to the picture chunks in every respect, except being masked, they consist of five EGA planes, not four. Some games (E.g [[Catacomb 3D]] make great use of masked pictures, but most games have only one or two. They need information from chunk 1, the masked picture table, to be displayed correctly.&lt;br /&gt;
&lt;br /&gt;
The number of Masked pictures is given in Chunk 1.&lt;br /&gt;
&lt;br /&gt;
=== Sprites ===&lt;br /&gt;
&lt;br /&gt;
The first Sprite chunk is at 3+numfonts+numpics+numMaskedPics.&lt;br /&gt;
&lt;br /&gt;
Sprites are exactly identical to masked pictures in format except the game cannot stretch or warp them. Most games use these for enemy, player or item graphics during gameplay. They need information from chunk 2, the sprite table both to display correctly and to interact correctly, something more complex than masked pictures.&lt;br /&gt;
&lt;br /&gt;
There are usually several hundred sprite chunks, but [[Catacomb 3D]] only has 3 sprite chunks and they are used for the PaddleWar game (Skulls and Bones). The number of sprite chunks is given in chunk 2.&lt;br /&gt;
&lt;br /&gt;
=== 8x8 tiles ===&lt;br /&gt;
&lt;br /&gt;
8x8 tiles are used by most games in status windows or foe the borders of message windows in-game. (And occasionally by TED5 to display levels.) There are thus not many of them. ALL the masked or unmasked tiles are one single chunk stored as four and five plane [[Raw EGA data]] respectively. The number of 8x8 unmasked and masked tiles is hard-coded into the executable, but can be worked out by dividing the decompressed chunk size by 32 and 40 (The size of one tile&#039;s data) respectively.&lt;br /&gt;
&lt;br /&gt;
=== 16x16 and 32x32 tiles ===&lt;br /&gt;
&lt;br /&gt;
32x32 tiles are optional and rarely used. 16x16 tiles are only occasionally absent and for most games make up the bulk of graphics. There are usually several thousand entries. Both come in masked and unmasked kinds, just like 8x8 tiles.&lt;br /&gt;
&lt;br /&gt;
These chunks have notable differences. Each tile is an individual chunk and stored as four or five plane [[Raw EGA data]] with a plane size of 128 (16x16) or 512 (32x32). These chunks do NOT have a dword specifying their decompressed size as this is hard-coded into the executable as a space saving measure. (As is the start and finish of unmasked and masked tile chunks.) This can cause problems for editing programs.&lt;br /&gt;
&lt;br /&gt;
Tiles make up the bulk of 2D game levels but are seldom seen elsewhere.&lt;br /&gt;
&lt;br /&gt;
=== Misc graphics ===&lt;br /&gt;
&lt;br /&gt;
Sometimes following tile graphics are miscellaneous graphics, that cannot be handled by the other chunk types. For example, Keen 4-6 has two misc graphics files used for the &#039;COOMANDER KEEN terminator text&#039; intro. These graphics usually have unique formats that fit their function and few have been investigated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Keen 4-6 Intro Bitmaps ====&lt;br /&gt;
&lt;br /&gt;
This is the text that displays after the &#039;Ready, press any key&#039; screen at Keen startup. It is composed of a monochrome bitmap that is scrolled across the screen and distorted for special effects. When displayed it is transparent, with a special palette so it is not black-and-white. It consists of a header followed by RLE compressed monochrome data.&lt;br /&gt;
&lt;br /&gt;
 HEADER:&lt;br /&gt;
 0   2    Img height  Height of the image in pixels&lt;br /&gt;
 2   2    Img width   Width of the image in pixels&lt;br /&gt;
 4   2x   Line point  Pointers to line 1,2,3..etc of data. There will be [Img height] of&lt;br /&gt;
                      these, each 2 bytes long. The first pointer will  have the value&lt;br /&gt;
                      (2 * [Img height] + 4)&lt;br /&gt;
 +2  ?    RLE data    RLE-WM compressed data&lt;br /&gt;
&lt;br /&gt;
 DATA:&lt;br /&gt;
 0   2    Black run   Number of black pixels to write&lt;br /&gt;
 2   2    Not-blk run Number of not-black pixels to write&lt;br /&gt;
 4   2    Black run....&lt;br /&gt;
 ...&lt;br /&gt;
 ..&lt;br /&gt;
 .&lt;br /&gt;
 ?  2     End         $FFFF; end of row.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game texts ===&lt;br /&gt;
&lt;br /&gt;
Also known as ANSII chunks, these are used by the game for things like help screens, and have their own format. In the main they are simply text documents, interspersed with various commands to make things happen. Each file is divided up into a number of &#039;pages&#039; which are moved between by pressing the up/down arrows. Pages can also have action sequences (Repeated each time the page is moved to, you cannot leave a page until the sequence finishes.)&lt;br /&gt;
&lt;br /&gt;
 ^P		First command in every file. Defines a page start&lt;br /&gt;
 ^E		Ends the file&lt;br /&gt;
 ^Cx		Change font color to $x until next page or ^C command&lt;br /&gt;
 ^Gx,y,z	Display (unmasked) picture chunk z at location x,y (In pixels)&lt;br /&gt;
 ^Tx,y,z,t	Display picture chunk z at x,y for z clicks of time&lt;br /&gt;
 ^Bx,y,z,t,b	?&lt;br /&gt;
 ^Lx,y		?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Misc files ===&lt;br /&gt;
&lt;br /&gt;
The last few chunks are demo files and occasionally miscellaneous data. Demo file formats are currently unknown but can be recorded using the demo cheat. They contain the level number and difficulty followed by a series of key commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
* [[KeenWiki:ModKeen|ModKeen]] (DOS) and [[KeenWiki:LModKeen|LModKeen]] (Linux/Windows) can be used to modify graphics and text stored in EGAGRAPH.CKx for the Commander Keen [[KeenWiki:Goodbye Galaxy|Goodbye Galaxy]] trilogy.&lt;br /&gt;
* WDC (Windows) can be used to view or modify the graphics and text stored in EGAGRAPH for [[Catacomb 3D]] and [[Catacomb Abyss]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Catacomb Abyss]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Commander Keen Dreams]]&lt;br /&gt;
[[Category:Dangerous Dave 3]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Graphics Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3598</id>
		<title>EGAGraph Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3598"/>
		<updated>2011-09-02T04:33:33Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* Dictionary (EGADICT.xxx) */ Catacomb Apocalypse&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;EGAGraph&#039;&#039;&#039;, short for &#039;EGA graphics library&#039; is the format used to store graphics, demos, fonts, game texts and more in many early [[:Category:Id Software|id Software]] games.&lt;br /&gt;
&lt;br /&gt;
The basic format is that of a number of [[Huffman Compression]] compressed sub-files (Chunks) stored in a similar manner to the [[AudioT Format]]. Like this format it has three main files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt;and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is notable that while the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; are stored in the game executable, they need to be extracted for [[TED5]] to edit levels.&lt;br /&gt;
&lt;br /&gt;
This article may contain errors as some formats have not been worked out completely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= File formats =&lt;br /&gt;
&lt;br /&gt;
== EGA Head (EGAHEAD.xxx) ==&lt;br /&gt;
There are two versions of this format. The first version, used in [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], is an array of 4-byte little-endian values. The second version, used in all later EGA games, is an array of 3-byte unsigned little-endian values.&lt;br /&gt;
&lt;br /&gt;
This header file may be present as an external file (eg. [[Bio Menace]]), or it may be included in the EXE file (eg. [[Catacomb 3D]]). The last entry in the header is always the size of the EGAGRAPH.xxx file, and the first entry in the header is always 00 00 00. To find the end, you can search for filesize(EGAGRAPH.xxx) as a 3-byte (little-endian) value in the EXE. Then to find the start, go back 3 bytes at a time until you get to 00 000 00. Or use the fact that entries always get smaller as you go back, unless the entry is $FFFFFF. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] v1.00 &amp;lt;tt&amp;gt;EGAHEAD.C3D&amp;lt;/tt&amp;gt; is at $1BFD0 from the start of the decompressed ([[unlzexe]]) EXE file, and is 1437 bytes long, or 479 3-byte entries (for 478 chunks). It is then followed by 3 zero bytes (padding to multiple of 16?) 00 00 00, then the &amp;lt;tt&amp;gt;MAPHEAD.C3D&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb Abyss]] v1.13 &amp;lt;tt&amp;gt;EGAHEAD.ABS&amp;lt;/tt&amp;gt; is at $1BDB0 from the start of the decompressed ([[unlzexe]]) EXE file, and 1881 bytes long and has 626 chunks.&lt;br /&gt;
&lt;br /&gt;
This header file stores the offsets (relative to the start of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file) for each sub file.  The format is trivial, in that the header file is simply an array of 3 or 4 byte variables.  (Each variable is a &amp;quot;slot&amp;quot;, as the game refers to files by index.) Most games use the more compact 3-byte variables, since the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is never larger than $FFFFFF. However games based on older engines, notably [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], use 4-byte vales as these are easier to deal with.&lt;br /&gt;
&lt;br /&gt;
It is important to note that not every &#039;slot&#039; will be in use. Tiles especially if blank (All black) will be considered &#039;empty&#039; and not worth adding to the file. (A blank 16x16 tile takes up 12 bytes of space if compressed, and there can be hundreds.) There are two ways of dealing with this; by default the games set all empty slot headers to -1, but many programs compress the graphics anyway and use a normal header value for them.&lt;br /&gt;
&lt;br /&gt;
The last offset in the file will be an offset to the end of the main &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file.  (So this should be ignored when reading the file to prevent a zero-byte file appearing last.) The total size of the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; divided by 3 (Or 4) will also give the number of &#039;slots&#039; the game uses. This varies, but is usually about 10,000.&lt;br /&gt;
&lt;br /&gt;
Unlike [[AudioT Format]] files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; is always compressed. However the header and dictionary may be external (E.g [[Bio Menace]])&lt;br /&gt;
&lt;br /&gt;
== Dictionary (EGADICT.xxx) ==&lt;br /&gt;
&lt;br /&gt;
The same [[Huffman Compression]] scheme used elsewhere in the [[Commander Keen]] series is used.  When reading compressed chunks out of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, the first four bytes located at the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; offset are a UINT32LE specifying the file&#039;s decompressed size (which is required for the decompression algorithm.)  The compressed data then follows, EXCEPT for 16x16 masked and unmasked tiles. Since these all have a similar decompressed size (128 bytes for unmasked, 256 bytes for masked) it is a waste of space to include these (Since tiles make up the bulk of graphics slots.) The decompressed size is hard coded, as are the start and finish of the unmasked and masked tile slots.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; file is not often obvious, usually being embedded in the main exe file. It is possible to locate it by looking for the string &amp;lt;tt&amp;gt;$FD $01 $00 $00 $00 $00&amp;lt;/tt&amp;gt;, which appears at the end of nearly all Huffman dictionaries. They are the last 6 bytes out of 1024 (256*2*2), so add 6 and subtract 1024 to get the start (pointer to the head node).&lt;br /&gt;
&lt;br /&gt;
Executables usually contain two or more dictionaries, but the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; is usually &#039;&#039;&#039;the second one&#039;&#039;&#039;, except in the case of early games like Keen Dreams, where it is the first of THREE. (A simple check of whether it decompresses the data sensibly works.)&lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] &amp;lt;tt&amp;gt;EGADICT.C3D&amp;lt;/tt&amp;gt; is at offset $24464 from the start of the decompressed CAT3D.EXE, which is the second Huffman dictionary and comes immediately after the first Huffman Dictionary.&lt;br /&gt;
&lt;br /&gt;
In [[Catacomb Abyss]] v1.13 &amp;lt;tt&amp;gt;EGADICT.ABS&amp;lt;/tt&amp;gt; is at offset $2734C from the start of the decompressed CATABYSS.EXE, which is the second Huffman dictionary.&lt;br /&gt;
&lt;br /&gt;
In [[Catacomb Apocalypse]] v1.00b &amp;lt;tt&amp;gt;EGADICT.APC&amp;lt;/tt&amp;gt; is at offset $26B24 from the start of the decompressed CATAPOC.EXE, which is the second Huffman dictionary.&lt;br /&gt;
&lt;br /&gt;
== Main file (EGAGRAPH.xxx) ==&lt;br /&gt;
&lt;br /&gt;
This file is simply an array of data files.  Each file starts at the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, and as there are no filenames each file is referred to by its index/slot number.  Slots containing dummy values in the header are treated as if they don&#039;t exist in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file. Each file within the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is individually compressed.  A file can be read by opening the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, seeking to the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, reading a UINT32LE for the decompressed file size, and then decompressing the data from that point onwards using standard Huffman decompression techniques.&lt;br /&gt;
&lt;br /&gt;
Note that in early games such as Keen Dreams, the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file may have another name. (Such as &amp;lt;tt&amp;gt;KDREAM.EGA&amp;lt;/tt&amp;gt; in that case.) in which case it is always the largest non-executable file.&lt;br /&gt;
&lt;br /&gt;
=== Chunks ===&lt;br /&gt;
&lt;br /&gt;
Each sub file or chunk is a separate graphic, ordered in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file in a specific way, much again like the [[AudioT Format]].  Chunks are labeled starting at 0. The game executable is hard coded for the start and finish of various chunk types. For example, Keen 4 has chunks 124-520 as sprites and will treat any chunk between these two numbers as a sprite. (Note that the game refers to chunk number, not sprite number.) The usual order of chunks is:&lt;br /&gt;
&lt;br /&gt;
 Picture table&lt;br /&gt;
 Masked picture table&lt;br /&gt;
 Sprite table&lt;br /&gt;
 Fonts&lt;br /&gt;
 Pictures (Unmasked bitmaps)&lt;br /&gt;
 Masked pictures&lt;br /&gt;
 8x8 unmasked tiles (Single chunk)&lt;br /&gt;
 8x8 masked tiles (Single chunk)&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 16x16 masked tiles&lt;br /&gt;
 32x32 unmasked tiles (Optional)&lt;br /&gt;
 32x32 masked tiles (Optional)&lt;br /&gt;
 Misc graphics (Optional)&lt;br /&gt;
 Game texts&lt;br /&gt;
 Demo files (Optional)&lt;br /&gt;
 Misc data (Optional)&lt;br /&gt;
&lt;br /&gt;
== Chunk formats ==&lt;br /&gt;
&lt;br /&gt;
When compressed each chunk consists of a dword giving the decompressed size followed by the compressed data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the first chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying picture chunks.&lt;br /&gt;
&lt;br /&gt;
Divide the decompressed size by 4 to get numpics.&lt;br /&gt;
&lt;br /&gt;
=== Masked picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the second chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying masked picture chunks. This table is often quite small.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprite table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the third chunk, the picture table is 16 * numspr bytes long, consisting of eight words for each sprite image (Width\8, Height, x offset, y offset and clipping rectangle left, top, right and bottom; all in that order.) used when displaying sprite chunks. This is what Modkeen exports as its notoriously hard to use xSPRITES.txt file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fonts ===&lt;br /&gt;
&lt;br /&gt;
Always present and always starting at the fourth chunk. (Chunk 3!) Each chunk is a single monochrome font, containing all the entries from 0-255 for that font. Each &#039;letter&#039; is stored separately and consecutively. A game will have at least one, and usually 3 fonts. The format is version two of [[EGA Font format]]&lt;br /&gt;
&lt;br /&gt;
Fonts are used in the game for game texts. They can be stretched or colored and are always transparent, meaning they look strange when not over a single-color background.&lt;br /&gt;
&lt;br /&gt;
=== Pictures (Bitmaps) ===&lt;br /&gt;
These follow game fonts. You need to know how many fonts there are before it to know how what chunk number the first picture is (3+NumFonts). In [[Catacomb 3D]] there are 2 fonts.&lt;br /&gt;
&lt;br /&gt;
Bitmaps are stored as standard [[Raw EGA data]], the size of each plane being the decompressed chunk size \ 4. In order to be displayed properly these need information from chunk 0, the picture table. Note that unlike fonts, data does not wrap, so a 4x4 sprite will consist of four planes of four bytes in size, the same as an 8x4 sprite.&lt;br /&gt;
&lt;br /&gt;
Pictures are used for things such as title screens or pictures in game texts. Most of the main menu will consist of pictures. They are also used for the wall textures in EGA FPS games like [[Catacomb 3D]], in which case the wall textures come near the end of the picture list (starting from chunk 137 in [[Catacomb 3D]]).&lt;br /&gt;
&lt;br /&gt;
The number of picture chunks is given in chunk 0, the picture table.&lt;br /&gt;
&lt;br /&gt;
=== Masked pictures (Masked bitmaps) ===&lt;br /&gt;
&lt;br /&gt;
These follow Pictures. You need to know how many fonts there are, to know how what chunk number the first Masked picture is (3+NumFonts+numpics).&lt;br /&gt;
&lt;br /&gt;
These are identical to the picture chunks in every respect, except being masked, they consist of five EGA planes, not four. Some games (E.g [[Catacomb 3D]] make great use of masked pictures, but most games have only one or two. They need information from chunk 1, the masked picture table, to be displayed correctly.&lt;br /&gt;
&lt;br /&gt;
The number of Masked pictures is given in Chunk 1.&lt;br /&gt;
&lt;br /&gt;
=== Sprites ===&lt;br /&gt;
&lt;br /&gt;
The first Sprite chunk is at 3+numfonts+numpics+numMaskedPics.&lt;br /&gt;
&lt;br /&gt;
Sprites are exactly identical to masked pictures in format except the game cannot stretch or warp them. Most games use these for enemy, player or item graphics during gameplay. They need information from chunk 2, the sprite table both to display correctly and to interact correctly, something more complex than masked pictures.&lt;br /&gt;
&lt;br /&gt;
There are usually several hundred sprite chunks, but [[Catacomb 3D]] only has 3 sprite chunks and they are used for the PaddleWar game (Skulls and Bones). The number of sprite chunks is given in chunk 2.&lt;br /&gt;
&lt;br /&gt;
=== 8x8 tiles ===&lt;br /&gt;
&lt;br /&gt;
8x8 tiles are used by most games in status windows or foe the borders of message windows in-game. (And occasionally by TED5 to display levels.) There are thus not many of them. ALL the masked or unmasked tiles are one single chunk stored as four and five plane [[Raw EGA data]] respectively. The number of 8x8 unmasked and masked tiles is hard-coded into the executable, but can be worked out by dividing the decompressed chunk size by 32 and 40 (The size of one tile&#039;s data) respectively.&lt;br /&gt;
&lt;br /&gt;
=== 16x16 and 32x32 tiles ===&lt;br /&gt;
&lt;br /&gt;
32x32 tiles are optional and rarely used. 16x16 tiles are only occasionally absent and for most games make up the bulk of graphics. There are usually several thousand entries. Both come in masked and unmasked kinds, just like 8x8 tiles.&lt;br /&gt;
&lt;br /&gt;
These chunks have notable differences. Each tile is an individual chunk and stored as four or five plane [[Raw EGA data]] with a plane size of 128 (16x16) or 512 (32x32). These chunks do NOT have a dword specifying their decompressed size as this is hard-coded into the executable as a space saving measure. (As is the start and finish of unmasked and masked tile chunks.) This can cause problems for editing programs.&lt;br /&gt;
&lt;br /&gt;
Tiles make up the bulk of 2D game levels but are seldom seen elsewhere.&lt;br /&gt;
&lt;br /&gt;
=== Misc graphics ===&lt;br /&gt;
&lt;br /&gt;
Sometimes following tile graphics are miscellaneous graphics, that cannot be handled by the other chunk types. For example, Keen 4-6 has two misc graphics files used for the &#039;COOMANDER KEEN terminator text&#039; intro. These graphics usually have unique formats that fit their function and few have been investigated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Keen 4-6 Intro Bitmaps ====&lt;br /&gt;
&lt;br /&gt;
This is the text that displays after the &#039;Ready, press any key&#039; screen at Keen startup. It is composed of a monochrome bitmap that is scrolled across the screen and distorted for special effects. When displayed it is transparent, with a special palette so it is not black-and-white. It consists of a header followed by RLE compressed monochrome data.&lt;br /&gt;
&lt;br /&gt;
 HEADER:&lt;br /&gt;
 0   2    Img height  Height of the image in pixels&lt;br /&gt;
 2   2    Img width   Width of the image in pixels&lt;br /&gt;
 4   2x   Line point  Pointers to line 1,2,3..etc of data. There will be [Img height] of&lt;br /&gt;
                      these, each 2 bytes long. The first pointer will  have the value&lt;br /&gt;
                      (2 * [Img height] + 4)&lt;br /&gt;
 +2  ?    RLE data    RLE-WM compressed data&lt;br /&gt;
&lt;br /&gt;
 DATA:&lt;br /&gt;
 0   2    Black run   Number of black pixels to write&lt;br /&gt;
 2   2    Not-blk run Number of not-black pixels to write&lt;br /&gt;
 4   2    Black run....&lt;br /&gt;
 ...&lt;br /&gt;
 ..&lt;br /&gt;
 .&lt;br /&gt;
 ?  2     End         $FFFF; end of row.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game texts ===&lt;br /&gt;
&lt;br /&gt;
Also known as ANSII chunks, these are used by the game for things like help screens, and have their own format. In the main they are simply text documents, interspersed with various commands to make things happen. Each file is divided up into a number of &#039;pages&#039; which are moved between by pressing the up/down arrows. Pages can also have action sequences (Repeated each time the page is moved to, you cannot leave a page until the sequence finishes.)&lt;br /&gt;
&lt;br /&gt;
 ^P		First command in every file. Defines a page start&lt;br /&gt;
 ^E		Ends the file&lt;br /&gt;
 ^Cx		Change font color to $x until next page or ^C command&lt;br /&gt;
 ^Gx,y,z	Display (unmasked) picture chunk z at location x,y (In pixels)&lt;br /&gt;
 ^Tx,y,z,t	Display picture chunk z at x,y for z clicks of time&lt;br /&gt;
 ^Bx,y,z,t,b	?&lt;br /&gt;
 ^Lx,y		?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Misc files ===&lt;br /&gt;
&lt;br /&gt;
The last few chunks are demo files and occasionally miscellaneous data. Demo file formats are currently unknown but can be recorded using the demo cheat. They contain the level number and difficulty followed by a series of key commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
* [[KeenWiki:ModKeen|ModKeen]] (DOS) and [[KeenWiki:LModKeen|LModKeen]] (Linux/Windows) can be used to modify graphics and text stored in EGAGRAPH.CKx for the Commander Keen [[KeenWiki:Goodbye Galaxy|Goodbye Galaxy]] trilogy.&lt;br /&gt;
* WDC (Windows) can be used to view or modify the graphics and text stored in EGAGRAPH for [[Catacomb 3D]] and [[Catacomb Abyss]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Catacomb Abyss]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Commander Keen Dreams]]&lt;br /&gt;
[[Category:Dangerous Dave 3]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Graphics Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3597</id>
		<title>EGAGraph Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3597"/>
		<updated>2011-09-02T02:20:24Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* Utilities */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;EGAGraph&#039;&#039;&#039;, short for &#039;EGA graphics library&#039; is the format used to store graphics, demos, fonts, game texts and more in many early [[:Category:Id Software|id Software]] games.&lt;br /&gt;
&lt;br /&gt;
The basic format is that of a number of [[Huffman Compression]] compressed sub-files (Chunks) stored in a similar manner to the [[AudioT Format]]. Like this format it has three main files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt;and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is notable that while the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; are stored in the game executable, they need to be extracted for [[TED5]] to edit levels.&lt;br /&gt;
&lt;br /&gt;
This article may contain errors as some formats have not been worked out completely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= File formats =&lt;br /&gt;
&lt;br /&gt;
== EGA Head (EGAHEAD.xxx) ==&lt;br /&gt;
There are two versions of this format. The first version, used in [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], is an array of 4-byte little-endian values. The second version, used in all later EGA games, is an array of 3-byte unsigned little-endian values.&lt;br /&gt;
&lt;br /&gt;
This header file may be present as an external file (eg. [[Bio Menace]]), or it may be included in the EXE file (eg. [[Catacomb 3D]]). The last entry in the header is always the size of the EGAGRAPH.xxx file, and the first entry in the header is always 00 00 00. To find the end, you can search for filesize(EGAGRAPH.xxx) as a 3-byte (little-endian) value in the EXE. Then to find the start, go back 3 bytes at a time until you get to 00 000 00. Or use the fact that entries always get smaller as you go back, unless the entry is $FFFFFF. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] v1.00 &amp;lt;tt&amp;gt;EGAHEAD.C3D&amp;lt;/tt&amp;gt; is at $1BFD0 from the start of the decompressed ([[unlzexe]]) EXE file, and is 1437 bytes long, or 479 3-byte entries (for 478 chunks). It is then followed by 3 zero bytes (padding to multiple of 16?) 00 00 00, then the &amp;lt;tt&amp;gt;MAPHEAD.C3D&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb Abyss]] v1.13 &amp;lt;tt&amp;gt;EGAHEAD.ABS&amp;lt;/tt&amp;gt; is at $1BDB0 from the start of the decompressed ([[unlzexe]]) EXE file, and 1881 bytes long and has 626 chunks.&lt;br /&gt;
&lt;br /&gt;
This header file stores the offsets (relative to the start of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file) for each sub file.  The format is trivial, in that the header file is simply an array of 3 or 4 byte variables.  (Each variable is a &amp;quot;slot&amp;quot;, as the game refers to files by index.) Most games use the more compact 3-byte variables, since the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is never larger than $FFFFFF. However games based on older engines, notably [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], use 4-byte vales as these are easier to deal with.&lt;br /&gt;
&lt;br /&gt;
It is important to note that not every &#039;slot&#039; will be in use. Tiles especially if blank (All black) will be considered &#039;empty&#039; and not worth adding to the file. (A blank 16x16 tile takes up 12 bytes of space if compressed, and there can be hundreds.) There are two ways of dealing with this; by default the games set all empty slot headers to -1, but many programs compress the graphics anyway and use a normal header value for them.&lt;br /&gt;
&lt;br /&gt;
The last offset in the file will be an offset to the end of the main &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file.  (So this should be ignored when reading the file to prevent a zero-byte file appearing last.) The total size of the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; divided by 3 (Or 4) will also give the number of &#039;slots&#039; the game uses. This varies, but is usually about 10,000.&lt;br /&gt;
&lt;br /&gt;
Unlike [[AudioT Format]] files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; is always compressed. However the header and dictionary may be external (E.g [[Bio Menace]])&lt;br /&gt;
&lt;br /&gt;
== Dictionary (EGADICT.xxx) ==&lt;br /&gt;
&lt;br /&gt;
The same [[Huffman Compression]] scheme used elsewhere in the [[Commander Keen]] series is used.  When reading compressed chunks out of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, the first four bytes located at the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; offset are a UINT32LE specifying the file&#039;s decompressed size (which is required for the decompression algorithm.)  The compressed data then follows, EXCEPT for 16x16 masked and unmasked tiles. Since these all have a similar decompressed size (128 bytes for unmasked, 256 bytes for masked) it is a waste of space to include these (Since tiles make up the bulk of graphics slots.) The decompressed size is hard coded, as are the start and finish of the unmasked and masked tile slots.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; file is not often obvious, usually being embedded in the main exe file. It is possible to locate it by looking for the string &amp;lt;tt&amp;gt;$FD $01 $00 $00 $00 $00&amp;lt;/tt&amp;gt;, which appears at the end of nearly all Huffman dictionaries. They are the last 6 bytes out of 1024 (256*2*2), so add 6 and subtract 1024 to get the start (pointer to the head node).&lt;br /&gt;
&lt;br /&gt;
Executables usually contain two or more dictionaries, but the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; is usually &#039;&#039;&#039;the second one&#039;&#039;&#039;, except in the case of early games like Keen Dreams, where it is the first of THREE. (A simple check of whether it decompresses the data sensibly works.)&lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] &amp;lt;tt&amp;gt;EGADICT.C3D&amp;lt;/tt&amp;gt; is at offset $24464 from the start of the decompressed CAT3D.EXE, which is the second Huffman dictionary and comes immediately after the first Huffman Dictionary.&lt;br /&gt;
&lt;br /&gt;
In [[Catacomb Abyss]] v1.13 &amp;lt;tt&amp;gt;EGADICT.ABS&amp;lt;/tt&amp;gt; is at offset $2734C from the start of the decompressed CATABYSS.EXE, which is the second Huffman dictionary.&lt;br /&gt;
&lt;br /&gt;
== Main file (EGAGRAPH.xxx) ==&lt;br /&gt;
&lt;br /&gt;
This file is simply an array of data files.  Each file starts at the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, and as there are no filenames each file is referred to by its index/slot number.  Slots containing dummy values in the header are treated as if they don&#039;t exist in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file. Each file within the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is individually compressed.  A file can be read by opening the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, seeking to the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, reading a UINT32LE for the decompressed file size, and then decompressing the data from that point onwards using standard Huffman decompression techniques.&lt;br /&gt;
&lt;br /&gt;
Note that in early games such as Keen Dreams, the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file may have another name. (Such as &amp;lt;tt&amp;gt;KDREAM.EGA&amp;lt;/tt&amp;gt; in that case.) in which case it is always the largest non-executable file.&lt;br /&gt;
&lt;br /&gt;
=== Chunks ===&lt;br /&gt;
&lt;br /&gt;
Each sub file or chunk is a separate graphic, ordered in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file in a specific way, much again like the [[AudioT Format]].  Chunks are labeled starting at 0. The game executable is hard coded for the start and finish of various chunk types. For example, Keen 4 has chunks 124-520 as sprites and will treat any chunk between these two numbers as a sprite. (Note that the game refers to chunk number, not sprite number.) The usual order of chunks is:&lt;br /&gt;
&lt;br /&gt;
 Picture table&lt;br /&gt;
 Masked picture table&lt;br /&gt;
 Sprite table&lt;br /&gt;
 Fonts&lt;br /&gt;
 Pictures (Unmasked bitmaps)&lt;br /&gt;
 Masked pictures&lt;br /&gt;
 8x8 unmasked tiles (Single chunk)&lt;br /&gt;
 8x8 masked tiles (Single chunk)&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 16x16 masked tiles&lt;br /&gt;
 32x32 unmasked tiles (Optional)&lt;br /&gt;
 32x32 masked tiles (Optional)&lt;br /&gt;
 Misc graphics (Optional)&lt;br /&gt;
 Game texts&lt;br /&gt;
 Demo files (Optional)&lt;br /&gt;
 Misc data (Optional)&lt;br /&gt;
&lt;br /&gt;
== Chunk formats ==&lt;br /&gt;
&lt;br /&gt;
When compressed each chunk consists of a dword giving the decompressed size followed by the compressed data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the first chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying picture chunks.&lt;br /&gt;
&lt;br /&gt;
Divide the decompressed size by 4 to get numpics.&lt;br /&gt;
&lt;br /&gt;
=== Masked picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the second chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying masked picture chunks. This table is often quite small.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprite table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the third chunk, the picture table is 16 * numspr bytes long, consisting of eight words for each sprite image (Width\8, Height, x offset, y offset and clipping rectangle left, top, right and bottom; all in that order.) used when displaying sprite chunks. This is what Modkeen exports as its notoriously hard to use xSPRITES.txt file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fonts ===&lt;br /&gt;
&lt;br /&gt;
Always present and always starting at the fourth chunk. (Chunk 3!) Each chunk is a single monochrome font, containing all the entries from 0-255 for that font. Each &#039;letter&#039; is stored separately and consecutively. A game will have at least one, and usually 3 fonts. The format is version two of [[EGA Font format]]&lt;br /&gt;
&lt;br /&gt;
Fonts are used in the game for game texts. They can be stretched or colored and are always transparent, meaning they look strange when not over a single-color background.&lt;br /&gt;
&lt;br /&gt;
=== Pictures (Bitmaps) ===&lt;br /&gt;
These follow game fonts. You need to know how many fonts there are before it to know how what chunk number the first picture is (3+NumFonts). In [[Catacomb 3D]] there are 2 fonts.&lt;br /&gt;
&lt;br /&gt;
Bitmaps are stored as standard [[Raw EGA data]], the size of each plane being the decompressed chunk size \ 4. In order to be displayed properly these need information from chunk 0, the picture table. Note that unlike fonts, data does not wrap, so a 4x4 sprite will consist of four planes of four bytes in size, the same as an 8x4 sprite.&lt;br /&gt;
&lt;br /&gt;
Pictures are used for things such as title screens or pictures in game texts. Most of the main menu will consist of pictures. They are also used for the wall textures in EGA FPS games like [[Catacomb 3D]], in which case the wall textures come near the end of the picture list (starting from chunk 137 in [[Catacomb 3D]]).&lt;br /&gt;
&lt;br /&gt;
The number of picture chunks is given in chunk 0, the picture table.&lt;br /&gt;
&lt;br /&gt;
=== Masked pictures (Masked bitmaps) ===&lt;br /&gt;
&lt;br /&gt;
These follow Pictures. You need to know how many fonts there are, to know how what chunk number the first Masked picture is (3+NumFonts+numpics).&lt;br /&gt;
&lt;br /&gt;
These are identical to the picture chunks in every respect, except being masked, they consist of five EGA planes, not four. Some games (E.g [[Catacomb 3D]] make great use of masked pictures, but most games have only one or two. They need information from chunk 1, the masked picture table, to be displayed correctly.&lt;br /&gt;
&lt;br /&gt;
The number of Masked pictures is given in Chunk 1.&lt;br /&gt;
&lt;br /&gt;
=== Sprites ===&lt;br /&gt;
&lt;br /&gt;
The first Sprite chunk is at 3+numfonts+numpics+numMaskedPics.&lt;br /&gt;
&lt;br /&gt;
Sprites are exactly identical to masked pictures in format except the game cannot stretch or warp them. Most games use these for enemy, player or item graphics during gameplay. They need information from chunk 2, the sprite table both to display correctly and to interact correctly, something more complex than masked pictures.&lt;br /&gt;
&lt;br /&gt;
There are usually several hundred sprite chunks, but [[Catacomb 3D]] only has 3 sprite chunks and they are used for the PaddleWar game (Skulls and Bones). The number of sprite chunks is given in chunk 2.&lt;br /&gt;
&lt;br /&gt;
=== 8x8 tiles ===&lt;br /&gt;
&lt;br /&gt;
8x8 tiles are used by most games in status windows or foe the borders of message windows in-game. (And occasionally by TED5 to display levels.) There are thus not many of them. ALL the masked or unmasked tiles are one single chunk stored as four and five plane [[Raw EGA data]] respectively. The number of 8x8 unmasked and masked tiles is hard-coded into the executable, but can be worked out by dividing the decompressed chunk size by 32 and 40 (The size of one tile&#039;s data) respectively.&lt;br /&gt;
&lt;br /&gt;
=== 16x16 and 32x32 tiles ===&lt;br /&gt;
&lt;br /&gt;
32x32 tiles are optional and rarely used. 16x16 tiles are only occasionally absent and for most games make up the bulk of graphics. There are usually several thousand entries. Both come in masked and unmasked kinds, just like 8x8 tiles.&lt;br /&gt;
&lt;br /&gt;
These chunks have notable differences. Each tile is an individual chunk and stored as four or five plane [[Raw EGA data]] with a plane size of 128 (16x16) or 512 (32x32). These chunks do NOT have a dword specifying their decompressed size as this is hard-coded into the executable as a space saving measure. (As is the start and finish of unmasked and masked tile chunks.) This can cause problems for editing programs.&lt;br /&gt;
&lt;br /&gt;
Tiles make up the bulk of 2D game levels but are seldom seen elsewhere.&lt;br /&gt;
&lt;br /&gt;
=== Misc graphics ===&lt;br /&gt;
&lt;br /&gt;
Sometimes following tile graphics are miscellaneous graphics, that cannot be handled by the other chunk types. For example, Keen 4-6 has two misc graphics files used for the &#039;COOMANDER KEEN terminator text&#039; intro. These graphics usually have unique formats that fit their function and few have been investigated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Keen 4-6 Intro Bitmaps ====&lt;br /&gt;
&lt;br /&gt;
This is the text that displays after the &#039;Ready, press any key&#039; screen at Keen startup. It is composed of a monochrome bitmap that is scrolled across the screen and distorted for special effects. When displayed it is transparent, with a special palette so it is not black-and-white. It consists of a header followed by RLE compressed monochrome data.&lt;br /&gt;
&lt;br /&gt;
 HEADER:&lt;br /&gt;
 0   2    Img height  Height of the image in pixels&lt;br /&gt;
 2   2    Img width   Width of the image in pixels&lt;br /&gt;
 4   2x   Line point  Pointers to line 1,2,3..etc of data. There will be [Img height] of&lt;br /&gt;
                      these, each 2 bytes long. The first pointer will  have the value&lt;br /&gt;
                      (2 * [Img height] + 4)&lt;br /&gt;
 +2  ?    RLE data    RLE-WM compressed data&lt;br /&gt;
&lt;br /&gt;
 DATA:&lt;br /&gt;
 0   2    Black run   Number of black pixels to write&lt;br /&gt;
 2   2    Not-blk run Number of not-black pixels to write&lt;br /&gt;
 4   2    Black run....&lt;br /&gt;
 ...&lt;br /&gt;
 ..&lt;br /&gt;
 .&lt;br /&gt;
 ?  2     End         $FFFF; end of row.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game texts ===&lt;br /&gt;
&lt;br /&gt;
Also known as ANSII chunks, these are used by the game for things like help screens, and have their own format. In the main they are simply text documents, interspersed with various commands to make things happen. Each file is divided up into a number of &#039;pages&#039; which are moved between by pressing the up/down arrows. Pages can also have action sequences (Repeated each time the page is moved to, you cannot leave a page until the sequence finishes.)&lt;br /&gt;
&lt;br /&gt;
 ^P		First command in every file. Defines a page start&lt;br /&gt;
 ^E		Ends the file&lt;br /&gt;
 ^Cx		Change font color to $x until next page or ^C command&lt;br /&gt;
 ^Gx,y,z	Display (unmasked) picture chunk z at location x,y (In pixels)&lt;br /&gt;
 ^Tx,y,z,t	Display picture chunk z at x,y for z clicks of time&lt;br /&gt;
 ^Bx,y,z,t,b	?&lt;br /&gt;
 ^Lx,y		?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Misc files ===&lt;br /&gt;
&lt;br /&gt;
The last few chunks are demo files and occasionally miscellaneous data. Demo file formats are currently unknown but can be recorded using the demo cheat. They contain the level number and difficulty followed by a series of key commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
* [[KeenWiki:ModKeen|ModKeen]] (DOS) and [[KeenWiki:LModKeen|LModKeen]] (Linux/Windows) can be used to modify graphics and text stored in EGAGRAPH.CKx for the Commander Keen [[KeenWiki:Goodbye Galaxy|Goodbye Galaxy]] trilogy.&lt;br /&gt;
* WDC (Windows) can be used to view or modify the graphics and text stored in EGAGRAPH for [[Catacomb 3D]] and [[Catacomb Abyss]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Catacomb Abyss]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Commander Keen Dreams]]&lt;br /&gt;
[[Category:Dangerous Dave 3]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Graphics Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3596</id>
		<title>EGAGraph Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3596"/>
		<updated>2011-09-02T02:05:36Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* Dictionary (EGADICT.xxx) */ Catacomb Abyss&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;EGAGraph&#039;&#039;&#039;, short for &#039;EGA graphics library&#039; is the format used to store graphics, demos, fonts, game texts and more in many early [[:Category:Id Software|id Software]] games.&lt;br /&gt;
&lt;br /&gt;
The basic format is that of a number of [[Huffman Compression]] compressed sub-files (Chunks) stored in a similar manner to the [[AudioT Format]]. Like this format it has three main files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt;and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is notable that while the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; are stored in the game executable, they need to be extracted for [[TED5]] to edit levels.&lt;br /&gt;
&lt;br /&gt;
This article may contain errors as some formats have not been worked out completely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= File formats =&lt;br /&gt;
&lt;br /&gt;
== EGA Head (EGAHEAD.xxx) ==&lt;br /&gt;
There are two versions of this format. The first version, used in [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], is an array of 4-byte little-endian values. The second version, used in all later EGA games, is an array of 3-byte unsigned little-endian values.&lt;br /&gt;
&lt;br /&gt;
This header file may be present as an external file (eg. [[Bio Menace]]), or it may be included in the EXE file (eg. [[Catacomb 3D]]). The last entry in the header is always the size of the EGAGRAPH.xxx file, and the first entry in the header is always 00 00 00. To find the end, you can search for filesize(EGAGRAPH.xxx) as a 3-byte (little-endian) value in the EXE. Then to find the start, go back 3 bytes at a time until you get to 00 000 00. Or use the fact that entries always get smaller as you go back, unless the entry is $FFFFFF. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] v1.00 &amp;lt;tt&amp;gt;EGAHEAD.C3D&amp;lt;/tt&amp;gt; is at $1BFD0 from the start of the decompressed ([[unlzexe]]) EXE file, and is 1437 bytes long, or 479 3-byte entries (for 478 chunks). It is then followed by 3 zero bytes (padding to multiple of 16?) 00 00 00, then the &amp;lt;tt&amp;gt;MAPHEAD.C3D&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb Abyss]] v1.13 &amp;lt;tt&amp;gt;EGAHEAD.ABS&amp;lt;/tt&amp;gt; is at $1BDB0 from the start of the decompressed ([[unlzexe]]) EXE file, and 1881 bytes long and has 626 chunks.&lt;br /&gt;
&lt;br /&gt;
This header file stores the offsets (relative to the start of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file) for each sub file.  The format is trivial, in that the header file is simply an array of 3 or 4 byte variables.  (Each variable is a &amp;quot;slot&amp;quot;, as the game refers to files by index.) Most games use the more compact 3-byte variables, since the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is never larger than $FFFFFF. However games based on older engines, notably [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], use 4-byte vales as these are easier to deal with.&lt;br /&gt;
&lt;br /&gt;
It is important to note that not every &#039;slot&#039; will be in use. Tiles especially if blank (All black) will be considered &#039;empty&#039; and not worth adding to the file. (A blank 16x16 tile takes up 12 bytes of space if compressed, and there can be hundreds.) There are two ways of dealing with this; by default the games set all empty slot headers to -1, but many programs compress the graphics anyway and use a normal header value for them.&lt;br /&gt;
&lt;br /&gt;
The last offset in the file will be an offset to the end of the main &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file.  (So this should be ignored when reading the file to prevent a zero-byte file appearing last.) The total size of the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; divided by 3 (Or 4) will also give the number of &#039;slots&#039; the game uses. This varies, but is usually about 10,000.&lt;br /&gt;
&lt;br /&gt;
Unlike [[AudioT Format]] files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; is always compressed. However the header and dictionary may be external (E.g [[Bio Menace]])&lt;br /&gt;
&lt;br /&gt;
== Dictionary (EGADICT.xxx) ==&lt;br /&gt;
&lt;br /&gt;
The same [[Huffman Compression]] scheme used elsewhere in the [[Commander Keen]] series is used.  When reading compressed chunks out of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, the first four bytes located at the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; offset are a UINT32LE specifying the file&#039;s decompressed size (which is required for the decompression algorithm.)  The compressed data then follows, EXCEPT for 16x16 masked and unmasked tiles. Since these all have a similar decompressed size (128 bytes for unmasked, 256 bytes for masked) it is a waste of space to include these (Since tiles make up the bulk of graphics slots.) The decompressed size is hard coded, as are the start and finish of the unmasked and masked tile slots.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; file is not often obvious, usually being embedded in the main exe file. It is possible to locate it by looking for the string &amp;lt;tt&amp;gt;$FD $01 $00 $00 $00 $00&amp;lt;/tt&amp;gt;, which appears at the end of nearly all Huffman dictionaries. They are the last 6 bytes out of 1024 (256*2*2), so add 6 and subtract 1024 to get the start (pointer to the head node).&lt;br /&gt;
&lt;br /&gt;
Executables usually contain two or more dictionaries, but the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; is usually &#039;&#039;&#039;the second one&#039;&#039;&#039;, except in the case of early games like Keen Dreams, where it is the first of THREE. (A simple check of whether it decompresses the data sensibly works.)&lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] &amp;lt;tt&amp;gt;EGADICT.C3D&amp;lt;/tt&amp;gt; is at offset $24464 from the start of the decompressed CAT3D.EXE, which is the second Huffman dictionary and comes immediately after the first Huffman Dictionary.&lt;br /&gt;
&lt;br /&gt;
In [[Catacomb Abyss]] v1.13 &amp;lt;tt&amp;gt;EGADICT.ABS&amp;lt;/tt&amp;gt; is at offset $2734C from the start of the decompressed CATABYSS.EXE, which is the second Huffman dictionary.&lt;br /&gt;
&lt;br /&gt;
== Main file (EGAGRAPH.xxx) ==&lt;br /&gt;
&lt;br /&gt;
This file is simply an array of data files.  Each file starts at the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, and as there are no filenames each file is referred to by its index/slot number.  Slots containing dummy values in the header are treated as if they don&#039;t exist in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file. Each file within the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is individually compressed.  A file can be read by opening the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, seeking to the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, reading a UINT32LE for the decompressed file size, and then decompressing the data from that point onwards using standard Huffman decompression techniques.&lt;br /&gt;
&lt;br /&gt;
Note that in early games such as Keen Dreams, the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file may have another name. (Such as &amp;lt;tt&amp;gt;KDREAM.EGA&amp;lt;/tt&amp;gt; in that case.) in which case it is always the largest non-executable file.&lt;br /&gt;
&lt;br /&gt;
=== Chunks ===&lt;br /&gt;
&lt;br /&gt;
Each sub file or chunk is a separate graphic, ordered in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file in a specific way, much again like the [[AudioT Format]].  Chunks are labeled starting at 0. The game executable is hard coded for the start and finish of various chunk types. For example, Keen 4 has chunks 124-520 as sprites and will treat any chunk between these two numbers as a sprite. (Note that the game refers to chunk number, not sprite number.) The usual order of chunks is:&lt;br /&gt;
&lt;br /&gt;
 Picture table&lt;br /&gt;
 Masked picture table&lt;br /&gt;
 Sprite table&lt;br /&gt;
 Fonts&lt;br /&gt;
 Pictures (Unmasked bitmaps)&lt;br /&gt;
 Masked pictures&lt;br /&gt;
 8x8 unmasked tiles (Single chunk)&lt;br /&gt;
 8x8 masked tiles (Single chunk)&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 16x16 masked tiles&lt;br /&gt;
 32x32 unmasked tiles (Optional)&lt;br /&gt;
 32x32 masked tiles (Optional)&lt;br /&gt;
 Misc graphics (Optional)&lt;br /&gt;
 Game texts&lt;br /&gt;
 Demo files (Optional)&lt;br /&gt;
 Misc data (Optional)&lt;br /&gt;
&lt;br /&gt;
== Chunk formats ==&lt;br /&gt;
&lt;br /&gt;
When compressed each chunk consists of a dword giving the decompressed size followed by the compressed data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the first chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying picture chunks.&lt;br /&gt;
&lt;br /&gt;
Divide the decompressed size by 4 to get numpics.&lt;br /&gt;
&lt;br /&gt;
=== Masked picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the second chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying masked picture chunks. This table is often quite small.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprite table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the third chunk, the picture table is 16 * numspr bytes long, consisting of eight words for each sprite image (Width\8, Height, x offset, y offset and clipping rectangle left, top, right and bottom; all in that order.) used when displaying sprite chunks. This is what Modkeen exports as its notoriously hard to use xSPRITES.txt file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fonts ===&lt;br /&gt;
&lt;br /&gt;
Always present and always starting at the fourth chunk. (Chunk 3!) Each chunk is a single monochrome font, containing all the entries from 0-255 for that font. Each &#039;letter&#039; is stored separately and consecutively. A game will have at least one, and usually 3 fonts. The format is version two of [[EGA Font format]]&lt;br /&gt;
&lt;br /&gt;
Fonts are used in the game for game texts. They can be stretched or colored and are always transparent, meaning they look strange when not over a single-color background.&lt;br /&gt;
&lt;br /&gt;
=== Pictures (Bitmaps) ===&lt;br /&gt;
These follow game fonts. You need to know how many fonts there are before it to know how what chunk number the first picture is (3+NumFonts). In [[Catacomb 3D]] there are 2 fonts.&lt;br /&gt;
&lt;br /&gt;
Bitmaps are stored as standard [[Raw EGA data]], the size of each plane being the decompressed chunk size \ 4. In order to be displayed properly these need information from chunk 0, the picture table. Note that unlike fonts, data does not wrap, so a 4x4 sprite will consist of four planes of four bytes in size, the same as an 8x4 sprite.&lt;br /&gt;
&lt;br /&gt;
Pictures are used for things such as title screens or pictures in game texts. Most of the main menu will consist of pictures. They are also used for the wall textures in EGA FPS games like [[Catacomb 3D]], in which case the wall textures come near the end of the picture list (starting from chunk 137 in [[Catacomb 3D]]).&lt;br /&gt;
&lt;br /&gt;
The number of picture chunks is given in chunk 0, the picture table.&lt;br /&gt;
&lt;br /&gt;
=== Masked pictures (Masked bitmaps) ===&lt;br /&gt;
&lt;br /&gt;
These follow Pictures. You need to know how many fonts there are, to know how what chunk number the first Masked picture is (3+NumFonts+numpics).&lt;br /&gt;
&lt;br /&gt;
These are identical to the picture chunks in every respect, except being masked, they consist of five EGA planes, not four. Some games (E.g [[Catacomb 3D]] make great use of masked pictures, but most games have only one or two. They need information from chunk 1, the masked picture table, to be displayed correctly.&lt;br /&gt;
&lt;br /&gt;
The number of Masked pictures is given in Chunk 1.&lt;br /&gt;
&lt;br /&gt;
=== Sprites ===&lt;br /&gt;
&lt;br /&gt;
The first Sprite chunk is at 3+numfonts+numpics+numMaskedPics.&lt;br /&gt;
&lt;br /&gt;
Sprites are exactly identical to masked pictures in format except the game cannot stretch or warp them. Most games use these for enemy, player or item graphics during gameplay. They need information from chunk 2, the sprite table both to display correctly and to interact correctly, something more complex than masked pictures.&lt;br /&gt;
&lt;br /&gt;
There are usually several hundred sprite chunks, but [[Catacomb 3D]] only has 3 sprite chunks and they are used for the PaddleWar game (Skulls and Bones). The number of sprite chunks is given in chunk 2.&lt;br /&gt;
&lt;br /&gt;
=== 8x8 tiles ===&lt;br /&gt;
&lt;br /&gt;
8x8 tiles are used by most games in status windows or foe the borders of message windows in-game. (And occasionally by TED5 to display levels.) There are thus not many of them. ALL the masked or unmasked tiles are one single chunk stored as four and five plane [[Raw EGA data]] respectively. The number of 8x8 unmasked and masked tiles is hard-coded into the executable, but can be worked out by dividing the decompressed chunk size by 32 and 40 (The size of one tile&#039;s data) respectively.&lt;br /&gt;
&lt;br /&gt;
=== 16x16 and 32x32 tiles ===&lt;br /&gt;
&lt;br /&gt;
32x32 tiles are optional and rarely used. 16x16 tiles are only occasionally absent and for most games make up the bulk of graphics. There are usually several thousand entries. Both come in masked and unmasked kinds, just like 8x8 tiles.&lt;br /&gt;
&lt;br /&gt;
These chunks have notable differences. Each tile is an individual chunk and stored as four or five plane [[Raw EGA data]] with a plane size of 128 (16x16) or 512 (32x32). These chunks do NOT have a dword specifying their decompressed size as this is hard-coded into the executable as a space saving measure. (As is the start and finish of unmasked and masked tile chunks.) This can cause problems for editing programs.&lt;br /&gt;
&lt;br /&gt;
Tiles make up the bulk of 2D game levels but are seldom seen elsewhere.&lt;br /&gt;
&lt;br /&gt;
=== Misc graphics ===&lt;br /&gt;
&lt;br /&gt;
Sometimes following tile graphics are miscellaneous graphics, that cannot be handled by the other chunk types. For example, Keen 4-6 has two misc graphics files used for the &#039;COOMANDER KEEN terminator text&#039; intro. These graphics usually have unique formats that fit their function and few have been investigated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Keen 4-6 Intro Bitmaps ====&lt;br /&gt;
&lt;br /&gt;
This is the text that displays after the &#039;Ready, press any key&#039; screen at Keen startup. It is composed of a monochrome bitmap that is scrolled across the screen and distorted for special effects. When displayed it is transparent, with a special palette so it is not black-and-white. It consists of a header followed by RLE compressed monochrome data.&lt;br /&gt;
&lt;br /&gt;
 HEADER:&lt;br /&gt;
 0   2    Img height  Height of the image in pixels&lt;br /&gt;
 2   2    Img width   Width of the image in pixels&lt;br /&gt;
 4   2x   Line point  Pointers to line 1,2,3..etc of data. There will be [Img height] of&lt;br /&gt;
                      these, each 2 bytes long. The first pointer will  have the value&lt;br /&gt;
                      (2 * [Img height] + 4)&lt;br /&gt;
 +2  ?    RLE data    RLE-WM compressed data&lt;br /&gt;
&lt;br /&gt;
 DATA:&lt;br /&gt;
 0   2    Black run   Number of black pixels to write&lt;br /&gt;
 2   2    Not-blk run Number of not-black pixels to write&lt;br /&gt;
 4   2    Black run....&lt;br /&gt;
 ...&lt;br /&gt;
 ..&lt;br /&gt;
 .&lt;br /&gt;
 ?  2     End         $FFFF; end of row.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game texts ===&lt;br /&gt;
&lt;br /&gt;
Also known as ANSII chunks, these are used by the game for things like help screens, and have their own format. In the main they are simply text documents, interspersed with various commands to make things happen. Each file is divided up into a number of &#039;pages&#039; which are moved between by pressing the up/down arrows. Pages can also have action sequences (Repeated each time the page is moved to, you cannot leave a page until the sequence finishes.)&lt;br /&gt;
&lt;br /&gt;
 ^P		First command in every file. Defines a page start&lt;br /&gt;
 ^E		Ends the file&lt;br /&gt;
 ^Cx		Change font color to $x until next page or ^C command&lt;br /&gt;
 ^Gx,y,z	Display (unmasked) picture chunk z at location x,y (In pixels)&lt;br /&gt;
 ^Tx,y,z,t	Display picture chunk z at x,y for z clicks of time&lt;br /&gt;
 ^Bx,y,z,t,b	?&lt;br /&gt;
 ^Lx,y		?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Misc files ===&lt;br /&gt;
&lt;br /&gt;
The last few chunks are demo files and occasionally miscellaneous data. Demo file formats are currently unknown but can be recorded using the demo cheat. They contain the level number and difficulty followed by a series of key commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
* [[KeenWiki:ModKeen|ModKeen]] (DOS) and [[KeenWiki:LModKeen|LModKeen]] (Linux/Windows) can be used to modify graphics and text stored in EGAGRAPH.CKx for the Commander Keen [[KeenWiki:Goodbye Galaxy|Goodbye Galaxy]] trilogy.&lt;br /&gt;
* WDC (Windows) can be used to view or modify the graphics and text stored in EGAGRAPH.C3D for [[Catacomb 3D]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Commander Keen Dreams]]&lt;br /&gt;
[[Category:Dangerous Dave 3]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Graphics Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3595</id>
		<title>EGAGraph Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3595"/>
		<updated>2011-09-02T02:00:55Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* EGA Head (EGAHEAD.xxx) */ Catacomb Abyss&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;EGAGraph&#039;&#039;&#039;, short for &#039;EGA graphics library&#039; is the format used to store graphics, demos, fonts, game texts and more in many early [[:Category:Id Software|id Software]] games.&lt;br /&gt;
&lt;br /&gt;
The basic format is that of a number of [[Huffman Compression]] compressed sub-files (Chunks) stored in a similar manner to the [[AudioT Format]]. Like this format it has three main files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt;and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is notable that while the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; are stored in the game executable, they need to be extracted for [[TED5]] to edit levels.&lt;br /&gt;
&lt;br /&gt;
This article may contain errors as some formats have not been worked out completely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= File formats =&lt;br /&gt;
&lt;br /&gt;
== EGA Head (EGAHEAD.xxx) ==&lt;br /&gt;
There are two versions of this format. The first version, used in [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], is an array of 4-byte little-endian values. The second version, used in all later EGA games, is an array of 3-byte unsigned little-endian values.&lt;br /&gt;
&lt;br /&gt;
This header file may be present as an external file (eg. [[Bio Menace]]), or it may be included in the EXE file (eg. [[Catacomb 3D]]). The last entry in the header is always the size of the EGAGRAPH.xxx file, and the first entry in the header is always 00 00 00. To find the end, you can search for filesize(EGAGRAPH.xxx) as a 3-byte (little-endian) value in the EXE. Then to find the start, go back 3 bytes at a time until you get to 00 000 00. Or use the fact that entries always get smaller as you go back, unless the entry is $FFFFFF. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] v1.00 &amp;lt;tt&amp;gt;EGAHEAD.C3D&amp;lt;/tt&amp;gt; is at $1BFD0 from the start of the decompressed ([[unlzexe]]) EXE file, and is 1437 bytes long, or 479 3-byte entries (for 478 chunks). It is then followed by 3 zero bytes (padding to multiple of 16?) 00 00 00, then the &amp;lt;tt&amp;gt;MAPHEAD.C3D&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb Abyss]] v1.13 &amp;lt;tt&amp;gt;EGAHEAD.ABS&amp;lt;/tt&amp;gt; is at $1BDB0 from the start of the decompressed ([[unlzexe]]) EXE file, and 1881 bytes long and has 626 chunks.&lt;br /&gt;
&lt;br /&gt;
This header file stores the offsets (relative to the start of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file) for each sub file.  The format is trivial, in that the header file is simply an array of 3 or 4 byte variables.  (Each variable is a &amp;quot;slot&amp;quot;, as the game refers to files by index.) Most games use the more compact 3-byte variables, since the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is never larger than $FFFFFF. However games based on older engines, notably [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], use 4-byte vales as these are easier to deal with.&lt;br /&gt;
&lt;br /&gt;
It is important to note that not every &#039;slot&#039; will be in use. Tiles especially if blank (All black) will be considered &#039;empty&#039; and not worth adding to the file. (A blank 16x16 tile takes up 12 bytes of space if compressed, and there can be hundreds.) There are two ways of dealing with this; by default the games set all empty slot headers to -1, but many programs compress the graphics anyway and use a normal header value for them.&lt;br /&gt;
&lt;br /&gt;
The last offset in the file will be an offset to the end of the main &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file.  (So this should be ignored when reading the file to prevent a zero-byte file appearing last.) The total size of the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; divided by 3 (Or 4) will also give the number of &#039;slots&#039; the game uses. This varies, but is usually about 10,000.&lt;br /&gt;
&lt;br /&gt;
Unlike [[AudioT Format]] files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; is always compressed. However the header and dictionary may be external (E.g [[Bio Menace]])&lt;br /&gt;
&lt;br /&gt;
== Dictionary (EGADICT.xxx) ==&lt;br /&gt;
&lt;br /&gt;
The same [[Huffman Compression]] scheme used elsewhere in the [[Commander Keen]] series is used.  When reading compressed chunks out of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, the first four bytes located at the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; offset are a UINT32LE specifying the file&#039;s decompressed size (which is required for the decompression algorithm.)  The compressed data then follows, EXCEPT for 16x16 masked and unmasked tiles. Since these all have a similar decompressed size (128 bytes for unmasked, 256 bytes for masked) it is a waste of space to include these (Since tiles make up the bulk of graphics slots.) The decompressed size is hard coded, as are the start and finish of the unmasked and masked tile slots.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; file is not often obvious, usually being embedded in the main exe file. It is possible to locate it by looking for the string &amp;lt;tt&amp;gt;$FD $01 $00 $00 $00 $00&amp;lt;/tt&amp;gt;, which appears at the end of nearly all Huffman dictionaries. They are the last 6 bytes out of 1024 (256*2*2), so add 6 and subtract 1024 to get the start (pointer to the head node).&lt;br /&gt;
&lt;br /&gt;
Executables usually contain two or more dictionaries, but the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; is usually &#039;&#039;&#039;the second one&#039;&#039;&#039;, except in the case of early games like Keen Dreams, where it is the first of THREE. (A simple check of whether it decompresses the data sensibly works.)&lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] &amp;lt;tt&amp;gt;EGADICT.C3D&amp;lt;/tt&amp;gt; is at offset $24464 from the start of the decompressed CAT3D.EXE, which is the second Huffman dictionary and comes immediately after the first Huffman Dictionary.&lt;br /&gt;
&lt;br /&gt;
== Main file (EGAGRAPH.xxx) ==&lt;br /&gt;
&lt;br /&gt;
This file is simply an array of data files.  Each file starts at the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, and as there are no filenames each file is referred to by its index/slot number.  Slots containing dummy values in the header are treated as if they don&#039;t exist in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file. Each file within the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is individually compressed.  A file can be read by opening the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, seeking to the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, reading a UINT32LE for the decompressed file size, and then decompressing the data from that point onwards using standard Huffman decompression techniques.&lt;br /&gt;
&lt;br /&gt;
Note that in early games such as Keen Dreams, the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file may have another name. (Such as &amp;lt;tt&amp;gt;KDREAM.EGA&amp;lt;/tt&amp;gt; in that case.) in which case it is always the largest non-executable file.&lt;br /&gt;
&lt;br /&gt;
=== Chunks ===&lt;br /&gt;
&lt;br /&gt;
Each sub file or chunk is a separate graphic, ordered in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file in a specific way, much again like the [[AudioT Format]].  Chunks are labeled starting at 0. The game executable is hard coded for the start and finish of various chunk types. For example, Keen 4 has chunks 124-520 as sprites and will treat any chunk between these two numbers as a sprite. (Note that the game refers to chunk number, not sprite number.) The usual order of chunks is:&lt;br /&gt;
&lt;br /&gt;
 Picture table&lt;br /&gt;
 Masked picture table&lt;br /&gt;
 Sprite table&lt;br /&gt;
 Fonts&lt;br /&gt;
 Pictures (Unmasked bitmaps)&lt;br /&gt;
 Masked pictures&lt;br /&gt;
 8x8 unmasked tiles (Single chunk)&lt;br /&gt;
 8x8 masked tiles (Single chunk)&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 16x16 masked tiles&lt;br /&gt;
 32x32 unmasked tiles (Optional)&lt;br /&gt;
 32x32 masked tiles (Optional)&lt;br /&gt;
 Misc graphics (Optional)&lt;br /&gt;
 Game texts&lt;br /&gt;
 Demo files (Optional)&lt;br /&gt;
 Misc data (Optional)&lt;br /&gt;
&lt;br /&gt;
== Chunk formats ==&lt;br /&gt;
&lt;br /&gt;
When compressed each chunk consists of a dword giving the decompressed size followed by the compressed data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the first chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying picture chunks.&lt;br /&gt;
&lt;br /&gt;
Divide the decompressed size by 4 to get numpics.&lt;br /&gt;
&lt;br /&gt;
=== Masked picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the second chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying masked picture chunks. This table is often quite small.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprite table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the third chunk, the picture table is 16 * numspr bytes long, consisting of eight words for each sprite image (Width\8, Height, x offset, y offset and clipping rectangle left, top, right and bottom; all in that order.) used when displaying sprite chunks. This is what Modkeen exports as its notoriously hard to use xSPRITES.txt file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fonts ===&lt;br /&gt;
&lt;br /&gt;
Always present and always starting at the fourth chunk. (Chunk 3!) Each chunk is a single monochrome font, containing all the entries from 0-255 for that font. Each &#039;letter&#039; is stored separately and consecutively. A game will have at least one, and usually 3 fonts. The format is version two of [[EGA Font format]]&lt;br /&gt;
&lt;br /&gt;
Fonts are used in the game for game texts. They can be stretched or colored and are always transparent, meaning they look strange when not over a single-color background.&lt;br /&gt;
&lt;br /&gt;
=== Pictures (Bitmaps) ===&lt;br /&gt;
These follow game fonts. You need to know how many fonts there are before it to know how what chunk number the first picture is (3+NumFonts). In [[Catacomb 3D]] there are 2 fonts.&lt;br /&gt;
&lt;br /&gt;
Bitmaps are stored as standard [[Raw EGA data]], the size of each plane being the decompressed chunk size \ 4. In order to be displayed properly these need information from chunk 0, the picture table. Note that unlike fonts, data does not wrap, so a 4x4 sprite will consist of four planes of four bytes in size, the same as an 8x4 sprite.&lt;br /&gt;
&lt;br /&gt;
Pictures are used for things such as title screens or pictures in game texts. Most of the main menu will consist of pictures. They are also used for the wall textures in EGA FPS games like [[Catacomb 3D]], in which case the wall textures come near the end of the picture list (starting from chunk 137 in [[Catacomb 3D]]).&lt;br /&gt;
&lt;br /&gt;
The number of picture chunks is given in chunk 0, the picture table.&lt;br /&gt;
&lt;br /&gt;
=== Masked pictures (Masked bitmaps) ===&lt;br /&gt;
&lt;br /&gt;
These follow Pictures. You need to know how many fonts there are, to know how what chunk number the first Masked picture is (3+NumFonts+numpics).&lt;br /&gt;
&lt;br /&gt;
These are identical to the picture chunks in every respect, except being masked, they consist of five EGA planes, not four. Some games (E.g [[Catacomb 3D]] make great use of masked pictures, but most games have only one or two. They need information from chunk 1, the masked picture table, to be displayed correctly.&lt;br /&gt;
&lt;br /&gt;
The number of Masked pictures is given in Chunk 1.&lt;br /&gt;
&lt;br /&gt;
=== Sprites ===&lt;br /&gt;
&lt;br /&gt;
The first Sprite chunk is at 3+numfonts+numpics+numMaskedPics.&lt;br /&gt;
&lt;br /&gt;
Sprites are exactly identical to masked pictures in format except the game cannot stretch or warp them. Most games use these for enemy, player or item graphics during gameplay. They need information from chunk 2, the sprite table both to display correctly and to interact correctly, something more complex than masked pictures.&lt;br /&gt;
&lt;br /&gt;
There are usually several hundred sprite chunks, but [[Catacomb 3D]] only has 3 sprite chunks and they are used for the PaddleWar game (Skulls and Bones). The number of sprite chunks is given in chunk 2.&lt;br /&gt;
&lt;br /&gt;
=== 8x8 tiles ===&lt;br /&gt;
&lt;br /&gt;
8x8 tiles are used by most games in status windows or foe the borders of message windows in-game. (And occasionally by TED5 to display levels.) There are thus not many of them. ALL the masked or unmasked tiles are one single chunk stored as four and five plane [[Raw EGA data]] respectively. The number of 8x8 unmasked and masked tiles is hard-coded into the executable, but can be worked out by dividing the decompressed chunk size by 32 and 40 (The size of one tile&#039;s data) respectively.&lt;br /&gt;
&lt;br /&gt;
=== 16x16 and 32x32 tiles ===&lt;br /&gt;
&lt;br /&gt;
32x32 tiles are optional and rarely used. 16x16 tiles are only occasionally absent and for most games make up the bulk of graphics. There are usually several thousand entries. Both come in masked and unmasked kinds, just like 8x8 tiles.&lt;br /&gt;
&lt;br /&gt;
These chunks have notable differences. Each tile is an individual chunk and stored as four or five plane [[Raw EGA data]] with a plane size of 128 (16x16) or 512 (32x32). These chunks do NOT have a dword specifying their decompressed size as this is hard-coded into the executable as a space saving measure. (As is the start and finish of unmasked and masked tile chunks.) This can cause problems for editing programs.&lt;br /&gt;
&lt;br /&gt;
Tiles make up the bulk of 2D game levels but are seldom seen elsewhere.&lt;br /&gt;
&lt;br /&gt;
=== Misc graphics ===&lt;br /&gt;
&lt;br /&gt;
Sometimes following tile graphics are miscellaneous graphics, that cannot be handled by the other chunk types. For example, Keen 4-6 has two misc graphics files used for the &#039;COOMANDER KEEN terminator text&#039; intro. These graphics usually have unique formats that fit their function and few have been investigated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Keen 4-6 Intro Bitmaps ====&lt;br /&gt;
&lt;br /&gt;
This is the text that displays after the &#039;Ready, press any key&#039; screen at Keen startup. It is composed of a monochrome bitmap that is scrolled across the screen and distorted for special effects. When displayed it is transparent, with a special palette so it is not black-and-white. It consists of a header followed by RLE compressed monochrome data.&lt;br /&gt;
&lt;br /&gt;
 HEADER:&lt;br /&gt;
 0   2    Img height  Height of the image in pixels&lt;br /&gt;
 2   2    Img width   Width of the image in pixels&lt;br /&gt;
 4   2x   Line point  Pointers to line 1,2,3..etc of data. There will be [Img height] of&lt;br /&gt;
                      these, each 2 bytes long. The first pointer will  have the value&lt;br /&gt;
                      (2 * [Img height] + 4)&lt;br /&gt;
 +2  ?    RLE data    RLE-WM compressed data&lt;br /&gt;
&lt;br /&gt;
 DATA:&lt;br /&gt;
 0   2    Black run   Number of black pixels to write&lt;br /&gt;
 2   2    Not-blk run Number of not-black pixels to write&lt;br /&gt;
 4   2    Black run....&lt;br /&gt;
 ...&lt;br /&gt;
 ..&lt;br /&gt;
 .&lt;br /&gt;
 ?  2     End         $FFFF; end of row.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game texts ===&lt;br /&gt;
&lt;br /&gt;
Also known as ANSII chunks, these are used by the game for things like help screens, and have their own format. In the main they are simply text documents, interspersed with various commands to make things happen. Each file is divided up into a number of &#039;pages&#039; which are moved between by pressing the up/down arrows. Pages can also have action sequences (Repeated each time the page is moved to, you cannot leave a page until the sequence finishes.)&lt;br /&gt;
&lt;br /&gt;
 ^P		First command in every file. Defines a page start&lt;br /&gt;
 ^E		Ends the file&lt;br /&gt;
 ^Cx		Change font color to $x until next page or ^C command&lt;br /&gt;
 ^Gx,y,z	Display (unmasked) picture chunk z at location x,y (In pixels)&lt;br /&gt;
 ^Tx,y,z,t	Display picture chunk z at x,y for z clicks of time&lt;br /&gt;
 ^Bx,y,z,t,b	?&lt;br /&gt;
 ^Lx,y		?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Misc files ===&lt;br /&gt;
&lt;br /&gt;
The last few chunks are demo files and occasionally miscellaneous data. Demo file formats are currently unknown but can be recorded using the demo cheat. They contain the level number and difficulty followed by a series of key commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
* [[KeenWiki:ModKeen|ModKeen]] (DOS) and [[KeenWiki:LModKeen|LModKeen]] (Linux/Windows) can be used to modify graphics and text stored in EGAGRAPH.CKx for the Commander Keen [[KeenWiki:Goodbye Galaxy|Goodbye Galaxy]] trilogy.&lt;br /&gt;
* WDC (Windows) can be used to view or modify the graphics and text stored in EGAGRAPH.C3D for [[Catacomb 3D]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Commander Keen Dreams]]&lt;br /&gt;
[[Category:Dangerous Dave 3]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Graphics Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=GameMaps_Format&amp;diff=3594</id>
		<title>GameMaps Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=GameMaps_Format&amp;diff=3594"/>
		<updated>2011-09-02T01:33:11Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The GameMaps format is how the levels in a number of [[Id Software]] games is stored. The filenames and compression varies somewhat across different games but all files stored in this format were produced by the program [[TED5]] or a close analogue.&lt;br /&gt;
&lt;br /&gt;
There are three main varieties of the GameMaps format, uncompressed, [[Carmack compression||carmackized]], and  [[Huffman Compression|huffman compressed]]. Each variation has its own file naming scheme  and pattern of external\internal files.&lt;br /&gt;
&lt;br /&gt;
There are two main components to the format, the game maps proper, which contain the game level data and the map headers, which contain both the locations of the start of level data in the game maps file and the tile info for the game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Structure of uncompressed data ==&lt;br /&gt;
&lt;br /&gt;
The uncompressed format is used by several games including [[Bio Menace]] and [[Wolfenstein 3D]]. In this format map data is stored in &amp;lt;tt&amp;gt;MAPTEMP.xxx&amp;lt;tt&amp;gt; and map headers in &amp;lt;tt&amp;gt;MAPTHEAD.xxx&amp;lt;/tt&amp;gt; this is the format saved by [[TED5]] when maps are being edited and can be directly accessed and edited by this utility, allowing changes to be made to the game.&lt;br /&gt;
&lt;br /&gt;
Note that filenames differ and that Wolfenstein 3D uses &amp;lt;tt&amp;gt;GAMEMAPS.WLx&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;MAPHEAD.xxx&amp;lt;/tt&amp;gt; files to store data. The main indicator of this format being used is that in the unaltered game the map header file is external.&lt;br /&gt;
&lt;br /&gt;
Only the latest Id Software games lacked compression, when file size was no longer an issue.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Map headers ===&lt;br /&gt;
&lt;br /&gt;
 0    2    Magic word       Magic word for [[RLEW compression]]&lt;br /&gt;
 2    400  Level ptr        100 4-byte pointers to start of level 0-99 data in game maps file&lt;br /&gt;
 402  ???  Tileinfo         Tileinfo data&lt;br /&gt;
&lt;br /&gt;
The map header file is of varying length and contains three main types of data. The first is the magic word or flag used for RLEW compression, it is always $ABCD. The second is 100 level pointers which give the location of the start of level data in the game maps file, relative to the start of that file. A value of 0 indicates no level. The third is the tileinfo data, tile properties for each tile used in level creation. (These are masked and unmasked and either 8x8, 16x16 or 32x32)&lt;br /&gt;
&lt;br /&gt;
Many programs treat the tileinfo as a separate file from the maphead and it is possible to modify a game in this manner. Indeed, some games, such as Wolfenstein 3D do not have any tileinfo data at all in the map header file (Giving a total file length of 402 bytes.) However TED5 works with any tileinfo data in the maphead.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game maps ===&lt;br /&gt;
&lt;br /&gt;
The game maps file consists of the string &#039;TED5v1.0.&#039; and a number of RLEW compressed chunks of varying length. Each level in GameMaps will have from two to four chunks (usually four), depending on game, with all levels in a given game having the same number of chunks. These are the level header and 1-3 planes (Foreground, background and sprite or info.) The chunks are in no particular order and it is possible to read through the entire file decompressing chunks as they&#039;re found.&lt;br /&gt;
&lt;br /&gt;
Chunks are ordered by the map header file, which will point to the level header chunks which in turn contain pointers to the other chunks used by that level. It is possible the string at the start of the file is to avoid the possibility of a level header at the start of the file which would be read as not existing.&lt;br /&gt;
&lt;br /&gt;
All data in game maps file is in the form of words (Or in the case of pointers, dwords.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Level headers ===&lt;br /&gt;
&lt;br /&gt;
The header for each level that is pointed to by MAPHEAD is 42 bytes long and RLEW compressed, though this is difficult to see since the data is so short and nonrepetitive. For the offsets to level planes a value of 0 indicates the plane does not exist.&lt;br /&gt;
&lt;br /&gt;
Plane 1 is background using unmasked tiles, plane 2 is foreground and uses masked tiles. Plane 3 is sprite or info. Levels must contain c background plane and usually an infoplane.&lt;br /&gt;
&lt;br /&gt;
 0   4    Offset in GAMEMAPS to beginning of compressed plane 0 data&lt;br /&gt;
 4   4    Offset in GAMEMAPS to beginning of compressed plane 1 data&lt;br /&gt;
 8   4    Offset in GAMEMAPS to beginning of compressed plane 2 data&lt;br /&gt;
 12  2    Length of compressed plane 0 data (in bytes)&lt;br /&gt;
 14  2    Length of compressed plane 1 data (in bytes)&lt;br /&gt;
 16  2    Length of compressed plane 2 data (in bytes)&lt;br /&gt;
 18  2    Width of level (in tiles)&lt;br /&gt;
 20  2    Height of level (in tiles)&lt;br /&gt;
 22  16   Internal name for level (used only by editor, not displayed in-game. null-terminated)&lt;br /&gt;
&lt;br /&gt;
== Carmack compression ==&lt;br /&gt;
&lt;br /&gt;
[[Carmack compression]] is the method used to compress later Id Software games, when file size was an issue. It is the most efficient and complex compression method and was created specifically to work with the word structure of the game maps file. The compression is detailed on its [[Carmack compression|own page.]]&lt;br /&gt;
&lt;br /&gt;
Carmackized game maps files are external &amp;lt;tt&amp;gt;GAMEMAPS.xxx&amp;lt;/tt&amp;gt; files and the map header is stored internally in the executable. The map header must be extracted and the game maps decompressed before TED5 can access them. TED5 itself can produce carmackized files and external &amp;lt;tt&amp;gt;MAPHEAD.xxx&amp;lt;/tt&amp;gt; files. Carmackization does not replace the RLEW compression used in uncompressed data, but compresses this data, that is, the data is doubly compressed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Huffman compression ==&lt;br /&gt;
&lt;br /&gt;
Huffman compression was used by earlier versions of TED5 (possibly not TED5 at all.) before carmackization was created. It uses the same method to compress its data as is used by Id Software games to compress their graphics and sounds. Again this compression method works with RLEW compressed data and has its [[Huffman Compression|own page.]]&lt;br /&gt;
&lt;br /&gt;
Huffman compression is easily detected since it works on the bit level and thus disrupts the word structure of the game data. This is easily seen in a hex editor. Compressed data will not contain the string $00 $00 or indeed even $00 very often (In contrast even carmackized data contains both strings hundreds of times.)&lt;br /&gt;
&lt;br /&gt;
There will be two internal files for this format, the map header and the huffman dictionary (which is always the first dictionary in the executable.) The map header format is also slightly different, being 502 bytes long, the extra 100 bytes being the length of the compressed level headers in the game maps data (These can be ignored when decompressing since huffman data can be read until the decompressed level header&#039;s fixed size is reached.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Location of internal files ==&lt;br /&gt;
&lt;br /&gt;
Game maps are always external, but in the case of compression the map header file is stored internally in the executable. Executables are themselves compressed wither with LZEXE or PKLite. Once decompressed it is a trivial task to find the map header file as it will start with the word $ABCD For level editing purposes only the first 402 (or 502) bytes of the file needs to be extracted, though it is possible to read the maphead file to calculate its length.&lt;br /&gt;
&lt;br /&gt;
The following addresses are in the locations in the decompressed executables for the start of the Map header files. Values are different for different versions.&lt;br /&gt;
&lt;br /&gt;
TODO: Add all known versions of all games.&lt;br /&gt;
&lt;br /&gt;
External files&lt;br /&gt;
 Biomenace&lt;br /&gt;
 Blake Stone 2: Planet Strike&lt;br /&gt;
 Corridor 7 Demo&lt;br /&gt;
 Noahs Ark 3D&lt;br /&gt;
 Operation Body Count&lt;br /&gt;
 Spear of Destiny&lt;br /&gt;
 Wolfenstein 3D&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Internal files:&lt;br /&gt;
  Catacomb 3-D: $1C570 from start of file CAT3D.EXE (after file is UNLZEXE)&lt;br /&gt;
  Catacomb 4 Abyss: $1C510 from start of file CATABYSS.EXE (after file is UNLZEXE)&lt;br /&gt;
  Catacomb 5 Apocalypse&lt;br /&gt;
  Catacomb 6 Armageddon&lt;br /&gt;
  Corridor 7 CD (): $30D50 from start of file CORR7CD.EXE (file is not compressed)&lt;br /&gt;
  Corridor 7 Floppy (): $24BF0 from start of file C7.EXE (file is not compressed)&lt;br /&gt;
  Keen 4 (Special Demo): (file is PKLite compressed)&lt;br /&gt;
  Keen 4 (1.4): $24830&lt;br /&gt;
  Keen 5 (1.4): $25990&lt;br /&gt;
  Keen 6 (1.4): $25080&lt;br /&gt;
 (Keen D (1.13): $1FA50)&lt;br /&gt;
&lt;br /&gt;
== Utilities ==&lt;br /&gt;
&lt;br /&gt;
[[TED5]] This program can edit the &amp;lt;tt&amp;gt;GAMEMAPS&amp;lt;/tt&amp;gt; format of any games that use it. It is the original editor used to crate these files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
This format was reverse engineered by Andrew Durdin (adurdin).&lt;br /&gt;
&lt;br /&gt;
The format is used by other games as well, including [[Bio Menace]], [[Blake Stone]], [[Catacomb 3D]], [[Catacomb Abyss]], [[Corridor 7]], [[Dangerous Dave 3]], [[Dave Goes Nutz]], [[Noah&#039;s Ark 3D]], [[Operation Body Count]], [[Spear of Destiny]], and [[Wolfenstein 3D]].&lt;br /&gt;
&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Map Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=GameMaps_Format&amp;diff=3593</id>
		<title>GameMaps Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=GameMaps_Format&amp;diff=3593"/>
		<updated>2011-09-02T01:32:06Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* Location of internal files */ Catacomb 3D and Catacomb Abyss&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The GameMaps format is how the levels in a number of [[Id Software]] games is stored. The filenames and compression varies somewhat across different games but all files stored in this format were produced by the program [[TED5]] or a close analogue.&lt;br /&gt;
&lt;br /&gt;
There are three main varieties of the GameMaps format, uncompressed, [[Carmack compression||carmackized]], and  [[Huffman Compression|huffman compressed]]. Each variation has its own file naming scheme  and pattern of external\internal files.&lt;br /&gt;
&lt;br /&gt;
There are two main components to the format, the game maps proper, which contain the game level data and the map headers, which contain both the locations of the start of level data in the game maps file and the tile info for the game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Structure of uncompressed data ==&lt;br /&gt;
&lt;br /&gt;
The uncompressed format is used by several games including [[Bio Menace]] and [[Wolfenstein 3D]]. In this format map data is stored in &amp;lt;tt&amp;gt;MAPTEMP.xxx&amp;lt;tt&amp;gt; and map headers in &amp;lt;tt&amp;gt;MAPTHEAD.xxx&amp;lt;/tt&amp;gt; this is the format saved by [[TED5]] when maps are being edited and can be directly accessed and edited by this utility, allowing changes to be made to the game.&lt;br /&gt;
&lt;br /&gt;
Note that filenames differ and that Wolfenstein 3D uses &amp;lt;tt&amp;gt;GAMEMAPS.WLx&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;MAPHEAD.xxx&amp;lt;/tt&amp;gt; files to store data. The main indicator of this format being used is that in the unaltered game the map header file is external.&lt;br /&gt;
&lt;br /&gt;
Only the latest Id Software games lacked compression, when file size was no longer an issue.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Map headers ===&lt;br /&gt;
&lt;br /&gt;
 0    2    Magic word       Magic word for [[RLEW compression]]&lt;br /&gt;
 2    400  Level ptr        100 4-byte pointers to start of level 0-99 data in game maps file&lt;br /&gt;
 402  ???  Tileinfo         Tileinfo data&lt;br /&gt;
&lt;br /&gt;
The map header file is of varying length and contains three main types of data. The first is the magic word or flag used for RLEW compression, it is always $ABCD. The second is 100 level pointers which give the location of the start of level data in the game maps file, relative to the start of that file. A value of 0 indicates no level. The third is the tileinfo data, tile properties for each tile used in level creation. (These are masked and unmasked and either 8x8, 16x16 or 32x32)&lt;br /&gt;
&lt;br /&gt;
Many programs treat the tileinfo as a separate file from the maphead and it is possible to modify a game in this manner. Indeed, some games, such as Wolfenstein 3D do not have any tileinfo data at all in the map header file (Giving a total file length of 402 bytes.) However TED5 works with any tileinfo data in the maphead.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game maps ===&lt;br /&gt;
&lt;br /&gt;
The game maps file consists of the string &#039;TED5v1.0.&#039; and a number of RLEW compressed chunks of varying length. Each level in GameMaps will have from two to four chunks (usually four), depending on game, with all levels in a given game having the same number of chunks. These are the level header and 1-3 planes (Foreground, background and sprite or info.) The chunks are in no particular order and it is possible to read through the entire file decompressing chunks as they&#039;re found.&lt;br /&gt;
&lt;br /&gt;
Chunks are ordered by the map header file, which will point to the level header chunks which in turn contain pointers to the other chunks used by that level. It is possible the string at the start of the file is to avoid the possibility of a level header at the start of the file which would be read as not existing.&lt;br /&gt;
&lt;br /&gt;
All data in game maps file is in the form of words (Or in the case of pointers, dwords.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Level headers ===&lt;br /&gt;
&lt;br /&gt;
The header for each level that is pointed to by MAPHEAD is 42 bytes long and RLEW compressed, though this is difficult to see since the data is so short and nonrepetitive. For the offsets to level planes a value of 0 indicates the plane does not exist.&lt;br /&gt;
&lt;br /&gt;
Plane 1 is background using unmasked tiles, plane 2 is foreground and uses masked tiles. Plane 3 is sprite or info. Levels must contain c background plane and usually an infoplane.&lt;br /&gt;
&lt;br /&gt;
 0   4    Offset in GAMEMAPS to beginning of compressed plane 0 data&lt;br /&gt;
 4   4    Offset in GAMEMAPS to beginning of compressed plane 1 data&lt;br /&gt;
 8   4    Offset in GAMEMAPS to beginning of compressed plane 2 data&lt;br /&gt;
 12  2    Length of compressed plane 0 data (in bytes)&lt;br /&gt;
 14  2    Length of compressed plane 1 data (in bytes)&lt;br /&gt;
 16  2    Length of compressed plane 2 data (in bytes)&lt;br /&gt;
 18  2    Width of level (in tiles)&lt;br /&gt;
 20  2    Height of level (in tiles)&lt;br /&gt;
 22  16   Internal name for level (used only by editor, not displayed in-game. null-terminated)&lt;br /&gt;
&lt;br /&gt;
== Carmack compression ==&lt;br /&gt;
&lt;br /&gt;
[[Carmack compression]] is the method used to compress later Id Software games, when file size was an issue. It is the most efficient and complex compression method and was created specifically to work with the word structure of the game maps file. The compression is detailed on its [[Carmack compression|own page.]]&lt;br /&gt;
&lt;br /&gt;
Carmackized game maps files are external &amp;lt;tt&amp;gt;GAMEMAPS.xxx&amp;lt;/tt&amp;gt; files and the map header is stored internally in the executable. The map header must be extracted and the game maps decompressed before TED5 can access them. TED5 itself can produce carmackized files and external &amp;lt;tt&amp;gt;MAPHEAD.xxx&amp;lt;/tt&amp;gt; files. Carmackization does not replace the RLEW compression used in uncompressed data, but compresses this data, that is, the data is doubly compressed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Huffman compression ==&lt;br /&gt;
&lt;br /&gt;
Huffman compression was used by earlier versions of TED5 (possibly not TED5 at all.) before carmackization was created. It uses the same method to compress its data as is used by Id Software games to compress their graphics and sounds. Again this compression method works with RLEW compressed data and has its [[Huffman Compression|own page.]]&lt;br /&gt;
&lt;br /&gt;
Huffman compression is easily detected since it works on the bit level and thus disrupts the word structure of the game data. This is easily seen in a hex editor. Compressed data will not contain the string $00 $00 or indeed even $00 very often (In contrast even carmackized data contains both strings hundreds of times.)&lt;br /&gt;
&lt;br /&gt;
There will be two internal files for this format, the map header and the huffman dictionary (which is always the first dictionary in the executable.) The map header format is also slightly different, being 502 bytes long, the extra 100 bytes being the length of the compressed level headers in the game maps data (These can be ignored when decompressing since huffman data can be read until the decompressed level header&#039;s fixed size is reached.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Location of internal files ==&lt;br /&gt;
&lt;br /&gt;
Game maps are always external, but in the case of compression the map header file is stored internally in the executable. Executables are themselves compressed wither with LZEXE or PKLite. Once decompressed it is a trivial task to find the map header file as it will start with the word $ABCD For level editing purposes only the first 402 (or 502) bytes of the file needs to be extracted, though it is possible to read the maphead file to calculate its length.&lt;br /&gt;
&lt;br /&gt;
The following addresses are in the locations in the decompressed executables for the start of the Map header files. Values are different for different versions.&lt;br /&gt;
&lt;br /&gt;
TODO: Add all known versions of all games.&lt;br /&gt;
&lt;br /&gt;
External files&lt;br /&gt;
 Biomenace&lt;br /&gt;
 Blake Stone 2: Planet Strike&lt;br /&gt;
 Corridor 7 Demo&lt;br /&gt;
 Noahs Ark 3D&lt;br /&gt;
 Operation Body Count&lt;br /&gt;
 Spear of Destiny&lt;br /&gt;
 Wolfenstein 3D&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Internal files:&lt;br /&gt;
  Catacomb 3-D: $1C570 from start of file CAT3D.EXE (after file is UNLZEXE)&lt;br /&gt;
  Catacomb 4 Abyss: $1C510 from start of file CATABYSS.EXE (after file is UNLZEXE)&lt;br /&gt;
  Catacomb 5 Apocalypse&lt;br /&gt;
  Catacomb 6 Armageddon&lt;br /&gt;
  Corridor 7 CD (): $30D50 from start of file CORR7CD.EXE (file is not compressed)&lt;br /&gt;
  Corridor 7 Floppy (): $24BF0 from start of file C7.EXE (file is not compressed)&lt;br /&gt;
  Keen 4 (Special Demo): (file is PKLite compressed)&lt;br /&gt;
  Keen 4 (1.4): $24830&lt;br /&gt;
  Keen 5 (1.4): $25990&lt;br /&gt;
  Keen 6 (1.4): $25080&lt;br /&gt;
 (Keen D (1.13): $1FA50)&lt;br /&gt;
&lt;br /&gt;
== Utilities ==&lt;br /&gt;
&lt;br /&gt;
[[TED5]] This program can edit the &amp;lt;tt&amp;gt;GAMEMAPS&amp;lt;/tt&amp;gt; format of any games that use it. It is the original editor used to crate these files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
This format was reverse engineered by Andrew Durdin (adurdin).&lt;br /&gt;
&lt;br /&gt;
The format is used by other games as well, including [[Bio Menace]], [[Blake Stone]], [[Catacomb 3D]], [[Corridor 7]], [[Dangerous Dave 3]], [[Dave Goes Nutz]], [[Noah&#039;s Ark 3D]], [[Operation Body Count]], [[Spear of Destiny]], and [[Wolfenstein 3D]].&lt;br /&gt;
&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Map Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3592</id>
		<title>EGAGraph Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3592"/>
		<updated>2011-09-01T07:47:01Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* Chunks */ 16x16 masked tiles was listed as unmasked.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;EGAGraph&#039;&#039;&#039;, short for &#039;EGA graphics library&#039; is the format used to store graphics, demos, fonts, game texts and more in many early [[:Category:Id Software|id Software]] games.&lt;br /&gt;
&lt;br /&gt;
The basic format is that of a number of [[Huffman Compression]] compressed sub-files (Chunks) stored in a similar manner to the [[AudioT Format]]. Like this format it has three main files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt;and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is notable that while the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; are stored in the game executable, they need to be extracted for [[TED5]] to edit levels.&lt;br /&gt;
&lt;br /&gt;
This article may contain errors as some formats have not been worked out completely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= File formats =&lt;br /&gt;
&lt;br /&gt;
== EGA Head (EGAHEAD.xxx) ==&lt;br /&gt;
There are two versions of this format. The first version, used in [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], is an array of 4-byte little-endian values. The second version, used in all later EGA games, is an array of 3-byte unsigned little-endian values.&lt;br /&gt;
&lt;br /&gt;
This header file may be present as an external file (eg. [[Bio Menace]]), or it may be included in the EXE file (eg. [[Catacomb 3D]]). The last entry in the header is always the size of the EGAGRAPH.xxx file, and the first entry in the header is always 00 00 00. To find the end, you can search for filesize(EGAGRAPH.xxx) as a 3-byte (little-endian) value in the EXE. Then to find the start, go back 3 bytes at a time until you get to 00 000 00. Or use the fact that entries always get smaller as you go back, unless the entry is $FFFFFF. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] v1.00 &amp;lt;tt&amp;gt;EGAHEAD.C3D&amp;lt;/tt&amp;gt; is at $1BFD0 from the start of the decompressed ([[unlzexe]]) EXE file, and is 1437 bytes long, or 479 3-byte entries (for 478 chunks). It is then followed by 3 zero bytes (padding to multiple of 16?) 00 00 00, then the &amp;lt;tt&amp;gt;MAPHEAD.C3D&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
This header file stores the offsets (relative to the start of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file) for each sub file.  The format is trivial, in that the header file is simply an array of 3 or 4 byte variables.  (Each variable is a &amp;quot;slot&amp;quot;, as the game refers to files by index.) Most games use the more compact 3-byte variables, since the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is never larger than $FFFFFF. However games based on older engines, notably [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], use 4-byte vales as these are easier to deal with.&lt;br /&gt;
&lt;br /&gt;
It is important to note that not every &#039;slot&#039; will be in use. Tiles especially if blank (All black) will be considered &#039;empty&#039; and not worth adding to the file. (A blank 16x16 tile takes up 12 bytes of space if compressed, and there can be hundreds.) There are two ways of dealing with this; by default the games set all empty slot headers to -1, but many programs compress the graphics anyway and use a normal header value for them.&lt;br /&gt;
&lt;br /&gt;
The last offset in the file will be an offset to the end of the main &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file.  (So this should be ignored when reading the file to prevent a zero-byte file appearing last.) The total size of the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; divided by 3 (Or 4) will also give the number of &#039;slots&#039; the game uses. This varies, but is usually about 10,000.&lt;br /&gt;
&lt;br /&gt;
Unlike [[AudioT Format]] files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; is always compressed. However the header and dictionary may be external (E.g [[Bio Menace]])&lt;br /&gt;
&lt;br /&gt;
== Dictionary (EGADICT.xxx) ==&lt;br /&gt;
&lt;br /&gt;
The same [[Huffman Compression]] scheme used elsewhere in the [[Commander Keen]] series is used.  When reading compressed chunks out of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, the first four bytes located at the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; offset are a UINT32LE specifying the file&#039;s decompressed size (which is required for the decompression algorithm.)  The compressed data then follows, EXCEPT for 16x16 masked and unmasked tiles. Since these all have a similar decompressed size (128 bytes for unmasked, 256 bytes for masked) it is a waste of space to include these (Since tiles make up the bulk of graphics slots.) The decompressed size is hard coded, as are the start and finish of the unmasked and masked tile slots.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; file is not often obvious, usually being embedded in the main exe file. It is possible to locate it by looking for the string &amp;lt;tt&amp;gt;$FD $01 $00 $00 $00 $00&amp;lt;/tt&amp;gt;, which appears at the end of nearly all Huffman dictionaries. They are the last 6 bytes out of 1024 (256*2*2), so add 6 and subtract 1024 to get the start (pointer to the head node).&lt;br /&gt;
&lt;br /&gt;
Executables usually contain two or more dictionaries, but the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; is usually &#039;&#039;&#039;the second one&#039;&#039;&#039;, except in the case of early games like Keen Dreams, where it is the first of THREE. (A simple check of whether it decompresses the data sensibly works.)&lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] &amp;lt;tt&amp;gt;EGADICT.C3D&amp;lt;/tt&amp;gt; is at offset $24464 from the start of the decompressed CAT3D.EXE, which is the second Huffman dictionary and comes immediately after the first Huffman Dictionary.&lt;br /&gt;
&lt;br /&gt;
== Main file (EGAGRAPH.xxx) ==&lt;br /&gt;
&lt;br /&gt;
This file is simply an array of data files.  Each file starts at the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, and as there are no filenames each file is referred to by its index/slot number.  Slots containing dummy values in the header are treated as if they don&#039;t exist in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file. Each file within the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is individually compressed.  A file can be read by opening the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, seeking to the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, reading a UINT32LE for the decompressed file size, and then decompressing the data from that point onwards using standard Huffman decompression techniques.&lt;br /&gt;
&lt;br /&gt;
Note that in early games such as Keen Dreams, the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file may have another name. (Such as &amp;lt;tt&amp;gt;KDREAM.EGA&amp;lt;/tt&amp;gt; in that case.) in which case it is always the largest non-executable file.&lt;br /&gt;
&lt;br /&gt;
=== Chunks ===&lt;br /&gt;
&lt;br /&gt;
Each sub file or chunk is a separate graphic, ordered in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file in a specific way, much again like the [[AudioT Format]].  Chunks are labeled starting at 0. The game executable is hard coded for the start and finish of various chunk types. For example, Keen 4 has chunks 124-520 as sprites and will treat any chunk between these two numbers as a sprite. (Note that the game refers to chunk number, not sprite number.) The usual order of chunks is:&lt;br /&gt;
&lt;br /&gt;
 Picture table&lt;br /&gt;
 Masked picture table&lt;br /&gt;
 Sprite table&lt;br /&gt;
 Fonts&lt;br /&gt;
 Pictures (Unmasked bitmaps)&lt;br /&gt;
 Masked pictures&lt;br /&gt;
 8x8 unmasked tiles (Single chunk)&lt;br /&gt;
 8x8 masked tiles (Single chunk)&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 16x16 masked tiles&lt;br /&gt;
 32x32 unmasked tiles (Optional)&lt;br /&gt;
 32x32 masked tiles (Optional)&lt;br /&gt;
 Misc graphics (Optional)&lt;br /&gt;
 Game texts&lt;br /&gt;
 Demo files (Optional)&lt;br /&gt;
 Misc data (Optional)&lt;br /&gt;
&lt;br /&gt;
== Chunk formats ==&lt;br /&gt;
&lt;br /&gt;
When compressed each chunk consists of a dword giving the decompressed size followed by the compressed data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the first chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying picture chunks.&lt;br /&gt;
&lt;br /&gt;
Divide the decompressed size by 4 to get numpics.&lt;br /&gt;
&lt;br /&gt;
=== Masked picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the second chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying masked picture chunks. This table is often quite small.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprite table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the third chunk, the picture table is 16 * numspr bytes long, consisting of eight words for each sprite image (Width\8, Height, x offset, y offset and clipping rectangle left, top, right and bottom; all in that order.) used when displaying sprite chunks. This is what Modkeen exports as its notoriously hard to use xSPRITES.txt file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fonts ===&lt;br /&gt;
&lt;br /&gt;
Always present and always starting at the fourth chunk. (Chunk 3!) Each chunk is a single monochrome font, containing all the entries from 0-255 for that font. Each &#039;letter&#039; is stored separately and consecutively. A game will have at least one, and usually 3 fonts. The format is version two of [[EGA Font format]]&lt;br /&gt;
&lt;br /&gt;
Fonts are used in the game for game texts. They can be stretched or colored and are always transparent, meaning they look strange when not over a single-color background.&lt;br /&gt;
&lt;br /&gt;
=== Pictures (Bitmaps) ===&lt;br /&gt;
These follow game fonts. You need to know how many fonts there are before it to know how what chunk number the first picture is (3+NumFonts). In [[Catacomb 3D]] there are 2 fonts.&lt;br /&gt;
&lt;br /&gt;
Bitmaps are stored as standard [[Raw EGA data]], the size of each plane being the decompressed chunk size \ 4. In order to be displayed properly these need information from chunk 0, the picture table. Note that unlike fonts, data does not wrap, so a 4x4 sprite will consist of four planes of four bytes in size, the same as an 8x4 sprite.&lt;br /&gt;
&lt;br /&gt;
Pictures are used for things such as title screens or pictures in game texts. Most of the main menu will consist of pictures. They are also used for the wall textures in EGA FPS games like [[Catacomb 3D]], in which case the wall textures come near the end of the picture list (starting from chunk 137 in [[Catacomb 3D]]).&lt;br /&gt;
&lt;br /&gt;
The number of picture chunks is given in chunk 0, the picture table.&lt;br /&gt;
&lt;br /&gt;
=== Masked pictures (Masked bitmaps) ===&lt;br /&gt;
&lt;br /&gt;
These follow Pictures. You need to know how many fonts there are, to know how what chunk number the first Masked picture is (3+NumFonts+numpics).&lt;br /&gt;
&lt;br /&gt;
These are identical to the picture chunks in every respect, except being masked, they consist of five EGA planes, not four. Some games (E.g [[Catacomb 3D]] make great use of masked pictures, but most games have only one or two. They need information from chunk 1, the masked picture table, to be displayed correctly.&lt;br /&gt;
&lt;br /&gt;
The number of Masked pictures is given in Chunk 1.&lt;br /&gt;
&lt;br /&gt;
=== Sprites ===&lt;br /&gt;
&lt;br /&gt;
The first Sprite chunk is at 3+numfonts+numpics+numMaskedPics.&lt;br /&gt;
&lt;br /&gt;
Sprites are exactly identical to masked pictures in format except the game cannot stretch or warp them. Most games use these for enemy, player or item graphics during gameplay. They need information from chunk 2, the sprite table both to display correctly and to interact correctly, something more complex than masked pictures.&lt;br /&gt;
&lt;br /&gt;
There are usually several hundred sprite chunks, but [[Catacomb 3D]] only has 3 sprite chunks and they are used for the PaddleWar game (Skulls and Bones). The number of sprite chunks is given in chunk 2.&lt;br /&gt;
&lt;br /&gt;
=== 8x8 tiles ===&lt;br /&gt;
&lt;br /&gt;
8x8 tiles are used by most games in status windows or foe the borders of message windows in-game. (And occasionally by TED5 to display levels.) There are thus not many of them. ALL the masked or unmasked tiles are one single chunk stored as four and five plane [[Raw EGA data]] respectively. The number of 8x8 unmasked and masked tiles is hard-coded into the executable, but can be worked out by dividing the decompressed chunk size by 32 and 40 (The size of one tile&#039;s data) respectively.&lt;br /&gt;
&lt;br /&gt;
=== 16x16 and 32x32 tiles ===&lt;br /&gt;
&lt;br /&gt;
32x32 tiles are optional and rarely used. 16x16 tiles are only occasionally absent and for most games make up the bulk of graphics. There are usually several thousand entries. Both come in masked and unmasked kinds, just like 8x8 tiles.&lt;br /&gt;
&lt;br /&gt;
These chunks have notable differences. Each tile is an individual chunk and stored as four or five plane [[Raw EGA data]] with a plane size of 128 (16x16) or 512 (32x32). These chunks do NOT have a dword specifying their decompressed size as this is hard-coded into the executable as a space saving measure. (As is the start and finish of unmasked and masked tile chunks.) This can cause problems for editing programs.&lt;br /&gt;
&lt;br /&gt;
Tiles make up the bulk of 2D game levels but are seldom seen elsewhere.&lt;br /&gt;
&lt;br /&gt;
=== Misc graphics ===&lt;br /&gt;
&lt;br /&gt;
Sometimes following tile graphics are miscellaneous graphics, that cannot be handled by the other chunk types. For example, Keen 4-6 has two misc graphics files used for the &#039;COOMANDER KEEN terminator text&#039; intro. These graphics usually have unique formats that fit their function and few have been investigated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Keen 4-6 Intro Bitmaps ====&lt;br /&gt;
&lt;br /&gt;
This is the text that displays after the &#039;Ready, press any key&#039; screen at Keen startup. It is composed of a monochrome bitmap that is scrolled across the screen and distorted for special effects. When displayed it is transparent, with a special palette so it is not black-and-white. It consists of a header followed by RLE compressed monochrome data.&lt;br /&gt;
&lt;br /&gt;
 HEADER:&lt;br /&gt;
 0   2    Img height  Height of the image in pixels&lt;br /&gt;
 2   2    Img width   Width of the image in pixels&lt;br /&gt;
 4   2x   Line point  Pointers to line 1,2,3..etc of data. There will be [Img height] of&lt;br /&gt;
                      these, each 2 bytes long. The first pointer will  have the value&lt;br /&gt;
                      (2 * [Img height] + 4)&lt;br /&gt;
 +2  ?    RLE data    RLE-WM compressed data&lt;br /&gt;
&lt;br /&gt;
 DATA:&lt;br /&gt;
 0   2    Black run   Number of black pixels to write&lt;br /&gt;
 2   2    Not-blk run Number of not-black pixels to write&lt;br /&gt;
 4   2    Black run....&lt;br /&gt;
 ...&lt;br /&gt;
 ..&lt;br /&gt;
 .&lt;br /&gt;
 ?  2     End         $FFFF; end of row.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game texts ===&lt;br /&gt;
&lt;br /&gt;
Also known as ANSII chunks, these are used by the game for things like help screens, and have their own format. In the main they are simply text documents, interspersed with various commands to make things happen. Each file is divided up into a number of &#039;pages&#039; which are moved between by pressing the up/down arrows. Pages can also have action sequences (Repeated each time the page is moved to, you cannot leave a page until the sequence finishes.)&lt;br /&gt;
&lt;br /&gt;
 ^P		First command in every file. Defines a page start&lt;br /&gt;
 ^E		Ends the file&lt;br /&gt;
 ^Cx		Change font color to $x until next page or ^C command&lt;br /&gt;
 ^Gx,y,z	Display (unmasked) picture chunk z at location x,y (In pixels)&lt;br /&gt;
 ^Tx,y,z,t	Display picture chunk z at x,y for z clicks of time&lt;br /&gt;
 ^Bx,y,z,t,b	?&lt;br /&gt;
 ^Lx,y		?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Misc files ===&lt;br /&gt;
&lt;br /&gt;
The last few chunks are demo files and occasionally miscellaneous data. Demo file formats are currently unknown but can be recorded using the demo cheat. They contain the level number and difficulty followed by a series of key commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
* [[KeenWiki:ModKeen|ModKeen]] (DOS) and [[KeenWiki:LModKeen|LModKeen]] (Linux/Windows) can be used to modify graphics and text stored in EGAGRAPH.CKx for the Commander Keen [[KeenWiki:Goodbye Galaxy|Goodbye Galaxy]] trilogy.&lt;br /&gt;
* WDC (Windows) can be used to view or modify the graphics and text stored in EGAGRAPH.C3D for [[Catacomb 3D]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Commander Keen Dreams]]&lt;br /&gt;
[[Category:Dangerous Dave 3]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Graphics Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3591</id>
		<title>EGAGraph Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3591"/>
		<updated>2011-09-01T07:43:56Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* Dictionary (EGADICT.xxx) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;EGAGraph&#039;&#039;&#039;, short for &#039;EGA graphics library&#039; is the format used to store graphics, demos, fonts, game texts and more in many early [[:Category:Id Software|id Software]] games.&lt;br /&gt;
&lt;br /&gt;
The basic format is that of a number of [[Huffman Compression]] compressed sub-files (Chunks) stored in a similar manner to the [[AudioT Format]]. Like this format it has three main files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt;and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is notable that while the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; are stored in the game executable, they need to be extracted for [[TED5]] to edit levels.&lt;br /&gt;
&lt;br /&gt;
This article may contain errors as some formats have not been worked out completely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= File formats =&lt;br /&gt;
&lt;br /&gt;
== EGA Head (EGAHEAD.xxx) ==&lt;br /&gt;
There are two versions of this format. The first version, used in [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], is an array of 4-byte little-endian values. The second version, used in all later EGA games, is an array of 3-byte unsigned little-endian values.&lt;br /&gt;
&lt;br /&gt;
This header file may be present as an external file (eg. [[Bio Menace]]), or it may be included in the EXE file (eg. [[Catacomb 3D]]). The last entry in the header is always the size of the EGAGRAPH.xxx file, and the first entry in the header is always 00 00 00. To find the end, you can search for filesize(EGAGRAPH.xxx) as a 3-byte (little-endian) value in the EXE. Then to find the start, go back 3 bytes at a time until you get to 00 000 00. Or use the fact that entries always get smaller as you go back, unless the entry is $FFFFFF. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] v1.00 &amp;lt;tt&amp;gt;EGAHEAD.C3D&amp;lt;/tt&amp;gt; is at $1BFD0 from the start of the decompressed ([[unlzexe]]) EXE file, and is 1437 bytes long, or 479 3-byte entries (for 478 chunks). It is then followed by 3 zero bytes (padding to multiple of 16?) 00 00 00, then the &amp;lt;tt&amp;gt;MAPHEAD.C3D&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
This header file stores the offsets (relative to the start of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file) for each sub file.  The format is trivial, in that the header file is simply an array of 3 or 4 byte variables.  (Each variable is a &amp;quot;slot&amp;quot;, as the game refers to files by index.) Most games use the more compact 3-byte variables, since the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is never larger than $FFFFFF. However games based on older engines, notably [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], use 4-byte vales as these are easier to deal with.&lt;br /&gt;
&lt;br /&gt;
It is important to note that not every &#039;slot&#039; will be in use. Tiles especially if blank (All black) will be considered &#039;empty&#039; and not worth adding to the file. (A blank 16x16 tile takes up 12 bytes of space if compressed, and there can be hundreds.) There are two ways of dealing with this; by default the games set all empty slot headers to -1, but many programs compress the graphics anyway and use a normal header value for them.&lt;br /&gt;
&lt;br /&gt;
The last offset in the file will be an offset to the end of the main &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file.  (So this should be ignored when reading the file to prevent a zero-byte file appearing last.) The total size of the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; divided by 3 (Or 4) will also give the number of &#039;slots&#039; the game uses. This varies, but is usually about 10,000.&lt;br /&gt;
&lt;br /&gt;
Unlike [[AudioT Format]] files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; is always compressed. However the header and dictionary may be external (E.g [[Bio Menace]])&lt;br /&gt;
&lt;br /&gt;
== Dictionary (EGADICT.xxx) ==&lt;br /&gt;
&lt;br /&gt;
The same [[Huffman Compression]] scheme used elsewhere in the [[Commander Keen]] series is used.  When reading compressed chunks out of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, the first four bytes located at the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; offset are a UINT32LE specifying the file&#039;s decompressed size (which is required for the decompression algorithm.)  The compressed data then follows, EXCEPT for 16x16 masked and unmasked tiles. Since these all have a similar decompressed size (128 bytes for unmasked, 256 bytes for masked) it is a waste of space to include these (Since tiles make up the bulk of graphics slots.) The decompressed size is hard coded, as are the start and finish of the unmasked and masked tile slots.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; file is not often obvious, usually being embedded in the main exe file. It is possible to locate it by looking for the string &amp;lt;tt&amp;gt;$FD $01 $00 $00 $00 $00&amp;lt;/tt&amp;gt;, which appears at the end of nearly all Huffman dictionaries. They are the last 6 bytes out of 1024 (256*2*2), so add 6 and subtract 1024 to get the start (pointer to the head node).&lt;br /&gt;
&lt;br /&gt;
Executables usually contain two or more dictionaries, but the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; is usually &#039;&#039;&#039;the second one&#039;&#039;&#039;, except in the case of early games like Keen Dreams, where it is the first of THREE. (A simple check of whether it decompresses the data sensibly works.)&lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] &amp;lt;tt&amp;gt;EGADICT.C3D&amp;lt;/tt&amp;gt; is at offset $24464 from the start of the decompressed CAT3D.EXE, which is the second Huffman dictionary and comes immediately after the first Huffman Dictionary.&lt;br /&gt;
&lt;br /&gt;
== Main file (EGAGRAPH.xxx) ==&lt;br /&gt;
&lt;br /&gt;
This file is simply an array of data files.  Each file starts at the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, and as there are no filenames each file is referred to by its index/slot number.  Slots containing dummy values in the header are treated as if they don&#039;t exist in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file. Each file within the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is individually compressed.  A file can be read by opening the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, seeking to the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, reading a UINT32LE for the decompressed file size, and then decompressing the data from that point onwards using standard Huffman decompression techniques.&lt;br /&gt;
&lt;br /&gt;
Note that in early games such as Keen Dreams, the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file may have another name. (Such as &amp;lt;tt&amp;gt;KDREAM.EGA&amp;lt;/tt&amp;gt; in that case.) in which case it is always the largest non-executable file.&lt;br /&gt;
&lt;br /&gt;
=== Chunks ===&lt;br /&gt;
&lt;br /&gt;
Each sub file or chunk is a separate graphic, ordered in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file in a specific way, much again like the [[AudioT Format]].  Chunks are labeled starting at 0. The game executable is hard coded for the start and finish of various chunk types. For example, Keen 4 has chunks 124-520 as sprites and will treat any chunk between these two numbers as a sprite. (Note that the game refers to chunk number, not sprite number.) The usual order of chunks is:&lt;br /&gt;
&lt;br /&gt;
 Picture table&lt;br /&gt;
 Masked picture table&lt;br /&gt;
 Sprite table&lt;br /&gt;
 Fonts&lt;br /&gt;
 Pictures (Unmasked bitmaps)&lt;br /&gt;
 Masked pictures&lt;br /&gt;
 8x8 unmasked tiles (Single chunk)&lt;br /&gt;
 8x8 masked tiles (Single chunk)&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 32x32 unmasked tiles (Optional)&lt;br /&gt;
 32x32 masked tiles (Optional)&lt;br /&gt;
 Misc graphics (Optional)&lt;br /&gt;
 Game texts&lt;br /&gt;
 Demo files (Optional)&lt;br /&gt;
 Misc data (Optional)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Chunk formats ==&lt;br /&gt;
&lt;br /&gt;
When compressed each chunk consists of a dword giving the decompressed size followed by the compressed data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the first chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying picture chunks.&lt;br /&gt;
&lt;br /&gt;
Divide the decompressed size by 4 to get numpics.&lt;br /&gt;
&lt;br /&gt;
=== Masked picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the second chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying masked picture chunks. This table is often quite small.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprite table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the third chunk, the picture table is 16 * numspr bytes long, consisting of eight words for each sprite image (Width\8, Height, x offset, y offset and clipping rectangle left, top, right and bottom; all in that order.) used when displaying sprite chunks. This is what Modkeen exports as its notoriously hard to use xSPRITES.txt file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fonts ===&lt;br /&gt;
&lt;br /&gt;
Always present and always starting at the fourth chunk. (Chunk 3!) Each chunk is a single monochrome font, containing all the entries from 0-255 for that font. Each &#039;letter&#039; is stored separately and consecutively. A game will have at least one, and usually 3 fonts. The format is version two of [[EGA Font format]]&lt;br /&gt;
&lt;br /&gt;
Fonts are used in the game for game texts. They can be stretched or colored and are always transparent, meaning they look strange when not over a single-color background.&lt;br /&gt;
&lt;br /&gt;
=== Pictures (Bitmaps) ===&lt;br /&gt;
These follow game fonts. You need to know how many fonts there are before it to know how what chunk number the first picture is (3+NumFonts). In [[Catacomb 3D]] there are 2 fonts.&lt;br /&gt;
&lt;br /&gt;
Bitmaps are stored as standard [[Raw EGA data]], the size of each plane being the decompressed chunk size \ 4. In order to be displayed properly these need information from chunk 0, the picture table. Note that unlike fonts, data does not wrap, so a 4x4 sprite will consist of four planes of four bytes in size, the same as an 8x4 sprite.&lt;br /&gt;
&lt;br /&gt;
Pictures are used for things such as title screens or pictures in game texts. Most of the main menu will consist of pictures. They are also used for the wall textures in EGA FPS games like [[Catacomb 3D]], in which case the wall textures come near the end of the picture list (starting from chunk 137 in [[Catacomb 3D]]).&lt;br /&gt;
&lt;br /&gt;
The number of picture chunks is given in chunk 0, the picture table.&lt;br /&gt;
&lt;br /&gt;
=== Masked pictures (Masked bitmaps) ===&lt;br /&gt;
&lt;br /&gt;
These follow Pictures. You need to know how many fonts there are, to know how what chunk number the first Masked picture is (3+NumFonts+numpics).&lt;br /&gt;
&lt;br /&gt;
These are identical to the picture chunks in every respect, except being masked, they consist of five EGA planes, not four. Some games (E.g [[Catacomb 3D]] make great use of masked pictures, but most games have only one or two. They need information from chunk 1, the masked picture table, to be displayed correctly.&lt;br /&gt;
&lt;br /&gt;
The number of Masked pictures is given in Chunk 1.&lt;br /&gt;
&lt;br /&gt;
=== Sprites ===&lt;br /&gt;
&lt;br /&gt;
The first Sprite chunk is at 3+numfonts+numpics+numMaskedPics.&lt;br /&gt;
&lt;br /&gt;
Sprites are exactly identical to masked pictures in format except the game cannot stretch or warp them. Most games use these for enemy, player or item graphics during gameplay. They need information from chunk 2, the sprite table both to display correctly and to interact correctly, something more complex than masked pictures.&lt;br /&gt;
&lt;br /&gt;
There are usually several hundred sprite chunks, but [[Catacomb 3D]] only has 3 sprite chunks and they are used for the PaddleWar game (Skulls and Bones). The number of sprite chunks is given in chunk 2.&lt;br /&gt;
&lt;br /&gt;
=== 8x8 tiles ===&lt;br /&gt;
&lt;br /&gt;
8x8 tiles are used by most games in status windows or foe the borders of message windows in-game. (And occasionally by TED5 to display levels.) There are thus not many of them. ALL the masked or unmasked tiles are one single chunk stored as four and five plane [[Raw EGA data]] respectively. The number of 8x8 unmasked and masked tiles is hard-coded into the executable, but can be worked out by dividing the decompressed chunk size by 32 and 40 (The size of one tile&#039;s data) respectively.&lt;br /&gt;
&lt;br /&gt;
=== 16x16 and 32x32 tiles ===&lt;br /&gt;
&lt;br /&gt;
32x32 tiles are optional and rarely used. 16x16 tiles are only occasionally absent and for most games make up the bulk of graphics. There are usually several thousand entries. Both come in masked and unmasked kinds, just like 8x8 tiles.&lt;br /&gt;
&lt;br /&gt;
These chunks have notable differences. Each tile is an individual chunk and stored as four or five plane [[Raw EGA data]] with a plane size of 128 (16x16) or 512 (32x32). These chunks do NOT have a dword specifying their decompressed size as this is hard-coded into the executable as a space saving measure. (As is the start and finish of unmasked and masked tile chunks.) This can cause problems for editing programs.&lt;br /&gt;
&lt;br /&gt;
Tiles make up the bulk of 2D game levels but are seldom seen elsewhere.&lt;br /&gt;
&lt;br /&gt;
=== Misc graphics ===&lt;br /&gt;
&lt;br /&gt;
Sometimes following tile graphics are miscellaneous graphics, that cannot be handled by the other chunk types. For example, Keen 4-6 has two misc graphics files used for the &#039;COOMANDER KEEN terminator text&#039; intro. These graphics usually have unique formats that fit their function and few have been investigated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Keen 4-6 Intro Bitmaps ====&lt;br /&gt;
&lt;br /&gt;
This is the text that displays after the &#039;Ready, press any key&#039; screen at Keen startup. It is composed of a monochrome bitmap that is scrolled across the screen and distorted for special effects. When displayed it is transparent, with a special palette so it is not black-and-white. It consists of a header followed by RLE compressed monochrome data.&lt;br /&gt;
&lt;br /&gt;
 HEADER:&lt;br /&gt;
 0   2    Img height  Height of the image in pixels&lt;br /&gt;
 2   2    Img width   Width of the image in pixels&lt;br /&gt;
 4   2x   Line point  Pointers to line 1,2,3..etc of data. There will be [Img height] of&lt;br /&gt;
                      these, each 2 bytes long. The first pointer will  have the value&lt;br /&gt;
                      (2 * [Img height] + 4)&lt;br /&gt;
 +2  ?    RLE data    RLE-WM compressed data&lt;br /&gt;
&lt;br /&gt;
 DATA:&lt;br /&gt;
 0   2    Black run   Number of black pixels to write&lt;br /&gt;
 2   2    Not-blk run Number of not-black pixels to write&lt;br /&gt;
 4   2    Black run....&lt;br /&gt;
 ...&lt;br /&gt;
 ..&lt;br /&gt;
 .&lt;br /&gt;
 ?  2     End         $FFFF; end of row.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game texts ===&lt;br /&gt;
&lt;br /&gt;
Also known as ANSII chunks, these are used by the game for things like help screens, and have their own format. In the main they are simply text documents, interspersed with various commands to make things happen. Each file is divided up into a number of &#039;pages&#039; which are moved between by pressing the up/down arrows. Pages can also have action sequences (Repeated each time the page is moved to, you cannot leave a page until the sequence finishes.)&lt;br /&gt;
&lt;br /&gt;
 ^P		First command in every file. Defines a page start&lt;br /&gt;
 ^E		Ends the file&lt;br /&gt;
 ^Cx		Change font color to $x until next page or ^C command&lt;br /&gt;
 ^Gx,y,z	Display (unmasked) picture chunk z at location x,y (In pixels)&lt;br /&gt;
 ^Tx,y,z,t	Display picture chunk z at x,y for z clicks of time&lt;br /&gt;
 ^Bx,y,z,t,b	?&lt;br /&gt;
 ^Lx,y		?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Misc files ===&lt;br /&gt;
&lt;br /&gt;
The last few chunks are demo files and occasionally miscellaneous data. Demo file formats are currently unknown but can be recorded using the demo cheat. They contain the level number and difficulty followed by a series of key commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
* [[KeenWiki:ModKeen|ModKeen]] (DOS) and [[KeenWiki:LModKeen|LModKeen]] (Linux/Windows) can be used to modify graphics and text stored in EGAGRAPH.CKx for the Commander Keen [[KeenWiki:Goodbye Galaxy|Goodbye Galaxy]] trilogy.&lt;br /&gt;
* WDC (Windows) can be used to view or modify the graphics and text stored in EGAGRAPH.C3D for [[Catacomb 3D]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Commander Keen Dreams]]&lt;br /&gt;
[[Category:Dangerous Dave 3]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Graphics Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3590</id>
		<title>EGAGraph Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3590"/>
		<updated>2011-09-01T06:35:41Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* EGA Head (EGAHEAD.xxx) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;EGAGraph&#039;&#039;&#039;, short for &#039;EGA graphics library&#039; is the format used to store graphics, demos, fonts, game texts and more in many early [[:Category:Id Software|id Software]] games.&lt;br /&gt;
&lt;br /&gt;
The basic format is that of a number of [[Huffman Compression]] compressed sub-files (Chunks) stored in a similar manner to the [[AudioT Format]]. Like this format it has three main files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt;and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is notable that while the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; are stored in the game executable, they need to be extracted for [[TED5]] to edit levels.&lt;br /&gt;
&lt;br /&gt;
This article may contain errors as some formats have not been worked out completely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= File formats =&lt;br /&gt;
&lt;br /&gt;
== EGA Head (EGAHEAD.xxx) ==&lt;br /&gt;
There are two versions of this format. The first version, used in [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], is an array of 4-byte little-endian values. The second version, used in all later EGA games, is an array of 3-byte unsigned little-endian values.&lt;br /&gt;
&lt;br /&gt;
This header file may be present as an external file (eg. [[Bio Menace]]), or it may be included in the EXE file (eg. [[Catacomb 3D]]). The last entry in the header is always the size of the EGAGRAPH.xxx file, and the first entry in the header is always 00 00 00. To find the end, you can search for filesize(EGAGRAPH.xxx) as a 3-byte (little-endian) value in the EXE. Then to find the start, go back 3 bytes at a time until you get to 00 000 00. Or use the fact that entries always get smaller as you go back, unless the entry is $FFFFFF. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] v1.00 &amp;lt;tt&amp;gt;EGAHEAD.C3D&amp;lt;/tt&amp;gt; is at $1BFD0 from the start of the decompressed ([[unlzexe]]) EXE file, and is 1437 bytes long, or 479 3-byte entries (for 478 chunks). It is then followed by 3 zero bytes (padding to multiple of 16?) 00 00 00, then the &amp;lt;tt&amp;gt;MAPHEAD.C3D&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
This header file stores the offsets (relative to the start of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file) for each sub file.  The format is trivial, in that the header file is simply an array of 3 or 4 byte variables.  (Each variable is a &amp;quot;slot&amp;quot;, as the game refers to files by index.) Most games use the more compact 3-byte variables, since the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is never larger than $FFFFFF. However games based on older engines, notably [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], use 4-byte vales as these are easier to deal with.&lt;br /&gt;
&lt;br /&gt;
It is important to note that not every &#039;slot&#039; will be in use. Tiles especially if blank (All black) will be considered &#039;empty&#039; and not worth adding to the file. (A blank 16x16 tile takes up 12 bytes of space if compressed, and there can be hundreds.) There are two ways of dealing with this; by default the games set all empty slot headers to -1, but many programs compress the graphics anyway and use a normal header value for them.&lt;br /&gt;
&lt;br /&gt;
The last offset in the file will be an offset to the end of the main &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file.  (So this should be ignored when reading the file to prevent a zero-byte file appearing last.) The total size of the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; divided by 3 (Or 4) will also give the number of &#039;slots&#039; the game uses. This varies, but is usually about 10,000.&lt;br /&gt;
&lt;br /&gt;
Unlike [[AudioT Format]] files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; is always compressed. However the header and dictionary may be external (E.g [[Bio Menace]])&lt;br /&gt;
&lt;br /&gt;
== Dictionary (EGADICT.xxx) ==&lt;br /&gt;
&lt;br /&gt;
The same [[Huffman Compression]] scheme used elsewhere in the [[Commander Keen]] series is used.  When reading compressed files out of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, the first four bytes located at the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; offset are a UINT32LE specifying the file&#039;s decompressed size (which is required for the decompression algorithm.)  The compressed data then follows, EXCEPT for 16x16 masked and unmasked tiles. Since these all have a similar decompressed size (128 bytes for unmasked, 256 bytes for masked) it is a waste of space to include these (Since tiles make up the bulk of graphics slots.) The decompressed size is hard coded, as are the start and finish of the unmasked and masked tile slots.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; file is not often obvious, usually being embedded in the main exe file. It is possible to locate it by looking for the string &amp;lt;tt&amp;gt;$FD $01 $00 $00 $00 $00&amp;lt;/tt&amp;gt;, which appears at the end of nearly all Huffman dictionaries. Executables usually contain two or more dictionaries, but the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; is usually the second one, except in the case of early games like Keen Dreams, where it is the first of THREE. (A simple check of whether it decompresses the data sensibly works.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Main file (EGAGRAPH.xxx) ==&lt;br /&gt;
&lt;br /&gt;
This file is simply an array of data files.  Each file starts at the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, and as there are no filenames each file is referred to by its index/slot number.  Slots containing dummy values in the header are treated as if they don&#039;t exist in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file. Each file within the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is individually compressed.  A file can be read by opening the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, seeking to the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, reading a UINT32LE for the decompressed file size, and then decompressing the data from that point onwards using standard Huffman decompression techniques.&lt;br /&gt;
&lt;br /&gt;
Note that in early games such as Keen Dreams, the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file may have another name. (Such as &amp;lt;tt&amp;gt;KDREAM.EGA&amp;lt;/tt&amp;gt; in that case.) in which case it is always the largest non-executable file.&lt;br /&gt;
&lt;br /&gt;
=== Chunks ===&lt;br /&gt;
&lt;br /&gt;
Each sub file or chunk is a separate graphic, ordered in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file in a specific way, much again like the [[AudioT Format]].  Chunks are labeled starting at 0. The game executable is hard coded for the start and finish of various chunk types. For example, Keen 4 has chunks 124-520 as sprites and will treat any chunk between these two numbers as a sprite. (Note that the game refers to chunk number, not sprite number.) The usual order of chunks is:&lt;br /&gt;
&lt;br /&gt;
 Picture table&lt;br /&gt;
 Masked picture table&lt;br /&gt;
 Sprite table&lt;br /&gt;
 Fonts&lt;br /&gt;
 Pictures (Unmasked bitmaps)&lt;br /&gt;
 Masked pictures&lt;br /&gt;
 8x8 unmasked tiles (Single chunk)&lt;br /&gt;
 8x8 masked tiles (Single chunk)&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 32x32 unmasked tiles (Optional)&lt;br /&gt;
 32x32 masked tiles (Optional)&lt;br /&gt;
 Misc graphics (Optional)&lt;br /&gt;
 Game texts&lt;br /&gt;
 Demo files (Optional)&lt;br /&gt;
 Misc data (Optional)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Chunk formats ==&lt;br /&gt;
&lt;br /&gt;
When compressed each chunk consists of a dword giving the decompressed size followed by the compressed data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the first chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying picture chunks.&lt;br /&gt;
&lt;br /&gt;
Divide the decompressed size by 4 to get numpics.&lt;br /&gt;
&lt;br /&gt;
=== Masked picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the second chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying masked picture chunks. This table is often quite small.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprite table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the third chunk, the picture table is 16 * numspr bytes long, consisting of eight words for each sprite image (Width\8, Height, x offset, y offset and clipping rectangle left, top, right and bottom; all in that order.) used when displaying sprite chunks. This is what Modkeen exports as its notoriously hard to use xSPRITES.txt file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fonts ===&lt;br /&gt;
&lt;br /&gt;
Always present and always starting at the fourth chunk. (Chunk 3!) Each chunk is a single monochrome font, containing all the entries from 0-255 for that font. Each &#039;letter&#039; is stored separately and consecutively. A game will have at least one, and usually 3 fonts. The format is version two of [[EGA Font format]]&lt;br /&gt;
&lt;br /&gt;
Fonts are used in the game for game texts. They can be stretched or colored and are always transparent, meaning they look strange when not over a single-color background.&lt;br /&gt;
&lt;br /&gt;
=== Pictures (Bitmaps) ===&lt;br /&gt;
These follow game fonts. You need to know how many fonts there are before it to know how what chunk number the first picture is (3+NumFonts). In [[Catacomb 3D]] there are 2 fonts.&lt;br /&gt;
&lt;br /&gt;
Bitmaps are stored as standard [[Raw EGA data]], the size of each plane being the decompressed chunk size \ 4. In order to be displayed properly these need information from chunk 0, the picture table. Note that unlike fonts, data does not wrap, so a 4x4 sprite will consist of four planes of four bytes in size, the same as an 8x4 sprite.&lt;br /&gt;
&lt;br /&gt;
Pictures are used for things such as title screens or pictures in game texts. Most of the main menu will consist of pictures. They are also used for the wall textures in EGA FPS games like [[Catacomb 3D]], in which case the wall textures come near the end of the picture list (starting from chunk 137 in [[Catacomb 3D]]).&lt;br /&gt;
&lt;br /&gt;
The number of picture chunks is given in chunk 0, the picture table.&lt;br /&gt;
&lt;br /&gt;
=== Masked pictures (Masked bitmaps) ===&lt;br /&gt;
&lt;br /&gt;
These follow Pictures. You need to know how many fonts there are, to know how what chunk number the first Masked picture is (3+NumFonts+numpics).&lt;br /&gt;
&lt;br /&gt;
These are identical to the picture chunks in every respect, except being masked, they consist of five EGA planes, not four. Some games (E.g [[Catacomb 3D]] make great use of masked pictures, but most games have only one or two. They need information from chunk 1, the masked picture table, to be displayed correctly.&lt;br /&gt;
&lt;br /&gt;
The number of Masked pictures is given in Chunk 1.&lt;br /&gt;
&lt;br /&gt;
=== Sprites ===&lt;br /&gt;
&lt;br /&gt;
The first Sprite chunk is at 3+numfonts+numpics+numMaskedPics.&lt;br /&gt;
&lt;br /&gt;
Sprites are exactly identical to masked pictures in format except the game cannot stretch or warp them. Most games use these for enemy, player or item graphics during gameplay. They need information from chunk 2, the sprite table both to display correctly and to interact correctly, something more complex than masked pictures.&lt;br /&gt;
&lt;br /&gt;
There are usually several hundred sprite chunks, but [[Catacomb 3D]] only has 3 sprite chunks and they are used for the PaddleWar game (Skulls and Bones). The number of sprite chunks is given in chunk 2.&lt;br /&gt;
&lt;br /&gt;
=== 8x8 tiles ===&lt;br /&gt;
&lt;br /&gt;
8x8 tiles are used by most games in status windows or foe the borders of message windows in-game. (And occasionally by TED5 to display levels.) There are thus not many of them. ALL the masked or unmasked tiles are one single chunk stored as four and five plane [[Raw EGA data]] respectively. The number of 8x8 unmasked and masked tiles is hard-coded into the executable, but can be worked out by dividing the decompressed chunk size by 32 and 40 (The size of one tile&#039;s data) respectively.&lt;br /&gt;
&lt;br /&gt;
=== 16x16 and 32x32 tiles ===&lt;br /&gt;
&lt;br /&gt;
32x32 tiles are optional and rarely used. 16x16 tiles are only occasionally absent and for most games make up the bulk of graphics. There are usually several thousand entries. Both come in masked and unmasked kinds, just like 8x8 tiles.&lt;br /&gt;
&lt;br /&gt;
These chunks have notable differences. Each tile is an individual chunk and stored as four or five plane [[Raw EGA data]] with a plane size of 128 (16x16) or 512 (32x32). These chunks do NOT have a dword specifying their decompressed size as this is hard-coded into the executable as a space saving measure. (As is the start and finish of unmasked and masked tile chunks.) This can cause problems for editing programs.&lt;br /&gt;
&lt;br /&gt;
Tiles make up the bulk of 2D game levels but are seldom seen elsewhere.&lt;br /&gt;
&lt;br /&gt;
=== Misc graphics ===&lt;br /&gt;
&lt;br /&gt;
Sometimes following tile graphics are miscellaneous graphics, that cannot be handled by the other chunk types. For example, Keen 4-6 has two misc graphics files used for the &#039;COOMANDER KEEN terminator text&#039; intro. These graphics usually have unique formats that fit their function and few have been investigated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Keen 4-6 Intro Bitmaps ====&lt;br /&gt;
&lt;br /&gt;
This is the text that displays after the &#039;Ready, press any key&#039; screen at Keen startup. It is composed of a monochrome bitmap that is scrolled across the screen and distorted for special effects. When displayed it is transparent, with a special palette so it is not black-and-white. It consists of a header followed by RLE compressed monochrome data.&lt;br /&gt;
&lt;br /&gt;
 HEADER:&lt;br /&gt;
 0   2    Img height  Height of the image in pixels&lt;br /&gt;
 2   2    Img width   Width of the image in pixels&lt;br /&gt;
 4   2x   Line point  Pointers to line 1,2,3..etc of data. There will be [Img height] of&lt;br /&gt;
                      these, each 2 bytes long. The first pointer will  have the value&lt;br /&gt;
                      (2 * [Img height] + 4)&lt;br /&gt;
 +2  ?    RLE data    RLE-WM compressed data&lt;br /&gt;
&lt;br /&gt;
 DATA:&lt;br /&gt;
 0   2    Black run   Number of black pixels to write&lt;br /&gt;
 2   2    Not-blk run Number of not-black pixels to write&lt;br /&gt;
 4   2    Black run....&lt;br /&gt;
 ...&lt;br /&gt;
 ..&lt;br /&gt;
 .&lt;br /&gt;
 ?  2     End         $FFFF; end of row.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game texts ===&lt;br /&gt;
&lt;br /&gt;
Also known as ANSII chunks, these are used by the game for things like help screens, and have their own format. In the main they are simply text documents, interspersed with various commands to make things happen. Each file is divided up into a number of &#039;pages&#039; which are moved between by pressing the up/down arrows. Pages can also have action sequences (Repeated each time the page is moved to, you cannot leave a page until the sequence finishes.)&lt;br /&gt;
&lt;br /&gt;
 ^P		First command in every file. Defines a page start&lt;br /&gt;
 ^E		Ends the file&lt;br /&gt;
 ^Cx		Change font color to $x until next page or ^C command&lt;br /&gt;
 ^Gx,y,z	Display (unmasked) picture chunk z at location x,y (In pixels)&lt;br /&gt;
 ^Tx,y,z,t	Display picture chunk z at x,y for z clicks of time&lt;br /&gt;
 ^Bx,y,z,t,b	?&lt;br /&gt;
 ^Lx,y		?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Misc files ===&lt;br /&gt;
&lt;br /&gt;
The last few chunks are demo files and occasionally miscellaneous data. Demo file formats are currently unknown but can be recorded using the demo cheat. They contain the level number and difficulty followed by a series of key commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
* [[KeenWiki:ModKeen|ModKeen]] (DOS) and [[KeenWiki:LModKeen|LModKeen]] (Linux/Windows) can be used to modify graphics and text stored in EGAGRAPH.CKx for the Commander Keen [[KeenWiki:Goodbye Galaxy|Goodbye Galaxy]] trilogy.&lt;br /&gt;
* WDC (Windows) can be used to view or modify the graphics and text stored in EGAGRAPH.C3D for [[Catacomb 3D]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Commander Keen Dreams]]&lt;br /&gt;
[[Category:Dangerous Dave 3]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Graphics Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3589</id>
		<title>EGAGraph Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3589"/>
		<updated>2011-09-01T06:22:30Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* Utilities */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;EGAGraph&#039;&#039;&#039;, short for &#039;EGA graphics library&#039; is the format used to store graphics, demos, fonts, game texts and more in many early [[:Category:Id Software|id Software]] games.&lt;br /&gt;
&lt;br /&gt;
The basic format is that of a number of [[Huffman Compression]] compressed sub-files (Chunks) stored in a similar manner to the [[AudioT Format]]. Like this format it has three main files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt;and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is notable that while the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; are stored in the game executable, they need to be extracted for [[TED5]] to edit levels.&lt;br /&gt;
&lt;br /&gt;
This article may contain errors as some formats have not been worked out completely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= File formats =&lt;br /&gt;
&lt;br /&gt;
== EGA Head (EGAHEAD.xxx) ==&lt;br /&gt;
There are two versions of this format. The first version, used in [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], is an array of 4-byte little-endian values. The second version, used in all later EGA games, is an array of 3-byte unsigned little-endian values.&lt;br /&gt;
&lt;br /&gt;
This header file may be present as an external file (eg. [[Bio Menace]]), or it may be included in the EXE file (eg. [[Catacomb 3D]]). The last entry in the header is always the size of the EGAGRAPH.xxx file, and the first entry in the header is always 00 00 00. To find the end, you can search for filesize(EGAGRAPH.xxx) as a 3-byte (little-endian) value in the EXE. Then to find the start, go back 3 bytes at a time until you get to 00 000 00. Or use the fact that entries always get smaller as you go back, unless the entry is $FFFFFF. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] v1.00 EGAHEAD.C3D is at $1BFD0 from the start of the decompressed ([[unlzexe]]) EXE file, and is 1436 bytes long, or 478 3-byte entries (for 477 chunks). It is then followed by 4 bytes (padding to multiple of 16?) 03 00 00 00, then the MAPHEAD.C3D. &lt;br /&gt;
&lt;br /&gt;
This header file stores the offsets (relative to the start of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file) for each sub file.  The format is trivial, in that the header file is simply an array of 3 or 4 byte variables.  (Each variable is a &amp;quot;slot&amp;quot;, as the game refers to files by index.) Most games use the more compact 3-byte variables, since the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is never larger than $FFFFFF. However games based on older engines, notably [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], use 4-byte vales as these are easier to deal with.&lt;br /&gt;
&lt;br /&gt;
It is important to note that not every &#039;slot&#039; will be in use. Tiles especially if blank (All black) will be considered &#039;empty&#039; and not worth adding to the file. (A blank 16x16 tile takes up 12 bytes of space if compressed, and there can be hundreds.) There are two ways of dealing with this; by default the games set all empty slot headers to -1, but many programs compress the graphics anyway and use a normal header value for them.&lt;br /&gt;
&lt;br /&gt;
The last offset in the file will be an offset to the end of the main &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file.  (So this should be ignored when reading the file to prevent a zero-byte file appearing last.) The total size of the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; divided by 3 (Or 4) will also give the number of &#039;slots&#039; the game uses. This varies, but is usually about 10,000.&lt;br /&gt;
&lt;br /&gt;
Unlike [[AudioT Format]] files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; is always compressed. However the header and dictionary may be external (E.g [[Bio Menace]])&lt;br /&gt;
&lt;br /&gt;
== Dictionary (EGADICT.xxx) ==&lt;br /&gt;
&lt;br /&gt;
The same [[Huffman Compression]] scheme used elsewhere in the [[Commander Keen]] series is used.  When reading compressed files out of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, the first four bytes located at the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; offset are a UINT32LE specifying the file&#039;s decompressed size (which is required for the decompression algorithm.)  The compressed data then follows, EXCEPT for 16x16 masked and unmasked tiles. Since these all have a similar decompressed size (128 bytes for unmasked, 256 bytes for masked) it is a waste of space to include these (Since tiles make up the bulk of graphics slots.) The decompressed size is hard coded, as are the start and finish of the unmasked and masked tile slots.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; file is not often obvious, usually being embedded in the main exe file. It is possible to locate it by looking for the string &amp;lt;tt&amp;gt;$FD $01 $00 $00 $00 $00&amp;lt;/tt&amp;gt;, which appears at the end of nearly all Huffman dictionaries. Executables usually contain two or more dictionaries, but the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; is usually the second one, except in the case of early games like Keen Dreams, where it is the first of THREE. (A simple check of whether it decompresses the data sensibly works.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Main file (EGAGRAPH.xxx) ==&lt;br /&gt;
&lt;br /&gt;
This file is simply an array of data files.  Each file starts at the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, and as there are no filenames each file is referred to by its index/slot number.  Slots containing dummy values in the header are treated as if they don&#039;t exist in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file. Each file within the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is individually compressed.  A file can be read by opening the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, seeking to the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, reading a UINT32LE for the decompressed file size, and then decompressing the data from that point onwards using standard Huffman decompression techniques.&lt;br /&gt;
&lt;br /&gt;
Note that in early games such as Keen Dreams, the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file may have another name. (Such as &amp;lt;tt&amp;gt;KDREAM.EGA&amp;lt;/tt&amp;gt; in that case.) in which case it is always the largest non-executable file.&lt;br /&gt;
&lt;br /&gt;
=== Chunks ===&lt;br /&gt;
&lt;br /&gt;
Each sub file or chunk is a separate graphic, ordered in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file in a specific way, much again like the [[AudioT Format]].  Chunks are labeled starting at 0. The game executable is hard coded for the start and finish of various chunk types. For example, Keen 4 has chunks 124-520 as sprites and will treat any chunk between these two numbers as a sprite. (Note that the game refers to chunk number, not sprite number.) The usual order of chunks is:&lt;br /&gt;
&lt;br /&gt;
 Picture table&lt;br /&gt;
 Masked picture table&lt;br /&gt;
 Sprite table&lt;br /&gt;
 Fonts&lt;br /&gt;
 Pictures (Unmasked bitmaps)&lt;br /&gt;
 Masked pictures&lt;br /&gt;
 8x8 unmasked tiles (Single chunk)&lt;br /&gt;
 8x8 masked tiles (Single chunk)&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 32x32 unmasked tiles (Optional)&lt;br /&gt;
 32x32 masked tiles (Optional)&lt;br /&gt;
 Misc graphics (Optional)&lt;br /&gt;
 Game texts&lt;br /&gt;
 Demo files (Optional)&lt;br /&gt;
 Misc data (Optional)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Chunk formats ==&lt;br /&gt;
&lt;br /&gt;
When compressed each chunk consists of a dword giving the decompressed size followed by the compressed data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the first chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying picture chunks.&lt;br /&gt;
&lt;br /&gt;
Divide the decompressed size by 4 to get numpics.&lt;br /&gt;
&lt;br /&gt;
=== Masked picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the second chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying masked picture chunks. This table is often quite small.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprite table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the third chunk, the picture table is 16 * numspr bytes long, consisting of eight words for each sprite image (Width\8, Height, x offset, y offset and clipping rectangle left, top, right and bottom; all in that order.) used when displaying sprite chunks. This is what Modkeen exports as its notoriously hard to use xSPRITES.txt file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fonts ===&lt;br /&gt;
&lt;br /&gt;
Always present and always starting at the fourth chunk. (Chunk 3!) Each chunk is a single monochrome font, containing all the entries from 0-255 for that font. Each &#039;letter&#039; is stored separately and consecutively. A game will have at least one, and usually 3 fonts. The format is version two of [[EGA Font format]]&lt;br /&gt;
&lt;br /&gt;
Fonts are used in the game for game texts. They can be stretched or colored and are always transparent, meaning they look strange when not over a single-color background.&lt;br /&gt;
&lt;br /&gt;
=== Pictures (Bitmaps) ===&lt;br /&gt;
These follow game fonts. You need to know how many fonts there are before it to know how what chunk number the first picture is (3+NumFonts). In [[Catacomb 3D]] there are 2 fonts.&lt;br /&gt;
&lt;br /&gt;
Bitmaps are stored as standard [[Raw EGA data]], the size of each plane being the decompressed chunk size \ 4. In order to be displayed properly these need information from chunk 0, the picture table. Note that unlike fonts, data does not wrap, so a 4x4 sprite will consist of four planes of four bytes in size, the same as an 8x4 sprite.&lt;br /&gt;
&lt;br /&gt;
Pictures are used for things such as title screens or pictures in game texts. Most of the main menu will consist of pictures. They are also used for the wall textures in EGA FPS games like [[Catacomb 3D]], in which case the wall textures come near the end of the picture list (starting from chunk 137 in [[Catacomb 3D]]).&lt;br /&gt;
&lt;br /&gt;
The number of picture chunks is given in chunk 0, the picture table.&lt;br /&gt;
&lt;br /&gt;
=== Masked pictures (Masked bitmaps) ===&lt;br /&gt;
&lt;br /&gt;
These follow Pictures. You need to know how many fonts there are, to know how what chunk number the first Masked picture is (3+NumFonts+numpics).&lt;br /&gt;
&lt;br /&gt;
These are identical to the picture chunks in every respect, except being masked, they consist of five EGA planes, not four. Some games (E.g [[Catacomb 3D]] make great use of masked pictures, but most games have only one or two. They need information from chunk 1, the masked picture table, to be displayed correctly.&lt;br /&gt;
&lt;br /&gt;
The number of Masked pictures is given in Chunk 1.&lt;br /&gt;
&lt;br /&gt;
=== Sprites ===&lt;br /&gt;
&lt;br /&gt;
The first Sprite chunk is at 3+numfonts+numpics+numMaskedPics.&lt;br /&gt;
&lt;br /&gt;
Sprites are exactly identical to masked pictures in format except the game cannot stretch or warp them. Most games use these for enemy, player or item graphics during gameplay. They need information from chunk 2, the sprite table both to display correctly and to interact correctly, something more complex than masked pictures.&lt;br /&gt;
&lt;br /&gt;
There are usually several hundred sprite chunks, but [[Catacomb 3D]] only has 3 sprite chunks and they are used for the PaddleWar game (Skulls and Bones). The number of sprite chunks is given in chunk 2.&lt;br /&gt;
&lt;br /&gt;
=== 8x8 tiles ===&lt;br /&gt;
&lt;br /&gt;
8x8 tiles are used by most games in status windows or foe the borders of message windows in-game. (And occasionally by TED5 to display levels.) There are thus not many of them. ALL the masked or unmasked tiles are one single chunk stored as four and five plane [[Raw EGA data]] respectively. The number of 8x8 unmasked and masked tiles is hard-coded into the executable, but can be worked out by dividing the decompressed chunk size by 32 and 40 (The size of one tile&#039;s data) respectively.&lt;br /&gt;
&lt;br /&gt;
=== 16x16 and 32x32 tiles ===&lt;br /&gt;
&lt;br /&gt;
32x32 tiles are optional and rarely used. 16x16 tiles are only occasionally absent and for most games make up the bulk of graphics. There are usually several thousand entries. Both come in masked and unmasked kinds, just like 8x8 tiles.&lt;br /&gt;
&lt;br /&gt;
These chunks have notable differences. Each tile is an individual chunk and stored as four or five plane [[Raw EGA data]] with a plane size of 128 (16x16) or 512 (32x32). These chunks do NOT have a dword specifying their decompressed size as this is hard-coded into the executable as a space saving measure. (As is the start and finish of unmasked and masked tile chunks.) This can cause problems for editing programs.&lt;br /&gt;
&lt;br /&gt;
Tiles make up the bulk of 2D game levels but are seldom seen elsewhere.&lt;br /&gt;
&lt;br /&gt;
=== Misc graphics ===&lt;br /&gt;
&lt;br /&gt;
Sometimes following tile graphics are miscellaneous graphics, that cannot be handled by the other chunk types. For example, Keen 4-6 has two misc graphics files used for the &#039;COOMANDER KEEN terminator text&#039; intro. These graphics usually have unique formats that fit their function and few have been investigated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Keen 4-6 Intro Bitmaps ====&lt;br /&gt;
&lt;br /&gt;
This is the text that displays after the &#039;Ready, press any key&#039; screen at Keen startup. It is composed of a monochrome bitmap that is scrolled across the screen and distorted for special effects. When displayed it is transparent, with a special palette so it is not black-and-white. It consists of a header followed by RLE compressed monochrome data.&lt;br /&gt;
&lt;br /&gt;
 HEADER:&lt;br /&gt;
 0   2    Img height  Height of the image in pixels&lt;br /&gt;
 2   2    Img width   Width of the image in pixels&lt;br /&gt;
 4   2x   Line point  Pointers to line 1,2,3..etc of data. There will be [Img height] of&lt;br /&gt;
                      these, each 2 bytes long. The first pointer will  have the value&lt;br /&gt;
                      (2 * [Img height] + 4)&lt;br /&gt;
 +2  ?    RLE data    RLE-WM compressed data&lt;br /&gt;
&lt;br /&gt;
 DATA:&lt;br /&gt;
 0   2    Black run   Number of black pixels to write&lt;br /&gt;
 2   2    Not-blk run Number of not-black pixels to write&lt;br /&gt;
 4   2    Black run....&lt;br /&gt;
 ...&lt;br /&gt;
 ..&lt;br /&gt;
 .&lt;br /&gt;
 ?  2     End         $FFFF; end of row.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game texts ===&lt;br /&gt;
&lt;br /&gt;
Also known as ANSII chunks, these are used by the game for things like help screens, and have their own format. In the main they are simply text documents, interspersed with various commands to make things happen. Each file is divided up into a number of &#039;pages&#039; which are moved between by pressing the up/down arrows. Pages can also have action sequences (Repeated each time the page is moved to, you cannot leave a page until the sequence finishes.)&lt;br /&gt;
&lt;br /&gt;
 ^P		First command in every file. Defines a page start&lt;br /&gt;
 ^E		Ends the file&lt;br /&gt;
 ^Cx		Change font color to $x until next page or ^C command&lt;br /&gt;
 ^Gx,y,z	Display (unmasked) picture chunk z at location x,y (In pixels)&lt;br /&gt;
 ^Tx,y,z,t	Display picture chunk z at x,y for z clicks of time&lt;br /&gt;
 ^Bx,y,z,t,b	?&lt;br /&gt;
 ^Lx,y		?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Misc files ===&lt;br /&gt;
&lt;br /&gt;
The last few chunks are demo files and occasionally miscellaneous data. Demo file formats are currently unknown but can be recorded using the demo cheat. They contain the level number and difficulty followed by a series of key commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
* [[KeenWiki:ModKeen|ModKeen]] (DOS) and [[KeenWiki:LModKeen|LModKeen]] (Linux/Windows) can be used to modify graphics and text stored in EGAGRAPH.CKx for the Commander Keen [[KeenWiki:Goodbye Galaxy|Goodbye Galaxy]] trilogy.&lt;br /&gt;
* WDC (Windows) can be used to view or modify the graphics and text stored in EGAGRAPH.C3D for [[Catacomb 3D]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Commander Keen Dreams]]&lt;br /&gt;
[[Category:Dangerous Dave 3]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Graphics Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3588</id>
		<title>EGAGraph Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3588"/>
		<updated>2011-09-01T06:19:43Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* Sprites */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;EGAGraph&#039;&#039;&#039;, short for &#039;EGA graphics library&#039; is the format used to store graphics, demos, fonts, game texts and more in many early [[:Category:Id Software|id Software]] games.&lt;br /&gt;
&lt;br /&gt;
The basic format is that of a number of [[Huffman Compression]] compressed sub-files (Chunks) stored in a similar manner to the [[AudioT Format]]. Like this format it has three main files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt;and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is notable that while the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; are stored in the game executable, they need to be extracted for [[TED5]] to edit levels.&lt;br /&gt;
&lt;br /&gt;
This article may contain errors as some formats have not been worked out completely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= File formats =&lt;br /&gt;
&lt;br /&gt;
== EGA Head (EGAHEAD.xxx) ==&lt;br /&gt;
There are two versions of this format. The first version, used in [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], is an array of 4-byte little-endian values. The second version, used in all later EGA games, is an array of 3-byte unsigned little-endian values.&lt;br /&gt;
&lt;br /&gt;
This header file may be present as an external file (eg. [[Bio Menace]]), or it may be included in the EXE file (eg. [[Catacomb 3D]]). The last entry in the header is always the size of the EGAGRAPH.xxx file, and the first entry in the header is always 00 00 00. To find the end, you can search for filesize(EGAGRAPH.xxx) as a 3-byte (little-endian) value in the EXE. Then to find the start, go back 3 bytes at a time until you get to 00 000 00. Or use the fact that entries always get smaller as you go back, unless the entry is $FFFFFF. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] v1.00 EGAHEAD.C3D is at $1BFD0 from the start of the decompressed ([[unlzexe]]) EXE file, and is 1436 bytes long, or 478 3-byte entries (for 477 chunks). It is then followed by 4 bytes (padding to multiple of 16?) 03 00 00 00, then the MAPHEAD.C3D. &lt;br /&gt;
&lt;br /&gt;
This header file stores the offsets (relative to the start of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file) for each sub file.  The format is trivial, in that the header file is simply an array of 3 or 4 byte variables.  (Each variable is a &amp;quot;slot&amp;quot;, as the game refers to files by index.) Most games use the more compact 3-byte variables, since the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is never larger than $FFFFFF. However games based on older engines, notably [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], use 4-byte vales as these are easier to deal with.&lt;br /&gt;
&lt;br /&gt;
It is important to note that not every &#039;slot&#039; will be in use. Tiles especially if blank (All black) will be considered &#039;empty&#039; and not worth adding to the file. (A blank 16x16 tile takes up 12 bytes of space if compressed, and there can be hundreds.) There are two ways of dealing with this; by default the games set all empty slot headers to -1, but many programs compress the graphics anyway and use a normal header value for them.&lt;br /&gt;
&lt;br /&gt;
The last offset in the file will be an offset to the end of the main &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file.  (So this should be ignored when reading the file to prevent a zero-byte file appearing last.) The total size of the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; divided by 3 (Or 4) will also give the number of &#039;slots&#039; the game uses. This varies, but is usually about 10,000.&lt;br /&gt;
&lt;br /&gt;
Unlike [[AudioT Format]] files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; is always compressed. However the header and dictionary may be external (E.g [[Bio Menace]])&lt;br /&gt;
&lt;br /&gt;
== Dictionary (EGADICT.xxx) ==&lt;br /&gt;
&lt;br /&gt;
The same [[Huffman Compression]] scheme used elsewhere in the [[Commander Keen]] series is used.  When reading compressed files out of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, the first four bytes located at the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; offset are a UINT32LE specifying the file&#039;s decompressed size (which is required for the decompression algorithm.)  The compressed data then follows, EXCEPT for 16x16 masked and unmasked tiles. Since these all have a similar decompressed size (128 bytes for unmasked, 256 bytes for masked) it is a waste of space to include these (Since tiles make up the bulk of graphics slots.) The decompressed size is hard coded, as are the start and finish of the unmasked and masked tile slots.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; file is not often obvious, usually being embedded in the main exe file. It is possible to locate it by looking for the string &amp;lt;tt&amp;gt;$FD $01 $00 $00 $00 $00&amp;lt;/tt&amp;gt;, which appears at the end of nearly all Huffman dictionaries. Executables usually contain two or more dictionaries, but the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; is usually the second one, except in the case of early games like Keen Dreams, where it is the first of THREE. (A simple check of whether it decompresses the data sensibly works.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Main file (EGAGRAPH.xxx) ==&lt;br /&gt;
&lt;br /&gt;
This file is simply an array of data files.  Each file starts at the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, and as there are no filenames each file is referred to by its index/slot number.  Slots containing dummy values in the header are treated as if they don&#039;t exist in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file. Each file within the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is individually compressed.  A file can be read by opening the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, seeking to the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, reading a UINT32LE for the decompressed file size, and then decompressing the data from that point onwards using standard Huffman decompression techniques.&lt;br /&gt;
&lt;br /&gt;
Note that in early games such as Keen Dreams, the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file may have another name. (Such as &amp;lt;tt&amp;gt;KDREAM.EGA&amp;lt;/tt&amp;gt; in that case.) in which case it is always the largest non-executable file.&lt;br /&gt;
&lt;br /&gt;
=== Chunks ===&lt;br /&gt;
&lt;br /&gt;
Each sub file or chunk is a separate graphic, ordered in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file in a specific way, much again like the [[AudioT Format]].  Chunks are labeled starting at 0. The game executable is hard coded for the start and finish of various chunk types. For example, Keen 4 has chunks 124-520 as sprites and will treat any chunk between these two numbers as a sprite. (Note that the game refers to chunk number, not sprite number.) The usual order of chunks is:&lt;br /&gt;
&lt;br /&gt;
 Picture table&lt;br /&gt;
 Masked picture table&lt;br /&gt;
 Sprite table&lt;br /&gt;
 Fonts&lt;br /&gt;
 Pictures (Unmasked bitmaps)&lt;br /&gt;
 Masked pictures&lt;br /&gt;
 8x8 unmasked tiles (Single chunk)&lt;br /&gt;
 8x8 masked tiles (Single chunk)&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 32x32 unmasked tiles (Optional)&lt;br /&gt;
 32x32 masked tiles (Optional)&lt;br /&gt;
 Misc graphics (Optional)&lt;br /&gt;
 Game texts&lt;br /&gt;
 Demo files (Optional)&lt;br /&gt;
 Misc data (Optional)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Chunk formats ==&lt;br /&gt;
&lt;br /&gt;
When compressed each chunk consists of a dword giving the decompressed size followed by the compressed data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the first chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying picture chunks.&lt;br /&gt;
&lt;br /&gt;
Divide the decompressed size by 4 to get numpics.&lt;br /&gt;
&lt;br /&gt;
=== Masked picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the second chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying masked picture chunks. This table is often quite small.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprite table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the third chunk, the picture table is 16 * numspr bytes long, consisting of eight words for each sprite image (Width\8, Height, x offset, y offset and clipping rectangle left, top, right and bottom; all in that order.) used when displaying sprite chunks. This is what Modkeen exports as its notoriously hard to use xSPRITES.txt file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fonts ===&lt;br /&gt;
&lt;br /&gt;
Always present and always starting at the fourth chunk. (Chunk 3!) Each chunk is a single monochrome font, containing all the entries from 0-255 for that font. Each &#039;letter&#039; is stored separately and consecutively. A game will have at least one, and usually 3 fonts. The format is version two of [[EGA Font format]]&lt;br /&gt;
&lt;br /&gt;
Fonts are used in the game for game texts. They can be stretched or colored and are always transparent, meaning they look strange when not over a single-color background.&lt;br /&gt;
&lt;br /&gt;
=== Pictures (Bitmaps) ===&lt;br /&gt;
These follow game fonts. You need to know how many fonts there are before it to know how what chunk number the first picture is (3+NumFonts). In [[Catacomb 3D]] there are 2 fonts.&lt;br /&gt;
&lt;br /&gt;
Bitmaps are stored as standard [[Raw EGA data]], the size of each plane being the decompressed chunk size \ 4. In order to be displayed properly these need information from chunk 0, the picture table. Note that unlike fonts, data does not wrap, so a 4x4 sprite will consist of four planes of four bytes in size, the same as an 8x4 sprite.&lt;br /&gt;
&lt;br /&gt;
Pictures are used for things such as title screens or pictures in game texts. Most of the main menu will consist of pictures. They are also used for the wall textures in EGA FPS games like [[Catacomb 3D]], in which case the wall textures come near the end of the picture list (starting from chunk 137 in [[Catacomb 3D]]).&lt;br /&gt;
&lt;br /&gt;
The number of picture chunks is given in chunk 0, the picture table.&lt;br /&gt;
&lt;br /&gt;
=== Masked pictures (Masked bitmaps) ===&lt;br /&gt;
&lt;br /&gt;
These follow Pictures. You need to know how many fonts there are, to know how what chunk number the first Masked picture is (3+NumFonts+numpics).&lt;br /&gt;
&lt;br /&gt;
These are identical to the picture chunks in every respect, except being masked, they consist of five EGA planes, not four. Some games (E.g [[Catacomb 3D]] make great use of masked pictures, but most games have only one or two. They need information from chunk 1, the masked picture table, to be displayed correctly.&lt;br /&gt;
&lt;br /&gt;
The number of Masked pictures is given in Chunk 1.&lt;br /&gt;
&lt;br /&gt;
=== Sprites ===&lt;br /&gt;
&lt;br /&gt;
The first Sprite chunk is at 3+numfonts+numpics+numMaskedPics.&lt;br /&gt;
&lt;br /&gt;
Sprites are exactly identical to masked pictures in format except the game cannot stretch or warp them. Most games use these for enemy, player or item graphics during gameplay. They need information from chunk 2, the sprite table both to display correctly and to interact correctly, something more complex than masked pictures.&lt;br /&gt;
&lt;br /&gt;
There are usually several hundred sprite chunks, but [[Catacomb 3D]] only has 3 sprite chunks and they are used for the PaddleWar game (Skulls and Bones). The number of sprite chunks is given in chunk 2.&lt;br /&gt;
&lt;br /&gt;
=== 8x8 tiles ===&lt;br /&gt;
&lt;br /&gt;
8x8 tiles are used by most games in status windows or foe the borders of message windows in-game. (And occasionally by TED5 to display levels.) There are thus not many of them. ALL the masked or unmasked tiles are one single chunk stored as four and five plane [[Raw EGA data]] respectively. The number of 8x8 unmasked and masked tiles is hard-coded into the executable, but can be worked out by dividing the decompressed chunk size by 32 and 40 (The size of one tile&#039;s data) respectively.&lt;br /&gt;
&lt;br /&gt;
=== 16x16 and 32x32 tiles ===&lt;br /&gt;
&lt;br /&gt;
32x32 tiles are optional and rarely used. 16x16 tiles are only occasionally absent and for most games make up the bulk of graphics. There are usually several thousand entries. Both come in masked and unmasked kinds, just like 8x8 tiles.&lt;br /&gt;
&lt;br /&gt;
These chunks have notable differences. Each tile is an individual chunk and stored as four or five plane [[Raw EGA data]] with a plane size of 128 (16x16) or 512 (32x32). These chunks do NOT have a dword specifying their decompressed size as this is hard-coded into the executable as a space saving measure. (As is the start and finish of unmasked and masked tile chunks.) This can cause problems for editing programs.&lt;br /&gt;
&lt;br /&gt;
Tiles make up the bulk of 2D game levels but are seldom seen elsewhere.&lt;br /&gt;
&lt;br /&gt;
=== Misc graphics ===&lt;br /&gt;
&lt;br /&gt;
Sometimes following tile graphics are miscellaneous graphics, that cannot be handled by the other chunk types. For example, Keen 4-6 has two misc graphics files used for the &#039;COOMANDER KEEN terminator text&#039; intro. These graphics usually have unique formats that fit their function and few have been investigated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Keen 4-6 Intro Bitmaps ====&lt;br /&gt;
&lt;br /&gt;
This is the text that displays after the &#039;Ready, press any key&#039; screen at Keen startup. It is composed of a monochrome bitmap that is scrolled across the screen and distorted for special effects. When displayed it is transparent, with a special palette so it is not black-and-white. It consists of a header followed by RLE compressed monochrome data.&lt;br /&gt;
&lt;br /&gt;
 HEADER:&lt;br /&gt;
 0   2    Img height  Height of the image in pixels&lt;br /&gt;
 2   2    Img width   Width of the image in pixels&lt;br /&gt;
 4   2x   Line point  Pointers to line 1,2,3..etc of data. There will be [Img height] of&lt;br /&gt;
                      these, each 2 bytes long. The first pointer will  have the value&lt;br /&gt;
                      (2 * [Img height] + 4)&lt;br /&gt;
 +2  ?    RLE data    RLE-WM compressed data&lt;br /&gt;
&lt;br /&gt;
 DATA:&lt;br /&gt;
 0   2    Black run   Number of black pixels to write&lt;br /&gt;
 2   2    Not-blk run Number of not-black pixels to write&lt;br /&gt;
 4   2    Black run....&lt;br /&gt;
 ...&lt;br /&gt;
 ..&lt;br /&gt;
 .&lt;br /&gt;
 ?  2     End         $FFFF; end of row.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game texts ===&lt;br /&gt;
&lt;br /&gt;
Also known as ANSII chunks, these are used by the game for things like help screens, and have their own format. In the main they are simply text documents, interspersed with various commands to make things happen. Each file is divided up into a number of &#039;pages&#039; which are moved between by pressing the up/down arrows. Pages can also have action sequences (Repeated each time the page is moved to, you cannot leave a page until the sequence finishes.)&lt;br /&gt;
&lt;br /&gt;
 ^P		First command in every file. Defines a page start&lt;br /&gt;
 ^E		Ends the file&lt;br /&gt;
 ^Cx		Change font color to $x until next page or ^C command&lt;br /&gt;
 ^Gx,y,z	Display (unmasked) picture chunk z at location x,y (In pixels)&lt;br /&gt;
 ^Tx,y,z,t	Display picture chunk z at x,y for z clicks of time&lt;br /&gt;
 ^Bx,y,z,t,b	?&lt;br /&gt;
 ^Lx,y		?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Misc files ===&lt;br /&gt;
&lt;br /&gt;
The last few chunks are demo files and occasionally miscellaneous data. Demo file formats are currently unknown but can be recorded using the demo cheat. They contain the level number and difficulty followed by a series of key commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
* [[KeenWiki:ModKeen|ModKeen]] (DOS) and [[KeenWiki:LModKeen|LModKeen]] (Linux/Windows) can be used to modify graphics and text stored in EGAGRAPH.CKx for the Commander Keen [[KeenWiki:Goodbye Galaxy|Goodbye Galaxy]] trilogy.&lt;br /&gt;
&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Commander Keen Dreams]]&lt;br /&gt;
[[Category:Dangerous Dave 3]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Graphics Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3587</id>
		<title>EGAGraph Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3587"/>
		<updated>2011-09-01T06:15:04Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* Masked pictures (Masked bitmaps) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;EGAGraph&#039;&#039;&#039;, short for &#039;EGA graphics library&#039; is the format used to store graphics, demos, fonts, game texts and more in many early [[:Category:Id Software|id Software]] games.&lt;br /&gt;
&lt;br /&gt;
The basic format is that of a number of [[Huffman Compression]] compressed sub-files (Chunks) stored in a similar manner to the [[AudioT Format]]. Like this format it has three main files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt;and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is notable that while the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; are stored in the game executable, they need to be extracted for [[TED5]] to edit levels.&lt;br /&gt;
&lt;br /&gt;
This article may contain errors as some formats have not been worked out completely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= File formats =&lt;br /&gt;
&lt;br /&gt;
== EGA Head (EGAHEAD.xxx) ==&lt;br /&gt;
There are two versions of this format. The first version, used in [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], is an array of 4-byte little-endian values. The second version, used in all later EGA games, is an array of 3-byte unsigned little-endian values.&lt;br /&gt;
&lt;br /&gt;
This header file may be present as an external file (eg. [[Bio Menace]]), or it may be included in the EXE file (eg. [[Catacomb 3D]]). The last entry in the header is always the size of the EGAGRAPH.xxx file, and the first entry in the header is always 00 00 00. To find the end, you can search for filesize(EGAGRAPH.xxx) as a 3-byte (little-endian) value in the EXE. Then to find the start, go back 3 bytes at a time until you get to 00 000 00. Or use the fact that entries always get smaller as you go back, unless the entry is $FFFFFF. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] v1.00 EGAHEAD.C3D is at $1BFD0 from the start of the decompressed ([[unlzexe]]) EXE file, and is 1436 bytes long, or 478 3-byte entries (for 477 chunks). It is then followed by 4 bytes (padding to multiple of 16?) 03 00 00 00, then the MAPHEAD.C3D. &lt;br /&gt;
&lt;br /&gt;
This header file stores the offsets (relative to the start of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file) for each sub file.  The format is trivial, in that the header file is simply an array of 3 or 4 byte variables.  (Each variable is a &amp;quot;slot&amp;quot;, as the game refers to files by index.) Most games use the more compact 3-byte variables, since the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is never larger than $FFFFFF. However games based on older engines, notably [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], use 4-byte vales as these are easier to deal with.&lt;br /&gt;
&lt;br /&gt;
It is important to note that not every &#039;slot&#039; will be in use. Tiles especially if blank (All black) will be considered &#039;empty&#039; and not worth adding to the file. (A blank 16x16 tile takes up 12 bytes of space if compressed, and there can be hundreds.) There are two ways of dealing with this; by default the games set all empty slot headers to -1, but many programs compress the graphics anyway and use a normal header value for them.&lt;br /&gt;
&lt;br /&gt;
The last offset in the file will be an offset to the end of the main &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file.  (So this should be ignored when reading the file to prevent a zero-byte file appearing last.) The total size of the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; divided by 3 (Or 4) will also give the number of &#039;slots&#039; the game uses. This varies, but is usually about 10,000.&lt;br /&gt;
&lt;br /&gt;
Unlike [[AudioT Format]] files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; is always compressed. However the header and dictionary may be external (E.g [[Bio Menace]])&lt;br /&gt;
&lt;br /&gt;
== Dictionary (EGADICT.xxx) ==&lt;br /&gt;
&lt;br /&gt;
The same [[Huffman Compression]] scheme used elsewhere in the [[Commander Keen]] series is used.  When reading compressed files out of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, the first four bytes located at the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; offset are a UINT32LE specifying the file&#039;s decompressed size (which is required for the decompression algorithm.)  The compressed data then follows, EXCEPT for 16x16 masked and unmasked tiles. Since these all have a similar decompressed size (128 bytes for unmasked, 256 bytes for masked) it is a waste of space to include these (Since tiles make up the bulk of graphics slots.) The decompressed size is hard coded, as are the start and finish of the unmasked and masked tile slots.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; file is not often obvious, usually being embedded in the main exe file. It is possible to locate it by looking for the string &amp;lt;tt&amp;gt;$FD $01 $00 $00 $00 $00&amp;lt;/tt&amp;gt;, which appears at the end of nearly all Huffman dictionaries. Executables usually contain two or more dictionaries, but the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; is usually the second one, except in the case of early games like Keen Dreams, where it is the first of THREE. (A simple check of whether it decompresses the data sensibly works.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Main file (EGAGRAPH.xxx) ==&lt;br /&gt;
&lt;br /&gt;
This file is simply an array of data files.  Each file starts at the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, and as there are no filenames each file is referred to by its index/slot number.  Slots containing dummy values in the header are treated as if they don&#039;t exist in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file. Each file within the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is individually compressed.  A file can be read by opening the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, seeking to the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, reading a UINT32LE for the decompressed file size, and then decompressing the data from that point onwards using standard Huffman decompression techniques.&lt;br /&gt;
&lt;br /&gt;
Note that in early games such as Keen Dreams, the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file may have another name. (Such as &amp;lt;tt&amp;gt;KDREAM.EGA&amp;lt;/tt&amp;gt; in that case.) in which case it is always the largest non-executable file.&lt;br /&gt;
&lt;br /&gt;
=== Chunks ===&lt;br /&gt;
&lt;br /&gt;
Each sub file or chunk is a separate graphic, ordered in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file in a specific way, much again like the [[AudioT Format]].  Chunks are labeled starting at 0. The game executable is hard coded for the start and finish of various chunk types. For example, Keen 4 has chunks 124-520 as sprites and will treat any chunk between these two numbers as a sprite. (Note that the game refers to chunk number, not sprite number.) The usual order of chunks is:&lt;br /&gt;
&lt;br /&gt;
 Picture table&lt;br /&gt;
 Masked picture table&lt;br /&gt;
 Sprite table&lt;br /&gt;
 Fonts&lt;br /&gt;
 Pictures (Unmasked bitmaps)&lt;br /&gt;
 Masked pictures&lt;br /&gt;
 8x8 unmasked tiles (Single chunk)&lt;br /&gt;
 8x8 masked tiles (Single chunk)&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 32x32 unmasked tiles (Optional)&lt;br /&gt;
 32x32 masked tiles (Optional)&lt;br /&gt;
 Misc graphics (Optional)&lt;br /&gt;
 Game texts&lt;br /&gt;
 Demo files (Optional)&lt;br /&gt;
 Misc data (Optional)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Chunk formats ==&lt;br /&gt;
&lt;br /&gt;
When compressed each chunk consists of a dword giving the decompressed size followed by the compressed data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the first chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying picture chunks.&lt;br /&gt;
&lt;br /&gt;
Divide the decompressed size by 4 to get numpics.&lt;br /&gt;
&lt;br /&gt;
=== Masked picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the second chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying masked picture chunks. This table is often quite small.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprite table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the third chunk, the picture table is 16 * numspr bytes long, consisting of eight words for each sprite image (Width\8, Height, x offset, y offset and clipping rectangle left, top, right and bottom; all in that order.) used when displaying sprite chunks. This is what Modkeen exports as its notoriously hard to use xSPRITES.txt file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fonts ===&lt;br /&gt;
&lt;br /&gt;
Always present and always starting at the fourth chunk. (Chunk 3!) Each chunk is a single monochrome font, containing all the entries from 0-255 for that font. Each &#039;letter&#039; is stored separately and consecutively. A game will have at least one, and usually 3 fonts. The format is version two of [[EGA Font format]]&lt;br /&gt;
&lt;br /&gt;
Fonts are used in the game for game texts. They can be stretched or colored and are always transparent, meaning they look strange when not over a single-color background.&lt;br /&gt;
&lt;br /&gt;
=== Pictures (Bitmaps) ===&lt;br /&gt;
These follow game fonts. You need to know how many fonts there are before it to know how what chunk number the first picture is (3+NumFonts). In [[Catacomb 3D]] there are 2 fonts.&lt;br /&gt;
&lt;br /&gt;
Bitmaps are stored as standard [[Raw EGA data]], the size of each plane being the decompressed chunk size \ 4. In order to be displayed properly these need information from chunk 0, the picture table. Note that unlike fonts, data does not wrap, so a 4x4 sprite will consist of four planes of four bytes in size, the same as an 8x4 sprite.&lt;br /&gt;
&lt;br /&gt;
Pictures are used for things such as title screens or pictures in game texts. Most of the main menu will consist of pictures. They are also used for the wall textures in EGA FPS games like [[Catacomb 3D]], in which case the wall textures come near the end of the picture list (starting from chunk 137 in [[Catacomb 3D]]).&lt;br /&gt;
&lt;br /&gt;
The number of picture chunks is given in chunk 0, the picture table.&lt;br /&gt;
&lt;br /&gt;
=== Masked pictures (Masked bitmaps) ===&lt;br /&gt;
&lt;br /&gt;
These follow Pictures. You need to know how many fonts there are, to know how what chunk number the first Masked picture is (3+NumFonts+numpics).&lt;br /&gt;
&lt;br /&gt;
These are identical to the picture chunks in every respect, except being masked, they consist of five EGA planes, not four. Some games (E.g [[Catacomb 3D]] make great use of masked pictures, but most games have only one or two. They need information from chunk 1, the masked picture table, to be displayed correctly.&lt;br /&gt;
&lt;br /&gt;
The number of Masked pictures is given in Chunk 1.&lt;br /&gt;
&lt;br /&gt;
=== Sprites ===&lt;br /&gt;
&lt;br /&gt;
Sprites are exactly identical to masked pictures in format except the game cannot stretch or warp them. Most games use these for enemy, player or item graphics during gameplay. They need information from chunk 2, the sprite table both to display correctly and to interact correctly, something more complex than masked pictures. There are usually several hundred sprite chunks.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== 8x8 tiles ===&lt;br /&gt;
&lt;br /&gt;
8x8 tiles are used by most games in status windows or foe the borders of message windows in-game. (And occasionally by TED5 to display levels.) There are thus not many of them. ALL the masked or unmasked tiles are one single chunk stored as four and five plane [[Raw EGA data]] respectively. The number of 8x8 unmasked and masked tiles is hard-coded into the executable, but can be worked out by dividing the decompressed chunk size by 32 and 40 (The size of one tile&#039;s data) respectively.&lt;br /&gt;
&lt;br /&gt;
=== 16x16 and 32x32 tiles ===&lt;br /&gt;
&lt;br /&gt;
32x32 tiles are optional and rarely used. 16x16 tiles are only occasionally absent and for most games make up the bulk of graphics. There are usually several thousand entries. Both come in masked and unmasked kinds, just like 8x8 tiles.&lt;br /&gt;
&lt;br /&gt;
These chunks have notable differences. Each tile is an individual chunk and stored as four or five plane [[Raw EGA data]] with a plane size of 128 (16x16) or 512 (32x32). These chunks do NOT have a dword specifying their decompressed size as this is hard-coded into the executable as a space saving measure. (As is the start and finish of unmasked and masked tile chunks.) This can cause problems for editing programs.&lt;br /&gt;
&lt;br /&gt;
Tiles make up the bulk of 2D game levels but are seldom seen elsewhere.&lt;br /&gt;
&lt;br /&gt;
=== Misc graphics ===&lt;br /&gt;
&lt;br /&gt;
Sometimes following tile graphics are miscellaneous graphics, that cannot be handled by the other chunk types. For example, Keen 4-6 has two misc graphics files used for the &#039;COOMANDER KEEN terminator text&#039; intro. These graphics usually have unique formats that fit their function and few have been investigated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Keen 4-6 Intro Bitmaps ====&lt;br /&gt;
&lt;br /&gt;
This is the text that displays after the &#039;Ready, press any key&#039; screen at Keen startup. It is composed of a monochrome bitmap that is scrolled across the screen and distorted for special effects. When displayed it is transparent, with a special palette so it is not black-and-white. It consists of a header followed by RLE compressed monochrome data.&lt;br /&gt;
&lt;br /&gt;
 HEADER:&lt;br /&gt;
 0   2    Img height  Height of the image in pixels&lt;br /&gt;
 2   2    Img width   Width of the image in pixels&lt;br /&gt;
 4   2x   Line point  Pointers to line 1,2,3..etc of data. There will be [Img height] of&lt;br /&gt;
                      these, each 2 bytes long. The first pointer will  have the value&lt;br /&gt;
                      (2 * [Img height] + 4)&lt;br /&gt;
 +2  ?    RLE data    RLE-WM compressed data&lt;br /&gt;
&lt;br /&gt;
 DATA:&lt;br /&gt;
 0   2    Black run   Number of black pixels to write&lt;br /&gt;
 2   2    Not-blk run Number of not-black pixels to write&lt;br /&gt;
 4   2    Black run....&lt;br /&gt;
 ...&lt;br /&gt;
 ..&lt;br /&gt;
 .&lt;br /&gt;
 ?  2     End         $FFFF; end of row.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game texts ===&lt;br /&gt;
&lt;br /&gt;
Also known as ANSII chunks, these are used by the game for things like help screens, and have their own format. In the main they are simply text documents, interspersed with various commands to make things happen. Each file is divided up into a number of &#039;pages&#039; which are moved between by pressing the up/down arrows. Pages can also have action sequences (Repeated each time the page is moved to, you cannot leave a page until the sequence finishes.)&lt;br /&gt;
&lt;br /&gt;
 ^P		First command in every file. Defines a page start&lt;br /&gt;
 ^E		Ends the file&lt;br /&gt;
 ^Cx		Change font color to $x until next page or ^C command&lt;br /&gt;
 ^Gx,y,z	Display (unmasked) picture chunk z at location x,y (In pixels)&lt;br /&gt;
 ^Tx,y,z,t	Display picture chunk z at x,y for z clicks of time&lt;br /&gt;
 ^Bx,y,z,t,b	?&lt;br /&gt;
 ^Lx,y		?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Misc files ===&lt;br /&gt;
&lt;br /&gt;
The last few chunks are demo files and occasionally miscellaneous data. Demo file formats are currently unknown but can be recorded using the demo cheat. They contain the level number and difficulty followed by a series of key commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
* [[KeenWiki:ModKeen|ModKeen]] (DOS) and [[KeenWiki:LModKeen|LModKeen]] (Linux/Windows) can be used to modify graphics and text stored in EGAGRAPH.CKx for the Commander Keen [[KeenWiki:Goodbye Galaxy|Goodbye Galaxy]] trilogy.&lt;br /&gt;
&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Commander Keen Dreams]]&lt;br /&gt;
[[Category:Dangerous Dave 3]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Graphics Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3586</id>
		<title>EGAGraph Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3586"/>
		<updated>2011-09-01T06:12:38Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* Pictures (Bitmaps) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;EGAGraph&#039;&#039;&#039;, short for &#039;EGA graphics library&#039; is the format used to store graphics, demos, fonts, game texts and more in many early [[:Category:Id Software|id Software]] games.&lt;br /&gt;
&lt;br /&gt;
The basic format is that of a number of [[Huffman Compression]] compressed sub-files (Chunks) stored in a similar manner to the [[AudioT Format]]. Like this format it has three main files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt;and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is notable that while the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; are stored in the game executable, they need to be extracted for [[TED5]] to edit levels.&lt;br /&gt;
&lt;br /&gt;
This article may contain errors as some formats have not been worked out completely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= File formats =&lt;br /&gt;
&lt;br /&gt;
== EGA Head (EGAHEAD.xxx) ==&lt;br /&gt;
There are two versions of this format. The first version, used in [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], is an array of 4-byte little-endian values. The second version, used in all later EGA games, is an array of 3-byte unsigned little-endian values.&lt;br /&gt;
&lt;br /&gt;
This header file may be present as an external file (eg. [[Bio Menace]]), or it may be included in the EXE file (eg. [[Catacomb 3D]]). The last entry in the header is always the size of the EGAGRAPH.xxx file, and the first entry in the header is always 00 00 00. To find the end, you can search for filesize(EGAGRAPH.xxx) as a 3-byte (little-endian) value in the EXE. Then to find the start, go back 3 bytes at a time until you get to 00 000 00. Or use the fact that entries always get smaller as you go back, unless the entry is $FFFFFF. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] v1.00 EGAHEAD.C3D is at $1BFD0 from the start of the decompressed ([[unlzexe]]) EXE file, and is 1436 bytes long, or 478 3-byte entries (for 477 chunks). It is then followed by 4 bytes (padding to multiple of 16?) 03 00 00 00, then the MAPHEAD.C3D. &lt;br /&gt;
&lt;br /&gt;
This header file stores the offsets (relative to the start of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file) for each sub file.  The format is trivial, in that the header file is simply an array of 3 or 4 byte variables.  (Each variable is a &amp;quot;slot&amp;quot;, as the game refers to files by index.) Most games use the more compact 3-byte variables, since the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is never larger than $FFFFFF. However games based on older engines, notably [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], use 4-byte vales as these are easier to deal with.&lt;br /&gt;
&lt;br /&gt;
It is important to note that not every &#039;slot&#039; will be in use. Tiles especially if blank (All black) will be considered &#039;empty&#039; and not worth adding to the file. (A blank 16x16 tile takes up 12 bytes of space if compressed, and there can be hundreds.) There are two ways of dealing with this; by default the games set all empty slot headers to -1, but many programs compress the graphics anyway and use a normal header value for them.&lt;br /&gt;
&lt;br /&gt;
The last offset in the file will be an offset to the end of the main &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file.  (So this should be ignored when reading the file to prevent a zero-byte file appearing last.) The total size of the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; divided by 3 (Or 4) will also give the number of &#039;slots&#039; the game uses. This varies, but is usually about 10,000.&lt;br /&gt;
&lt;br /&gt;
Unlike [[AudioT Format]] files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; is always compressed. However the header and dictionary may be external (E.g [[Bio Menace]])&lt;br /&gt;
&lt;br /&gt;
== Dictionary (EGADICT.xxx) ==&lt;br /&gt;
&lt;br /&gt;
The same [[Huffman Compression]] scheme used elsewhere in the [[Commander Keen]] series is used.  When reading compressed files out of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, the first four bytes located at the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; offset are a UINT32LE specifying the file&#039;s decompressed size (which is required for the decompression algorithm.)  The compressed data then follows, EXCEPT for 16x16 masked and unmasked tiles. Since these all have a similar decompressed size (128 bytes for unmasked, 256 bytes for masked) it is a waste of space to include these (Since tiles make up the bulk of graphics slots.) The decompressed size is hard coded, as are the start and finish of the unmasked and masked tile slots.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; file is not often obvious, usually being embedded in the main exe file. It is possible to locate it by looking for the string &amp;lt;tt&amp;gt;$FD $01 $00 $00 $00 $00&amp;lt;/tt&amp;gt;, which appears at the end of nearly all Huffman dictionaries. Executables usually contain two or more dictionaries, but the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; is usually the second one, except in the case of early games like Keen Dreams, where it is the first of THREE. (A simple check of whether it decompresses the data sensibly works.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Main file (EGAGRAPH.xxx) ==&lt;br /&gt;
&lt;br /&gt;
This file is simply an array of data files.  Each file starts at the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, and as there are no filenames each file is referred to by its index/slot number.  Slots containing dummy values in the header are treated as if they don&#039;t exist in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file. Each file within the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is individually compressed.  A file can be read by opening the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, seeking to the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, reading a UINT32LE for the decompressed file size, and then decompressing the data from that point onwards using standard Huffman decompression techniques.&lt;br /&gt;
&lt;br /&gt;
Note that in early games such as Keen Dreams, the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file may have another name. (Such as &amp;lt;tt&amp;gt;KDREAM.EGA&amp;lt;/tt&amp;gt; in that case.) in which case it is always the largest non-executable file.&lt;br /&gt;
&lt;br /&gt;
=== Chunks ===&lt;br /&gt;
&lt;br /&gt;
Each sub file or chunk is a separate graphic, ordered in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file in a specific way, much again like the [[AudioT Format]].  Chunks are labeled starting at 0. The game executable is hard coded for the start and finish of various chunk types. For example, Keen 4 has chunks 124-520 as sprites and will treat any chunk between these two numbers as a sprite. (Note that the game refers to chunk number, not sprite number.) The usual order of chunks is:&lt;br /&gt;
&lt;br /&gt;
 Picture table&lt;br /&gt;
 Masked picture table&lt;br /&gt;
 Sprite table&lt;br /&gt;
 Fonts&lt;br /&gt;
 Pictures (Unmasked bitmaps)&lt;br /&gt;
 Masked pictures&lt;br /&gt;
 8x8 unmasked tiles (Single chunk)&lt;br /&gt;
 8x8 masked tiles (Single chunk)&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 32x32 unmasked tiles (Optional)&lt;br /&gt;
 32x32 masked tiles (Optional)&lt;br /&gt;
 Misc graphics (Optional)&lt;br /&gt;
 Game texts&lt;br /&gt;
 Demo files (Optional)&lt;br /&gt;
 Misc data (Optional)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Chunk formats ==&lt;br /&gt;
&lt;br /&gt;
When compressed each chunk consists of a dword giving the decompressed size followed by the compressed data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the first chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying picture chunks.&lt;br /&gt;
&lt;br /&gt;
Divide the decompressed size by 4 to get numpics.&lt;br /&gt;
&lt;br /&gt;
=== Masked picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the second chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying masked picture chunks. This table is often quite small.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprite table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the third chunk, the picture table is 16 * numspr bytes long, consisting of eight words for each sprite image (Width\8, Height, x offset, y offset and clipping rectangle left, top, right and bottom; all in that order.) used when displaying sprite chunks. This is what Modkeen exports as its notoriously hard to use xSPRITES.txt file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fonts ===&lt;br /&gt;
&lt;br /&gt;
Always present and always starting at the fourth chunk. (Chunk 3!) Each chunk is a single monochrome font, containing all the entries from 0-255 for that font. Each &#039;letter&#039; is stored separately and consecutively. A game will have at least one, and usually 3 fonts. The format is version two of [[EGA Font format]]&lt;br /&gt;
&lt;br /&gt;
Fonts are used in the game for game texts. They can be stretched or colored and are always transparent, meaning they look strange when not over a single-color background.&lt;br /&gt;
&lt;br /&gt;
=== Pictures (Bitmaps) ===&lt;br /&gt;
These follow game fonts. You need to know how many fonts there are before it to know how what chunk number the first picture is (3+NumFonts). In [[Catacomb 3D]] there are 2 fonts.&lt;br /&gt;
&lt;br /&gt;
Bitmaps are stored as standard [[Raw EGA data]], the size of each plane being the decompressed chunk size \ 4. In order to be displayed properly these need information from chunk 0, the picture table. Note that unlike fonts, data does not wrap, so a 4x4 sprite will consist of four planes of four bytes in size, the same as an 8x4 sprite.&lt;br /&gt;
&lt;br /&gt;
Pictures are used for things such as title screens or pictures in game texts. Most of the main menu will consist of pictures. They are also used for the wall textures in EGA FPS games like [[Catacomb 3D]], in which case the wall textures come near the end of the picture list (starting from chunk 137 in [[Catacomb 3D]]).&lt;br /&gt;
&lt;br /&gt;
The number of picture chunks is given in chunk 0, the picture table.&lt;br /&gt;
&lt;br /&gt;
=== Masked pictures (Masked bitmaps) ===&lt;br /&gt;
&lt;br /&gt;
These are identical to the picture chunks in every respect, except being masked, they consist of five EGA planes, not four. Some games (E.g [[Catacomb 3D]] make great use of masked pictures, but most games have only one or two. They need information from chunk 1, the masked picture table, to be displayed correctly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprites ===&lt;br /&gt;
&lt;br /&gt;
Sprites are exactly identical to masked pictures in format except the game cannot stretch or warp them. Most games use these for enemy, player or item graphics during gameplay. They need information from chunk 2, the sprite table both to display correctly and to interact correctly, something more complex than masked pictures. There are usually several hundred sprite chunks.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== 8x8 tiles ===&lt;br /&gt;
&lt;br /&gt;
8x8 tiles are used by most games in status windows or foe the borders of message windows in-game. (And occasionally by TED5 to display levels.) There are thus not many of them. ALL the masked or unmasked tiles are one single chunk stored as four and five plane [[Raw EGA data]] respectively. The number of 8x8 unmasked and masked tiles is hard-coded into the executable, but can be worked out by dividing the decompressed chunk size by 32 and 40 (The size of one tile&#039;s data) respectively.&lt;br /&gt;
&lt;br /&gt;
=== 16x16 and 32x32 tiles ===&lt;br /&gt;
&lt;br /&gt;
32x32 tiles are optional and rarely used. 16x16 tiles are only occasionally absent and for most games make up the bulk of graphics. There are usually several thousand entries. Both come in masked and unmasked kinds, just like 8x8 tiles.&lt;br /&gt;
&lt;br /&gt;
These chunks have notable differences. Each tile is an individual chunk and stored as four or five plane [[Raw EGA data]] with a plane size of 128 (16x16) or 512 (32x32). These chunks do NOT have a dword specifying their decompressed size as this is hard-coded into the executable as a space saving measure. (As is the start and finish of unmasked and masked tile chunks.) This can cause problems for editing programs.&lt;br /&gt;
&lt;br /&gt;
Tiles make up the bulk of 2D game levels but are seldom seen elsewhere.&lt;br /&gt;
&lt;br /&gt;
=== Misc graphics ===&lt;br /&gt;
&lt;br /&gt;
Sometimes following tile graphics are miscellaneous graphics, that cannot be handled by the other chunk types. For example, Keen 4-6 has two misc graphics files used for the &#039;COOMANDER KEEN terminator text&#039; intro. These graphics usually have unique formats that fit their function and few have been investigated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Keen 4-6 Intro Bitmaps ====&lt;br /&gt;
&lt;br /&gt;
This is the text that displays after the &#039;Ready, press any key&#039; screen at Keen startup. It is composed of a monochrome bitmap that is scrolled across the screen and distorted for special effects. When displayed it is transparent, with a special palette so it is not black-and-white. It consists of a header followed by RLE compressed monochrome data.&lt;br /&gt;
&lt;br /&gt;
 HEADER:&lt;br /&gt;
 0   2    Img height  Height of the image in pixels&lt;br /&gt;
 2   2    Img width   Width of the image in pixels&lt;br /&gt;
 4   2x   Line point  Pointers to line 1,2,3..etc of data. There will be [Img height] of&lt;br /&gt;
                      these, each 2 bytes long. The first pointer will  have the value&lt;br /&gt;
                      (2 * [Img height] + 4)&lt;br /&gt;
 +2  ?    RLE data    RLE-WM compressed data&lt;br /&gt;
&lt;br /&gt;
 DATA:&lt;br /&gt;
 0   2    Black run   Number of black pixels to write&lt;br /&gt;
 2   2    Not-blk run Number of not-black pixels to write&lt;br /&gt;
 4   2    Black run....&lt;br /&gt;
 ...&lt;br /&gt;
 ..&lt;br /&gt;
 .&lt;br /&gt;
 ?  2     End         $FFFF; end of row.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game texts ===&lt;br /&gt;
&lt;br /&gt;
Also known as ANSII chunks, these are used by the game for things like help screens, and have their own format. In the main they are simply text documents, interspersed with various commands to make things happen. Each file is divided up into a number of &#039;pages&#039; which are moved between by pressing the up/down arrows. Pages can also have action sequences (Repeated each time the page is moved to, you cannot leave a page until the sequence finishes.)&lt;br /&gt;
&lt;br /&gt;
 ^P		First command in every file. Defines a page start&lt;br /&gt;
 ^E		Ends the file&lt;br /&gt;
 ^Cx		Change font color to $x until next page or ^C command&lt;br /&gt;
 ^Gx,y,z	Display (unmasked) picture chunk z at location x,y (In pixels)&lt;br /&gt;
 ^Tx,y,z,t	Display picture chunk z at x,y for z clicks of time&lt;br /&gt;
 ^Bx,y,z,t,b	?&lt;br /&gt;
 ^Lx,y		?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Misc files ===&lt;br /&gt;
&lt;br /&gt;
The last few chunks are demo files and occasionally miscellaneous data. Demo file formats are currently unknown but can be recorded using the demo cheat. They contain the level number and difficulty followed by a series of key commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
* [[KeenWiki:ModKeen|ModKeen]] (DOS) and [[KeenWiki:LModKeen|LModKeen]] (Linux/Windows) can be used to modify graphics and text stored in EGAGRAPH.CKx for the Commander Keen [[KeenWiki:Goodbye Galaxy|Goodbye Galaxy]] trilogy.&lt;br /&gt;
&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Commander Keen Dreams]]&lt;br /&gt;
[[Category:Dangerous Dave 3]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Graphics Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3585</id>
		<title>EGAGraph Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3585"/>
		<updated>2011-09-01T06:11:00Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* Picture table */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;EGAGraph&#039;&#039;&#039;, short for &#039;EGA graphics library&#039; is the format used to store graphics, demos, fonts, game texts and more in many early [[:Category:Id Software|id Software]] games.&lt;br /&gt;
&lt;br /&gt;
The basic format is that of a number of [[Huffman Compression]] compressed sub-files (Chunks) stored in a similar manner to the [[AudioT Format]]. Like this format it has three main files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt;and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is notable that while the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; are stored in the game executable, they need to be extracted for [[TED5]] to edit levels.&lt;br /&gt;
&lt;br /&gt;
This article may contain errors as some formats have not been worked out completely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= File formats =&lt;br /&gt;
&lt;br /&gt;
== EGA Head (EGAHEAD.xxx) ==&lt;br /&gt;
There are two versions of this format. The first version, used in [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], is an array of 4-byte little-endian values. The second version, used in all later EGA games, is an array of 3-byte unsigned little-endian values.&lt;br /&gt;
&lt;br /&gt;
This header file may be present as an external file (eg. [[Bio Menace]]), or it may be included in the EXE file (eg. [[Catacomb 3D]]). The last entry in the header is always the size of the EGAGRAPH.xxx file, and the first entry in the header is always 00 00 00. To find the end, you can search for filesize(EGAGRAPH.xxx) as a 3-byte (little-endian) value in the EXE. Then to find the start, go back 3 bytes at a time until you get to 00 000 00. Or use the fact that entries always get smaller as you go back, unless the entry is $FFFFFF. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] v1.00 EGAHEAD.C3D is at $1BFD0 from the start of the decompressed ([[unlzexe]]) EXE file, and is 1436 bytes long, or 478 3-byte entries (for 477 chunks). It is then followed by 4 bytes (padding to multiple of 16?) 03 00 00 00, then the MAPHEAD.C3D. &lt;br /&gt;
&lt;br /&gt;
This header file stores the offsets (relative to the start of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file) for each sub file.  The format is trivial, in that the header file is simply an array of 3 or 4 byte variables.  (Each variable is a &amp;quot;slot&amp;quot;, as the game refers to files by index.) Most games use the more compact 3-byte variables, since the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is never larger than $FFFFFF. However games based on older engines, notably [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], use 4-byte vales as these are easier to deal with.&lt;br /&gt;
&lt;br /&gt;
It is important to note that not every &#039;slot&#039; will be in use. Tiles especially if blank (All black) will be considered &#039;empty&#039; and not worth adding to the file. (A blank 16x16 tile takes up 12 bytes of space if compressed, and there can be hundreds.) There are two ways of dealing with this; by default the games set all empty slot headers to -1, but many programs compress the graphics anyway and use a normal header value for them.&lt;br /&gt;
&lt;br /&gt;
The last offset in the file will be an offset to the end of the main &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file.  (So this should be ignored when reading the file to prevent a zero-byte file appearing last.) The total size of the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; divided by 3 (Or 4) will also give the number of &#039;slots&#039; the game uses. This varies, but is usually about 10,000.&lt;br /&gt;
&lt;br /&gt;
Unlike [[AudioT Format]] files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; is always compressed. However the header and dictionary may be external (E.g [[Bio Menace]])&lt;br /&gt;
&lt;br /&gt;
== Dictionary (EGADICT.xxx) ==&lt;br /&gt;
&lt;br /&gt;
The same [[Huffman Compression]] scheme used elsewhere in the [[Commander Keen]] series is used.  When reading compressed files out of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, the first four bytes located at the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; offset are a UINT32LE specifying the file&#039;s decompressed size (which is required for the decompression algorithm.)  The compressed data then follows, EXCEPT for 16x16 masked and unmasked tiles. Since these all have a similar decompressed size (128 bytes for unmasked, 256 bytes for masked) it is a waste of space to include these (Since tiles make up the bulk of graphics slots.) The decompressed size is hard coded, as are the start and finish of the unmasked and masked tile slots.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; file is not often obvious, usually being embedded in the main exe file. It is possible to locate it by looking for the string &amp;lt;tt&amp;gt;$FD $01 $00 $00 $00 $00&amp;lt;/tt&amp;gt;, which appears at the end of nearly all Huffman dictionaries. Executables usually contain two or more dictionaries, but the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; is usually the second one, except in the case of early games like Keen Dreams, where it is the first of THREE. (A simple check of whether it decompresses the data sensibly works.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Main file (EGAGRAPH.xxx) ==&lt;br /&gt;
&lt;br /&gt;
This file is simply an array of data files.  Each file starts at the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, and as there are no filenames each file is referred to by its index/slot number.  Slots containing dummy values in the header are treated as if they don&#039;t exist in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file. Each file within the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is individually compressed.  A file can be read by opening the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, seeking to the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, reading a UINT32LE for the decompressed file size, and then decompressing the data from that point onwards using standard Huffman decompression techniques.&lt;br /&gt;
&lt;br /&gt;
Note that in early games such as Keen Dreams, the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file may have another name. (Such as &amp;lt;tt&amp;gt;KDREAM.EGA&amp;lt;/tt&amp;gt; in that case.) in which case it is always the largest non-executable file.&lt;br /&gt;
&lt;br /&gt;
=== Chunks ===&lt;br /&gt;
&lt;br /&gt;
Each sub file or chunk is a separate graphic, ordered in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file in a specific way, much again like the [[AudioT Format]].  Chunks are labeled starting at 0. The game executable is hard coded for the start and finish of various chunk types. For example, Keen 4 has chunks 124-520 as sprites and will treat any chunk between these two numbers as a sprite. (Note that the game refers to chunk number, not sprite number.) The usual order of chunks is:&lt;br /&gt;
&lt;br /&gt;
 Picture table&lt;br /&gt;
 Masked picture table&lt;br /&gt;
 Sprite table&lt;br /&gt;
 Fonts&lt;br /&gt;
 Pictures (Unmasked bitmaps)&lt;br /&gt;
 Masked pictures&lt;br /&gt;
 8x8 unmasked tiles (Single chunk)&lt;br /&gt;
 8x8 masked tiles (Single chunk)&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 32x32 unmasked tiles (Optional)&lt;br /&gt;
 32x32 masked tiles (Optional)&lt;br /&gt;
 Misc graphics (Optional)&lt;br /&gt;
 Game texts&lt;br /&gt;
 Demo files (Optional)&lt;br /&gt;
 Misc data (Optional)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Chunk formats ==&lt;br /&gt;
&lt;br /&gt;
When compressed each chunk consists of a dword giving the decompressed size followed by the compressed data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the first chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying picture chunks.&lt;br /&gt;
&lt;br /&gt;
Divide the decompressed size by 4 to get numpics.&lt;br /&gt;
&lt;br /&gt;
=== Masked picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the second chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying masked picture chunks. This table is often quite small.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprite table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the third chunk, the picture table is 16 * numspr bytes long, consisting of eight words for each sprite image (Width\8, Height, x offset, y offset and clipping rectangle left, top, right and bottom; all in that order.) used when displaying sprite chunks. This is what Modkeen exports as its notoriously hard to use xSPRITES.txt file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fonts ===&lt;br /&gt;
&lt;br /&gt;
Always present and always starting at the fourth chunk. (Chunk 3!) Each chunk is a single monochrome font, containing all the entries from 0-255 for that font. Each &#039;letter&#039; is stored separately and consecutively. A game will have at least one, and usually 3 fonts. The format is version two of [[EGA Font format]]&lt;br /&gt;
&lt;br /&gt;
Fonts are used in the game for game texts. They can be stretched or colored and are always transparent, meaning they look strange when not over a single-color background.&lt;br /&gt;
&lt;br /&gt;
=== Pictures (Bitmaps) ===&lt;br /&gt;
These follow game fonts. You need to know how many fonts there are before it to know how what chunk number the first picture is (4+NumFonts). In [[Catacomb 3D]] there are 2 fonts.&lt;br /&gt;
&lt;br /&gt;
Bitmaps are stored as standard [[Raw EGA data]], the size of each plane being the decompressed chunk size \ 4. In order to be displayed properly these need information from chunk 0, the picture table. Note that unlike fonts, data does not wrap, so a 4x4 sprite will consist of four planes of four bytes in size, the same as an 8x4 sprite.&lt;br /&gt;
&lt;br /&gt;
Pictures are used for things such as title screens or pictures in game texts. Most of the main menu will consist of pictures. They are also used for the wall textures in EGA FPS games like [[Catacomb 3D]], in which case the wall textures come near the end of the picture list (starting from chunk 137 in [[Catacomb 3D]]).&lt;br /&gt;
&lt;br /&gt;
The number of picture chunks is given in chunk 0, the picture table.&lt;br /&gt;
&lt;br /&gt;
=== Masked pictures (Masked bitmaps) ===&lt;br /&gt;
&lt;br /&gt;
These are identical to the picture chunks in every respect, except being masked, they consist of five EGA planes, not four. Some games (E.g [[Catacomb 3D]] make great use of masked pictures, but most games have only one or two. They need information from chunk 1, the masked picture table, to be displayed correctly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprites ===&lt;br /&gt;
&lt;br /&gt;
Sprites are exactly identical to masked pictures in format except the game cannot stretch or warp them. Most games use these for enemy, player or item graphics during gameplay. They need information from chunk 2, the sprite table both to display correctly and to interact correctly, something more complex than masked pictures. There are usually several hundred sprite chunks.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== 8x8 tiles ===&lt;br /&gt;
&lt;br /&gt;
8x8 tiles are used by most games in status windows or foe the borders of message windows in-game. (And occasionally by TED5 to display levels.) There are thus not many of them. ALL the masked or unmasked tiles are one single chunk stored as four and five plane [[Raw EGA data]] respectively. The number of 8x8 unmasked and masked tiles is hard-coded into the executable, but can be worked out by dividing the decompressed chunk size by 32 and 40 (The size of one tile&#039;s data) respectively.&lt;br /&gt;
&lt;br /&gt;
=== 16x16 and 32x32 tiles ===&lt;br /&gt;
&lt;br /&gt;
32x32 tiles are optional and rarely used. 16x16 tiles are only occasionally absent and for most games make up the bulk of graphics. There are usually several thousand entries. Both come in masked and unmasked kinds, just like 8x8 tiles.&lt;br /&gt;
&lt;br /&gt;
These chunks have notable differences. Each tile is an individual chunk and stored as four or five plane [[Raw EGA data]] with a plane size of 128 (16x16) or 512 (32x32). These chunks do NOT have a dword specifying their decompressed size as this is hard-coded into the executable as a space saving measure. (As is the start and finish of unmasked and masked tile chunks.) This can cause problems for editing programs.&lt;br /&gt;
&lt;br /&gt;
Tiles make up the bulk of 2D game levels but are seldom seen elsewhere.&lt;br /&gt;
&lt;br /&gt;
=== Misc graphics ===&lt;br /&gt;
&lt;br /&gt;
Sometimes following tile graphics are miscellaneous graphics, that cannot be handled by the other chunk types. For example, Keen 4-6 has two misc graphics files used for the &#039;COOMANDER KEEN terminator text&#039; intro. These graphics usually have unique formats that fit their function and few have been investigated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Keen 4-6 Intro Bitmaps ====&lt;br /&gt;
&lt;br /&gt;
This is the text that displays after the &#039;Ready, press any key&#039; screen at Keen startup. It is composed of a monochrome bitmap that is scrolled across the screen and distorted for special effects. When displayed it is transparent, with a special palette so it is not black-and-white. It consists of a header followed by RLE compressed monochrome data.&lt;br /&gt;
&lt;br /&gt;
 HEADER:&lt;br /&gt;
 0   2    Img height  Height of the image in pixels&lt;br /&gt;
 2   2    Img width   Width of the image in pixels&lt;br /&gt;
 4   2x   Line point  Pointers to line 1,2,3..etc of data. There will be [Img height] of&lt;br /&gt;
                      these, each 2 bytes long. The first pointer will  have the value&lt;br /&gt;
                      (2 * [Img height] + 4)&lt;br /&gt;
 +2  ?    RLE data    RLE-WM compressed data&lt;br /&gt;
&lt;br /&gt;
 DATA:&lt;br /&gt;
 0   2    Black run   Number of black pixels to write&lt;br /&gt;
 2   2    Not-blk run Number of not-black pixels to write&lt;br /&gt;
 4   2    Black run....&lt;br /&gt;
 ...&lt;br /&gt;
 ..&lt;br /&gt;
 .&lt;br /&gt;
 ?  2     End         $FFFF; end of row.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game texts ===&lt;br /&gt;
&lt;br /&gt;
Also known as ANSII chunks, these are used by the game for things like help screens, and have their own format. In the main they are simply text documents, interspersed with various commands to make things happen. Each file is divided up into a number of &#039;pages&#039; which are moved between by pressing the up/down arrows. Pages can also have action sequences (Repeated each time the page is moved to, you cannot leave a page until the sequence finishes.)&lt;br /&gt;
&lt;br /&gt;
 ^P		First command in every file. Defines a page start&lt;br /&gt;
 ^E		Ends the file&lt;br /&gt;
 ^Cx		Change font color to $x until next page or ^C command&lt;br /&gt;
 ^Gx,y,z	Display (unmasked) picture chunk z at location x,y (In pixels)&lt;br /&gt;
 ^Tx,y,z,t	Display picture chunk z at x,y for z clicks of time&lt;br /&gt;
 ^Bx,y,z,t,b	?&lt;br /&gt;
 ^Lx,y		?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Misc files ===&lt;br /&gt;
&lt;br /&gt;
The last few chunks are demo files and occasionally miscellaneous data. Demo file formats are currently unknown but can be recorded using the demo cheat. They contain the level number and difficulty followed by a series of key commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
* [[KeenWiki:ModKeen|ModKeen]] (DOS) and [[KeenWiki:LModKeen|LModKeen]] (Linux/Windows) can be used to modify graphics and text stored in EGAGRAPH.CKx for the Commander Keen [[KeenWiki:Goodbye Galaxy|Goodbye Galaxy]] trilogy.&lt;br /&gt;
&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Commander Keen Dreams]]&lt;br /&gt;
[[Category:Dangerous Dave 3]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Graphics Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3584</id>
		<title>EGAGraph Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3584"/>
		<updated>2011-09-01T06:07:49Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* Pictures (Bitmaps) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;EGAGraph&#039;&#039;&#039;, short for &#039;EGA graphics library&#039; is the format used to store graphics, demos, fonts, game texts and more in many early [[:Category:Id Software|id Software]] games.&lt;br /&gt;
&lt;br /&gt;
The basic format is that of a number of [[Huffman Compression]] compressed sub-files (Chunks) stored in a similar manner to the [[AudioT Format]]. Like this format it has three main files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt;and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is notable that while the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; are stored in the game executable, they need to be extracted for [[TED5]] to edit levels.&lt;br /&gt;
&lt;br /&gt;
This article may contain errors as some formats have not been worked out completely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= File formats =&lt;br /&gt;
&lt;br /&gt;
== EGA Head (EGAHEAD.xxx) ==&lt;br /&gt;
There are two versions of this format. The first version, used in [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], is an array of 4-byte little-endian values. The second version, used in all later EGA games, is an array of 3-byte unsigned little-endian values.&lt;br /&gt;
&lt;br /&gt;
This header file may be present as an external file (eg. [[Bio Menace]]), or it may be included in the EXE file (eg. [[Catacomb 3D]]). The last entry in the header is always the size of the EGAGRAPH.xxx file, and the first entry in the header is always 00 00 00. To find the end, you can search for filesize(EGAGRAPH.xxx) as a 3-byte (little-endian) value in the EXE. Then to find the start, go back 3 bytes at a time until you get to 00 000 00. Or use the fact that entries always get smaller as you go back, unless the entry is $FFFFFF. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] v1.00 EGAHEAD.C3D is at $1BFD0 from the start of the decompressed ([[unlzexe]]) EXE file, and is 1436 bytes long, or 478 3-byte entries (for 477 chunks). It is then followed by 4 bytes (padding to multiple of 16?) 03 00 00 00, then the MAPHEAD.C3D. &lt;br /&gt;
&lt;br /&gt;
This header file stores the offsets (relative to the start of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file) for each sub file.  The format is trivial, in that the header file is simply an array of 3 or 4 byte variables.  (Each variable is a &amp;quot;slot&amp;quot;, as the game refers to files by index.) Most games use the more compact 3-byte variables, since the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is never larger than $FFFFFF. However games based on older engines, notably [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], use 4-byte vales as these are easier to deal with.&lt;br /&gt;
&lt;br /&gt;
It is important to note that not every &#039;slot&#039; will be in use. Tiles especially if blank (All black) will be considered &#039;empty&#039; and not worth adding to the file. (A blank 16x16 tile takes up 12 bytes of space if compressed, and there can be hundreds.) There are two ways of dealing with this; by default the games set all empty slot headers to -1, but many programs compress the graphics anyway and use a normal header value for them.&lt;br /&gt;
&lt;br /&gt;
The last offset in the file will be an offset to the end of the main &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file.  (So this should be ignored when reading the file to prevent a zero-byte file appearing last.) The total size of the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; divided by 3 (Or 4) will also give the number of &#039;slots&#039; the game uses. This varies, but is usually about 10,000.&lt;br /&gt;
&lt;br /&gt;
Unlike [[AudioT Format]] files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; is always compressed. However the header and dictionary may be external (E.g [[Bio Menace]])&lt;br /&gt;
&lt;br /&gt;
== Dictionary (EGADICT.xxx) ==&lt;br /&gt;
&lt;br /&gt;
The same [[Huffman Compression]] scheme used elsewhere in the [[Commander Keen]] series is used.  When reading compressed files out of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, the first four bytes located at the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; offset are a UINT32LE specifying the file&#039;s decompressed size (which is required for the decompression algorithm.)  The compressed data then follows, EXCEPT for 16x16 masked and unmasked tiles. Since these all have a similar decompressed size (128 bytes for unmasked, 256 bytes for masked) it is a waste of space to include these (Since tiles make up the bulk of graphics slots.) The decompressed size is hard coded, as are the start and finish of the unmasked and masked tile slots.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; file is not often obvious, usually being embedded in the main exe file. It is possible to locate it by looking for the string &amp;lt;tt&amp;gt;$FD $01 $00 $00 $00 $00&amp;lt;/tt&amp;gt;, which appears at the end of nearly all Huffman dictionaries. Executables usually contain two or more dictionaries, but the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; is usually the second one, except in the case of early games like Keen Dreams, where it is the first of THREE. (A simple check of whether it decompresses the data sensibly works.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Main file (EGAGRAPH.xxx) ==&lt;br /&gt;
&lt;br /&gt;
This file is simply an array of data files.  Each file starts at the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, and as there are no filenames each file is referred to by its index/slot number.  Slots containing dummy values in the header are treated as if they don&#039;t exist in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file. Each file within the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is individually compressed.  A file can be read by opening the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, seeking to the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, reading a UINT32LE for the decompressed file size, and then decompressing the data from that point onwards using standard Huffman decompression techniques.&lt;br /&gt;
&lt;br /&gt;
Note that in early games such as Keen Dreams, the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file may have another name. (Such as &amp;lt;tt&amp;gt;KDREAM.EGA&amp;lt;/tt&amp;gt; in that case.) in which case it is always the largest non-executable file.&lt;br /&gt;
&lt;br /&gt;
=== Chunks ===&lt;br /&gt;
&lt;br /&gt;
Each sub file or chunk is a separate graphic, ordered in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file in a specific way, much again like the [[AudioT Format]].  Chunks are labeled starting at 0. The game executable is hard coded for the start and finish of various chunk types. For example, Keen 4 has chunks 124-520 as sprites and will treat any chunk between these two numbers as a sprite. (Note that the game refers to chunk number, not sprite number.) The usual order of chunks is:&lt;br /&gt;
&lt;br /&gt;
 Picture table&lt;br /&gt;
 Masked picture table&lt;br /&gt;
 Sprite table&lt;br /&gt;
 Fonts&lt;br /&gt;
 Pictures (Unmasked bitmaps)&lt;br /&gt;
 Masked pictures&lt;br /&gt;
 8x8 unmasked tiles (Single chunk)&lt;br /&gt;
 8x8 masked tiles (Single chunk)&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 32x32 unmasked tiles (Optional)&lt;br /&gt;
 32x32 masked tiles (Optional)&lt;br /&gt;
 Misc graphics (Optional)&lt;br /&gt;
 Game texts&lt;br /&gt;
 Demo files (Optional)&lt;br /&gt;
 Misc data (Optional)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Chunk formats ==&lt;br /&gt;
&lt;br /&gt;
When compressed each chunk consists of a dword giving the decompressed size followed by the compressed data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the first chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying picture chunks.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Masked picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the second chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying masked picture chunks. This table is often quite small.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprite table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the third chunk, the picture table is 16 * numspr bytes long, consisting of eight words for each sprite image (Width\8, Height, x offset, y offset and clipping rectangle left, top, right and bottom; all in that order.) used when displaying sprite chunks. This is what Modkeen exports as its notoriously hard to use xSPRITES.txt file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fonts ===&lt;br /&gt;
&lt;br /&gt;
Always present and always starting at the fourth chunk. (Chunk 3!) Each chunk is a single monochrome font, containing all the entries from 0-255 for that font. Each &#039;letter&#039; is stored separately and consecutively. A game will have at least one, and usually 3 fonts. The format is version two of [[EGA Font format]]&lt;br /&gt;
&lt;br /&gt;
Fonts are used in the game for game texts. They can be stretched or colored and are always transparent, meaning they look strange when not over a single-color background.&lt;br /&gt;
&lt;br /&gt;
=== Pictures (Bitmaps) ===&lt;br /&gt;
These follow game fonts. You need to know how many fonts there are before it to know how what chunk number the first picture is (4+NumFonts). In [[Catacomb 3D]] there are 2 fonts.&lt;br /&gt;
&lt;br /&gt;
Bitmaps are stored as standard [[Raw EGA data]], the size of each plane being the decompressed chunk size \ 4. In order to be displayed properly these need information from chunk 0, the picture table. Note that unlike fonts, data does not wrap, so a 4x4 sprite will consist of four planes of four bytes in size, the same as an 8x4 sprite.&lt;br /&gt;
&lt;br /&gt;
Pictures are used for things such as title screens or pictures in game texts. Most of the main menu will consist of pictures. They are also used for the wall textures in EGA FPS games like [[Catacomb 3D]], in which case the wall textures come near the end of the picture list (starting from chunk 137 in [[Catacomb 3D]]).&lt;br /&gt;
&lt;br /&gt;
The number of picture chunks is given in chunk 0, the picture table.&lt;br /&gt;
&lt;br /&gt;
=== Masked pictures (Masked bitmaps) ===&lt;br /&gt;
&lt;br /&gt;
These are identical to the picture chunks in every respect, except being masked, they consist of five EGA planes, not four. Some games (E.g [[Catacomb 3D]] make great use of masked pictures, but most games have only one or two. They need information from chunk 1, the masked picture table, to be displayed correctly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprites ===&lt;br /&gt;
&lt;br /&gt;
Sprites are exactly identical to masked pictures in format except the game cannot stretch or warp them. Most games use these for enemy, player or item graphics during gameplay. They need information from chunk 2, the sprite table both to display correctly and to interact correctly, something more complex than masked pictures. There are usually several hundred sprite chunks.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== 8x8 tiles ===&lt;br /&gt;
&lt;br /&gt;
8x8 tiles are used by most games in status windows or foe the borders of message windows in-game. (And occasionally by TED5 to display levels.) There are thus not many of them. ALL the masked or unmasked tiles are one single chunk stored as four and five plane [[Raw EGA data]] respectively. The number of 8x8 unmasked and masked tiles is hard-coded into the executable, but can be worked out by dividing the decompressed chunk size by 32 and 40 (The size of one tile&#039;s data) respectively.&lt;br /&gt;
&lt;br /&gt;
=== 16x16 and 32x32 tiles ===&lt;br /&gt;
&lt;br /&gt;
32x32 tiles are optional and rarely used. 16x16 tiles are only occasionally absent and for most games make up the bulk of graphics. There are usually several thousand entries. Both come in masked and unmasked kinds, just like 8x8 tiles.&lt;br /&gt;
&lt;br /&gt;
These chunks have notable differences. Each tile is an individual chunk and stored as four or five plane [[Raw EGA data]] with a plane size of 128 (16x16) or 512 (32x32). These chunks do NOT have a dword specifying their decompressed size as this is hard-coded into the executable as a space saving measure. (As is the start and finish of unmasked and masked tile chunks.) This can cause problems for editing programs.&lt;br /&gt;
&lt;br /&gt;
Tiles make up the bulk of 2D game levels but are seldom seen elsewhere.&lt;br /&gt;
&lt;br /&gt;
=== Misc graphics ===&lt;br /&gt;
&lt;br /&gt;
Sometimes following tile graphics are miscellaneous graphics, that cannot be handled by the other chunk types. For example, Keen 4-6 has two misc graphics files used for the &#039;COOMANDER KEEN terminator text&#039; intro. These graphics usually have unique formats that fit their function and few have been investigated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Keen 4-6 Intro Bitmaps ====&lt;br /&gt;
&lt;br /&gt;
This is the text that displays after the &#039;Ready, press any key&#039; screen at Keen startup. It is composed of a monochrome bitmap that is scrolled across the screen and distorted for special effects. When displayed it is transparent, with a special palette so it is not black-and-white. It consists of a header followed by RLE compressed monochrome data.&lt;br /&gt;
&lt;br /&gt;
 HEADER:&lt;br /&gt;
 0   2    Img height  Height of the image in pixels&lt;br /&gt;
 2   2    Img width   Width of the image in pixels&lt;br /&gt;
 4   2x   Line point  Pointers to line 1,2,3..etc of data. There will be [Img height] of&lt;br /&gt;
                      these, each 2 bytes long. The first pointer will  have the value&lt;br /&gt;
                      (2 * [Img height] + 4)&lt;br /&gt;
 +2  ?    RLE data    RLE-WM compressed data&lt;br /&gt;
&lt;br /&gt;
 DATA:&lt;br /&gt;
 0   2    Black run   Number of black pixels to write&lt;br /&gt;
 2   2    Not-blk run Number of not-black pixels to write&lt;br /&gt;
 4   2    Black run....&lt;br /&gt;
 ...&lt;br /&gt;
 ..&lt;br /&gt;
 .&lt;br /&gt;
 ?  2     End         $FFFF; end of row.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game texts ===&lt;br /&gt;
&lt;br /&gt;
Also known as ANSII chunks, these are used by the game for things like help screens, and have their own format. In the main they are simply text documents, interspersed with various commands to make things happen. Each file is divided up into a number of &#039;pages&#039; which are moved between by pressing the up/down arrows. Pages can also have action sequences (Repeated each time the page is moved to, you cannot leave a page until the sequence finishes.)&lt;br /&gt;
&lt;br /&gt;
 ^P		First command in every file. Defines a page start&lt;br /&gt;
 ^E		Ends the file&lt;br /&gt;
 ^Cx		Change font color to $x until next page or ^C command&lt;br /&gt;
 ^Gx,y,z	Display (unmasked) picture chunk z at location x,y (In pixels)&lt;br /&gt;
 ^Tx,y,z,t	Display picture chunk z at x,y for z clicks of time&lt;br /&gt;
 ^Bx,y,z,t,b	?&lt;br /&gt;
 ^Lx,y		?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Misc files ===&lt;br /&gt;
&lt;br /&gt;
The last few chunks are demo files and occasionally miscellaneous data. Demo file formats are currently unknown but can be recorded using the demo cheat. They contain the level number and difficulty followed by a series of key commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
* [[KeenWiki:ModKeen|ModKeen]] (DOS) and [[KeenWiki:LModKeen|LModKeen]] (Linux/Windows) can be used to modify graphics and text stored in EGAGRAPH.CKx for the Commander Keen [[KeenWiki:Goodbye Galaxy|Goodbye Galaxy]] trilogy.&lt;br /&gt;
&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Commander Keen Dreams]]&lt;br /&gt;
[[Category:Dangerous Dave 3]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Graphics Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3583</id>
		<title>EGAGraph Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3583"/>
		<updated>2011-09-01T05:50:04Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* EGA Head (EGAHEAD.xxx) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;EGAGraph&#039;&#039;&#039;, short for &#039;EGA graphics library&#039; is the format used to store graphics, demos, fonts, game texts and more in many early [[:Category:Id Software|id Software]] games.&lt;br /&gt;
&lt;br /&gt;
The basic format is that of a number of [[Huffman Compression]] compressed sub-files (Chunks) stored in a similar manner to the [[AudioT Format]]. Like this format it has three main files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt;and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is notable that while the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; are stored in the game executable, they need to be extracted for [[TED5]] to edit levels.&lt;br /&gt;
&lt;br /&gt;
This article may contain errors as some formats have not been worked out completely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= File formats =&lt;br /&gt;
&lt;br /&gt;
== EGA Head (EGAHEAD.xxx) ==&lt;br /&gt;
There are two versions of this format. The first version, used in [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], is an array of 4-byte little-endian values. The second version, used in all later EGA games, is an array of 3-byte unsigned little-endian values.&lt;br /&gt;
&lt;br /&gt;
This header file may be present as an external file (eg. [[Bio Menace]]), or it may be included in the EXE file (eg. [[Catacomb 3D]]). The last entry in the header is always the size of the EGAGRAPH.xxx file, and the first entry in the header is always 00 00 00. To find the end, you can search for filesize(EGAGRAPH.xxx) as a 3-byte (little-endian) value in the EXE. Then to find the start, go back 3 bytes at a time until you get to 00 000 00. Or use the fact that entries always get smaller as you go back, unless the entry is $FFFFFF. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] v1.00 EGAHEAD.C3D is at $1BFD0 from the start of the decompressed ([[unlzexe]]) EXE file, and is 1436 bytes long, or 478 3-byte entries (for 477 chunks). It is then followed by 4 bytes (padding to multiple of 16?) 03 00 00 00, then the MAPHEAD.C3D. &lt;br /&gt;
&lt;br /&gt;
This header file stores the offsets (relative to the start of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file) for each sub file.  The format is trivial, in that the header file is simply an array of 3 or 4 byte variables.  (Each variable is a &amp;quot;slot&amp;quot;, as the game refers to files by index.) Most games use the more compact 3-byte variables, since the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is never larger than $FFFFFF. However games based on older engines, notably [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], use 4-byte vales as these are easier to deal with.&lt;br /&gt;
&lt;br /&gt;
It is important to note that not every &#039;slot&#039; will be in use. Tiles especially if blank (All black) will be considered &#039;empty&#039; and not worth adding to the file. (A blank 16x16 tile takes up 12 bytes of space if compressed, and there can be hundreds.) There are two ways of dealing with this; by default the games set all empty slot headers to -1, but many programs compress the graphics anyway and use a normal header value for them.&lt;br /&gt;
&lt;br /&gt;
The last offset in the file will be an offset to the end of the main &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file.  (So this should be ignored when reading the file to prevent a zero-byte file appearing last.) The total size of the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; divided by 3 (Or 4) will also give the number of &#039;slots&#039; the game uses. This varies, but is usually about 10,000.&lt;br /&gt;
&lt;br /&gt;
Unlike [[AudioT Format]] files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; is always compressed. However the header and dictionary may be external (E.g [[Bio Menace]])&lt;br /&gt;
&lt;br /&gt;
== Dictionary (EGADICT.xxx) ==&lt;br /&gt;
&lt;br /&gt;
The same [[Huffman Compression]] scheme used elsewhere in the [[Commander Keen]] series is used.  When reading compressed files out of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, the first four bytes located at the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; offset are a UINT32LE specifying the file&#039;s decompressed size (which is required for the decompression algorithm.)  The compressed data then follows, EXCEPT for 16x16 masked and unmasked tiles. Since these all have a similar decompressed size (128 bytes for unmasked, 256 bytes for masked) it is a waste of space to include these (Since tiles make up the bulk of graphics slots.) The decompressed size is hard coded, as are the start and finish of the unmasked and masked tile slots.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; file is not often obvious, usually being embedded in the main exe file. It is possible to locate it by looking for the string &amp;lt;tt&amp;gt;$FD $01 $00 $00 $00 $00&amp;lt;/tt&amp;gt;, which appears at the end of nearly all Huffman dictionaries. Executables usually contain two or more dictionaries, but the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; is usually the second one, except in the case of early games like Keen Dreams, where it is the first of THREE. (A simple check of whether it decompresses the data sensibly works.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Main file (EGAGRAPH.xxx) ==&lt;br /&gt;
&lt;br /&gt;
This file is simply an array of data files.  Each file starts at the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, and as there are no filenames each file is referred to by its index/slot number.  Slots containing dummy values in the header are treated as if they don&#039;t exist in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file. Each file within the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is individually compressed.  A file can be read by opening the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, seeking to the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, reading a UINT32LE for the decompressed file size, and then decompressing the data from that point onwards using standard Huffman decompression techniques.&lt;br /&gt;
&lt;br /&gt;
Note that in early games such as Keen Dreams, the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file may have another name. (Such as &amp;lt;tt&amp;gt;KDREAM.EGA&amp;lt;/tt&amp;gt; in that case.) in which case it is always the largest non-executable file.&lt;br /&gt;
&lt;br /&gt;
=== Chunks ===&lt;br /&gt;
&lt;br /&gt;
Each sub file or chunk is a separate graphic, ordered in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file in a specific way, much again like the [[AudioT Format]].  Chunks are labeled starting at 0. The game executable is hard coded for the start and finish of various chunk types. For example, Keen 4 has chunks 124-520 as sprites and will treat any chunk between these two numbers as a sprite. (Note that the game refers to chunk number, not sprite number.) The usual order of chunks is:&lt;br /&gt;
&lt;br /&gt;
 Picture table&lt;br /&gt;
 Masked picture table&lt;br /&gt;
 Sprite table&lt;br /&gt;
 Fonts&lt;br /&gt;
 Pictures (Unmasked bitmaps)&lt;br /&gt;
 Masked pictures&lt;br /&gt;
 8x8 unmasked tiles (Single chunk)&lt;br /&gt;
 8x8 masked tiles (Single chunk)&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 32x32 unmasked tiles (Optional)&lt;br /&gt;
 32x32 masked tiles (Optional)&lt;br /&gt;
 Misc graphics (Optional)&lt;br /&gt;
 Game texts&lt;br /&gt;
 Demo files (Optional)&lt;br /&gt;
 Misc data (Optional)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Chunk formats ==&lt;br /&gt;
&lt;br /&gt;
When compressed each chunk consists of a dword giving the decompressed size followed by the compressed data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the first chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying picture chunks.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Masked picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the second chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying masked picture chunks. This table is often quite small.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprite table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the third chunk, the picture table is 16 * numspr bytes long, consisting of eight words for each sprite image (Width\8, Height, x offset, y offset and clipping rectangle left, top, right and bottom; all in that order.) used when displaying sprite chunks. This is what Modkeen exports as its notoriously hard to use xSPRITES.txt file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fonts ===&lt;br /&gt;
&lt;br /&gt;
Always present and always starting at the fourth chunk. (Chunk 3!) Each chunk is a single monochrome font, containing all the entries from 0-255 for that font. Each &#039;letter&#039; is stored separately and consecutively. A game will have at least one, and usually 3 fonts. The format is version two of [[EGA Font format]]&lt;br /&gt;
&lt;br /&gt;
Fonts are used in the game for game texts. They can be stretched or colored and are always transparent, meaning they look strange when not over a single-color background.&lt;br /&gt;
&lt;br /&gt;
=== Pictures (Bitmaps) ===&lt;br /&gt;
&lt;br /&gt;
These follow game fonts. Bitmaps are stored as standard [[Raw EGA data]], the size of each plane being the decompressed chunk size \ 4. In order to be displayed properly these need information from chunk 0, the picture table. Note that unlike fonts, data does not wrap, so a 4x4 sprite will consist of four planes of four bytes in size, the same as an 8x4 sprite.&lt;br /&gt;
&lt;br /&gt;
Pictures are used for things such as title screens or pictures in game texts. Most of the main menu will consist of pictures.&lt;br /&gt;
&lt;br /&gt;
=== Masked pictures (Masked bitmaps) ===&lt;br /&gt;
&lt;br /&gt;
These are identical to the picture chunks in every respect, except being masked, they consist of five EGA planes, not four. Some games (E.g [[Catacomb 3D]] make great use of masked pictures, but most games have only one or two. They need information from chunk 1, the masked picture table, to be displayed correctly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprites ===&lt;br /&gt;
&lt;br /&gt;
Sprites are exactly identical to masked pictures in format except the game cannot stretch or warp them. Most games use these for enemy, player or item graphics during gameplay. They need information from chunk 2, the sprite table both to display correctly and to interact correctly, something more complex than masked pictures. There are usually several hundred sprite chunks.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== 8x8 tiles ===&lt;br /&gt;
&lt;br /&gt;
8x8 tiles are used by most games in status windows or foe the borders of message windows in-game. (And occasionally by TED5 to display levels.) There are thus not many of them. ALL the masked or unmasked tiles are one single chunk stored as four and five plane [[Raw EGA data]] respectively. The number of 8x8 unmasked and masked tiles is hard-coded into the executable, but can be worked out by dividing the decompressed chunk size by 32 and 40 (The size of one tile&#039;s data) respectively.&lt;br /&gt;
&lt;br /&gt;
=== 16x16 and 32x32 tiles ===&lt;br /&gt;
&lt;br /&gt;
32x32 tiles are optional and rarely used. 16x16 tiles are only occasionally absent and for most games make up the bulk of graphics. There are usually several thousand entries. Both come in masked and unmasked kinds, just like 8x8 tiles.&lt;br /&gt;
&lt;br /&gt;
These chunks have notable differences. Each tile is an individual chunk and stored as four or five plane [[Raw EGA data]] with a plane size of 128 (16x16) or 512 (32x32). These chunks do NOT have a dword specifying their decompressed size as this is hard-coded into the executable as a space saving measure. (As is the start and finish of unmasked and masked tile chunks.) This can cause problems for editing programs.&lt;br /&gt;
&lt;br /&gt;
Tiles make up the bulk of 2D game levels but are seldom seen elsewhere.&lt;br /&gt;
&lt;br /&gt;
=== Misc graphics ===&lt;br /&gt;
&lt;br /&gt;
Sometimes following tile graphics are miscellaneous graphics, that cannot be handled by the other chunk types. For example, Keen 4-6 has two misc graphics files used for the &#039;COOMANDER KEEN terminator text&#039; intro. These graphics usually have unique formats that fit their function and few have been investigated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Keen 4-6 Intro Bitmaps ====&lt;br /&gt;
&lt;br /&gt;
This is the text that displays after the &#039;Ready, press any key&#039; screen at Keen startup. It is composed of a monochrome bitmap that is scrolled across the screen and distorted for special effects. When displayed it is transparent, with a special palette so it is not black-and-white. It consists of a header followed by RLE compressed monochrome data.&lt;br /&gt;
&lt;br /&gt;
 HEADER:&lt;br /&gt;
 0   2    Img height  Height of the image in pixels&lt;br /&gt;
 2   2    Img width   Width of the image in pixels&lt;br /&gt;
 4   2x   Line point  Pointers to line 1,2,3..etc of data. There will be [Img height] of&lt;br /&gt;
                      these, each 2 bytes long. The first pointer will  have the value&lt;br /&gt;
                      (2 * [Img height] + 4)&lt;br /&gt;
 +2  ?    RLE data    RLE-WM compressed data&lt;br /&gt;
&lt;br /&gt;
 DATA:&lt;br /&gt;
 0   2    Black run   Number of black pixels to write&lt;br /&gt;
 2   2    Not-blk run Number of not-black pixels to write&lt;br /&gt;
 4   2    Black run....&lt;br /&gt;
 ...&lt;br /&gt;
 ..&lt;br /&gt;
 .&lt;br /&gt;
 ?  2     End         $FFFF; end of row.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game texts ===&lt;br /&gt;
&lt;br /&gt;
Also known as ANSII chunks, these are used by the game for things like help screens, and have their own format. In the main they are simply text documents, interspersed with various commands to make things happen. Each file is divided up into a number of &#039;pages&#039; which are moved between by pressing the up/down arrows. Pages can also have action sequences (Repeated each time the page is moved to, you cannot leave a page until the sequence finishes.)&lt;br /&gt;
&lt;br /&gt;
 ^P		First command in every file. Defines a page start&lt;br /&gt;
 ^E		Ends the file&lt;br /&gt;
 ^Cx		Change font color to $x until next page or ^C command&lt;br /&gt;
 ^Gx,y,z	Display (unmasked) picture chunk z at location x,y (In pixels)&lt;br /&gt;
 ^Tx,y,z,t	Display picture chunk z at x,y for z clicks of time&lt;br /&gt;
 ^Bx,y,z,t,b	?&lt;br /&gt;
 ^Lx,y		?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Misc files ===&lt;br /&gt;
&lt;br /&gt;
The last few chunks are demo files and occasionally miscellaneous data. Demo file formats are currently unknown but can be recorded using the demo cheat. They contain the level number and difficulty followed by a series of key commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
* [[KeenWiki:ModKeen|ModKeen]] (DOS) and [[KeenWiki:LModKeen|LModKeen]] (Linux/Windows) can be used to modify graphics and text stored in EGAGRAPH.CKx for the Commander Keen [[KeenWiki:Goodbye Galaxy|Goodbye Galaxy]] trilogy.&lt;br /&gt;
&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Commander Keen Dreams]]&lt;br /&gt;
[[Category:Dangerous Dave 3]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Graphics Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3582</id>
		<title>EGAGraph Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=EGAGraph_Format&amp;diff=3582"/>
		<updated>2011-09-01T05:24:15Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* EGA Head (EGAHEAD.xxx) */ Details about internal files and Catacomb 3D,&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;EGAGraph&#039;&#039;&#039;, short for &#039;EGA graphics library&#039; is the format used to store graphics, demos, fonts, game texts and more in many early [[:Category:Id Software|id Software]] games.&lt;br /&gt;
&lt;br /&gt;
The basic format is that of a number of [[Huffman Compression]] compressed sub-files (Chunks) stored in a similar manner to the [[AudioT Format]]. Like this format it has three main files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt;and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is notable that while the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; are stored in the game executable, they need to be extracted for [[TED5]] to edit levels.&lt;br /&gt;
&lt;br /&gt;
This article may contain errors as some formats have not been worked out completely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= File formats =&lt;br /&gt;
&lt;br /&gt;
== EGA Head (EGAHEAD.xxx) ==&lt;br /&gt;
There are two versions of this format. The first version, used in [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], is an array of 4-byte little-endian values. The second version, used in all later EGA games, is an array of 3-byte unsigned little-endian values.&lt;br /&gt;
&lt;br /&gt;
This header file may be present as an external file (eg. [[Bio Menace]]), or it may be included in the EXE file (eg. [[Catacomb 3D]]). The last entry in the header is always the size of the EGAGRAPH.xxx file, and the first entry in the header is always 00 00 00. To find the end, you can search for filesize(EGAGRAPH.xxx) as a 3-byte (little-endian) value in the EXE. Then to find the start, go back 3 bytes at a time until you get to 00 000 00. Or use the fact that entries always get smaller as you go back, unless the entry is $FFFFFF. &lt;br /&gt;
&lt;br /&gt;
In [[Catacomb 3D]] v1.00 EGAHEAD.C3D is at $1BFD00 from the start of the decompressed ([[unlzexe]]) EXE file, and is 1436 bytes long, or 478 3-byte entries (for 477 chunks). It is then followed by 4 bytes (padding to multiple of 16?) 03 00 00 00, then the MAPHEAD.C3D. &lt;br /&gt;
&lt;br /&gt;
This header file stores the offsets (relative to the start of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file) for each sub file.  The format is trivial, in that the header file is simply an array of 3 or 4 byte variables.  (Each variable is a &amp;quot;slot&amp;quot;, as the game refers to files by index.) Most games use the more compact 3-byte variables, since the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is never larger than $FFFFFF. However games based on older engines, notably [[Commander Keen Dreams]], [[Dangerous Dave 3]] and [[Dangerous Dave 4]], use 4-byte vales as these are easier to deal with.&lt;br /&gt;
&lt;br /&gt;
It is important to note that not every &#039;slot&#039; will be in use. Tiles especially if blank (All black) will be considered &#039;empty&#039; and not worth adding to the file. (A blank 16x16 tile takes up 12 bytes of space if compressed, and there can be hundreds.) There are two ways of dealing with this; by default the games set all empty slot headers to -1, but many programs compress the graphics anyway and use a normal header value for them.&lt;br /&gt;
&lt;br /&gt;
The last offset in the file will be an offset to the end of the main &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file.  (So this should be ignored when reading the file to prevent a zero-byte file appearing last.) The total size of the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; divided by 3 (Or 4) will also give the number of &#039;slots&#039; the game uses. This varies, but is usually about 10,000.&lt;br /&gt;
&lt;br /&gt;
Unlike [[AudioT Format]] files, &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; is always compressed. However the header and dictionary may be external (E.g [[Bio Menace]])&lt;br /&gt;
&lt;br /&gt;
== Dictionary (EGADICT.xxx) ==&lt;br /&gt;
&lt;br /&gt;
The same [[Huffman Compression]] scheme used elsewhere in the [[Commander Keen]] series is used.  When reading compressed files out of the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, the first four bytes located at the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; offset are a UINT32LE specifying the file&#039;s decompressed size (which is required for the decompression algorithm.)  The compressed data then follows, EXCEPT for 16x16 masked and unmasked tiles. Since these all have a similar decompressed size (128 bytes for unmasked, 256 bytes for masked) it is a waste of space to include these (Since tiles make up the bulk of graphics slots.) The decompressed size is hard coded, as are the start and finish of the unmasked and masked tile slots.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; file is not often obvious, usually being embedded in the main exe file. It is possible to locate it by looking for the string &amp;lt;tt&amp;gt;$FD $01 $00 $00 $00 $00&amp;lt;/tt&amp;gt;, which appears at the end of nearly all Huffman dictionaries. Executables usually contain two or more dictionaries, but the &amp;lt;tt&amp;gt;EGADICT&amp;lt;/tt&amp;gt; is usually the second one, except in the case of early games like Keen Dreams, where it is the first of THREE. (A simple check of whether it decompresses the data sensibly works.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Main file (EGAGRAPH.xxx) ==&lt;br /&gt;
&lt;br /&gt;
This file is simply an array of data files.  Each file starts at the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, and as there are no filenames each file is referred to by its index/slot number.  Slots containing dummy values in the header are treated as if they don&#039;t exist in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file. Each file within the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file is individually compressed.  A file can be read by opening the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file, seeking to the offset specified in the &amp;lt;tt&amp;gt;EGAHEAD&amp;lt;/tt&amp;gt; file, reading a UINT32LE for the decompressed file size, and then decompressing the data from that point onwards using standard Huffman decompression techniques.&lt;br /&gt;
&lt;br /&gt;
Note that in early games such as Keen Dreams, the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file may have another name. (Such as &amp;lt;tt&amp;gt;KDREAM.EGA&amp;lt;/tt&amp;gt; in that case.) in which case it is always the largest non-executable file.&lt;br /&gt;
&lt;br /&gt;
=== Chunks ===&lt;br /&gt;
&lt;br /&gt;
Each sub file or chunk is a separate graphic, ordered in the &amp;lt;tt&amp;gt;EGAGRAPH&amp;lt;/tt&amp;gt; file in a specific way, much again like the [[AudioT Format]].  Chunks are labeled starting at 0. The game executable is hard coded for the start and finish of various chunk types. For example, Keen 4 has chunks 124-520 as sprites and will treat any chunk between these two numbers as a sprite. (Note that the game refers to chunk number, not sprite number.) The usual order of chunks is:&lt;br /&gt;
&lt;br /&gt;
 Picture table&lt;br /&gt;
 Masked picture table&lt;br /&gt;
 Sprite table&lt;br /&gt;
 Fonts&lt;br /&gt;
 Pictures (Unmasked bitmaps)&lt;br /&gt;
 Masked pictures&lt;br /&gt;
 8x8 unmasked tiles (Single chunk)&lt;br /&gt;
 8x8 masked tiles (Single chunk)&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 16x16 unmasked tiles&lt;br /&gt;
 32x32 unmasked tiles (Optional)&lt;br /&gt;
 32x32 masked tiles (Optional)&lt;br /&gt;
 Misc graphics (Optional)&lt;br /&gt;
 Game texts&lt;br /&gt;
 Demo files (Optional)&lt;br /&gt;
 Misc data (Optional)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Chunk formats ==&lt;br /&gt;
&lt;br /&gt;
When compressed each chunk consists of a dword giving the decompressed size followed by the compressed data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the first chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying picture chunks.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Masked picture table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the second chunk, the picture table is 4 * numpics bytes long, consisting of two words for each picture (Width\8, Height) used when displaying masked picture chunks. This table is often quite small.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprite table ===&lt;br /&gt;
&lt;br /&gt;
Always present and always the third chunk, the picture table is 16 * numspr bytes long, consisting of eight words for each sprite image (Width\8, Height, x offset, y offset and clipping rectangle left, top, right and bottom; all in that order.) used when displaying sprite chunks. This is what Modkeen exports as its notoriously hard to use xSPRITES.txt file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fonts ===&lt;br /&gt;
&lt;br /&gt;
Always present and always starting at the fourth chunk. (Chunk 3!) Each chunk is a single monochrome font, containing all the entries from 0-255 for that font. Each &#039;letter&#039; is stored separately and consecutively. A game will have at least one, and usually 3 fonts. The format is version two of [[EGA Font format]]&lt;br /&gt;
&lt;br /&gt;
Fonts are used in the game for game texts. They can be stretched or colored and are always transparent, meaning they look strange when not over a single-color background.&lt;br /&gt;
&lt;br /&gt;
=== Pictures (Bitmaps) ===&lt;br /&gt;
&lt;br /&gt;
These follow game fonts. Bitmaps are stored as standard [[Raw EGA data]], the size of each plane being the decompressed chunk size \ 4. In order to be displayed properly these need information from chunk 0, the picture table. Note that unlike fonts, data does not wrap, so a 4x4 sprite will consist of four planes of four bytes in size, the same as an 8x4 sprite.&lt;br /&gt;
&lt;br /&gt;
Pictures are used for things such as title screens or pictures in game texts. Most of the main menu will consist of pictures.&lt;br /&gt;
&lt;br /&gt;
=== Masked pictures (Masked bitmaps) ===&lt;br /&gt;
&lt;br /&gt;
These are identical to the picture chunks in every respect, except being masked, they consist of five EGA planes, not four. Some games (E.g [[Catacomb 3D]] make great use of masked pictures, but most games have only one or two. They need information from chunk 1, the masked picture table, to be displayed correctly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sprites ===&lt;br /&gt;
&lt;br /&gt;
Sprites are exactly identical to masked pictures in format except the game cannot stretch or warp them. Most games use these for enemy, player or item graphics during gameplay. They need information from chunk 2, the sprite table both to display correctly and to interact correctly, something more complex than masked pictures. There are usually several hundred sprite chunks.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== 8x8 tiles ===&lt;br /&gt;
&lt;br /&gt;
8x8 tiles are used by most games in status windows or foe the borders of message windows in-game. (And occasionally by TED5 to display levels.) There are thus not many of them. ALL the masked or unmasked tiles are one single chunk stored as four and five plane [[Raw EGA data]] respectively. The number of 8x8 unmasked and masked tiles is hard-coded into the executable, but can be worked out by dividing the decompressed chunk size by 32 and 40 (The size of one tile&#039;s data) respectively.&lt;br /&gt;
&lt;br /&gt;
=== 16x16 and 32x32 tiles ===&lt;br /&gt;
&lt;br /&gt;
32x32 tiles are optional and rarely used. 16x16 tiles are only occasionally absent and for most games make up the bulk of graphics. There are usually several thousand entries. Both come in masked and unmasked kinds, just like 8x8 tiles.&lt;br /&gt;
&lt;br /&gt;
These chunks have notable differences. Each tile is an individual chunk and stored as four or five plane [[Raw EGA data]] with a plane size of 128 (16x16) or 512 (32x32). These chunks do NOT have a dword specifying their decompressed size as this is hard-coded into the executable as a space saving measure. (As is the start and finish of unmasked and masked tile chunks.) This can cause problems for editing programs.&lt;br /&gt;
&lt;br /&gt;
Tiles make up the bulk of 2D game levels but are seldom seen elsewhere.&lt;br /&gt;
&lt;br /&gt;
=== Misc graphics ===&lt;br /&gt;
&lt;br /&gt;
Sometimes following tile graphics are miscellaneous graphics, that cannot be handled by the other chunk types. For example, Keen 4-6 has two misc graphics files used for the &#039;COOMANDER KEEN terminator text&#039; intro. These graphics usually have unique formats that fit their function and few have been investigated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Keen 4-6 Intro Bitmaps ====&lt;br /&gt;
&lt;br /&gt;
This is the text that displays after the &#039;Ready, press any key&#039; screen at Keen startup. It is composed of a monochrome bitmap that is scrolled across the screen and distorted for special effects. When displayed it is transparent, with a special palette so it is not black-and-white. It consists of a header followed by RLE compressed monochrome data.&lt;br /&gt;
&lt;br /&gt;
 HEADER:&lt;br /&gt;
 0   2    Img height  Height of the image in pixels&lt;br /&gt;
 2   2    Img width   Width of the image in pixels&lt;br /&gt;
 4   2x   Line point  Pointers to line 1,2,3..etc of data. There will be [Img height] of&lt;br /&gt;
                      these, each 2 bytes long. The first pointer will  have the value&lt;br /&gt;
                      (2 * [Img height] + 4)&lt;br /&gt;
 +2  ?    RLE data    RLE-WM compressed data&lt;br /&gt;
&lt;br /&gt;
 DATA:&lt;br /&gt;
 0   2    Black run   Number of black pixels to write&lt;br /&gt;
 2   2    Not-blk run Number of not-black pixels to write&lt;br /&gt;
 4   2    Black run....&lt;br /&gt;
 ...&lt;br /&gt;
 ..&lt;br /&gt;
 .&lt;br /&gt;
 ?  2     End         $FFFF; end of row.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game texts ===&lt;br /&gt;
&lt;br /&gt;
Also known as ANSII chunks, these are used by the game for things like help screens, and have their own format. In the main they are simply text documents, interspersed with various commands to make things happen. Each file is divided up into a number of &#039;pages&#039; which are moved between by pressing the up/down arrows. Pages can also have action sequences (Repeated each time the page is moved to, you cannot leave a page until the sequence finishes.)&lt;br /&gt;
&lt;br /&gt;
 ^P		First command in every file. Defines a page start&lt;br /&gt;
 ^E		Ends the file&lt;br /&gt;
 ^Cx		Change font color to $x until next page or ^C command&lt;br /&gt;
 ^Gx,y,z	Display (unmasked) picture chunk z at location x,y (In pixels)&lt;br /&gt;
 ^Tx,y,z,t	Display picture chunk z at x,y for z clicks of time&lt;br /&gt;
 ^Bx,y,z,t,b	?&lt;br /&gt;
 ^Lx,y		?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Misc files ===&lt;br /&gt;
&lt;br /&gt;
The last few chunks are demo files and occasionally miscellaneous data. Demo file formats are currently unknown but can be recorded using the demo cheat. They contain the level number and difficulty followed by a series of key commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
* [[KeenWiki:ModKeen|ModKeen]] (DOS) and [[KeenWiki:LModKeen|LModKeen]] (Linux/Windows) can be used to modify graphics and text stored in EGAGRAPH.CKx for the Commander Keen [[KeenWiki:Goodbye Galaxy|Goodbye Galaxy]] trilogy.&lt;br /&gt;
&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Commander Keen Dreams]]&lt;br /&gt;
[[Category:Dangerous Dave 3]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Graphics Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Super_3-D_Noah%27s_Ark&amp;diff=3581</id>
		<title>Super 3-D Noah&#039;s Ark</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Super_3-D_Noah%27s_Ark&amp;diff=3581"/>
		<updated>2011-09-01T04:07:10Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: Made like Wolfenstein 3-D page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
This is the PC version of the game &#039;&#039;&#039;Super 3D Noah&#039;s Ark&#039;&#039;&#039; by Wisdom Tree Games. It uses a modified (licensed) version of the [[Wolfenstein 3-D]] engine, with added support for textured floors and ceilings. Super 3D Noah&#039;s Ark&#039;s homepage is at [http://www.wisdomtreegames.com/games/super3dnoahsark/ http://www.wisdomtreegames.com/games/super3dnoahsark/], where it is still for sale.&lt;br /&gt;
&lt;br /&gt;
{{GamePage|Noah&#039;s Ark 3D}}&lt;br /&gt;
== File formats ==&lt;br /&gt;
&lt;br /&gt;
This section lists the major file formats used in the game.&lt;br /&gt;
&lt;br /&gt;
* [[AudioT Format]] - sounds and music are stored in the &amp;lt;tt&amp;gt;AUDIO*.N3D&amp;lt;/tt&amp;gt; files&lt;br /&gt;
* WLF Format - identical to the [[IMF Format]] only with a faster tempo. (720 vs 560)&lt;br /&gt;
* [[GameMaps Format]] - used for storing level maps in the files &amp;lt;tt&amp;gt;GAMEMAPS.N3D&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;MAPHEAD.N3D&amp;lt;/tt&amp;gt;&lt;br /&gt;
* [[B800 Text]] - there are a couple of text screens in the main .EXE file (including the text displayed on the screen when you quit)&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
These tools can be used to edit this game.&lt;br /&gt;
&lt;br /&gt;
* [[TED5]] - the editor used by id Software to create the original levels&lt;br /&gt;
&lt;br /&gt;
== Further information ==&lt;br /&gt;
&lt;br /&gt;
The source code of Wolfenstein 3-D was released by id Software on July 21, 1995. It can be downloaded from id Software&#039;s [ftp://ftp.idsoftware.com/idstuff/source/ FTP server].&lt;br /&gt;
&lt;br /&gt;
[[Category:Apogee]]&lt;br /&gt;
[[Category:id Software]]&lt;br /&gt;
[[Category:3D]]&lt;br /&gt;
[[Category:First-Person Shooter]]&lt;br /&gt;
[[Category:Noah&#039;s Ark 3D]]&lt;br /&gt;
[[Category:Wolfenstein 3-D]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Super_3-D_Noah%27s_Ark&amp;diff=3580</id>
		<title>Super 3-D Noah&#039;s Ark</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Super_3-D_Noah%27s_Ark&amp;diff=3580"/>
		<updated>2011-09-01T03:59:42Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: Started stub&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is the PC version of the game &#039;&#039;&#039;Super 3D Noah&#039;s Ark&#039;&#039;&#039; by Wisdom Tree Games. It uses a modified (licensed) version of the [[Wolfenstein 3-D]] engine, with added support for textured floors and ceilings. Super 3D Noah&#039;s Ark&#039;s homepage is at [http://www.wisdomtreegames.com/games/super3dnoahsark/ http://www.wisdomtreegames.com/games/super3dnoahsark/], where it is still for sale.&lt;br /&gt;
&lt;br /&gt;
{{Stub}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Noah&#039;s Ark 3D]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Category:Super_3-D_Noah%27s_Ark&amp;diff=3579</id>
		<title>Category:Super 3-D Noah&#039;s Ark</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Category:Super_3-D_Noah%27s_Ark&amp;diff=3579"/>
		<updated>2011-09-01T03:55:10Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: Created category page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;These pages are relevant to the PC version of the game &#039;&#039;&#039;Super 3D Noah&#039;s Ark&#039;&#039;&#039; by Wisdom Tree Games. It uses a modified version of the [[Wolfenstein 3-D]] engine. Super 3D Noah&#039;s Ark&#039;s homepage is at [http://www.wisdomtreegames.com/games/super3dnoahsark/ http://www.wisdomtreegames.com/games/super3dnoahsark/].&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=AudioT_Format&amp;diff=3578</id>
		<title>AudioT Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=AudioT_Format&amp;diff=3578"/>
		<updated>2011-09-01T03:48:19Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: Noah&amp;#039;s Ark 3D category&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &amp;lt;b&amp;gt;AudioT&amp;lt;/b&amp;gt; format is a [[:Category:Group Files|group file]] used by many id/Apogee games to store Adlib music, Adlib sound effects and PC Speaker sound effects in a single file.  The basic structure of this format is very similar to the [[EGAGraph_Format]] and the [[GameMaps Format]]. The main audio file can be compressed (&amp;lt;tt&amp;gt;AUDIO.xxx&amp;lt;/tt&amp;gt;) or uncompressed (&amp;lt;tt&amp;gt;AUDIOT.xxx&amp;lt;/tt&amp;gt;). It requires an associated &amp;lt;tt&amp;gt;AUDIOHED.xxx&amp;lt;/tt&amp;gt; which stores the offsets of each file, and an &amp;lt;tt&amp;gt;AUDIODCT.xxx&amp;lt;/tt&amp;gt; if the file is compressed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== File formats ==&lt;br /&gt;
&lt;br /&gt;
=== Audio Head (AUDIOHED.xxx) ===&lt;br /&gt;
&lt;br /&gt;
This header file stores the offsets (relative to the start of the &amp;lt;tt&amp;gt;AUDIO/AUDIOT&amp;lt;/tt&amp;gt; file) for each sub file.  The format is trivial, in that the header file is simply an array of &amp;lt;tt&amp;gt;UINT32LE&amp;lt;/tt&amp;gt; offsets.&lt;br /&gt;
&lt;br /&gt;
The last offset in the file will be an offset to the end of the main &amp;lt;tt&amp;gt;AUDIO/AUDIOT&amp;lt;/tt&amp;gt; file. This was probably done so that the size of each chunk could be calculated with the formula below. Thus, the number of offsets (size of the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; in dwords) minus one will give the number of chunks (slots) included in the main file. This number varies, but is usually about 200. (Games refer to the chunks by index, not by name).&lt;br /&gt;
&lt;br /&gt;
The size of a chunk can be calculated like this:&lt;br /&gt;
&lt;br /&gt;
 size[i] = offset[i+1] - offset[i]&lt;br /&gt;
&lt;br /&gt;
Empty chunks (size[i] = 0) should be skipped when extracting chunks.&lt;br /&gt;
&lt;br /&gt;
In most (not all) games, the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; is included in the executable file. See [[Extracting data files from executables]] for information on how to locate and extract them. &lt;br /&gt;
&lt;br /&gt;
=== Dictionary (AUDIODCT.xxx) ===&lt;br /&gt;
&lt;br /&gt;
If the main audio file is named &amp;lt;tt&amp;gt;AUDIO.xxx&amp;lt;/tt&amp;gt;, then the file is compressed.  The same [[Huffman Compression]] scheme used elsewhere in the [[Commander Keen]] series is used.  When reading compressed files out of the &amp;lt;tt&amp;gt;AUDIO&amp;lt;/tt&amp;gt; file, the first four bytes located at the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; offset are a UINT32LE specifying the file&#039;s decompressed size (which is required for the decompression algorithm.)  The compressed data then follows.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;AUDIODCT&amp;lt;/tt&amp;gt; file is not often obvious, usually being embedded in the main exe file. Executables usually contain two or more dictionaries, but the &amp;lt;tt&amp;gt;AUDIODCT&amp;lt;/tt&amp;gt; is usually the first one. (A simple check of whether it decompresses the data sensibly works.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Main file (AUDIOT.xxx, AUDIO.xxx) ===&lt;br /&gt;
&lt;br /&gt;
This file is simply an array of data files.  Each file starts at the offset specified in the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; file, and as there are no filenames each file is referred to by its index/slot number.  Slots containing dummy values in the header are treated as if they don&#039;t exist in the &amp;lt;tt&amp;gt;AUDIO/AUDIOT&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
If compression is in use then the &amp;lt;tt&amp;gt;AUDIO&amp;lt;/tt&amp;gt; file itself isn&#039;t compressed, rather each file within the &amp;lt;tt&amp;gt;AUDIO&amp;lt;/tt&amp;gt; file is individually compressed.  A file can be read by opening the &amp;lt;tt&amp;gt;AUDIOT&amp;lt;/tt&amp;gt; file, seeking to the offset specified in the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; file, reading a UINT32LE for the decompressed file size, and then decompressing the data from that point onwards using standard Huffman decompression techniques.&lt;br /&gt;
&lt;br /&gt;
If compression is not in use (&amp;lt;tt&amp;gt;AUDIOT&amp;lt;/tt&amp;gt; files) then a file can be read by simply seeking to the offset specified in the AUDIOHED file and reading until the offset of the following file is reached.  Since the last offset in the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; file is the size of the &amp;lt;tt&amp;gt;AUDIOT&amp;lt;/tt&amp;gt; file itself, no extra handling should be necessary to correctly read all of the last file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Chunks ==&lt;br /&gt;
&lt;br /&gt;
The AUDIOT format is a container format, meaning that any files the game can handle can be stored in it. Traditionally there have been three types of &#039;sub files&#039; or chunks: Adlib music files (which are [[IMF Format]]), Adlib sound effects and PC Speaker sound effects. By default most games store PC effects first, followed by their Adlib equivalents, with the IMF music filling the last entries.&lt;br /&gt;
&lt;br /&gt;
At least one case is known where the music is in MIDI format ([[Noah&#039;s Ark 3D]]) and it is possible that soundblaster &#039;digital&#039; sound effects have been stored like this as well at some point. There has often been confusion about what part of a file are data and which are the AUDIOT file, for example the IMF file format was widely believed to exist in two types until it was discovered that &#039;type 1&#039; IMFs were simply &#039;type 0&#039; that had been incorrectly extracted from the AUDIOT file with their chunk length and tags.&lt;br /&gt;
&lt;br /&gt;
It is notable that a sound file will contain exactly as many PC sounds as adlib sounds (and an arbitrary number of IMF files.) This is because most games have a PC\Adlib option and thus must match every PC sound with an adlib equivalent. The number of sounds appears to be hard-coded, though all games (except for [[Commander Keen Dreams]]) seem to add the string &amp;quot;!ID!&amp;quot; after the last sound of each &#039;section&#039;. The &amp;quot;!ID!&amp;quot; tags themselves don&#039;t seem to be part of any chunk and are probably put in for debugging purposes.&lt;br /&gt;
&lt;br /&gt;
Sound chunks are always in the same order, PC, then adlib then IMF. A simple method to classify the sound chunks is to check the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; for chunks of size 0. These are &#039;empty&#039; sounds and seperate sound chunks from music chunks . Every nonzero length chunk after this is an IMF chunk. (IMFs are always the last chunks in the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; and contain no zero length chunks) For the PC\adlib chunks, the number of chunks before the first zero length chunk can be divided into two, the first half being PC, the second half being adlib.&lt;br /&gt;
&lt;br /&gt;
If the file is uncompressed then the adlib and IMF chunks will be tagged (huffman compression, being a space saving exercise doesn&#039;t comoress tags.) PC chunks are never tagged. It appears that the compiler used added a footer to each chunk as they were compiled. For sounds these are null terminated strings of 12 characters or less, including terminator. For IMF files these are 88 byte strings detailed on the [[IMF Format]] page. These names are not read by games (with the possible exception of the aforementioned &#039;!ID!&#039; tags.)&lt;br /&gt;
&lt;br /&gt;
TODO: Need to also document both sound effect formats so the sounds can be edited and not just imported/exported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== IMF Music ===&lt;br /&gt;
&lt;br /&gt;
[[IMF Format]] files are packed at the end of the audio file. Occasionally &#039;empty&#039; music files are found (e.g [[Wolfenstein 3-D]]) that contain no actual data, just footer information placed there by a compiler. They can be extracted as they are and played with various utilities such as Adplug.&lt;br /&gt;
&lt;br /&gt;
=== PC Sounds ===&lt;br /&gt;
&lt;br /&gt;
 0    4    Length of sound data (Usually chunk length - 7)&lt;br /&gt;
 4    2    Priority of sound, only 1 PC sound may play at a time; any sound&lt;br /&gt;
           will interrupt a sound of equal or lower priority.&lt;br /&gt;
 6    ?    Sound data&lt;br /&gt;
 ?    1    Terminating null&lt;br /&gt;
&lt;br /&gt;
PC sounds use a modified form of the [[Inverse Frequency Sound format]] used in earlier ID games. Briefly, the sound data is stored as bytes, each specifying the inverse of a frequency. (Higher value, higher frequency.) This format is properly detailed elsewhere.&lt;br /&gt;
&lt;br /&gt;
While most PC chunks have no sound name and thus can be identified solely by their first four bytes and their length, it appears they can in fact be named and some games occasionally do name them.&lt;br /&gt;
&lt;br /&gt;
These files can be converted into Wave files easily enough, but currently the only program known to do so is Keenwave: http://levellord.toxicsheep.com/KWbeta.zip&lt;br /&gt;
&lt;br /&gt;
TODO: Document this too (Code exists to do this)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Adlib Sounds ===&lt;br /&gt;
&lt;br /&gt;
Adlib sounds are slightly more complex. Their header contains additional information to the PC sounds, used to set up the Adlib chip when playing the sound. Games always reset the chip when playing a new sound and so each sound is given 17 bytes of Adlib data. This information is what, in effect, makes the Adlib sounds sound different from the PC ones. by changing these values, various properties of the sound can be altered. Specifically these refer to the values for each of two operators for a single Adlib channel. (Adlib sounds use two sound waves, a carrier and a modulator, C1 and C2, the modulator moves through the carrier, modifying it as it does so.)  Adlib sound effects can be converted into IMF format as IMFs are essentially sequences of Adlib sounds on several instead of just one Adlib channel.&lt;br /&gt;
&lt;br /&gt;
An Adlib sound entry is contained in this structure:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || length || Length of sound data&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT16LE]] || priority || Sound priority&lt;br /&gt;
|-&lt;br /&gt;
| [[BYTE]][] || data || Actual sound data&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT8]] || terminator || ?&lt;br /&gt;
|-&lt;br /&gt;
| [[ASCIIZ]][] || name || NULL-terminated sound effect name (optional)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The format of the &amp;lt;tt&amp;gt;data&amp;lt;/tt&amp;gt; field is described on the [[Adlib sound effect]] page.&lt;br /&gt;
&lt;br /&gt;
== Utilities ==&lt;br /&gt;
&lt;br /&gt;
[http://www.winamp.com/player Download Winamp] a program capable of playing IMF files with the right library.&lt;br /&gt;
&lt;br /&gt;
KeenWave: This program can extract, and to a limited extent, edit the AUDIOT files into various formats, including wave files. It is currently at the beta stage. http://levellord.toxicsheep.com/KWbeta.zip It also contains:&lt;br /&gt;
&lt;br /&gt;
KeenISF: This program plays the Adlib sounds, if they are extracted as raw data.&lt;br /&gt;
&lt;br /&gt;
[[Category:Adlib]]&lt;br /&gt;
[[Category:Audio Files]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Music Files]]&lt;br /&gt;
[[Category:Sound Files]]&lt;br /&gt;
[[Category:Compressed Files]]&lt;br /&gt;
[[Category:Huffman Compression]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- All the games that use this file format --&amp;gt;&lt;br /&gt;
[[Category:Bio Menace]]&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Noah&#039;s Ark 3D]]&lt;br /&gt;
[[Category:Wolfenstein 3-D]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=AudioT_Format&amp;diff=3577</id>
		<title>AudioT Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=AudioT_Format&amp;diff=3577"/>
		<updated>2011-09-01T03:46:16Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* Chunks */ Noah&amp;#039;s Ark 3D&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &amp;lt;b&amp;gt;AudioT&amp;lt;/b&amp;gt; format is a [[:Category:Group Files|group file]] used by many id/Apogee games to store Adlib music, Adlib sound effects and PC Speaker sound effects in a single file.  The basic structure of this format is very similar to the [[EGAGraph_Format]] and the [[GameMaps Format]]. The main audio file can be compressed (&amp;lt;tt&amp;gt;AUDIO.xxx&amp;lt;/tt&amp;gt;) or uncompressed (&amp;lt;tt&amp;gt;AUDIOT.xxx&amp;lt;/tt&amp;gt;). It requires an associated &amp;lt;tt&amp;gt;AUDIOHED.xxx&amp;lt;/tt&amp;gt; which stores the offsets of each file, and an &amp;lt;tt&amp;gt;AUDIODCT.xxx&amp;lt;/tt&amp;gt; if the file is compressed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== File formats ==&lt;br /&gt;
&lt;br /&gt;
=== Audio Head (AUDIOHED.xxx) ===&lt;br /&gt;
&lt;br /&gt;
This header file stores the offsets (relative to the start of the &amp;lt;tt&amp;gt;AUDIO/AUDIOT&amp;lt;/tt&amp;gt; file) for each sub file.  The format is trivial, in that the header file is simply an array of &amp;lt;tt&amp;gt;UINT32LE&amp;lt;/tt&amp;gt; offsets.&lt;br /&gt;
&lt;br /&gt;
The last offset in the file will be an offset to the end of the main &amp;lt;tt&amp;gt;AUDIO/AUDIOT&amp;lt;/tt&amp;gt; file. This was probably done so that the size of each chunk could be calculated with the formula below. Thus, the number of offsets (size of the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; in dwords) minus one will give the number of chunks (slots) included in the main file. This number varies, but is usually about 200. (Games refer to the chunks by index, not by name).&lt;br /&gt;
&lt;br /&gt;
The size of a chunk can be calculated like this:&lt;br /&gt;
&lt;br /&gt;
 size[i] = offset[i+1] - offset[i]&lt;br /&gt;
&lt;br /&gt;
Empty chunks (size[i] = 0) should be skipped when extracting chunks.&lt;br /&gt;
&lt;br /&gt;
In most (not all) games, the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; is included in the executable file. See [[Extracting data files from executables]] for information on how to locate and extract them. &lt;br /&gt;
&lt;br /&gt;
=== Dictionary (AUDIODCT.xxx) ===&lt;br /&gt;
&lt;br /&gt;
If the main audio file is named &amp;lt;tt&amp;gt;AUDIO.xxx&amp;lt;/tt&amp;gt;, then the file is compressed.  The same [[Huffman Compression]] scheme used elsewhere in the [[Commander Keen]] series is used.  When reading compressed files out of the &amp;lt;tt&amp;gt;AUDIO&amp;lt;/tt&amp;gt; file, the first four bytes located at the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; offset are a UINT32LE specifying the file&#039;s decompressed size (which is required for the decompression algorithm.)  The compressed data then follows.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;AUDIODCT&amp;lt;/tt&amp;gt; file is not often obvious, usually being embedded in the main exe file. Executables usually contain two or more dictionaries, but the &amp;lt;tt&amp;gt;AUDIODCT&amp;lt;/tt&amp;gt; is usually the first one. (A simple check of whether it decompresses the data sensibly works.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Main file (AUDIOT.xxx, AUDIO.xxx) ===&lt;br /&gt;
&lt;br /&gt;
This file is simply an array of data files.  Each file starts at the offset specified in the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; file, and as there are no filenames each file is referred to by its index/slot number.  Slots containing dummy values in the header are treated as if they don&#039;t exist in the &amp;lt;tt&amp;gt;AUDIO/AUDIOT&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
If compression is in use then the &amp;lt;tt&amp;gt;AUDIO&amp;lt;/tt&amp;gt; file itself isn&#039;t compressed, rather each file within the &amp;lt;tt&amp;gt;AUDIO&amp;lt;/tt&amp;gt; file is individually compressed.  A file can be read by opening the &amp;lt;tt&amp;gt;AUDIOT&amp;lt;/tt&amp;gt; file, seeking to the offset specified in the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; file, reading a UINT32LE for the decompressed file size, and then decompressing the data from that point onwards using standard Huffman decompression techniques.&lt;br /&gt;
&lt;br /&gt;
If compression is not in use (&amp;lt;tt&amp;gt;AUDIOT&amp;lt;/tt&amp;gt; files) then a file can be read by simply seeking to the offset specified in the AUDIOHED file and reading until the offset of the following file is reached.  Since the last offset in the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; file is the size of the &amp;lt;tt&amp;gt;AUDIOT&amp;lt;/tt&amp;gt; file itself, no extra handling should be necessary to correctly read all of the last file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Chunks ==&lt;br /&gt;
&lt;br /&gt;
The AUDIOT format is a container format, meaning that any files the game can handle can be stored in it. Traditionally there have been three types of &#039;sub files&#039; or chunks: Adlib music files (which are [[IMF Format]]), Adlib sound effects and PC Speaker sound effects. By default most games store PC effects first, followed by their Adlib equivalents, with the IMF music filling the last entries.&lt;br /&gt;
&lt;br /&gt;
At least one case is known where the music is in MIDI format ([[Noah&#039;s Ark 3D]]) and it is possible that soundblaster &#039;digital&#039; sound effects have been stored like this as well at some point. There has often been confusion about what part of a file are data and which are the AUDIOT file, for example the IMF file format was widely believed to exist in two types until it was discovered that &#039;type 1&#039; IMFs were simply &#039;type 0&#039; that had been incorrectly extracted from the AUDIOT file with their chunk length and tags.&lt;br /&gt;
&lt;br /&gt;
It is notable that a sound file will contain exactly as many PC sounds as adlib sounds (and an arbitrary number of IMF files.) This is because most games have a PC\Adlib option and thus must match every PC sound with an adlib equivalent. The number of sounds appears to be hard-coded, though all games (except for [[Commander Keen Dreams]]) seem to add the string &amp;quot;!ID!&amp;quot; after the last sound of each &#039;section&#039;. The &amp;quot;!ID!&amp;quot; tags themselves don&#039;t seem to be part of any chunk and are probably put in for debugging purposes.&lt;br /&gt;
&lt;br /&gt;
Sound chunks are always in the same order, PC, then adlib then IMF. A simple method to classify the sound chunks is to check the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; for chunks of size 0. These are &#039;empty&#039; sounds and seperate sound chunks from music chunks . Every nonzero length chunk after this is an IMF chunk. (IMFs are always the last chunks in the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; and contain no zero length chunks) For the PC\adlib chunks, the number of chunks before the first zero length chunk can be divided into two, the first half being PC, the second half being adlib.&lt;br /&gt;
&lt;br /&gt;
If the file is uncompressed then the adlib and IMF chunks will be tagged (huffman compression, being a space saving exercise doesn&#039;t comoress tags.) PC chunks are never tagged. It appears that the compiler used added a footer to each chunk as they were compiled. For sounds these are null terminated strings of 12 characters or less, including terminator. For IMF files these are 88 byte strings detailed on the [[IMF Format]] page. These names are not read by games (with the possible exception of the aforementioned &#039;!ID!&#039; tags.)&lt;br /&gt;
&lt;br /&gt;
TODO: Need to also document both sound effect formats so the sounds can be edited and not just imported/exported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== IMF Music ===&lt;br /&gt;
&lt;br /&gt;
[[IMF Format]] files are packed at the end of the audio file. Occasionally &#039;empty&#039; music files are found (e.g [[Wolfenstein 3-D]]) that contain no actual data, just footer information placed there by a compiler. They can be extracted as they are and played with various utilities such as Adplug.&lt;br /&gt;
&lt;br /&gt;
=== PC Sounds ===&lt;br /&gt;
&lt;br /&gt;
 0    4    Length of sound data (Usually chunk length - 7)&lt;br /&gt;
 4    2    Priority of sound, only 1 PC sound may play at a time; any sound&lt;br /&gt;
           will interrupt a sound of equal or lower priority.&lt;br /&gt;
 6    ?    Sound data&lt;br /&gt;
 ?    1    Terminating null&lt;br /&gt;
&lt;br /&gt;
PC sounds use a modified form of the [[Inverse Frequency Sound format]] used in earlier ID games. Briefly, the sound data is stored as bytes, each specifying the inverse of a frequency. (Higher value, higher frequency.) This format is properly detailed elsewhere.&lt;br /&gt;
&lt;br /&gt;
While most PC chunks have no sound name and thus can be identified solely by their first four bytes and their length, it appears they can in fact be named and some games occasionally do name them.&lt;br /&gt;
&lt;br /&gt;
These files can be converted into Wave files easily enough, but currently the only program known to do so is Keenwave: http://levellord.toxicsheep.com/KWbeta.zip&lt;br /&gt;
&lt;br /&gt;
TODO: Document this too (Code exists to do this)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Adlib Sounds ===&lt;br /&gt;
&lt;br /&gt;
Adlib sounds are slightly more complex. Their header contains additional information to the PC sounds, used to set up the Adlib chip when playing the sound. Games always reset the chip when playing a new sound and so each sound is given 17 bytes of Adlib data. This information is what, in effect, makes the Adlib sounds sound different from the PC ones. by changing these values, various properties of the sound can be altered. Specifically these refer to the values for each of two operators for a single Adlib channel. (Adlib sounds use two sound waves, a carrier and a modulator, C1 and C2, the modulator moves through the carrier, modifying it as it does so.)  Adlib sound effects can be converted into IMF format as IMFs are essentially sequences of Adlib sounds on several instead of just one Adlib channel.&lt;br /&gt;
&lt;br /&gt;
An Adlib sound entry is contained in this structure:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || length || Length of sound data&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT16LE]] || priority || Sound priority&lt;br /&gt;
|-&lt;br /&gt;
| [[BYTE]][] || data || Actual sound data&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT8]] || terminator || ?&lt;br /&gt;
|-&lt;br /&gt;
| [[ASCIIZ]][] || name || NULL-terminated sound effect name (optional)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The format of the &amp;lt;tt&amp;gt;data&amp;lt;/tt&amp;gt; field is described on the [[Adlib sound effect]] page.&lt;br /&gt;
&lt;br /&gt;
== Utilities ==&lt;br /&gt;
&lt;br /&gt;
[http://www.winamp.com/player Download Winamp] a program capable of playing IMF files with the right library.&lt;br /&gt;
&lt;br /&gt;
KeenWave: This program can extract, and to a limited extent, edit the AUDIOT files into various formats, including wave files. It is currently at the beta stage. http://levellord.toxicsheep.com/KWbeta.zip It also contains:&lt;br /&gt;
&lt;br /&gt;
KeenISF: This program plays the Adlib sounds, if they are extracted as raw data.&lt;br /&gt;
&lt;br /&gt;
[[Category:Adlib]]&lt;br /&gt;
[[Category:Audio Files]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Music Files]]&lt;br /&gt;
[[Category:Sound Files]]&lt;br /&gt;
[[Category:Compressed Files]]&lt;br /&gt;
[[Category:Huffman Compression]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- All the games that use this file format --&amp;gt;&lt;br /&gt;
[[Category:Bio Menace]]&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Wolfenstein 3-D]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=AudioT_Format&amp;diff=3576</id>
		<title>AudioT Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=AudioT_Format&amp;diff=3576"/>
		<updated>2011-09-01T03:43:17Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* IMF Music */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &amp;lt;b&amp;gt;AudioT&amp;lt;/b&amp;gt; format is a [[:Category:Group Files|group file]] used by many id/Apogee games to store Adlib music, Adlib sound effects and PC Speaker sound effects in a single file.  The basic structure of this format is very similar to the [[EGAGraph_Format]] and the [[GameMaps Format]]. The main audio file can be compressed (&amp;lt;tt&amp;gt;AUDIO.xxx&amp;lt;/tt&amp;gt;) or uncompressed (&amp;lt;tt&amp;gt;AUDIOT.xxx&amp;lt;/tt&amp;gt;). It requires an associated &amp;lt;tt&amp;gt;AUDIOHED.xxx&amp;lt;/tt&amp;gt; which stores the offsets of each file, and an &amp;lt;tt&amp;gt;AUDIODCT.xxx&amp;lt;/tt&amp;gt; if the file is compressed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== File formats ==&lt;br /&gt;
&lt;br /&gt;
=== Audio Head (AUDIOHED.xxx) ===&lt;br /&gt;
&lt;br /&gt;
This header file stores the offsets (relative to the start of the &amp;lt;tt&amp;gt;AUDIO/AUDIOT&amp;lt;/tt&amp;gt; file) for each sub file.  The format is trivial, in that the header file is simply an array of &amp;lt;tt&amp;gt;UINT32LE&amp;lt;/tt&amp;gt; offsets.&lt;br /&gt;
&lt;br /&gt;
The last offset in the file will be an offset to the end of the main &amp;lt;tt&amp;gt;AUDIO/AUDIOT&amp;lt;/tt&amp;gt; file. This was probably done so that the size of each chunk could be calculated with the formula below. Thus, the number of offsets (size of the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; in dwords) minus one will give the number of chunks (slots) included in the main file. This number varies, but is usually about 200. (Games refer to the chunks by index, not by name).&lt;br /&gt;
&lt;br /&gt;
The size of a chunk can be calculated like this:&lt;br /&gt;
&lt;br /&gt;
 size[i] = offset[i+1] - offset[i]&lt;br /&gt;
&lt;br /&gt;
Empty chunks (size[i] = 0) should be skipped when extracting chunks.&lt;br /&gt;
&lt;br /&gt;
In most (not all) games, the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; is included in the executable file. See [[Extracting data files from executables]] for information on how to locate and extract them. &lt;br /&gt;
&lt;br /&gt;
=== Dictionary (AUDIODCT.xxx) ===&lt;br /&gt;
&lt;br /&gt;
If the main audio file is named &amp;lt;tt&amp;gt;AUDIO.xxx&amp;lt;/tt&amp;gt;, then the file is compressed.  The same [[Huffman Compression]] scheme used elsewhere in the [[Commander Keen]] series is used.  When reading compressed files out of the &amp;lt;tt&amp;gt;AUDIO&amp;lt;/tt&amp;gt; file, the first four bytes located at the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; offset are a UINT32LE specifying the file&#039;s decompressed size (which is required for the decompression algorithm.)  The compressed data then follows.&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;tt&amp;gt;AUDIODCT&amp;lt;/tt&amp;gt; file is not often obvious, usually being embedded in the main exe file. Executables usually contain two or more dictionaries, but the &amp;lt;tt&amp;gt;AUDIODCT&amp;lt;/tt&amp;gt; is usually the first one. (A simple check of whether it decompresses the data sensibly works.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Main file (AUDIOT.xxx, AUDIO.xxx) ===&lt;br /&gt;
&lt;br /&gt;
This file is simply an array of data files.  Each file starts at the offset specified in the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; file, and as there are no filenames each file is referred to by its index/slot number.  Slots containing dummy values in the header are treated as if they don&#039;t exist in the &amp;lt;tt&amp;gt;AUDIO/AUDIOT&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
If compression is in use then the &amp;lt;tt&amp;gt;AUDIO&amp;lt;/tt&amp;gt; file itself isn&#039;t compressed, rather each file within the &amp;lt;tt&amp;gt;AUDIO&amp;lt;/tt&amp;gt; file is individually compressed.  A file can be read by opening the &amp;lt;tt&amp;gt;AUDIOT&amp;lt;/tt&amp;gt; file, seeking to the offset specified in the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; file, reading a UINT32LE for the decompressed file size, and then decompressing the data from that point onwards using standard Huffman decompression techniques.&lt;br /&gt;
&lt;br /&gt;
If compression is not in use (&amp;lt;tt&amp;gt;AUDIOT&amp;lt;/tt&amp;gt; files) then a file can be read by simply seeking to the offset specified in the AUDIOHED file and reading until the offset of the following file is reached.  Since the last offset in the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; file is the size of the &amp;lt;tt&amp;gt;AUDIOT&amp;lt;/tt&amp;gt; file itself, no extra handling should be necessary to correctly read all of the last file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Chunks ==&lt;br /&gt;
&lt;br /&gt;
The AUDIOT format is a container format, meaning that any files the game can handle can be stored in it. Traditionally there have been three types of &#039;sub files&#039; or chunks: Adlib music files (which are [[IMF Format]]), Adlib sound effects and PC Speaker sound effects. By default most games store PC effects first, followed by their Adlib equivalents, with the IMF music filling the last entries.&lt;br /&gt;
&lt;br /&gt;
At least on case is known where the music is in MIDI format (Noah&#039;s Ark 3D) and it is possible that soundblaster &#039;digital&#039; sound effects have been stored like this as well at some point. There has often been confusion about what part of a file are data and which are the AUDIOT file, for example the IMF file format was widely believed to exist in two types until it was discovered that &#039;type 1&#039; IMFs were simply &#039;type 0&#039; that had been incorrectly extracted from the AUDIOT file with their chunk length and tags.&lt;br /&gt;
&lt;br /&gt;
It is notable that a sound file will contain exactly as many PC sounds as adlib sounds (and an arbitrary number of IMF files.) This is because most games have a PC\Adlib option and thus must match every PC sound with an adlib equivalent. The number of sounds appears to be hard-coded, though all games (except for [[Commander Keen Dreams]]) seem to add the string &amp;quot;!ID!&amp;quot; after the last sound of each &#039;section&#039;. The &amp;quot;!ID!&amp;quot; tags themselves don&#039;t seem to be part of any chunk and are probably put in for debugging purposes.&lt;br /&gt;
&lt;br /&gt;
Sound chunks are always in the same order, PC, then adlib then IMF. A simple method to classify the sound chunks is to check the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; for chunks of size 0. These are &#039;empty&#039; sounds and seperate sound chunks from music chunks . Every nonzero length chunk after this is an IMF chunk. (IMFs are always the last chunks in the &amp;lt;tt&amp;gt;AUDIOHED&amp;lt;/tt&amp;gt; and contain no zero length chunks) For the PC\adlib chunks, the number of chunks before the first zero length chunk can be divided into two, the first half being PC, the second half being adlib.&lt;br /&gt;
&lt;br /&gt;
If the file is uncompressed then the adlib and IMF chunks will be tagged (huffman compression, being a space saving exercise doesn&#039;t comoress tags.) PC chunks are never tagged. It appears that the compiler used added a footer to each chunk as they were compiled. For sounds these are null terminated strings of 12 characters or less, including terminator. For IMF files these are 88 byte strings detailed on the [[IMF Format]] page. These names are not read by games (with the possible exception of the aforementioned &#039;!ID!&#039; tags.)&lt;br /&gt;
&lt;br /&gt;
TODO: Need to also document both sound effect formats so the sounds can be edited and not just imported/exported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== IMF Music ===&lt;br /&gt;
&lt;br /&gt;
[[IMF Format]] files are packed at the end of the audio file. Occasionally &#039;empty&#039; music files are found (e.g [[Wolfenstein 3-D]]) that contain no actual data, just footer information placed there by a compiler. They can be extracted as they are and played with various utilities such as Adplug.&lt;br /&gt;
&lt;br /&gt;
=== PC Sounds ===&lt;br /&gt;
&lt;br /&gt;
 0    4    Length of sound data (Usually chunk length - 7)&lt;br /&gt;
 4    2    Priority of sound, only 1 PC sound may play at a time; any sound&lt;br /&gt;
           will interrupt a sound of equal or lower priority.&lt;br /&gt;
 6    ?    Sound data&lt;br /&gt;
 ?    1    Terminating null&lt;br /&gt;
&lt;br /&gt;
PC sounds use a modified form of the [[Inverse Frequency Sound format]] used in earlier ID games. Briefly, the sound data is stored as bytes, each specifying the inverse of a frequency. (Higher value, higher frequency.) This format is properly detailed elsewhere.&lt;br /&gt;
&lt;br /&gt;
While most PC chunks have no sound name and thus can be identified solely by their first four bytes and their length, it appears they can in fact be named and some games occasionally do name them.&lt;br /&gt;
&lt;br /&gt;
These files can be converted into Wave files easily enough, but currently the only program known to do so is Keenwave: http://levellord.toxicsheep.com/KWbeta.zip&lt;br /&gt;
&lt;br /&gt;
TODO: Document this too (Code exists to do this)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Adlib Sounds ===&lt;br /&gt;
&lt;br /&gt;
Adlib sounds are slightly more complex. Their header contains additional information to the PC sounds, used to set up the Adlib chip when playing the sound. Games always reset the chip when playing a new sound and so each sound is given 17 bytes of Adlib data. This information is what, in effect, makes the Adlib sounds sound different from the PC ones. by changing these values, various properties of the sound can be altered. Specifically these refer to the values for each of two operators for a single Adlib channel. (Adlib sounds use two sound waves, a carrier and a modulator, C1 and C2, the modulator moves through the carrier, modifying it as it does so.)  Adlib sound effects can be converted into IMF format as IMFs are essentially sequences of Adlib sounds on several instead of just one Adlib channel.&lt;br /&gt;
&lt;br /&gt;
An Adlib sound entry is contained in this structure:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || length || Length of sound data&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT16LE]] || priority || Sound priority&lt;br /&gt;
|-&lt;br /&gt;
| [[BYTE]][] || data || Actual sound data&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT8]] || terminator || ?&lt;br /&gt;
|-&lt;br /&gt;
| [[ASCIIZ]][] || name || NULL-terminated sound effect name (optional)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The format of the &amp;lt;tt&amp;gt;data&amp;lt;/tt&amp;gt; field is described on the [[Adlib sound effect]] page.&lt;br /&gt;
&lt;br /&gt;
== Utilities ==&lt;br /&gt;
&lt;br /&gt;
[http://www.winamp.com/player Download Winamp] a program capable of playing IMF files with the right library.&lt;br /&gt;
&lt;br /&gt;
KeenWave: This program can extract, and to a limited extent, edit the AUDIOT files into various formats, including wave files. It is currently at the beta stage. http://levellord.toxicsheep.com/KWbeta.zip It also contains:&lt;br /&gt;
&lt;br /&gt;
KeenISF: This program plays the Adlib sounds, if they are extracted as raw data.&lt;br /&gt;
&lt;br /&gt;
[[Category:Adlib]]&lt;br /&gt;
[[Category:Audio Files]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Music Files]]&lt;br /&gt;
[[Category:Sound Files]]&lt;br /&gt;
[[Category:Compressed Files]]&lt;br /&gt;
[[Category:Huffman Compression]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- All the games that use this file format --&amp;gt;&lt;br /&gt;
[[Category:Bio Menace]]&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Wolfenstein 3-D]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Carmack_compression&amp;diff=3575</id>
		<title>Carmack compression</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Carmack_compression&amp;diff=3575"/>
		<updated>2011-09-01T03:37:58Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: More games that use it, categories&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Carmack compression]] is used in the [[GameMaps Format|GAMEMAPS file]] in [[Commander Keen 4-6]], [[Catacomb 3D]], [[Wolfenstein 3D]], and [[Noah&#039;s Ark 3D]] to further shrink the levels down beyond what [[RLEW compression]] can achieve. Its basic idea is somewhat like LZ (Lempel-Ziv) compression in that it contains pointers back to previous data.&lt;br /&gt;
&lt;br /&gt;
As in RLEW compression, the first word in the Carmack compressed data is the number of bytes (not words) in the decompressed data. This is typically the number of bytes in the compressed RLEW data, as Carmack compression is performed after RLEW compression.&lt;br /&gt;
&lt;br /&gt;
Carmack compression contains two types of references to previous data: near pointers and far pointers.&lt;br /&gt;
&lt;br /&gt;
= Near Pointers =&lt;br /&gt;
&lt;br /&gt;
Near pointers occupy three bytes in the compressed data. The first is the number of words in the referenced sequence, the second is the signal byte of xA7, and the third is the number of words to the start of the reference (counting backwards from the current location). As a concrete example, the three bytes x05 xA7 x0A mean &#039;repeat the 5 words starting 10 words ago&#039;.&lt;br /&gt;
&lt;br /&gt;
Notice that near pointers only let one refer to the last 255 words. To refer to sequences further back, one must use far pointers.&lt;br /&gt;
&lt;br /&gt;
= Far Pointers =&lt;br /&gt;
&lt;br /&gt;
Far pointers occupy four bytes in the compressed data. The first is, again, the number of words in the referenced sequence, the second is xA8, and the third and fourth are interpreted as a word - a 0-based pointer to the start of the reference (in words). As a concrete example, the four bytes x10 xA8 x01 x20 mean &#039;repeat the 16 words starting at word number 513&#039;.&lt;br /&gt;
&lt;br /&gt;
= Words with a high byte of $A7 or $A8 =&lt;br /&gt;
&lt;br /&gt;
Words whose high (second) byte is xA7 or xA8 would appear to be issue, as they would be confused with near or far pointers. These are handled by representing them as the three bytes: $00, $Ax $xx, this is recognized as an exception (Repeating zero words would make no sense.)&lt;br /&gt;
&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Compressed Files]]&lt;br /&gt;
[[Category:Compression Algorithms]]&lt;br /&gt;
[[Category:Commander Keen 4-6]]&lt;br /&gt;
[[Category:Catacomb 3D]]&lt;br /&gt;
[[Category:Wolfenstein 3D]]&lt;br /&gt;
[[Category:Noah&#039;s Ark 3D]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=GameMaps_Format&amp;diff=3574</id>
		<title>GameMaps Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=GameMaps_Format&amp;diff=3574"/>
		<updated>2011-08-31T16:20:54Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* Location of internal files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The GameMaps format is how the levels in a number of [[Id Software]] games is stored. The filenames and compression varies somewhat across different games but all files stored in this format were produced by the program [[TED5]] or a close analogue.&lt;br /&gt;
&lt;br /&gt;
There are three main varieties of the GameMaps format, uncompressed, [[Carmack compression||carmackized]], and  [[Huffman Compression|huffman compressed]]. Each variation has its own file naming scheme  and pattern of external\internal files.&lt;br /&gt;
&lt;br /&gt;
There are two main components to the format, the game maps proper, which contain the game level data and the map headers, which contain both the locations of the start of level data in the game maps file and the tile info for the game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Structure of uncompressed data ==&lt;br /&gt;
&lt;br /&gt;
The uncompressed format is used by several games including [[Bio Menace]] and [[Wolfenstein 3D]]. In this format map data is stored in &amp;lt;tt&amp;gt;MAPTEMP.xxx&amp;lt;tt&amp;gt; and map headers in &amp;lt;tt&amp;gt;MAPTHEAD.xxx&amp;lt;/tt&amp;gt; this is the format saved by [[TED5]] when maps are being edited and can be directly accessed and edited by this utility, allowing changes to be made to the game.&lt;br /&gt;
&lt;br /&gt;
Note that filenames differ and that Wolfenstein 3D uses &amp;lt;tt&amp;gt;GAMEMAPS.WLx&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;MAPHEAD.xxx&amp;lt;/tt&amp;gt; files to store data. The main indicator of this format being used is that in the unaltered game the map header file is external.&lt;br /&gt;
&lt;br /&gt;
Only the latest Id Software games lacked compression, when file size was no longer an issue.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Map headers ===&lt;br /&gt;
&lt;br /&gt;
 0    2    Magic word       Magic word for [[RLEW compression]]&lt;br /&gt;
 2    400  Level ptr        100 4-byte pointers to start of level 0-99 data in game maps file&lt;br /&gt;
 402  ???  Tileinfo         Tileinfo data&lt;br /&gt;
&lt;br /&gt;
The map header file is of varying length and contains three main types of data. The first is the magic word or flag used for RLEW compression, it is always $ABCD. The second is 100 level pointers which give the location of the start of level data in the game maps file, relative to the start of that file. A value of 0 indicates no level. The third is the tileinfo data, tile properties for each tile used in level creation. (These are masked and unmasked and either 8x8, 16x16 or 32x32)&lt;br /&gt;
&lt;br /&gt;
Many programs treat the tileinfo as a separate file from the maphead and it is possible to modify a game in this manner. Indeed, some games, such as Wolfenstein 3D do not have any tileinfo data at all in the map header file (Giving a total file length of 402 bytes.) However TED5 works with any tileinfo data in the maphead.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game maps ===&lt;br /&gt;
&lt;br /&gt;
The game maps file consists of the string &#039;TED5v1.0.&#039; and a number of RLEW compressed chunks of varying length. Each level in GameMaps will have from two to four chunks (usually four), depending on game, with all levels in a given game having the same number of chunks. These are the level header and 1-3 planes (Foreground, background and sprite or info.) The chunks are in no particular order and it is possible to read through the entire file decompressing chunks as they&#039;re found.&lt;br /&gt;
&lt;br /&gt;
Chunks are ordered by the map header file, which will point to the level header chunks which in turn contain pointers to the other chunks used by that level. It is possible the string at the start of the file is to avoid the possibility of a level header at the start of the file which would be read as not existing.&lt;br /&gt;
&lt;br /&gt;
All data in game maps file is in the form of words (Or in the case of pointers, dwords.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Level headers ===&lt;br /&gt;
&lt;br /&gt;
The header for each level that is pointed to by MAPHEAD is 42 bytes long and RLEW compressed, though this is difficult to see since the data is so short and nonrepetitive. For the offsets to level planes a value of 0 indicates the plane does not exist.&lt;br /&gt;
&lt;br /&gt;
Plane 1 is background using unmasked tiles, plane 2 is foreground and uses masked tiles. Plane 3 is sprite or info. Levels must contain c background plane and usually an infoplane.&lt;br /&gt;
&lt;br /&gt;
 0   4    Offset in GAMEMAPS to beginning of compressed plane 0 data&lt;br /&gt;
 4   4    Offset in GAMEMAPS to beginning of compressed plane 1 data&lt;br /&gt;
 8   4    Offset in GAMEMAPS to beginning of compressed plane 2 data&lt;br /&gt;
 12  2    Length of compressed plane 0 data (in bytes)&lt;br /&gt;
 14  2    Length of compressed plane 1 data (in bytes)&lt;br /&gt;
 16  2    Length of compressed plane 2 data (in bytes)&lt;br /&gt;
 18  2    Width of level (in tiles)&lt;br /&gt;
 20  2    Height of level (in tiles)&lt;br /&gt;
 22  16   Internal name for level (used only by editor, not displayed in-game. null-terminated)&lt;br /&gt;
&lt;br /&gt;
== Carmack compression ==&lt;br /&gt;
&lt;br /&gt;
[[Carmack compression]] is the method used to compress later Id Software games, when file size was an issue. It is the most efficient and complex compression method and was created specifically to work with the word structure of the game maps file. The compression is detailed on its [[Carmack compression|own page.]]&lt;br /&gt;
&lt;br /&gt;
Carmackized game maps files are external &amp;lt;tt&amp;gt;GAMEMAPS.xxx&amp;lt;/tt&amp;gt; files and the map header is stored internally in the executable. The map header must be extracted and the game maps decompressed before TED5 can access them. TED5 itself can produce carmackized files and external &amp;lt;tt&amp;gt;MAPHEAD.xxx&amp;lt;/tt&amp;gt; files. Carmackization does not replace the RLEW compression used in uncompressed data, but compresses this data, that is, the data is doubly compressed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Huffman compression ==&lt;br /&gt;
&lt;br /&gt;
Huffman compression was used by earlier versions of TED5 (possibly not TED5 at all.) before carmackization was created. It uses the same method to compress its data as is used by Id Software games to compress their graphics and sounds. Again this compression method works with RLEW compressed data and has its [[Huffman Compression|own page.]]&lt;br /&gt;
&lt;br /&gt;
Huffman compression is easily detected since it works on the bit level and thus disrupts the word structure of the game data. This is easily seen in a hex editor. Compressed data will not contain the string $00 $00 or indeed even $00 very often (In contrast even carmackized data contains both strings hundreds of times.)&lt;br /&gt;
&lt;br /&gt;
There will be two internal files for this format, the map header and the huffman dictionary (which is always the first dictionary in the executable.) The map header format is also slightly different, being 502 bytes long, the extra 100 bytes being the length of the compressed level headers in the game maps data (These can be ignored when decompressing since huffman data can be read until the decompressed level header&#039;s fixed size is reached.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Location of internal files ==&lt;br /&gt;
&lt;br /&gt;
Game maps are always external, but in the case of compression the map header file is stored internally in the executable. Executables are themselves compressed wither with LZEXE or PKLite. Once decompressed it is a trivial task to find the map header file as it will start with the word $ABCD For level editing purposes only the first 402 (or 502) bytes of the file needs to be extracted, though it is possible to read the maphead file to calculate its length.&lt;br /&gt;
&lt;br /&gt;
The following addresses are in the locations in the decompressed executables for the start of the Map header files. Values are different for different versions.&lt;br /&gt;
&lt;br /&gt;
TODO: Add all known versions of all games.&lt;br /&gt;
&lt;br /&gt;
External files&lt;br /&gt;
 Biomenace&lt;br /&gt;
 Blake Stone 2: Planet Strike&lt;br /&gt;
 Corridor 7 Demo&lt;br /&gt;
 Noahs Ark 3D&lt;br /&gt;
 Operation Body Count&lt;br /&gt;
 Spear of Destiny&lt;br /&gt;
 Wolfenstein 3D&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Internal files:&lt;br /&gt;
  Catacomb 3-D&lt;br /&gt;
  Catacomb 4 Abyss&lt;br /&gt;
  Catacomb 5 Apocalypse&lt;br /&gt;
  Catacomb 6 Armageddon&lt;br /&gt;
  Corridor 7 CD (): $30D50 from start of file CORR7CD.EXE (file is not compressed)&lt;br /&gt;
  Corridor 7 Floppy (): $24BF0 from start of file C7.EXE (file is not compressed)&lt;br /&gt;
  Keen 4 (Special Demo): (file is PKLite compressed)&lt;br /&gt;
  Keen 4 (1.4): $24830&lt;br /&gt;
  Keen 5 (1.4): $25990&lt;br /&gt;
  Keen 6 (1.4): $25080&lt;br /&gt;
 (Keen D (1.13): $1FA50)&lt;br /&gt;
&lt;br /&gt;
== Utilities ==&lt;br /&gt;
&lt;br /&gt;
[[TED5]] This program can edit the &amp;lt;tt&amp;gt;GAMEMAPS&amp;lt;/tt&amp;gt; format of any games that use it. It is the original editor used to crate these files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
This format was reverse engineered by Andrew Durdin (adurdin).&lt;br /&gt;
&lt;br /&gt;
The format is used by other games as well, including [[Bio Menace]], [[Blake Stone]], [[Catacomb 3D]], [[Corridor 7]], [[Dangerous Dave 3]], [[Dave Goes Nutz]], [[Noah&#039;s Ark 3D]], [[Operation Body Count]], [[Spear of Destiny]], and [[Wolfenstein 3D]].&lt;br /&gt;
&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Map Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=GameMaps_Format&amp;diff=3573</id>
		<title>GameMaps Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=GameMaps_Format&amp;diff=3573"/>
		<updated>2011-08-31T16:02:28Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* Notes */ More games&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The GameMaps format is how the levels in a number of [[Id Software]] games is stored. The filenames and compression varies somewhat across different games but all files stored in this format were produced by the program [[TED5]] or a close analogue.&lt;br /&gt;
&lt;br /&gt;
There are three main varieties of the GameMaps format, uncompressed, [[Carmack compression||carmackized]], and  [[Huffman Compression|huffman compressed]]. Each variation has its own file naming scheme  and pattern of external\internal files.&lt;br /&gt;
&lt;br /&gt;
There are two main components to the format, the game maps proper, which contain the game level data and the map headers, which contain both the locations of the start of level data in the game maps file and the tile info for the game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Structure of uncompressed data ==&lt;br /&gt;
&lt;br /&gt;
The uncompressed format is used by several games including [[Bio Menace]] and [[Wolfenstein 3D]]. In this format map data is stored in &amp;lt;tt&amp;gt;MAPTEMP.xxx&amp;lt;tt&amp;gt; and map headers in &amp;lt;tt&amp;gt;MAPTHEAD.xxx&amp;lt;/tt&amp;gt; this is the format saved by [[TED5]] when maps are being edited and can be directly accessed and edited by this utility, allowing changes to be made to the game.&lt;br /&gt;
&lt;br /&gt;
Note that filenames differ and that Wolfenstein 3D uses &amp;lt;tt&amp;gt;GAMEMAPS.WLx&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;MAPHEAD.xxx&amp;lt;/tt&amp;gt; files to store data. The main indicator of this format being used is that in the unaltered game the map header file is external.&lt;br /&gt;
&lt;br /&gt;
Only the latest Id Software games lacked compression, when file size was no longer an issue.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Map headers ===&lt;br /&gt;
&lt;br /&gt;
 0    2    Magic word       Magic word for [[RLEW compression]]&lt;br /&gt;
 2    400  Level ptr        100 4-byte pointers to start of level 0-99 data in game maps file&lt;br /&gt;
 402  ???  Tileinfo         Tileinfo data&lt;br /&gt;
&lt;br /&gt;
The map header file is of varying length and contains three main types of data. The first is the magic word or flag used for RLEW compression, it is always $ABCD. The second is 100 level pointers which give the location of the start of level data in the game maps file, relative to the start of that file. A value of 0 indicates no level. The third is the tileinfo data, tile properties for each tile used in level creation. (These are masked and unmasked and either 8x8, 16x16 or 32x32)&lt;br /&gt;
&lt;br /&gt;
Many programs treat the tileinfo as a separate file from the maphead and it is possible to modify a game in this manner. Indeed, some games, such as Wolfenstein 3D do not have any tileinfo data at all in the map header file (Giving a total file length of 402 bytes.) However TED5 works with any tileinfo data in the maphead.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game maps ===&lt;br /&gt;
&lt;br /&gt;
The game maps file consists of the string &#039;TED5v1.0.&#039; and a number of RLEW compressed chunks of varying length. Each level in GameMaps will have from two to four chunks (usually four), depending on game, with all levels in a given game having the same number of chunks. These are the level header and 1-3 planes (Foreground, background and sprite or info.) The chunks are in no particular order and it is possible to read through the entire file decompressing chunks as they&#039;re found.&lt;br /&gt;
&lt;br /&gt;
Chunks are ordered by the map header file, which will point to the level header chunks which in turn contain pointers to the other chunks used by that level. It is possible the string at the start of the file is to avoid the possibility of a level header at the start of the file which would be read as not existing.&lt;br /&gt;
&lt;br /&gt;
All data in game maps file is in the form of words (Or in the case of pointers, dwords.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Level headers ===&lt;br /&gt;
&lt;br /&gt;
The header for each level that is pointed to by MAPHEAD is 42 bytes long and RLEW compressed, though this is difficult to see since the data is so short and nonrepetitive. For the offsets to level planes a value of 0 indicates the plane does not exist.&lt;br /&gt;
&lt;br /&gt;
Plane 1 is background using unmasked tiles, plane 2 is foreground and uses masked tiles. Plane 3 is sprite or info. Levels must contain c background plane and usually an infoplane.&lt;br /&gt;
&lt;br /&gt;
 0   4    Offset in GAMEMAPS to beginning of compressed plane 0 data&lt;br /&gt;
 4   4    Offset in GAMEMAPS to beginning of compressed plane 1 data&lt;br /&gt;
 8   4    Offset in GAMEMAPS to beginning of compressed plane 2 data&lt;br /&gt;
 12  2    Length of compressed plane 0 data (in bytes)&lt;br /&gt;
 14  2    Length of compressed plane 1 data (in bytes)&lt;br /&gt;
 16  2    Length of compressed plane 2 data (in bytes)&lt;br /&gt;
 18  2    Width of level (in tiles)&lt;br /&gt;
 20  2    Height of level (in tiles)&lt;br /&gt;
 22  16   Internal name for level (used only by editor, not displayed in-game. null-terminated)&lt;br /&gt;
&lt;br /&gt;
== Carmack compression ==&lt;br /&gt;
&lt;br /&gt;
[[Carmack compression]] is the method used to compress later Id Software games, when file size was an issue. It is the most efficient and complex compression method and was created specifically to work with the word structure of the game maps file. The compression is detailed on its [[Carmack compression|own page.]]&lt;br /&gt;
&lt;br /&gt;
Carmackized game maps files are external &amp;lt;tt&amp;gt;GAMEMAPS.xxx&amp;lt;/tt&amp;gt; files and the map header is stored internally in the executable. The map header must be extracted and the game maps decompressed before TED5 can access them. TED5 itself can produce carmackized files and external &amp;lt;tt&amp;gt;MAPHEAD.xxx&amp;lt;/tt&amp;gt; files. Carmackization does not replace the RLEW compression used in uncompressed data, but compresses this data, that is, the data is doubly compressed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Huffman compression ==&lt;br /&gt;
&lt;br /&gt;
Huffman compression was used by earlier versions of TED5 (possibly not TED5 at all.) before carmackization was created. It uses the same method to compress its data as is used by Id Software games to compress their graphics and sounds. Again this compression method works with RLEW compressed data and has its [[Huffman Compression|own page.]]&lt;br /&gt;
&lt;br /&gt;
Huffman compression is easily detected since it works on the bit level and thus disrupts the word structure of the game data. This is easily seen in a hex editor. Compressed data will not contain the string $00 $00 or indeed even $00 very often (In contrast even carmackized data contains both strings hundreds of times.)&lt;br /&gt;
&lt;br /&gt;
There will be two internal files for this format, the map header and the huffman dictionary (which is always the first dictionary in the executable.) The map header format is also slightly different, being 502 bytes long, the extra 100 bytes being the length of the compressed level headers in the game maps data (These can be ignored when decompressing since huffman data can be read until the decompressed level header&#039;s fixed size is reached.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Location of internal files ==&lt;br /&gt;
&lt;br /&gt;
Game maps are always external, but in the case of compression the map header file is stored internally in the executable. Executables are themselves compressed wither with LZEXE or PKLite. Once decompressed it is a trivial task to find the map header file as it will start with the word $ABCD For level editing purposes only the first 402 (or 502) bytes of the file needs to be extracted, though it is possible to read the maphead file to calculate its length.&lt;br /&gt;
&lt;br /&gt;
The following addresses are in the locations in the decompressed executables for the start of the Map header files. Values are different for different versions.&lt;br /&gt;
&lt;br /&gt;
TODO: Add all known versions of all games.&lt;br /&gt;
&lt;br /&gt;
External files&lt;br /&gt;
 Biomenace&lt;br /&gt;
 Blake Stone 2: Planet Strike&lt;br /&gt;
 Corridor 7 Demo&lt;br /&gt;
 Noahs Ark 3D&lt;br /&gt;
 Operation Body Count&lt;br /&gt;
 Spear of Destiny&lt;br /&gt;
 Wolfenstein 3D&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Internal files:&lt;br /&gt;
  Keen 4 (Special Demo): (file is PKLite compressed)&lt;br /&gt;
  Keen 4 (1.4): $24830&lt;br /&gt;
  Keen 5 (1.4): $25990&lt;br /&gt;
  Keen 6 (1.4): $25080&lt;br /&gt;
 (Keen D (1.13): $1FA50)&lt;br /&gt;
  Corridor 7 CD (): $30D50 from start of file CORR7CD.EXE (file is not compressed)&lt;br /&gt;
&lt;br /&gt;
== Utilities ==&lt;br /&gt;
&lt;br /&gt;
[[TED5]] This program can edit the &amp;lt;tt&amp;gt;GAMEMAPS&amp;lt;/tt&amp;gt; format of any games that use it. It is the original editor used to crate these files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
This format was reverse engineered by Andrew Durdin (adurdin).&lt;br /&gt;
&lt;br /&gt;
The format is used by other games as well, including [[Bio Menace]], [[Blake Stone]], [[Catacomb 3D]], [[Corridor 7]], [[Dangerous Dave 3]], [[Dave Goes Nutz]], [[Noah&#039;s Ark 3D]], [[Operation Body Count]], [[Spear of Destiny]], and [[Wolfenstein 3D]].&lt;br /&gt;
&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Map Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=GameMaps_Format&amp;diff=3572</id>
		<title>GameMaps Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=GameMaps_Format&amp;diff=3572"/>
		<updated>2011-08-31T15:58:11Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* Location of internal files */ Blake Stone 2, Spear of Destiny&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The GameMaps format is how the levels in a number of [[Id Software]] games is stored. The filenames and compression varies somewhat across different games but all files stored in this format were produced by the program [[TED5]] or a close analogue.&lt;br /&gt;
&lt;br /&gt;
There are three main varieties of the GameMaps format, uncompressed, [[Carmack compression||carmackized]], and  [[Huffman Compression|huffman compressed]]. Each variation has its own file naming scheme  and pattern of external\internal files.&lt;br /&gt;
&lt;br /&gt;
There are two main components to the format, the game maps proper, which contain the game level data and the map headers, which contain both the locations of the start of level data in the game maps file and the tile info for the game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Structure of uncompressed data ==&lt;br /&gt;
&lt;br /&gt;
The uncompressed format is used by several games including [[Bio Menace]] and [[Wolfenstein 3D]]. In this format map data is stored in &amp;lt;tt&amp;gt;MAPTEMP.xxx&amp;lt;tt&amp;gt; and map headers in &amp;lt;tt&amp;gt;MAPTHEAD.xxx&amp;lt;/tt&amp;gt; this is the format saved by [[TED5]] when maps are being edited and can be directly accessed and edited by this utility, allowing changes to be made to the game.&lt;br /&gt;
&lt;br /&gt;
Note that filenames differ and that Wolfenstein 3D uses &amp;lt;tt&amp;gt;GAMEMAPS.WLx&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;MAPHEAD.xxx&amp;lt;/tt&amp;gt; files to store data. The main indicator of this format being used is that in the unaltered game the map header file is external.&lt;br /&gt;
&lt;br /&gt;
Only the latest Id Software games lacked compression, when file size was no longer an issue.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Map headers ===&lt;br /&gt;
&lt;br /&gt;
 0    2    Magic word       Magic word for [[RLEW compression]]&lt;br /&gt;
 2    400  Level ptr        100 4-byte pointers to start of level 0-99 data in game maps file&lt;br /&gt;
 402  ???  Tileinfo         Tileinfo data&lt;br /&gt;
&lt;br /&gt;
The map header file is of varying length and contains three main types of data. The first is the magic word or flag used for RLEW compression, it is always $ABCD. The second is 100 level pointers which give the location of the start of level data in the game maps file, relative to the start of that file. A value of 0 indicates no level. The third is the tileinfo data, tile properties for each tile used in level creation. (These are masked and unmasked and either 8x8, 16x16 or 32x32)&lt;br /&gt;
&lt;br /&gt;
Many programs treat the tileinfo as a separate file from the maphead and it is possible to modify a game in this manner. Indeed, some games, such as Wolfenstein 3D do not have any tileinfo data at all in the map header file (Giving a total file length of 402 bytes.) However TED5 works with any tileinfo data in the maphead.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game maps ===&lt;br /&gt;
&lt;br /&gt;
The game maps file consists of the string &#039;TED5v1.0.&#039; and a number of RLEW compressed chunks of varying length. Each level in GameMaps will have from two to four chunks (usually four), depending on game, with all levels in a given game having the same number of chunks. These are the level header and 1-3 planes (Foreground, background and sprite or info.) The chunks are in no particular order and it is possible to read through the entire file decompressing chunks as they&#039;re found.&lt;br /&gt;
&lt;br /&gt;
Chunks are ordered by the map header file, which will point to the level header chunks which in turn contain pointers to the other chunks used by that level. It is possible the string at the start of the file is to avoid the possibility of a level header at the start of the file which would be read as not existing.&lt;br /&gt;
&lt;br /&gt;
All data in game maps file is in the form of words (Or in the case of pointers, dwords.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Level headers ===&lt;br /&gt;
&lt;br /&gt;
The header for each level that is pointed to by MAPHEAD is 42 bytes long and RLEW compressed, though this is difficult to see since the data is so short and nonrepetitive. For the offsets to level planes a value of 0 indicates the plane does not exist.&lt;br /&gt;
&lt;br /&gt;
Plane 1 is background using unmasked tiles, plane 2 is foreground and uses masked tiles. Plane 3 is sprite or info. Levels must contain c background plane and usually an infoplane.&lt;br /&gt;
&lt;br /&gt;
 0   4    Offset in GAMEMAPS to beginning of compressed plane 0 data&lt;br /&gt;
 4   4    Offset in GAMEMAPS to beginning of compressed plane 1 data&lt;br /&gt;
 8   4    Offset in GAMEMAPS to beginning of compressed plane 2 data&lt;br /&gt;
 12  2    Length of compressed plane 0 data (in bytes)&lt;br /&gt;
 14  2    Length of compressed plane 1 data (in bytes)&lt;br /&gt;
 16  2    Length of compressed plane 2 data (in bytes)&lt;br /&gt;
 18  2    Width of level (in tiles)&lt;br /&gt;
 20  2    Height of level (in tiles)&lt;br /&gt;
 22  16   Internal name for level (used only by editor, not displayed in-game. null-terminated)&lt;br /&gt;
&lt;br /&gt;
== Carmack compression ==&lt;br /&gt;
&lt;br /&gt;
[[Carmack compression]] is the method used to compress later Id Software games, when file size was an issue. It is the most efficient and complex compression method and was created specifically to work with the word structure of the game maps file. The compression is detailed on its [[Carmack compression|own page.]]&lt;br /&gt;
&lt;br /&gt;
Carmackized game maps files are external &amp;lt;tt&amp;gt;GAMEMAPS.xxx&amp;lt;/tt&amp;gt; files and the map header is stored internally in the executable. The map header must be extracted and the game maps decompressed before TED5 can access them. TED5 itself can produce carmackized files and external &amp;lt;tt&amp;gt;MAPHEAD.xxx&amp;lt;/tt&amp;gt; files. Carmackization does not replace the RLEW compression used in uncompressed data, but compresses this data, that is, the data is doubly compressed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Huffman compression ==&lt;br /&gt;
&lt;br /&gt;
Huffman compression was used by earlier versions of TED5 (possibly not TED5 at all.) before carmackization was created. It uses the same method to compress its data as is used by Id Software games to compress their graphics and sounds. Again this compression method works with RLEW compressed data and has its [[Huffman Compression|own page.]]&lt;br /&gt;
&lt;br /&gt;
Huffman compression is easily detected since it works on the bit level and thus disrupts the word structure of the game data. This is easily seen in a hex editor. Compressed data will not contain the string $00 $00 or indeed even $00 very often (In contrast even carmackized data contains both strings hundreds of times.)&lt;br /&gt;
&lt;br /&gt;
There will be two internal files for this format, the map header and the huffman dictionary (which is always the first dictionary in the executable.) The map header format is also slightly different, being 502 bytes long, the extra 100 bytes being the length of the compressed level headers in the game maps data (These can be ignored when decompressing since huffman data can be read until the decompressed level header&#039;s fixed size is reached.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Location of internal files ==&lt;br /&gt;
&lt;br /&gt;
Game maps are always external, but in the case of compression the map header file is stored internally in the executable. Executables are themselves compressed wither with LZEXE or PKLite. Once decompressed it is a trivial task to find the map header file as it will start with the word $ABCD For level editing purposes only the first 402 (or 502) bytes of the file needs to be extracted, though it is possible to read the maphead file to calculate its length.&lt;br /&gt;
&lt;br /&gt;
The following addresses are in the locations in the decompressed executables for the start of the Map header files. Values are different for different versions.&lt;br /&gt;
&lt;br /&gt;
TODO: Add all known versions of all games.&lt;br /&gt;
&lt;br /&gt;
External files&lt;br /&gt;
 Biomenace&lt;br /&gt;
 Blake Stone 2: Planet Strike&lt;br /&gt;
 Corridor 7 Demo&lt;br /&gt;
 Noahs Ark 3D&lt;br /&gt;
 Operation Body Count&lt;br /&gt;
 Spear of Destiny&lt;br /&gt;
 Wolfenstein 3D&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Internal files:&lt;br /&gt;
  Keen 4 (Special Demo): (file is PKLite compressed)&lt;br /&gt;
  Keen 4 (1.4): $24830&lt;br /&gt;
  Keen 5 (1.4): $25990&lt;br /&gt;
  Keen 6 (1.4): $25080&lt;br /&gt;
 (Keen D (1.13): $1FA50)&lt;br /&gt;
  Corridor 7 CD (): $30D50 from start of file CORR7CD.EXE (file is not compressed)&lt;br /&gt;
&lt;br /&gt;
== Utilities ==&lt;br /&gt;
&lt;br /&gt;
[[TED5]] This program can edit the &amp;lt;tt&amp;gt;GAMEMAPS&amp;lt;/tt&amp;gt; format of any games that use it. It is the original editor used to crate these files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
This format was reverse engineered by Andrew Durdin (adurdin).&lt;br /&gt;
&lt;br /&gt;
The format is used by other games as well, including [[Bio Menace]], [[Catacomb 3D]], [[Dangerous Dave 3]], [[Dave Goes Nutz]], and [[Wolfenstein 3D]]&lt;br /&gt;
&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Map Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=GameMaps_Format&amp;diff=3571</id>
		<title>GameMaps Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=GameMaps_Format&amp;diff=3571"/>
		<updated>2011-08-31T14:44:16Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: /* Location of internal files */ Corridor 7, Operation Body Count, Keen 4 Special Demo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The GameMaps format is how the levels in a number of [[Id Software]] games is stored. The filenames and compression varies somewhat across different games but all files stored in this format were produced by the program [[TED5]] or a close analogue.&lt;br /&gt;
&lt;br /&gt;
There are three main varieties of the GameMaps format, uncompressed, [[Carmack compression||carmackized]], and  [[Huffman Compression|huffman compressed]]. Each variation has its own file naming scheme  and pattern of external\internal files.&lt;br /&gt;
&lt;br /&gt;
There are two main components to the format, the game maps proper, which contain the game level data and the map headers, which contain both the locations of the start of level data in the game maps file and the tile info for the game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Structure of uncompressed data ==&lt;br /&gt;
&lt;br /&gt;
The uncompressed format is used by several games including [[Bio Menace]] and [[Wolfenstein 3D]]. In this format map data is stored in &amp;lt;tt&amp;gt;MAPTEMP.xxx&amp;lt;tt&amp;gt; and map headers in &amp;lt;tt&amp;gt;MAPTHEAD.xxx&amp;lt;/tt&amp;gt; this is the format saved by [[TED5]] when maps are being edited and can be directly accessed and edited by this utility, allowing changes to be made to the game.&lt;br /&gt;
&lt;br /&gt;
Note that filenames differ and that Wolfenstein 3D uses &amp;lt;tt&amp;gt;GAMEMAPS.WLx&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;MAPHEAD.xxx&amp;lt;/tt&amp;gt; files to store data. The main indicator of this format being used is that in the unaltered game the map header file is external.&lt;br /&gt;
&lt;br /&gt;
Only the latest Id Software games lacked compression, when file size was no longer an issue.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Map headers ===&lt;br /&gt;
&lt;br /&gt;
 0    2    Magic word       Magic word for [[RLEW compression]]&lt;br /&gt;
 2    400  Level ptr        100 4-byte pointers to start of level 0-99 data in game maps file&lt;br /&gt;
 402  ???  Tileinfo         Tileinfo data&lt;br /&gt;
&lt;br /&gt;
The map header file is of varying length and contains three main types of data. The first is the magic word or flag used for RLEW compression, it is always $ABCD. The second is 100 level pointers which give the location of the start of level data in the game maps file, relative to the start of that file. A value of 0 indicates no level. The third is the tileinfo data, tile properties for each tile used in level creation. (These are masked and unmasked and either 8x8, 16x16 or 32x32)&lt;br /&gt;
&lt;br /&gt;
Many programs treat the tileinfo as a separate file from the maphead and it is possible to modify a game in this manner. Indeed, some games, such as Wolfenstein 3D do not have any tileinfo data at all in the map header file (Giving a total file length of 402 bytes.) However TED5 works with any tileinfo data in the maphead.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Game maps ===&lt;br /&gt;
&lt;br /&gt;
The game maps file consists of the string &#039;TED5v1.0.&#039; and a number of RLEW compressed chunks of varying length. Each level in GameMaps will have from two to four chunks (usually four), depending on game, with all levels in a given game having the same number of chunks. These are the level header and 1-3 planes (Foreground, background and sprite or info.) The chunks are in no particular order and it is possible to read through the entire file decompressing chunks as they&#039;re found.&lt;br /&gt;
&lt;br /&gt;
Chunks are ordered by the map header file, which will point to the level header chunks which in turn contain pointers to the other chunks used by that level. It is possible the string at the start of the file is to avoid the possibility of a level header at the start of the file which would be read as not existing.&lt;br /&gt;
&lt;br /&gt;
All data in game maps file is in the form of words (Or in the case of pointers, dwords.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Level headers ===&lt;br /&gt;
&lt;br /&gt;
The header for each level that is pointed to by MAPHEAD is 42 bytes long and RLEW compressed, though this is difficult to see since the data is so short and nonrepetitive. For the offsets to level planes a value of 0 indicates the plane does not exist.&lt;br /&gt;
&lt;br /&gt;
Plane 1 is background using unmasked tiles, plane 2 is foreground and uses masked tiles. Plane 3 is sprite or info. Levels must contain c background plane and usually an infoplane.&lt;br /&gt;
&lt;br /&gt;
 0   4    Offset in GAMEMAPS to beginning of compressed plane 0 data&lt;br /&gt;
 4   4    Offset in GAMEMAPS to beginning of compressed plane 1 data&lt;br /&gt;
 8   4    Offset in GAMEMAPS to beginning of compressed plane 2 data&lt;br /&gt;
 12  2    Length of compressed plane 0 data (in bytes)&lt;br /&gt;
 14  2    Length of compressed plane 1 data (in bytes)&lt;br /&gt;
 16  2    Length of compressed plane 2 data (in bytes)&lt;br /&gt;
 18  2    Width of level (in tiles)&lt;br /&gt;
 20  2    Height of level (in tiles)&lt;br /&gt;
 22  16   Internal name for level (used only by editor, not displayed in-game. null-terminated)&lt;br /&gt;
&lt;br /&gt;
== Carmack compression ==&lt;br /&gt;
&lt;br /&gt;
[[Carmack compression]] is the method used to compress later Id Software games, when file size was an issue. It is the most efficient and complex compression method and was created specifically to work with the word structure of the game maps file. The compression is detailed on its [[Carmack compression|own page.]]&lt;br /&gt;
&lt;br /&gt;
Carmackized game maps files are external &amp;lt;tt&amp;gt;GAMEMAPS.xxx&amp;lt;/tt&amp;gt; files and the map header is stored internally in the executable. The map header must be extracted and the game maps decompressed before TED5 can access them. TED5 itself can produce carmackized files and external &amp;lt;tt&amp;gt;MAPHEAD.xxx&amp;lt;/tt&amp;gt; files. Carmackization does not replace the RLEW compression used in uncompressed data, but compresses this data, that is, the data is doubly compressed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Huffman compression ==&lt;br /&gt;
&lt;br /&gt;
Huffman compression was used by earlier versions of TED5 (possibly not TED5 at all.) before carmackization was created. It uses the same method to compress its data as is used by Id Software games to compress their graphics and sounds. Again this compression method works with RLEW compressed data and has its [[Huffman Compression|own page.]]&lt;br /&gt;
&lt;br /&gt;
Huffman compression is easily detected since it works on the bit level and thus disrupts the word structure of the game data. This is easily seen in a hex editor. Compressed data will not contain the string $00 $00 or indeed even $00 very often (In contrast even carmackized data contains both strings hundreds of times.)&lt;br /&gt;
&lt;br /&gt;
There will be two internal files for this format, the map header and the huffman dictionary (which is always the first dictionary in the executable.) The map header format is also slightly different, being 502 bytes long, the extra 100 bytes being the length of the compressed level headers in the game maps data (These can be ignored when decompressing since huffman data can be read until the decompressed level header&#039;s fixed size is reached.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Location of internal files ==&lt;br /&gt;
&lt;br /&gt;
Game maps are always external, but in the case of compression the map header file is stored internally in the executable. Executables are themselves compressed wither with LZEXE or PKLite. Once decompressed it is a trivial task to find the map header file as it will start with the word $ABCD For level editing purposes only the first 402 (or 502) bytes of the file needs to be extracted, though it is possible to read the maphead file to calculate its length.&lt;br /&gt;
&lt;br /&gt;
The following addresses are in the locations in the decompressed executables for the start of the Map header files. Values are different for different versions.&lt;br /&gt;
&lt;br /&gt;
TODO: Add all known versions of all games.&lt;br /&gt;
&lt;br /&gt;
External files&lt;br /&gt;
 Biomenace&lt;br /&gt;
 Corridor 7 Demo&lt;br /&gt;
 Noahs Ark 3D&lt;br /&gt;
 Operation Body Count&lt;br /&gt;
 Wolfenstein 3D&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Internal files:&lt;br /&gt;
  Keen 4 (Special Demo): (file is PKLite compressed)&lt;br /&gt;
  Keen 4 (1.4): $24830&lt;br /&gt;
  Keen 5 (1.4): $25990&lt;br /&gt;
  Keen 6 (1.4): $25080&lt;br /&gt;
 (Keen D (1.13): $1FA50)&lt;br /&gt;
  Corridor 7 CD (): $30D50 from start of file CORR7CD.EXE (file is not compressed)&lt;br /&gt;
&lt;br /&gt;
== Utilities ==&lt;br /&gt;
&lt;br /&gt;
[[TED5]] This program can edit the &amp;lt;tt&amp;gt;GAMEMAPS&amp;lt;/tt&amp;gt; format of any games that use it. It is the original editor used to crate these files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
This format was reverse engineered by Andrew Durdin (adurdin).&lt;br /&gt;
&lt;br /&gt;
The format is used by other games as well, including [[Bio Menace]], [[Catacomb 3D]], [[Dangerous Dave 3]], [[Dave Goes Nutz]], and [[Wolfenstein 3D]]&lt;br /&gt;
&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Map Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Hovertank_3-D&amp;diff=3563</id>
		<title>Hovertank 3-D</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Hovertank_3-D&amp;diff=3563"/>
		<updated>2011-08-26T14:45:55Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Hovertank 3D&#039;&#039;&#039; is one of the first FPS games and the direct ancestor of most FPS games.&lt;br /&gt;
&lt;br /&gt;
It has EGA graphics with no textures, but with scaled sprites. Like the later [[Wolfenstein 3D]], this game includes different brightnesses of the same tile when viewed from the N/S or E/W.&lt;br /&gt;
&lt;br /&gt;
It was followed by [[Catacomb 3D]], which added textures.&lt;br /&gt;
&lt;br /&gt;
==Level format==&lt;br /&gt;
&lt;br /&gt;
Levels are in LEVELxx.HOV files. They use [[RLEW compression]] with the tag $FEFE.&lt;br /&gt;
&lt;br /&gt;
{{stub}}&lt;br /&gt;
[[Category:Game Intro Page]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Hovertank_3-D&amp;diff=3562</id>
		<title>Hovertank 3-D</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Hovertank_3-D&amp;diff=3562"/>
		<updated>2011-08-26T14:44:05Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: Category&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Hovertank 3D&#039;&#039;&#039; is one of the first FPS games and the direct ancestor of most FPS games.&lt;br /&gt;
&lt;br /&gt;
It has EGA graphics with no textures, but with scaled sprites. Like the later [[Wolfenstein 3D]], this game includes &lt;br /&gt;
&lt;br /&gt;
It was followed by [[Catacomb 3D]], which added textures.&lt;br /&gt;
&lt;br /&gt;
==Level format==&lt;br /&gt;
&lt;br /&gt;
Levels are in LEVELxx.HOV files. They use [[RLEW compression]] with the tag $FEFE.&lt;br /&gt;
&lt;br /&gt;
{{stub}}&lt;br /&gt;
[[Category:Game Intro Page]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Hovertank_3-D&amp;diff=3561</id>
		<title>Hovertank 3-D</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Hovertank_3-D&amp;diff=3561"/>
		<updated>2011-08-26T14:42:29Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: Started stub&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Hovertank 3D&#039;&#039;&#039; is one of the first FPS games and the direct ancestor of most FPS games.&lt;br /&gt;
&lt;br /&gt;
It has EGA graphics with no textures, but with scaled sprites. Like the later [[Wolfenstein 3D]], this game includes &lt;br /&gt;
&lt;br /&gt;
It was followed by [[Catacomb 3D]], which added textures.&lt;br /&gt;
&lt;br /&gt;
==Level format==&lt;br /&gt;
&lt;br /&gt;
Levels are in LEVELxx.HOV files. They use [[RLEW compression]] with the tag $FEFE.&lt;br /&gt;
&lt;br /&gt;
{{stub}}&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=RLE_Compression&amp;diff=3560</id>
		<title>RLE Compression</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=RLE_Compression&amp;diff=3560"/>
		<updated>2011-08-26T14:29:45Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[RLE Compression]] is a form of lossless compression and one of the simplest ways of compressing and storing data. It is used, in various forms, by nearly every platform game. The essence of this compression method is to compress data by storing it as a collection of length/value pairs. To take a simple case, the string &#039;aaaaaaaabbb&#039; could be compressed to &#039;8a3b&#039; (8 bytes of a, 3 bytes of b).  The trick with RLE is to make sure the data does not end up becoming &#039;&#039;larger&#039;&#039; after processing (for example, &#039;abracadabra&#039; could become &#039;1a1b1r1a1c1a1d1a1b1r1a&#039;)&lt;br /&gt;
&lt;br /&gt;
Most systems also tell the program beforehand the size of the decompressed data, stored as a word or dword at the start of the data block.  This is usually done so that the correct amount of memory can be allocated before the data is processed.  In modern programs this is an obvious security risk (it is trivial to [[wp:Buffer overflow|write past the end of the allocated buffer]]) however this was not an issue at the time the games were written.&lt;br /&gt;
&lt;br /&gt;
== Length/value vs Flag Systems ==&lt;br /&gt;
&lt;br /&gt;
There are two main systems of RLE divided by how length is differentiated from value.&lt;br /&gt;
&lt;br /&gt;
In the first system, the first data is assumed to be a length, the next data(s) to be values. So using the simple system above the string &#039;3a3b2c&#039; would be read as &#039;Length 3 of a, length 3 of b...&#039; Any individual piece of data may be a length or a value and can only be told apart by what type came before it. This system is simplest, but has the disadvantage that the data must be read from the start and that any error will ruin all data that follows it.&lt;br /&gt;
&lt;br /&gt;
In the second system a &#039;flag&#039; is used. This is a special value that tells a program to do something whenever it is encountered. So the string &#039;*3abcd*3e&#039; could be decompressed to &#039;aaabcdeee&#039; where &#039;*&#039; is the flag value, indicating that a length/value pair is coming up next. Flags may indicate a number of things (Usually a value/length pair) and be words, bytes or bits (E.g all values over 128 are length bytes, all under value bytes.) This is more complex and is less efficient space-wise than the first system, but has the advantage that the data can usually be read from multiple points and an error may not corrupt all following data. (Since ever flag &#039;resets&#039; the decompression.)&lt;br /&gt;
&lt;br /&gt;
==== Literals ====&lt;br /&gt;
&lt;br /&gt;
A literal is a piece of data that is uncompressed and should be copied directly to output. If RLE is used to compress something like text for example, there will be a large amount of data (Words) with no pattern that cannot readily be compressed and so would appear &#039;as-is&#039; in the compressed data.&lt;br /&gt;
&lt;br /&gt;
While simpler systems must encode everything as length/value pairs, flag systems especially assume that all data is literal and just copy it to output until they come across a flag. This saves a lot of space since incompressible data won&#039;t increase in size. This is why flag systems are the more common way of compressing data (Especially graphics.) and are more common in older games.&lt;br /&gt;
&lt;br /&gt;
== Compression units ==&lt;br /&gt;
&lt;br /&gt;
RLE compression can occur at several levels, bits, bytes or words (RLEB, RLE, [[RLEW compression |RLEW]]) Most common is at the byte level. The type used often depends on what data is being compressed. For example, most tilesets work on the byte level (1 pixel = 1 byte) and so will be compressed at the byte level, while most levels are made of two byte values for tiles and will be compressed at the word level.&lt;br /&gt;
&lt;br /&gt;
[[RLEW compression]] has its own page which describes how it it commonly implemented.&lt;br /&gt;
&lt;br /&gt;
== Types of RLE ==&lt;br /&gt;
&lt;br /&gt;
* Supplemental data in [[Duke Nukem II Map Format#Supplemental foreground data|Duke Nukem II map files]]&lt;br /&gt;
* [[Keen 1-3 RLE compression]] also used by [[Dangerous Dave]] and [[Catacomb]]&lt;br /&gt;
* [[Jazz Jackrabbit RLE compression]]&lt;br /&gt;
* [[DAT Format (Monster Bash)#RLE|Monster Bash RLE]] used in .DAT file&lt;br /&gt;
* [[RLEW compression]]&lt;br /&gt;
&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Compressed Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Keen_1-3_RLE_compression&amp;diff=3559</id>
		<title>Keen 1-3 RLE compression</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Keen_1-3_RLE_compression&amp;diff=3559"/>
		<updated>2011-08-26T14:27:16Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: Catacomb usage&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Commander Keen 1-3]] uses [[RLE compression]] to compress its 320x200 &amp;lt;tt&amp;gt;FINALE.CKx&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;PREVIEWx.CK1&amp;lt;/tt&amp;gt; screens.  [[Dangerous Dave]] also uses this format to compress its graphics. It was previously used in [[Catacomb|Catacomb I and II]] for the level data (not the graphics). This is one of many possible ways to create a functional RLE system.&lt;br /&gt;
&lt;br /&gt;
The compressed file consists of a UINT32LE giving the decompressed size, followed by the compressed data.&lt;br /&gt;
&lt;br /&gt;
The compressed data is processed in a loop.  After each byte is read, its value is used to select an action.  If the high bit is set (val &amp;amp; 0x80) then one more than the lower seven bits ((val &amp;amp; 0x7F) + 1) is the number of following bytes passed through unchanged.  If the high bit was not set, then that value plus three is the number of times the following byte is repeated.&lt;br /&gt;
&lt;br /&gt;
The next byte is then read and the same procedure followed until there is no more data or the decompressed size in the header has been reached.&lt;br /&gt;
&lt;br /&gt;
An illustration:&lt;br /&gt;
&lt;br /&gt;
 80 aa 00 00 81 bb cc 05 dd&lt;br /&gt;
&lt;br /&gt;
This data is interpreted as follows:&lt;br /&gt;
&lt;br /&gt;
 80 aa     # Copy AA through unchanged&lt;br /&gt;
 00 00     # Repeat 00 three times&lt;br /&gt;
 81 bb cc  # Copy BB and CC through unchanged&lt;br /&gt;
 05 dd     # Repeat DD eight times&lt;br /&gt;
&lt;br /&gt;
Or as pseudocode:&lt;br /&gt;
&lt;br /&gt;
* Get the initial dword [Final length]&lt;br /&gt;
* If [Decompressed data length] &amp;lt; [Final length] then:&lt;br /&gt;
*# Read a byte [Value]&lt;br /&gt;
*# If the byte value &amp;gt;= 128, then:&lt;br /&gt;
*#* Read and output the next [value - 127] bytes&lt;br /&gt;
*#* Move forward [Value - 126] bytes and return to step 1.&lt;br /&gt;
*# If the byte value &amp;lt; 128, then:&lt;br /&gt;
*#* Read the next byte and output it (value + 3) times.&lt;br /&gt;
*#* Move forward 2 bytes and return to step 1.&lt;br /&gt;
&lt;br /&gt;
It can be seen that this system is not optimal since two repeating bytes must be treated as non-repeating.&lt;br /&gt;
&lt;br /&gt;
[[Category:Catacomb]]&lt;br /&gt;
[[Category:Commander Keen 1-3]]&lt;br /&gt;
[[Category:Dangerous Dave]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Compressed Files]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Catacomb&amp;diff=3558</id>
		<title>Catacomb</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Catacomb&amp;diff=3558"/>
		<updated>2011-08-26T14:20:11Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: Formatting&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
{{GamePage}}&lt;br /&gt;
&lt;br /&gt;
[[Catacomb]] was distributed on the same Gamer&#039;s Edge disk as [[Dangerous Dave]].&lt;br /&gt;
&lt;br /&gt;
Catacomb and Catacomb II are top-down Gauntlet-style shooters. They are two of ID software&#039;s earliest games.&lt;br /&gt;
They are the direct ancestors of most First Person Shooters. They introduced strafing. &lt;br /&gt;
&lt;br /&gt;
They are part of series of 6 games, in two trilogies:&lt;br /&gt;
* Catacomb I&lt;br /&gt;
* Catacomb II&lt;br /&gt;
* [[Catacomb 3-D]]&lt;br /&gt;
* [[Catacomb Abyss]]&lt;br /&gt;
* [[Catacomb Armageddon]]&lt;br /&gt;
* [[Catacomb Apocalypse]]&lt;br /&gt;
&lt;br /&gt;
It evolved like this: [[Catacomb]] + [[Hovertank]] -&amp;gt; [[Catacomb 3-D]] -&amp;gt; [[Catacomb Abyss]] -&amp;gt; [[Wolfenstein 3D]] -&amp;gt; [[Doom]] -&amp;gt; [[Quake]]&lt;br /&gt;
&lt;br /&gt;
== File formats ==&lt;br /&gt;
&lt;br /&gt;
===Game levels===&lt;br /&gt;
Game levels are stored in LEVEL1.CAT to LEVEL10.CAT for Catacomb I, and LEVEL1.CA2 to LEVEL30.CA2 for Catacomb II. Note that the number in the level name is not padded, unlike in later games.&lt;br /&gt;
&lt;br /&gt;
Every level is the fixed size 64x64, like the later [[Wolfenstein 3D]]. But there is only one plane of data, and each tile is only one byte. &lt;br /&gt;
&lt;br /&gt;
The first 4 bytes of the level file is the size of the uncompressed data in little-endian format. It is always 4096 (64x64). Following that is the compressed level data, compressed with [[Keen 1-3 RLE compression]]. There is nothing else in the level file. &lt;br /&gt;
&lt;br /&gt;
Here are some possible tile values:&lt;br /&gt;
 61..7A (lowercase ASCII &#039;a&#039;..&#039;z&#039;) = block with letter A..Z&lt;br /&gt;
 80 = green floor (purple in CGA)&lt;br /&gt;
 81 = pink block (white and cyan in CGA)&lt;br /&gt;
 82 = grey left wall of room (black in CGA)&lt;br /&gt;
 83 = top wall of room (purple and grey wall in EGA, white bricks in CGA)&lt;br /&gt;
 84 = bottom right corner of block &lt;br /&gt;
 85 = top left corner of room&lt;br /&gt;
 86 = bottom left corner of block&lt;br /&gt;
 87 = top right corner of block&lt;br /&gt;
 88 = secret passage&lt;br /&gt;
 89 = secret passage in left wall&lt;br /&gt;
 8A = secret passage in top wall&lt;br /&gt;
&lt;br /&gt;
 8F = bag pickup (secret)&lt;br /&gt;
 91 = key pickup (secret)&lt;br /&gt;
 A2 = bag (not secret)&lt;br /&gt;
 A3 = scroll&lt;br /&gt;
 A4 = key pickup&lt;br /&gt;
 A6 = door&lt;br /&gt;
 A7 = chest&lt;br /&gt;
&lt;br /&gt;
 E7 = portal&lt;br /&gt;
 E8 = teddy bear&lt;br /&gt;
 E9 = skeleton&lt;br /&gt;
 EA = big red/purple monster&#039;s top left corner&lt;br /&gt;
&lt;br /&gt;
Levels are in [[Catacomb Map Format]]&lt;br /&gt;
&lt;br /&gt;
===Other===&lt;br /&gt;
* Savegames are in [[Catacomb Savegame Format]] (&#039;&#039;&#039;Catacomb 2&#039;&#039;&#039; only)&lt;br /&gt;
* Sounds are in [[Inverse Frequency Sound format]]&lt;br /&gt;
* Tile graphics are in [[xGAChars Format]]&lt;br /&gt;
* Other graphics are in &lt;br /&gt;
** [[xGAPics Format]] for &#039;&#039;&#039;Catacomb 2&#039;&#039;&#039;&lt;br /&gt;
** [[PIC Format]] for &#039;&#039;&#039;Catacomb 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;&#039;Catacomb 1&#039;&#039;&#039;, all graphics files are stored in the EXE. Their location in the &#039;&#039;uncompressed&#039;&#039; executable is as follows:&lt;br /&gt;
&lt;br /&gt;
 Location   | Size   | Description&lt;br /&gt;
 -----------+--------+-------------&lt;br /&gt;
 0x00006100 | 0xB6C0 | EGACHARS.CAT&lt;br /&gt;
 0x000117D0 | 0x5B60 | CGACHARS.CAT&lt;br /&gt;
 0x00017997 | 0x4000 | TITLE.PIC&lt;br /&gt;
 0x0001B997 | 0x4000 | END.PIC&lt;br /&gt;
&lt;br /&gt;
[[Category:Catacomb]]&lt;br /&gt;
[[Category:Softdisk]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Catacomb&amp;diff=3557</id>
		<title>Catacomb</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Catacomb&amp;diff=3557"/>
		<updated>2011-08-26T14:18:46Z</updated>

		<summary type="html">&lt;p&gt;CarlKenner: More information&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
{{GamePage}}&lt;br /&gt;
&lt;br /&gt;
[[Catacomb]] was distributed on the same Gamer&#039;s Edge disk as [[Dangerous Dave]].&lt;br /&gt;
&lt;br /&gt;
Catacomb and Catacomb II are top-down Gauntlet-style shooters. They are two of ID software&#039;s earliest games.&lt;br /&gt;
They are the direct ancestors of most First Person Shooters. They introduced strafing. &lt;br /&gt;
&lt;br /&gt;
They are part of series of 6 games, in two trilogies:&lt;br /&gt;
* Catacomb I&lt;br /&gt;
* Catacomb II&lt;br /&gt;
* [[Catacomb 3-D]]&lt;br /&gt;
* [[Catacomb Abyss]]&lt;br /&gt;
* [[Catacomb Armageddon]]&lt;br /&gt;
* [[Catacomb Apocalypse]]&lt;br /&gt;
&lt;br /&gt;
It evolved like this: [[Catacomb]] + [[Hovertank]] -&amp;gt; [[Catacomb 3-D]] -&amp;gt; [[Catacomb Abyss]] -&amp;gt; [[Wolfenstein 3D]] -&amp;gt; [[Doom]] -&amp;gt; [[Quake]]&lt;br /&gt;
&lt;br /&gt;
== File formats ==&lt;br /&gt;
&lt;br /&gt;
===Game levels===&lt;br /&gt;
Game levels are stored in LEVEL1.CAT to LEVEL10.CAT for Catacomb I, and LEVEL1.CA2 to LEVEL30.CA2 for Catacomb II. Note that the number in the level name is not padded, unlike in later games.&lt;br /&gt;
&lt;br /&gt;
Every level is the fixed size 64x64, like the later [[Wolfenstein 3D]]. But there is only one plane of data, and each tile is only one byte. &lt;br /&gt;
&lt;br /&gt;
The first 4 bytes of the level file is the size of the uncompressed data in little-endian format. It is always 4096 (64x64). Following that is the compressed level data, compressed with [[Keen 1-3 RLE compression]]. There is nothing else in the level file. &lt;br /&gt;
&lt;br /&gt;
Here are some possible tile values:&lt;br /&gt;
61..7A (lowercase ASCII &#039;a&#039;..&#039;z&#039;) = block with letter A..Z&lt;br /&gt;
80 = green floor (purple in CGA)&lt;br /&gt;
81 = pink block (white and cyan in CGA)&lt;br /&gt;
82 = grey left wall of room (black in CGA)&lt;br /&gt;
83 = top wall of room (purple and grey wall in EGA, white bricks in CGA)&lt;br /&gt;
84 = bottom right corner of block &lt;br /&gt;
85 = top left corner of room&lt;br /&gt;
86 = bottom left corner of block&lt;br /&gt;
87 = top right corner of block&lt;br /&gt;
88 = secret passage&lt;br /&gt;
89 = secret passage in left wall&lt;br /&gt;
8A = secret passage in top wall&lt;br /&gt;
&lt;br /&gt;
8F = bag pickup (secret)&lt;br /&gt;
91 = key pickup (secret)&lt;br /&gt;
A2 = bag (not secret)&lt;br /&gt;
A3 = scroll&lt;br /&gt;
A4 = key pickup&lt;br /&gt;
A6 = door&lt;br /&gt;
A7 = chest&lt;br /&gt;
&lt;br /&gt;
E7 = portal&lt;br /&gt;
E8 = teddy bear&lt;br /&gt;
E9 = skeleton&lt;br /&gt;
EA = big red/purple monster&#039;s top left corner&lt;br /&gt;
&lt;br /&gt;
Levels are in [[Catacomb Map Format]]&lt;br /&gt;
&lt;br /&gt;
===Other===&lt;br /&gt;
* Savegames are in [[Catacomb Savegame Format]] (&#039;&#039;&#039;Catacomb 2&#039;&#039;&#039; only)&lt;br /&gt;
* Sounds are in [[Inverse Frequency Sound format]]&lt;br /&gt;
* Tile graphics are in [[xGAChars Format]]&lt;br /&gt;
* Other graphics are in &lt;br /&gt;
** [[xGAPics Format]] for &#039;&#039;&#039;Catacomb 2&#039;&#039;&#039;&lt;br /&gt;
** [[PIC Format]] for &#039;&#039;&#039;Catacomb 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In &#039;&#039;&#039;Catacomb 1&#039;&#039;&#039;, all graphics files are stored in the EXE. Their location in the &#039;&#039;uncompressed&#039;&#039; executable is as follows:&lt;br /&gt;
&lt;br /&gt;
 Location   | Size   | Description&lt;br /&gt;
 -----------+--------+-------------&lt;br /&gt;
 0x00006100 | 0xB6C0 | EGACHARS.CAT&lt;br /&gt;
 0x000117D0 | 0x5B60 | CGACHARS.CAT&lt;br /&gt;
 0x00017997 | 0x4000 | TITLE.PIC&lt;br /&gt;
 0x0001B997 | 0x4000 | END.PIC&lt;br /&gt;
&lt;br /&gt;
[[Category:Catacomb]]&lt;br /&gt;
[[Category:Softdisk]]&lt;/div&gt;</summary>
		<author><name>CarlKenner</name></author>
	</entry>
</feed>