Linux.com

Developing kernel: Hex for text color?

Link to this post 13 Sep 10

I'm developing a kernel, but I want to know the hex values for colors. I don't really know how to phrase this question, so here's the code:

#define WHITE_TXT    0x07     // white on black text
#define GREEN_TXT //what I want to know
#define BLUE_TXT //what I want to know
#define RED_TXT //what I want to know

void k_clear_screen();
unsigned int k_printf(char *message, unsigned int line);

k_main() // like main in a normal C program
{
k_clear_screen();
k_printf("mcKlos 1.0.1 -- Copyright (c) Matthew Caswell, 2010\n", 0);
}


void k_clear_screen() // clear the entire text screen
{
char *vidmem = (char *) 0xb8000;
unsigned int i=0;
while(i < (80*25*2))
{
vidmem=' ';
i++;
vidmem=WHITE_TXT;
i++;
};
};

unsigned int k_printf(char *message, unsigned int line) // the message and then the line #
{
char *vidmem = (char *) 0xb8000;
unsigned int i=0;

i=(line*80*2);

while(*message!=0)
{
if(*message=='\n') // check for a new line
{
line++;
i=(line*80*2);
*message++;
} else {
vidmem=*message;
*message++;
i++;
vidmem=WHITE_TXT;
i++;
};
};

return(1);
};

please give me a list.

Link to this post 13 Sep 10

Yeah, that would be great, and I've used that before, but this is a standalone kernel (from boot). The code in that example is for win32 console programming. This is from boot, with it's own boot loader. So, again, the hex values for primary colors?

Link to this post 14 Sep 10

Here you go, my friend:
BLACK = 00h
BLUE = 01h
GREEN = 02h
CYAN = 03h
RED = 04h
MAGENTA = 05h
BROWN = 06h
GRAY = 07h
DARK GRAY = 08h
BRIGHT BLUE = 09h
BRIGHT GREEN = 0Ah
BRIGHT CYAN = 0Bh
PINK = 0Ch
BRIGHT MAGENTA = 0Dh
YELLOW = 0Eh
WHITE = 0Fh

Link to this post 14 Sep 10

Thanks, now to add it and test it.

Link to this post 15 Sep 10

It worked great! Thanks!

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board