![]()
In order to draw shapes and pictures on the screen you need a graphics mode.
Any computer that has a VGA or SVGA card can use the most basic graphics mode
which is 320 pixels wide, 200 tall, and each pixel on the screen can have one
of 256 colours that are in the palette. Every video
mode has a number to represent it when you ask the BIOS to change video modes
and the number that represents 320x200x256 mode is 0x13 (or just
plain 19 in decimal, but most use 13 hex, they're the same thing).
In order to tell the BIOS that you want to set a video mode you must call the BIOS's video-interrupt. If you don't know what an interrupt is, you can think of it as just a function you can call that will always be in any PC with a standard BIOS (I've never seen a PC that didn't), but the function is not in your program's memory but in the BIOS's. Every PC has machine language instructions to call interrupts from your software so when you call an interrupt of any specified number (interrupts have numbers, not names) your programs execution will jump far away and execute the code in the interrupt and then return to the place where you called it.
The number used for the video-interrupt is 0x10 (16 in decimal) and so the code
below will set two of the CPU registers and then call interrupt 0x10 to set
any video mode ...
void setVideoMode(char mode) {
asm mov ah,0 //'ah' register must be 0 (set-video-mode)
asm mov al,[mode] //'al' register must contain desired mode
asm int 10h //Instruction that calls interrupt 0x10
}
To use this function in a simple program you might do this ...
For further explanation of how to actually work with this mode see
Accessing the VGA.
void main(void) {
... //Do any startup code here
setVideoMode(0x13); //Switch screen to graphics mode
... //Put your main-loop here
setVideoMode(0x03); //Once its done, set mode 3 to get back
//DOS text-mode (you must do this, its not automatic)
}
A Note on Hexadecimal ... (incase you're curious)
Usually you will see mode 19 referred to as mode 0x13 (in C) because 13 is the hexadecimal
equivilant of 19. "Hexawhat?" you may ask, and if you haven't been into computers
for long you probably won't know what it is.
Hexadecimal is works just like decimal except it has a different range of numbers
for each digit. Instead of having 10 different
symbols for each digit (0-9) there are 16 (0-F). If you were counting from 0 to 9 in
hexadecimal, it would be exactly like you'd expect from decimal. However, if you counted to 20
the line of hexadecimal numbers would continue taking only one digit until it
went past the letter F.
For example -
DEC: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20 ... HEX: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F,10,11,12,13,14 ...
So as you can see, 13-hex is the same as 19 decimal. What's the relevancey of this hexadecimal crap? Hexadecimal fits into the binary sceme that computers use much better than decimal and its much easier to recognize key values in hex than decimal ... for instance:
16 = 0xF 128 = 0x80 255 = 0xFF 65357 = 0xFFFFOk ok, so I can't think of a good example now but the need for Hex sometimes arises and pretty much all DOS interrupt stuff is represented in Hex so its a good idea to get used to it.