foxygit / fake-08-xbox360 Log in
commit c961fe1976b0e123a3a44c666bd65a4db92c01a9
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Wed Aug 17 20:25:39 2022 -0600
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Wed Aug 17 20:25:39 2022 -0600

    Fix a text coloring bug and add a some tests
---
 source/printHelper.cpp    |  3 ++-
 test/printHelperTests.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/source/printHelper.cpp b/source/printHelper.cpp
index eb6a7ba..39260a7 100644
--- a/source/printHelper.cpp
+++ b/source/printHelper.cpp
@@ -324,7 +324,8 @@ int print(std::string str, int x, int y, uint8_t c) {
 			uint8_t fgColChar = str[++n];
 			fgColor = p0CharToNum(fgColChar);
 			_ph_graphics->color(fgColor);
-			_ph_mem->drawState.drawPaletteMap[7] = _ph_graphics->getDrawPalMappedColor(fgColor);
+            //this is needed for legacy text drawing
+			_ph_mem->drawState.drawPaletteMap[7] = prevDrawPal[fgColor] & 0x0f;
 		}
 		else if (ch == '\n') {
 			x = homeX;
diff --git a/test/printHelperTests.cpp b/test/printHelperTests.cpp
index 30b021c..734d8d0 100644
--- a/test/printHelperTests.cpp
+++ b/test/printHelperTests.cpp
@@ -99,6 +99,17 @@ TEST_CASE("Print helper functions") {
         CHECK(memory->drawState.text_y == 24);
         CHECK(memory->drawState.color == 14);
     }
+    SUBCASE("print({str}, {x}, {y}, {c}) updates text location correct in multiline situation") {
+        graphics->cls();
+        memory->drawState.text_x = 3;
+        memory->drawState.text_y = 4;
+        memory->drawState.color = 10;
+
+        print("doesnt\nmatter\nwell\nkinda\ndoes", 19, 18, 14);
+
+        CHECK(memory->drawState.text_x == 19);
+        CHECK(memory->drawState.text_y == 48);
+    }
     SUBCASE("print({str}) uses pal mapped color") {
         graphics->cls();
         graphics->color(2);
@@ -354,6 +365,40 @@ TEST_CASE("Print helper functions") {

         checkPoints(graphics, expectedPoints);
     }
+
+       SUBCASE("p8scii special control code move cursor(\\^j) and update home and color test") {
+        graphics->cls();
+    //"\^j87\-f\|a\^h\f7:\^je8other\n:"
+    /*
+--\^j87- move cursor to 32,28
+ --\-f- move cursor horizontally -1 (31,28)
+ --\|a- move cursor vertically -6 (31,22)
+ --\^h --set cursor home to be current location (31,22)
+ --\f7 change color to 7 (white)
+ --: print the ":" character
+ --\^je8- move cursor to 56,32
+ --print "other\n" followed by a new line
+ --print one more ":"
+    */
+        // coordinates x=40 ("a" = 10, 10 * 4 = 40), y=48 ("c" = 12, 12 * 4 = 48)
+        print("\x06""j87\x03""f\x04""a\x06""h\x0c""7:\x06""je8:\n:", 0, 0);
+
+        std::vector<coloredPoint> expectedPoints = {
+            {32, 22, 0},
+            {32, 23, 7},
+            {32, 24, 0},
+            {32, 25, 7},
+            {32, 26, 0},
+
+            {32, 38, 0},
+            {32, 39, 7},
+            {32, 40, 0},
+            {32, 41, 7},
+            {32, 42, 0},
+        };
+
+        checkPoints(graphics, expectedPoints);
+    }
     SUBCASE("p8scii special control code tab stop width(\\^s) ") {
         graphics->cls();