【问题标题】:Top row of terminal not clearing as expected终端的顶行未按预期清除
【发布时间】:2015-02-27 05:27:30
【问题描述】:

我正在关注this barebones kernel tutorial。我目前正在尝试get terminal scrolling working,为此,我已将给定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 行文本时,终端并没有滚动,而是简单地跳过了最后一行。我在这里遗漏了什么明显的东西吗?

【问题讨论】:

    标签: c linux x86 kernel elf


    【解决方案1】:
    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-24
      • 1970-01-01
      • 2012-03-30
      • 1970-01-01
      • 2020-08-18
      • 2015-03-11
      • 2012-04-23
      • 1970-01-01
      相关资源
      最近更新 更多