VT100.net: Digital VT102 User Guide

# C Programming Summary

## General

This appendix provides a summary of VT102 escape and control sequences.

Figure C-1 shows the codes generated by the standard keys. Figure C-2 shows the control codes generated by the function keys; shaded keys do not need CTRL down to generate the control character.

## Programming Sequences

The rest of this appendix repeats the information on the VT102 Programming Reference Card (EK-VT102-RC-001).

### Control Characters Received

Name | Character Mnemonic | Octal Code | Function
--- | --- | --- | ---
Null | NUL | 000 | Ignored when received (not stored in input buffer) and used as a fill character.
End of text | ETX | 003 | Can be selected as a half-duplex turnaround character.
End of transmission | EOT | 004 | Can be selected as a disconnect character or half-duplex turnaround character. When used as a turnaround character, the disconnect character is DLE-EOT.
Enquire | ENQ | 005 | Transmits answerback message.
Bell | BEL | 007 | Generates bell tone.
Backspace | BS | 010 | Moves cursor to the left one character position; if cursor is at left margin, no action occurs.
Horizontal tab | HT | 011 | Moves cursor to next tab stop, or to right margin if there are no more tab stops.
Linefeed | LF | 012 | Causes a linefeed or a new line operation. (See Linefeed/New Line mode). Also causes printing if auto print operation selected.
Vertical tab | VT | 013 | Processed as LF.
Form feed | FF | 014 | Processed as LF. FF can also be selected as a half-duplex turnaround character.
Carriage return | CR | 015 | Moves cursor to left margin on current line. CR can also be selected as a half-duplex turnaround character.
Shift out | SO | 016 | Selects G1 character set designated by a select character set sequence.
Shift in | SI | 017 | Selects G0 character set designated by a select character set sequence.
Device control 1 | DC1 | 021 | Processed as XON. DC1 causes terminal to continue transmitting characters.
Device control 3 | DC3 | 023 | Processed as XOFF. DC3 causes terminal to stop transmitting all characters except XOFF and XON. DC3 can also be selected as a half-duplex turnaround character.
Cancel | CAN | 030 | If received during an escape or control sequence, cancels the sequence and displays substitution character ().
Substitute | SUB | 032 | Processed as CAN.
Escape | ESC | 033 | Processed as a sequence introducer.

### ANSI Compatible Sequences

#### Set Mode

Name | Mnemonic | Mode | Sequence
--- | --- | --- | ---
Keyboard action | KAM | Locked | `ESC [ 2 h`
Insertion-replacement | IRM | Insert | `ESC [ 4 h`
Send-receive | SRM | Off | `ESC [ 1 2 h`
Linefeed/new line | LMN | New line | `ESC [ 2 0 h`
Cursor key | DECCKM | Application | `ESC [ ? 1 h`
ANSI/VT52 | DECANM | ANSI | N/A
Column | DECCOLM | 132 column | `ESC [ ? 3 h`
Scrolling | DECSCLM | Smooth | `ESC [ ? 4 h`
Screen | DECSCNM | Reverse | `ESC [ ? 5 h`
Origin | DECOM | Relative | `ESC [ ? 6 h`
Auto wrap | DECAWM | On | `ESC [ ? 7 h`
Auto repeat | DECARM | On | `ESC [ ? 8 h`
Print form feed | DECPFF | On | `ESC [ ? 1 8 h`
Print extent | DECPEX | Full screen | `ESC [ ? 1 9 h`

#### Reset Mode

