:: commit a5def082c335b5dbb506b016478d87fbab955816

mintsuki <mintsuki@protonmail.com> — 2021-08-25 21:57

parents: 31f52c2b30

term: Reverse video should not make the cursor invisible

diff --git a/stage23/drivers/vga_textmode.s2.c b/stage23/drivers/vga_textmode.s2.c
index 075a5dda..26c1fc57 100644
--- a/stage23/drivers/vga_textmode.s2.c
+++ b/stage23/drivers/vga_textmode.s2.c
@@ -29,8 +29,6 @@ static struct context {
 #define cursor_status context.cursor_status
     uint8_t text_palette;
 #define text_palette context.text_palette
-    uint8_t cursor_palette;
-#define cursor_palette context.cursor_palette
     bool scroll_enabled;
 #define scroll_enabled context.scroll_enabled
 } context;
@@ -43,7 +41,8 @@ static void clear_cursor(void) {
 
 static void draw_cursor(void) {
     if (cursor_status) {
-        video_mem[cursor_offset + 1] = cursor_palette;
+        uint16_t c = current_buffer[cursor_offset + 1];
+        video_mem[cursor_offset + 1] = (c << 4) | (c >> 4);
     }
 }
 
@@ -165,7 +164,6 @@ void init_vga_textmode(size_t *_rows, size_t *_cols, bool managed) {
     cursor_offset = 0;
     cursor_status = true;
     text_palette = 0x07;
-    cursor_palette = 0x70;
     scroll_enabled = true;
 
     text_clear(false);
diff --git a/stage23/lib/gterm.c b/stage23/lib/gterm.c
index 5c3804f1..03344ddf 100644
--- a/stage23/lib/gterm.c
+++ b/stage23/lib/gterm.c
@@ -86,11 +86,16 @@ void gterm_swap_palette(void) {
     }
 }
 
-#define A(rgb) (uint8_t)(rgb >> 24)
-#define R(rgb) (uint8_t)(rgb >> 16)
-#define G(rgb) (uint8_t)(rgb >> 8)
-#define B(rgb) (uint8_t)(rgb)
-#define ARGB(a, r, g, b) (a << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF)
+#define A(rgb) ((uint8_t)((rgb) >> 24))
+#define R(rgb) ((uint8_t)((rgb) >> 16))
+#define G(rgb) ((uint8_t)((rgb) >> 8))
+#define B(rgb) ((uint8_t)((rgb) >> 0))
+#define ARGB(a, r, g, b) ( \
+    ((uint32_t)((a) & 0xFF) << 24) \
+  | ((uint32_t)((r) & 0xFF) << 16) \
+  | ((uint32_t)((g) & 0xFF) << 8) \
+  | ((uint32_t)((b) & 0xFF) << 0) \
+)
 
 static inline uint32_t colour_blend(uint32_t fg, uint32_t bg) {
     unsigned alpha = 255 - A(fg);
@@ -337,8 +342,16 @@ static void clear_cursor(void) {
 static void draw_cursor(void) {
     if (cursor_status) {
         struct gterm_char c = grid[cursor_x + cursor_y * cols];
-        c.fg = 0;
-        c.bg = 0xcccccc;
+        uint32_t tmp = c.fg;
+        if (c.bg == 0xffffffff) {
+            c.fg = ARGB(A(tmp),
+                        R(tmp) < 128 ? 255 : 0,
+                        G(tmp) < 128 ? 255 : 0,
+                        B(tmp) < 128 ? 255 : 0);
+        } else {
+            c.fg = c.bg;
+        }
+        c.bg = tmp;
         plot_char_grid_force(&c, cursor_x, cursor_y);
     }
 }
tab: 248 wrap: offon