From c8584cd8a18667d30c7df19a5864ec274ad37957 Mon Sep 17 00:00:00 2001 From: catfood Date: Sat, 24 Dec 2022 21:42:44 +0800 Subject: [PATCH] add bottom line --- include/tty.h | 3 ++- kernel/vga.c | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/tty.h b/include/tty.h index 81212ce..805238d 100644 --- a/include/tty.h +++ b/include/tty.h @@ -68,7 +68,8 @@ typedef struct vga_buf void *buf; // 2d array, screen size, for text mode it's [maxline][80] int max_line; // to support scroll, max line should be a lot more than screen int scr_top_line; // the index in buf of top line on screen; - int scr_cur_line; // the index in buf of the cursor's line + int scr_cur_line; // the index in buf of the cursor's line; + int scr_bot_line; // the index in buf of the most-bottom printed line int head_line; // for circular buffer use int cur_row; int cur_col; // cursor position, on screen diff --git a/kernel/vga.c b/kernel/vga.c index 71f7371..3525bf9 100644 --- a/kernel/vga.c +++ b/kernel/vga.c @@ -132,7 +132,7 @@ void vga_tty_init(NTTY *tty) // kprintf("malloced %p %p %p\n", vga->buf, &vga->buf, &vga->scr_top_line); vga->cur_col = vga->cur_row = 0; // buf->max_line = SCR_BUFSIZE / SCR_WIDTH; - vga->scr_top_line = vga->scr_cur_line = 0; + vga->scr_top_line = vga->scr_cur_line = vga->scr_bot_line = 0; vga->head_line = 0; u32 *ptr_buf = (u32 *)vga->buf; for (int i = 0; i < SCR_BUFSIZE * sizeof(u16) / sizeof(u32); ++i) @@ -551,6 +551,9 @@ void vga_tty_write(NTTY *tty, char ch) } } vga->cur_row = CYCLE_SUB(vga->scr_top_line, vga->scr_cur_line, SCR_MAXLINE); + if (CYCLE_SUB(vga->head_line, vga->scr_cur_line, SCR_MAXLINE) >= CYCLE_SUB(vga->head_line, vga->scr_bot_line, SCR_MAXLINE)){ + vga->scr_bot_line = vga->scr_cur_line; + } // kprintf("row: %d; ", vga->cur_row); } @@ -577,6 +580,8 @@ void vga_tty_flush(NTTY *tty) u16 *buf = vga->buf; int i, cur_line; vga_set_cursor(INDEX(vga->cur_row, vga->cur_col)); + vga->cur_row = CYCLE_SUB(vga->scr_top_line, vga->scr_cur_line, SCR_MAXLINE); + int bottom = min(max(vga->cur_row, CYCLE_SUB(vga->scr_top_line, vga->scr_bot_line, SCR_MAXLINE)), SCR_HEIGHT); // if (vga->cur_row == SCR_HEIGHT - 1) // { // vga_flush_screen(&buf[INDEX(vga->scr_top_line, 0)]); @@ -585,7 +590,7 @@ void vga_tty_flush(NTTY *tty) // else // { cur_line = vga->scr_top_line; - for (i = 0; i <= vga->cur_row; ++i) + for (i = 0; i <= bottom; ++i) { vga_flush_line(&buf[INDEX(cur_line, 0)], i); cur_line = NEXTLINE(cur_line);