The k project

The framebuffer

Video memory is directly mapped to memory areas from 0xA0000 to 0xBFFFF. There are different graphic mode, and therefore different framebuffers. For now, let us stick with the default mode: color text mode. This mode allow us to write 25 rows of 80 columns and to use colors. Its buffer starts at address 0xB8000: everything written in this buffer is displayed on the screen.

This buffer works as a big unidimensional array. Each cell is represented by two bytes: the character and then its color parameters (see below).

Character definition

Here is the description of each byte of a text framebuffer character:

Bit  Color        Function

15     B    Background intensity
14     R      Background color
13     G      Background color
12     B      Background color
11     I    Foreground intensity
10     R      Foreground color
9      G      Foreground color
8      B      Foreground color
0-7    -         ASCII code

Here is the color table:

I  R  G  B   Color

0  0  0  0   Black
0  0  0  1   Blue
0  0  1  0   Green
0  0  1  1   Cyan
0  1  0  0   Red
0  1  0  1   Magenta
0  1  1  0   Brown
0  1  1  1   White
1  0  0  0   Gray
1  0  0  1   Light Blue
1  0  1  0   Light Green
1  0  1  1   Ligth Cyan
1  1  0  0   Light Red
1  1  0  1   Light Magenta
1  1  1  0   Yellow
1  1  1  1   White (high intensity)

I stands for intensity, R for red, G for green and B for blue.

Example

The following C code displays the character ‘k’ on the zeroth line, twelveth column with a red foreground on a blue background:

char* video_mem = (void*) 0xb8000;
video_mem[(0 * 80 + 11) * 2] = 'k';
video_mem[(0 * 80 + 11) * 2 + 1] = 0x14;

Example