foxygit / fake-08-xbox360 Log in
commit fe7a241fb9ec2c4357d4b8b0de617d97441864b7
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Sat Mar 12 13:03:13 2022 -0700
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Sat Mar 12 13:03:13 2022 -0700

    Add support for wide, tall, and stripey text
---
 source/graphics.cpp       | 36 +++++++++++++++-----
 source/graphics.h         |  3 +-
 source/printHelper.cpp    |  7 ++--
 test/printHelperTests.cpp | 85 ++++++++++++++++++++++++++++++++++++++++++-----
 4 files changed, 111 insertions(+), 20 deletions(-)

diff --git a/source/graphics.cpp b/source/graphics.cpp
index baf9d79..e1f990c 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -204,7 +204,10 @@ void Graphics::copyStretchSpriteToScreen(
 	int scr_w,
 	int scr_h,
 	bool flip_x,
-	bool flip_y)
+	bool flip_y,
+	//skipStretchPx is currently only used for drawing stripey mode text,
+	//so it is only used when drawing in non-flipped mode
+	bool skipStretchPx)
 {
 	if (scr_w == 0 || scr_h == 0)
 		return;
@@ -287,18 +290,31 @@ void Graphics::copyStretchSpriteToScreen(
 		dy = -dy;
 	}

+	int prevSprX = -1;
+	int prevSprY = -1;
+
 	//ugly duplication but see if inlining helps
 	if (hwState.colorBitmask == 0xff){
 		for (int y = 0; y < scr_h; y++) {
-			uint8_t* spr = spritebuffer + (((spr_y + y * dy) >> 16) & 0x7f) * 64;
+			int sprY = ((spr_y + y * dy) >> 16);
+			uint8_t* spr = spritebuffer + (sprY & 0x7f) * 64;
+
+			if (skipStretchPx && prevSprY == sprY){
+				continue;
+			}
+			prevSprY = sprY;

 			if (!flip_x) {
 				for (int x = 0; x < scr_w; x++) {
-					int pixIndex = (spr_x + x * dx);
-					int combinedPixIdx = ((pixIndex / 2) >> 16) & 0x7f;
-					uint8_t bothPix = spr[combinedPixIdx];
+					int shiftedPixIndex = (spr_x + x * dx) >> 16;
+					if (skipStretchPx && prevSprX == shiftedPixIndex){
+						continue;
+					}
+					prevSprX = shiftedPixIndex;
+					int preShiftedCombinedPixIndex = (shiftedPixIndex / 2) & 0x7f;
+					uint8_t bothPix = spr[preShiftedCombinedPixIndex];

-					uint8_t c = (pixIndex >> 16) % 2 == 0
+					uint8_t c = shiftedPixIndex % 2 == 0
 						? bothPix & 0x0f //just first 4 bits
 						: bothPix >> 4;  //just last 4 bits

@@ -1253,6 +1269,7 @@ int Graphics::drawCharacter(uint8_t ch, int x, int y, uint8_t printMode) {
 	if ((printMode & PRINT_MODE_ON) == PRINT_MODE_ON){
 		int scrW = 4;
 		int scrH = 5;
+		bool evenPxOnly = false;

 		if ((printMode & PRINT_MODE_WIDE) == PRINT_MODE_WIDE) {
 			scrW *= 2;
@@ -1262,16 +1279,17 @@ int Graphics::drawCharacter(uint8_t ch, int x, int y, uint8_t printMode) {
 		}
 		if((printMode & PRINT_MODE_STRIPEY) == PRINT_MODE_STRIPEY) {
 			//draw every other pixel-- also kinda broken on pico 8 0.2.4
+			evenPxOnly = true;
 		}
 		//TODO: other print modes

 		if (ch >= 0x10 && ch < 0x80) {
 			int index = ch - 0x10;
-			copyStretchSpriteToScreen(fontSpriteData, (index % 16) * 8, (index / 16) * 8, 4, 5, x, y, scrW, scrH, false, false);
+			copyStretchSpriteToScreen(fontSpriteData, (index % 16) * 8, (index / 16) * 8, 4, 5, x, y, scrW, scrH, false, false, evenPxOnly);
 		} else if (ch >= 0x80) {
 			int index = ch - 0x80;
 			extraCharWidth = 4;
-			copyStretchSpriteToScreen(fontSpriteData, (index % 16) * 8, (index / 16) * 8 + 56, 8, 5, x, y, (scrW + extraCharWidth), scrH, false, false);
+			copyStretchSpriteToScreen(fontSpriteData, (index % 16) * 8, (index / 16) * 8 + 56, 8, 5, x, y, (scrW + extraCharWidth), scrH, false, false, evenPxOnly);

 		}

@@ -1318,7 +1336,7 @@ void Graphics::sspr(
         bool flip_x = false,
         bool flip_y = false)
 {
-	copyStretchSpriteToScreen(GetP8SpriteSheetBuffer(), sx, sy, sw, sh, dx, dy, dw, dh, flip_x, flip_y);
+	copyStretchSpriteToScreen(GetP8SpriteSheetBuffer(), sx, sy, sw, sh, dx, dy, dw, dh, flip_x, flip_y, false);
 }

 bool Graphics::fget(uint8_t n, uint8_t f){
diff --git a/source/graphics.h b/source/graphics.h
index ce3a0e2..757030a 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -35,7 +35,8 @@ class Graphics {
 		int scr_w,
 		int scr_h,
 		bool flip_x,
-		bool flip_y);
+		bool flip_y,
+		bool skipStretchPx);

 	void swap(int *x, int *y);
 	void applyCameraToPoint(int *x, int *y);
diff --git a/source/printHelper.cpp b/source/printHelper.cpp
index 525eb0f..119a720 100644
--- a/source/printHelper.cpp
+++ b/source/printHelper.cpp
@@ -204,13 +204,14 @@ int print(std::string str, int x, int y, uint8_t c) {
             else if (commandChar == 'w'){
                 printMode |= PRINT_MODE_ON;
                 printMode |= PRINT_MODE_WIDE;
-
+                charWidth *=2;
             }
             else if (commandChar == 't'){
                 printMode |= PRINT_MODE_ON;
                 printMode |= PRINT_MODE_TALL;
+                charHeight *=2;
             }
-            else if (commandChar == '.'){
+            else if (commandChar == '='){
                 printMode |= PRINT_MODE_ON;
                 printMode |= PRINT_MODE_STRIPEY;
             }
@@ -219,6 +220,8 @@ int print(std::string str, int x, int y, uint8_t c) {
                 printMode |= PRINT_MODE_WIDE;
                 printMode |= PRINT_MODE_TALL;
                 printMode |= PRINT_MODE_STRIPEY;
+                charWidth *=2;
+                charHeight *=2;
             }
             else if (commandChar == 'i'){
                 printMode |= PRINT_MODE_ON;
diff --git a/test/printHelperTests.cpp b/test/printHelperTests.cpp
index 68bc893..9d2430e 100644
--- a/test/printHelperTests.cpp
+++ b/test/printHelperTests.cpp
@@ -404,14 +404,14 @@ TEST_CASE("Print helper functions") {
     SUBCASE("p8scii special control code for wide character(\\^w) ") {
         graphics->cls();

-        print("\x06""w:", 0, 0);
+        print("\x06""w::", 0, 0);

         std::vector<coloredPoint> expectedPoints = {
-            {2, 0, 0}, {3, 0, 0},
-            {2, 1, 6}, {3, 1, 6},
-            {2, 2, 0}, {3, 2, 0},
-            {2, 3, 6}, {3, 3, 6},
-            {2, 4, 0}, {3, 4, 0}
+            {2, 0, 0}, {3, 0, 0},    {10, 0, 0}, {11, 0, 0},
+            {2, 1, 6}, {3, 1, 6},    {10, 1, 6}, {11, 1, 6},
+            {2, 2, 0}, {3, 2, 0},    {10, 2, 0}, {11, 2, 0},
+            {2, 3, 6}, {3, 3, 6},    {10, 3, 6}, {11, 3, 6},
+            {2, 4, 0}, {3, 4, 0},    {10, 4, 0}, {11, 4, 0},
         };

         checkPoints(graphics, expectedPoints);
@@ -419,7 +419,7 @@ TEST_CASE("Print helper functions") {
     SUBCASE("p8scii special control code for char height(\\^t) ") {
         graphics->cls();

-        print("\x06""t:", 0, 0);
+        print("\x06""t:\n:", 0, 0);

         std::vector<coloredPoint> expectedPoints = {
             {1, 0, 0},
@@ -430,7 +430,76 @@ TEST_CASE("Print helper functions") {
             {1, 5, 0},
             {1, 6, 6},
             {1, 7, 6},
-            {1, 8, 0}
+            {1, 8, 0},
+            {1, 9, 0},
+
+            {1, 10, 0},
+            {1, 11, 0},
+
+            {1, 12, 0},
+            {1, 13, 0},
+            {1, 14, 6},
+            {1, 15, 6},
+            {1, 16, 0},
+            {1, 17, 0},
+            {1, 18, 6},
+            {1, 19, 6},
+            {1, 20, 0}
+        };
+
+        checkPoints(graphics, expectedPoints);
+    }
+    SUBCASE("p8scii special control code for wide character with stripey option(\\^w\\^=) ") {
+        graphics->cls();
+
+        print("\x06""w""\x06""=:", 0, 0);
+
+        std::vector<coloredPoint> expectedPoints = {
+            {2, 0, 0}, {3, 0, 0},
+            {2, 1, 6}, {3, 1, 0},
+            {2, 2, 0}, {3, 2, 0},
+            {2, 3, 6}, {3, 3, 0},
+            {2, 4, 0}, {3, 4, 0},
+        };
+
+        checkPoints(graphics, expectedPoints);
+    }
+    SUBCASE("p8scii special control code for char height with stripey option(\\^t\\^=) ") {
+        graphics->cls();
+
+        print("\x06""t""\x06""=:", 0, 0);
+
+        std::vector<coloredPoint> expectedPoints = {
+            {1, 0, 0},
+            {1, 1, 0},
+            {1, 2, 6},
+            {1, 3, 0},
+            {1, 4, 0},
+            {1, 5, 0},
+            {1, 6, 6},
+            {1, 7, 0},
+            {1, 8, 0},
+            {1, 9, 0}
+        };
+
+        checkPoints(graphics, expectedPoints);
+    }
+    SUBCASE("p8scii special control code for pinball option(\\^p) ") {
+        graphics->cls();
+
+        print("\x06""p:", 0, 0);
+
+        std::vector<coloredPoint> expectedPoints = {
+            {2, 0, 0}, {3, 0, 0},
+            {2, 1, 0}, {3, 1, 0},
+            {2, 2, 6}, {3, 2, 0},
+            {2, 3, 0}, {3, 3, 0},
+            {2, 4, 0}, {3, 4, 0},
+            {2, 5, 0}, {3, 5, 0},
+            {2, 6, 6}, {3, 6, 0},
+            {2, 7, 0}, {3, 7, 0},
+            {2, 8, 0}, {3, 8, 0},
+            {2, 9, 0}, {3, 9, 0}
         };

         checkPoints(graphics, expectedPoints);