foxygit / fake-08-xbox360 Log in
commit 74d9da27b88407319d891188342a558eedbc3716
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Fri Mar 11 07:03:54 2022 -0700
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Fri Mar 11 07:03:54 2022 -0700

    Add p8scii ctrl code to update cursor home
---
 source/printHelper.cpp    | 12 +++++++++++-
 test/printHelperTests.cpp | 30 ++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/source/printHelper.cpp b/source/printHelper.cpp
index ff4b132..97d4735 100644
--- a/source/printHelper.cpp
+++ b/source/printHelper.cpp
@@ -79,6 +79,8 @@ int print(std::string str, int x, int y, uint8_t c) {

 	_ph_mem->drawState.text_x = x;
 	_ph_mem->drawState.text_y = y;
+    int homeX = x;
+    int homeY = y;

 	uint8_t effectiveC = _ph_graphics->getDrawPalMappedColor(c);

@@ -159,9 +161,17 @@ int print(std::string str, int x, int y, uint8_t c) {
             else if (commandChar == 'c'){
                 uint8_t colChar = str[++n];
                 uint8_t col = p0CharToNum(colChar);
-
+
                 _ph_graphics->cls(col);
             }
+            else if (commandChar == 'g'){
+                x = homeX;
+                y = homeY;
+            }
+            else if (commandChar == 'h'){
+                homeX = x;
+                homeY = y;
+            }

 		}
 		else if (ch == 12) { //"\f{p0}" draw text with this foreground color
diff --git a/test/printHelperTests.cpp b/test/printHelperTests.cpp
index f6ce957..53662ea 100644
--- a/test/printHelperTests.cpp
+++ b/test/printHelperTests.cpp
@@ -308,6 +308,36 @@ TEST_CASE("Print helper functions") {

         checkPoints(graphics, expectedPoints);
     }
+    SUBCASE("p8scii special control code home the cursor(\\^g) ") {
+        graphics->cls();
+
+        print("\n\n\nstuff\x06""g:", 0, 0);
+
+        std::vector<coloredPoint> expectedPoints = {
+            {1, 0, 0},
+            {1, 1, 6},
+            {1, 2, 0},
+            {1, 3, 6},
+            {1, 4, 0}
+        };
+
+        checkPoints(graphics, expectedPoints);
+    }
+    SUBCASE("p8scii special control code update cursor home(\\^h) ") {
+        graphics->cls();
+
+        print("\n\n\n\x06""h\n\n\nmorestuff\x06""g:", 0, 0);
+
+        std::vector<coloredPoint> expectedPoints = {
+            {1, 18, 0},
+            {1, 19, 6},
+            {1, 20, 0},
+            {1, 21, 6},
+            {1, 22, 0}
+        };
+
+        checkPoints(graphics, expectedPoints);
+    }


     delete stubHost;