|
The best way I found to plot pixels is to use an
unsigned char far pointer to the memory address 0xA0000000L, which is the
begginning memory address for the video memory in mode 13h. So to plot a
pixel all you need to do is after you put the video card in mode
13h:
/*Assign this somewhere as a global
declaration*/
unsigned char far
*video_buffer=0xA0000000L;
/*Call this function to plot a pixel*/
void Write_Pixel(int x, int y, int
nColor)
{
video_buffer[(y<<8)+(y<<6)+x]=(unsigned char)nColor;
}
The video memory must have colors recorded in
unsigned characters, because it's the only thing the video card
understands. It's like machine code. And then the reason for the
weird looking "(y<<8)+(y<<6)+x" for the coordinates is because mode
13h is a chained memory mode. So it's just a straight line. So in
order to access an x,y coordinate, you need to multiply the y coordinate by 320
(the horizontal resolution) and then add the x. Just think about it,
you'll figure it out. Also the reason for the binary shift operators is
because it is faster than actual multiplication. 2^8 + 2^6 is 320, so
shifting the binary of y this way is the same as multiplying by 320. I
hope this helps.
|