-----------------------------------------------------------
                   VT102 Commands
     as implemented in Ice-T Terminal Emulator v2.8.2+
                   by Itay Chamiel
-----------------------------------------------------------

Conventions used:

Esc    - the ASCII character 27
^      - Control.
__     - Decimal number from 0 to 255 in ASCII digits 0-9. Leading zeros are
         ignored. An absent value is parsed as a zero. Any argument higher than
         255 is also parsed as zero.
Spaces are shown only for clarity and are never part of any command sequence.

"Can scroll" means that if the cursor cannot move up or down without passing
the scrolling margins (not necessarily the top or bottom of the screen), it
will not move, and cause a scroll to occur.
If the scrolling margin is not the same as the screen edge, and the cursor
is at the top or bottom of the screen, "can scroll" commands will not cause a
scroll. A scroll occurs only at scroll margins.

All commands are case sensitive.

Commands with parameters look like this:
Esc [ __ ; __ ; __ ; ....... ; __ x (where x is a different letter for each
command). Ice-T allows up to 255 values to be received in one command, but
most commands will only be affected by the first one or two values. (In
case 256 or more values are received, only the last n modulo 256 values will
take effect.) All such commands have defaults which are used if no parameters
are received, or if less are received than expected.

Unknown control characters, unknown "Esc x" commands and unknown
"Esc [ __ ; ... ; __ x" commands are silently ignored by the emulator.

Line and column numbers start at 1. The screen has 80 columns and 24 lines.

Any incoming character that is not a control code or part of a command sequence
is displayed at the cursor position. The cursor is then advanced one position
to the right. When reaching the right margin with autowrap mode on, there is a
subtle distinction between ANSI and VT102 mode: If the cursor is at column 80
and a character is displayed, in VT102 mode the cursor will remain in place
until another character is received, at which point the cursor will move to the
next line (scrolling if required), display the new character and move to column
2. In ANSI mode the cursor will immediately move to the next line. This
distinction is relied upon by certain pedantic applications such as GNU Emacs.

Control characters
------------------
^E  Send "Answerback" response, in this case the text "Ice-T" and the version.
^G  Bell, flash border color.
^H  Cursor left one character. No effect if cursor on col 1
^I  Tab. Cursor moves to next tabstop, or rightmost column if no further tabs.
    Default tabstops are at columns 9, 17, 25, and so on, spaced 8 apart.
^J  Linefeed, move cursor down one line. Move cursor to col 1 ONLY if newline
    mode is SET (see Esc [ __ h). Can scroll.
^K  Vertical tab, treated as Linefeed (^J)
^L  Form feed, treated as Linefeed (^J)
^M  Carriage-Return, move cursor to col 1
^N  Invoke G1 character set (see "Esc )" commands)
^O  Invoke G0 character set (see "Esc (" commands)
^X or ^Z  Abort any Esc sequence currently in progress. If a sequence was in
    progress and ^X or ^Z were sent, the checkerboard character is displayed
    to inform of an error. If not - the code is ignored.
^X B00 - Begin a Zmodem session. This is the beginning of the ZRQINIT frame.
^[  Escape. Begins a new Escape-sequence, cancelling any other which may have
    been in progress.

Esc x Codes
-----------
Esc c  Reset terminal settings, clear screen, home cursor.
Esc D  Cursor down 1 line, can scroll.
Esc E  Cursor down one line and moves to col 1, can scroll.
Esc H  Set tab at current cursor horizontal position.
Esc M  Cursor up 1 line, can scroll
Esc Z  Identify Terminal. Software replies by sending VT102 response: Esc [?6c
Esc 7  Save cursor position, graphic rendition, character set, origin mode.
Esc 8  Restore parameters saved with Esc 7 (or just home cursor if none)
Esc >  Numeric Keypad Mode (NumLock On)
Esc =  Application Keypad Mode (NumLock Off)

Esc [ __ x commands
-------------------
These commands are also recognized if they do not receive any parameter
(Esc [ x), or if they receive less than the required amount of parameters.
In these cases, the default(s) replace the required number.

Esc [ __ A  (none/0 --> 1) Cursor up __ lines, does not scroll, stops if at
          edge of screen (or scroll margin in Origin mode).
Esc [ __ B  Down, same as above
Esc [ __ C  Forward, same as above, cursor stays on same line
Esc [ __ D  Backward, same as above
Esc [ __ ; __ H  (none/0 --> 1,1) Set cursor to row, col. If any parameter is
          not within range (1-24 for row or 1-80 for col, or scroll region in
          Origin mode) they are truncated appropriately. 0 is converted to 1.
Esc [ __ J  (none --> 0) Erase part of the screen:
          0 - cursor position to end of line (inclusive) and all lines below
          1 - cursor position to start of line (inclusive) and all lines above
          2 - entire screen. cursor does not move. (ANSI-BBS: home cursor)
          Other - ignore command
Esc [ __ K  (none --> 0) Erase part of line:
          0 - cursor position to end of line (inclusive)
          1 - cursor position to start of line (inclusive)
          2 - entire line
          Other - ignore command
Esc [ __ c  (Parameter ignored) Device attributes. Same as Esc Z
Esc [ __ ; __ f  (none --> 1,1) same as Esc[_;_H (above)
Esc [ __ g  (none --> 0)
          0 - Clear tab at cursor column
          3 - Clear all tabs.
          Other - ignore command
Esc [ __ h
          4  - Set Insert mode:
               Any displayed character pushes the rest of the characters on the
               same line one position forward. Note that due to design
               limitations, graphics attributes of moved characters are lost.
          20 - Set Newline mode:
               Receiving an lf will be treated as cr + lf
               Pressing Return on keyboard sends cr + lf
Esc [ __ l
          4  - Reset Insert mode (default):
               Any displayed character overwrites the character that was
               previously displayed at that position.
          20 - Reset Newline mode (default):
               Receiving an lf will be treated as lf alone
               Pressing Return on keyboard sends cr alone
Esc [ ? __ ; ... ; __ h  Set mode(s), see below
Esc [ ? __ ; ... ; __ l  Reset mode(s), see below
Parameter          Set           Reset
 1 - cursor keys   Application   Numeric
 2 - terminal type VT102         VT52
 3 - columns       132 column mode not supported, but in either case clear
                   screen, home cursor, reset scrolling margins.
 5 - screen color  Reverse-vid   Normal
 6 - Origin mode   On            Off (in Origin mode cursor remains only
                   within scrolling margins. Homes cursor.)
 7 - autowrap      On            Off
Esc [ __ ; ... ; __ m  (at least one parameter, none --> 0)
 Select rendition mode(s) for text, parsed in the order they appear:
 0 - Reset to normal   1 - Bold (bright)   4 - Underline
 5 - Blink             7 - Reverse video   8 - Invisible (writes blank spaces)
 22 - Normal intensity (turn bold off)
 30-37 - foreground color (Black/Red/Green/Yellow/Blue/Magenta/Cyan/White)
 38 - extended foreground (see below)
 39 - default foreground color.
 40-47 - background color - overrides foreground color until unset.
 48 - extended background (see below)
 49 - default background color.
 90-97 - same as 30-37 but bold is also turned on.
 100-107 - same as 40-47 but bold is also turned on.

Values 38 and 48 allow extended color support and require additional
parameters. If there are insufficient parameters then the command is ignored
with no effect.
 2 ; __ ; __ ; __ - the last three values are parsed as R, G, B values. Inputs
   are internally converted to an Xterm index, so this doesn't actually allow a
   broader range of colors than parameter 5 below.
 5 ; __ - for Xterm indexed colors, described at:
   https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
 9 ; __ - the argument is parsed as an Atari color. This is a private
   extension.

Colors are implemented using Atari Player/Missile graphics. Each P/M covers a
width of 16 characters and has only 8 pixels of resolution, therefore the
horizontal resolution is only 40 columns; coloring a character may also color
its neighbor. Also, all colored characters within the same 16-character-wide
column will share a single color. If an attempt is made to use two different
colors within the same region the most recently applied color will change the
others within that range. Vertically there is no limitation.

ANSI allows defining the background and foreground colors separately but this
is impossible in ANTIC F (Graphics 8) mode which Ice-T uses. So for a colored
character the foreground and background colors are the same. If different
background and foreground colors are specified the background color takes
priority and foreground is ignored. If only a foreground color is specified
then spaces are not painted with the color.

Esc [ __ ; ... ; __ q Virtual LEDs control. 0 turns all off, 1-4 turns on the
            respective LED.
Esc [ __ n  (none --> 5)
            Device Status Report. Response depends on parameter:
            5: response is "ready" - Esc [0n
            6: report cursor position (relative to top of scroll region if in
               Origin mode) - Esc [ row ; col R
Esc [ __ ; __ r (defaults: 1,24) Set top and bottom scrolling margins.
            1 and 24, for example, mean the entire screen scrolls.
            14 and 24 cause the last 10 lines to scroll. 14,24 mean lines
            14 to 24 inclusive. Cursor is moved to home - top of scrolling
            region in Origin mode, top of screen otherwise.
Esc [ __ x (default: 0) Request Terminal Parameters. In response to values 0
            or 1, returns the string: Esc [ N1;1;1;N2;N2;1;0x
            where N1 is 2 if arg was 0, 3 if arg was 1,
            and N2 depends on current baud rate setting:
            48, 56, 64, 72, 88, 104, 112, 120 for 300, 600, 1200, 1800, 2400,
            4800, 9600 and 19200 baud respectively.
ESC [ __ L  (none/0 --> 1) Insert __ lines at line with cursor. Lines are moved
                           down. Ignored when cursor is outside scrolling
                           region.
ESC [ __ M  (none/0 --> 1) Deletes __ lines, starting at line with cursor.
                           Lines move up. Ignored when cursor is outside
                           scrolling region.
ESC [ __ P  (none/0 --> 1) Deletes __ characters, starting at cursor position.
                           Characters to the right of the cursor move left.
                           (Due to design limitations graphics attributes of
                           moved characters are lost.)

Other Escape sequences
----------------------
Esc ( A or Esc ( B             Set G0 to point to ASCII characters
Esc ( 0 or Esc ( 1 or Esc ( 2  Set G0 to point to line-drawing graphics
Esc ) A or Esc ) B             Set G1 to point to ASCII characters
Esc ) 0 or Esc ) 1 or Esc ) 2  Set G1 to point to line-drawing graphics

Esc # 3 Double-Height, top half
Esc # 4 Double-Height, bottom half
Esc # 5 Normal size
Esc # 6 Double-width
Esc # 7 Normal size
Esc # 8 Fill screen with the letter E for screen adjustment

The line-changing commands preserve anything already on that line, unless
an 80-column line is changed into a 40-column line. In that case, the
last 40 characters of that line are lost.
Double-size characters use the standard built-in character set (since it's
40 columns) plus a few characters like tilde and curly braces, and for the
special graphics characters, which don't exist in ATASCII, a simple routine
which doubles the 80-column characters is used.
Double-height characters are the same as double-width, but each line of pixels
is duplicated to achieve double height.

Additional ANSI sequences
-------------------------
Ice-T doesn't fully emulate anything beyond VT102, but some commonly used
codes from the wider ANSI standard have been implemented.

Esc [ __ d  (none/0 --> 1) Set cursor row. Column is unchanged.
Esc [ __ G  (none/0 --> 1) Set cursor column. Row is unchanged.
ESC [ __ @  (none/0 --> 1) Inserts __ characters, starting at cursor position.
                           Characters to the right of the cursor move right.
                           (Due to design limitations graphics attributes of
                           moved characters are lost.)
Esc [ __ E  (none/0 --> 1) Same as Esc [ __ B and moves cursor to left margin.
Esc [ __ F  (none/0 --> 1) Same as Esc [ __ A and moves cursor to left margin.
Esc [ __ S  (none/0 --> 1) Scroll down by __ lines. Cursor doesn't move.
Esc [ __ T  (none/0 --> 1) Scroll up by __ lines. Cursor doesn't move.
Esc [ __ X  (none/0 --> 1) Clears __ characters, starting at cursor position.
                           Cursor doesn't move.
Esc [ __ Z  (none/0 --> 1) Moves backwards __ tab stops, stopping at left
                           margin.
Esc [ __ s  (Parameter ignored) Same as Esc 7
Esc [ __ u  (Parameter ignored) Same as Esc 8

Private extensions
------------------
The following codes are private to Ice-T. They are all of the form:
Esc [ __ ; ... ; __ / t
where the first argument defines the command to perform and the following
arguments are parameters for that command. Only one command may be performed
at a time.

1 - Time Delay: expects 1 parameter (none/0 --> 1, max. 255) - pauses for a
    time delay of that many vertical blanks. If the user presses a key during
    the delay period then the delay is aborted and the key is handled as usual.

2 - Paint: expects 2 or 4 parameters (none/0 --> 1,1,1,1, max. 24,40,24,40) -
    color the character(s) at these coordinates according to the current color
    set with Esc [ ... m. If no color is set then this will "uncolor" those
    characters. If two parameters are supplied then they are the row and column
    of a single point. If four parameters are supplied then they are the top-
    left and lower-right corners of a rectangle that will be filled with the
    desired color. Note that the X coordinate is limited to half the normal
    resolution due to hardware limitations.

3 - Set Underlay Colors: expects 2 parameters (none/0 --> 1,1, max. 24,5)
    followed by an arbitrary number of color values. Starts at the given row
    and PM column and sets the PM color according to the third argument.
    Continues to read arguments and set them in the color table, moving from
    left to right and down to the next row in the PM color table until the list
    of arguments is exhausted or the end of the table is reached.

4 - Colors Scroll Lock: expects 1 parameter (none --> 0, max. 1) - this "locks"
    scrolling of the color PM underlay. If set to 1 then the colors will remain
    fixed on the screen even when the text is scrolling.
    This may cause a minor side effect: when outputting space characters in
    normal (i.e. no color) rendition mode and the cursor was over a colored
    region, the coloring at that position might not be cleared.

5, 6 - Vertical Force Scroll: scrolls the color underlay down/up without
    modifying the text, according to the terminal's currently set scrolling
    margins. Expects the following parameters:
    Param 1 (none --> 1, max. 24) - amount of lines to scroll.
    Param 2 (none --> 1, max. 1) - 0 or 1, whether to scroll the PM bitmap.
    Param 3 (none --> 1, max. 1) - 0 or 1, whether to scroll the color assign-
      ment table.
    Param 4 (none --> 0, max. 1) - 0 or 1, rotation. If set to 0 scroll will
      behave as normal, and the currently set background color will fill the
      new line. If 1, the new line will be a copy of the line scrolled out.

10 - Set Screen Colors: allows setting the color registers affecting ANTIC mode
     15 (a.k.a. Graphics 8): COLOR1 (luminance of lit pixels), COLOR2
     (playfield), COLOR4 (border).
     Setting no arguments will reset the colors to default.
     You may specify up to three color values to modify the registers.
     Keep in mind that the screen is normally inverted from what you'd expect,
     i.e. the background is actually composed of lit pixels, so setting COLOR1
     and COLOR2 may have the opposite effect of what you expect. These custom
     colors are reset by VT100 codes Esc [?5 h or l (screen inverse control),
     Esc c (reset terminal), the "Reset term" menu entry or the Reset console
     key.

The following five commands allow direct control of P/M graphics. This document
assumes the reader is familiar with the relevant hardware capabilities. Note
that misuse of these commands can easily render the color underlay unusable, or
cause a garbage screen display. In any case, you can reset things to normal
with an "Esc c" code, the "Reset term" menu entry, or the console Reset button.
Note that player graphics are in double line resolution and this may not be
changed.

As explained in command 10 above, the screen background is normally composed of
lit pixels which will mostly obscure any players you may want to draw (their
luminance will be forced to the background's luminance). To work around this
you may emit the following series of codes:
Esc [0;7m Esc [2J
This resets the graphic rendition and sets inverse mode, then it clears the
screen with inverse mode still active. The effect of this is that the screen
will be filled with inverse spaces, which are actually zero bytes. Further
text that will be written will also be in inverse. Note that to prevent the
screen from appearing inverse to the user it's recommended to invert the screen
colors using command 10.
An example of such a transition (with some additional codes to make it less
visible to the user) may be found in the example animation created by
animation_demo.cpp.

11 - Player Control. Allows direct control of player position, size and color.
    Param 1 (mandatory, 0-7) - 0-3 selects a player, 4-7 selects a missile.
    Param 2 (mandatory) - set horizontal position. Note that the 4 players and
      4 missiles are normally positioned at:
      48, 80, 112, 144, 200, 192, 184, 176
    Param 3 (optional) - set player width. For players 0-3 the valid values are
      0-3. For players 4-7 the given value is written as-is to register SIZEM,
      affecting all missiles.
    Param 4 (optional) - set player color. For players 4-7 the value is always
      written to COLOR3 (the "5th player" color register), affecting all
      missiles unless set otherwise in GPRIOR (see below). Note that setting a
      player color using this command will immediately disable the DLI
      normally used for changing the PM colors for each text line. It will also
      disable any update to the boldface underlay when text is rendered (i.e.
      no bold text or automatic coloring) and prevent scrolling of the boldface
      underlay when the text screen is scrolled. If you don't want these
      changes to happen, use command 3 (Set Colors, described above) instead.
      This state can be undone by resetting the terminal with the code Esc c.

12 - GPRIOR Control.
    Param 1 (none --> 17 or $11) - value is masked with $3F (to disable the
      highest 2 bits, which would garble the display) and written to GPRIOR.

13 - PM Fill Region. Fills a block of PM memory.
    Param 1 (mandatory, 0-4) - 0-3 selects a player, 4 selects the missiles.
    Param 2 (mandatory, 0-127) - start offset of area to fill.
    Param 3 (mandatory) - size of area to fill.
    Param 4 (none --> 0) - value to fill.

14 - Set PM Shape. Fills a region of PM memory with a given bitmap.
    Param 1 (mandatory, 0-4) - 0-3 selects a player, 4 selects the missiles.
    Param 2 (mandatory, 0-127) - start offset of area to fill.
    Param 3 and on - data of bitmap to apply into PM memory.

15 - Move PM Shape. Copies memory within the PM area.
    Param 1 (mandatory, 0-4) - 0-3 selects a player, 4 selects the missiles.
    Param 2 (mandatory, 0-127) - source offset of area to copy.
    Param 3 (mandatory, 0-127) - destination offset of area to copy.
    Param 4 (mandatory) - size of area to copy.

20 - Get Inputs. Arguments are ignored. Ice-T will respond with 8 hexadecimal
      digits, each containing values read from the following locations:
      stick0; stick1; strig0 and strig1, in bits 0 and 1 respectively; consol;
      paddl0 (two digits); paddl1 (two digits).

Special codes transmitted from the Ice-T keyboard:

Numeric keypad:             Arrows: (Ctrl-Up/Down/Right/Left arrow keys)
(Shift-Ctrl-key)
                            Arrow |         Cursor key mode
 Key  | On <NumLock> Off     Key  | Reset (Numeric) | Set (Application)
------+-----+------------   ------+-----------------+------------------
  0   | 0   | Esc O p        Up   | Esc [ A         | Esc O A
  1   | 1   | Esc O q       Down  | Esc [ B         | Esc O B
  2   | 2   | Esc O r       Right | Esc [ C         | Esc O C
  3   | 3   | Esc O s       Left  | Esc [ D         | Esc O D
  4   | 4   | Esc O t
  5   | 5   | Esc O u
  6   | 6   | Esc O v
  7   | 7   | Esc O w
  8   | 8   | Esc O x
  9   | 9   | Esc O y
  -   | -   | Esc O m
  ,   | ,   | Esc O l
  .   | .   | Esc O n
Enter | ^M  | Esc O M
 PF1  | --> | Esc O P  (Shift-Ctrl-Q)
 PF2  | --> | Esc O Q  (Shift-Ctrl-W)
 PF3  | --> | Esc O R  (Shift-Ctrl-E)
 PF4  | --> | Esc O S  (Shift-Ctrl-R)

Special characters in graphics mode:

ASCII| Character in graphics mode
-----+-------------------------------------
Underscore (95): Blank
Grave accent (96): Diamond
 a    Checkerboard
 b    Two small letters ('digraph') HT, in upper-left and lower-right corners
        of character
 c    Letters FF
 d    Letters CR
 e    Letters LF
 f    Degree symbol
 g    +/- symbol
 h    Letters NL
 i    Letters VT
 j    lower-right corner of square
 k    upper-right corner
 l    upper-left corner
 m    lower-left corner
 n    crossing lines (+)
 o    horizontal line - line 1 in character
 p    horiz line - line 2
 q    line 4
 r    line 6
 s    line 8
 t    Left T            |-    (approximate appearance shown here)
 u    Right T        -|
 v    Bottom T         _|_
 w    Top T          T
 x    vertical bar      |
 y    less/equal     _<
 z    greater/equal     >_
Opening curly braces (123): Pi symbol
 | (124)    Not equal        =/=
Closing curly braces (125): UK pound symbol
Tilde (126):                Centered dot
Code 127 is ignored and has no effect, whether graphics are enabled or not.

VT-52 Mode
----------
Display and control characters are treated as in VT-102. Esc x sequences are
shown below; other escape sequences are not valid.

Esc A/B/C/D/H/J/K - equivalent to VT102 Esc [ A/B/C/D/H/J/K with no arguments.
Esc F/G - set/unset graphics mode - however the VT52 graphics characters are
  not implemented (instead the VT102 graphics are shown).
Esc I - equivalent to VT102 Esc M (move up one line, can scroll).
Esc = and Esc > - set/reset numlock mode as in VT102 mode
Esc Y - expects two additional characters as arguments n1 and n2. Arguments
  are encoded as ASCII 31 plus the argument's value. Result is equivalent to
  VT102 Esc [ n1 ; n2 H (position cursor)
Esc Z - responds with identifier code: Esc / Z
Esc < - switch back to VT102 mode (has no effect if VT52 mode forced by user).

Special codes sent from the keyboard in VT-52 mode:

Numeric keypad:             Arrows: (Ctrl-Up/Down/Right/Left arrow keys)
(Shift-Ctrl-key)
                            Arrow |
 Key  | On <NumLock> Off     Key  | Code
------+-----+------------   ------+------
  0   | 0   | Esc ? p       Up    | Esc A
  1   | 1   | Esc ? q       Down  | Esc B
  2   | 2   | Esc ? r       Right | Esc C
  3   | 3   | Esc ? s       Left  | Esc D
  4   | 4   | Esc ? t
  5   | 5   | Esc ? u
  6   | 6   | Esc ? v
  7   | 7   | Esc ? w
  8   | 8   | Esc ? x
  9   | 9   | Esc ? y
  -   | -   | Esc ? m
  ,   | ,   | Esc ? l
  .   | .   | Esc ? n
Enter | ^M  | Esc ? M
 PF1  | --> | Esc P    (Shift-Ctrl-Q)
 PF2  | --> | Esc Q    (Shift-Ctrl-W)
 PF3  | --> | Esc R    (Shift-Ctrl-E)
 PF4  | --> | Esc S    (Shift-Ctrl-R)
