简体   繁体   English

扩展的ASCII字符以黄色而不是白色打印-OSDev

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

I am developing an OS kernel. 我正在开发OS内核。 I am facing a problem while printing extended ASCII characters to the screen. 在屏幕上打印扩展的ASCII字符时遇到问题。 When I try to print characters on the screen the general ascii characters are printed well in WHITE color easily. 当我尝试在屏幕上打印字符时,一般的ascii字符可以轻松地以白色打印。 But when I try to print the extended ASCII characters like the blocks, sigma etc. it prints in yellow. 但是,当我尝试打印扩展的ASCII字符(例如块,sigma等)时,它将以黄色打印。 Rather these characters get printed with the color's number - 1 . 而是这些字符以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 - 输出是-

输出

I could have used the color+1 code but there's nothing above white. 我本可以使用color + 1代码,但白色之上没有任何东西。 How could I print them in white? 如何将它们打印成白色?

EDIT - The putChar Code 编辑-putChar代码

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;
}

Most likely the problem is here: 问题最有可能在这里:

(attr<<8)+character

In x86 gcc the type char is signed by default. 在x86 gcc中,默认情况下对char类型进行签名。 So, when you pass characters with codes of 0x80 ... 0xFF, those are treated as signed and get sign extended prior to addition. 因此,当您传递代码为0x80 ... 0xFF的字符时,这些字符将被视为已签名并在添加之前得到扩展的符号。 So, for those characters you're effectively getting (attr<<8)+0xFFFFFF80 ... (attr<<8)+0xFFFFFFFF . 因此,对于那些字符,您实际上得到了(attr<<8)+0xFFFFFF80 ... (attr<<8)+0xFFFFFFFF And adding 0xFF00 to (attr<<8) effectively subtracts 1 from attr . 并将0xFF00添加到(attr<<8)有效地从attr减去1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM