ASCII CODES INCLUDING ESCAPE SEQUENCE

SOURCE: http://paulbourke.net/dataformats/ascii/

ASCII codes

Compiled by Paul Bourke
August 1995

Decimal   Hex     Oct      Usage                  Control
----------------------------------------------------------------------------
   0       0       0       NUL (Null)             @
   1       1       1       SOH                    A
   2       2       2       STX                    B
   3       3       3       ETX                    C
   4       4       4       EQT                    D
   5       5       5       ENQ (Answerback)       E
   6       6       6       ACK                    F
   7       7       7       BEL (Bell)             G
   8       8      10       BS  (Backspace)        H
   9       9      11       HT  (Tab)              I
  10       a      12       LF  (Linefeed)         J
  11       b      13       VT                     K
  12       c      14       FF                     L
  13       d      15       CR  (Carriage Return)  M
  14       e      16       SO                     N
  15       f      17       SI                     O
  16      10      20       DLE                    P
  17      11      21       DC1 (Xon)              Q
  18      12      22       DC2                    R
  19      13      23       DC3 (Xoff)             S
  20      14      24       DC4                    T
  21      15      25       NAK                    U
  22      16      26       SYN                    V
  23      17      27       ETB                    W
  24      18      30       CAN (Cancel)           X
  25      19      31       EM                     Y
  26      1a      32       SUB                    Z
  27      1b      33       ESC (Escape)           [
  28      1c      34       FS                     \
  29      1d      35       GS                     ]
  30      1e      36       RS                     ~
  31      1f      37       US                     ?
  32      20      40       Space
  33      21      41       !
  34      22      42       "
  35      23      43       #
  36      24      44       $
  37      25      45       %
  38      26      46       &
  39      27      47       '
  40      28      50       (
  41      29      51       )
  42      2a      52       *
  43      2b      53       +
  44      2c      54       ,
  45      2d      55       -
  46      2e      56       .
  47      2f      57       /
  48      30      60       0
  49      31      61       1
  50      32      62       2
  51      33      63       3
  52      34      64       4
  53      35      65       5
  54      36      66       6
  55      37      67       7
  56      38      70       8
  57      39      71       9
  58      3a      72       :
  59      3b      73       ;
  60      3c      74       <
  61      3d      75       =
  62      3e      76       >
  63      3f      77       ?
  64      40     100       @
  65      41     101       A
  66      42     102       B
  67      43     103       C
  68      44     104       D
  69      45     105       E
  70      46     106       F
  71      47     107       G
  72      48     110       H
  73      49     111       I
  74      4a     112       J
  75      4b     113       K
  76      4c     114       L
  77      4d     115       M
  78      4e     116       N
  79      4f     117       O
  80      50     120       P
  81      51     121       Q
  82      52     122       R
  83      53     123       S
  84      54     124       T
  85      55     125       U
  86      56     126       V
  87      57     127       W
  88      58     130       X
  89      59     131       Y
  90      5a     132       Z
  91      5b     133       [
  92      5c     134       \
  93      5d     135       ]
  94      5e     136       ^
  95      5f     137       _
  96      60     140       `
  97      61     141       a
  98      62     142       b
  99      63     143       c
 100      64     144       d
 101      65     145       e
 102      66     146       f
 103      67     147       g
 104      68     150       h
 105      69     151       i
 106      6a     152       j
 107      6b     153       k
 108      6c     154       l
 109      6d     155       m
 110      6e     156       n
 111      6f     157       o
 112      70     160       p
 113      71     161       q
 114      72     162       r
 115      73     163       s
 116      74     164       t
 117      75     165       u
 118      76     166       v
 119      77     167       w
 120      78     170       x
 121      79     171       y
 122      7a     172       z
 123      7b     173       {
 124      7c     174       |
 125      7d     175       }
 126      7e     176       ~
 127      7f     177       DEL (Delete)

 

Latin 1 character set

The following is the “official” Latin I Character set. In particular, these characters can be included in HTML documents by enclosing them as &#__;. For precise details view the source of this file.

 32             160         Non-breaking space
 33    !        161    ¡    Inverted exclamation
 34    "        162    ¢    Cent sign
 35    #        163    £    Pound sterling
 36    $        164    ¤    General currency sign
 37    %        165    ¥    Yen sign
 38    &        166    ¦    Broken vertical bar
 39    '        167    §    Section sign
 40    (        168    ¨    Umlaut (dieresis)
 41    )        169    ©    Copyright
 42    *        170    ª    Feminine ordinal
 43    +        171    «    Left angle quote, guillemotleft
 44    ,        172    ¬    Not sign
 45    -        173    ­    Soft hyphen
 46    .        174    ®    Registered trademark
 47    /        175    ¯    Macron accent
 48    0        176    °    Degree sign
 49    1        177    ±    Plus or minus
 50    2        178    ²    Superscript two
 51    3        179    ³    Superscript three
 52    4        180    ´    Acute accent
 53    5        181    µ    Micro sign
 54    6        182    ¶    Paragraph sign
 55    7        183    ·    Middle dot
 56    8        184    ¸    Cedilla
 57    9        185    ¹    Superscript one
 58    :        186    º    Masculine ordinal
 59    ;        187    »    Right angle quote, guillemotright
 60    <        188    ¼    Fraction one-fourth
 61    =        189    ½    Fraction one-half
 62    >        190    ¾    Fraction three-fourths
 63    ?        191    ¿    Inverted question mark
 64    @        192    À    Capital A, grave accent ("&Agrave;")
 65    A        193    Á    Capital A, acute accent ("&Aacute;")
 66    B        194    Â    Capital A, circumflex accent ("&Acirc;")
 67    C        195    Ã    Capital A, tilde ("&Atilde;")
 68    D        196    Ä    Capital A, dieresis or umlaut mark ("&Auml;")
 69    E        197    Å    Capital A, ring ("&Aring;")
 70    F        198    Æ    Capital AE dipthong (ligature) ("&AElig;")
 71    G        199    Ç    Capital C, cedilla ("&Ccedil;")
 72    H        200    È    Capital E, grave accent ("&Egrave;")
 73    I        201    É    Capital E, acute accent ("&Eacute;")
 74    J        202    Ê    Capital E, circumflex accent ("&Ecirc;")
 75    K        203    Ë    Capital E, dieresis or umlaut mark ("&Euml;")
 76    L        204    Ì    Capital I, grave accent ("&Igrave;")
 77    M        205    Í    Capital I, acute accent ("&Iacute;")
 78    N        206    Î    Capital I, circumflex accent ("&Icirc;")
 79    O        207    Ï    Capital I, dieresis or umlaut mark ("&Iuml;")
 80    P        208    Ð    Capital Eth, Icelandic ("&ETH;")
 81    Q        209    Ñ    Capital N, tilde ("&Ntilde;")
 82    R        210    Ò    Capital O, grave accent ("&Ograve;")
 83    S        211    Ó    Capital O, acute accent ("&Oacute;")
 84    T        212    Ô    Capital O, circumflex accent ("&Ocirc;")
 85    U        213    Õ    Capital O, tilde ("&Otilde;")
 86    V        214    Ö    Capital O, dieresis or umlaut mark ("&Ouml;")
 87    W        215    ×    Multiply sign
 88    X        216    Ø    Capital O, slash ("&Oslash;")
 89    Y        217    Ù    Capital U, grave accent ("&Ugrave;")
 90    Z        218    Ú    Capital U, acute accent ("&Uacute;")
 91    [        219    Û    Capital U, circumflex accent ("&Ucirc;")
 92    \        220    Ü    Capital U, dieresis or umlaut mark ("&Uuml;")
 93    ]        221    Ý    Capital Y, acute accent ("&Yacute;")
 94    ^        222    Þ    Capital THORN, Icelandic ("&THORN;")
 95    _        223    ß    Small sharp s, German (sz ligature) ("&szlig;")
 96    `        224    à    Small a, grave accent ("&agrave;")
 97    a        225    á    Small a, acute accent ("&aacute;")
 98    b        226    â    Small a, circumflex accent ("&acirc;")
 99    c        227    ã    Small a, tilde ("&atilde;")
