Kenji
Kenji

Reputation: 11

How to obtain other color combinations in Assembly Language?

Good Day/Evening!

I've been trying to figure out how to obtain the indigo color in assembly language.

Here is my sample code:

mov ah, 06h
mov bh, 10h ; 8.Blue
mov ch, 13
mov cl, 0
mov dh, 16
mov dl, 11
int 10h

Thanks in advance!

Upvotes: 0

Views: 2065

Answers (1)

Margaret Bloom
Margaret Bloom

Reputation: 44046

TL;DR

Use this interrupt service.
Sorry for this long answer, I was really bored this evening.


Unfortunately there is no such color as Indigo in the original CGA palette, which was fixed in hardware and thus not open for customization.

CGA had 4 bits color depth, in what was called IRGB format: bit 2 was Red, bit 1 was Green, bit 0 was Blue and bit 3 was Intensity. These bits drove the equivalent signals in the output connector of the display adapter, thus the palette wasn't really there, leaving to the monitor the burden of converting them into analog voltage signals.

However chances are that your are not really using a true IBM CGA display adapter but rather a video card of a reasonable recent era.
After the CGA, came the EGA which introduced an indexed color system: you have 16 numbers, for each number you can associate a color of you choice from a total of 64. When coloring pixels/characters you use one of the sixteen numbers, called indices.

For backward compatibility the color associated with each index is the same as the color a CGA adapter would display for said index.

After the EGA was the turn of original VGA, the original VGA is still important because it is still supported (through emulation) by possibly all modern video cards and it is the last true hardware interface standard1.
And it is the mode you are going to use for you programming.

VGA, in its time, quenched the quest for more colors by widening the RGB mode to 6 bit per channel, or a total of 262.144 possible colors, a number which is better known as 218.

In some mode, the original VGA also enlarged the index space, the number of numbers, to 256 indices.

You want to know how to get an Indigo on VGA display adapter

Among the 256 default colors of VGA there seems to be no Indigo, colors #34, #56, #57 are a close catch but not really an Indigo (see: VGA default colors).

But you now know that VGA has plenty of colors, not just those 256 preset!
You can pickup the best approximation of Indigo and assign it to an index.

1. Finding the best approximation

Indigo is, according to Wikipedia, #4B0082, or a 4Bh component of Red (29,41% of brightest red), 00h component of blue (0% of brightest green), 82h component of blue (50,98% of brightest blue).

The VGA max value for a color is 26-1 or 63, so translating this percentages into numbers using this new maximum values give us the RGB triplet (12h, 00h, 20h).

2. Assign the triplet to an index

You can let the BIOS do it, with a very simple interrupt service.
You can do it yourself programming the hardware registers, here a more useful reference.

You write the index number (as a byte) to the port 3c8h, then perform three consecutive writes to the port 3c9h to set the Red, Green, Blue component respectively. These last three bytes written are masked to their lower six bits.

For example you can change the default red (12, or 0ch) with this code

;Using the BIOS                               ;Without BIOS
mov ax, 1010h                                 mov dx, 3c8h  ;Color write port
mov bx, 0ch      ;0ch is Red                  mov al, 0ch   ;Red index
mov dh, 12h      ;Red component               out dx, al   
mov cx, 20h      ;Green & Blue components     inc dl        ;Data port
int 10h                                       mov al, 0ch   ;Red component
                                              out dx, al
                                              xor al, al    ;Green component
                                              out dx, al
                                              mov al, 20h   ;Blue component
                                              out dx, al

BEWARE
While in mode 13h you can directly use the index number, in text mode this may not be true. The characters attributes may not be mapped to indices in a straightforward way. In my old video card I have seen that the first 8 attributes (from 00h to 07h) were mapped to their identical indices, but the attributes from 08h to 0fh are mapped to a continuous block of 8 indices starting in the middle of index space.

I don't recognize the interrupt service you are using, so I cannot really tell how you are going to use these indices and be more specific.


This is a CGA legacy.
EGA used a RGB color mode, with 2 bit per channel; with a total color depth of 6 bit, or 26 colors
1 VESA tried to promote a standardized software interface, but then the video cards became more and more complex and competitive among each others.

Upvotes: 2

Related Questions