This is only a preview of the April 1991 issue of Silicon Chip. You can view 49 of the 96 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "Build The SteamSound Simulator":
Articles in this series:
Articles in this series:
Articles in this series:
Articles in this series:
Articles in this series:
Articles in this series:
|
COMPUTER BITS
BY JENNIFER BONNITCHA
Playing with the ANSI.SYS file
This month, we take a close look at the
enhanced keyboard and display device
driver - ANSI.SYS. This is an extensive list
of codes for driver controlling your monitor
screen and keyboard.
ANSI.SYS is a driver which causes
your computer to emulate the American National Standards Institute
(ANSI) standard for terminals. Together with the International Standards Organisation (ISO), these bodies originally established an extensive set of console control codes for
terminals connected to mainframe
computers. The standards provide
software portability for hardware
interfaces.
Note that ANSI.SYS is not a full
implementation of the Digital Electronics Corporation (DEC) terminal
VT-100 control codes. While the VT100 terminal implements all ANSI
control codes, the DOS version of
ANSI.SYS lacks the VT-100 terminal
codes to:
• erase from the current cursor position to the end of screen.
• erase from current cursor position
to the beginning of screen.
• erase from current cursor position
to the beginning of line.
ANSI.SYS recognises a subset of
the control codes defined in the ANSI
console standard.
Before you can start experimenting
with installable device driver
ANSI.SYS, you must explicitly configure your system. The driver needs
to be somewhere on your boot disc,
although it is usually found in the
root or DOS directories. If your driver
is in the root directory, include the
following statement in your
CONFIG.SYS file: device=ansi.sys
However, if your driver is located
in another directory (typically the
DOS directory), include this statement:
device=c: \dos \ansi.sys
Once you include the driver, you
must reboot your system for it to take
effect. It remains installed until you
remove the device line from your
CONFIG.SYS file and reboot the
computer again.
Technically, ANSI.SYS is a console
device driver. It oversees the actions
of the keyboard and screen which are
collectively known as the console.
The program was introduced with
MS-DOS 2.0 and has some 15 sepa-
Before you can start experimenting with
ANSI.SYS, you must configure your system. The
driver needs to be somewhere on your boot
disc, although it is usually found in the root or
DOS directories.
74
SILICON CHIP
rate functions which can be grouped
into five categories:
• control of cursor position;
• erase all or part of the display
screen;
• control video mode settings;
• control video attribute setting;
• reassign character strings to individual keys on the keyboard.
Data entered from the keyboard is
sent to the computer as a sequence of
ASCII (American Standard Code for
Information Interchange) characters.
ANSI.SYS operates by intercepting
special codes sent to the video display and using them to change how
the display and keyboard function.
ANSI.SYS then recognises certain
character sequences as being command sequences which can direct
modification of the display screen
output.
All ANSI commands have the same
format; the command is introduced
with an escape character and a left
bracket. You will often find the word
ESC shown in reference manuals to
represent the escape sequence.
An ANSI escape sequence is a series of characters that you can use to
define functions for MS-DOS. Specifically, you can change graphics
functions and affect the movement of
the cursor. All ANSI.SYS command
sequences begin with an escape character whose ASCII value is 27. The
escape character doesn't display on
the screen, however you will usually
see a left arrow or A(. Either way,
ASCII character code 2 7 is the escape
character and not the Esc key on your
keyboard.
The escape character and the left
bracket are usually followed by a parameter, although there are some escape sequences which can have multiple parameters and some that don't
require any at all.
You can specify multiple parame-·
ters by separating them by semi-colons. Each sequence ends with a letter to indicate the instruction and terminate the sequence. If the function
requires any parameters, they are entered between the [ and the letter. A
typical ANSI code, Esc[2J is the clear
screen instruction. Note that the function code letter is case sensitive - you
need to be careful.
ANSI.SYS escape sequences
The numeric ANSI sequences have
three functions:
• to represent the co-ordinates or
number of columns or lines to move
for cursor positions;
• to represent the mode (such as the
2 in Esc[2J - the clear entire screen
command) for erasing the display or
screen settings;
• to represent the ASCII character of
the extended code for a key when
reassigning the keyboard keys.
ANSI.SYS & cursor position
The most popular use for the commands is to control the cursor's screen
location. Although cursor control is
limited from the DOS prompt, you
can use this type of command in batch
files. You could clear the screen then
position the cursor in the centre of
the screen. Note the appropriate case
for each function code letter.
Cursor position - ESC[#;#H - Moves
the cursor to a position on the display
screen specified by the # parameters.
The first parameter specifies the line
number, the second the column number of the cursor position. The cursor
moves to the home position - upper
left corner of the screen - if none is
specified.
'
Horizontal/vertical position - ESC
[#;#f - Has the same function as the
cursor position command. Again,
with no parameters specified, the
cursor moves to the home position.
Cursor up - ESC[#A - Moves the cursor up a number of lines without
changing columns, where # determines the number of lines moved.
The default is 1. If the cursor is already on the top line, MS-DOS ignores the sequence.
Cursor down - ESC[#B -As for ESC#A
with the cursor moving down the
screen. If the cursor is already on the
bottom line, MS-DOS ignores the sequence.
Cursor forward - ESC[#C - This se-
quence moves the cursor forward one
column without changing lines. The
# sets the number of columns moved,
where the default is 1. If the cursor is
already in the far right column, MSDOS ignores the sequence.
Cursor back- ESC[#D -As for ESC[#C
and the movement is backwards. If
the cursor is already in the far left
column, MS-DOS ignores the sequence.
Save cursor position - ESC[s - Saves
in memory the current position of the
cursor. Cursor position is then restored using the following command,
Restore Cursor Position.
Restore cursor position - ESC[u - This
sequence restores the cursor position
to the value it had when the console
driver received the Save Cursor Position sequence.
Device status report - ESC6n - Requests that ANSI.SYS issue a cursor
position report.
Cursor position report - ESC[#;#R Reports the current position of the
cursor. The first parameter is the current line, the second the current column. ANSI.SYS issues this report in
response to the request for a Device
Status Report.
Erase display - ESC[2J - Erases the
entire display and positions the cursor at the home position.
Erase line - ESC[K - Erases from the
cursor to the end of the line, including the cursor position.
There's much more but perhaps the
obvious has emerged - how to send
the ANSI commands to the screen?
You can't just type the escape character, since when DOS interprets the
Esc key it means erase this line and
start over. Fortunately, you have several alternatives.
The DOS TYPE command
• create a text file using an editor
which lets you enter the escape character just by pressing Ctrl [ (note that
it may appear as either a left arrow or
A[). You can then use the DOS command TYPE to display the file and
activate the functions.
A good trick to remember is that
the escape character is actually Ctrl V
(AV). EDLIN, the DOS line editor, is
quite happy to receive this key sequence. The Ctrl V tells EDLIN to
make the next character in the sequence a control character. Thus, to
enter an escape character, use AV[
followed by the required sequence;
{ONI
50 MHz Frequency Counter Kit
$ 99.00
1 GHz Frequency Counter Kit
$299.00
121240V 40 Watt Inverter Kit
$ 99.00
121240V 300 Watt Inverter Kit
$379.00
Discolite Kit
$159.50
Gates 2V 2.SAH's D Cell
$ 7.95
Gates 2V SAH's X Cell
$ 11.95
Arlec 6V Lantern Battery with
240V charger & 12V Cigarette
lighter charger
$ 59.00
Arlec variable Power Supply
5-15V DC 2A
$ 89.95
100meter Roll Speaker Cable
$ 16.95
President AM 40Channel CB
Radio
$109.00
4 Channel Audio Mixer for
VCR's Arista AVM-1 $ 69.95
13.SV 7.4A Transformer
$ 16.95
18V 6A Transformer
$ 39.95
200 channel handheld scanner
66-88MHz,
118-174MHz,
406-512MHz, 806-956MHz.
$499.00
NOW OPEN our new:
Electronics Disposal Store
27 The Mall
Sth. Croydon, Vic, 3136
Telephone: (03) 723 2699
Please Note: We are interested
in purchasing your Surplus
components & equipment.
M,
n
Electronic World
30 Lacey St, Croydon
VIC, 3136.
Telephone:
Fax:
(03)723 3860
(03)723 3094
(03)725 9443
APRIL 1991
75
TABLE 1
SPECIFY THIS
CHARACTER
$
b
d
e
g
I
n
p
V
TO GET THIS PROMPT
The $ character
The I character
The current date
Escape character (ASCII code 1b hex, 27 decimal)
The
The
The
The
The
> character
< character
default drive
working directory of the default drive
current time
The DOS version number
Carriage return, linefeed sequence. Note this is the
underscore character
eg, AV[[1;37;44m. You must use the
double square brackets [[ since the
first is used with Ctrl V to create the
escape character and the second is
the normal lead_-in sequence for the
ANSI command sequences. When
complete, TYPE filename to see the
results.
The DOS ECHO command
• create a batch file using the above
methods to enter the escape character
and then use the ECHO batch command to activate the functions.
Type the same command above
using:
ECHO AV([1;37;44m
At the DOS prompt, type 't he name
of the batch file then press Enter.
The DOS PROMPT command
• you could use the DOS command
PROMPT to activate the commands,
since the PROMPT code $E is an escape code - and this is possibly the
easiest method . Note that the
PROMPT codes are NOT case sensitive.
Once again, for the same command:
PROMPT $e[1;37;44m
The PROMPT command lets you
change the MS-DOS system prompt
using characters and prompt commands to create special prompts. You
must precede each character with a
dollar sign ($). Table 1 shows the details.
The most popular prompt displays
the current drive and path followed
by the > than sign: PROMPT $P$G.
76
SILICON CHIP
Remember that since the PROMPT
command can send ANSI command
sequences, you can combine the best
of both worlds:
PROMPT $e[1;37;44m$P$G
This tells DOS to change the screen
colour display and make the prompt
show the current drive and path information.
Using BASIC
BASIC shelters the user from the
operating system and thus intercepts
many of the DOS and computer interrupts. The same shelter environment
shields the ANSI device driver. You
could, however, use compiled BASIC
such as QuickBASIC, Turbo BASIC
etc. Clever people can use interpretive BASIC (BASIC, BASICA and GWBASIC) together with the DOS command TYPE to print ANSI sequences.
For example:
OPEN "TEST4.BAT" FOR OUTPUT
AS 1
PRINT #1, CHR$(27);"1;37;44m"
CLOSE #1
The program can then be used by
typing the DOS command:
TYPE TEST4.BAT
With practice, you can gain valuable experience both with your computer and the ANSI commands.
ANSI.SYS escape sequences
The main cursor control functions
are up (A), down (B), left (D) and
right (C). Remember the default is 1,
so used without a parameter, each
command moves the -cursor one row
.or column. You can however specify
the cursor position more accurately:
ESC[5B ... I'm here
This positions the cursor five rows
down the screen, while:
ESC[12;35H ... Now I'm here!
positions the cursor approximately to
the centre of the screen. You could
try these commands using COPY CON
as discussed last month. As a quick
memory jogger, note that each line
ends with the Enter key and you press
function key F6 or AZ (Ctrl Z) at the
completion to copy the console contents to a file:
COPY CON TEST.BAT
<at>echo off
cls
prompt $e[5B ... I'm here
AZ
then
COPY CON TEST2.BAT
<at>echo off
cls
prompt $e[12 ;35H ... Now I'm here!
AZ
MS-DOS 3.3 and 4.x allow you to
suppress the display of a line in a
batch file by preceding the line with
the <at> character. Without the <at> sign,
the ECHO OFF command would display on the screen. Thus, the above
batch files display only what you
need.
Remember to separate multiple
numeric codes with a semicolon and
don't use a semicolon just before the
command letter in a sequence. The
final letter in an ANSI sequence is
the command letter; ANSI does not
see this letter if a leading semicolon
is used; eg, ESC[44;1;37;m is incorrect. Make sure you use the correct
case for the ANSI command letter
since upper and lowercase letters are
significant.
Finally, if you omit a numeric parameter, the assumed value is O (zero)
or 1. Depending on the sequence used,
ANSI makes various assumptions
about missing values. The assumed
value for cursor positioning is 1, while
for screen attributes it is 0. Be aware
that in some situations the default
value may not work and yet in others
will work correctly. If you omit the
row and column co-ordinates from
the ESC[f command, ESC[1;1f (the
home location) is assumed.
Next month, we'll have more adventures with the PROMPT command, setting screen colours and
customising the keyboard.
SC
|