:: commit b96046f8b9397c992aa0a95a2c81fcb8aef62adb

mintsuki <mintsuki@protonmail.com> — 2022-03-07 20:11

parents: 220ebb3830

term: Change default settings to prefer video to text mode

diff --git a/CONFIG.md b/CONFIG.md
index 771ec95c..2b2fd3b6 100644
--- a/CONFIG.md
+++ b/CONFIG.md
@@ -61,7 +61,7 @@ Some keys take *URIs* as values; these are described in the next section.
 * `QUIET` - If set to `yes`, enable quiet mode, where all screen output except panics and important warnings is suppressed. If `TIMEOUT` is not 0, the `TIMEOUT` still occurs, and pressing any key during the timeout will reveal the menu and disable quiet mode.
 * `SERIAL` - If set to `yes`, enable serial I/O for the bootloader.
 * `DEFAULT_ENTRY` - 1-based entry index of the entry which will be automatically selected at startup. If unspecified, it is `1`.
-* `GRAPHICS` - If set to `yes`, use a graphical framebuffer for the boot menu, else use text mode. Ignored with Limine UEFI, forced to `yes`.
+* `GRAPHICS` - If set to `no`, force CGA text mode for the boot menu, else use a video mode. Ignored with Limine UEFI.
 * `MENU_RESOLUTION` - Specify screen resolution to be used by the Limine menu in the form `<width>x<height>`. This will *only* affect the menu, not any booted OS. If not specified, Limine will pick a resolution automatically. If the resolution is not available, Limine will pick another one automatically. Ignored if `GRAPHICS` is not `yes`.
 * `MENU_BRANDING` - A string that will be displayed on top of the Limine menu.
 * `MENU_BRANDING_COLOUR` - A value between 0 and 7 specifying the colour of the branding string. Default is cyan (6).
