B800 Text

From ModdingWiki
Jump to: navigation, search
B800 Text
B800 Text.png
Format typeImage
HardwareCGA, EGA, VGA
Colour depth4-bit
Minimum size (pixels)80×25 cells
Maximum size (pixels)80×25 cells
PaletteUnknown
Plane count2
Transparent pixels?No
Hitmap pixels?No
GamesUnknown


B800 Text is a text-mode screen dump, and under x86 real mode (such as used by DOS) can be copied byte for byte into video memory starting at B800:0000, causing the data to appear on the screen when the video card is in text mode. It is most often used to display the final text screen after quitting a game, with the DOS prompt appearing on the last line once the game has terminated.

File format

Full CGA 16-color palette
0 — black
#000000
8 — (dark) gray
#555555
1 — blue
#0000AA
9 — bright blue
#5555FF
2 — green
#00AA00
10 — bright green
#55FF55
3 — cyan
#00AAAA
11 — bright cyan
#55FFFF
4 — red
#AA0000
12 — bright red
#FF5555
5 — magenta
#AA00AA
13 — bright magenta
#FF55FF
6 — brown
#AA5500
14 — yellow
#FFFF55
7 — white (light gray)
#AAAAAA
15 — bright white
#FFFFFF

Since the file format is just a direct dump of video memory, this would more accurately be termed the "CGA text mode format." The file is almost always 4000 bytes long, as this is the exact amount of space required to store a standard 80x25 text screen (80 columns * 25 rows * two bytes per cell == 4000 bytes.)

The data is arranged in cells, with each cell being two bytes long (one byte for the ASCII character to display, followed by an attribute byte indicating the colour of the character.) The data appears starting at the top-left of the screen (1,1) and works its way across to the right (80,1) and then wraps down to the next line (1,2).

The attribute byte contains two nybbles of data. The most significant four bits are the background colour, and the least significant bits are the foreground colour. This means the background and foreground colours can each be assigned a colour value between zero (black) and 15 (white) - see the table on the right for the full list of colours.

The background colour is slightly different however. By default, the intensity bit is used to cause the text to flash instead. This means setting the background colour to 14 won't produce a bright-yellow background, but instead will produce a normal yellow background (colour #6) with blinking text. The CGA standard includes a toggle bit that allows this flashing to be switched off, thus allowing the full 16 background colours to be used (without any flashing of course.)

Example

As a demonstration, these bytes:

48 1E  65 2E  6C 3E  6C 4E  6F 5E        H.e.l.l.o.

Would appear like this:

 Hello

Rendering behavior for VGA mode compared to CGA/EGA/MCGA modes

CGA/EGA/MCGA text modes have an horizontal resolution of 640 pixels, but VGA instead has an horizontal resolution of 720 pixels. In the case of VGA, the rendering process is a bit different to compensate for the horizontal resolution differences between these modes. In text mode, the usual width of a character is 8 pixels and in the case of CGA/EGA/MCGA that value is a perfect fit (80 columns × 8 pixels = 640 pixels). But for VGA, a character width is extended to 9 pixels which in turn makes it a perfect fit since 80 columns × 9 pixels = 720 pixels.[1]

As a byte is eight bits wide, a font only needs one byte per row to store character data (a "glyph"). So an 8x8 CGA character requires 8 bytes per glyph, and EGA 8x14 requires 14 bytes per glyph. But VGA's glyph width of 9 means either complex bit manipulation is needed to store nine bits/pixels per row, or a whole extra byte is needed which is quite wasteful. So instead, a trick is used.

Based on the character code, the right-most pixels (the last/ninth column) are either blank, or are a duplicate of the eighth column. Characters 192 to 223 have their eighth column duplicated, while all the others do not.[2] This allows all the box and line drawing characters to connect without any gaps, while normal text has a minimum of one pixel gap between each glyph. This mode is on by default in all 9×16 text modes, however it can be switched off by changing the value of a VGA register.

The following screenshots show the differences between the glyph sizes. Differences are particularly visible in the lowercase letters m and w, as well as the distance between each quote in the double-quote (") symbol. ! These aren't traditional fonts, the VGA one is just the EGA font with more space
CGA/EGA/MCGA (640×400 pixels)
VGA (720×400 pixels)


Back in the CRT era, and unless technically versed in the subject, one would hardly notice such subtleties as a CRT screen would fit the content it is being fed. Today however, this behaviour is more obvious since the world has switched to LCD screens with fixed-size square pixels.

But while increasing the glyph width to nine pixels increases the text clarity, the aspect ratio becomes incorrect, or not, depending one's opinion. This question is hard to answer in the case of text modes since this is a weird case as in the absolute, the characters are of equal widths in both resolutions using this technology; it is only the spacing that differs. CRT technology in comparison would (normally) produce an incorrect aspect ratio in the case of VGA text mode.

Detecting B800 text

B800 text is usually 80×25, with two bytes per cell, so any file that is exactly 4000 bytes long (80 × 25 × 2) has a good chance of being B800 text.

The following C# snippet will detect whether an array of bytes contains B800 related characters.

/// <summary>
///     Gets if the specified array of bytes contains B800 byte characters (ranging from 0 to 31 and from 128 to 255).
/// </summary>
/// <param name="bytes"></param>
/// <returns></returns>
public static bool ContainsB800(byte[] bytes)
{
    if (bytes == null) throw new ArgumentNullException("bytes");
    var b800 =
        Enumerable.Concat(Enumerable.Range(0, 32), Enumerable.Range(128, 128)).Select(s => (byte)s);
    return bytes.Any(s => b800.Any(t => t == s));
}

Notice for B800-related coding in modern development environments:

Modern development frameworks generally use the Unicode norm for representing strings. Unfortunately, Extended ASCII codes used in B800 text files will be converted to "?" (question marks) since they are not part of that norm. A foolproof approach to address this issue is to always read your B800 text file as binary, e.g. in the case of .NET you will want to call File.ReadAllBytes instead of File.ReadAllText.

Tools

The following tools are known to work with this format:

  • TheDraw - DOS-based text animation/screen editor, which does support B800 text and many other DOS formats. TheDraw also runs under DOSBox.
  • TextPaint - DOS-based text screen editor, which unfortunately doesn't support B800 text but is still very powerful, and useful enough to warrant a mention.
  • Shmansi - Another DOS-based text screen editor, which can import and export B800 text.
  • ENDOOMER- Yet another DOS-based text screen editor, which can import and export B800 text, and can be used with the mouse as well.
  • B800- a .NET library that renders B800 text supporting arbitrary fonts and column widths as well as character expansion like in VGA text mode.

See also

References

  1. http://en.wikipedia.org/wiki/VGA-compatible_text_mode VGA-compatible text mode
  2. http://support.microsoft.com/kb/59953/en-us 9th Pixel of 9x16 VGA Fonts Mimics 8th Pixel for ASCII 192-223