The Color Registers in the standard VGA provide a mapping between the palette of between 2 and 256 colors to a larger 18-bit color space. This capability allows for efficient use of video memory while providing greater flexibility in color choice. The standard VGA has 256 palette entries containing six bits each of red, green, and blue values. The palette RAM is accessed via a pair of address registers and a data register. To write a palette entry, output the palette entry's index value to the DAC Address Write Mode Register then perform 3 writes to the DAC Data Register, loading the red, green, then blue values into the palette RAM. The internal write address automatically advances allowing the next value's RGB values to be loaded without having to reprogram the DAC Address Write Mode Register.  This allows the entire palette to be loaded in one write operation. To read a palette entry, output the palette entry's index to the DAC Address Read Mode Register. Then perform 3 reads from the DAC Data Register, loading the red, green, then blue values from palette RAM. The internal write address automatically advances allowing the next RGB values to be written without having to reprogram the DAC Address Read Mode Register.

Note: I have noticed some great variance in the actual behavior of these registers on VGA chipsets. The best way to ensure compatibility with the widest range of cards is to start an operation by writing to the appropriate address register and performing reads and writes in groups of 3 color values. While the automatic increment works fine on all cards tested, reading back the value from the DAC Address Write Mode Register may not always produce the expected result. Also interleaving reads and writes to the DAC Data Register without first writing to the respected address register may produce unexpected results. In addition, writing values in anything other than groups of 3 to the DAC Data Register and then performing reads may produce unexpected results. I have found that some cards fail to perform the desired update until the third value is written.

 
DAC Address Write Mode Register (Read/Write at 3C8h)
7 6 5 4 3 2 1 0
DAC Write Address
   
DAC Address Read Mode Register (Write at 3C7h)
7 6 5 4 3 2 1 0
DAC Read Address
   
DAC Data Register (Read/Write at 3C9h)
7 6 5 4 3 2 1 0
DAC Data
   
DAC State Register (Read at 3C7h)
7 6 5 4 3 2 1 0
DAC State
 

Notice: All trademarks used or referred to on this page are the property of their respective owners.
All pages are Copyright © 1997, 1998, J. D. Neal, except where noted. Permission for utilization and distribution is subject to the terms of the FreeVGA Project Copyright License.