PC Fonts
The PC draws text through a character generator: a table of glyph bitmaps in the adapter, one per character code. In the standard 80×25 text mode each cell shows one glyph, coloured by an attribute. The built-in set is IBM code page 437, and on VGA the whole font can be swapped for one of your own.
Overview
In text mode the screen is not a bitmap of pixels but a grid of character cells. Each cell stores a character code and a colour attribute, and the adapter's character generator turns the code into pixels on the fly by looking up its glyph in a font table. This is why text-mode screens are tiny in memory and why changing the font instantly re-styles every character already on screen.
Text mode
The default text mode is 80 columns by 25 rows, 2000 cells. Each cell is two bytes in video memory at B800:0000: a character byte, the code 0 to 255, and an attribute byte holding the foreground and background colours. The character generator draws each cell in a fixed pixel box, the character cell. On CGA and EGA this is 8×8; VGA uses a taller 8×16 box, which is why VGA text looks crisper.
| Property | Value |
|---|---|
| Text grid | 80 × 25 cells |
| Bytes per cell | 2 (character + attribute) |
| Glyphs in set | 256 |
| Cell size (CGA/EGA) | 8 × 8 pixels |
| Cell size (VGA) | 8 × 16 pixels |
| Video memory | B800:0000 |
Glyph format
A glyph is a bitmap stored one byte per pixel row. The cell is eight pixels wide, so each row fits in one byte, the most significant bit on the left; a set bit draws the foreground colour, a clear bit the background. An 8×8 glyph is 8 bytes, an 8×16 glyph is 16 bytes, and the whole font is those glyph tables laid end to end, 256 of them, indexed by character code.
| Row | Byte (bits 7…0) | Pixels |
|---|---|---|
| 0 | 00011000 | ██ |
| 1 | 00111100 | ████ |
| 2 | 01100110 | ██ ██ |
| 3 | 01100110 | ██ ██ |
| 4 | 01111110 | ██████ |
| 5 | 01100110 | ██ ██ |
| 6 | 01100110 | ██ ██ |
| 7 | 00000000 |
The example is an 8×8 letter A: each row's byte, read as bits from left to right, gives the on and off pixels of that scanline. To find the byte for row r of character code c in an 8-high font, read offset c * 8 + r in the font table; for an 8×16 font it is c * 16 + r.
Code page 437
The character codes are mapped to glyphs by IBM code page 437, the original PC character set. Codes 32 to 126 are the standard printable ASCII letters, digits and punctuation. The rest are put to use rather than left blank: codes 0 to 31 and 127, normally control characters, carry symbols such as faces, arrows and card suits, and codes 128 to 255 hold accented letters, Greek letters, maths symbols and, most usefully for programs, a set of box-drawing and block-shading characters.
Those box and block glyphs let text-mode programs draw framed windows, bars and simple pictures out of characters alone, which is why so much DOS software has a boxed, panelled look.
Loading a custom font
On EGA and VGA the font is not fixed in ROM but held in a plane of video memory, and a program can replace it. The glyph bitmaps live in bit-plane 2 of the adapter's memory. A program maps that plane in, writes its own 256 glyph tables over the standard ones, then unmaps it, and every character drawn afterward uses the new shapes.
This is done either through the BIOS character-generator call, which takes a pointer to a font table and its cell height, or by programming the sequencer and graphics-controller registers directly to expose plane 2. Loading a custom font lets a program restyle all its text, add game-specific tiles into unused codes, or switch to a different code page, without any change to the text already on screen.
| Item | Value |
|---|---|
| Font storage | Bit-plane 2 of video memory |
| Glyph size | 8 × height bytes, 1 byte per row |
| Table length | 256 glyphs |
| BIOS access | Character-generator call, INT 10h |