+==========================================================================================+ |Keen 1-3 type level format: | +==========================================================================================+ This is the level format for Keen 1-3, actually used by many ID Software games before the group GAMEMAPS format was invented in 1992. The original, 'Dangerous Dave in Copyright Infringement' format. is identical to Keen's, but it is totally uncompressed +------------------------------------------------------------------------------------------+ |LEVELXX: | +------------------------------------------------------------------------------------------+ Level format is basically three sections; the header, which is a fixed size, followed by the tile and sprite planes, which are of equal size. The level is word-based, meaning that each 'tile' in a level is represented by two bytes. The level is compressed using RLE-W, word based RLE compression, described below. When decompressed fully the level size is 4(h * w) + 36 though usually 'minimal' compression is used. (See below.) Most of the header is (Or was.) used by TED v1.5 to load the level and its associated graphics and is not used by Keen per se. These can be left blank and nobody will care, since the original TED is long gone. ------------------------------------------------------------------------------- FILE STRUCUTURE: HEADER TILE PLANE SPRITE PLANE ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- COMPRESSED: ------------------------------------------------ HEADER: 0 4 Data size Size of the DECOMPRESSED level in bytes 4 x RLE-W Data RLE-W compressed level data ------------------------------------------------ ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- UNCOMPRESSED: [But including data size variable] ------------------------------------------------ 0 4 Data size Size of the DECOMPRESSED level in bytes 4 2 Lev width Width of the level in tiles 6 2 Lev height Height of level in tiles 8 2 Numplanes Number of planes in level (2) 10 4 Blank Blank 14 4 Ted var 2 TED 1.5 varaibles (Ignored by Keen) 18 2 Planesize Level planesize; = 2(h * w) rounded to the next highest multiple of 16 bytes (So a level of 10x10 = 100 has a PS of 112) 20 16 Ted var 6 TED 1.5 variables, the first 1 byte long the rest 3 bytes. Notice that the first byte of each of the last 5 variables is the same. (For Keen 1 for example it is $FF) 36 2P Tile plane The tiles in the level, [Planesize] entries of two-byte words, with the 'padding' words being set at $00 $00 Thus the size of this block is 2 * [Planesize] The level is filled in from top-left to bottom- right, moving right across a row and down a row after reaching a row's end. ~2P 2P Sprite data Same as the tile data, but for sprites ------------------------------------------------ ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- COMPRESSION: The compression is RLE-W; flag $FEFE. What this means is that it is a form of RLE compression at the word (Two byte) level instead of the byte level. The file is read in words, each word being copied directly to output UNLESS that word is $FEFE. If $FEFE is encountered, the next word is the count and the next next word is the repeated word. This is incredibly efficient. This also means that there is no real 'uncompressed' level; a level lacking all flags can still be read using the same algorithm. -------------------------------------------------------------------------------