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   
Text File  |  1985-07-08  |  22KB  |  462 lines

  1.                   ANSI.SYS
  2.                   ~~~~~~~~
  3. What is a Device Driver ?
  4.  
  5.   Basically, a Device Driver is a special software program used to manage
  6. all communications between a device (usually hardware) and the PC.  It's
  7. helpful to think of a device driver as a "logical" device.  To the operating
  8. system, this driver is the device.  DOS never "sees" the actual device, but
  9. accesses the actual device through the driver.    In other words, the device
  10. driver is an interface.  DOS has several "built-in" device drivers that
  11. handle such things as the diskette drives, system clock, the console (key-
  12. board and display), printer (parallel port) and communications (serial
  13. port).
  14.  
  15.   There are two (2) types of devices, character and block.  Character
  16. devices handle I/O in a serial manner like CON, AUX, CLOCK$ and PRN.
  17. Character devices can be "opened" to do input and/or output since they have
  18. only one name and handle only one physical device.
  19.  
  20.   On the other hand, block devices are the hard disk and diskette drives in
  21. a system and do random I/O in pieces called blocks (usually the sector size
  22. of a disk).  These devices are not named like the character devices, rather
  23. they are "mapped" alphabetically by drive letter.  Block devices can handle
  24. several physical units.  So a single device driver can be responsible for
  25. I/O to several diskette drives and/or hard disks.
  26.  
  27. The CONFIG.SYS file
  28.  
  29.   One of the first things things to happen when you "boot" your computer, is
  30. that the operating system looks for special information about how it is to
  31. configure itself.  It expects to find those directions in a text file on the
  32. boot disk called CONFIG.SYS.  If DOS can't find a CONFIG.SYS file, it sets
  33. itself up in a "default" configuration.  Think of CONFIG.SYS as containing
  34. the first directions you give to DOS.  Among other things, those directions
  35. may include the names of foreign (non IBM) devices that are to be added to
  36. the system.  When you add a device to the computer that is non IBM, (and
  37. even some that are IBM), you will need a matching software device driver so
  38. that it can be integrated into the system.  A typical CONFIG.SYS file might
  39. look like this.
  40.  
  41.                Sample CONFIG.SYS file
  42.               -----------------------
  43.              | DEVICE = MOUSE.SYS     |
  44.              | DEVICE = CLOCK.SYS     |
  45.              | DEVICE = HARDDISK.SYS |
  46.              | DEVICE = RAMDISK.SYS  |
  47.               -----------------------
  48.  
  49.   The sample file tells DOS to install character (mouse and clock-calendar)
  50. and block (a hard disk and a ram disk) devices.  Notice that the ram disk is
  51. entirely software.  No hardware is involved.  This is one of the very useful
  52. feature of device drivers.  To install a new or replacement device in your
  53. computer system, one of the steps will include adding a line to the
  54. CONFIG.SYS file.
  55.  
  56.  
  57. ANSI.SYS - A CONsole device driver
  58.  
  59.   The ANSI.SYS driver gets its name from the American National Standards
  60. Institute (ANSI), which defined a standard method for control of certain
  61. terminal characteristics.  The effort at standardization was a reaction to
  62. the many types of intelligent terminals being manufactured.  Unfortunately,
  63. ANSI.SYS was not entirely successful: manufacturers having different goals
  64. than the committee.  In fact, no terminals are ANSI standard, although the
  65. DEC VT-100 comes quite close.
  66.  
  67.   The central concern of the committee was to define codes in addition to
  68. the standard ASCII control codes that could be use to govern terminal
  69. characteristics such as cursor and character positioning, character high-
  70. lighting and character color.
  71.  
  72.   You may know, ASCII is a code that provides for the translation of the
  73. standard alphanumeric characters into a binary form for storage and manipu-
  74. lation by the computer.  Using binary notation, 7-bits can represent any of
  75. 128 different values (2 to the 7th) which is more than ample for encoding
  76. the 96 standard alphanumeric characters and a few punctuation symbols.    The
  77. standard ASCII codes (as opposed to the extended IBM set of 256) also
  78. include 32 "control characters" (i.e. carriage return, tab, line feed, etc).
  79.  
  80.   Control characters generally provide "commands" (as opposed to data) to
  81. peripheral devices.  For example, a line feed tells a display to move the
  82. cursor down 1 line.  But 32 characters allow only a total of 32 possible
  83. commands, rather limited.  What the ANSI committee attempted was to provide
  84. a standard syntax which would allow a greatly increased number of control
  85. codes for terminals.  The method they arrived at was to select a single
  86. ASCII character, which when detected by the terminal, would indicate that
  87. the next sequence of characters was a command, not data for display.  This
  88. simple decision made possible many more than the original 32 control codes
  89. for issuing commands to intelligent terminals.    You probably guessed that
  90. the ASCII character they picked was ASCII 27, commonly known as "escape".
  91.  
  92.   All of which brings us back to ANSI.SYS, a subset of the coding language
  93. established by the committee.  To use it, you must install it as a device
  94. driver by adding the following line to the CONFIG.SYS file.
  95.  
  96.                  DEVICE = ANSI.SYS
  97.  
  98. When listed in the CONFIG.SYS file, ANSI.SYS replaces the CONsole handler
  99. that DOS uses by default.  Its installation gives you added control over the
  100. keyboard and display.
  101.  
  102.  
  103.   Now.    As previously mentioned, the leading character of all "control
  104. sequences" is ESCape.  Unfortunately, it's not possible to enter an ASCII 27
  105. from the keyboard.  If you do, DOS simply cancels the current line.  But,
  106. one of the DOS commands, PROMPT, does allow the sending of <ESC>, as part of
  107. a text string, to the console display.    It turns out that one of the easiest
  108. ways to send commands to ANSI.SYS is by using the PROMPT command.  The
  109. syntax for PROMPT is:
  110.                 PROMPT [prompt-text]
  111.  
  112.   Since the ANSI standard was deliberately designed to be as open-ended as
  113. possible, a second leading character is used to define each particular
  114. subset.  On the IBM PC, that character is the left bracket "[".  Therefore
  115. each of our control sequences begin with "ESCape [".  The characters used by
  116. PROMPT to indicate ESCape are "$e", making the beginning of each PROMPT
  117. command look like this.
  118.                    PROMPT $e[ ...
  119.  
  120. After these two "lead-in" characters, are the parameters of the ANSI com-
  121. mand, then the character that identifies the command.  The syntax is:
  122.  
  123.          PROMPT $e[<parameter>;...;<parameter><identifier>
  124.  
  125. Cursor Control
  126.  
  127.   As an example, let's prepare a command for moving the cursor.  There are a
  128. total of 10 control sequences that can be used for controlling the cursor,
  129. but 2 of them are functionally identical.  They are CUP (CUrsor Position)
  130. and HVP (Horizontal Vertical Position).  We'll use HVP for this example.
  131. The syntax we want is:
  132.              PROMPT $e[<row>;<column>f
  133.  
  134. If you chose to move the cursor to the beginning of the last line of the
  135. screen, (row 25, column 1), the command would read:
  136.  
  137.                   PROMPT $e[25;1f
  138.  
  139.   If you type this command and press <enter>, you will see the cursor (a
  140. flashing underline) at the beginning of the last line on your screen.  The
  141. normal DOS drive letter prompt has disappeared.  What has happened is that
  142. you've changed the standard A> prompt to an abstract prompt which consists
  143. of an escape sequence.    So every time DOS tries to display the prompt, it is
  144. intercepted by ANSI.SYS.  It never makes it to the display.  If you wish to
  145. have your old DOS prompt back, just type the word PROMPT and press <enter>.
  146. That causes DOS to revert to the default system prompt.
  147.  
  148.  
  149.   The cursor control sequences may be divided into the following groups.
  150.  
  151.                   Cursor Movement
  152.       -------------------------------------------------------
  153.      | CUU - CUrsor Up    - PROMPT $e[<number of rows>A     |
  154.      | CUD - CUrsor Down    - PROMPT $e[<number of rows>B     |
  155.      | CUF - CUrsor Forward - PROMPT $e[<number of columns>C |
  156.      | CUB - CUrsor Back    - PROMPT $e[<number of columns>D |
  157.       -------------------------------------------------------
  158.  
  159.             Find Current Cursor Position
  160.      ----------------------------------------------------------
  161.     | DSR - Device Status Report   - PROMPT $e[6n           |
  162.     | CPR - Cursor Position Report - PROMPT $e[<row>;<column>R |
  163.      ----------------------------------------------------------
  164.        DSR is your query of the device - CPR is the response
  165.  
  166.                  Cursor Positioning
  167.      ------------------------------------------------------------------
  168.     | CUP - CUrsor Position           - PROMPT $e[<row>;<column>H |
  169.     | HVP - Horizontal & Vertical Position - PROMPT $e[<row>;<column;f |
  170.     | SCP - Save Cursor Position       - PROMPT $e[s           |
  171.     | RCP - Restore Cursor Position       - PROMPT $e[u           |
  172.      ------------------------------------------------------------------
  173.  
  174.                   Erasing
  175.           ---------------------------------------
  176.          | ED  - Erase in Display - PROMPT $e[2J |
  177.          | EL  - Erase in Line      - PROMPT $e[k  |
  178.           ---------------------------------------
  179.  
  180. With this range of commands at your disposal, you have a lot of power over
  181. the curser, enough to build a rudimentary text editor, but the exploration
  182. of each is up to you.
  183.  
  184.  
  185. Mode Control
  186.  
  187.   Another feature of ANSI.SYS is the ability to control the mode used for
  188. display, including screen width, color, intensity and word wrap.  For
  189. example, if you wish to set the display to a 40 column screen width using a
  190. black and white display attribute, you would use the Set Mode control
  191. sequence.  Here is the list of possible display modes.
  192.  
  193.              Setting the Display Modes
  194.            ---------------------------------------------
  195.           |  SM  - Set Mode   - PROMPT $e[=<parameter>h |
  196.           |  RM  - Reset Mode - PROMPT $e[=<parameter>l |
  197.            ---------------------------------------------
  198.            |           parameter list           |
  199.            |           ~~~~~~~~~~~~~~           |
  200.            | 0      -    40x25 black and white   |\
  201.            | 1      -    40x25 color           | \  Text
  202.            | 2      -    80x25 black and white   | / Screens
  203.            | 3      -    80x25 color           |/
  204.            | 4      -    320x200 color           |\
  205.            | 5      -    320x200 black and white | > Graphic
  206.            | 6      -    640x200 black and white |/  Screens
  207.            | 7      -    if SM, word wrap is on  |
  208.            |           if RM, word wrap is off |
  209.             -----------------------------------
  210.  
  211. Using the example of a 40 column black and white display, the code sequence
  212. would be:
  213.                 PROMPT $e[=0
  214.  
  215. If you want to change that to a color display with 80 columns, the sequence
  216. becomes:
  217.                 PROMPT $e[=3
  218.  
  219.  
  220.   Now that the console is set for the display of color, a control sequence
  221. is needed to set the color and intensity.
  222.  
  223.             Setting Color and Intensity
  224.   -----------------------------------------------------------------------
  225.  | SGR - Set Graphics Rendition - PROMPT $e[<parameter>;...;<parameter>m |
  226.   -----------------------------------------------------------------------
  227.          |               parameter list             |
  228.          |               ~~~~~~~~~~~~~~             |
  229.          | 0    -     normal attributes (default display) |
  230.          | 1    -     bold on (high intensity)         |
  231.          | 4    -     underline on (monochrome only)      |
  232.          | 5    -     blink on                 |
  233.          | 7    -     reverse video on             |
  234.          | 8    -     canceled on (invisible)         |
  235.          | 30   -     black characters             |
  236.          | 31   -     red characters              |
  237.          | 32   -     green characters             |
  238.          | 33   -     yellow characters             |
  239.          | 34   -     blue characters             |
  240.          | 35   -     magenta characters             |
  241.          | 36   -     cyan characters             |
  242.          | 37   -     white characters             |
  243.          | 40   -     black background             |
  244.          | 41   -     red background              |
  245.          | 42   -     green background             |
  246.          | 43   -     yellow background             |
  247.          | 44   -     blue background             |
  248.          | 45   -     magenta background             |
  249.          | 46   -     cyan background             |
  250.          | 47   -     white background             |
  251.           -----------------------------------------------
  252.  
  253. To set the display to a blue background with red characters displayed in
  254. high intensity, the control sequence would be:
  255.  
  256.                  PROMPT $e[44;31;1m
  257.  
  258. or for blue characters on a light yellow background:
  259.  
  260.                  PROMPT $e[34;43;7m
  261.  
  262.   That is the range of control sequences available for control of the
  263. display screen while using ANSI.SYS.  Not unlimited to be sure, but it does
  264. increase the user's control over the way things are displayed.  In fact here
  265. is a sample batch file called COLOR.BAT that let's you easily change the
  266. color of the characters bring displayed on your screen.  The syntax for its
  267. use is:
  268.                 COLOR <your choice>
  269.  
  270.  
  271.                  COLOR.BAT
  272.               --------------------------------
  273.              | if %1 == red prompt $e[31m     |
  274.              | if %1 == green prompt $e[32m   |
  275.              | if %1 == yellow prompt $e[33m  |
  276.              | if %1 == blue prompt $e[34m    |
  277.              | if %1 == magenta prompt $e[35m |
  278.              | if %1 == cyan prompt $e[36m    |
  279.              | if %1 == white prompt $e[37m   |
  280.              | prompt                  |
  281.               --------------------------------
  282.  
  283. Redefining the Keyboard
  284.  
  285.   One of the most popular types of software on the market allows the user to
  286. redefine the keyboard and/or assign strings of characters to single key
  287. strokes.  What many do not know is that by using the ANSI.SYS device driver
  288. these features are already available.  If want to rearrange the keyboard to
  289. a "davork" layout, (as opposed to qwerty) you can use ANSI.SYS to do it.  If
  290. you would rather press <Crtl-Home> to clear the screen (like you do while
  291. using BASIC) than typing out CLS and pressing <enter>, you can do that too.
  292. Or maybe you'd like to spell out the word "Bloomington" by typing <Alt-B>.
  293. The keyboard redefinition features of ANSI.SYS are very powerful.  Here is
  294. the basic control sequence you need for keyboard redefinition.
  295.  
  296.             PROMPT $e[<number>;<number>p
  297.  
  298. The 2 numbers stand for, respectively, the ASCII value of the character you
  299. want replaced and the ASCII value of the new character.  For instance, if
  300. you want a "B" to display every time you press "A", the code sequence would
  301. be:
  302.                   PROMPT $e[65;66p
  303.  
  304. "A" is ASCII 65 and "B" is ASCII 66.  After executing this command, whenever
  305. you type "A", you'll see "B" displayed.  By building yourself a batch file
  306. containing the necessary control sequences, you can use this method to
  307. convert your keyboard to the "davork" layout.  You can even physically move
  308. the keytops if you want.
  309.  
  310.   Another form of the control sequence allows a single keystroke to generate
  311. a string of characters.  It looks like this.
  312.  
  313.             PROMPT $e[<number>;"string"p
  314.  
  315. When the command is received, the key that represents the ASCII value of
  316. <number> will generate whatever string appears between the two quote marks.
  317. For instance, the control sequence,
  318.  
  319.                PROMPT $e[122;"zebra"p
  320.  
  321. will cause the "z" key to be replaced by the word "zebra".
  322.  
  323.  
  324.   A more useful feature of key board redefinition is accomplished with yet
  325. another form of the control sequence.
  326.  
  327.         PROMPT $e[0;<number>;"string";...<number or string>p
  328.  
  329. This is the really powerful version that allows the assigning of strings so
  330. that complex commands (or tasks) can be executed using single keystrokes.
  331. For instance, I might want to redefine the function keys to perform common
  332. DOS commands.  The batch file for reassignment might look like this.
  333.  
  334.                 FKEY-NEW.BAT
  335.               --------------------------------
  336.              | prompt $e[0;59;"dir a:/p";13p  |
  337.              | prompt $e[0;60;"dir b:/p";13p  |
  338.              | prompt $e[0;61;"basica";13p    |
  339.              | prompt $e[0;62;"copy "p        |
  340.              | prompt $e[0;63;"cls";13p       |
  341.              | prompt $e[0;64;"format b:"p    |
  342.              | prompt $e[0;65;"chkdsk "p      |
  343.              | prompt $e[0;66;"mode co80";13p |
  344.              | prompt $e[0;67;"debug";13p     |
  345.              | prompt $e[0;68;"del "p         |
  346.              | prompt                  |
  347.               --------------------------------
  348.  
  349. Of course, you may prefer to assign different functions to the function
  350. keys, so your batch file would have different strings for each key.  Notice
  351. that in several definitions "13" was added before the identifier "p".
  352. That's the ASCII value for carriage return and causes the command to execute
  353. automatically when the respective function key is pressed.  But there are
  354. times when that's not desirable.  For example, when using the CHKDSK com-
  355. mand, it may be necessary to specify a different drive or include one of the
  356. parameters.  In such a case, pressing the F7 key displays only "chkdsk"
  357. followed by a space. It's up to the user to complete and execute the
  358. command.
  359.  
  360.   It is possible to assign more than one string to each function key.  Since
  361. most keys produce a different value (scan code) when pressed in combination
  362. with either <shift> key, the <Alt> key or the <Ctrl> key, different strings
  363. may be assigned to each combination.  That allows 4 strings to be assigned
  364. to each function key giving a total of 40 strings just for the function
  365. keys.
  366.  
  367.  
  368.   While most may think of only the function keys for string assignment,
  369. other possibilities exist.  Assignment of string to the standard alpha-
  370. numeric keys (letters and numbers) pressed in combination with the <Alt> key
  371. is acceptable.    This allows us to retain the combination of letter keys and
  372. <Ctrl> key for use in imbedding printer control codes in our files, and the
  373. original values of the unshifted and shifted keys.  If a application program
  374. assigns meaning to the function keys, the only remaining choice may be to
  375. use the <Alt> key in combination with the alphanumerics for string assign
  376. ment.  For instance, the control sequence needed to cause the <ALT-d>
  377. combination to display the directory of th current drive would be:
  378.  
  379.               PROMPT $e[0;32;"dir";13p
  380.  
  381.   To make it easier for you to assign strings and/or commands to specific
  382. keys, the next page has a table of the numbers (scan codes) for each key
  383. that you are likely to want to redefine or assign strings and/or commands
  384. to.
  385.  
  386.   When you first look at the table, you will notice that there seem to be
  387. several codes that are generated by more than one key stroke combination.
  388. Not so!  All of the function keys (alone or in combination with the <shift>,
  389. <Ctrl> and <Alt> keys) and the alphanumeric keys (in combination with the
  390. <Alt> key) generate an extended code.  Since there are more key stroke
  391. combinations than there are ASCII codes, something had to be done to allow
  392. the computer to recognize the extra combinations.  The solution was to have
  393. the addition combinations produce an extended code.  These codes consist of
  394. two values instead of one.  The first value is always a null (ASCII 00) and
  395. indicates to the computers CONsole driver that a special key has been
  396. pressed.  (Remember the leading zero in the above PROMPT string?)  The
  397. second value is then used to identify the particular key (or combination of
  398. keys) that was pressed.  Although the codes in the table may at first seem
  399. to be duplications, they are not.
  400.  
  401.   Hopefully this discussion of ANSI.SYS will help you integrate its use into
  402. your computing in order to simplify the execution of routine tasks.
  403.  
  404.  
  405.                          by Michael L Hoyt, 5 jul 85
  406.  
  407.  
  408.          Table of Keyboard Extended Function Codes
  409.           -----------------------------------------------
  410.          | Key    Normal      <Shift>   <Ctrl>     <Alt> |
  411.          |    F1      59        84          94    104  |
  412.        F     |    F2      60        85          95    105  |
  413.        U     |    F3      61        86          96    106  |
  414.        N  K  |    F4      62        87          97    107  |
  415.        C  E  |    F5      63        88          98    108  |
  416.        T  Y  |    F6      64        89          99    109  |
  417.        I  S  |    F7      65        90          100    110  |
  418.        O     |    F8      66        91          101    111  |
  419.        N     |    F9      67        92          102    112  |
  420.          |    F10      68        93          103    113  |
  421.          |===============================================|
  422.          |    1      49        33           *    120  |
  423.          |    2      50        64          00    121  |
  424.        N     |    3      51        35           *    122  |
  425.        U  K  |    4      52        36           *    123  |
  426.        M  E  |    5      53        37           *    124  |
  427.        B  Y  |    6      54        94          30    125  |
  428.        E  S  |    7      55        38           *    126  |
  429.        R     |    8      56        42           *    127  |
  430.          |    9      57        40           *    128  |
  431.          |    0      48        41           *    129  |
  432.          |===============================================|
  433.          |    A      97        65          01    30   |
  434.          |    B      98        66          02    48   |
  435.          |    C      99        67          03    46   |
  436.          |    D      100        68          04    32   |
  437.          |    E      101        69          05    18   |
  438.          |    F      102        70          06    33   |
  439.          |    G      103        71          07    34   |
  440.          |    H      104        72          08    35   |
  441.          |    I      105        73          09    23   |
  442.        L     |    J      106        74          10    36   |
  443.        E  K  |    K      107        75          11    37   |
  444.        T  E  |    L      108        76          12    38   |
  445.        T  Y  |    M      109        77          13    50   |
  446.        E  S  |    N      110        78          14    49   |
  447.        R     |    O      111        79          15    24   |
  448.          |    P      112        80          16    25   |
  449.          |    Q      113        81          17    16   |
  450.          |    R      114        82          18    19   |
  451.          |    S      115        83          19    31   |
  452.          |    T      116        84          20    20   |
  453.          |    U      117        85          21    22   |
  454.          |    V      118        86          22    47   |
  455.          |    W      119        87          23    17   |
  456.          |    X      120        88          24    45   |
  457.          |    Y      121        89          25    21   |
  458.          |    Z      122        90          26    44   |
  459.           -----------------------------------------------
  460.     If *, code is trapped by keyboard routine and not displayed.
  461.  
  462.