An Allegro datafile is a bit like a zip file in that it consists of lots of different pieces of data stuck together one after another, and optionally compressed. This means that your game doesn't have to clutter up the disk with hundreds of tiny files, and it makes programming easier because you can load everything with a single function call at program startup. Another benefit is that the LZSS file compression algorithm works much better with one large file than with many small ones.
Datafiles have the extension .dat, and can be created and edited with the graphical grabber program or the command line dat utility. They can be stored as separate files and loaded into memory by the load_datafile() function, or you can use dat2s to convert them into asm code which can then be linked directly into your executable.
Each datafile contains a number of objects, of varying types. Object types are represented by 32 bit integer ID's, which are interpreted as four character ASCII strings. These ID's can be constructed with the DAT_ID() macro, for example a DATA object is represented by DAT_ID('D','A','T','A'), or you can use the predefined DAT_* constants for the standard data types:
DAT_FILE - "FILE" A datafile, which contains a list of other objects. Datafile objects can be nested inside other datafiles, allowing you to create hierarchical structures of any depth.
DAT_DATA - "DATA" A block of binary data. Allegro treats all unknown types as binary data objects, so you don't need to use this ID: you can create custom object formats using whatever ID's you like.
DAT_FONT - "FONT" A font.
DAT_SAMPLE - "SAMP" A digital sound sample.
DAT_MIDI - "MIDI" A MIDI file.
DAT_PATCH - "PAT " A Gravis patch (MIDI instrument).
DAT_FLI - "FLIC" An FLI or FLC animation.
DAT_BITMAP - "BMP " A bitmap.
DAT_RLE_SPRITE - "RLE " A run length encoded sprite.
DAT_C_SPRITE - "CMP " A compiled sprite.
DAT_XC_SPRITE - "XCMP" A mode-X compiled sprite.
DAT_PALETTE - "PAL " A 256 color palette.
DAT_PROPERTY - "prop" An object property (see below). You will never directly encounter this object type, but you should be aware that it is treated specially by the datafile code.
DAT_INFO - "info" The grabber utility uses this object to store information about the datafile. Like property objects, you ought never to encounter it, but you should avoid using the ID for any custom object formats you create.
DAT_END - -1 Special marker used to indicate the end of a datafile.
Each object can have any number of properties attached to it. These are ASCII strings describing attributes of the object, such as its name and where it came from. Like the objects themselves, properties are identified by 32 bit integer ID's which are constructed from four character strings by the DAT_ID() macro. Allegro defines the standard properties:
"NAME" The name of the object.
"ORIG" The object's origin, ie. the name of the file from which it was grabbed.
"DATE" A timestamp, used by the update command in the grabber and dat utilities. This is the modification time of the file from which the object was grabbed, in "m-dd-yyyy, hh:mm" format.
"XPOS" For bitmap objects which were grabbed from part of a larger image, the x position of the origin within the parent bitmap.
"YPOS" For bitmap objects which were grabbed from part of a larger image, the y position of the origin within the parent bitmap.
"XSIZ" For bitmap objects which were grabbed from part of a larger image, the width of the selected region.
"YSIZ" For bitmap objects which were grabbed from part of a larger image, the height of the selected region.
"XCRP" For autocropped bitmap objects, the amount of cropping on the left of the image.
"YCRP" For autocropped bitmap objects, the amount of cropping at the top of the image.
You can use whatever other ID's you like to store custom information about your objects (the grabber internally use some other properties stored in a hidden DAT_INFO object, so they won't conflict with yours).
In case anyone wants to do some serious hackery, and for my own future reference, here are some details of the innards of the datafile format.
Note that this is different to the datafile format used by Allegro versions 2.1 and earlier. Allegro can still load files from the old format, but it was much less flexible and didn't support nice things like object properties, so you should load any old files into the grabber and save them out again to convert to the new format.
Nb. if all you want to do is write a utility that manipulates datafiles in some way, the easiest approach is probably to use the helper functions in datedit.c, which are currently shared by the dat, dat2s, and grabber programs. These functions handle loading, saving, inserting and deleting objects, and modifying the contents of datafiles in various ways, but life is too short for me to bother documenting them all here. Look at the source...
Anyway. All numbers are stored in big-endian (Motorola) format. All text is stored in UTF-8 encoding. A datafile begins with one of the 32 bit values F_PACK_MAGIC or F_NOPACK_MAGIC, which are defined in allegro.h. If it starts with F_PACK_MAGIC the rest of the file is compressed with the LZSS algorithm, otherwise it is uncompressed. This magic number and optional decompression can be handled automatically by using the packfile functions and opening the file in F_READ_PACKED mode. After this comes the 32 bit value DAT_MAGIC, followed by the number of objects in the root datafile (not including objects nested inside child datafiles), followed by each of those objects in turn.
Each object is in the format:
OBJECT =
var -
The property list can contain zero or more object properties, in the form:
PROPERTY =
32 bit -
If the uncompressed size field in an object is positive, the contents of the
object are not compressed (ie. the raw and compressed sizes should be the
same). If the uncompressed size is negative, the object is LZSS compressed,
and will expand into -
The contents of an object vary depending on the type. Allegro defines the
standard types:
DAT_FILE =
32 bit -