Extended ASCII characters are printed in yellow instead of white - OSDev

336 views Asked by At

I am developing an OS kernel. I am facing a problem while printing extended ASCII characters to the screen. When I try to print characters on the screen the general ascii characters are printed well in WHITE color easily. But when I try to print the extended ASCII characters like the blocks, sigma etc. it prints in yellow. Rather these characters get printed with the color's number - 1.

WHITE -> YELLOW
YELLOW -> BRIGHT MAGENTA
BRIGHT MAGENTA -> BRIGHT RED
.
.
and so on

Can anyone tell why is this happening and help my solve this problem?

My code is such -

putChar(0xdb,0,3,color(BLACK,BLACK));
putChar('A',2,3,color(WHITE,BLACK));

putChar(228,0,4,color(B_GREEN,BLUE));
putChar('A',2,4,color(B_GREEN,BLUE));

putChar(228,0,5,color(B_MAGENTA,BLUE));
putChar('A',2,5,color(B_MAGENTA,BLUE));

And the output is -

The Output

I could have used the color+1 code but there's nothing above white. How could I print them in white?

EDIT - The putChar Code

void putChar(char character, short col, short row, unsigned char attr) {
    volatile unsigned char* vid_mem = (unsigned char *) VIDEO_MEM;
    int offset = (row*80 + col)*2;
    vid_mem += offset;
    if(!attr) {
        attr = default_color;
    }
    *(unsigned short int *)vid_mem = (attr<<8)+character;
}
1

There are 1 answers

1
Alexey Frunze On BEST ANSWER

Most likely the problem is here:

(attr<<8)+character

In x86 gcc the type char is signed by default. So, when you pass characters with codes of 0x80 ... 0xFF, those are treated as signed and get sign extended prior to addition. So, for those characters you're effectively getting (attr<<8)+0xFFFFFF80 ... (attr<<8)+0xFFFFFFFF. And adding 0xFF00 to (attr<<8) effectively subtracts 1 from attr.