How MS-DOS 6.22 Displays ANSI Color Graphics
MS-DOS 6.22 displays ANSI color graphics in the console through a
dedicated device driver called ANSI.SYS. By default, the
standard MS-DOS console driver (CON) treats all characters
as plain text and lacks the native ability to parse formatting commands.
When loaded, ANSI.SYS intercepts standard console output,
interprets standardized escape sequences, and translates them into video
hardware calls to change text colors, alter background attributes, and
reposition the screen cursor.
The Role of ANSI.SYS
The primary mechanism for enabling ANSI support is loading the
ANSI.SYS driver into memory at boot time. Because MS-DOS
does not include ANSI processing directly inside
COMMAND.COM or the core operating system kernel
(MSDOS.SYS), the driver must be explicitly declared in the
system's CONFIG.SYS file using the following directive:
DEVICE=C:\DOS\ANSI.SYS
Alternatively, users running memory managers such as
HIMEM.SYS and EMM386.EXE can load it into
upper memory to conserve conventional memory:
DEVICEHIGH=C:\DOS\ANSI.SYS
Interception and Escape Sequences
Once loaded, ANSI.SYS replaces the default console
output handler by hooking into the internal DOS character output
routines (principally Interrupt 29h, the fast console output
interrupt).
As programs write text to the console, the driver continuously scans
the data stream for the ASCII Escape character (ASCII 27 or
hex 1B), followed by the left bracket character
[ (ASCII 91). This combination represents the
Control Sequence Introducer (CSI).
When ANSI.SYS detects a CSI, it temporarily stops
printing characters directly to the display buffer and instead buffers
the incoming characters to parse them as a command.
Attribute Mapping via Select Graphic Rendition (SGR)
To render colors and text formatting, ANSI.SYS uses the
Select Graphic Rendition (SGR) subset of the ANSI standard. An SGR
sequence typically ends with the letter m, preceded by one
or more numerical codes separated by semicolons (for example,
ESC[1;31;40m).
The driver parses these numbers and maps them directly to IBM PC video text attributes:
- Foreground Colors (30–37): Maps standard ANSI colors (black, red, green, yellow, blue, magenta, cyan, white) to the lower four bits of the PC video attribute byte.
- Background Colors (40–47): Maps standard background colors to the higher bits of the attribute byte.
- Text Attributes: Codes such as
0(reset),1(bold/high intensity foreground),5(blink), and7(reverse video) modify specific bits within the attribute byte.
Direct Hardware and BIOS Output
After interpreting the escape codes, ANSI.SYS applies
the visual changes by making calls to BIOS video services (Interrupt
10h). For color and formatting changes, it sets the active text
attribute for subsequent output characters. For cursor manipulation
commands (such as moving the cursor up, down, or to absolute row/column
coordinates), it calls BIOS INT 10h, Function 02h (Set Cursor
Position).
This combination of interrupt interception, stream parsing, and BIOS attribute manipulation allows MS-DOS 6.22 to produce colorful text-based user interfaces and ANSI art in a standard command-line environment.