From d5d7762cfb39f366d687019261c4a92012860b5a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Deuc=D0=B5?= <shurd@sasktel.net>
Date: Wed, 27 Nov 2024 10:48:56 -0500
Subject: [PATCH] Fix double-height drawing

Top/bottom detection was somewhat broken.
Interestingly, now the previous commit isn't working anymore.
So issue 172 is not quite fixed yet.
---
 src/conio/bitmap_con.c | 30 ++++++++++++------------------
 src/conio/cterm.c      | 14 ++++++++------
 2 files changed, 20 insertions(+), 24 deletions(-)

diff --git a/src/conio/bitmap_con.c b/src/conio/bitmap_con.c
index 11e0181093..7f9e909734 100644
--- a/src/conio/bitmap_con.c
+++ b/src/conio/bitmap_con.c
@@ -605,24 +605,18 @@ static int bitmap_draw_one_char(struct vmem_cell *vc, unsigned int xpos, unsigne
 		struct vstat_vmem *vmem_ptr = get_vmem(&vstat);
 		unsigned char lattr = vc->legacy_attr;
 
-		if (ypos > 1) {
-			for (y = 0; y < ypos; y++) {
-				if (top) {
-					bottom = true;
-					top = false;
-				}
-				else {
-					if (bottom)
-						bottom = false;
-					else {
-						if (y == ypos - 1)
-							break;
-						for (x = 0; x < vstat.cols; x++) {
-							if (vmem_ptr->vmem[y * vstat.cols + x].bg & 0x01000000) {
-								top = true;
-								break;
-							}
-						}
+		for (y = 0; y < ypos; y++) {
+			if (top) {
+				bottom = true;
+				top = false;
+			}
+			else {
+				if (bottom)
+					bottom = false;
+				for (x = 0; x < vstat.cols; x++) {
+					if (vmem_ptr->vmem[y * vstat.cols + x].bg & 0x01000000) {
+						top = true;
+						break;
 					}
 				}
 			}
diff --git a/src/conio/cterm.c b/src/conio/cterm.c
index 8a6a7bd552..0c7fd8ac06 100644
--- a/src/conio/cterm.c
+++ b/src/conio/cterm.c
@@ -4956,7 +4956,7 @@ static void prestel_fix_line(struct cterminal *cterm, int x, int y, bool restore
 	unsigned char attr = cterm->attr;
 	uint8_t prestel_last_mosaic = cterm->prestel_last_mosaic;
 	bool fixed = false;
-	bool fixedheight = false;
+	bool dblheight = false;
 
 	coord_conv_xy(cterm, CTERM_COORD_TERM, CTERM_COORD_SCREEN, &sy, &sx);
 	ex = sx + TERM_MAXX - 1;
@@ -4978,13 +4978,13 @@ static void prestel_fix_line(struct cterminal *cterm, int x, int y, bool restore
 				// Should be double-high
 				line[i].bg |= 0x01000000;
 				fixed = true;
-				fixedheight = true;
+				dblheight = true;
 			}
 			if (((cterm->extattr & CTERM_EXTATTR_PRESTEL_DOUBLE_HEIGHT) == 0) && (line[i].bg & 0x01000000)) {
 				// Should not be double-high
 				line[i].bg &= ~0x01000000;
 				fixed = true;
-				fixedheight = true;
+				dblheight = true;
 			}
 			if (line[i].fg != (cterm->fg_color | (ch << 24))
 			    || line[i].bg != cterm->bg_color
@@ -5014,6 +5014,8 @@ static void prestel_fix_line(struct cterminal *cterm, int x, int y, bool restore
 				prestel_last_mosaic = cterm->prestel_last_mosaic;
 			}
 			prestel_apply_ctrl_after(cterm, ch);
+			if (cterm->extattr & CTERM_EXTATTR_PRESTEL_DOUBLE_HEIGHT)
+				dblheight = true;
 		}
 		else {
 			// This is displayable
@@ -5021,13 +5023,13 @@ static void prestel_fix_line(struct cterminal *cterm, int x, int y, bool restore
 				// Should be double-high
 				line[i].bg |= 0x01000000;
 				fixed = true;
-				fixedheight = true;
+				dblheight = true;
 			}
 			if (((cterm->extattr & CTERM_EXTATTR_PRESTEL_DOUBLE_HEIGHT) == 0) && (line[i].bg & 0x01000000)) {
 				// Should not be double-high
 				line[i].bg &= ~0x01000000;
 				fixed = true;
-				fixedheight = true;
+				dblheight = true;
 			}
 			if (line[i].fg != cterm->fg_color
 			    || line[i].bg != cterm->bg_color
@@ -5085,7 +5087,7 @@ static void prestel_fix_line(struct cterminal *cterm, int x, int y, bool restore
 	if (force || fixed)
 		vmem_puttext(sx, sy, ex, sy, line);
 	free(line);
-	if (fixedheight) {
+	if (dblheight) {
 		prestel_fix_line(cterm, x, y+1, false, true);
 	}
 	if (restore) {
-- 
GitLab