Page 1 of 1

Problem With Text Output

Posted: Mon Jun 04, 2007 4:04 pm
by jzgriffin
Recently (last night, in fact), I got back into OS development. I'm working on a simple OS that will (hopefully) have a GUI by November. Right now. there's a GDT, IDT and IRQ implementation in C. But, now that those are in, I've tried to create text I/O routines. They work 99%, but at the end of every line, an inverted degree sign will be displayed. I've made at least 15 little changes to the source code that haven't fixed it, so by now I'm stumped. Hopefully you guys can help me!

Code: Select all

/* Includes */
#include <video.h>

/* Variables */
unsigned char videoColor;
unsigned videoX = 0, videoY = 0;

/**
 * Description:
 *     Changes the value of videoColor.
 *
 * Parameters:
 *     newVideoColor - New value for videoColor.
 *
 * Result:
 *
 */
void SetVideoColor(unsigned char newVideoColor)
{
    videoColor = newVideoColor;
}

/**
 * Description:
 *     Prints a character to the screen.
 *
 * Parameters:
 *     character - Character to print.
 *
 * Result:
 *
 */
void PrintChr(const unsigned char character)
{
    unsigned char *where = (unsigned char *)(0xB8000 + (videoY * 80 + videoX) * 2);

    *where++ = character;
    *where++ = videoColor;

    if(character >= ' ')
    {
        *where++ = character;
        *where++ = videoColor;
        videoX++;
        if(videoX == 80)
        {
            videoY++;
            videoX = 0;
        }
    }
    else
    {
        switch(character)
        {
        case('\n'):
            {
                videoX = 0;
                videoY++;
            }
            break;
        case('\r'):
            {
                videoX = 0;
            }
            break;
        }
    }
}

/**
 * Description:
 *     Prints a string to the screen.
 *
 * Parameters:
 *     string - String to print.
 *
 * Result:
 *
 */
void PrintStr(char *string)
{
    for(; *string != '\0'; string++)
        PrintChr(*string);
}
Thanks for any help that you can provide...
- Jeremiah

Re: Problem With Text Output

Posted: Mon Jun 04, 2007 4:51 pm
by pcmattman
Jeremiah Griffin wrote:<snip>

Code: Select all

void PrintChr(const unsigned char character)
{
    unsigned char *where = (unsigned char *)(0xB8000 + (videoY * 80 + videoX) * 2);

    *where++ = character; // <================
    *where++ = videoColor; // <================

    if(character >= ' ')
    {
        *where++ = character;
        *where++ = videoColor;
        videoX++;
        if(videoX == 80)
        {
            videoY++;
            videoX = 0;
        }
    }
    else
    {
        switch(character)
        {
        case('\n'):
            {
                videoX = 0;
                videoY++;
            }
            break;
        case('\r'):
            {
                videoX = 0;
            }
            break;
        }
    }
}
[/quote]

You attempt to print the character twice. Anything like a newline or other control characters will print weird things on that first print.

Posted: Mon Jun 04, 2007 4:56 pm
by jzgriffin
Oh...wow...thanks. I guess that I didn't read the code thoroughly enough. :-P

Posted: Mon Jun 04, 2007 4:57 pm
by pcmattman
A fresh look always helps :D