3270 data stream protocol

Description
This is a simplified overview of the protocol between the host and the terminal. For a complete reference, please see the full IBM reference document.

Screen buffer
The terminal display is a visual representation of the screen buffer, which is an array of characters with attributes. The characters are in EBCDIC.

There is one location in the screen buffer for each character position on the screen. For example, a model 2 has 24 rows with 80 columns each, so it has a 1920-element screen buffer. The first 80 buffer positions are the first row of the screen, the next 80 are the second row, etc.

Fields
The host can optionally program the display buffer with fields. Fields are sections of the screen buffer with particular attributes. A field is defined by a Start Field character, which takes up a position in the buffer and is displayed as a blank.

Field attributes include:
 * Protected (read-only)
 * Numeric-only
 * Intensified display
 * Light-pen selectable
 * Foreground color
 * Background color
 * Underlining
 * Character set (code page)

A field consists of each of the screen buffer positions between successive Start Field characters, and can span rows. The Start Field character that ends a field (and starts the next one) is found by scanning to the right of each Start Field character, wrapping from the end of one row to the beginning of the next row, and wrapping from the bottom-right corner of the screen back up to the top-left corner. Thus a screen buffer with just one Start Field character has one gigantic field, consisting of the entire screen (except for the Start Field character itself).

A screen buffer with at least one field is said to be formatted. A screen buffer with no fields is said to be unformatted.

x3270, c3270, wc3270 and wx3270 include options to make Start Field characters and other control characters visible, for debugging purposes.

AIDs
When the terminal wants to send data to the host, it sends an Attention IDentifier (AID). There are distinct AIDs associated with the Clear key, the Enter key, the four Program Attention keys (PA1 through PA4), and twenty-four Program Function keys (PF1 through PF24).

The AID sent to the host also includes the contents of all of the modified fields on the screen, with EBCDIC NUL characters removed.