Global variable will not initialize correctly
Posted: Mon May 16, 2011 9:03 pm
Hi,
I have a very simple k_main() that clears the screen and prints "kernel loaded" when it is called... the print() and clr() functions are in a separate file. The function is called correctly and the clr() function works as it should, but print() does not seem to do anything at all. What isn't working here?
in the file containing clr() and print():
thanks
I have a very simple k_main() that clears the screen and prints "kernel loaded" when it is called... the print() and clr() functions are in a separate file. The function is called correctly and the clr() function works as it should, but print() does not seem to do anything at all. What isn't working here?
Code: Select all
const char *msg = "kernel loaded.";
void k_main()
{
clr();
print(msg);
idt_install();
for(;;);
}
Code: Select all
void print(const char *_message)
{
unsigned short cr_pos;
unsigned long i;
char *vidmem = (char *)0xB8000;
// Read cursor position
out(0x3D4, 14);
cr_pos = in(0x3D5) << 8;
out(0x3D4, 15);
cr_pos |= in(0x3D5);
vidmem += cr_pos*2;
unsigned short cr_x = cr_pos % 80;
unsigned short cr_y = (cr_pos - cr_x)/80;
// Continue until we reach null character
i = 0;
while (_message[i] != 0)
{
if (_message[i] == 10)
{
cr_y++;
if (cr_y == 25)
{
scroll();
cr_y = 24;
}
cr_x = 0;
unsigned int m = (unsigned int)vidmem;
vidmem += (160 - ((m - 64) % 160));
i++;
continue;
}
*vidmem = _message[i];
i++;
vidmem += 2;
cr_x++;
if (cr_x == 80)
{
cr_y++;
if (cr_y == 25)
{
scroll();
cr_y = 24;
}
cr_x = 0;
}
}