Search code examples
cgraphicscolorsbitmapvga

Trouble drawing pixels in 640x480 16-color VGA mode


I am trying to draw a single red pixel in VGA video mode 12 in C. The code that I have written works as expected in video mode 13 (200p 256 colors).

volatile char *video = (volatile char*) 0xA0000;
*video = 4;

In video mode 13, a single red pixel is drawn on-screen. This is what I want to happen in video mode 12. When this code is used with video mode 12, what appear to be representations of the bits in the byte sent are displayed (i.e. the byte 00011000 is copied, three black pixels, two white pixels, and three more black pixels are displayed.


Solution

  • The 16 color mode is planar, which means one byte is eight pixels and will set the specific bits of the pixels. There is a mask register in port 0x3c4 index 2 where you set which planes you want to set when you write to the memory. It’s a lot more complicated than using a byte-per-pixel mode.

    You can get more information about the Plane Write Enable register and different graphics modes from for example the OSDev Wiki