Problem With Text Output

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
jzgriffin
Member
Member
Posts: 190
Joined: Tue Sep 26, 2006 1:40 pm
Libera.chat IRC: Nokurn
Location: Ontario, CA, USA
Contact:

Problem With Text Output

Post 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
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: Problem With Text Output

Post 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.
jzgriffin
Member
Member
Posts: 190
Joined: Tue Sep 26, 2006 1:40 pm
Libera.chat IRC: Nokurn
Location: Ontario, CA, USA
Contact:

Post by jzgriffin »

Oh...wow...thanks. I guess that I didn't read the code thoroughly enough. :-P
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

A fresh look always helps :D
Post Reply