From 48a7c12e5b4492d4b799f01589eb3363978bb338 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Tue, 4 Oct 2022 19:10:38 +0200 Subject: [PATCH] term: Misc fixes and improvements --- common/drivers/vga_textmode.c | 25 ++++++++++++++++++++++--- common/drivers/vga_textmode.h | 24 ++++-------------------- common/lib/gterm.c | 5 ++++- common/menu.c | 17 +++++++++-------- 4 files changed, 39 insertions(+), 32 deletions(-) diff --git a/common/drivers/vga_textmode.c b/common/drivers/vga_textmode.c index 9cabef49..e555254d 100644 --- a/common/drivers/vga_textmode.c +++ b/common/drivers/vga_textmode.c @@ -11,6 +11,23 @@ #include #include +struct textmode_context { + struct term_context term; + + volatile uint8_t *video_mem; + + uint8_t *back_buffer; + uint8_t *front_buffer; + + size_t cursor_offset; + size_t old_cursor_offset; + bool cursor_status; + uint8_t text_palette; + + uint8_t saved_state_text_palette; + size_t saved_state_cursor_offset; +}; + #define VIDEO_BOTTOM ((VD_ROWS * VD_COLS) - 1) #define VD_COLS (80 * 2) #define VD_ROWS 25 @@ -350,10 +367,12 @@ void vga_textmode_init(bool managed) { term->full_refresh = text_full_refresh; term->deinit = text_deinit; - term_backend = TEXTMODE; - term_context_reinit(term); - term->in_bootloader = true; + + term_context_reinit(term); + term->full_refresh(term); + + term_backend = TEXTMODE; } #endif diff --git a/common/drivers/vga_textmode.h b/common/drivers/vga_textmode.h index 0f9b875c..f9355d4a 100644 --- a/common/drivers/vga_textmode.h +++ b/common/drivers/vga_textmode.h @@ -1,28 +1,12 @@ #ifndef __DRIVERS__VGA_TEXTMODE_H__ #define __DRIVERS__VGA_TEXTMODE_H__ +#if defined (BIOS) + #include -#include -#include -#include - -struct textmode_context { - struct term_context term; - - volatile uint8_t *video_mem; - - uint8_t *back_buffer; - uint8_t *front_buffer; - - size_t cursor_offset; - size_t old_cursor_offset; - bool cursor_status; - uint8_t text_palette; - - uint8_t saved_state_text_palette; - size_t saved_state_cursor_offset; -}; void vga_textmode_init(bool managed); #endif + +#endif diff --git a/common/lib/gterm.c b/common/lib/gterm.c index d61ace4c..3d19cfe6 100644 --- a/common/lib/gterm.c +++ b/common/lib/gterm.c @@ -771,6 +771,10 @@ no_load_font:; font_scale_x, font_scale_y, margin); + if (term == NULL) { + return false; + } + pmm_free(font, FONT_MAX); if (bg_canvas != NULL) { pmm_free(bg_canvas, bg_canvas_size); @@ -784,7 +788,6 @@ no_load_font:; term->in_bootloader = true; term_context_reinit(term); - term->full_refresh(term); term_backend = GTERM; diff --git a/common/menu.c b/common/menu.c index 4dd07d41..5df24f43 100644 --- a/common/menu.c +++ b/common/menu.c @@ -564,7 +564,7 @@ static void menu_init_term(void) { if (menu_resolution != NULL) parse_resolution(&req_width, &req_height, &req_bpp, menu_resolution); - if (!gterm_init(NULL, req_width, req_height)) { + if (!quiet && !gterm_init(NULL, req_width, req_height)) { #if defined (BIOS) vga_textmode_init(true); #elif defined (UEFI) @@ -851,17 +851,18 @@ timeout_aborted: selected_menu_entry->expanded = !selected_menu_entry->expanded; goto refresh; } - if (term_backend == FALLBACK) { - gterm_init(NULL, 0, 0); - if (term == NULL) { + if (!quiet) { + if (term_backend == FALLBACK) { + if (!gterm_init(NULL, 0, 0)) { #if defined (BIOS) - vga_textmode_init(true); + vga_textmode_init(true); #elif defined (UEFI) - panic(true, "menu: Failed to initialise terminal"); + panic(true, "menu: Failed to initialise terminal"); #endif + } + } else { + reset_term(); } - } else { - reset_term(); } boot(selected_menu_entry->body); case 'e':