home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 December
/
simtel1292_SIMTEL_1292_Walnut_Creek.iso
/
msdos
/
sysutl
/
ansi_sys.arc
/
ANSI-SYS.DOC
< prev
Wrap
Text File
|
1985-07-08
|
22KB
|
462 lines
ANSI.SYS
~~~~~~~~
What is a Device Driver ?
Basically, a Device Driver is a special software program used to manage
all communications between a device (usually hardware) and the PC. It's
helpful to think of a device driver as a "logical" device. To the operating
system, this driver is the device. DOS never "sees" the actual device, but
accesses the actual device through the driver. In other words, the device
driver is an interface. DOS has several "built-in" device drivers that
handle such things as the diskette drives, system clock, the console (key-
board and display), printer (parallel port) and communications (serial
port).
There are two (2) types of devices, character and block. Character
devices handle I/O in a serial manner like CON, AUX, CLOCK$ and PRN.
Character devices can be "opened" to do input and/or output since they have
only one name and handle only one physical device.
On the other hand, block devices are the hard disk and diskette drives in
a system and do random I/O in pieces called blocks (usually the sector size
of a disk). These devices are not named like the character devices, rather
they are "mapped" alphabetically by drive letter. Block devices can handle
several physical units. So a single device driver can be responsible for
I/O to several diskette drives and/or hard disks.
The CONFIG.SYS file
One of the first things things to happen when you "boot" your computer, is
that the operating system looks for special information about how it is to
configure itself. It expects to find those directions in a text file on the
boot disk called CONFIG.SYS. If DOS can't find a CONFIG.SYS file, it sets
itself up in a "default" configuration. Think of CONFIG.SYS as containing
the first directions you give to DOS. Among other things, those directions
may include the names of foreign (non IBM) devices that are to be added to
the system. When you add a device to the computer that is non IBM, (and
even some that are IBM), you will need a matching software device driver so
that it can be integrated into the system. A typical CONFIG.SYS file might
look like this.
Sample CONFIG.SYS file
-----------------------
| DEVICE = MOUSE.SYS |
| DEVICE = CLOCK.SYS |
| DEVICE = HARDDISK.SYS |
| DEVICE = RAMDISK.SYS |
-----------------------
The sample file tells DOS to install character (mouse and clock-calendar)
and block (a hard disk and a ram disk) devices. Notice that the ram disk is
entirely software. No hardware is involved. This is one of the very useful
feature of device drivers. To install a new or replacement device in your
computer system, one of the steps will include adding a line to the
CONFIG.SYS file.
ANSI.SYS - A CONsole device driver
The ANSI.SYS driver gets its name from the American National Standards
Institute (ANSI), which defined a standard method for control of certain
terminal characteristics. The effort at standardization was a reaction to
the many types of intelligent terminals being manufactured. Unfortunately,
ANSI.SYS was not entirely successful: manufacturers having different goals
than the committee. In fact, no terminals are ANSI standard, although the
DEC VT-100 comes quite close.
The central concern of the committee was to define codes in addition to
the standard ASCII control codes that could be use to govern terminal
characteristics such as cursor and character positioning, character high-
lighting and character color.
You may know, ASCII is a code that provides for the translation of the
standard alphanumeric characters into a binary form for storage and manipu-
lation by the computer. Using binary notation, 7-bits can represent any of
128 different values (2 to the 7th) which is more than ample for encoding
the 96 standard alphanumeric characters and a few punctuation symbols. The
standard ASCII codes (as opposed to the extended IBM set of 256) also
include 32 "control characters" (i.e. carriage return, tab, line feed, etc).
Control characters generally provide "commands" (as opposed to data) to
peripheral devices. For example, a line feed tells a display to move the
cursor down 1 line. But 32 characters allow only a total of 32 possible
commands, rather limited. What the ANSI committee attempted was to provide
a standard syntax which would allow a greatly increased number of control
codes for terminals. The method they arrived at was to select a single
ASCII character, which when detected by the terminal, would indicate that
the next sequence of characters was a command, not data for display. This
simple decision made possible many more than the original 32 control codes
for issuing commands to intelligent terminals. You probably guessed that
the ASCII character they picked was ASCII 27, commonly known as "escape".
All of which brings us back to ANSI.SYS, a subset of the coding language
established by the committee. To use it, you must install it as a device
driver by adding the following line to the CONFIG.SYS file.
DEVICE = ANSI.SYS
When listed in the CONFIG.SYS file, ANSI.SYS replaces the CONsole handler
that DOS uses by default. Its installation gives you added control over the
keyboard and display.
Now. As previously mentioned, the leading character of all "control
sequences" is ESCape. Unfortunately, it's not possible to enter an ASCII 27
from the keyboard. If you do, DOS simply cancels the current line. But,
one of the DOS commands, PROMPT, does allow the sending of <ESC>, as part of
a text string, to the console display. It turns out that one of the easiest
ways to send commands to ANSI.SYS is by using the PROMPT command. The
syntax for PROMPT is:
PROMPT [prompt-text]
Since the ANSI standard was deliberately designed to be as open-ended as
possible, a second leading character is used to define each particular
subset. On the IBM PC, that character is the left bracket "[". Therefore
each of our control sequences begin with "ESCape [". The characters used by
PROMPT to indicate ESCape are "$e", making the beginning of each PROMPT
command look like this.
PROMPT $e[ ...
After these two "lead-in" characters, are the parameters of the ANSI com-
mand, then the character that identifies the command. The syntax is:
PROMPT $e[<parameter>;...;<parameter><identifier>
Cursor Control
As an example, let's prepare a command for moving the cursor. There are a
total of 10 control sequences that can be used for controlling the cursor,
but 2 of them are functionally identical. They are CUP (CUrsor Position)
and HVP (Horizontal Vertical Position). We'll use HVP for this example.
The syntax we want is:
PROMPT $e[<row>;<column>f
If you chose to move the cursor to the beginning of the last line of the
screen, (row 25, column 1), the command would read:
PROMPT $e[25;1f
If you type this command and press <enter>, you will see the cursor (a
flashing underline) at the beginning of the last line on your screen. The
normal DOS drive letter prompt has disappeared. What has happened is that
you've changed the standard A> prompt to an abstract prompt which consists
of an escape sequence. So every time DOS tries to display the prompt, it is
intercepted by ANSI.SYS. It never makes it to the display. If you wish to
have your old DOS prompt back, just type the word PROMPT and press <enter>.
That causes DOS to revert to the default system prompt.
The cursor control sequences may be divided into the following groups.
Cursor Movement
-------------------------------------------------------
| CUU - CUrsor Up - PROMPT $e[<number of rows>A |
| CUD - CUrsor Down - PROMPT $e[<number of rows>B |
| CUF - CUrsor Forward - PROMPT $e[<number of columns>C |
| CUB - CUrsor Back - PROMPT $e[<number of columns>D |
-------------------------------------------------------
Find Current Cursor Position
----------------------------------------------------------
| DSR - Device Status Report - PROMPT $e[6n |
| CPR - Cursor Position Report - PROMPT $e[<row>;<column>R |
----------------------------------------------------------
DSR is your query of the device - CPR is the response
Cursor Positioning
------------------------------------------------------------------
| CUP - CUrsor Position - PROMPT $e[<row>;<column>H |
| HVP - Horizontal & Vertical Position - PROMPT $e[<row>;<column;f |
| SCP - Save Cursor Position - PROMPT $e[s |
| RCP - Restore Cursor Position - PROMPT $e[u |
------------------------------------------------------------------
Erasing
---------------------------------------
| ED - Erase in Display - PROMPT $e[2J |
| EL - Erase in Line - PROMPT $e[k |
---------------------------------------
With this range of commands at your disposal, you have a lot of power over
the curser, enough to build a rudimentary text editor, but the exploration
of each is up to you.
Mode Control
Another feature of ANSI.SYS is the ability to control the mode used for
display, including screen width, color, intensity and word wrap. For
example, if you wish to set the display to a 40 column screen width using a
black and white display attribute, you would use the Set Mode control
sequence. Here is the list of possible display modes.
Setting the Display Modes
---------------------------------------------
| SM - Set Mode - PROMPT $e[=<parameter>h |
| RM - Reset Mode - PROMPT $e[=<parameter>l |
---------------------------------------------
| parameter list |
| ~~~~~~~~~~~~~~ |
| 0 - 40x25 black and white |\
| 1 - 40x25 color | \ Text
| 2 - 80x25 black and white | / Screens
| 3 - 80x25 color |/
| 4 - 320x200 color |\
| 5 - 320x200 black and white | > Graphic
| 6 - 640x200 black and white |/ Screens
| 7 - if SM, word wrap is on |
| if RM, word wrap is off |
-----------------------------------
Using the example of a 40 column black and white display, the code sequence
would be:
PROMPT $e[=0
If you want to change that to a color display with 80 columns, the sequence
becomes:
PROMPT $e[=3
Now that the console is set for the display of color, a control sequence
is needed to set the color and intensity.
Setting Color and Intensity
-----------------------------------------------------------------------
| SGR - Set Graphics Rendition - PROMPT $e[<parameter>;...;<parameter>m |
-----------------------------------------------------------------------
| parameter list |
| ~~~~~~~~~~~~~~ |
| 0 - normal attributes (default display) |
| 1 - bold on (high intensity) |
| 4 - underline on (monochrome only) |
| 5 - blink on |
| 7 - reverse video on |
| 8 - canceled on (invisible) |
| 30 - black characters |
| 31 - red characters |
| 32 - green characters |
| 33 - yellow characters |
| 34 - blue characters |
| 35 - magenta characters |
| 36 - cyan characters |
| 37 - white characters |
| 40 - black background |
| 41 - red background |
| 42 - green background |
| 43 - yellow background |
| 44 - blue background |
| 45 - magenta background |
| 46 - cyan background |
| 47 - white background |
-----------------------------------------------
To set the display to a blue background with red characters displayed in
high intensity, the control sequence would be:
PROMPT $e[44;31;1m
or for blue characters on a light yellow background:
PROMPT $e[34;43;7m
That is the range of control sequences available for control of the
display screen while using ANSI.SYS. Not unlimited to be sure, but it does
increase the user's control over the way things are displayed. In fact here
is a sample batch file called COLOR.BAT that let's you easily change the
color of the characters bring displayed on your screen. The syntax for its
use is:
COLOR <your choice>
COLOR.BAT
--------------------------------
| if %1 == red prompt $e[31m |
| if %1 == green prompt $e[32m |
| if %1 == yellow prompt $e[33m |
| if %1 == blue prompt $e[34m |
| if %1 == magenta prompt $e[35m |
| if %1 == cyan prompt $e[36m |
| if %1 == white prompt $e[37m |
| prompt |
--------------------------------
Redefining the Keyboard
One of the most popular types of software on the market allows the user to
redefine the keyboard and/or assign strings of characters to single key
strokes. What many do not know is that by using the ANSI.SYS device driver
these features are already available. If want to rearrange the keyboard to
a "davork" layout, (as opposed to qwerty) you can use ANSI.SYS to do it. If
you would rather press <Crtl-Home> to clear the screen (like you do while
using BASIC) than typing out CLS and pressing <enter>, you can do that too.
Or maybe you'd like to spell out the word "Bloomington" by typing <Alt-B>.
The keyboard redefinition features of ANSI.SYS are very powerful. Here is
the basic control sequence you need for keyboard redefinition.
PROMPT $e[<number>;<number>p
The 2 numbers stand for, respectively, the ASCII value of the character you
want replaced and the ASCII value of the new character. For instance, if
you want a "B" to display every time you press "A", the code sequence would
be:
PROMPT $e[65;66p
"A" is ASCII 65 and "B" is ASCII 66. After executing this command, whenever
you type "A", you'll see "B" displayed. By building yourself a batch file
containing the necessary control sequences, you can use this method to
convert your keyboard to the "davork" layout. You can even physically move
the keytops if you want.
Another form of the control sequence allows a single keystroke to generate
a string of characters. It looks like this.
PROMPT $e[<number>;"string"p
When the command is received, the key that represents the ASCII value of
<number> will generate whatever string appears between the two quote marks.
For instance, the control sequence,
PROMPT $e[122;"zebra"p
will cause the "z" key to be replaced by the word "zebra".
A more useful feature of key board redefinition is accomplished with yet
another form of the control sequence.
PROMPT $e[0;<number>;"string";...<number or string>p
This is the really powerful version that allows the assigning of strings so
that complex commands (or tasks) can be executed using single keystrokes.
For instance, I might want to redefine the function keys to perform common
DOS commands. The batch file for reassignment might look like this.
FKEY-NEW.BAT
--------------------------------
| prompt $e[0;59;"dir a:/p";13p |
| prompt $e[0;60;"dir b:/p";13p |
| prompt $e[0;61;"basica";13p |
| prompt $e[0;62;"copy "p |
| prompt $e[0;63;"cls";13p |
| prompt $e[0;64;"format b:"p |
| prompt $e[0;65;"chkdsk "p |
| prompt $e[0;66;"mode co80";13p |
| prompt $e[0;67;"debug";13p |
| prompt $e[0;68;"del "p |
| prompt |
--------------------------------
Of course, you may prefer to assign different functions to the function
keys, so your batch file would have different strings for each key. Notice
that in several definitions "13" was added before the identifier "p".
That's the ASCII value for carriage return and causes the command to execute
automatically when the respective function key is pressed. But there are
times when that's not desirable. For example, when using the CHKDSK com-
mand, it may be necessary to specify a different drive or include one of the
parameters. In such a case, pressing the F7 key displays only "chkdsk"
followed by a space. It's up to the user to complete and execute the
command.
It is possible to assign more than one string to each function key. Since
most keys produce a different value (scan code) when pressed in combination
with either <shift> key, the <Alt> key or the <Ctrl> key, different strings
may be assigned to each combination. That allows 4 strings to be assigned
to each function key giving a total of 40 strings just for the function
keys.
While most may think of only the function keys for string assignment,
other possibilities exist. Assignment of string to the standard alpha-
numeric keys (letters and numbers) pressed in combination with the <Alt> key
is acceptable. This allows us to retain the combination of letter keys and
<Ctrl> key for use in imbedding printer control codes in our files, and the
original values of the unshifted and shifted keys. If a application program
assigns meaning to the function keys, the only remaining choice may be to
use the <Alt> key in combination with the alphanumerics for string assign
ment. For instance, the control sequence needed to cause the <ALT-d>
combination to display the directory of th current drive would be:
PROMPT $e[0;32;"dir";13p
To make it easier for you to assign strings and/or commands to specific
keys, the next page has a table of the numbers (scan codes) for each key
that you are likely to want to redefine or assign strings and/or commands
to.
When you first look at the table, you will notice that there seem to be
several codes that are generated by more than one key stroke combination.
Not so! All of the function keys (alone or in combination with the <shift>,
<Ctrl> and <Alt> keys) and the alphanumeric keys (in combination with the
<Alt> key) generate an extended code. Since there are more key stroke
combinations than there are ASCII codes, something had to be done to allow
the computer to recognize the extra combinations. The solution was to have
the addition combinations produce an extended code. These codes consist of
two values instead of one. The first value is always a null (ASCII 00) and
indicates to the computers CONsole driver that a special key has been
pressed. (Remember the leading zero in the above PROMPT string?) The
second value is then used to identify the particular key (or combination of
keys) that was pressed. Although the codes in the table may at first seem
to be duplications, they are not.
Hopefully this discussion of ANSI.SYS will help you integrate its use into
your computing in order to simplify the execution of routine tasks.
by Michael L Hoyt, 5 jul 85
Table of Keyboard Extended Function Codes
-----------------------------------------------
| Key Normal <Shift> <Ctrl> <Alt> |
| F1 59 84 94 104 |
F | F2 60 85 95 105 |
U | F3 61 86 96 106 |
N K | F4 62 87 97 107 |
C E | F5 63 88 98 108 |
T Y | F6 64 89 99 109 |
I S | F7 65 90 100 110 |
O | F8 66 91 101 111 |
N | F9 67 92 102 112 |
| F10 68 93 103 113 |
|===============================================|
| 1 49 33 * 120 |
| 2 50 64 00 121 |
N | 3 51 35 * 122 |
U K | 4 52 36 * 123 |
M E | 5 53 37 * 124 |
B Y | 6 54 94 30 125 |
E S | 7 55 38 * 126 |
R | 8 56 42 * 127 |
| 9 57 40 * 128 |
| 0 48 41 * 129 |
|===============================================|
| A 97 65 01 30 |
| B 98 66 02 48 |
| C 99 67 03 46 |
| D 100 68 04 32 |
| E 101 69 05 18 |
| F 102 70 06 33 |
| G 103 71 07 34 |
| H 104 72 08 35 |
| I 105 73 09 23 |
L | J 106 74 10 36 |
E K | K 107 75 11 37 |
T E | L 108 76 12 38 |
T Y | M 109 77 13 50 |
E S | N 110 78 14 49 |
R | O 111 79 15 24 |
| P 112 80 16 25 |
| Q 113 81 17 16 |
| R 114 82 18 19 |
| S 115 83 19 31 |
| T 116 84 20 20 |
| U 117 85 21 22 |
| V 118 86 22 47 |
| W 119 87 23 17 |
| X 120 88 24 45 |
| Y 121 89 25 21 |
| Z 122 90 26 44 |
-----------------------------------------------
If *, code is trapped by keyboard routine and not displayed.