VGA Fonts
Alongside its graphics modes VGA has a text mode built around a character generator. The screen is a grid of cells, each holding a character code and a colour, and the shapes of the characters live in font memory as small bitmaps. The font is not fixed in silicon: a program can load its own glyphs and redraw the text screen in any typeface it likes.
Overview
In text mode the display is not a bitmap the program paints. It is a grid of character cells, and the hardware draws each cell by looking up its character code in the font and painting that glyph in the cell's colours. The program only writes character codes and colours; the character generator turns them into pixels every frame. This is fast, compact, and the reason the DOS console runs so lightly.
Text mode
The default VGA text mode is 80 columns by 25 rows, a grid of 2000 cells. Each cell is an 8×16 pixel character box, giving a 720×400 pixel display. VGA can also switch the cell to 8×8, doubling the rows to 80×50, or widen it to 9×16 for the crisper look used by the built-in fonts, where the ninth column is drawn from the eighth for line-drawing glyphs.
The text screen lives at segment B800:0000. Each cell takes two bytes: the character code then the attribute byte. The cell at column cx, row cy is at offset (cy * 80 + cx) * 2, with the character code at that offset and the attribute in the next byte.
| Property | Value |
|---|---|
| Text grid | 80 × 25 (or 80 × 50) |
| Character cell | 8 × 16 (also 8 × 8, 9 × 16) |
| Glyphs | 256, code page 437 |
| Bytes per cell | 2 (character code + attribute) |
| Screen segment | B800:0000 |
Glyph byte format
The font is a table of 256 glyphs held in font memory, which lives in plane 2 of video memory. Each glyph is a stack of rows, one byte per row, and the cell height sets how many rows: an 8×16 font stores 16 bytes per glyph, an 8×8 font stores 8. Within a row byte the eight bits are the eight pixels of that scanline, the most significant bit on the left. A one bit draws the foreground colour, a zero the background.
So the glyph for character code c in an 8×16 font starts at c * 16 in the font table, and its n-th row is the byte at c * 16 + n, painted top bit first. The character codes follow code page 437, the original IBM PC set, which places the ASCII letters and digits in their usual positions and fills the rest with accented letters, box-drawing lines, and block shapes.
| Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Pixel | leftmost | · | · | · | · | · | · | rightmost |
The attribute byte
Each cell's second byte is its attribute, packing the foreground and background colours and two flags. The low nibble is the foreground colour (0 to 15), the colour of the glyph's set pixels. The next three bits are the background colour (0 to 7), the colour of the clear pixels. The top bit is blink or, when blink is turned off, the fourth background bit, letting the background use all 16 colours instead of 8.
| Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Meaning | Blink / bg bit 3 | Background (0–7) | Foreground (0–15) | |||||
The 16 foreground colours are the 8 base colours plus an intensity bit, so bit 3 of the foreground nibble is the bright flag that lifts a colour to its light shade. The background is limited to the 8 base colours unless blink is disabled. When blink is on, a set top bit makes the whole cell flash on and off.
Custom fonts
The character generator reads its glyphs from font memory in plane 2, and a program can overwrite that memory to install its own typeface. It switches the Sequencer to expose plane 2, writes new glyph bytes in the same row-per-byte format, then switches back to normal text access. From then on the hardware draws the new shapes for the same character codes, so redefining a font recolours nothing but changes every letter on screen at once.
VGA can hold several font tables at once and pick between them per cell through an attribute bit, which is how some setups show two 256-glyph fonts for a 512-glyph screen. Loading a full replacement font is a common trick: games and demos swap in their own glyphs to draw stylised text, and utilities load 8×8 fonts to switch the screen into 80×50 mode.