EGA Font format

From ModdingWiki
Jump to navigation Jump to search

The 'EGA Font format' is used to store a monochrome font used in many Softdisk and ID Software games. While the font is functionally monochrome is is related to EGA and used solely by EGA games. There are two versions of the font, differing slightly in format. This is because the first format was dropped due to limitations in what it could display (256 characters of one color) however after some experimentation using 8x8 unmasked tiles for font (Notable in Commander Keen 1-3.), a new way to use the font for more varied purposes was discovered.


0	UINT16LE	Line height	Height of lines (And thus all characters)	
2	256*UINT16LE	Char offset	Array of 16-bit offsets to characters from the start of the data chunk
514	256*UINT8	Char width	Width of the character on-screen (but see below)
770	bytes to the end of the chunk	Character image data (see below)

Each file starts with a 770 byte header. This can be used to search for the font if it is stored internally. This is because characters 0-31 are used by the game to write 8x8 window tiles inside which text is written. Therefore a font file will start with a word of varying value followed by 64 nulls and the word $302, pointing to the end of the header.

The offsets in the header refer to 1-plane (one bit per pixel, monochrome) image data. The size of the stored image is line height*rounded with, where rounded width is "char width," but rounded up to the next multiple of 8.

For example, in a font with height 10, a character where "width" == 7 is stored in a 10x8 monochrome image. A character where "width" == 11 is stored in a 10x16 monochrome image.

The additional pixels to the right of the width line are not meant to be rendered and are consequently always set to 0 in the mask; the rounding is simply to prevent the rows of the planar image from having an odd (non-byte-aligned) number of bits.

Version 1 and Version 2

There is one difference between the two versions of fonts; version 1 has twice as much character data, as each character's data is preceded by a mask. It is not known if or how the game uses this, but it may have something to do with character overlap mentioned above. The difference between versions can be detected by comparing the size of a character's data with its height\width. The 4x10 character above would have 20 bytes of data in version 1.

Version 1 is found either internally in executables or externally as a single file in earlier Softdisk\ID Software games such as Shadow Knights or Rescue Rover. Version 2 is found inside EGAGraph files as a font chunk.


In its earliest implementation characters are treated as another plane of EGA data overlaid on the screen. The game performs a NOT check meaning in essence that the nonzero part of the character inverts the color it is displayed on. In a text window this turns the white background black, but characters can be displayed over images outside of text windows, where this effect can be seen more clearly.

Later games allow the font to be warped in various ways, as well as having custom colors instead of simple inversion. This can be seen in the Commander Keen 4-6 help screens for example.