||This article includes a list of references, related reading or external links, but its sources remain unclear because it lacks inline citations. (March 2012)|
ANSI.SYS is a device driver in the DOS operating system that provides extra console functions through ANSI escape sequences. It is partially based upon a subset of the text terminal control standard proposed by the ANSI X3L2 Technical Committee on Codes and Character Sets (the "X3 Committee").
where drive: and path are the drive letter and path to the directory in which the file ANSI.SYS is found, and options can be a number of optional switches to control the behaviour. ANSI.SYS may also be loaded into upper memory via DEVICEHIGH/HIDEVICE.
- /K use extended keyboard BIOS functions (INT 16h) rather than standard ones
- /L force number of lines
- /R adjust line scrolling to support screen readers
- /S or /SCREENSIZE set screensize
- /X support redefinition of extended key codes independent of standard codes
Once loaded, ANSI.SYS enabled code sequences that changed the colors of the cursor and characters on the screen, or enabled software programs to move the cursor up or down lines, enabled blinking text, and similar text graphics features. Using this driver, text could be displayed in 16 different colors ("foreground" colors), with 8 optional background colors. It also allowed for the changing of the video mode from standard 80x25 text mode to a number of different graphics modes (for example, 320x200, 640x200, 40-column text mode) depending on which video graphics card was installed.
An interesting feature about ANSI.SYS was that it allowed for the remapping of any key on the keyboard in order to perform shortcuts or macros for complex instructions. This feature was also used by evildoers to create simple trojans out of text files called "ANSI bombs" laced with nefarious keyboard remaps. A number of antivirus utilities were written to ensure that, for example, the F3 function key wasn't remapped to DEL *.* or FORMAT C: and the N-key (for no) wasn't remapped to Y. As a security measure some versions of ANSI.SYS supported a command line switch to disable the key remapping feature.
ANSI.SYS was relatively slow as it mapped to the BIOS calls. There were several third-party replacements that directly mapped the video memory (similar to how most programs that did full-screen display worked on the IBM PC) that made console io useful. Typically these replacements deliberately did not support the keyboard remapping functions and thus defused the "ANSI bombs".
By default, the internal DOS command CLS works by directly calling the corresponding BIOS function to clear the screen, thereby prominently violating the hardware abstraction model otherwise maintained. However, if an ANSI driver is detected by the DR-DOS COMMAND.COM, it will instead send the control sequence defined in the reserved environment variable $CLS to the attached console device. If the environment variable is undefined, it falls back to send the sequence
ESC [ 2 J instead. Specifying other sequences can be used to control various screen settings after a CLS. Due to the difficulties to define environment variables containing binary data COMMAND.COM also accepts a special \nnn notation for octal numbers. For example, to send an alternative control sequence like
ESC + (for 1Bh 2Bh as used by ASCII terminals), one could define the variable as follows:
These features are supported by COMMAND.COM in all versions of DOS Plus and DR-DOS, but not in MS-DOS or PC DOS. They are also supported by the command interpreters in Concurrent DOS, Multiuser DOS and REAL/32, although they use VT52 rather than ANSI control sequences by default (e.g.
The file ANSI.SYS is a part of several Microsoft operating systems, including:
- Windows 95
- Windows 98
- Windows NT
- Windows 2000
- Windows XP
- Windows Server 2003 (x86 versions)
- Windows Vista
ANSI.SYS was required to run some software that used its cursor and color control functions. It could also be used to enable elaborate color codes in the COMMAND.COM prompt. These uses were overshadowed by the use of ANSI.SYS in BBSes; ANSI escape sequences were used to enable BBSes to send elaborate text graphics more elaborate than ASCII art, and to control the cursor in ways that were used in a number of online games and similar features.
CSI (Control Sequence Introducer) is a placeholder for the common two-byte escape lead-in sequence "ESC [" (that is, 0x1B 0x5B). The ANSI standard also defines an alternative single-byte CSI code 0x9B, which is not supported by ANSI.SYS.
Standard DOS ANSI.SYS drivers support only the following sub-set of ANSI escape sequences:
|ESC [ r A||Cursor up (CUU)|
|ESC [ r B||Cursor down (CUD)|
|ESC [ c C||Cursor forward (CUF)|
|ESC [ c D||Cursor back (CUB)|
|ESC [ r;c f||Horizontal and vertical position (HVP)|
|ESC [ r;c H||Cursor position (CUP)|
|ESC [ n J||Erase display (ED) (n=0,2 or n=0,1,2)[nb 1]|
|ESC [ n K||Erase in line (EL) (n=0 or n=0,1,2)[nb 1]|
|ESC [ n m||Select graphic rendition (SGR) (n=0..47)|
|ESC [ 6 n||Device status report (DSR) requests cursor position,
returned as cursor position report (CPR):
ESC [ r;c R
|ESC [ s||Save cursor position (SCP)|
|ESC [ u||Restore cursor position (RCP)|
There are also some escape sequences specific to the implementation of ANSI.SYS. They are not generally supported by ANSI consoles in other operating systems.
|ESC [ n h
ESC [ ?n h
ESC [ =n h
ESC [ >n h[nb 2]
|Set screen mode (SM)[nb 2]|
|ESC [ n l
ESC [ ?n l
ESC [ =n l
ESC [ >n l[nb 2]
|Reset screen mode (RM)[nb 2]|
|ESC [ n q||Enable (n=1) or disable (n=0) /X support[nb 3]|
|ESC [ L||Insert line (IL)[nb 4]|
|ESC [ M||Delete line (DL)[nb 4]|
|ESC $ ) 1||Switch keyboard input mode to Korean (Hangul)[nb 5]|
|ESC ( 2||Switch keyboard input mode to English[nb 5]|
|ESC [ +||Enable console output[nb 6]|
|ESC [ -||Disable console output[nb 6]|
|ESC [ a;b;... p||Set key re-definement (SKR/KR)|
|0||40 × 25 monochrome||1||40 × 25 color|
|2||80 × 25 monochrome||3||80 × 25 color|
|4||320 × 200 color||5||320 × 200 monochrome|
|6||640 × 200 monochrome|
|7||Wrap at end of line[nb 7]|
|13||320 x 200 color (graphics)||14||640 x 200 color (16-color graphics)|
|15||640 x 350 monochrome (2-color graphics)||16||640 x 350 color (16-color graphics)|
|17||640 x 480 monochrome (2-color graphics)||18||640 x 480 color (16-color graphics)|
|19||320 x 200 color (256-color graphics)|
|114||640 x 480 color (16-color graphics)[nb 8]||115||640 x 475 color (16-color graphics)[nb 8]|
- Arguments 0,1,2 are only supported and distinguished by Japanese versions of MS-DOS and PC DOS ANSI.SYS. Western issues of ANSI.SYS will not support or not distinguish between them. They are, however, also supported by Multiuser DOS.
- Lead-in prefix '>' is only supported in Japanese versions of MS-DOS, PC DOS and DR-DOS ANSI.SYS to access special Japanese display modes.
- This non-standard escape sequence is only supported by MS-DOS and PC DOS ANSI.SYS. It can be used to enable or disable extended keyboard support at runtime similar to the ANSI.SYS /X startup option.
- These non-standand escape sequences to insert and delete lines are only supported by Japanese versions of MS-DOS and PC DOS. They are also supported by Western issues of Multiuser DOS, but not by DR-DOS.
- These non-standard escape sequences to switch between the Korean and English keyboard input modes are only supported by Korean versions of MS-DOS, PC DOS and DR-DOS ANSI.SYS.
- These non-standard escape sequences to disable and reenable any output to the CON: device are supported by ANSI.SYS of DR-DOS 7.02 and higher only. They are used to mute the console output during boot, for example in conjunction with DR-WebSpyder boot floppies.
- A value of 7 is used to either enable (with SM) or disable (with RM) the wrap around at the end of rows. If enabled, the option causes extra characters to wrap onto the next line, while these characters will be lost, if wrapping is disabled.
- Video modes 114 and 115 are only supported by Japanese DOS/V issues of ANSI.SYS found in DR DOS 6.0, Novell DOS 7 and higher.
- Paul, Matthias (1997-07-30). "NWDOS-TIPs — Tips & Tricks rund um Novell DOS 7, mit Blick auf undokumentierte Details, Bugs und Workarounds" (e-book). MPDOSTIP (in German) (3, release 157 ed.). Retrieved 2012-01-11. NWDOSTIP.TXT is a comprehensive work on Novell DOS 7 and OpenDOS 7.01, including the description of many undocumented features and internals. It is part of the author's yet larger MPDOSTIP.ZIP collection maintained up to 2001 and distributed on many sites at the time. The provided link points to a HTML-converted older version of the NWDOSTIP.TXT file.
- DR-DOS 7 user documentation, description of ANSI.SYS escape sequences (incomplete)
- Modifying the DOS prompt with ANSI.SYS
- ANSICON ANSI.SYS alternative for recent Windows versions (Vista, 7) supporting both 32 and 64 bits
- Guide to using ANSI.SYS
- Ansilove/PHP A set of tools for converting ANSi/BiN/ADF/iDF/TUNDRA/XBiN files into PNG images
- ANSI.SYS keyboard codes from µVGA