c - 使用 vga 将消息打印到屏幕上

标签 c operating-system kernel osdev vga

我正在尝试编写一个函数,该函数将使用 VGA 文本模式缓冲区将消息打印到屏幕上。 这是打印单个字符的函数:

void putc(uint8_t c, enum Color term_color)
{
    uint8_t *vidptr = (uint8_t*)0xB8000;

    *vidptr = c;
    vidptr++;
    *vidptr = (uint8_t*)term_color;
    vidptr++;
}

这是我想要打印字符串的函数:

void puts(const uint8_t* str, enum Color term_color)
{
    for(size_t i = 0; i != '\0'; i++) {
        putc(str[i], term_color);
    }
}

但它不打印任何内容。只是黑屏,光标闪烁。

编辑:第一个打印单个字符的函数有效。

最佳答案

功能

putc(uint8_t c, enum Color term_color)

始终将字符放在同一位置 (0xB8000)。
您需要声明

uint8_t *vidptr

在函数外部,每次调用时正确递增它。

关于c - 使用 vga 将消息打印到屏幕上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50174996/

相关文章:

linux - 两个进程之间的通信是否只有一个Unix Domain Socket?

operating-system - 操作系统中的陷阱指令有什么作用?

linux - 从内核中断读取设备

c - 分段故障。未知原因(丢失文件?)

mysql c api mysql_fetch_row() 复制字段

c - 关于 C 中 calloc 和 free 函数的问题

linux - 在哪里可以找到 linux 64 位程序集的系统调用列表?

c - c 中的 shell 未按预期工作 - 与管道损坏相关

c - C如何跨平台?

linux - 丢弃包含字符串 linux 内核模块的数据包