foxygit / fake-08-xbox360 Log in
commit 769c98ca5d9ad8c8e91257abe0a28cc59619b44d
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Sat Mar 4 20:08:12 2023 -0700
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Sat Mar 4 20:08:12 2023 -0700

    Honor custom font dimensions

    Fix pico world race big numbers
---
 source/printHelper.cpp                             |   5 ++
 test/carts/ppwr-big-digit-test.p8                  |  60 +++++++++++++++++++++
 test/carts/screenshots/ppwr-big-digit-test_f01.png | Bin 0 -> 638 bytes
 test/endtoendtests.cpp                             |  14 +++++
 4 files changed, 79 insertions(+)

diff --git a/source/printHelper.cpp b/source/printHelper.cpp
index 5187e19..c7b435b 100644
--- a/source/printHelper.cpp
+++ b/source/printHelper.cpp
@@ -156,6 +156,11 @@ int print(std::string str, int x, int y, uint8_t c) {
         printMode = 0;
     }

+    if ((printMode & PRINT_MODE_CUSTOM_FONT)) {
+        charWidth = _ph_mem->data[0x5600];
+        charHeight = _ph_mem->data[0x5602];
+    }
+
     uint8_t* drawPal = _ph_mem->drawState.drawPaletteMap;

     int framesBetweenChars = 0;
diff --git a/test/carts/ppwr-big-digit-test.p8 b/test/carts/ppwr-big-digit-test.p8
new file mode 100644
index 0000000..3187839
--- /dev/null
+++ b/test/carts/ppwr-big-digit-test.p8
@@ -0,0 +1,60 @@
+pico-8 cartridge // http://www.pico-8.com
+version 41
+__lua__
+--font used from Pico World Race https://www.lexaloffle.com/bbs/?pid=106518
+--https://creativecommons.org/licenses/by-nc-sa/4.0/
+-- custom font
+font="8,8,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,248,252,28,28,0,0,0,15,31,63,56,56,0,0,0,192,192,192,128,128,0,0,0,3,3,3,3,3,0,0,0,252,252,252,0,240,0,0,0,15,31,63,56,63,0,0,0,252,252,252,0,252,0,0,0,15,31,63,56,63,0,0,0,224,240,120,60,28,0,0,0,28,28,28,28,28,0,0,0,252,252,252,28,252,0,0,0,63,63,63,0,15,0,0,0,240,248,252,28,252,0,0,0,31,31,31,0,15,0,0,0,240,248,252,28,0,0,0,0,15,31,63,56,56,28,28,28,252,248,240,0,0,56,56,56,63,31,15,0,0,128,128,128,128,128,128,0,0,3,3,3,3,3,3,0,0,248,252,28,252,252,252,0,0,31,15,0,63,63,63,0,0,252,252,0,252,252,252,0,0,63,63,56,63,31,15,0,0,28,252,248,0,0,0,0,0,28,63,63,28,28,28,0,0,252,252,0,252,252,252,0,0,31,63,56,63,31,15,0,0,252,252,28,252,248,240,0,0,31,63,56,63,31,15,0,0,0,0,0,0,128,128,0,0,56,60,30,15,7,3,0,0,0,0,0,240,248,252,28,252,0,0,0,15,31,63,56,63,0,0,0,240,248,252,28,252,0,0,0,15,31,63,56,63,0,0,0,240,248,252,28,156,0,0,0,63,63,63,0,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,252,28,252,248,240,0,0,63,63,56,63,31,15,0,0,252,248,0,248,248,248,0,0,63,63,56,63,63,31,0,0,156,156,28,252,248,240,0,0,63,63,56,63,63,63,0,0,0,0,0,0,0,0,0,0,0"
+
+
+function _init()
+--font init
+memset(0x5600,0,256*8)
+poke(0x5600,unpack(split(font)))
+
+end
+
+function _draw()
+cls(1)
+printbigdigitoutline( 10,50,30, 0 )
+printbigdigit(10,50,30)
+
+printbigdigitoutline(5,50,50,0 )
+printbigdigit(5,50,50)
+
+printbigdigit(3,10,10)
+
+printbigdigitoutline(4,10,30,7)
+
+printbigdigit(9,10,50)
+
+end
+
+function printbigdigit( n, x, y,nrend)
+x-=2
+if not nrend then
+poke(0x5f58, 0x1 | 0x80) --custom font
+  n1=n*2+16+n\8*16
+  print(chr(n1)..chr(n1+1).."\n"..chr(n1+16)..chr(n1+17),x,y-3,7) --4 chars to print 1 big
+poke(0x5f58, 0x0) --default font
+end
+if (n==1) return 12
+return 16
+end
+
+function printbigdigitoutline( n, x, y, col )
+i=n+1
+pal( 7, col )
+printbigdigit( n, x-1, y )
+printbigdigit( n, x+1, y )
+printbigdigit( n, x, y-1 )
+printbigdigit( n, x, y+1 )
+pal( 7, 7 )
+end
+__gfx__
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
diff --git a/test/carts/screenshots/ppwr-big-digit-test_f01.png b/test/carts/screenshots/ppwr-big-digit-test_f01.png
new file mode 100644
index 0000000..0741671
Binary files /dev/null and b/test/carts/screenshots/ppwr-big-digit-test_f01.png differ
diff --git a/test/endtoendtests.cpp b/test/endtoendtests.cpp
index d82551f..43a20af 100644
--- a/test/endtoendtests.cpp
+++ b/test/endtoendtests.cpp
@@ -707,6 +707,20 @@ TEST_CASE("Loading and running carts") {

         vm->CloseCart();
     }
+    SUBCASE("custom font test"){
+        //font used from Pico World Race https://www.lexaloffle.com/bbs/?pid=106518
+        //https://creativecommons.org/licenses/by-nc-sa/4.0/
+        vm->LoadCart("ppwr-big-digit-test.p8");
+
+        SUBCASE("sceen matches screenshot"){
+            vm->UpdateAndDraw();
+
+            CHECK(verifyScreenshot(vm, host, "carts/screenshots/ppwr-big-digit-test_f01.png"));
+        }
+
+        vm->CloseCart();
+    }
+

     delete vm;
     delete host;