Name | Mnemonic | Mode | Sequence*
--- | --- | --- | ---
Keyboard action | KAM | Unlocked | `ESC [ 2 l`
Insertion-replacement | IRM | Replace | `ESC [ 4 l`
Send-receive | SRM | On | `ESC [ 1 2 l`
Linefeed/new line | LMN | Linefeed | `ESC [ 2 0 l`
Cursor key | DECCKM | Cursor | `ESC [ ? 1 l`
ANSI/VT52 | DECANM | VT52 | `ESC [ ? 2 l`
Column | DECCOLM | 80 column | `ESC [ ? 3 l`
Scrolling | DECSCLM | Jump | `ESC [ ? 4 l`
Screen | DECSCNM | Normal | `ESC [ ? 5 l`
Origin | DECOM | Absolute | `ESC [ ? 6 l`
Auto wrap | DECAWM | Off | `ESC [ ? 7 l`
Auto repeat | DECARM | Off | `ESC [ ? 8 l`
Print form feed | DECPFF | Off | `ESC [ ? 1 8 l`
Print extent | DECPEX | Scrolling region | `ESC [ ? 1 9 l`
* The last character of the sequence is lowercase L (1548)

#### Cursor Key Codes Generated

Cursor Key (Arrow) | ANSI Characters Generated
--- | ---
Reset (Cursor) | Set (Application)
Up | `ESC [ A` | `ESC O A`
Down | `ESC [ B` | `ESC O B`
Right | `ESC [ C` | `ESC O C`
Left | `ESC [ D` | `ESC O D`

#### Keypad Character Selection

Name | Mnemonic | Sequence
--- | --- | ---
Alternate | DECKPAM | `ESC =`
Numeric | DECKPNM | `ESC >`

#### Keypad Codes Generated

Key | VT52 Numeric Keypad Mode | VT52 Alternate Keypad Mode | ANSI Numeric Keypad Mode | ANSI Alternate Keypad Mode
--- | --- | --- | --- | ---
0 | 0 | `ESC ? p` | 0 | `ESC O p`
1 | 1 | `ESC ? q` | 1 | `ESC O q`
2 | 2 | `ESC ? r` | 2 | `ESC O r`
3 | 3 | `ESC ? s` | 3 | `ESC O s`
4 | 4 | `ESC ? t` | 4 | `ESC O t`
5 | 5 | `ESC ? u` | 5 | `ESC O u`
6 | 6 | `ESC ? v` | 6 | `ESC O v`
7 | 7 | `ESC ? w` | 7 | `ESC O w`
8 | 8 | `ESC ? x` | 8 | `ESC O x`
9 | 9 | `ESC ? y` | 9 | `ESC O y`
- (minus) | - (minus) | `ESC ? m` | - (minus) | `ESC O m`
, (comma) | , (comma) | `ESC ? l`* | , (comma) | `ESC O l`*
. (period) | . (period) | `ESC ? n` | . (period) | `ESC O n`
ENTER | Same as RETURN | `ESC ? M` | Same as RETURN | `ESC O M`
PF1 | `ESC P` | `ESC P` | `ESC O P` | `ESC O P`
PF2 | `ESC Q` | `ESC Q` | `ESC O Q` | `ESC O Q`
PF3 | `ESC R` | `ESC R` | `ESC O R` | `ESC O R`
PF4 | `ESC S` | `ESC S` | `ESC O S` | `ESC O S`
* The last character of the sequence is lowercase L (1548)

#### Select Character Sets SCS

Character Set | G0 Designator | G1 Designator
--- | --- | ---
United Kingdom (UK) | `ESC ( A` | `ESC ) A`
United States (US) | `ESC ( B` | `ESC ) B`
Special characters and line drawing set | `ESC ( 0` | `ESC ) 0`
Alternate character ROM | `ESC ( 1` | `ESC ) 1`
Alternate character ROM - special characters | `ESC ( 2` | `ESC ) 2`

Name | Mnemonic | Sequence
--- | --- | ---
Single shift 2 | SS2 | `ESC N`
Single shift 3 | SS3 | `ESC O`

#### Character Attributes

