5250 colors and display attributes
The IBM 5250 data stream was devised in the 1970's. Color was not thought of, even though color displays were well known for a long time from TV. After the later introduction of color displays for computer terminal screens, already established display attributes were reused for indicating which color something on the screen should have.
Display attributes include properties like e. g. "bright" (high intensity), underlined, blinking, and column separators[1] for elements and text on screen.
Display attributes are encoded in a single, otherwise invisible screen position directly preceding the screen element(s) the attribute is applied to. The attribute stays in effect up to the next attribute on screen.[2] This attribute byte can be modified with the DDS keywords COLOR and DSPATR and indicators. Since indicators are limited in count, conditionally applying many attributes to many screen objects can quickly exhaust the number of available indicators for a given screen (record format).[3] One way around this is a USRDFN record format, where the program assembles the 5250 data stream itself, including the attribute bytes listed below.
Attributes
The basic display attributes are specified as follows. Bits counted from right to left (LSB to MSB). Note: IBM counts the other way! IBM's bit numbers are given in the second column; RPG's BITON/BITOFF also use IBM's numbering.
| Bit | IBM bit | Value | Attribute (DSPATR-Name) |
|---|---|---|---|
| 0 | 7 | 1 | Reverse Image (RI) |
| 1 | 6 | 2 | High Intensity (HI) |
| 2 | 5 | 4 | Underline (UL) |
| 3 | 4 | 8 | Blink (BL) |
| 4 | 3 | 16 | Column separator (CS) |
| 5 | 2 | 32 | Attribute identification flag, always 001 |
| 6 | 1 | 64 | |
| 7 | 0 | 128 |
If underline, high intensity and reverse image are all set, the field is not displayed (nondisplay, ND). Hence, valid attribute bytes are in the range 0x20 to 0x3f.
Protecting a field is not an attribute. See Input fields and protection.
Attribute to color mapping
As stated, color was introduced later. Hence, display attribute bits have been reused for setting color:
- Blink = Red (not blinking)
- Column separator = Turquoise (cyan)
- High intensity = White
Further colors can be displayed by combining bits 1, 3, and 4:
- Blink, high intensity = Red, blinking
- Blink, column separator = Pink (magenta)
- Blink, column separator, high intensity = Blue
- Column separator, high intensity = Yellow
Red is the only color which can blink. On a color display, high intensity only selects a color, text is never shown brighter.
Normally, you don't need to memorize all of that, but just use the DDS COLOR(xxx) keyword to enable the available colors:
| Desired color | DDS COLOR statement | equivalent DDS DSPATR statement |
|---|---|---|
| White | COLOR(WHT) | DSPATR(HI) |
| Red | COLOR(RED) | DSPATR(BL) |
| Green | COLOR(GRN) | |
| Blue | COLOR(BLU) | DSPATR(BL CS HI) |
| Yellow | COLOR(YLW) | DSPATR(CS HI) |
| Pink (magenta) | COLOR(PNK) | DSPATR(BL CS) |
| Turquoise (cyan) | COLOR(TRQ) | DSPATR(CS) |
Nondisplay (DSPATR(ND)) is not a color: The data is still present in the display buffer, and input is accepted. This is commonly used for password fields.
All colors can be combined with the Reverse Video (RI) attribute to have black letters on colored background.[4] Reverse image plus underline is not possible with white, yellow, and blue, because these combinations already mean nondisplay (0x27, 0x37, 0x3f).
Depending on the settings of the used color display terminal or emulator, attributes and color might be shown concurrently. This is most apparent when setting the color of an input capable field to cyan, and the result not only is cyan, but also looks weird, due to column separators being displayed. On IBM color display stations, they disappear by reconfiguring the display for reduced line spacing. Most emulators have a configuration setting to only show colors and not apply attributes being reused for specifying color.[5]
Table of valid attribute byte values
Colors as documented in the 5494 Remote Control Unit Functions Reference.[6]
| Hex | Binary | Color | Attribute(s) | Screen appearance |
|---|---|---|---|---|
| 0x20 | 0b00100000 | GRN | Green | |
| 0x21 | 0b00100001 | GRN | RI | Green, reverse image |
| 0x22 | 0b00100010 | WHT | White | |
| 0x23 | 0b00100011 | WHT | RI | White, reverse image |
| 0x24 | 0b00100100 | GRN | UL | Green, underline |
| 0x25 | 0b00100101 | GRN | UL RI | Green, underline, reverse image |
| 0x26 | 0b00100110 | WHT | UL | White, underline |
| 0x27 | 0b00100111 | ND | Nondisplay | |
| 0x28 | 0b00101000 | RED | Red | |
| 0x29 | 0b00101001 | RED | RI | Red, reverse image |
| 0x2a | 0b00101010 | RED | BL | Red, blink |
| 0x2b | 0b00101011 | RED | BL RI | Red, reverse image, blink |
| 0x2c | 0b00101100 | RED | UL | Red, underline |
| 0x2d | 0b00101101 | RED | UL RI | Red, underline, reverse image |
| 0x2e | 0b00101110 | RED | UL BL | Red, underline, blink |
| 0x2f | 0b00101111 | ND | Nondisplay | |
| 0x30 | 0b00110000 | TRQ | CS | Turquoise, column separator |
| 0x31 | 0b00110001 | TRQ | CS RI | Turquoise, column separator, reverse image |
| 0x32 | 0b00110010 | YLW | CS | Yellow, column separator |
| 0x33 | 0b00110011 | YLW | CS RI | Yellow, column separator, reverse image |
| 0x34 | 0b00110100 | TRQ | UL CS | Turquoise, underline, column separator |
| 0x35 | 0b00110101 | TRQ | UL RI CS | Turquoise, underline, reverse image, column separator |
| 0x36 | 0b00110110 | YLW | UL CS | Yellow, underline, column separator |
| 0x37 | 0b00110111 | ND | Nondisplay | |
| 0x38 | 0b00111000 | PNK | Pink | |
| 0x39 | 0b00111001 | PNK | RI | Pink, reverse image |
| 0x3a | 0b00111010 | BLU | Blue | |
| 0x3b | 0b00111011 | BLU | RI | Blue, reverse image |
| 0x3c | 0b00111100 | PNK | UL | Pink, underline |
| 0x3d | 0b00111101 | PNK | UL RI | Pink, underline, reverse image |
| 0x3e | 0b00111110 | BLU | UL | Blue, underline |
| 0x3f | 0b00111111 | ND | Nondisplay |
Arithmetics of attributes
Because the meaning of attributes or color is well defined, many lines of IF or SELECT statements in RPG can possibly be substituted by BITON/BITOFF operations.
Start with 0x20, and add (OR) the attribute values: RI 0x01, HI 0x02, UL 0x04, BL 0x08, CS 0x10. Keep in mind:
- BITON/BITOFF count bits from the left. RI is bit '7', CS is bit '3'.
- Setting UL, HI and RI together results in nondisplay.
Input fields and protection
In a hand-made 5250 data stream, the attribute byte appears in two places.
Output-only text is written with a Set Buffer Address (SBA, 0x11) order, followed by row, column, the attribute byte, the text, and a closing attribute (usually 0x20). The closing attribute must be written by the program. Otherwise, the attribute stays in effect up to the next attribute on screen. Such text cannot be typed over, because it is not an input field.
Input fields are defined with a Start of Field (SF, 0x1d) order. The SBA order before it addresses the position of the leading attribute.
| SF | FFW | FCW | Attribute | Length |
|---|---|---|---|---|
| 0x1d | 2 bytes | optional, 2 bytes each | 1 byte | 2 bytes |
The terminal (or 5494) distinguishes the Field Format Word (FFW) from the attribute by the leading bits: FFW starts with 01, the attribute with 001. For input fields, the terminal writes the leading and ending attributes itself.
Protection is set by the bypass bit (IBM bit 2) of the FFW. With all other FFW bits clear, the first FFW byte is 0x40 for a normal input field, and 0x60 for a protected (bypass) field. This is what DSPATR(PR) ends up as in the data stream.
Weblinks
- COLOR (Color) keyword for display files, IBM DDS reference
- DSPATR (Display Attribute) keyword for display files, IBM DDS reference
- IBM 5250, Wikipedia
Literature
- IBM 5494 Remote Control Unit: Functions Reference, SC30-3533, chapter Start of Field Order
Footnotes
- ↑ That was thought as an aid to precisely know where characters were placed in an on-screen editable field. Appearing somewhat confusing to the common eye, real world usage was probably not very widespread.
- ↑ The DDS logic takes care to switch off set attributes after a screen element's end. When assembling a 5250 data stream by hand, see below for information about ending the attribute.
- ↑ It should be noted that in a subfile, each record has an independent set of indicators.
- ↑ This should be used sparsely, because it's very eye straining.
- ↑ Due to reusing of attribute bits, changing this setting disables the display of color-mapped attributes globally. You can't then display one field with e. g. column separators. Instead, the field is then colored cyan.
- ↑ The DDS reference lists 0x2a and 0x2b as red with high intensity instead of blink, and 0x33 as white instead of yellow. Its own description of COLOR and DSPATR on color displays agrees with the values given here.