foxygit / fake-08-xbox360 Log in
commit 733e16cf90945c702057bcb0de5963515a458754
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Sat Jul 9 10:36:24 2022 -0600
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Sat Jul 9 10:36:24 2022 -0600

    WIP slightly off char printing from ctrl code
---
 source/graphics.cpp    | 20 ++++++++++++++++++++
 source/graphics.h      |  2 ++
 source/printHelper.cpp | 29 +++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+)

diff --git a/source/graphics.cpp b/source/graphics.cpp
index 98f5c21..632d1e6 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -4,6 +4,7 @@
 #include <string.h>
 #include <string>
 #include <algorithm>
+#include <vector>

 #include "graphics.h"
 #include "hostVmShared.h"
@@ -1316,6 +1317,25 @@ int Graphics::drawCharacter(uint8_t ch, int x, int y, uint8_t printMode) {
 	return extraCharWidth;
 }

+int Graphics::drawCharacterFromBytes(std::vector<uint8_t> chBytes, int x, int y, uint8_t printMode) {
+	int extraCharWidth = 0;
+	if (chBytes.size() != 8){
+		return 0;
+	}
+	//TODO: character modes
+
+	for (size_t i = 0; i < chBytes.size(); i++) {
+		for(uint8_t bitn = 0; bitn < 8; bitn++) {
+			bool on = BITMASK(bitn) & chBytes[i];
+			if (on) {
+				pset(x + bitn, y+ i);
+			}
+		}
+	}
+
+	return extraCharWidth;
+}
+
 void Graphics::spr(
 	int n,
 	int x,
diff --git a/source/graphics.h b/source/graphics.h
index f385097..428c7fe 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -2,6 +2,7 @@

 #include <string>
 #include <tuple>
+#include <vector>
 #include "hostVmShared.h"
 #include "PicoRam.h"
 #include <fix32.h>
@@ -110,6 +111,7 @@ class Graphics {
 	fix32 fillp(fix32 pat);

 	int drawCharacter(uint8_t ch, int x, int y, uint8_t printMode = 0);
+	int drawCharacterFromBytes(std::vector<uint8_t> chBytes, int x, int y, uint8_t printMode = 0);

 	void spr(
 		int n,
diff --git a/source/printHelper.cpp b/source/printHelper.cpp
index 8e471dd..4618f6b 100644
--- a/source/printHelper.cpp
+++ b/source/printHelper.cpp
@@ -12,6 +12,20 @@ Graphics* _ph_graphics;
 Vm* _ph_vm;
 Audio* _ph_audio;

+std::vector<uint8_t> oneOffCharToBytes(std::string hex) {
+  std::vector<uint8_t> bytes;
+  char buff[3];
+  buff[2] = 0;
+  for (unsigned int i = 0; i < hex.length(); i += 2) {
+    buff[0] = hex[i+ 1];
+    buff[1] = hex[i];
+    uint8_t byte = (uint8_t) strtol(buff, NULL, 16);
+    bytes.push_back(byte);
+  }
+
+  return bytes;
+}
+
 void initPrintHelper(PicoRam* memory, Graphics* graphics, Vm* vm, Audio* audio) {
     _ph_mem = memory;
     _ph_graphics = graphics;
@@ -86,6 +100,7 @@ int print(std::string str, int x, int y, uint8_t c) {
     int charHeight = 6;
     int lineHeight = 6;
     uint8_t bgColor = 0;
+    std::vector<uint8_t> charBytes;

     uint8_t printMode = _ph_mem->hwState.printAttributes;

@@ -242,6 +257,20 @@ int print(std::string str, int x, int y, uint8_t c) {
                 printMode |= PRINT_MODE_ON;
                 printMode |= PRINT_MODE_SOLID_BG;
             }
+            else if (commandChar == ':'){
+                std::string hexStr = str.substr(n, 16);
+                n+=16;
+                charBytes = oneOffCharToBytes(hexStr);
+
+                //TODO: combine with other text rendering
+                x += charWidth + _ph_graphics->drawCharacterFromBytes(charBytes, x, y, printMode);
+            }
+            else if (commandChar == '.'){
+                std::string binStr = str.substr(n, 8);
+                n+=8;
+                //todo: convert bin string to char bytes
+
+            }
             else if (commandChar == '-'){
                 uint8_t turnOffModeChar = str[++n];
                 if (printMode) {