Name | Mnemonic | Sequence
--- | --- | ---
Select graphic rendition (no attributes) | SGR | `ESC [ m`
Select graphic rendition (no attributes) | SGR | `ESC [ 0 m`
Select graphic rendition (select attribute bold) | SGR | `ESC [ 1 m`
Select graphic rendition (select attribute underline) | SGR | `ESC [ 4 m`
Select graphic rendition (select attribute blink) | SGR | `ESC [ 5 m`
Select graphic rendition (select attribute, reverse video) | SGR | `ESC [ 7 m`

#### Scrolling Region

Name | Mnemonic | Sequence
--- | --- | ---
Set top and bottom margins | DECSTBM | `ESC [ Pt ; Pb r`

#### Cursor Movement Commands

Name | Mnemonic | Sequence
--- | --- | ---
Cursor up | CUU | `ESC [ Pn A`
Cursor down | CUD | `ESC [ Pn B`
Cursor forward (right) | CUF | `ESC [ Pn C`
Cursor backward (left) | CUB | `ESC [ Pn D`
Cursor position | CUP | `ESC [ Pl ; Pc H`
Cursor position (home) | CUP | `ESC [ H`
Horizontal and vertical position | HVP | `ESC [ Pl ; Pc f`
Horizontal and vertical position (home) | HVP | `ESC [ f`
Index | IND | `ESC D`
Reverse index | RI | `ESC M`
Next line | NEL | `ESC E`
Save cursor (and attributes) | DECSC | `ESC 7`
Restore cursor (and attributes) | DECRC | `ESC 8`

#### Tab Stops

Name | Mnemonic | Sequence
--- | --- | ---
Horizontal tab set (at current column) | HTS | `ESC H`
Tabulation clear (at current column) | TBC | `ESC [ g`
Tabulation clear (at current column) | TBC | `ESC [ 0 g`
Tabulation clear (all tabs) | TBC | `ESC [ 3 g`

#### Line Attributes

Name | Mnemonic | Sequence
--- | --- | ---
Double-height top half | DECDHL | `ESC # 3`
Double-height bottom half | DECDHL | `ESC # 4`
Single-width single-height | DECSWL | `ESC # 5`
Double-width single-height | DECDWL | `ESC # 6`

#### Erasing

Name | Mnemonic | Sequence
--- | --- | ---
Erase in line (cursor to end of line) | EL | `ESC [ K`
Erase in line (cursor to end of line) | EL | `ESC [ 0 K`
Erase in line (beginning of line to cursor) | EL | `ESC [ 1 K`
Erase in line (entire line containing cursor) | EL | `ESC [ 2 K`
Erase in display (cursor to end of screen) | ED | `ESC [ J`
Erase in display (cursor to end of screen) | ED | `ESC [ 0 J`
Erase in display (beginning of screen to cursor) | ED | `ESC [ 1 J`
Erase in display (entire screen) | ED | `ESC [ 2 J`

#### Editing Functions

Name | Mnemonic | Sequence
--- | --- | ---
Delete character | DCH | `ESC [ Pn P`
Insert line | IL | `ESC [ Pn L`
Delete line | DL | `ESC [ Pn M`

#### Print Commands

Name | Mnemonic | Sequence
--- | --- | ---
Media copy (enter auto print) | MC | `ESC [ ? 5 i`
Media copy (exit auto print) | MC | `ESC [ ? 4 i`
Media copy (enter printer controller) | MC | `ESC [ 5 i`
Media copy (exit printer controller) | MC | `ESC [ 4 i`
Media copy (print screen) | MC | `ESC [ i`
Media copy (print screen) | MC | `ESC [ 0 i`
Media copy (print cursor line) | MC | `ESC [ ? 1 i`

#### Reports

