Printing characters - random colors... [solved]
Posted: Sun Oct 25, 2009 6:05 pm
I wrote some code thats supposed to write characters to the screen. Like the title of the thread says, only every other character/even characters show up, and every character has a different foreground and background color. everything else works, the cursor is in the right place, the screen scrolls, but I can't get the colors right and have absolutely no idea why only half of the characters appear.
Look at the screenshot attached and you'll see what I mean...
Look at the screenshot attached and you'll see what I mean...
Code: Select all
unsigned char *videoram = (unsigned char *) 0xb8000;
videoram[1] = 0x17; //fore, background color
unsigned char bgColor = 1;
unsigned char fgColor = 7;
int x = 0;
int y = 0;
void put(unsigned char c)
{
unsigned short attribByte = (bgColor << 4) | (fgColor & 0x0F);
volatile unsigned short attrib = attribByte << 8;
volatile unsigned char *location;
//handle any printable character
if (c >= ' ')
{
location = videoram + (y*80 + x);
*location = c | attrib;
x++;
}
if (x >= 80)
{
x = 0;
y++;
}
cursor();
}
void write(char *c)
{
int i = 0;
while (c[i])
{
put(c[i++]);
}
}
clear();
write("Hello World");