VGA text mode


VGA text mode was introduced in 1987 by IBM as part of the VGA standard for its IBM PS/2 computers. Its use on IBM PC compatibles was widespread through the 1990s and persists today for some applications on modern computers. The main features of VGA text mode are colored characters and their background, blinking, various shapes of the cursor, and loadable fonts. The Linux console traditionally uses hardware VGA text modes, and the Win32 console environment has an ability to switch the screen to text mode for some text window sizes.

Data arrangement

Text buffer

Each screen character is represented by two bytes aligned as a 16-bit word accessible by the CPU in a single operation. The lower, or character, byte is the actual code point for the current character set, and the higher, or attribute, byte is a bit field used to select various video attributes such as color, blinking, character set, and so forth. This byte-pair scheme is among the features that the VGA inherited from the EGA, CGA, and ultimately from the MDA.
  1. Depending on the mode setup, attribute bit 7 may be either the blink bit or the fourth background color bit.
  2. Attribute bit 3 also selects between fonts A and B. Therefore, if these fonts are not the same, this bit is simultaneously an additional code point bit.
  3. Attribute bit 0 also enables underline, if certain other attribute bits are set to zero.
Colors are assigned in the same way as in 4-bit indexed color graphic modes.
VGA modes have no need for the MDA's reverse and bright attributes because foreground and background colors can be set explicitly.

Underline

The VGA hardware has the ability to enable an underline on any character that has attribute bit 0 set. However, since this is an MDA-compatible feature, the attribute bits not used by the MDA must be set to zero or the underline will not be shown. This means that only bits 3 and 7 can be set concurrently with bit 0. With the default VGA palette, setting bit 0 to enable underline will also change the text colour to blue. This means text in only two colors can be underlined.
Despite all this, the underline is not normally visible in color modes, as the location of the underline defaults to a scanline [|below] the character glyph, rendering it invisible. If the underline location is set to a visible scanline, then the underline will appear.

Fonts

Screen fonts used in EGA and VGA are monospace raster fonts containing 256 glyphs. All glyphs in a font are the same size, but this size can be changed. Typically, glyphs are 8 dots wide and 8–16 dots high, however the height can be any value up to a maximum of 32. Each row of a glyph is coded in an 8 bit byte, with high bits to the left of the glyph and low bits to the right. Along with several hardware-dependent fonts stored in the adapter's ROM, the text mode offers 8 loadable fonts. Two active font pointers select two of the available fonts, although they usually point to the same font. When they each point to different fonts, attribute bit 3 acts as a font selection bit instead of as a foreground color bit. On real VGA hardware, this overrides the bit's use for color selection, but on many clones and emulators, the color selection remains — meaning one font is displayed as normal intensity, and the other as high-intensity. This error can be overcome by changing the palette registers to contain two copies of an 8-color palette.
There are modes with a character box width of 9 dots, however the 9th column is used for spacing between characters, so the content cannot be changed. It is always blank, and drawn with the current background colour. An exception to this is in Line Graphics Enable mode, which causes code points 0xC0 to 0xDF inclusive to have the 8th column repeated as the 9th. These code points cover those box drawing characters which must extend all the way to the right side of the glyph box. For this reason, placing letter-like characters in code points 0xC0–0xDF should be avoided. The box drawing characters from 0xB0 to 0xBF are not extended, as they do not point to the right and so do not require extending.

Cursor

The shape of the cursor is restricted to a rectangle the full width of the character box, and filled with the foreground color of the character at the cursor's current location. Its height and position may be set to anywhere within a character box;. The EGA and many VGA clones allowed a split-box cursor, by setting the end of the cursor before the start, however if this is done on the original VGA, the cursor is completely hidden instead. The VGA standard does not provide a way to alter the blink rate, although common workarounds involve hiding the cursor and using a normal character glyph to provide a so-called software cursor.
A mouse cursor in TUI is not usually the same thing as a hardware cursor, but a moving rectangle with altered background or a special glyph.
Some text-based interfaces, such as that of Impulse Tracker, went to even greater lengths to provide a smoother and more graphic-looking mouse cursor. This was done by constantly re-generating character glyphs in real-time according to the cursor's on-screen position and the underlying characters.

Access methods

