Microsoft KB Archive/75274

{|
 * width="100%"|

16 Background Colors in Text Mode with MCGA, EGA, or VGA

 * }

Q75274

-

The information in this article applies to:


 * The C Run-Time (CRT), included with:
 * Microsoft C for MS-DOS, versions 5.1, 6.0, 6.0a, and 6.0ax
 * Microsoft C/C++ for MS-DOS, version 7.0
 * Microsoft Visual C++, versions 1.0, 1.5

-

SUMMARY
The attribute byte for video display in text mode is

    7  6  5  4   3   2  1  0 -   | |         |   |         |     - where the bits control the following:

  Bits  Control --  0-2   Foreground color 3  Foreground intensity 4-6  Background color 7  Blinking for foreground - or - Intensity for background A total of 16 foreground colors are possible with the combination of bits 0-3. If bit 7 is on (default), these colors can be optionally blinking, for a combination of 32 foreground colors.

Eight background colors are possible with the combination of bits 4-6. With an MCGA, EGA, or VGA, bit 7 can be toggled to be interpreted as background intensity rather than the default blinking color. Doing so makes 16 background colors available in text mode.

MORE INFORMATION
The BIOS call that toggles the interpretation of bit 7 is Interrupt 10h, function 10h, subfunction 03h. This call is available only with an MCGA, EGA, or VGA. A zero (0) in BL enables intensity, a one (1) in BL enables blinking text.

The following sample program illustrates the effect of this toggle. First, bit 7 is left as the blink bit; therefore, there are eight background colors and 32 foreground colors. Each of the 32 foreground colors is displayed once and each background color is repeated four times.

Next, bit 7 is toggled to intensity; therefore, there are 16 background colors and no blinking text. Still, you have to go through foreground colors 0-31 to view all 16 background colors. This is because bit 7 is still controlled in the setting of the foreground color; however, it is now interpreted to affect the display of the background color rather than the foreground color. Viewing the output of the sample program should clarify this concept.

Sample Code
/* Compile options needed: none void toggle_intensity( int ); void main {  long i;   int row; int color; char buf[80]; _settextrows( 43 ); _clearscreen( _GCLEARSCREEN ); toggle_intensity( 1 ); /* Bit 7 = blink; there are 8 background colors and blinking text */ for (i = 0, row = 1, color = 31; i <= 31; i++, row++, color--) {     _setbkcolor( i ); _settextcolor( color ); _settextposition( row, 10 ); sprintf( buf, &quot; Background %2ld  Foreground %2d\n&quot;, i,color ); _outtext( buf ); }  _setbkcolor( _BLACK ); _settextcolor( 7 ); _outtext( &quot;\n\nSetting 8 background colors, blinking text.&quot; ); _outtext( &quot;\n\nStrike any key to continue...&quot; ); getch; _clearscreen( _GCLEARSCREEN ); toggle_intensity( 0 ); /* Bit 7 = intensity; there are 16 background colors */ for (i = 0, row = 1, color = 31; i <= 31; i++, row++, color--) {     _setbkcolor( i ); _settextcolor( color ); _settextposition( row, 10 ); sprintf( buf, &quot; Background %2ld  Foreground %2d\n&quot;, i,color ); _outtext (buf); }  _setbkcolor( _BLACK ); _settextcolor( 7 ); _outtext( &quot;\n\nSetting 16 background colors, no blinking text.&quot; ); _outtext( &quot;\n\nStrike any key to quit...&quot; ); getch; _setvideomode( _DEFAULTMODE ); _clearscreen( _GCLEARSCREEN ); } void toggle_intensity( int onoff ) {  union REGS regs; regs.h.ah = VIDEO_IO; regs.h.al = INTENSITY_TGL; if ( !onoff ) regs.h.bl = 0x0; else regs.h.bl = 0x1; int86( BIOS_CALL, &regs, &regs ); } Additional query words: kbinf 1.00 1.50 5.10 6.00 6.00a 6.00ax 7.00
 * 1) include 
 * 2) include 
 * 3) include 
 * 4) include 
 * 5) define TRUE 1
 * 6) define FALSE 0
 * 7) define VIDEO_IO       0x10
 * 8) define BIOS_CALL      0x10
 * 9) define INTENSITY_TGL  0x03
 * 1) define INTENSITY_TGL  0x03

Keywords : kb16bitonly

Issue type :

Technology : kbVCsearch kbAudDeveloper kbCRT