You have to declare your screen somewhere, and the address of the screen buffer in memory is 0xA0000000 (hexidecimal). So you say:

unsigned char *Screen = (unsigned char *) 0xA0000000;

why do you declare it as an unsigned char *? Because 13h is a 256 color mode...and unsigned char ranges from 0 to 255. So you declare a variable called Screen and give it the address of the screen so you can write directly to it.

Next you have the initGraph function which initializes (starts) 13h graphics mode:

void initGraph (void)
{
asm {
mov ax, 13h
int 10h
}
}

To understand this code you have to understand assembler. The command int in assembler means interrupt. It is kind of like calling a function in C++. Each interrupt has parameters, like functions in C++. interrupt 21h (h is for hexidecimal) is the command to output to the screen. So if I did this:

mov dl, 2
mov ah, 0
int 21
int 20

That would output a single character, a smiley face. Why? Because int 21 takes the two parameters, the registers dl and ah, and looks at them. dl tells it what to do. If dl is 2, then it means to output a single character. Then it looks at ah for what to output. It outputs the character 0. Then int 20 is like return 0 in C++.

So lets apply this knowledge to the 13h asm code. interrupt 10h is the interrupt to change screen modes. It takes the parameter ax and looks at. The parameter contains 13h, so it knows to go to mode 13h.

Now lets look at the finishGraph function:

void finishGraph (void)
{
asm {
mov ax, 03h
int 10h
}
}

This uses interrupt 10 again, and calls mode 3. Mode 3 is a text mode, so basically when we call this function we are exiting 13h and going back to a normal text mode.

So how do we implement all of this code? Well, look at this small example:

int main (void)
{
initGraph();

Screen[0] = 3;

getch();
finishGraph();
return 0;
}

This makes the pixel on the top left corner of the screen a kind of turquoise color. Now, why did I do that to draw to the screen?

When we did this:

unsigned char *Screen = (unsigned char *) 0xA0000000;

We created a pointer called Screen which pointed to an unsigned char. Now, 0xA0000000 is the address of the screen, and it is an array of 64000 unsigned chars. The screen is linear. Each row of the screen is 320 pixels, and there are 200 rows, creating a total of 64000 pixels. So if we wanted to plot a pixel to the second row, first pixel on the row, we would say Screen[320] = color. Why would we say 320? Because the first row goes from 0 to 319, and the second row STARTS on 320 and goes to 639, etc.

So that is a basic lesson on the screen in 13h. I will give you one more function. This will allow you to plot to the screen in (x,y) terms so you dont have to bother with all that Screen[xxx] = color stuff:

When I try it, I don't get any errors, but there are not pixels on the screen. I tried changing the position of the pixels, so it's not a faulty screen configuration. Is there someway to tell the screen to update or something of that nature?