From 25d9fd661432b51a17292a16b8de7f6b33647000 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Thu, 8 Jul 2021 16:33:24 +0200 Subject: [PATCH] term: Do not scroll screen when it shouldn't be --- stage23/drivers/vga_textmode.h | 2 ++ stage23/drivers/vga_textmode.s2.c | 15 +++++++++++++++ stage23/lib/gterm.c | 23 +++++++++++++++++++---- stage23/lib/gterm.h | 2 ++ stage23/lib/term.c | 2 ++ stage23/lib/term.h | 2 ++ stage23/lib/term.s2.c | 7 +++++++ stage23/menu.c | 2 +- 8 files changed, 50 insertions(+), 5 deletions(-) diff --git a/stage23/drivers/vga_textmode.h b/stage23/drivers/vga_textmode.h index 5c5d98ff..31c0ce7a 100644 --- a/stage23/drivers/vga_textmode.h +++ b/stage23/drivers/vga_textmode.h @@ -13,6 +13,8 @@ void text_set_cursor_pos(int x, int y); void text_get_cursor_pos(int *x, int *y); void text_set_text_fg(int fg); void text_set_text_bg(int bg); +bool text_scroll_disable(void); +void text_scroll_enable(void); void text_double_buffer(bool state); void text_double_buffer_flush(void); diff --git a/stage23/drivers/vga_textmode.s2.c b/stage23/drivers/vga_textmode.s2.c index a0fa694d..fd29912d 100644 --- a/stage23/drivers/vga_textmode.s2.c +++ b/stage23/drivers/vga_textmode.s2.c @@ -37,7 +37,22 @@ static void draw_cursor(void) { } } +static bool scroll_enabled = true; + +bool text_scroll_disable(void) { + bool ret = scroll_enabled; + scroll_enabled = false; + return ret; +} + +void text_scroll_enable(void) { + scroll_enabled = true; +} + static void scroll(void) { + if (scroll_enabled == false) + return; + // move the text up by one row for (size_t i = 0; i <= VIDEO_BOTTOM - VD_COLS; i++) { current_buffer[i] = current_buffer[i + VD_COLS]; diff --git a/stage23/lib/gterm.c b/stage23/lib/gterm.c index 9c1e7655..742183e9 100644 --- a/stage23/lib/gterm.c +++ b/stage23/lib/gterm.c @@ -74,7 +74,7 @@ void gterm_plot_px(int x, int y, uint32_t hex) { gterm_framebuffer[fb_i] = hex; } -static uint32_t blend_gradient_from_box(int x, int y, uint32_t bg_px, uint32_t hex) { +static uint32_t blend_gradient_from_box(int x, int y, uint32_t bg_px, uint32_t hex) { int distance, x_distance, y_distance; if (x < frame_width) @@ -153,13 +153,13 @@ static uint32_t blend_gradient_from_box(int x, int y, uint32_t bg_px, uint32_t h void gterm_generate_canvas(void) { if (background) { - // Instead of executing blend_gradient_from_box for every pixel in the fb, just run it for the margin + // Instead of executing blend_gradient_from_box for every pixel in the fb, just run it for the margin uint8_t *img = background->img; const int img_width = background->img_width, x16_x_delta = (img_width * 16) / gterm_width, img_height = background->img_height, img_pitch = background->pitch, colsize = background->bpp / 8; const int frame_height_end = frame_height + VGA_FONT_HEIGHT * rows, frame_width_end = frame_width + VGA_FONT_WIDTH * cols; const int fheight = frame_height - margin_gradient, fheight_end = frame_height_end + margin_gradient, - fwidth = frame_width - margin_gradient, fwidth_end = frame_width_end + margin_gradient; + fwidth = frame_width - margin_gradient, fwidth_end = frame_width_end + margin_gradient; // Draw the part of the image outside the margin genloop(0, gterm_width, 0, fheight, i); @@ -284,7 +284,22 @@ static inline bool compare_char(struct gterm_char *a, struct gterm_char *b) { return !(a->c != b->c || a->bg != b->bg || a->fg != b->fg); } +static bool scroll_enabled = true; + +bool gterm_scroll_disable(void) { + bool ret = scroll_enabled; + scroll_enabled = false; + return ret; +} + +void gterm_scroll_enable(void) { + scroll_enabled = true; +} + static void scroll(void) { + if (scroll_enabled == false) + return; + clear_cursor(); for (int i = cols; i < rows * cols; i++) { @@ -316,7 +331,7 @@ void gterm_clear(bool move) { empty.fg = 9; empty.bg = 8; for (int i = 0; i < rows * cols; i++) grid[i] = empty; - + if (move) { cursor_x = 0; cursor_y = 0; diff --git a/stage23/lib/gterm.h b/stage23/lib/gterm.h index 9e8f7311..43ce6607 100644 --- a/stage23/lib/gterm.h +++ b/stage23/lib/gterm.h @@ -18,6 +18,8 @@ void gterm_set_cursor_pos(int x, int y); void gterm_get_cursor_pos(int *x, int *y); void gterm_set_text_fg(int fg); void gterm_set_text_bg(int bg); +bool gterm_scroll_disable(void); +void gterm_scroll_enable(void); void gterm_double_buffer_flush(void); void gterm_double_buffer(bool state); diff --git a/stage23/lib/term.c b/stage23/lib/term.c index 9510517b..bce44892 100644 --- a/stage23/lib/term.c +++ b/stage23/lib/term.c @@ -27,6 +27,8 @@ void term_vbe(int width, int height) { get_cursor_pos = gterm_get_cursor_pos; set_text_fg = gterm_set_text_fg; set_text_bg = gterm_set_text_bg; + scroll_disable = gterm_scroll_disable; + scroll_enable = gterm_scroll_enable; term_double_buffer = gterm_double_buffer; term_double_buffer_flush = gterm_double_buffer_flush; diff --git a/stage23/lib/term.h b/stage23/lib/term.h index 6b0b19ec..c2bb1988 100644 --- a/stage23/lib/term.h +++ b/stage23/lib/term.h @@ -13,6 +13,8 @@ extern void (*set_cursor_pos)(int x, int y); extern void (*get_cursor_pos)(int *x, int *y); extern void (*set_text_fg)(int fg); extern void (*set_text_bg)(int bg); +extern bool (*scroll_disable)(void); +extern void (*scroll_enable)(void); extern void (*term_double_buffer)(bool status); extern void (*term_double_buffer_flush)(void); diff --git a/stage23/lib/term.s2.c b/stage23/lib/term.s2.c index 619e5868..1892ab51 100644 --- a/stage23/lib/term.s2.c +++ b/stage23/lib/term.s2.c @@ -25,6 +25,8 @@ void (*set_cursor_pos)(int x, int y); void (*get_cursor_pos)(int *x, int *y); void (*set_text_fg)(int fg); void (*set_text_bg)(int bg); +bool (*scroll_disable)(void); +void (*scroll_enable)(void); void (*term_double_buffer)(bool status); void (*term_double_buffer_flush)(void); @@ -45,6 +47,8 @@ void term_textmode(void) { get_cursor_pos = text_get_cursor_pos; set_text_fg = text_set_text_fg; set_text_bg = text_set_text_bg; + scroll_disable = text_scroll_disable; + scroll_enable = text_scroll_enable; term_double_buffer = text_double_buffer; term_double_buffer_flush = text_double_buffer_flush; @@ -215,8 +219,11 @@ static void control_sequence_parse(uint8_t c) { int x, y; get_cursor_pos(&x, &y); set_cursor_pos(0, y); + bool r = scroll_disable(); for (int i = 0; i < term_cols; i++) raw_putchar(' '); + if (r) + scroll_enable(); set_cursor_pos(x, y); break; } diff --git a/stage23/menu.c b/stage23/menu.c index f59aff6e..813545cf 100644 --- a/stage23/menu.c +++ b/stage23/menu.c @@ -606,7 +606,7 @@ refresh: term_double_buffer_flush(); if ((c = pit_sleep_and_quit_on_keypress(1))) { skip_timeout = true; - print("\e[2K\r\e[2A"); + print("\e[2K\r"); term_double_buffer_flush(); goto timeout_aborted; }