简体   繁体   English

C:写入视频内存

[英]C : write to video ram

I am trying to make a function that would write strings to video memory with a specific color.我正在尝试制作一个将字符串写入具有特定颜色的视频内存的函数。 However, I am unable to make it work.但是,我无法使其工作。 To write single characters, i would do this:要写单个字符,我会这样做:

*(char *)0xb8000 = 'O'; //Prints the letter O at the first position in video memory
*(char *)0xb8001 = 'O'; //Adds it some colors (Haven't figured how to write a byte here)

But I need to write with a variable, so I tried this but it just prints nothing.但是我需要用一个变量来写,所以我尝试了这个,但它什么也没打印。

int currentAddressVRAM = 0xb8000;

*(char *)currentAddressVRAM = 'O';
currentAddressVRAM++;

*(char *)currentAddressVRAM = 'O';
currentAddressVRAM++;

How would I do this?我该怎么做? What am I doing wrong?我究竟做错了什么?

Edit: I tried this too and it just printed nothing:编辑:我也试过了,它什么也没打印:

char *currentAddressVRAM = (char *)0xb8000;

*currentAddressVRAM = 'O';
currentAddressVRAM++;

*currentAddressVRAM = 'O';
currentAddressVRAM++;

I found out how to do it finally!我终于知道怎么做了!
Thanks for all of your helpful comments, it help me find the solution to my problem.感谢您所有有用的评论,它帮助我找到解决问题的方法。
Here is my code :这是我的代码:

#define VIDEO_MEMORY 0xb8000

void PrintS(char *text, char color)
{
    char *currentAddressVRAM = (char *)VIDEO_MEMORY;
    for (int i = 0; 1; i++)
    {
        if (text[i] == '\0')
        {
            break;
        }
        *currentAddressVRAM++ = text[i];
        *currentAddressVRAM++ = color;
    }
}

The only problem with this is that I don't know how to save the current address between the uses of the function.唯一的问题是我不知道如何在函数的使用之间保存当前地址。 If somebody knows, please let me know!如果有人知道,请告诉我!

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

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