Please create an account or Login! Have fun!

DAT: Difference between revisions

Jump to navigation Jump to search
15,834 bytes added ,  1 May 2021
port in the file format description
m (Tylersontag moved page dAT to DAT over redirect: revert)
(port in the file format description)
Line 1: Line 1:
A '''DAT''' file (having the extension .dat) is the file format which Chip's Challenge [[level set]]s are commonly stored in.
In the context of [[Chip's Challenge]], '''DAT''' or <code>.dat</code> is the file format which Chip's Challenge 1 [[level set]]s are commonly stored in, named for the <code>CHIPS.DAT</code> file containing the levels for [[MSCC]].  The <code>.dat</code> extension is short for "data" and commonly used on data files with ad-hoc formats; it is not specific to Chip's Challenge.


Since the release of [[CCTools]], level sets are sometimes stored in '''CCL''' files (having the extension .ccl, which stands for [[Chip's Challenge]] level set). For people who have [[ChipEdit]], which does not provide a way to open CCL files "normally", simply change the extension back to .dat, or type the file name manually when in the Open dialog.
Since the release of [[CCTools]], the format is sometimes referred to as '''CCL''' or <code>.ccl</code>, short for "[[Chip's Challenge]] levels". For people who have [[ChipEdit]], which does not provide a way to open CCL files "normally", simply change the extension back to .dat, or type the file name manually when in the Open dialog.


==External Links==
== Structure ==
 
The format is a relatively simple binary structure.  All fields are little-endian.
 
=== File header ====
 
{| class="wikitable" border="1"
!Offset
!Bytes
!Content
|-
|$00
|4
|Magic number, identifying the file format.  MSCC will reject the file if this is not <code>$0002AAAC</code>.  Tile World will also accept <code>$0102AAAC</code> as meaning a level set using [[Ruleset#Lynx|Lynx rules]].  The [[pgchip]] modification expects <code>$0003aaac</code>.
|-
|$04
|2
|Number of levels in the file.
|}
 
Levels begin at offset $06, immediately following the header.
 
=== Level structure ===
 
{| class="wikitable" border="1"
!Offset
!Bytes
!Content
|-
|$00
|2
|Length of this level in bytes, '''not''' including this field.
|-
|$02
|2
|Level number.  <!-- XXX what if this doesn't match the level order?  is this only used in the UI? -->
|-
|$04
|2
|Time limit, in seconds.  Zero indicates the level is untimed.  Every official version of the game has a three-digit timer, so values over 999 are uncommon.
|-
|$06
|2
|Required number of [[chip]]s.  This may be less than the number of chips in the level, in which case the extras will be optional, or it may be more, in which case the [[chip socket]] will be impossible to open.
|-
|$08
|2
|Unclear.  Must always be 0 or 1.  The original levels all have this set to 1.  Possibly once indicated whether the level data was compressed or not.
|-
|$0a
|2
|Length of top layer, in bytes.
|-
|$0c
|varies
|Contents of top layer; see [[#Level contents|below]].
|-
|varies
|2
|Length of bottom layer, in bytes.
|-
|varies
|varies
|Contents of bottom layer; see [[#Level contents|below]].
|-
|varies
|2
|Total length of all metadata chunks, in bytes; see [[#Level metadata chunks|below]].  MSCC crashes if there are more than 1152 bytes of metadata.
|-
|varies
|varies
|Zero or more metadata chunks; see [[#Level metadata chunks|below]].
|}
 
=== Level contents ===
 
The level is encoded as two layers, top and bottom.  Every CC1 level is 32×32, so each layer contains exactly 1024 tiles.  If a cell only contains one tile, it should be placed on the ''top'' layer, and the corresponding tile in the ''bottom'' layer should simply be floor.  (Another way to think of this is that the floor byte, <code>$00</code>, represents ''nothing'', but that every cell implicitly has floor underneath.)
 
''Any'' tile may appear on either layer, which allows for a vast number of strange combinations.  However, within the original rules of the game, the only valid combinations are a lone static tile, or a static tile with a movable object on top.  Anything else (including some otherwise intuitive possibilities that would work in [[Chip's Challenge 2]], like a key on gravel) is an [[invalid tile]], will be rejected by Tile World's Lynx mode, and may behave unexpectedly.
 
A layer is a simple stream of bytes representing the tiles in [[reading order]].  A lone byte indicates a particular tile according to the encoding below.  A <code>$FF</code> byte indicates simple run-length encoding, where the next two bytes are the number of copies and the byte to repeat.  The sequence `00 FF 0A 01 00` thus describes twelve tiles: a floor tile, a span of ten walls, and another floor tile.
 
==== Tile encoding ====
 
The tile encoding exactly matches the arrangement of sprites in the [[:File:Color_Tileset.gif|MSCC tileset]].
 
Values of <code>$70</code> and above are used internally for graphical transparency.  <!-- XXX what happens if you use them? -->
 
{| class="wikitable" border="1"
!Byte
!Tile
!Byte
!Tile
!Byte
!Tile
!Byte
!Tile
!Byte
!Tile
!Byte
!Tile
!Byte
!Tile
|-
|<code>$00</code>
|[[Image:Floor.png]] [[Floor]]
|<code>$10</code>
|[[Image:Clone block S.png]] [[Clone block]] (S)
|<code>$20</code>
|''unused''<br><small>(used internally as [[overlay buffer|Combination]])</small>
|<code>$30</code>
|[[Image:Thin wall SE.png]] [[Thin wall]] (SE)
|<code>$40</code>
|[[Image:Bug N.png]] [[Bug]] (N)
|<code>$50</code>
|[[Image:Glider N.png]] [[Glider]] (N)
|<code>$60</code>
|[[Image:Paramecium NS.png]] [[Paramecium]] (N)
|-
|<code>$01</code>
|[[Image:Wall.png]] [[Wall]]
|<code>$11</code>
|[[Image:Clone block E.png]] [[Clone block]] (E)
|<code>$21</code>
|[[Image:Thief.png]] [[Key thief]]
|<code>$31</code>
|[[Image:Clone machine.png]] [[Cloner]]
|<code>$41</code>
|[[Image:Bug W.png]] [[Bug]] (W)
|<code>$51</code>
|[[Image:Glider W.png]] [[Glider]] (W)
|<code>$61</code>
|[[Image:Paramecium WE.png]] [[Paramecium]] (W)
|-
|<code>$02</code>
|[[Image:Computer chip.png]] [[Computer chip]]
|<code>$12</code>
|[[Image:Force floor N.png]] [[Force floor]] (N)
|<code>$22</code>
|[[Image:Socket.png]] [[Chip socket]]
|<code>$32</code>
|[[Image:Force floor Random.png]] [[Random force floor]]
|<code>$42</code>
|[[Image:Bug S.png]] [[Bug]] (S)
|<code>$52</code>
|[[Image:Glider S.png]] [[Glider]] (S)
|<code>$62</code>
|[[Image:Paramecium NS.png]] [[Paramecium]] (S)
|-
|<code>$03</code>
|[[Image:Water.png]] [[Water]]
|<code>$13</code>
|[[Image:Force floor E.png]] [[Force floor]] (E)
|<code>$23</code>
|[[Image:Green button.png]] [[Green button]]
|<code>$33</code>
|[[Image:Drowned Chip.png]] <s>[[Drowned Chip]]</s>
|<code>$43</code>
|[[Image:Bug E.png]] [[Bug]] (E)
|<code>$53</code>
|[[Image:Glider E.png]] [[Glider]] (E)
|<code>$63</code>
|[[Image:Paramecium WE.png]] [[Paramecium]] (E)
|-
|<code>$04</code>
|[[Image:Fire.png]] [[Fire]]
|<code>$14</code>
|[[Image:Force floor W.png]] [[Force floor]] (W)
|<code>$24</code>
|[[Image:Red button.png]] [[Red button]]
|<code>$34</code>
|[[Image:Chip in Fire.png]] <s>[[Burned Chip]]</s>
|<code>$44</code>
|[[Image:Fireball.png]] [[Fireball]] (N)
|<code>$54</code>
|[[Image:Teeth N.png]] [[Teeth]] (N)
|<code>$64</code>
|[[Image:Blue key.png]] [[Blue key]]
|-
|<code>$05</code>
|[[Image:Invisible wall.png]] [[Invisible wall]]
|<code>$15</code>
|[[Image:Exit.png]] [[Exit]]
|<code>$25</code>
|[[Image:Toggle wall Closed.png]] [[Toggle wall]]
|<code>$35</code>
|[[Image:Burned Chip.png]] <s>[[Burned Chip]]</s>
|<code>$45</code>
|[[Image:Fireball.png]] [[Fireball]] (W)
|<code>$55</code>
|[[Image:Teeth W.png]] [[Teeth]] (W)
|<code>$65</code>
|[[Image:Red key.png]] [[Red key]]
|-
|<code>$06</code>
|[[Image:Thin wall N.png]] [[Thin wall]] (N)
|<code>$16</code>
|[[Image:Blue lock.png]] [[Blue lock]]
|<code>$26</code>
|[[Image:Toggle wall Open.png]] [[Toggle wall|Toggle floor]]
|<code>$36</code>
|''unused''<br><small>(acts as invisible wall)</small>
|<code>$46</code>
|[[Image:Fireball.png]] [[Fireball]] (S)
|<code>$56</code>
|[[Image:Teeth S.png]] [[Teeth]] (S)
|<code>$66</code>
|[[Image:Green key.png]] [[Green key]]
|-
|<code>$07</code>
|[[Image:Thin wall W.png]] [[Thin wall]] (W)
|<code>$17</code>
|[[Image:Red lock.png]] [[Red lock]]
|<code>$27</code>
|[[Image:Brown button.png]] [[Brown button]]
|<code>$37</code>
|''unused''<br><small>(acts as invisible wall)</small>
|<code>$47</code>
|[[Image:Fireball.png]] [[Fireball]] (E)
|<code>$57</code>
|[[Image:Teeth E.png]] [[Teeth]] (E)
|<code>$67</code>
|[[Image:Yellow key.png]] [[Yellow key]]
|-
|<code>$08</code>
|[[Image:Thin wall S.png]] [[Thin wall]] (S)
|<code>$18</code>
|[[Image:Green lock.png]] [[Green lock]]
|<code>$28</code>
|[[Image:Blue button.png]] [[Blue button]]
|<code>$38</code>
|''unused''<br><small>(acts as invisible wall)</small><br><small>([[Ice block]] in [[pgchip]])</small>
|<code>$48</code>
|[[Image:Pink ball.png]] [[Ball]] (N)
|<code>$58</code>
|[[Image:Walker NS.png]] [[Walker]] (N)
|<code>$68</code>
|[[Image:Flippers.png]] [[Flippers]]
|-
|<code>$09</code>
|[[Image:Thin wall E.png]] [[Thin wall]] (E)
|<code>$19</code>
|[[Image:Yellow lock.png]] [[Yellow lock]]
|<code>$29</code>
|[[Image:Teleport.png]] [[Teleporter]]
|<code>$39</code>
|[[Image:Chip in Exit.png]] <s>[[Fake exit]]</s>
|<code>$49</code>
|[[Image:Pink ball.png]] [[Ball]] (W)
|<code>$59</code>
|[[Image:Walker WE.png]] [[Walker]] (W)
|<code>$69</code>
|[[Image:Fire boots.png]] [[Fire boots]]
|-
|<code>$0a</code>
|[[Image:Block.png]] [[Dirt block]]
|<code>$1a</code>
|[[Image:Ice NW.png]] [[Ice corner]] (NW)
|<code>$2a</code>
|[[Image:Bomb.png]] [[Bomb]]
|<code>$3a</code>
|[[Image:Exit2.png]] <s>[[Fake exit]]</s>
|<code>$4a</code>
|[[Image:Pink ball.png]] [[Ball]] (S)
|<code>$5a</code>
|[[Image:Walker NS.png]] [[Walker]] (S)
|<code>$6a</code>
|[[Image:Ice skates.png]] [[Ice skates]]
|-
|<code>$0b</code>
|[[Image:Dirt.png]] [[Dirt]]
|<code>$1b</code>
|[[Image:Ice NE.png]] [[Ice corner]] (NE)
|<code>$2b</code>
|[[Image:Trap.png]] [[Trap]]
|<code>$3b</code>
|[[Image:Exit3.png]] <s>[[Fake exit]]</s>
|<code>$4b</code>
|[[Image:Pink ball.png]] [[Ball]] (E)
|<code>$5b</code>
|[[Image:Walker WE.png]] [[Walker]] (E)
|<code>$6b</code>
|[[Image:Suction boots.png]] [[Suction boots]]
|-
|<code>$0c</code>
|[[Image:Ice.png]] [[Ice]]
|<code>$1c</code>
|[[Image:Ice SE.png]] [[Ice corner]] (SE)
|<code>$2c</code>
|[[Image:Hidden wall.png]] [[Hidden wall]]
|<code>$3c</code>
|[[Image:Swimming Chip N.png]] <s>[[Swimming Chip]] (N)</s>
|<code>$4c</code>
|[[Image:Tank N.png]] [[Tank]] (N)
|<code>$5c</code>
|[[Image:Blob.png]] [[Blob]] (N)
|<code>$6c</code>
|[[Image:Chip N.png]] [[Chip]] (N)
|-
|<code>$0d</code>
|[[Image:Force floor S.png]] [[Force floor]] (S)
|<code>$1d</code>
|[[Image:Ice SW.png]] [[Ice corner]] (SW)
|<code>$2d</code>
|[[Image:Gravel.png]] [[Gravel]]
|<code>$3d</code>
|[[Image:Swimming Chip W.png]] <s>[[Swimming Chip]] (W)</s>
|<code>$4d</code>
|[[Image:Tank W.png]] [[Tank]] (W)
|<code>$5d</code>
|[[Image:Blob.png]] [[Blob]] (W)
|<code>$6d</code>
|[[Image:Chip W.png]] [[Chip]] (W)
|-
|<code>$0e</code>
|[[Image:Clone block N.png]] [[Clone block]] (N)
|<code>$1e</code>
|[[Image:Blue wall.png]] Fake [[blue wall]]
|<code>$2e</code>
|[[Image:Recessed wall.png]] [[Recessed wall]]
|<code>$3e</code>
|[[Image:Swimming Chip S.png]] <s>[[Swimming Chip]] (S)</s>
|<code>$4e</code>
|[[Image:Tank S.png]] [[Tank]] (S)
|<code>$5e</code>
|[[Image:Blob.png]] [[Blob]] (S)
|<code>$6e</code>
|[[Image:Chip S.png]] [[Chip]] (S)
|-
|<code>$0f</code>
|[[Image:Clone block W.png]] [[Clone block]] (W)
|<code>$1f</code>
|[[Image:Blue wall.png]] Real [[blue wall]]
|<code>$2f</code>
|[[Image:Hint.png]] [[Hint]]
|<code>$3f</code>
|[[Image:Swimming Chip E.png]] <s>[[Swimming Chip]] (E)</s>
|<code>$4f</code>
|[[Image:Tank E.png]] [[Tank]] (E)
|<code>$5f</code>
|[[Image:Blob.png]] [[Blob]] (E)
|<code>$6f</code>
|[[Image:Chip E.png]] [[Chip]] (E)
|}
 
=== Level metadata chunks ===
 
Each chunk begins with a small header.
 
Because the length of a chunk is stored in a single byte, no chunk may be longer than 255 bytes.
 
{| class="wikitable" border="1"
!Offset
!Bytes
!Content
|-
|$00
|1
|Chunk type
|-
|$01
|1
|Chunk length in bytes, '''not''' including this two-byte header
|}
 
A level '''must''' have a title (3) and password (6).  A level intended to work under MS rules should also have [[trap]] linkage (4), [[cloner]] linkage (5), and a [[monster]] list (10), or those elements will not work.
 
Unrecognized chunk types are ignored.
 
==== 1: Time limit ====
 
{| class="wikitable" border="1"
!Offset
!Bytes
!Content
|-
|$02
|2
|Time limit in seconds
|}
 
This chunk is never used in the original game, since it's redundant with the time limit field in the level header.
 
==== 2: Required chips ====
 
{| class="wikitable" border="1"
!Offset
!Bytes
!Content
|-
|$02
|2
|Required number of chips
|}
 
This chunk is never used in the original game, since it's redundant with the required chips field in the level header.
 
==== 3: Title ====
 
{| class="wikitable" border="1"
!Offset
!Bytes
!Content
|-
|$02
|?
|Map title.  Must include a trailing NUL byte, and must not exceed 64 characters (including the NUL).  Should generally be ASCII, though Tile World appears to interpret this as Latin-1.  <!-- XXX what does MSCC do with a long title or byte over 128? -->
|}
 
==== 4: Trap linkage ====
 
Contains zero or more of the following structure.  As this structure is 10 bytes in size, the chunk size should be a multiple of 10, and there cannot be more than 25 trap linkages in a level.  Any given brown button may only be linked to a single trap.
 
{| class="wikitable" border="1"
!Offset
!Bytes
!Content
|-
|$00
|2
|x-coordinate of brown button
|-
|$02
|2
|y-coordinate of brown button
|-
|$04
|2
|x-coordinate of trap
|-
|$06
|2
|y-coordinate of trap
|-
|$08
|2
|Always zero.  Presumably a placeholder for runtime state regarding whether the trap is open or closed.
|}
 
This structure links brown buttons to traps in MSCC, where such linkage must be explicit.  If a brown button is not listed in this chunk, it will not function in MSCC.
 
Tile World in Lynx mode will ignore this structure and always connect brown buttons in [[reading order]].
 
If this chunk appears more than once, MSCC will only read the first, but Tile World will merge them all.
 
==== 5: Cloner linkage ====
 
Contains zero or more of the following structure.  As this structure is 8 bytes in size, the chunk size should be a multiple of 8, and there cannot be more than 31 cloner linkages in a level.
 
{| class="wikitable" border="1"
!Offset
!Bytes
!Content
|-
|$00
|2
|x-coordinate of red button
|-
|$02
|2
|y-coordinate of red button
|-
|$04
|2
|x-coordinate of cloner
|-
|$06
|2
|y-coordinate of cloner
|}
 
This structure links red buttons to cloners in MSCC, where such linkage must be explicit.  If a red button is not listed in this chunk, it will not function in MSCC.  Any given red button may only be linked to a single cloner.
 
Tile World in Lynx mode will ignore this structure and always connect red buttons in [[reading order]].
 
If this chunk appears more than once, MSCC will only read the first, but Tile World will merge them all.
 
==== 6: Password ====
 
{| class="wikitable" border="1"
!Offset
!Bytes
!Content
|-
|$02
|?
|Encrypted password.  Must include a trailing NUL.  Should be ASCII.  May be up to 10 characters, but generally should be 5 (4 + NUL).
|}
 
The password is encrypted trivially, by XORing every character ('''not''' including the trailing NUL) with <code>0x99</code>.
 
==== 7: Hint ====
 
{| class="wikitable" border="1"
!Offset
!Bytes
!Content
|-
|$02
|?
|[[Hint]] text.  Must include a trailing NUL byte, and must not exceed 128 characters (including the NUL).  Should generally be ASCII, though Tile World appears to interpret this as Latin-1.  <!-- XXX what does MSCC do with a long title or byte over 128? -->
|}
 
==== 8: Unencrypted password ====
 
This chunk is identical to chunk 6, but without the encryption.  It is never used in the original <code>CHIPS.DAT</code>, and Tile World ignores it.
 
==== 10: Monster list ====
 
Contains zero or more of the following structure.  As this structure is 2 bytes in size, the chunk size should be a multiple of 2, and there cannot be more than 128 moving monsters in a level.
 
{| class="wikitable" border="1"
!Offset
!Bytes
!Content
|-
|$00
|2
|x-coordinate of monster
|-
|$02
|2
|y-coordinate of monster
|}
 
This structure allows monsters to move in MSCC; if a monster is not listed in this chunk, it will not move.
 
Tile World in Lynx mode will ignore this structure and always allow any number of monsters to move as normal.
 
== See also ==
 
* [[C2M]], the more flexible format used in [[Chip's Challenge 2]]
* Implementation in [[Tile World]]: [[https://github.com/zrax/tworld/blob/master/series.c|<code>series.c</code>]] (whole file) and [[https://github.com/zrax/tworld/blob/master/encoding.c|<code>encoding.c</code>]] (individual level)
* Implementation in [[Lexy's Labyrinth]]: [[https://github.com/eevee/lexys-labyrinth/blob/master/js/format-dat.js|<code>js/format-dat.js</code>]]
 
== External Links ==


[http://www.seasip.info/ccfile.html Explanation of the CHIPS.DAT format]
[http://www.seasip.info/ccfile.html Explanation of the CHIPS.DAT format]
{{stub}}


[[Category:Terminology]]
[[Category:Terminology]]
[[Category:File formats]]
[[Category:File formats]]
trusted-editors
68

edits

Navigation menu