vga_setmode - sets a video mode
int vga_setmode(int mode);
selects the video mode
and clears the screen (if it was a graphics mode). Basically this should be
the first action of your application after calling vga_init
finding out which mode to use. Prior to exiting your application should call
returns 0 on success and -1 if this mode is not available.
From svgalib-1.4.1, if mode
is -1 then vga_setmode() returns the current
svgalib version, in BCD format, so svgalib 1.4.1 returns 0x1410.
should be one of the following, predefined values, or generally a
value in range 1 <= mode <= vga_lastmodenumber()
(3) returned details about this mode. Instead of
trying to set the mode, vga_hasmode
(3) determines if the mode would
actually be supported. It is also possible to use the numeric values given
below though this is discouraged. They are commonly used as values for the
environment variable to set the
Here are the predefined values for mode
(0) restores textmode and falls back to ordinary text console
handling. All other calls switch to a graphics mode. You should set this mode
prior to exiting an svgalib application.
In general, for all modes following, the first number is the amount of x pixels,
the second the amount of y pixels, the third the number of colors, with
shortcuts 32K, 64K, 16M, 16M4 for 32768, 65536, and 1677721. Those with 2 or
more than 256 colors use fixed color mappings (either black and white or some
RGB true/high color) the others make use of a color lookup table.
Memory layout for the VGA modes is weird. Too weird to be explained here, but
you can check the usual VGA literature. vga_setmodeX
(3) has a short
explanation which is valid for all 256 color modes.
(8), and G640x480x2
These use linear 256 color memory layouts similar to G320x200x256
These also use linear memory layouts, but for 32K & 64K each pixel occupies
two bytes and three for 16M. For 32K, each 16 bit word is divided into 555 bit
portions refering to 5 bit red, green, blue part. The most significant bit is
ignored by the card. For 64K the division is 565 allowing to specify green in
a little bit more detail (Human eyes are more sensitive to green. People joke
this is because our ancestors lived in trees where light was filtered through
For the 16M modes, from low to high addresses the 3 bytes are named BGR and
specify the blue, green, red parts of the pixel value.
Memory layout is probably one nibble per pixel, two pixels per byte in a linear
fashion where the most significant nibble is the left most pixel.
(30), and G1280x1024x16
Again check out the ordinary VGA literature for the memory layout.
These are similar to 16M but each pixel uses four bytes. The first three are
similar to 16M but the fourth is left empty and ignored by the VGA card (you
can store own status there).
This eases pixel address calculations on the screen and drawing operations.
However, 1/3 more data has to be moved to the screen. Experiments show that
usually the higher memory bandwidth used outweighs the effects of the
simplified algorithms by far.
(36), and G1280x1024x16M32
It should by now be clear how the modes will look.
(6) produces a list of supported modes for your hardware,
prints some info on the modes and allows you to try each of them.
This manual page was edited by Michael Weller
<email@example.com>. The exact source of the referenced
function as well as of the original documentation is unknown.
It is very likely that both are at least to some extent are due to Harm
Occasionally this might be wrong. I hereby asked to be excused by the original
author and will happily accept any additions or corrections to this first
version of the svgalib manual.