commit ae54159e86507f9159cece35bb28e5abe0857bc0
Author: Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Fri Jan 2 18:43:28 2026 -0700
Commit: Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Fri Jan 2 18:43:28 2026 -0700
Fix issues with solid backgrounds in p8scii
---
source/graphics.cpp | 12 ++---
source/printHelper.cpp | 7 ++-
test/carts/p8scii_bg_custom_font_test.p8 | 21 +++++++++
.../screenshots/p8scii_bg_custom_font_test_f01.png | Bin 0 -> 555 bytes
test/endtoendtests.cpp | 16 +++++++
test/printHelperTests.cpp | 52 +++++++++++++++++++++
6 files changed, 99 insertions(+), 9 deletions(-)
diff --git a/source/graphics.cpp b/source/graphics.cpp
index 86423c2..5df8ab6 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -21,7 +21,6 @@ using namespace std;
#include <fix32.h>
using namespace z8;
-
//call initialize to make sure defaults are correct
Graphics::Graphics(std::string fontdata, PicoRam* memory) {
_memory = memory;
@@ -1604,12 +1603,11 @@ std::tuple<int, int> Graphics::drawCharacterFromBytes(
on = !on;
}
- if (on) {
- setPixelNibble(absDestX, absDestY, fgColor, screenBuffer);
- }
- if(!on && (solidBg || bgColor > 0)) {
- setPixelNibble(absDestX, absDestY, bgColor, screenBuffer);
- }
+ if (on) {
+ setPixelNibble(absDestX, absDestY, fgColor, screenBuffer);
+ } else if (solidBg) {
+ setPixelNibble(absDestX, absDestY, bgColor, screenBuffer);
+ }
}
}
}
diff --git a/source/printHelper.cpp b/source/printHelper.cpp
index b4298db..e7255ec 100644
--- a/source/printHelper.cpp
+++ b/source/printHelper.cpp
@@ -133,6 +133,7 @@ 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 length = str.length();
+
int homeX = x;
int homeY = y;
int prevX = x;
@@ -200,6 +201,8 @@ int print(std::string str, int x, int y, uint8_t c) {
else if (ch == 2) { // "\#{p0}" draw text on a solid background color
uint8_t bgColChar = str[++n];
bgColor = p0CharToNum(bgColChar);
+ printMode |= PRINT_MODE_ON;
+ printMode |= PRINT_MODE_SOLID_BG;
}
else if (ch == 3) { // "\-{p0}" move text cursor horizontally by 16-p0 pixels
uint8_t pixelCountChar = str[++n];
@@ -375,7 +378,7 @@ int print(std::string str, int x, int y, uint8_t c) {
else if (turnOffModeChar == 'b') {
printMode &= ~(PRINT_MODE_PADDING);
}
- else if (turnOffModeChar == 'b') {
+ else if (turnOffModeChar == '#') {
printMode &= ~(PRINT_MODE_SOLID_BG);
}
}
@@ -493,7 +496,7 @@ int print(std::string str, int x, int y, uint8_t c) {
}
else if (ch >= 0x10) {
lineHeight = charHeight > lineHeight ? charHeight : lineHeight;
- if (bgColor != 0xff) {
+ if (printMode & PRINT_MODE_SOLID_BG) {
uint8_t prevPenColor = _ph_mem->drawState.color;
_ph_graphics->rectfill(x-1, y-1, x + charWidth-1, y + lineHeight-1, bgColor);
_ph_mem->drawState.color = prevPenColor;
diff --git a/test/carts/p8scii_bg_custom_font_test.p8 b/test/carts/p8scii_bg_custom_font_test.p8
new file mode 100644
index 0000000..898653b
--- /dev/null
+++ b/test/carts/p8scii_bg_custom_font_test.p8
@@ -0,0 +1,21 @@
+pico-8 cartridge // http://www.pico-8.com
+version 43
+__lua__
+function _init()
+poke(22016,unpack(split"8,8,10,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,63,63,63,63,63,63,63,0,0,0,63,63,63,0,0,0,0,0,63,51,63,0,0,0,0,0,51,12,51,0,0,0,0,0,51,0,51,0,0,0,0,0,51,51,51,0,0,0,0,48,60,63,60,48,0,0,0,3,15,63,15,3,0,0,62,6,6,6,6,0,0,0,0,0,48,48,48,48,62,0,99,54,28,62,8,62,8,0,0,0,0,24,0,0,0,0,0,0,0,0,0,12,24,0,0,0,0,0,0,12,12,0,0,0,10,10,0,0,0,0,0,4,10,4,0,0,0,0,0,0,0,0,0,0,0,0,12,12,12,12,12,0,12,0,0,54,54,0,0,0,0,0,0,54,127,54,54,127,54,0,8,62,11,62,104,62,8,0,0,51,24,12,6,51,0,0,14,27,27,110,59,59,110,0,12,12,0,0,0,0,0,0,24,12,6,6,6,12,24,0,12,24,48,48,48,24,12,0,0,54,28,127,28,54,0,0,0,12,12,63,12,12,0,0,0,0,0,0,0,12,12,6,0,0,0,62,0,0,0,0,0,0,0,0,0,12,12,0,32,48,24,12,6,3,1,0,62,99,115,107,103,99,62,0,24,28,24,24,24,24,60,0,63,96,96,62,3,3,127,0,63,96,96,60,96,96,63,0,51,51,51,126,48,48,48,0,127,3,3,63,96,96,63,0,62,3,3,63,99,99,62,0,127,96,48,24,12,12,12,0,62,99,99,62,99,99,62,0,62,99,99,126,96,96,62,0,0,0,12,0,0,12,0,0,0,0,12,0,0,12,6,0,48,24,12,6,12,24,48,0,0,0,30,0,30,0,0,0,6,12,24,48,24,12,6,0,30,51,48,24,12,0,12,0,0,30,51,59,59,3,30,0,0,0,62,96,126,99,126,0,3,3,63,99,99,99,63,0,0,0,62,99,3,99,62,0,96,96,126,99,99,99,126,0,0,0,62,99,127,3,62,0,124,6,6,63,6,6,6,0,0,0,126,99,99,126,96,62,3,3,63,99,99,99,99,0,0,24,0,28,24,24,60,0,48,0,56,48,48,48,51,30,3,3,51,27,15,27,51,0,12,12,12,12,12,12,56,0,0,0,99,119,127,107,99,0,0,0,63,99,99,99,99,0,0,0,62,99,99,99,62,0,0,0,63,99,99,63,3,3,0,0,126,99,99,126,96,96,0,0,62,99,3,3,3,0,0,0,62,3,62,96,62,0,12,12,62,12,12,12,56,0,0,0,99,99,99,99,126,0,0,0,99,99,34,54,28,0,0,0,99,99,107,127,54,0,0,0,99,54,28,54,99,0,0,0,99,99,99,126,96,62,0,0,127,112,28,7,127,0,62,6,6,6,6,6,62,0,1,3,6,12,24,48,32,0,62,48,48,48,48,48,62,0,12,30,18,0,0,0,0,0,0,0,0,0,0,0,30,0,12,24,0,0,0,0,0,0,28,54,99,99,127,99,99,0,63,99,99,63,99,99,63,0,62,99,3,3,3,99,62,0,31,51,99,99,99,51,31,0,127,3,3,63,3,3,127,0,127,3,3,63,3,3,3,0,62,3,3,115,99,99,126,0,99,99,99,127,99,99,99,0,63,12,12,12,12,12,63,0,127,24,24,24,24,24,15,0,99,51,27,15,27,51,99,0,3,3,3,3,3,3,127,0,99,119,127,107,99,99,99,0,99,103,111,107,123,115,99,0,62,99,99,99,99,99,62,0,63,99,99,63,3,3,3,0,62,99,99,99,99,51,110,0,63,99,99,63,27,51,99,0,62,99,3,62,96,99,62,0,63,12,12,12,12,12,12,0,99,99,99,99,99,99,62,0,99,99,99,99,54,28,8,0,99,99,99,107,127,119,99,0,99,99,54,28,54,99,99,0,99,99,99,126,96,96,63,0,127,96,48,28,6,3,127,0,56,12,12,7,12,12,56,0,8,8,8,0,8,8,8,0,14,24,24,112,24,24,14,0,0,0,110,59,0,0,0,0,0,0,0,0,0,0,0,0,127,127,127,127,127,127,127,0,85,42,85,42,85,42,85,0,65,99,127,93,93,119,62,0,62,99,99,119,62,65,62,0,17,68,17,68,17,68,17,0,4,12,124,62,31,24,16,0,28,38,95,95,127,62,28,0,34,119,127,127,62,28,8,0,42,28,54,119,54,28,42,0,28,28,62,93,28,20,20,0,8,28,62,127,62,42,58,0,62,103,99,103,62,65,62,0,62,127,93,93,127,99,62,0,24,120,8,8,8,15,7,0,62,99,107,99,62,65,62,0,8,20,42,93,42,20,8,0,0,0,0,85,0,0,0,0,62,115,99,115,62,65,62,0,8,28,127,28,54,34,0,0,127,34,20,8,20,34,127,0,62,119,99,99,62,65,62,0,0,10,4,0,80,32,0,0,17,42,68,0,17,42,68,0,62,107,119,107,62,65,62,0,127,0,127,0,127,0,127,0,85,85,85,85,85,85,85,0"))
+
+end
+
+function _draw()
+ cls()
+ print("⁶-b⁶x8⁶y8 ᶜ2⁶.\0\0\0\0█ナユュ⁶.\0█ヲ◜◝◝◝◝⁶.ナ◝◝◝◝◝◝◝²2 ⁶-#⁶.⁷◝◝◝◝◝◝◝⁶.\0¹゜○◝◝◝◝⁶.\0\0\0\0¹⁷ᶠ?\n ")
+ print("ᵉcontroller",64-#"controller"*4,96,2)print("ᵉrecommended",64-#"recommended"*4,106,2)
+
+end
+__gfx__
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
diff --git a/test/carts/screenshots/p8scii_bg_custom_font_test_f01.png b/test/carts/screenshots/p8scii_bg_custom_font_test_f01.png
new file mode 100644
index 0000000..b549622
Binary files /dev/null and b/test/carts/screenshots/p8scii_bg_custom_font_test_f01.png differ
diff --git a/test/endtoendtests.cpp b/test/endtoendtests.cpp
index 722a52b..72eb999 100644
--- a/test/endtoendtests.cpp
+++ b/test/endtoendtests.cpp
@@ -954,6 +954,22 @@ TEST_CASE("Loading and running carts") {
vm->CloseCart();
}
+ SUBCASE("p8scii solid bg with custom font test"){
+ vm->LoadCart("p8scii_bg_custom_font_test.p8", false);
+ vm->vm_run();
+ vm->Step();
+
+ SUBCASE("No error reported"){
+ CHECK(vm->GetBiosError() == "");
+ }
+ SUBCASE("screen matches screenshot"){
+ vm->Step();
+
+ CHECK(verifyScreenshot(vm, host, "carts/screenshots/p8scii_bg_custom_font_test_f01.png"));
+ }
+
+ vm->CloseCart();
+ }
delete vm;
delete host;
diff --git a/test/printHelperTests.cpp b/test/printHelperTests.cpp
index ceac1b4..3f5b0c5 100644
--- a/test/printHelperTests.cpp
+++ b/test/printHelperTests.cpp
@@ -881,6 +881,58 @@ TEST_CASE("Print helper functions") {
checkPoints(graphics, expectedPoints);
}
+ SUBCASE("\\#p0 (char 2) automatically enables SOLID_BG mode") {
+ graphics->cls();
+
+ // \x02 (char 2) sets bgColor and enables solid bg mode
+ print("\x02""4 ", 0, 0);
+
+ //the space should just be a solid bg color of 4
+ std::vector<coloredPoint> expectedPoints = {
+ {0, 0, 4}, // bg fill from space
+ {1, 0, 4},
+ {2, 0, 4},
+ {3, 0, 4},
+ };
+
+ checkPoints(graphics, expectedPoints);
+ }
+ SUBCASE("⁶-# disables solid bg mode - subsequent chars have no bg fill") {
+ graphics->cls();
+
+ // \x02 4 enables solid bg with color 4
+ // Then \x06 -# disables solid bg mode
+ print("\x02""4 \x06""-# ", 0, 0);
+
+ std::vector<coloredPoint> expectedPoints = {
+ {0, 0, 4},
+ {1, 0, 4},
+ {2, 0, 4},
+ {3, 0, 4},
+ {4, 0, 0},
+ {5, 0, 0},
+ {6, 0, 0},
+ {7, 0, 0},
+ };
+
+ checkPoints(graphics, expectedPoints);
+ }
+ SUBCASE("⁶-# disables bg fill for raw pixel drawing too") {
+ graphics->cls();
+
+ print("\x02""4\x06"":0000000000000000\x06""-#\x06"":0000000000000000", 0, 0);
+
+ std::vector<coloredPoint> expectedPoints = {
+ {0, 0, 4},
+ {1, 0, 4},
+ {7, 0, 4},
+ {8, 0, 0},
+ {9, 0, 0},
+ {15, 0, 0},
+ };
+
+ checkPoints(graphics, expectedPoints);
+ }
delete stubHost;
delete graphics;