100    d        228    ä    Small a, dieresis or umlaut mark ("&auml;")
101    e        229    å    Small a, ring ("&aring;")
102    f        230    æ    Small ae dipthong (ligature) ("&aelig;")
103    g        231    ç    Small c, cedilla ("&ccedil;")
104    h        232    è    Small e, grave accent ("&egrave;")
105    i        233    é    Small e, acute accent ("&eacute;")
106    j        234    ê    Small e, circumflex accent ("&ecirc;")
107    k        235    ë    Small e, dieresis or umlaut mark ("&euml;")
108    l        236    ì    Small i, grave accent ("&igrave;")
109    m        237    í    Small i, acute accent ("&iacute;")
110    n        238    î    Small i, circumflex accent ("&icirc;")
111    o        239    ï    Small i, dieresis or umlaut mark ("&iuml;")
112    p        240    ð    Small eth, Icelandic ("&eth;")
113    q        241    ñ    Small n, tilde ("&ntilde;")
114    r        242    ò    Small o, grave accent ("&ograve;")
115    s        243    ó    Small o, acute accent ("&oacute;")
116    t        244    ô    Small o, circumflex accent ("&ocirc;")
117    u        245    õ    Small o, tilde ("&otilde;")
118    v        246    ö    Small o, dieresis or umlaut mark ("&ouml;")
119    w        247    ÷    Division sign
120    x        248    ø    Small o, slash ("&oslash;")
121    y        249    ù    Small u, grave accent ("&ugrave;")
122    z        250    ú    Small u, acute accent ("&uacute;")
123    {        251    û    Small u, circumflex accent ("&ucirc;")
124    |        252    ü    Small u, dieresis or umlaut mark ("&uuml;")
125    }        253    ý    Small y, acute accent ("&yacute;")
126    ~        254    þ    Small thorn, Icelandic ("&thorn;")
127            255    ÿ    Small y, dieresis or umlaut mark ("&yuml;")

 

ANSI Standard (X3.64) Control Sequences for Video Terminals and Peripherals in alphabetic order by mnemonic

Compiled by Paul Bourke
March 1989

Ps and Pn are parameters expressed in ASCII.
Numeric parameters are given in decimal radix.
Abbreviations are explained in detail at end.
Spaces used in this table for clarity are not used in the actual codes.

                                                           Default    Type
