C语言 终端顶行未按预期清除



我正在遵循这个准系统内核教程。我目前正在尝试使终端滚动工作,为此,我将给定kernel.c文件中的代码修改为以下内容:

void terminal_putchar (char c) {
  if (c == 'n') {
    terminal_row++;
    terminal_column = 0;
  } else {
    terminal_putentryat(c, terminal_colour, terminal_column, terminal_row);
    if (++terminal_column == VGA_WIDTH) {
      terminal_column = 0;
      if (terminal_row < VGA_HEIGHT) {
         terminal_row++;
       } else {
         //clear top row
         for (size_t i = 0; i < VGA_WIDTH; i++) {
           terminal_buffer[i] = make_vgaentry(' ', terminal_colour);
         }
          //move everything up one row
         for (size_t y = 1; y < VGA_HEIGHT; y++) {
          for (size_t x = 0; x < VGA_WIDTH; x++) {
            size_t const old_index = y * VGA_WIDTH + x;
            size_t const new_index = (y-1) * VGA_WIDTH + x;
            terminal_buffer[new_index] = terminal_buffer[old_index];
            terminal_buffer[old_index] = make_vgaentry(' ', terminal_colour);
          }
        }
        //put us on the last (empty) row
        terminal_row = 24;
      }
    }
  }
}

但是,这并没有给我所需的行为 - 当我告诉它输出超过 25 行文本时,终端最终不会滚动,而是简单地跳过最后几行。我在这里错过了一些明显的东西吗?

one of the logic errors is:
when the cursor is on row 24 (the last row as rows start with 0)
then a 'n' is passed to the function,
the row number is incremented
Now the cursor is on row 25 (past the end of the buffer)
Under the above scenario, a vertical scroll should have been
performed, leaving the cursor on row 24
with the whole row 24 being blanks
so the logic needs some more work

最新更新