(This tutorial was originally written in 2004 and featured in http://asm.inightmare.org/)
This is my second tutorial on Graphics programming and now we’re going to see how palette is programmed.
When operating in video mode 13h or even 12h it’s sometimes necessary to adjust palette colors. For example to adjust to match colors of image being displayed or different scenery of a computer game, this way it is possible to show more colors than the mode actually supports.
There are two ways to do this: 1) by using direct access to video ports; 2) using BIOS interrupts (preferred)
Now lets looks how palette color management using Video BIOS looks like:
mov ax,1010h ; Video BIOS function to change palette color |
Easy like that. OK now lets read the palette.
mov ax,1015h |
Return values are: dh = red color component; ch = green color component; cl = blue color component.
Now lets try this using direct access to video card ports, I don’t recommend doing this unless really needed (for pmode OSes).
Ports: 3C8h is used to set color (output color index), 3C7h is used for reading palette values (output color index), and 3C9h is used to output color component data in RGB.
mov al,0 ; set to 0 for color 0 |
Now reading works like this:
mov dx,3C7h ; palette data read port |
That’s it. I hope I helped. And always use interrupts if possible, because data port way sometimes has errors and red color component is not always set. Good luck!