【问题标题】:How to implement terminal scrolling? [closed]如何实现终端滚动? [关闭]
【发布时间】:2020-10-24 21:59:04
【问题描述】:

我目前正在尝试为无人机开发操作系统。我正在关注本指南:https://wiki.osdev.org/Bare_Bones

请在这里找到我的代码,我故意删除了头文件。

void terminal_putentryat(char c, uint8_t color, size_t x, size_t y) 
{
    if(y > VGA_HEIGHT) {
        for(size_t y = 0; y < VGA_HEIGHT; y++) {
            const size_t index = y * VGA_WIDTH + x;
            terminal_buffer[index] = terminal_buffer[index+1];
            terminal_buffer[index] = vga_entry(c, color);
        }
    }
    const size_t index = y * VGA_WIDTH + x;
    terminal_buffer[index] = vga_entry(c, color);
}
 
void terminal_putchar(char c) 
{
    if(c == '\n') {
                terminal_row = terminal_row+1;
                terminal_column = 0;
                return;
        }

    terminal_putentryat(c, terminal_color, terminal_column, terminal_row);
    if(++terminal_column == VGA_WIDTH) {
        terminal_column = 0;
        if (++terminal_row == VGA_HEIGHT) 
        terminal_row = 0;
    }
}
 
void terminal_write(const char* data, size_t size) 
{
    for (size_t i = 0; i < size; i++)
        terminal_putchar(data[i]);
}
 
void terminal_writestring(const char* data) 
{
    terminal_write(data, strlen(data));
}
 

【问题讨论】:

    标签: c terminal kernel osdev


    【解决方案1】:

    先将终端缓冲区中的字符复制一行:

    memmove(terminal_buffer, terminal_buffer + VGA_WIDTH, VGA_WIDTH * (VGA_HEIGHT - 1) * sizeof(uint16_t));
    

    然后清除底部的行

    size_t index = (VGA_HEIGHT - 1) * VGA_WIDTH;
    for(size_t x = 0; x < VGA_WIDTH; ++x)
    {
        terminal_buffer[index + x] = vga_entry(' ', terminal_color);
    }
    

    【讨论】:

      猜你喜欢
      • 2015-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-16
      相关资源
      最近更新 更多