diff --git a/common/drivers/gop.c b/common/drivers/gop.c
index 222f0e7d..ddab844d 100644
--- a/common/drivers/gop.c
+++ b/common/drivers/gop.c
@@ -104,7 +104,7 @@ static bool try_mode(struct fb_info *ret, size_t mode, int width, int height, in
         status = gop->SetMode(gop, mode);
 
         if (status) {
-            current_video_mode = -2;
+            current_video_mode = -1;
             printv("gop: Failed to set video mode %x, moving on...\n", mode);
             return false;
         }
diff --git a/common/drivers/vbe.c b/common/drivers/vbe.c
index ae74274a..0f341691 100644
--- a/common/drivers/vbe.c
+++ b/common/drivers/vbe.c
@@ -189,7 +189,7 @@ retry:
             if (vid_modes[i] == current_video_mode) {
                 printv("vbe: Mode was already set, perfect!\n");
             } else if (set_vbe_mode(vid_modes[i]) == 0x01) {
-                current_video_mode = -2;
+                current_video_mode = -1;
                 printv("vbe: Failed to set video mode %x, moving on...\n", vid_modes[i]);
                 continue;
             }
diff --git a/common/drivers/vga_textmode.c b/common/drivers/vga_textmode.c
index 0f9bbe8c..225f779c 100644
--- a/common/drivers/vga_textmode.c
+++ b/common/drivers/vga_textmode.c
@@ -162,12 +162,12 @@ void text_full_refresh(void) {
 }
 
 void init_vga_textmode(size_t *_rows, size_t *_cols, bool managed) {
-    if (current_video_mode != -1) {
+    if (current_video_mode != 0x3) {
         struct rm_regs r = {0};
         r.eax = 0x0003;
         rm_int(0x10, &r, &r);
 
-        current_video_mode = -1;
+        current_video_mode = 0x3;
     }
 
     if (back_buffer == NULL) {
diff --git a/common/entry.s2.c b/common/entry.s2.c
index 52e01d4b..14d48479 100644
--- a/common/entry.s2.c
+++ b/common/entry.s2.c
@@ -80,13 +80,6 @@ noreturn void entry(uint8_t boot_drive, int boot_from) {
     if (!a20_enable())
         panic(false, "Could not enable A20 line");
 
-    struct rm_regs r = {0};
-    r.eax = 0x0003;
-    rm_int(0x10, &r, &r);
-
-    outb(0x3d4, 0x0a);
-    outb(0x3d5, 0x20);
-
     init_e820();
     init_memmap();
 
diff --git a/common/lib/gterm.c b/common/lib/gterm.c
index a7c99fa4..d0e60f81 100644
--- a/common/lib/gterm.c
+++ b/common/lib/gterm.c
@@ -601,6 +601,9 @@ static bool last_serial = false;
 
 bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
     if (current_video_mode >= 0
+#if bios == 1
+     && current_video_mode != 0x03
+#endif
      && fbinfo.default_res == true
      && width == 0
      && height == 0
@@ -614,6 +617,9 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
     }
 
     if (current_video_mode >= 0
+#if bios == 1
+     && current_video_mode != 0x03
+#endif
      && fbinfo.framebuffer_width == width
      && fbinfo.framebuffer_height == height
      && fbinfo.framebuffer_bpp == 32
@@ -716,6 +722,21 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
     text_fg = default_fg;
     text_bg = 0xffffffff;
 
+    background = NULL;
+    char *background_path = config_get_value(NULL, 0, "BACKGROUND_PATH");
+    if (background_path != NULL) {
+        struct file_handle *bg_file;
+        if ((bg_file = uri_open(background_path)) != NULL) {
+            background = image_open(bg_file);
+            fclose(bg_file);
+        }
+    }
+
+    if (background == NULL) {
+        margin = 0;
+        margin_gradient = 0;
+    }
+
     char *theme_margin = config_get_value(NULL, 0, "THEME_MARGIN");
     if (theme_margin != NULL) {
         margin = strtoui(theme_margin, NULL, 10);
@@ -726,15 +747,6 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
         margin_gradient = strtoui(theme_margin_gradient, NULL, 10);
     }
 
-    char *background_path = config_get_value(NULL, 0, "BACKGROUND_PATH");
-    if (background_path != NULL) {
-        struct file_handle *bg_file;
-        if ((bg_file = uri_open(background_path)) != NULL) {
-            background = image_open(bg_file);
-            fclose(bg_file);
-        }
-    }
-
     if (background != NULL) {
         char *background_layout = config_get_value(NULL, 0, "BACKGROUND_STYLE");
         if (background_layout != NULL && strcmp(background_layout, "centered") == 0) {
diff --git a/common/menu.c b/common/menu.c
index a428c3f0..61278ffe 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -725,7 +725,7 @@ static noreturn void _menu(bool timeout_enabled) {
 #endif
 
 reterm:
-    if (graphics != NULL && !strcmp(graphics, "yes")) {
+    if (graphics == NULL || strcmp(graphics, "no") == 1) {
         size_t req_width = 0, req_height = 0, req_bpp = 0;
 
         char *menu_resolution = config_get_value(NULL, 0, "MENU_RESOLUTION");
@@ -887,10 +887,11 @@ timeout_aborted:
                     goto refresh;
                 }
                 if (term_backend == NOT_READY) {
-#if bios == 1
-                    term_textmode();
-#elif uefi == 1
                     term_vbe(0, 0);
+#if bios == 1
+                    if (term_backend == NOT_READY) {
+                        term_textmode();
+                    }
 #endif
                 } else {
                     reset_term();
diff --git a/test/limine.cfg b/test/limine.cfg
index dc340159..ff871886 100644
--- a/test/limine.cfg
+++ b/test/limine.cfg
@@ -3,7 +3,6 @@ ${BACKGROUND_PATH}=boot:///boot/bg.bmp
 
 DEFAULT_ENTRY=1
 TIMEOUT=3
-GRAPHICS=yes
 VERBOSE=yes
 
 THEME_BACKGROUND=50000000
tab: 248 wrap: offon