Microsoft KB Archive/59952

How to Get High-Intensity BACKGROUND-COLOR with COBOL DISPLAY

PSS ID Number: Q59952 Article last modified on 03-27-1990

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: When DISPLAYing literals or data-names in COBOL, the foreground and background colors for the item can be specified with the FOREGROUND-COLOR and BACKGROUND-COLOR clauses. A high-intensity (8 through 15) foreground color can be achieved by using the HIGHLIGHT clause, but HIGHLIGHT has no effect on the background color. Achieving a high-intensity background color in a DOS program involves calling interrupt 10 Hex, function 10 Hex, subfunction 03 Hex. The interrupt is used to cause the most significant bit of a character attribute to toggle on/off an intensified background color rather than a blinking foreground color. Nothing extra needs to be done to get a high-intensity background color for an OS/2 protected mode program. The high-intensity colors (8 through 15) are displayed properly when used with the BACKGROUND-COLOR clause. This information applies to Microsoft COBOL Compiler Versions 3.00 and 3.00a for MS-DOS and MS OS/2.

More Information: In a DOS (or OS/2 real mode) program, if a high-intensity color is used with the BACKGROUND-COLOR clause and the above interrupt has not been called, the background color is not in high intensity and the foreground color blinks. This is because by default the most significant bit of a character attribute is used to set foreground blinking on or off. Using colors 8 through 15 sets this bit, and thus turns blinking on. In addition, the background color itself is not correct; the actual color displayed is the background color that was specified minus 8. After the interrupt is called, however, setting the bit enables high intensity, and the color displays correctly. The following examples demonstrate how to get a high-intensity background color in a DOS (or OS/2 real mode) program (Example 1) and in the equivalent OS/2 protected mode program (Example 2), which uses high-intensity background colors by default. The interrupt that controls whether the most significant bit of a character attribute specifies blinking or intensity uses 2 registers, AX and BX. The high byte of AX (A-H) must have the value 16 (or 10 Hex) and the low byte (A-L) must be 3 (03 Hex). This specifies function 10 Hex, subfunction 03 Hex. The BX register must contain a 0 (zero) to enable intensity and a 1 to enable blinking. The last example program (Example 3) illustrates how a high-intensity background color is displayed improperly and makes the foreground blink if the interrupt isn’t called. This is the default behavior. For more information on calling interrupts from COBOL 3.00 and 3.00a, consult Pages 8-4 to 8-5 of the “Microsoft COBOL Compiler 3.0: Operating Guide.” For more information on the format and use of character attributes, consult Pages 6-1 to 6-5 of the “Microsoft COBOL Compiler 3.0: Operating Guide.” For more information on interrupt 10 Hex, function 10 Hex, subfunction 03 Hex, consult Page 513 of “Advanced MS-DOS Programming, 2nd Edition” by Ray Duncan (Microsoft Press, 1988).

Example 1 (DOS or OS/2 Real Mode)
Compile and link as follows: cobol example1; link example1 adis adisinit adiskey; DATA DIVISION. WORKING-STORAGE SECTION. * interrupt 10H. 01 INTERRUPT PIC X VALUE X“10”. * load actual registers with CALL X“84” parameters. 01 FLAG PIC X VALUE X“FF”. 01 AX. * function 16. 05 A-H PIC 99 COMP-X VALUE 16. * subfunction 3. 05 A-L PIC 99 COMP-X VALUE 3. 01 BX. 05 B-H PIC 99 COMP-X. * select intensity. 05 B-L PIC 99 COMP-X VALUE 0. 01 CX. 05 C-H PIC 99 COMP-X. 05 C-L PIC 99 COMP-X. 01 DX. 05 D-H PIC 99 COMP-X. 05 D-L PIC 99 COMP-X. PROCEDURE DIVISION. * call the interrupt to set high intensity. CALL X“84” USING INTERRUPT, FLAG, AX, BX, CX, DX. DISPLAY “YELLOW IS A HIGH INTENSITY BACKGROUND” WITH FOREGROUND-COLOR 2 BACKGROUND-COLOR 14. STOP RUN.

Example 2 (OS/2 Protected Mode)
Compile and link as follows: pcobol example2; link /nop example2 adis adisinit adiskey,,,pcobol doscalls; PROCEDURE DIVISION. * high intensity background is default in protected mode. DISPLAY “YELLOW IS A HIGH INTENSITY BACKGROUND” WITH FOREGROUND-COLOR 2 BACKGROUND-COLOR 14. STOP RUN.

Example 3 (DOS or OS/2 Real Mode)
Compile and link as follows: cobol example1; link example1 adis adisinit adiskey; PROCEDURE DIVISION. * yellow (color 14) - 8 gives brown (color 6), * also the green foreground will blink. DISPLAY “YELLOW WITHOUT INTENSITY ON IS BROWN” WITH FOREGROUND-COLOR 2 BACKGROUND-COLOR 14. STOP RUN.

Copyright Microsoft Corporation 1990.