There are generally two ways to access VGA text-mode for an application: through the Video BIOS interface or by directly accessing video RAM and I/O ports. The latter method is considerably faster, and allows quick reading of the text buffer, for which reason it is preferred for advanced TUI programs.
The VGA text buffer is located at physical memory address 0xB8000. Since this is usually used by 16-bit x86 processes operating in real-mode, it is the first half of memory segment 0xB800. The text buffer data can be read and written, and bitwise operations can be applied. A part of text buffer memory [|above] the scope of the current mode is accessible, but is not shown.
The same physical addresses are used in protected mode. Applications may either have this part of memory mapped to their address space or access it via the operating system. When an application does not have control over the console, it accesses a part of system RAM instead of the actual text buffer.
For computers in the 1980s, very fast manipulation of the text buffer, with the hardware generating the individual pixels as fast as they could be displayed, was extremely useful for a fast UI. Even on relatively modern hardware, the overhead of text mode emulation via hardware APA modes may be noticeable.

Modes and timings

Video signal

From the monitor's side, there is no difference in input signal in a text mode and an APA mode of the same size. A text mode signal may have the same timings as VESA standard modes. The same registers are used on adapter's side to set up these parameters in a text mode as in APA modes. The text mode output signal is essentially the same as in graphic modes, but its source is a text buffer and character generator, not a framebuffer as in APA.

PC common text modes

Depending on the graphics adapter used, a variety of text modes are available on IBM PC compatible computers. They are listed on the table below:
Text res.Char. sizeGraphics res.ColorsAdapters
80×259×14720×350B&W TextMDA, Hercules
40×258×8320×20016 colorsCGA, EGA
80×258×8640×20016 colorsCGA, EGA
80×258×14640×35016 colorsEGA
80×438×8640×35016 colorsEGA
80×259×16720×40016 colorsVGA
80×509×8720×40016 colorsVGA
80×6016 colorsVESA-compatible Super VGA
132×2516 colorsVESA-compatible Super VGA
132×4316 colorsVESA-compatible Super VGA
132×5016 colorsVESA-compatible Super VGA
132×6016 colorsVESA-compatible Super VGA

VGA and compatible cards support MDA, CGA and EGA modes. All colored modes have the same design of text attributes. MDA modes have some specific features — a text could be emphasized with bright, underline, reverse and blinking attributes.
The most common text mode used in DOS environments and initial Windows consoles is the default 80 columns by 25 rows, or 80×25, with 16 colors and 8×16 pixels large characters. VGA cards always have a built-in font of this size whereas other sizes may require downloading a differently sized font. This mode was available on practically all IBM and compatible personal computers.
Two other VGA text modes, 80×40 and 80×50, exist but are less common. Windows NT 4.0 displayed its system messages during the boot process in 80×50 text mode.
Character sizes and graphical resolutions for the extended VESA-compatible Super VGA text modes are manufacturer's dependent. Some cards supported custom very large text modes, like 132×43 and 132×25. Like as in graphic modes, graphic adapters of 2000s commonly are capable to set up an arbitrarily-sized text mode instead of choosing its parameters from some list.

SVGATextMode

On Linux and DOS systems with so named SVGA cards, a program called SVGATextMode can be used to set up better looking text modes than EGA and VGA standard ones. This is particularly useful for large monitors, where the normal 80×25 VGA text mode's 720×400 pixel resolution is far lower than a typical graphics mode would be. SVGATextMode allows setting of the pixel clock and higher refresh rate, larger font size, cursor size, etc., and allows a better use of the potential of a video card and monitor. In non-Windows systems, the use of SVGATextMode to obtain a sharp text is critical for LCD monitors of 1280×1024 because none of so named standard text modes fits to this matrix size. SVGATextMode also allows a fine tuning of video signal timings.
Despite the name of this program, only a few of its supported modes conform to SVGA standards.

General restrictions

VGA text mode has some hardware-imposed limitations. Because these are too restrictive for modern applications, the hardware text mode on VGA compatible video adapters only has a limited use.
* 8 colors may be used by font A and other 8 colors by font B; so, if font A ≠ font B, then the palette should be halved and a text may effectively use only 8 colors.
** Normally, first 8 colors of the same palette. If blink is disabled, then all 16 colors are available for background.