C:写入视频公羊

发布于 2025-02-09 04:37:02 字数 692 浏览 1 评论 0原文

我正在尝试制作一个可以用特定颜色将字符串写入视频内存的函数。但是,我无法使它起作用。要编写单个字符,我会这样做:

*(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)

但是我需要用一个变量写入,所以我尝试了一下,但是它什么也没打印。

int currentAddressVRAM = 0xb8000;

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

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

我该怎么做?我在做什么错?

编辑: 我也尝试过,它什么也没印刷:

char *currentAddressVRAM = (char *)0xb8000;

*currentAddressVRAM = 'O';
currentAddressVRAM++;

*currentAddressVRAM = 'O';
currentAddressVRAM++;

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゃ懵逼小萝莉 2025-02-16 04:37:02

我发现了最终如何做!
感谢您的所有有用的评论,它可以帮助我找到解决问题的解决方案。
这是我的代码:

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

唯一的问题是我不知道如何在功能的使用之间保存当前地址。如果有人知道,请告诉我!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文