Sequence     Sequence                                      Parameter   or
Mnemonic     Name              Sequence                    Value      Mode
---------------------------------------------------------------------------
APC  Applicatn Program Command Esc Fe                                 Delim
CBT  Cursor Backward Tab       Esc [ Pn Z                   1         EdF
CCH  Cancel Previous Character Esc T
CHA  Cursor Horzntal Absolute  Esc [ Pn G                   1         EdF
CHT  Cursor Horizontal Tab     Esc [ Pn I                   1         EdF
CNL  Cursor Next Line          Esc [ Pn E                   1         EdF
CPL  Cursor Preceding Line     Esc [ Pn F                   1         EdF
CPR  Cursor Position Report    Esc [ Pn ; Pn R              1, 1
CSI  Control Sequence Intro    Esc [                                  Intro
CTC  Cursor Tab Control        Esc [ Ps W                   0         EdF
CUB  Cursor Backward           Esc [ Pn D                   1         EdF
CUD  Cursor Down               Esc [ Pn B                   1         EdF
CUF  Cursor Forward            Esc [ Pn C                   1         EdF
CUP  Cursor Position           Esc [ Pn ; Pn H              1, 1      EdF
CUU  Cursor Up                 Esc [ Pn A                   1         EdF
CVT  Cursor Vertical Tab       Esc [ Pn Y                             EdF
DA   Device Attributes         Esc [ Pn c                   0
DAQ  Define Area Qualification Esc [ Ps o                   0
DCH  Delete Character          Esc [ Pn P                   1         EdF
DCS  Device Control String     Esc P                                  Delim
DL   Delete Line               Esc [ Pn M                   1         EdF
DMI  Disable Manual Input      Esc \                                  Fs
DSR  Device Status Report      Esc [ Ps n                   0
EA   Erase in Area             Esc [ Ps O                   0         EdF
ECH  Erase Character           Esc [ Pn X                   1         EdF
ED   Erase in Display          Esc [ Ps J                   0         EdF
EF   Erase in Field            Esc [ Ps N                   0         EdF
EL   Erase in Line             Esc [ Ps K                   0         EdF
EMI  Enable Manual Input       Esc b                                  Fs
EPA  End of Protected Area     Esc W
ESA  End of Selected Area      Esc G
FNT  Font Selection            Esc [ Pn ; Pn Space D        0, 0      FE
GSM  Graphic Size Modify       Esc [ Pn ; Pn Space B        100, 100  FE
GSS  Graphic Size Selection    Esc [ Pn Space C             none      FE
HPA  Horz Position Absolute    Esc [ Pn `                   1         FE
HPR  Horz Position Relative    Esc [ Pn a                   1         FE
HTJ  Horz Tab w/Justification  Esc I                                  FE
HTS  Horizontal Tab Set        Esc H                                  FE
HVP  Horz & Vertical Position  Esc [ Pn ; Pn f              1, 1      FE
ICH  Insert Character          Esc [ Pn @                   1         EdF
IL   Insert Line               Esc [ Pn L                   1         EdF
IND  Index                     Esc D                                  FE
INT  Interrupt                 Esc a                                  Fs
JFY  Justify                   Esc [ Ps ; ... ; Ps Space F  0         FE
MC   Media Copy                Esc [ Ps i                   0
MW   Message Waiting           Esc U
NEL  Next Line                 Esc E                                  FE
NP   Next Page                 Esc [ Pn U                   1         EdF
OSC  Operating System Command  Esc ]                                  Delim
PLD  Partial Line Down         Esc K                                  FE
PLU  Partial Line Up           Esc L                                  FE
PM   Privacy Message           Esc ^                                  Delim
PP   Preceding Page            Esc [ Pn V                   1         EdF
PU1  Private Use 1             Esc Q
PU2  Private Use 2             Esc R
QUAD Typographic Quadding      Esc [ Ps Space H             0         FE
REP  Repeat Char or Control    Esc [ Pn b                   1
RI   Reverse Index             Esc M                                  FE
RIS  Reset to Initial State    Esc c                                  Fs
RM   Reset Mode                Esc [ Ps l                   none
SD   Scroll Down               Esc [ Pn T                   1         EdF
SEM  Select Edit Extent Mode   Esc [ Ps Q                   0
SGR  Select Graphic Rendition  Esc [ Ps m                   0         FE
SL   Scroll Left               Esc [ Pn Space @             1         EdF
SM   Select Mode               Esc [ Ps h                   none
SPA  Start of Protected Area   Esc V
SPI  Spacing Increment         Esc [ Pn ; Pn Space G        none      FE
SR   Scroll Right              Esc [ Pn Space A             1         EdF
SS2  Single Shift 2 (G2 set)   Esc N                                  Intro
SS3  Single Shift 3 (G3 set)   Esc O                                  Intro
SSA  Start of Selected Area    Esc F
ST   String Terminator         Esc \                                  Delim
STS  Set Transmit State        Esc S
SU   Scroll Up                 Esc [ Pn S                   1         EdF
TBC  Tab Clear                 Esc [ Ps g                   0         FE
TSS  Thin Space Specification  Esc [ Pn Space E             none      FE
VPA  Vert Position Absolute    Esc [ Pn d                   1         FE
VPR  Vert Position Relative    Esc [ Pn e                   1         FE
VTS  Vertical Tabulation Set   Esc J                                  FE

Abbreviations:

Intro  an Introducer of some kind of defined sequence; the normal 7-bit
       X3.64 Control Sequence Introducer is the two characters "Escape ["
Delim  a Delimiter
x/y    identifies a character by position in the ASCII table (column/row)
EdF    editor function (see explanation)
FE     format effector (see explanation)
F      is a Final character in
            an Escape sequence (F from 3/0 to 7/14 in the ASCII table)
            a control sequence (F from 4/0 to 7/14)
Gs     is a graphic character appearing in strings (Gs ranges from
       2/0 to 7/14) in the ASCII table
Ce     is a control represented as a single bit combination in the C1 set
       of controls in an 8-bit character set
C0     the familiar set of 7-bit ASCII control characters
C1     roughly, the set of control characters available only in 8-bit systems.
       This is too complicated to explain fully here, so read Jim Fleming's
       article in the February 1983 BYTE, especially pages 214 through 224.
Fe     is a Final character of a 2-character Escape sequence that has an
       equivalent representation in an 8-bit environment as a Ce-type
       (Fe ranges from 4/0 to 5/15)
Fs     is a Final character of a 2-character Escape sequence that is
       standardized internationally with identical representation in 7-bit
       and 8-bit environments and is independent of the currently
       designated C0 and C1 control sets (Fs ranges from 6/0 to 7/14)
I      is an Intermediate character from 2/0 to 2/15 (inclusive) in the
       ASCII table
P      is a parameter character from 3/0 to 3/15 (inclusive) in the ASCII
       table
Pn     is a numeric parameter in a control sequence, a string of zero or
       more characters ranging from 3/0 to 3/9 in the ASCII table
Ps     is a variable number of selective parameters in a control sequence
       with each selective parameter separated from the other by the code
       3/11 (which usually represents a semicolon); Ps ranges from
       3/0 to 3/9 and includes 3/11

Format Effectors versus Editor Functions

A format effector specifies how the final output is to be created.
An editor function allows you to modify the specification.

For instance, a format effector that moves the "active position" (the
cursor or equvalent) one space to the left would be useful when you want to
create an overstrike, a compound character made of two standard characters
overlaid. Control-H, the Backspace character, is actually supposed to be a
format effector, so you can do this. But many systems use it in a
nonstandard fashion, as an editor function, deleting the character to the
left of the cursor and moving the cursor left. When Control-H is assumed to
be an editor function, you cannot predict whether its use will create an
overstrike unless you also know whether the output device is in an "insert
mode" or an "overwrite mode". When Control-H is used as a format effector,
its effect can always be predicted. The familiar characters carriage
return, linefeed, formfeed, etc., are defined as format effectors.

ANSI X3.64 Mode-Changing Parameters for use with the Select Mode (SM) and Reset Mode (RM) functions

    Parameter           Mode          Mode Function
    Characters          Mnemonic
 column/    graphic
  row       repres.
----------------------------------------------------------------------------
3/0           0                       an error condition
3/1           1          GATM         guarded-area transfer mode
3/2           2          KAM          keyboard action mode
3/3           3          CRM          control representation mode
3/4           4          IRM          insertion/replacement mode
3/5           5          SRTM         status-reporting transfer mode
3/6           6          ERM          erasure mode
3/7           7          VEM          vertical editing mode
3/8           8                       reserved for future standardization
3/9           9                       reserved for future standardization
3/10          :                       reserved separator for parameters
3/11          ;                       Standard separator for parameters
3/12          <                       reserved for private (experimental) use
3/13          =                       reserved for private (experimental) use
3/14          >                       reserved for private (experimental) use
3/15          ?                       reserved for private (experimental) use
3/1  3/0      10         HEM          horizontal editing mode
3/1  3/1      11         PUM          positioning unit mode
3/1  3/2      12         SRM          send/receive mode
3/1  3/3      13         FEAM         format effector action mode
3/1  3/4      14         FETM         format effector transfer mode
3/1  3/5      15         MATM         multiple area transfer mode
3/1  3/6      16         TTM          transfer termination mode
3/1  3/7      17         SATM         selected area transfer mode
3/1  3/8      18         TSM          tabulation stop mode
3/1  3/9      19         EBM          editing boundary mode
3/1  3/10     1:                      reserved separator for parameters
3/1  3/11     1;                      Standard separator for parameters
3/1  3/12     1<                      error condition--unspecified recovery
3/1  3/13     1=                      error condition--unspecified recovery
3/1  3/14     1>                      error condition--unspecified recovery
3/1  3/15     1?                      error condition--unspecified recovery
3/2  3/0      20         LNM          linefeed/newline mode (not in ISO 6429)
3/2  3/1      21
 .            .
 .            .                       reserved for future standardization
 .            .
3/9  3/9      99

3/12 3/0      <0
 .            .
 .            .                       reserved for private (experimental) use
 .            .
3/15 3/15     ??


NOTES ON THE DEC VT100 IMPLEMENTATION

In the case of the popular DEC VT100 video-terminal implementation,
the only mode that may be altered is the linefeed/newline (LNM) mode.
Other modes are considered permanently set, reset, or not applicable
as follows:

     Set:   ERM
     Reset: CRM, EBM, FEAM, FETM, IRM, KAM, PUM, SRTM, TSM
     N/A:   GATM, HEM, MATM, SATM, TTM, VEM

Control sequences implemented in the VT100 are as follows:

     CPR, CUB, CUD, CUF, CUP, CUU, DA, DSR, ED, EL, HTS, HVP, IND,
     LNM, NEL, RI, RIS, RM, SGR, SM, TBC

plus several private DEC commands.

Erasing parts of the display (EL and ED) in the VT100 is performed thus:

     Erase from cursor to end of line           Esc [ 0 K    or Esc [ K
     Erase from beginning of line to cursor     Esc [ 1 K
     Erase line containing cursor               Esc [ 2 K
     Erase from cursor to end of screen         Esc [ 0 J    or Esc [ J
     Erase from beginning of screen to cursor   Esc [ 1 J
     Erase entire screen                        Esc [ 2 J

The VT100 responds to receiving the DA (Device Attributes) control

     Esc [ c    (or Esc [ 0 c)

by transmitting the sequence

     Esc [ ? l ; Ps c

where Ps is a character that describes installed options.

The VT100's cursor location can be read with the DSR (Device Status
Report) control

     Esc [ 6 n

The VT100 reports by transmitting the CPR sequence

     Esc [ Pl ; Pc R

where Pl is the line number and Pc is the column number (in decimal).

The complete document describing the standard,  "ANSI X3.64-1979:
Additional Controls for Use with the American National Standard
Code for Information Interchange," can be ordered for $13.50 (plus
$4 postage) from

     Standards Sales Department
     American National Standards Institute
     1430 Broadway
     New York, NY 10018
     212/354-3300

It's best to read the full standard before using it. It also helps
to have copies of the related standards "X3.4-1977: American
National Standard Code for Information Interchange" (the ASCII
standard) and "X3.41.1974: Code-Extension Techniques for Use with
the 7-Bit Coded Character Set of American National Standard for
Information Interchange."

See also the chapter "Using Extended Screens and Keyboard Control"
in the IBM PC-DOS manuals (versions 2.0, 2.1, and 3.0), especially
for the coding for character attributes.

The specification for the DEC VT100 is document EK-VT100-UG-003,
available for $13.00 prepaid from:

     Digital Equipment Corporation
     Accessories and Supplies Group
     POB CS-2008
     Nashua, NH 03061

Copyright 1984 BYTE Publications, subsidiary of McGraw-Hill Inc.
Permission granted to reproduce for noncommercial uses.
This file prepared by Richard S. Shuford.

 

VT100 commands and control sequences

edited by Paul Bourke

The  following  are  the VT100 commands as  described  by  the 
Digital VT101 Video Terminal User Guide  (EK-VT101-UG-003).   An 
asterik (*)  beside the function indicate that it is  currently 
supported.  A plus (+) means the function is trapped and ignored.  

Scrolling Functions:

 *  ESC [ pt ; pb r   set scroll region
 *  ESC [ ? 6 h       turn on region - origin mode
 *  ESC [ ? 6 l       turn off region - full screen mode
                
Cursor Functions:

 *  ESC [ pn A        cursor up pn times - stop at top
 *  ESC [ pn B        cursor down pn times - stop at bottom
 *  ESC [ pn C        cursor right pn times - stop at far right
 *  ESC [ pn D        cursor left pn times - stop at far left
 *  ESC [ pl ; pc H   set cursor position - pl Line, pc Column
 *  ESC [ H           set cursor home
 *  ESC [ pl ; pc f   set cursor position - pl Line, pc Column
 *  ESC [ f           set cursor home
 *  ESC D             cursor down - at bottom of region, scroll up
 *  ESC M             cursor up - at top of region, scroll down
 *  ESC E             next line (same as CR LF)
 *  ESC 7             save cursor position(char attr,char set,org)
 *  ESC 8             restore position (char attr,char set,origin)

Applications / Normal Mode:

 *  ESC [ ? 1 h       cursor keys in applications mode
 *  ESC [ ? 1 l       cursor keys in cursor positioning mode
 *  ESC =             keypad keys in applications mode
 *  ESC >             keypad keys in numeric mode

Character Sets:

 *  ESC ( A           UK char set as G0
 *  ESC ( B           US char set as G0
 *  ESC ( 0           line char set as G0
 *  ESC ) A           UK char set as G1
 *  ESC ) B           US char set as G1
 *  ESC ) 0           line char set as G1
 *  ESC N             select G2 set for next character only
 *  ESC O             select G3 set for next character only

Character Attributes:

 *  ESC [ m           turn off attributes - normal video
 *  ESC [ 0 m         turn off attributes - normal video
!*  ESC [ 4 m         turn on underline mode 
 *  ESC [ 7 m         turn on inverse video mode
 *  ESC [ 1 m         highlight
 *  ESC [ 5 m         blink

!  On color systems underlined characters are displayed in blue

Line Attributes:

 +  ESC # 3           double high (top half) - double wide 
 +  ESC # 4           double high (bottom half) - double wide
 +  ESC # 5           single wide - single height
 +  ESC # 6           double wide - single height
                
Erasing:

 *  ESC [ K           erase to end of line (inclusive)
 *  ESC [ 0 K         erase to end of line (inclusive)
 *  ESC [ 1 K         erase to beginning of line (inclusive)
 *  ESC [ 2 K         erase entire line (cursor doesn't move)
 *  ESC [ J           erase to end of screen (inclusive)
 *  ESC [ 0 J         erase to end of screen (inclusive)
 *  ESC [ 1 J         erase to beginning of screen (inclusive)
 *  ESC [ 2 J         erase entire screen (cursor doesn't move)

Tabulation:

 *  ESC H             set tab in current position
 *  ESC [ g           clear tab stop in current position
 *  ESC [ 0 g         clear tab stop in current position
 *  ESC [ 3 g         clear all tab stops

Printing:

 *  ESC [ i           print page
 *  ESC [ 0 i         print page
 *  ESC [ 1 i         print line
 *  ESC [ ? 4 i       auto print off
 *  ESC [ ? 5 i       auto print on                
 +  ESC [ 4 i         print controller off
 +  ESC [ 5 i         print controller on

Requests / Reports:

 *  ESC [ 5 n         request for terminal status
    ESC [ 0 n         report - no malfunction
 *  ESC [ 6 n         request for cursor position report
    ESC [ pl;pc R     report - cursor at line pl, & column pc
 *  ESC [ ? 1 5 n     request printer status
    ESC [ ? 1 0 n     report - printer ready
 *  ESC [ c           request to identify terminal type
 *  ESC [ 0 c         request to identify terminal type
 *  ESC Z             request to identify terminal type
    ESC [ ? 1;0 c     report - type VT100

Initialization / Tests:

 +  ESC c             reset to initial state
 +  ESC [ 2 ; 1 y     power up test
 +  ESC [ 2 ; 2 y     loop back test
 +  ESC [ 2 ; 9 y     power up test till failure or power down
 +  ESC [ 2 ; 10 y    loop back test till failure or power down
 +  ESC # 8           video alignment test-fill screen with E's


Setup Functions:

 +  ESC [ ? 2 l       enter VT52 mode
 +  ESC <             exit VT52 mode
 +  ESC [ ? 3 h       132 column mode
 +  ESC [ ? 3 l       80 column mode
 +  ESC [ ? 4 h       smooth scroll
 +  ESC [ ? 4 l       jump scroll
 *  ESC [ ? 5 h       black characters on white screen mode
 *  ESC [ ? 5 l       white characters on black screen mode
 *  ESC [ ? 7 h       auto wrap to new line
 *  ESC [ ? 7 l       auto wrap off
 +  ESC [ ? 8 h       keyboard auto repeat mode on
 +  ESC [ ? 8 l       keyboard auto repeat mode off
 +  ESC [ ? 9 h       480 scan line mode
 +  ESC [ ? 9 l       240 scan line mode
 *  ESC [ ? 1 8 h     print form feed on
 *  ESC [ ? 1 8 l     print form feed off
 *  ESC [ ? 1 9 h     print whole screen
 *  ESC [ ? 1 9 l     print only scroll region
 +  ESC [ 2 0 h       newline mode LF, FF, VT, CR = CR/LF)
 +  ESC [ 2 0 l       line feed mode (LF, FF, VT = LF ; CR = CR)

LED Functions:

!*  ESC [ 0 q         turn off LED 1-4
!*  ESC [ 1 q         turn on LED #1
!*  ESC [ 2 q         turn on LED #2
!*  ESC [ 3 q         turn on LED #3
!*  ESC [ 4 q         turn on LED #4

!   The bottom line of the screen is used as a status line by the
    VT100 emulation.   The information on the bottom line is:

1)  the status of the four VT100 LED's
2)  the  status  of the numeric  keypad  (application mode /normal mode)
3)  the  status  of  the cursor  keypad  (application mode/normal  mode)


Interpreted Control Characters:
 
 *  ^O                shift in  - selects G0 character set
 *  ^N                shift out - selects G1 character set


VT100 KEYBOARD MAP

   The following table describes the special function keys of the 
VT100 and shows the transmitted sequences.  It also shows the key 
or  key sequence required to produce this function on the  IBM-PC 
keyboard.  The  VT100 has four function keys PF1 - PF4,  four arrow 
keys, and a numeric keypad with 0-9,  ".",  "-",  RETURN and  ",".
The numeric  keypad  and  the arrow keys may be in standard  mode or 
applications mode as set by the host computer.  Sequences will be 
sent as follows:

 To Get                                  Press Key on
VT100 Key    Standard    Applications     IBM Keypad
=====================================================

                                          NUMLOK - On
Keypad:

   0            0           ESC O p           0
   1            1           ESC O q           1
   2            2           ESC O r           2
   3            3           ESC O s           3 
   4            4           ESC O t           4
   5            5           ESC O u           5
   6            6           ESC O v           6
   7            7           ESC O w           7
   8            8           ESC O x           8
   9            9           ESC O y           9
   -            -           ESC O m           -
   ,            ,           ESC O l      * (on PrtSc key)   
   .            .           ESC O n           .
Return       Return         ESC O M           +

           
                                         NUMLOK - Off    
Arrows:

   Up        ESC [ A        ESC O A           Up
  Down       ESC [ B        ESC O B          Down
  Right      ESC [ C        ESC O C          Right
  Left       ESC [ D        ESC O D          Left

   Up        ESC [ A        ESC O A          Alt 9
  Down       ESC [ B        ESC O B          Alt 0
  Right      ESC [ C        ESC O C          Alt -
  Left       ESC [ D        ESC O D          Alt =

  Note that either set of keys may be used to send VT100 arrow keys.
  The Alt 9,0,-, and = do not require NumLok to be off.
  
Functions:

PF1 - Gold   ESC O P        ESC O P           F1
PF2 - Help   ESC O Q        ESC O Q           F2
PF3 - Next   ESC O R        ESC O R           F3
PF4 - DelBrk ESC O S        ESC O S           F4

Please note that the backspace key transmits an ascii DEL
(character 127) while in VT100 emulation.  To get a true ascii
backspace (character 8) you must press control-backspace.

 

mmencode/mmdecode

Written by Paul Bourke
June 1993man mmencode states

Name
“mimencode – Translate to and from mail-oriented encoding formats”

Description

The mimencode program simply converts a byte stream into (or out of) one of the standard mail encoding formats defined by MIME, the proposed standard for internet multimedia mail formats. Such an encoding is necessary because binary data cannot be sent through the mail. The encodings understood by mimencode are preferable to the use of the uuencode/uudecode programs, for use in mail, in several respects that were important to the authors of MIME.

The man pages don’t tell you how it does it, this is the discussion of this short note

mmencode by default uses a system previously known as “base64”. Basically, consider the bytes of a file lines up one after the other in a long stream. Now move along this stream taking 6 bits at a time and encode them using some “dictionary” of printable characters. The only trick now is to know what dictionary mmencode actually uses. It is given below.

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/

For example if the current 6 bits happen to be 000001 then the letter B is written to the mmencoded file. If 111110 is encountered then + is written to the mmencoded file.

There are a number of way of encoding binary file into text only files for various restrictive transmission channels. Generally they are all very similar except for the bit length they use and the dictionary that maps whatever number of bits to a printable character. The two most common alternative formats are hqx which is generally used on Macintosh systems, and uuencode which is used on UNIX.

 

MacBinary format

Originally by Peter OlsonCompiled by Paul Bourke

November 1990

Introduction

MacBinary is a binary (non-text) format that encodes Macintosh files so that they can be safely stored or transfered through non-Macintosh systems. MacBinary combines the two forks of a Mac file, together with the file information (Name, Creator Application, File Type, etc) into a single binary data stream, suitable for storage on non-Mac systems. This serves a similar purpose to BinHex, except that BinHex takes things even further and stores the file using only text characters, so that the file will be preserved on almost any system, and can be sent through Email or USENET News without loss or corruption.

MacBinary II is the current standard for the MacBinary format. I have further extended the format to allow the encoding of folder hierarchies into a single MacBinary II+ file. But be warned, currently no one else implements this extension, and it may well be that no one else ever will, so the only program you can use to decode folders stored in MacBinary II+ format is this one. Note that this does not affect files stored in MacBinary II format, since files use the MacBinary II format without the new extensions, so any MacBinary decoder should work happily.

Specification

This is a preliminary specification of an extension to the MacBinary II Standard to allow MacBinary to incorporate a directory tree in a similar way to a unix tar file. This is done by a fairly simple extension to the standard (which is documented separately, and which you should be familiar with before reading this), basically, I defined a 128 byte block that marks the start of a folder, and another one that marks the end of the folder, and then set it up like this:

start block for folder "Folder1"
  file1 - standard macbinary format
  file2
  start block for "Folder2"
    file3
  end block
end block

While the end block doesn’t actually need to contain any information, its format is similar to the header block for consistency.

Start Block:

  Offset 000-version 1 - this is incompatible with previous decoders.
  Offset 001-Byte, Length of foldername (must be in the range 1-63)
  Offset 002-1 to 63 chars, foldername (only "length" bytes are significant, 
             the rest should be zero).
  Offset 065-Long Word, file type - 'fold'
  Offset 069-Long Word, file creator - $FFFFFFFF
  Offset 073-Byte, original Finder flags of folder (high byte)
  Offset 074-Byte, zero fill, must be zero for compatibility
  Offset 075-Word, folder's vertical position within its window.
  Offset 077-Word, folder's horizontal position within its window.
  Offset 079-Word, folder's window or folder ID.
  Offset 081-Byte, "Protected" flag (in low order bit).
  Offset 082-Byte, zero fill, must be zero for compatibility
  Offset 083-Long Word, Data Fork length 0
  Offset 087-Long Word, Resource Fork length 0
  Offset 091-Long Word, Folder's creation date
  Offset 095-Long Word, Folder's "last modified" date.
  Offset 099-Word, length of Get Info comment to be sent after the resource
             fork (if implemented, see below).
 *Offset 101-Byte, Finder Flags, bits 0-7. (Bits 8-15 are already in byte 73)
 *Offset 116-Long Word, Length of total files when packed files are unpacked.
             This may be zero to avoid having to preparse the folder when
             creating the MacBinary file.
 *Offset 120-Word, Length of a secondary header.  If this is non-zero,
             Skip this many bytes (rounded up to the next multiple of 128)
             This is for future expansion only, when sending files with
             MacBinary, this word should be zero.
 *Offset 122-Byte, Version number of Macbinary II - 130
 *Offset 123-Byte, Minimum MacBinary II version needed to read this file - 130
 *Offset 124-Word, CRC of previous 124 bytes

Notes

  • The secondary header length MAY be non-zero, and if so, the secondary header immediately follows the Start Block, padded to a multiple of 128 bytes as usual.

  • The comment length MAY be non-zero, and if so, the comment immediately follows the Start Block or secondary header, padded to a multiple of 128 bytes as usual.

End Block:

  Offset 000-version 1 - this is incompatible with previous decoders.
  Offset 065-Long Word, file type - 'fold'
  Offset 069-Long Word, file creator - $FFFFFFFE
 *Offset 116-Long Word, Length of total files when packed files are unpacked.
             This may be zero.
 *Offset 120-Word, Length of a secondary header.  If this is non-zero,
             Skip this many bytes (rounded up to the next multiple of 128)
             This is for future expansion only, when sending files with
             MacBinary, this word should be zero.
 *Offset 122-Byte, Version number of Macbinary II - 130
 *Offset 123-Byte, Minimum MacBinary II version needed to read this file - 130
 *Offset 124-Word, CRC of previous 124 bytes

Note
This block is static except for the total length field, which may be zero as well, in which case its totally static.

You should recognize the Start and End blocks by the version, file type and creator fields. Decoders MUST NOT rely on ANY other fields in the End Block being valid. Encoders MAY fill them out to look like a start block, or may zero-fill them. Encoders SHOULD zero-fill any bytes not explicitly set – this applies to all header blocks and all padding.

All internal files should have version 0, MacBinary II version 129,129.An extended MacBinary file MUST start with a Start Block. Thus a MacBinary II+ file is either:
1) A MacBinary II file encoding a single file, OR
2) A MacBinary II+ file encoding a single folder.

Revised standard

These are the new changes to the MacBinary Standard, as generally agreed upon in the MacBinary II Conference 6/21/87, and as changed in the followup conference 6/28/87. Revised 7/24/87 to reflect suggestions and clarifications that came later, and to include all necessary information needed from the original MacBinary standard document to implement MacBinary II.

The new standard will be very similar to the original MacBinary standard as described in [MacBinary Standard]. (Reading the original standard is recommended for a full understanding of implementation and philosophy behind the MacBinary I and II formats.) The binary format consists of a 128-byte header containing all the information necessary to reproduce the document’s directory entry on the receiving Macintosh; followed by the document’s Data Fork (if it has one), padded with nulls to a multiple of 128 bytes (if necessary); followed by the document’s Resource Fork (again, padded if necessary). The lengths of these forks (either or both of which may be zero) are contained in the header.

Header format

  Offset 000-Byte, old version number, must be kept at zero for compatibility
  Offset 001-Byte, Length of filename (must be in the range 1-63)
  Offset 002-1 to 63 chars, filename (only "length" bytes are significant).
  Offset 065-Long Word, file type (normally expressed as four characters)
  Offset 069-Long Word, file creator (normally expressed as four characters)
  Offset 073-Byte, original Finder flags
                                 Bit 7 - Locked.
                                 Bit 6 - Invisible.
                                 Bit 5 - Bundle.
                                 Bit 4 - System.
                                 Bit 3 - Bozo.
                                 Bit 2 - Busy.
                                 Bit 1 - Changed.
                                 Bit 0 - Inited.
  Offset 074-Byte, zero fill, must be zero for compatibility
  Offset 075-Word, file's vertical position within its window.
  Offset 077-Word, file's horizontal position within its window.
  Offset 079-Word, file's window or folder ID.
  Offset 081-Byte, "Protected" flag (in low order bit).
  Offset 082-Byte, zero fill, must be zero for compatibility
  Offset 083-Long Word, Data Fork length (bytes, zero if no Data Fork).
  Offset 087-Long Word, Resource Fork length (bytes, zero if no R.F.).
  Offset 091-Long Word, File's creation date
  Offset 095-Long Word, File's "last modified" date.
  Offset 099-Word, length of Get Info comment to be sent after the resource
             fork (if implemented, see below).
 *Offset 101-Byte, Finder Flags, bits 0-7. (Bits 8-15 are already in byte 73)
 *Offset 116-Long Word, Length of total files when packed files are unpacked.
             This is only used by programs that pack and unpack on the fly,
             mimicking a standalone utility such as PackIt.  A program that is
             uploading a single file must zero this location when sending a
             file.  Programs that do not unpack/uncompress files when
             downloading may ignore this value.
 *Offset 120-Word, Length of a secondary header.  If this is non-zero,
             Skip this many bytes (rounded up to the next multiple of 128)
             This is for future expansion only, when sending files with
             MacBinary, this word should be zero.
 *Offset 122-Byte, Version number of Macbinary II that the uploading program
             is written for (the version begins at 129)
 *Offset 123-Byte, Minimum MacBinary II version needed to read this file
             (start this value at 129 129)
 *Offset 124-Word, CRC of previous 124 bytes

* This is newly defined for MacBinary II.

All values are stored in normal 68000 order, with Most Significant Byte appearing first then the file. Any bytes in the header not defined above should be set to zero.

The original MacBinary format was amended to include the sending of the FCMT (Get Info comment) after the resource fork was sent, if the length for such comment, given in offset 99, is not zero. To the best of our knowledge, no program has implemented this feature, due to Apple’s stated position that no program should read or write these comments. The definition remains in MacBinary II, so that should Apple ever provide a documented way of reading and writing these comments, terminal programs will be able to take advantage of this feature.

All Finder flags and information would be uploaded, however, a downloading program should clear the Finder flag bits of
0 – Set if file/folder is on the desktop (Finder 5.0 and later)
1 – bFOwnAppl (used internally)
8 – Inited (seen by Finder)
9 – Changed (used internally by Finder)
10 – Busy (copied from File System busy bit)

Also, fdLocation and fdFldr should be zeroed

To determine if a header is a valid MacBinary header, check bytes 0 and 74 to be both zero. If they are both zero, either (a) the CRC should match, which means it is a MB II file, or (b) byte 82 is zero, which means it may be a MB I file. (Note that, at the current version level, byte 82 is kept zero to maintain compatibility with MacBinary I. If at some point the MacBinary versions change sufficiently that it is necessary to keep MacBinary I programs from downloading these files, we can change byte 82 to non-zero.)

If the header is a MB II header, the program will check the minimum version byte, to see if it knows enough to decode the file. If the minimum version in the header is greater than the version that the terminal program was written for, it will download the file as pure XModem (creating a “TEXT” file) and notify the user that conversion is needed because the MacBinary version was too high.

If the header does NOT represent a valid MB II header, the program must at minimum check byte 82 to be zero–if it is not zero, the file is not a MB I file. It is possible to write a much more robust routine, by checking the following:

  • Offsets 101-125, Byte, should all be 0.

  • Offset 2, Byte, (the length of the file name) should be in the range of 1-63.

  • Offsets 83 and 87, Long Word, (the length of the forks) should be in the range of 0-$007F FFFF.

If any of these tests fail, the file is not a valid MacBinary file. It may still be desirable to distinguish between text files and foreign binary files (for stripping line feeds or similar helpful acts). Some tests that would prove useful include:

  • A quantity of bytes in the first block with the high bit set would point to a binary file (though this could be fooled by files with many extended ascii characters, such as generated by the option key on a Mac).

  • A large quantity of zero bytes (nulls) would also point to a binary file.

CSV – Comma Separated Value

Written by Paul Bourke
April 2000

The CSV (Comma Separated Value) format is a straightforward (mostly) way of transfering data between programs. It is typically used for spreadsheet and database applications because it is suited to data arranged in a table, that is, made up of rows and columns.

In it’s simplest form a CSV file consists of records and fields. The records are separated by any combination of linefeeds, carriage control, or a carriage control linefeed pairs. Fields are separated by commas and any leading or trailing spaces are removed from fields.

For example the following has two records each with four fields.

1,tree,december,1999
5,bush,january, 2000

The above begs the question, “What if my field contains leading or trailing spaces, commas, linefeeds, or carriage control characters?”. The answer is to enclose fields in double quotes. Note that this means that records can span lines. The following example has two records each with three fields.

1," tree","december, 1999"
5,bush,"january, 2000"

So what about fields that contain double quotes? These are represented by two double quotes, the field itself must also be enclosed in double quotes. For example the first field in the following becomes I said “stop”.

"I said ""stop""","January 2000","5pm"

In the vast majority of cases CSV is used to transfer human readable ascii data, however there is no reason why it can’t be used for more general binary data.

Advertisements
This entry was posted in DOS. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s