foxygit / fake-08-xbox360 Log in
commit 4c901913301a7e05618c2c9a0ab0b9126a198214
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Fri Jan 27 18:02:54 2023 -0700
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Fri Jan 27 18:02:54 2023 -0700

    fix palette mapping of text bg colors
---
 source/graphics.cpp                          |  39 +++++++++++++++++----------
 source/printHelper.cpp                       |   8 +++---
 test/carts/screenshots/one_off_chars_f01.png | Bin 931 -> 931 bytes
 3 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/source/graphics.cpp b/source/graphics.cpp
index cdf8cc2..48d7b38 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -1449,12 +1449,21 @@ std::tuple<int, int> Graphics::drawCharacterFromBytes(
 		//TODO: other print modes
 	}

-	if (bgColor != 0) {
-		//possible todo: check perf if this is better than doing it in the other loop (m)
-		uint8_t prevPenColor = _memory->drawState.color;
-		rectfill(x-1, y-1, x + charWidth*wFactor - 1, y + charHeight*hFactor - 1, bgColor);
-		_memory->drawState.color = prevPenColor;
+	//possible todo: check perf if this is better than doing it in the other loop (m)
+	// if (bgColor != 0) {
+	// 	uint8_t prevPenColor = _memory->drawState.color;
+	// 	rectfill(x-1, y-1, x + charWidth*wFactor - 1, y + charHeight*hFactor - 1, bgColor);
+	// 	_memory->drawState.color = prevPenColor;
+	// }
+	fgColor &= 0x0f;
+	bgColor &= 0x0f;
+	/*
+	if (invertColors) {
+		uint8_t temp = fgColor;
+		fgColor = bgColor;
+		bgColor = temp;
 	}
+	*/

 	for (int relDestY = 0; relDestY < charHeight * hFactor; relDestY++) {
 		for(int relDestX = 0; relDestX < charWidth * wFactor; relDestX++) {
@@ -1466,15 +1475,17 @@ std::tuple<int, int> Graphics::drawCharacterFromBytes(
 			int absDestX = x + relDestX;
 			int absDestY = y + relDestY;

-			if (invertColors) {
-				on = !on;
-			}
-
-			if (on && isWithinClip(absDestX, absDestY)) {
-				setPixelNibble(absDestX, absDestY, fgColor, screenBuffer);
-			}
-			if(!on && solidBg && isWithinClip(absDestX, absDestY)) {
-				setPixelNibble(absDestX, absDestY, bgColor, screenBuffer);
+			if (isWithinClip(absDestX, absDestY)) {
+				if (invertColors) {
+					on = !on;
+				}
+
+				if (on) {
+					setPixelNibble(absDestX, absDestY, fgColor, screenBuffer);
+				}
+				if(!on && (solidBg || bgColor > 0)) {
+					setPixelNibble(absDestX, absDestY, bgColor, screenBuffer);
+				}
 			}
 		}
 	}
diff --git a/source/printHelper.cpp b/source/printHelper.cpp
index 7d6ffe4..6d153a7 100644
--- a/source/printHelper.cpp
+++ b/source/printHelper.cpp
@@ -144,7 +144,7 @@ int print(std::string str, int x, int y, uint8_t c) {
                     x,
                     y,
                     prevDrawPal[fgColor & 0x0f],
-                    bgColor,
+                    prevDrawPal[bgColor & 0x0f],
                     printMode,
                     forceCharWidth,
                     forceCharHeight);
@@ -290,7 +290,7 @@ int print(std::string str, int x, int y, uint8_t c) {
                     x,
                     y,
                     prevDrawPal[fgColor & 0x0f],
-                    bgColor,
+                    prevDrawPal[bgColor & 0x0f],
                     printMode,
                     8,
                     charHeight);
@@ -355,7 +355,7 @@ int print(std::string str, int x, int y, uint8_t c) {
                 prevX + xOffset,
                 prevY + yOffset,
                 prevDrawPal[fgColor & 0x0f],
-                bgColor,
+                prevDrawPal[bgColor & 0x0f],
                 printMode,
                 forceCharWidth,
                 forceCharHeight);
@@ -404,7 +404,7 @@ int print(std::string str, int x, int y, uint8_t c) {
                 x,
                 y,
                 prevDrawPal[fgColor & 0x0f],
-                bgColor,
+                prevDrawPal[bgColor & 0x0f],
                 printMode,
                 forceCharWidth,
                 forceCharHeight);
diff --git a/test/carts/screenshots/one_off_chars_f01.png b/test/carts/screenshots/one_off_chars_f01.png
index 425e66c..bb8c5bb 100644
Binary files a/test/carts/screenshots/one_off_chars_f01.png and b/test/carts/screenshots/one_off_chars_f01.png differ