Driving with ANSI.SYS (PC Magazine Vol 3 No 7 Apr 17, 1984/S. Smith) A program in DOS 2.0 called ANSI.SYS will give users of the PC extended control over keyboard and display functions, provided you can figure out how to use it. ANSI.SYS is a loadable device driver that becomes part of DOS and remains in memory with COMMAND.COM. Loadable drivers are a feature of DOS added with version 2.0. They allow you to change the software that controls your PC's peripherals, for example the console and disk drives, and to add support for new devices, such as RAMdisk or mouse. ANSI.SYS changes the console control software, the programs in DOS that interpret the codes sent from your keyboard and place characters on your display. It allows an application program to alter the input that will result from given keys and to change the attributes (color, intensity, etc.) and location (row and column) of output to the screen. These functions are provided by a specific set of control codes sent to the console as part of an output string. In other words, some portions of a program's output appear on your screen, but other parts are intercepted by the device driver, ANSI.SYS, and produce the altered functions you want. It is important, of course, that the commands don't appear in normal output. To ensure that this doesn't happen, the control codes begin with ASCII 27, the data link escape code. By convention, this character should never appear in an output string unless the program intends to send commands to a peripheral or its device driver. Many devices, for example the IBM printer, respond to the escape character by interpreting the next several characters as a command instead of as data. The standard console handler provided in DOS does not respond to escape codes, but ANSI.SYS does. When designing ANSI.SYS, IBM selected a set of commands adopted by the New York-based American National Standards Institute or ANSI -- hence the driver's name. The driver's incorporation of three ANSI standards permits the use of the many programs that are designed with the standards in mind (see Figure below). With the new console device driver installed, the PC can use these programs. ANSI.SYS can also be used to develop programs for the PC or other systems with terminals that meet the standard. It is no longer necessary to include hardware-specific commands to control the display or cursor location. Program outputs can achieve the same results on any conforming hardware. Unfortunately, the program output that is easiest for most of us to produce, BASIC print statements, does not pass through the DOS console driver and therefore bypasses ANSI.SYS. BASIC contains its own console handler which does not respond to escape commands. It is possible for BASIC to write strings containing the escape code to disk files and to send these to the console using the DOS TYPE or COPY commands. A later article will explore this approach for both the console and various printers in considerable depth. Here we'll see how other programs can use ANSI.SYS to control the display and reassign keys with DOS. DOS provides a simple way to laod device drivers. First, the file containing the driver software must be on the disk you will use to load DOS. To use the procedure given here, copy ANSI.SYS from the DOS disk to your working disk. Second, you must create a file called CONFIG.SYS that contains the following line: DEVICE = ANSI.SYS DOS 2.0 looks for this file whenever it is started and will install any device driver it specifies. The easiest way to create CONFIG.SYS is to enter the following commands after you start your system: COPY CON:CONFIG.SYS DEVICE = ANSI.SYS After entering these lines, press F6 or Ctrl-Z and the Return key. Now restart DOS, and ANSI.SYS will have been installed. At this point, your PC can use software written for terminals that use the ANSI standards. Programmers who are proficient in Pascal or assembly language can also write code that uses the extended keyboard and display control features. The rest of us are not left out, however, because there are still some clever things that ANSI.SYS can do using DOS commands alone. The trick is to find a way to generate the escape command. Generating an escape is not as easy as you might think. If you press the Esc key in either DOS or EDLIN, your current line is deleted (although not removed from the display), and the system waits for you to reenter it. Most other editors use the escape key in combinations to provide additional commands. They will not allow you to embed an ASCII 27 in your files. There is, however, a DOS command that allows you to send escape sequences directly to the console. The command is PROMPT, a little gem tucked away in Chapter 10 of the DOS manual under "Advanced Commands." Its purpose is to change the symbol that DOS uses to tell you that it is waiting for input, but it can do quite a lot more. The DOS manual states, "All text on the PROMPT command line is taken by DOS to be the new system prompt." If you enter: PROMPT READY DOS will no longer signal you with A>, but will use READY- instead. You can create any prompt you want by changing the text that allows the PROMPT command. Not all that text is taken literally, however. Some of it forms what are called "metastrings," groups of characters that take on special meaning. For example, if the PROMPT command includes the characters $t, DOS will not use them in the system prompt. Instead, it will replace them with the current time. Try entering PROMPT $t to see the effect. You will notice that entering PROMPT alone brings back A>. The next installment of this column will offer an expanded list of metastrings that can be used in combination with the PROMPT command. The most important of these is the metastring $e which generates an ASCII escape character and which will prove to be the key to using ANSI.SYS. Figure: ANSI standard console command codes implemented by IBM. ANSI.SYS does not display these strings, but rather takes the action indicated under "Function." Command Escape code name Function sequence ------- -------------------------------------- ------------ CUP Both these commands move the cursor Esc [1#,c# H HVP to line 1# and column c# Esc [1#,c# f CUU Move cursor up # lines Esc [# A CUD Move cursor down # lines Esc [# B CUF Move cursor forward # spaces Esc [# C CUB Move cursor backward # spaces Esc [# D SCP Save the cursor position Esc [s RCP Return the cursor to the position it Esc [u had when the last SCP was sent DSR Request console to send a CPR Esc [6 n CPR Cursor is at line #1 and column #c Esc [#1,#c R (The CPR is received by a program as if it had been entered at the keyboard.) ED Clear screen and home cursor Esc [2J EL Clear line from cursor to end (ANSI Esc [k specifies more erase options, but IBM does not support them.) SGR Set display attributes where # is Esc [#;...;#m 0 for normal display 1 for bold (high intensity) 4 underline 5 blink 7 reverse video 8 nondisplayed (invisible) (Options for color are in the DOS manual) SM Put the screen in the indicated mode Esc [=#h where # is chose from 0 for 40x25 black and white 1 for 40x25 color 2 for 80x25 black and white 3 for 80x25 color 4 for 320x200 color graphics 5 for 320x200 black and white 6 for 640x200 black and white 7 to wrap at end of line RM Reset the modes described above Esc [=# 1 ----------------------------------------------------------------- Metastring Magic (PC Magazine Vol 3 No 8 May 1, 1984/S. Smith) PROMPT is one command in DOS 2.0 that permits you to enter an escape character without deleting your current line. The escape is essential for transforming ordinary text characters into commands to a peripheral or its device driver to, for instance, control the display or reassign keys. PROMPT accomplishes this feat with the metastring $e (Figure 1). When inserted in a PROMPT statement, this metastring, with its ability to generate an ASCII escape character, unlocks the power of ANSI.SYS. The keyboard reassignment example from Chapter 13 of the DOS manual illustrates the procedure. It suggests that we send ANSI.SYS an escape followed by the string {0;68;"dir";13. To do this when the system prompt A> appears, type: PROMPT $e[0;68;"DIR";13p and press Return. You'll discover that the system no longer gives you any prompt at all. This is because the entire string has been used as a command by ANSI.SYS. Entering PROMPT with nothing following will bring back the A>, but there has been another change. If you press function key F10, you'll find that it now invokes the DOS directory command. PROMPT has sent a command to ANSI.SYS to effect the reassignment. Each of the three statements that follow is a valid form for a keyboard reassignment: Esc [#;#;. . .;#p Esc [#;"string"p Esc [#;#;"string";#;. . .;#p The first number sign (#) is the keyboard code of the key to be reassigned. The remaining #'s and strings are the ASCII characters to be assigned to the key. If the first # is zero, however, the second # becomes part of the keyboard code, because two-digit extended ASCII codes are being used. Keyboard codes are listed in Figure 2. With them, we could produce a series of PROMPT commands such as those in Figure 3. They can be entered one at a time or placed in a batch file called ALTKEYS.BAT. Invoking the ALTKEYS file will now make the following assignments to these combinations of the Alt key and the function keys: Alt-F1 Lists the directory of drive A Alt-F2 Lists the directory of drive B Alt-F3 Clears the screen Alt-F4 Shows the current disk volume Alt-F5 Turns Break function on (default setting) Alt-F6 Turns Break function off Alt-F7 Turns Verify mode on Alt-F8 Turns Verify mode off (default setting) Alt-F9 Enters Reverse Video mode Alt-F10 Restores normal while on black display Suddenly, 10 new functions keys are available under DOS, and you didn't have to buy any new software. Other reassignments are possible. Just use PROMPT as though it were a reassignment command and substitute $e where Chapter 13 directs you to use escape. Now that the link between PROMPT and ANSI.SYS has been established, the system prompt can be used to perform some clever operations. The next example illustrates control of the cursor position. Try entering: PROMPT $e[s$e[1;1H$e[k$e[60C$t$h$h$h$e[u$n$g This sequence saves the cursor position (Esc[s), moves the cursor to the first row and column (Esc [1;1H), clears the row (Esc [k), moves the cursor to the sixtieth column (Esc [60C), displays the current time ($t), backspaces three times to erase the hundredths of seconds ($h$h$h), returns the cursor to its saved position (Esc [u), and gives the standard prompt of the default driver ($n$g). You might call this the poor man's clock display. PROMPT can also control the display format or attributes. You can use it like the MODE command to select color or black-and-white display, 80- or 40-column width, and graphics or character displays. In the following examples, it is used to put the display in Reverse Video mode and return it to normal. Enter: PROMPT $e[7m$e[2J$n$g This sequence begins Reverse Video mode (Esc [7m), clears the screen to reverse all cells (Esc [2J), and then presents the standard prompt. Entering: PROMPT $e[0m$e[2J$n$g returns the screen to normal white on black. These commands can be placed in separate batch files. The examples I have included here are only some of the possibilities. I hope they show you that DOS is more than the sum or its parts. ANSI.SYS and PROMPT are useful by themselves, but together they can really expand your control over your computer. ANSI.SYS will let you reassign any of the keyboard codes defined by DOS, give you control over the location and movement of the cursor, and let you change the attributes of your display. PROMPT lets you change the signal DOS uses to show that it is ready to accept a command. By including metastrings, it allows you to show the time, date, default disk drive, and so forth in the prompt. Most significantly, PROMPT has a metastring for the ASCII escape code that allows it to include ANSI standard control sequences. When ANSI.SYS is installed, PROMPT can use its features to enhance the display, for example, with the poor man's clock. PROMPT can also serve as a command generator for the console driver, providing the direction to reassign keys and alter display formats. IBM has certainly added new capabilities to DOS 2.0; it's just a matter of figuring out how to use them. Figure 1: A listing of metastrings. DOS takes everything that follows a PROMPT command to be the new prompt, but it does not take all characters literally. The characters in these metastrings are automatically redefined. 1. The values generated by these metastrings change during the operation of your programs and cannot be known in advance. Metastring Will be replaced by ---------- ------------------- $d the system date $t the system time $n the default drive $p a directory of the default drive $v the DOS version number 2. These metastrings generate characters that would otherwise be given a different interpretation by DOS when they are entered. Metastring Will be replaced by ---------- ------------------- $h a backspace over the previous character $$ a dollar sign "$" $g the ">" character $l the "<" character $b the "|" character $q an equals sign "=" $- a carriage return and linefeed $e an escape, ASCII 27 Figure 2: A listing of keyboard codes. These codes, generated by the IBM PC keyboard and sent to the console device driver, are used in commands to ANSI.SYS to indicate which keys are to be redefined. Key Code Key Code Key Code -------------- ------------------ --------------- Null 3 F1 59 Ctrl F1 94 Back Tab 15 F2 60 Ctrl F2 95 Alt Q 16 F3 61 Ctrl F3 96 Alt W 17 F4 62 Ctrl F4 97 Alt E 18 F5 63 Ctrl F5 98 Alt R 19 F6 64 Ctrl F6 99 Alt T 20 F7 65 Ctrl F7 100 Alt Y 21 F8 66 Ctrl F8 101 Alt U 22 F9 67 Ctrl F9 102 Alt I 23 F10 68 Ctrl F10 103 Alt O 24 HOME 71 Alt F1 104 Alt P 25 Cursor Up 72 Alt F2 105 Alt A 30 Page Up 73 Alt F3 106 Alt S 31 Cursor Left 75 Alt F4 107 Alt D 32 Cursor Right 77 Alt F5 108 Alt F 33 End 79 Alt F6 109 Alt G 34 Cursor Down 80 Alt F7 110 Alt H 35 Page Down 81 Alt F8 111 Alt J 36 Ins 82 Alt F9 112 Alt K 37 Del 83 Alt F10 113 Alt L 38 Ctrl PrtSc 114 Shift F1 59 Alt Z 44 Ctrl Cursor Shift F2 60 Alt X 45 Left 115 Shift F3 61 Alt C 46 Ctrl Cursor Shift F4 62 Alt V 47 Right 116 Shift F5 63 Alt B 48 Ctrl End 117 Shift F6 64 Alt N 49 Ctrl PgDn 118 Shift F7 65 Alt M 50 Ctrl Home 119 Shift F8 66 Alt 1 120 Ctrl PgUp 132 Shift F9 67 Alt 2 121 Alt = 131 Shift F10 68 Alt 3 122 Alt - 130 Alt 4 123 Alt 5 124 Alt 6 125 Alt 7 126 Alt 8 127 Alt 9 128 Alt 0 129 Figure 3: PROMPT commands for defining combinations of the Alt key and various function keys. PROMPT $e[0;104;"DIR A:";13p PROMPT $e[0;105;"DIR B:";13p PROMPT $e[0;106;"CLS";13p PROMPT $e[0;107;"VOL";13p PROMPT $e[0;108;"BREAK ON";13p PROMPT $e[0;109;"BREAK OFF";13p PROMPT $e[0;110;"VERIFY ON";13p PROMPT $e[0;111;"VERIFY OFF";13p PROMPT $e[0;112;"PROMPT $$e[7m$$e[2J";13;"PROMPT";13p PROMPT $e[0;113;"PROMPT $$e[0m$$e[2J";13;"PROMPT";13p PROMPT ----------------------------------------------------------------- The MS-DOS Prompt Command Has More Power Than You Think (Microsystems November 1984 by C. Petzold) We usually think of using a disk operating system rathen than programming it. But DOS offers many powerful programming tools. DOS 2.0 and later lets you: - Display the time and date - Display the current directory path (for tree-structured directories) - Put this information anywhere on the screen - Change the color/graphics display mode and color (or monochrome display attributes) - Redefine the keyboard It's all a matter of understanding PROMPT, and DOS. The PROMPT command is an internal rather than an external command. The general format of the command is: PROMPT prompt-text where prompt-text stands for a wide range of commands. Executing this command in DOS makes the text following the word PROMPT the new system prompt, until you change it or boot again. Only one blank between PROMPT and the prompt-text will become part of the prompt, but any number of trailing blanks following the prompt-text (before you press Enter) are included. The word PROMPT, with no prompt-text following, resets the system prompt to the default drive and right angle bracket. How long can the new prompt be? Normal command processing accepts strings of 128 characters, including the final Return. This rule would allow a prompt of 120 characters (128 minus 6 for the word PROMPT, 1 for the space after the word PROMPT, and 1 for the final Return. It is possible to create a longer prompt if the command is a line in a batch file. The prompt becomes part of the command processor's environment. The environment memory (and hence any prompt that you set) can be viewed with the SET command if you include no parameters. If you have executed any programs that remain in memory (such as MODE, PRINT, ASSIGN, or GRAPHICS), you may have limited your environment storage. Using a long prompt may prevent you from specifying a long path name. Usually, the message OUT OF ENVIRONMENT SPACE results, but a crash could also occur when attempting to set long prompts. Certain characters cannot be used directly in prompt-text. These characters are the angle brackets, `<' and `>', the equal sign, `=', and the vertical bar, `|'. DOS uses these characters for other things, such as redirection of standard input and output. The equal sign works if it is not the first character of the prompt. Spaces, commas, semicolons, and equal signs are all ignored when they are the first character of the string. To use such characters in the prompt, you can define metastrings to take their places. These metastrings consist of a dollar sign, followed by a letter or symbol. The letter may be upper or lowercase. The PROMPT metastrings are shown in Figure 1. To use the right angle bracket, for example, enter the metastring $G. Thus, the command: PROMPT Enter a DOS command--$G causes the prompt: ==>. Since the dollar sign is used for these meta- strings, it takes two dollar signs to put one in a prompt display. If you want to create a prompt that begins with a blank, comma or semicolon, you must begin the string with a null character. Null characters are created by combining a dollar sign and any character not used for any other metastring, such as X. For a prompt that begins and ends with three blanks, try: PROMPT $X System Prompt $X Note the three spaces after the first $X and before the second. For a noisy prompt, type Ctrl-G in the prompt-text. It will appear on the screen as ^G. But instead of showing up when the prompt is displayed, your PC will beep. This beep can be used as a signal that a long DOS job is done. The second group of metastrings displays current information about the system. These allow you to show the current default drive (the normal prompt), the current directory path (if you are using tree- structured directories), the date, time and version number. The current directory path is what the CHDIR (of CD) command produces without parameters; the version number is the text that the VER command displays. For instance, the command: PROMPT $P$G will display: A:\> if drive A: is your default and you are in the root directory. If you are not in your root directory, then the directory path will be displayed: A:\LEVEL1\LEVEL2> The above display gives you a constant visual reminder of the current directory path, but the system must access the disk before displaying a directory-path prompt. This may cause a delay, depending on how deeply embedded in subdirectories you are. If your default drive is a disk rather than the fixed disk, this frequent disk access may be annoying. Other metastrings position the cursor as part of the PROMPT. The cursor can be backspaced (with an erasure), or a carriage return/linefeed can send the cursor to the beginning of the next line. The $H metastring backspaces and deletes a character. You may want to combine this feature with the time display to get rid of the hundredths-of-seconds. For instance, the command: PROMPT $T$H$H$H$G will produce the prompt: 10:52:30> Three more $H's will get rid of the seconds as well. The metastring $__ is a carriage return/linefeed sequence. The new prompt is displayed up to the $__, and then the cursor drops to the beginning of the next line, where anything after the $__ is displayed. The command: PROMPT OK$__ displays the same prompt you get in BASIC -- the OK prompt -- and waits for input on the next line. This prompt may not be a wise choice since it looks like BASIC, but you're still in DOS. Similarly confusing prompts should be avoided unless you have a special application for them. Finally, the $E metastring displays the ASCII Escape character (Hex 1B). Normally, this character shows up on the screen as a tiny left arrow. However, the ASCII Escape character, with the help of the DOS ANSI.SYS file, opens up a whole world of options with PROMPT. ANSI.SYS includes a series of video control routines that begin with an Escape code. Since ANSI.SYS assists DOS in driving the display, it functions as a device driver. Using ANSI.SYS with the PROMPT command is simple. ANSI.SYS is loaded from a CONFIG.SYS file when DOS is booted and becomes a part of DOS. You can create the necessary CONFIG.SYS file with the COPY command. Type: copy con:config.sys press Enter, and they type: device = ansi.sys and press Enter, F6 (or Ctrl-Z) and Enter again. The boot disk must contain CONFIG.SYS and the ANSI.SYS file. Now, the $E metastring gives you the whole range of extended screen control features. ANSI.SYS can interpret any command string that begins with an ASCII Escape character and either position the cursor, move it around, set display attributes and colors, or redefine the keyboard. Some of the more useful screen control sequences are shown in Figure 2 below. Notice that some characters are uppercase and some lowercase. This is an important distinction. ANSI.SYS interprets uppercase and lowercase characters differently. Try something simple: PROMPT $E[s$E{0;0H$T$E[K$E[u$N$G It may not appear simple but it is. Every $E metastring is converted to an ASCII Escape code when the prompt is displayed, and thus indicates to the ANSI.SYS file that a control sequence is present. The $E[s ANSI.SYS string saves the current cursor position so you can put it back where it belongs after moving it around the screen. Next, $E[0;0H moves the cursor to position 0,0 on the display -- the upper left-hand corner. The $T metastring prints the time, while $E[K erases the rest of the top line, $E[u restores the cursor and $N$G prints the normal prompt. When DOS tries to display this prompt, the $E metastring first sends an Escape character to the screen. ANSI.SYS recognizes the Escape code, intercepts the characters that follow, and carries out the command. The time display in the corner of the screen will be updated only when DOS displays the next prompt. In other words, it simply indicates the time when DOS last displayed the prompt. If this command doesn't work and you see some tiny arrows on the screen, then ANSI.SYS probably hasn't been loaded. You can find out by using the CHKDSK command to display the amount of available memory, since ANSI.SYS is a load-and-stay resident module. Putting the time on the top of the screen creates a primitive status line. These status lines are fairly easy to create and customize with the PROMPT command as long as you accept their limitations. Put status lines at the top rather than at the bottom of the display so that, when the screen scrolls, the previous status line will roll off the top and be replaced by the next. Here's a prompt that displays all available status information on the top four lines of the display: PROMPT $E[s$E[0;0H$V$E[K $_Directory:$P$E[K $_Date: $D$E[K $_Time: $T$E[K$E[u$N$G The $E[s saves the current cursor position (to be restored later) and the $E[0;0H portion sets the cursor at position 0,0. The $V metastring prints the version line, and the $E[K sequence erases the rest of the line. The next three sequences begin with a carriage return/linefeed ($-) so they'll each have a line of their own on the display. Spaces are shown after Date and Time, so the information lines up nicely. Remember that the $E[K erases the rest of the current line. The cursor is restored from the initial save by the $E[u sequence. Finally, back where the prompt should be, the $N$G sequence shows the familiar default drive and right angle bracket. For clarity these commands are shown on separate lines, but in reality this PROMPT sequence must be entered on a single line. If you'd like this status information to stand out try using reverse video or some other attribute with a control sequence. The $E[7m sequence turns on reverse video. Anything that follows will be printed black on green (on a monochrome display). The $E[0m sequence restores normal video unless you want all DOS displays in reverse video. A $E[5m sequence makes characters blink. If you have a color display, you can switch background and foreground colors. If you leave out the version number, you can put the current directory, date and time on one line at the top of the screen, provided that your directory path is 10 characters less than the maximum of 63. My favorite prompt puts the date and time in the upper left-hand corner of the display in reverse video and replaces the normal prompt with the current directory path: PROMPT $E[s$E[1;51H$E[K$E[7m$D/$T$E[0m$E[u$P$G Once you find a prompt you like, put it in AUTOEXEC.BAT so that the prompt will be set every time you boot up. You can do this either by putting the prompt directly in the AUTOEXEC.BAT file, or by putting the prompt in a batch file (mine is called PROMPTST.BAT) and then putting the name of the batch file in AUTOEXEC.BAT. An ANSI.SYS control sequence that permits keyboard reassignment is: $E[key;definitionp The key specification is either the ASCII code in decimal for the key you are redefining -- `65' for capital A, for example -- or a zero followed by a semicolor followed by an extended ASCII key number. Extended ASCII key numbers are used for keys that do not have normal ASCII definitions. These include the function keys, cursor movement keys and some others. The definition specification is what the key will become. This can be more than one character long and may be specified in pieces. The pieces are separated by semicolons. They may be either ASCII codes in decimal, or text in double quotation marks. The keyboard redefinition is terminated by lowercase p. ANSI.SYS will store the reassignment and use it when the redefined key is pressed. Once a key is redefined, it stays redefined until you change it or boot up again. The PROMPT command that redefines a key can be used only once. The key is then redefined, and you can specify a different prompt to control what is displayed on the screen. These keyboard reassignments will not work in any program that bypasses DOS to get keyboard information, such as the BASIC interpreters. These programs go straight to the BIOS for their keyboard information. You'll have to experiment with various programs to find out which ones will accept the redefined keys. The redefined keys will be the one most frequently used for DOS commands, following the operating system prompt. When you see the prompt, the COMMAND.COM file is running, and that program only uses DOS keyboard information. What keys should you reassign? The function keys are your best bet. For instance, if you have a number of batch files set up, you can define function keys to run them. If you find yourself typing the same command over and over, let a function key do the job. You probably do not want to use function keys F1 through F6. These keys have special meaning to DOS. If you think that leaves only four function keys, guess again. The 10 keys are really 40 function keys, since they can be pressed in combination with the Shift, Ctrl or Alt keys. So, you actually have 34 function keys left if you don't use F1-F6. The extended keyboard numbers for these keys are shown in Figure 3. If that's not enough, you can try using the Alt key in combination with letters or the top row of number keys. To define F7 to run a directory of the A: drive, type: PROMPT $E[0;65;"Dir A:";13p The entire prompt-text is used for the keyboard reassignment so nothing is displayed on the screen after this prompt sequence has been executed. The prompt-text consists of an Escape character, a left bracket, a zero (to indicate the use of an extended keyboard number), the number from Figure 3, another semicolon, the redefinition, another semicolon, a 13 (ASCII carriage return) and a lowercase p which tells ANSI.SYS that this sequence is a keyboard reassignment. After the key has been reassigned, you can type PROMPT without an argument to restore the regular prompt. Pressing the F7 key causes the "Dir A:" to be treated as a command. You can reassign keyboard keys more conveniently with a two-line batch file called KEYDEFIN.BAT: PROMPT $E[0;%1;"%2 %3 %4";13p PROMPT The first line is the PROMPT command to reassign a keyboard key. The percent signs followed by numbers are replacable parameters of the batch file. The second line restores the prompt to normal. Instead of executing the PROMPT command in the second line, you may want to put in the name of the batch file where your favorite prompt is stored. Note that the Echo feature must be on for this file to work. DOS must actually try to display the prompt for ANSI.SYS to intercept it and reassign the keys. To use this batch file, try: KEYDEFIN 66 DIR b: This sets %1 to 66, %2 to DIR, %3 to B:, and %4 to nothing, resulting in the following set of commands: PROMPT $E[0;66;"DIR B:";13p .....(missing text) appear on the command line and displays the directory. By selecting extended keyboard numbers from Figure 2, you can define keys to activate your most-used commands. Note that the number of batch parameters you want the redefined key to accept is equal to the number of items (separated by blanks) within the quotation marks. For example, the batch file above can't be used to define a key that accepts four parameters. To do that, the command is: PROMPT $E[0;%1;"%2 %3 %4 %5";13p because the %1 parameter selects the key to be redefined. You can even go all out and try: PROMPT $e[0;%1;"%2 %3 %4 %5 %6 %7 %8 %9";13p but since the parameters of %2 through %9 must be separated by blanks (to preserve the spacing in the key reassignment sequence) this command adds unnecessary characters to key definitions that have less than eight parameters. Because there's a zero after the left bracket, this batch file can only reassign keys with extended keyboard numbers. Another batch file without the zero and first semicolon would handle definitions for regular ASCII codes. Without the semicolon followed by the number 13 in the PROMPT statement, the cursor will stop after typing DIR A: and wait for more input or the Enter key. The `;13' sequence puts in the carriage return. If you prefer the option of adding something to the line, they leave out the carriage return (but don't leave out the final lowercase p). If you want the function key to deliver several commands, separate each of them by a semicolon, a `13', and another semicolon. The sequence inserts carriage returns between the commands. You can put your favorite keyboard reassignments in an AUTO- EXEC.BAT file to be set during the system boot. Each redefinition requires one PROMPT command. After all the key redefinitions are done, a final PROMPT command or the name of another batch file can set the display prompt. You also can set up batch files to define particular keys for special functions, but with a parameter to define a filename. For instance, an assembly language programmer may want to define function keys that assemble, link, run an EXE2BIN utility, and then load DEBUG -- with the same program name. A batch file to do this reassignment (named QUICKASM.BAT) can be: PROMPT $E[0;65;"MASM %1";13p PROMPT $E[0;66;"LINK %1";13p PROMPT $E[0;67;"EXE2BIN %1;%1.COM";13p PROMPT $E[0;68;"DEBUG %1.COM";13p Then, using the command: QUICKASM you can assemble the program by pressing the F7 key, link it with the F8 key, change it to a .COM file with the F9 key, and load it into DEBUG with the F10 key. Not all programs get keyboard information from the standard DOS function calls. Also, ANSI.SYS reserves only 200 bytes for the storage of keyboard reassignments -- when your system crashes you know you've defined one key too many. However, you can use DEBUG to patch the ANSI.SYS file to allow more than 200 bytes of keyboard reassignments. Figure 1: PROMPT metastrings. MetaString Definition Special Characters ----------- ----------------------------- $B The ":" character $G The ">" character $L The "<" character $Q The "=" character $$ The "$" character System Information ------------------ $D The date (14 characters: 3 character day-of-week, blank, 2 character month, dash, 2 character day, dash, 4 character year) $T The time (11 characters: 2 digit hour, colon, 2 digit minutes, colon, 2 digit seconds, point, 2 digit hundredths-of-seconds) $N The default drive (1 character) $P The current directory path of the default drive (begins with default drive, colon, then a maximum of 63 characters of the path from the root to the current directory) $V The version number (currently prints 39 characters) Cursor Control -------------- $H Backspace & erasure of the previous character $_ A carriage return and linefeed sequence Other ASCII characters ---------------------- $E The ASCII Escape character $X A null string (where X is anything not used above) Figure 2: Screen Control Sequence. Control String Definition -------------- ---------- $E[s SCP (save cursor position for a future RCP sequence) $E[u RCP (restore cursor position from a previous SCP sequence) $E[#;#H CUP (cursor position: sets cursor to the row and column substituted for the 1st and 2nd #, respectively) $E[#A CUU (cursor up # positions) $E[#B CUD (cursor down # positions) $E[#C CUF (cursor forward # positions) $E[#D CUB (cursor backward # positions) $E[2J ED (erases whole display and homes cursor to upper righthand corner) $E[K EL (erases from cursor to end of line) $E[#;...#m SGR (set graphics rendition, e.g., $E[7m will turn on reverse video; $e[0m will go back to normal) $E[0;#;"s";13p Reassign extended ASCII keyboard key # to the command string "s" followed by carriage return) Figure 3: Extended Keyboard Numbers for F7-F10. Function Extended Keyboard Number Key Base Shift Ctrl Alt -------- --------------------------------- F1 (59) 84 94 104 F2 (60) 85 95 105 F3 (61) 86 96 106 F4 (62) 87 97 107 F5 (63) 88 98 108 F6 (64) 89 99 109 F7 65 90 100 110 F8 66 91 101 111 F9 67 92 102 112 F10 68 93 103 113 ( ): Used for DOS line editing Top row of Extended Keyboard Number keyboard in combination with ALT ---------- ------------------------ 1 120 2 121 3 122 4 123 5 124 6 125 7 126 8 127 9 128 0 129 - 130 = 131 Letter Extended Keyboard Letter Extended Keyboard Key Number with ALT Key Number with ALT ------ ----------------- ------ ----------------- A 30 N 49 B 48 O 24 C 46 P 25 D 32 Q 16 E 18 R 19 F 33 S 31 G 34 T 20 H 35 U 22 I 23 V 47 J 36 W 17 K 37 X 45 L 38 Y 21 M 50 Z 44 ----------------------------------------------------------------- Prompt Solution (PC Magazine Vol 4 No 10 May 14, 1985 PC Tutor) In using the IBM AT, I found that in order to remove a subdirectory the files contained in a subdirectory must first be erased. My first, and last, attempt caused all of the DOS files to be erased. The command I used was either ERASE .. or ERASE *.*. This brings me to another point: what do .(DIR) and ..(DIR) mean when they appear in a directory listing? Response: It sounds as if ERASE .. was what you typed. To see what that does, you need to know what the . and .. subdirectories are. By convention, the . subdirectory is the current subdirectory. The .. subdirectory is the "parent" subdirectory. For example, if your current directory is \DOS\UTIL\SYS, then the . subdirectory is just \DOS\UTIL\SYS. In this case, the .. subdirectory is \DOS\UTIL. Thus, when you typed in ERASE .., it erased all files in the parent, which, in your case, contained all your DOS files. To erase all of the files in the subdirectory you currently occupy, you can type either: ERASE *.* or ERASE . (note the single .) Given the confusion inherent in the second command, I would suggest using *.* exclusively. In fact, there is an even safer approach which is to name the subdirectory explicitly. For example, suppose I want to erase all files in \DOS\UTIL\SYS. Type: ERASE \DOS\UTIL\SYS This procedure works from any current directory, and it removes all possible ambiguity. One of the problems of using subdirectories is that it is very easy to lose your way and not know which directory you are currently in. The simplest approach is just to type: A>CD This will put the name of your current subdirectry on the screen. A more complex approach, but one often used, is to include the subdirectory name within the DOS prompt itself. That way you're never in doubt. With DOS 2.x you can create a custom prompt that can be quite complex. The prompt can contain any of the items: the time ($t) the date ($d) the current directory ($p) the version ($v) the default drive ($n) a backspace ($h) > character ($g) < character ($1) | character ($b) = character ($q) CR/LF sequence ($_) any string To make up the prompt you want, just issue the PROMPT command followed by any arbitrary string you want printed including, if you want, some of the special symbols listed above. (For the last, you type in the characters within the parentheses.) For example, the DOS default prompt you're used to would be entered as PROMPT $n$g if you had to create it. Issuing the command: PROMPT $p$_$n$g gives you a two-line prompt that shows the current drive and subdirectory on the first line and the usual drive:> on the second. I sometimes use the following prompt command: PROMPT $pTime...$t$h$h$h$h$h$h$_$g This prints the name of the current directory, a few tabs (you just hit the tab key where you see above), then the string "Time ..." followed by the time of day. The $h backspaces and erases the seconds, which would be more information that I want. Finally, the $_$g produces a new line with a > sign on it. This is handy for project billing since a screen printout clearly shows me what application is being run and how long I have spent running it. I think you'll find that it is both fun and instructive to experiment with the PROMPT command. If you decide you want to use a customized prompt regularly, however, you must make the PROMPT command sequence a part of your AUTOEXEC.BAT file since otherwise DOS will go back to its normal default prompt each time you boot.