Name | Mnemonic | Sequence
--- | --- | ---
Device status report (request status of VT102) | DSR | `ESC [ 5 n`
Response: |  |
Terminal OK | DSR | `ESC [ 0 n`
Terminal not OK | DSR | `ESC [ 3 n`
Device status report (request status of printer) | DSR | `ESC [ ? 1 5 n`
Response: |  |
Printer ready | DSR | `ESC [ ? 1 0 n`
Printer not ready | DSR | `ESC [ ? 1 1 n`
No printer | DSR | `ESC [ ? 1 3 n`
Device status report (report cursor position) | DSR | `ESC [ 6 n`
Cursor position report | CPR | `ESC [ Pl ; Pc R`
Device attributes (what are you) | DA | `ESC [ c`
Device attributes (what are you) | DA | `ESC [ 0 c`
Identify terminal (what are you) | DECID | `ESC Z`
NOTE: `ESC Z` is not recommended.
Device attributes response: VT102 | DA | `ESC [ ? 6 c`

#### Reset

Name | Mnemonic | Sequence
--- | --- | ---
Reset to initial state | RIS | `ESC c`

#### Tests and adjustments

Name | Mnemonic | Sequence
--- | --- | ---
Screen alignment display (fill screen with "Es") | DECALN | `ESC # 8`
Invoke confidence test (power-up test) | DECTST | `ESC [ 2 ; 1 y`
Invoke confidence test (data loopback test; requires test connector) | DECTST | `ESC [ 2 ; 2 y`
Invoke confidence test (EIA modem control test; requires test connector) | DECTST | `ESC [ 2 ; 4 y`
Invoke confidence test (repeat power-up test continuously until failure or power-off) | DECTST | `ESC [ 2 ; 9 y`
Invoke confidence test (repeat data loopback test continuously until failure or power-off; requires test connector) | DECTST | `ESC [ 2 ; 1 0 y`
Invoke confidence test (repeat EIA test continuously until failure or power-off; requires test connector) | DECTST | `ESC [ 2 ; 1 2 y`
Invoke confidence test (printer port data loopback test; requires test connector) | DECTST | `ESC [ 2 ; 1 6 y`
Invoke confidence test (repeat printer port data loopback test continuously until failure or power-off; requires test connector) | DECTST | `ESC [ 2 ; 2 4 y`

#### Keyboard LEDs

Name | Mnemonic | Sequence
--- | --- | ---
Load LEDs (L1 off) | DECLL | `ESC [ q`
Load LEDs (L1 off) | DECLL | `ESC [ 0 q`
Load LEDs (L1 on) | DECLL | `ESC [ 1 q`

### VT52 Compatible Mode

Modes | Sequence
--- | ---
Enter ANSI mode | `ESC <`

#### Keypad Character Selection

Name | Sequence
--- | ---
Enter alternate keypad mode | `ESC =`
Exit alternate keypad mode (Numeric keypad mode) | `ESC >`

NOTE: VT52 alternate keypad and numeric keypad mode different than ANSI.

#### Character Sets

Name | Sequence
--- | ---
Special graphics character set | `ESC F`*
Select US/UK character set (as determined by the US/UK character SET-UP feature) | `ESC G`
* Same as special character and line drawing set in ANSI mode.

#### Cursor Position

Name | Sequence
--- | ---
Cursor up* | `ESC A`
Cursor down* | `ESC B`
Cursor right* | `ESC C`
Cursor left* | `ESC D`
Cursor to home | `ESC H`
Direct cursor address | `ESC Y Pl Pc†`
Reverse line feed | `ESC I‡`
* Same when sent from the terminal.
† Line and column numbers for direct cursor address are single character codes whose values are the desired number plus 378. Line and colum numbers start at one.
‡ The last character of the sequence is an uppercase i (1118).

#### Erasing

Name | Sequence
--- | ---
Erase to end of line | `ESC K`
Erase to end of screen | `ESC J`

#### Print Commands

Name | Sequence
--- | ---
Enter auto print mode | `ESC ^`
Exit auto print mode | `ESC _`
Enter printer controller mode | `ESC W`
Exit printer controll mode | `ESC X`
Print screen | `ESC ]`
Print cursor line | `ESC V`

#### Reports

Name | Sequence
--- | ---
Identify (what are you) | `ESC Z`
Response: VT102 (same as VT52) | `ESC / Z`