foxygit / fake-08-xbox360 Log in
commit 7ab26fa03284a95ff5ef2f4525ef06ecdf6d4abf
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Wed Jan 11 07:13:53 2023 -0700
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Wed Jan 11 07:13:53 2023 -0700

    WIP- more progress refactoring text rendering
---
 source/fontdata.h      |  2 +-
 source/graphics.cpp    | 65 ++++++++++++++++++++++++++++++++++++++++----------
 source/graphics.h      |  5 +++-
 source/printHelper.cpp |  6 +++--
 4 files changed, 61 insertions(+), 17 deletions(-)

diff --git a/source/fontdata.h b/source/fontdata.h
index 39f7b5f..608da90 100644
--- a/source/fontdata.h
+++ b/source/fontdata.h
@@ -4,7 +4,7 @@

 std::string get_font_data();

-const uint8_t defaultFontBinaryData[2048] = {
+uint8_t defaultFontBinaryData[2048] = {
 // char 0 -- info about how to render font
 4, //0x5600 character width in pixels (can be more than 8, but only 8 pixels are drawn)
 8, //0x5601 character width for character 128 and above
diff --git a/source/graphics.cpp b/source/graphics.cpp
index 80a58a4..848a68c 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -10,6 +10,7 @@
 #include "hostVmShared.h"
 #include "nibblehelpers.h"
 #include "mathhelpers.h"
+#include "fontdata.h"

 #include "stringToDataHelpers.h"

@@ -1337,6 +1338,20 @@ int Graphics::drawCharacter(
 		}
 	}
 	else if ((printMode & PRINT_MODE_CUSTOM_FONT) == PRINT_MODE_CUSTOM_FONT) {
+		uint8_t charWidth =
+			ch < 0x80
+			? forceCharWidth > -1 && forceCharWidth < 4 ? forceCharWidth : _memory->data[0x5600]
+			: forceCharWidth > -1 && forceCharWidth < 4 ? forceCharWidth : _memory->data[0x5601];
+
+		uint8_t charHeight = forceCharHeight > -1 && forceCharHeight < 5 ? forceCharHeight : _memory->data[0x5602];
+
+		if (charWidth > 8) {
+			charWidth = 8;
+		}
+		if (charHeight > 8) {
+			charHeight = 8;
+		}
+
 		if (ch > 0x0f) {
 			drawCharacterFromBytes(
 				&(_memory->data[0x5600 + ch*8]),//get bytes from memory (0x5600)
@@ -1344,7 +1359,9 @@ int Graphics::drawCharacter(
 				y,
 				fgColor,
 				bgColor,
-				printMode
+				printMode,
+				charWidth,
+				charHeight
 			);
 		}

@@ -1352,15 +1369,38 @@ int Graphics::drawCharacter(
 	}
 	else{
 		if (ch >= 0x10 && ch < 0x80) {
-			int index = ch - 0x10;
-			int width = forceCharWidth > -1 && forceCharWidth < 4 ? forceCharWidth : 4;
-			int height = forceCharHeight > -1 && forceCharHeight < 5 ? forceCharHeight : 5;
-			copySpriteToScreen(fontSpriteData, x, y, (index % 16) * 8, (index / 16) * 8, width, height, false, false);
+			uint8_t charWidth = forceCharWidth > -1 && forceCharWidth < 4 ? forceCharWidth : 4;
+			uint8_t charHeight = forceCharHeight > -1 && forceCharHeight < 5 ? forceCharHeight : 5;
+
+			//need to pass in w/h to crop
+			drawCharacterFromBytes(
+				&(defaultFontBinaryData[ch*8]),//get bytes from memory (0x5600)
+				x,
+				y,
+				fgColor,
+				bgColor,
+				printMode,
+				charWidth,
+				charHeight
+			);
+
+			//copySpriteToScreen(fontSpriteData, x, y, (index % 16) * 8, (index / 16) * 8, width, height, false, false);
 		} else if (ch >= 0x80) {
-			int index = ch - 0x80;
-			int width = forceCharWidth > -1 && forceCharWidth < 4 ? (forceCharWidth + 4) : 8;
-			int height = forceCharHeight > -1 && forceCharHeight < 5 ? forceCharHeight : 5;
-			copySpriteToScreen(fontSpriteData, x, y, (index % 16) * 8, (index / 16) * 8 + 56, width, height, false, false);
+			uint8_t charWidth = forceCharWidth > -1 && forceCharWidth < 4 ? (forceCharWidth + 4) : 8;
+			uint8_t charHeight = forceCharHeight > -1 && forceCharHeight < 5 ? forceCharHeight : 5;
+
+			drawCharacterFromBytes(
+				&(defaultFontBinaryData[ch*8]),//get bytes from memory (0x5600)
+				x,
+				y,
+				fgColor,
+				bgColor,
+				printMode,
+				charWidth,
+				charHeight
+			);
+
+			//copySpriteToScreen(fontSpriteData, x, y, (index % 16) * 8, (index / 16) * 8 + 56, width, height, false, false);
 			extraCharWidth = 4;
 		}
 	}
@@ -1374,16 +1414,15 @@ std::tuple<int, int> Graphics::drawCharacterFromBytes(
 	int y,
 	uint8_t fgColor,
 	uint8_t bgColor,
-	uint8_t printMode) {
+	uint8_t printMode,
+	uint8_t charWidth,
+	uint8_t charHeight) {

 	applyCameraToPoint(&x, &y);
 	uint8_t *screenBuffer = GetP8FrameBuffer();

 	int extraCharWidth = 0;
 	int extraCharHeight = 0;
-	//these may need to get passed in later when drawing normal chars
-	int charWidth = 8;
-	int charHeight = 8;
 	int wFactor = 1;
 	int hFactor = 1;
 	//TODO: character modes
diff --git a/source/graphics.h b/source/graphics.h
index b5e441e..c05d06e 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -9,6 +9,7 @@ using namespace z8;


 class Graphics {
+	//deprecated
 	uint8_t fontSpriteData[128 * 64];

 	PicoRam* _memory;
@@ -125,7 +126,9 @@ class Graphics {
 		int y,
 		uint8_t fgColor,
 		uint8_t bgColor,
-		uint8_t printMode);
+		uint8_t printMode,
+		uint8_t charWidth,
+		uint8_t charHeight);

 	void spr(
 		int n,
diff --git a/source/printHelper.cpp b/source/printHelper.cpp
index d3bfb7c..4d19b66 100644
--- a/source/printHelper.cpp
+++ b/source/printHelper.cpp
@@ -294,7 +294,9 @@ int print(std::string str, int x, int y, uint8_t c) {
                     y,
                     prevDrawPal[fgColor & 0x0f],
                     bgColor,
-                    printMode);
+                    printMode,
+                    8,
+                    charHeight);

                 x += 8 + get<0>(values);
                 charHeight = charHeight + get<1>(values);
@@ -409,7 +411,7 @@ int print(std::string str, int x, int y, uint8_t c) {
                 printMode,
                 forceCharWidth,
                 forceCharHeight);
-
+
             while (framesToPause > 0){
                 _ph_vm->vm_flip();