commit 0f3596c70bbfc2dfc8b0db30cc185b198242f682
Author: Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Sun Sep 14 16:35:29 2025 -0600
Commit: Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Sun Sep 14 16:41:29 2025 -0600
add basics of p8scii outline
---
source/printHelper.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++
test/printHelperTests.cpp | 15 +++++++++++++++
2 files changed, 61 insertions(+)
diff --git a/source/printHelper.cpp b/source/printHelper.cpp
index 2b423a9..42822d7 100644
--- a/source/printHelper.cpp
+++ b/source/printHelper.cpp
@@ -149,6 +149,8 @@ int print(std::string str, int x, int y, uint8_t c) {
uint8_t charBytes[8];
uint8_t audioStrBytes[32];
bool cancelWrap = false;
+ uint8_t outlineColor = 0;
+ uint8_t outlineNeighbors = 0;
uint8_t printMode = _ph_mem->hwState.printAttributes;
@@ -407,6 +409,21 @@ int print(std::string str, int x, int y, uint8_t c) {
for(size_t i = 0; i < size; i++) {
_ph_mem->data[addr + i] = binStr[i];
}
+ }
+ else if (commandChar == 'o'){
+ //Pico-8 docs for outline:
+ //The first character after the command "\^o" is the colour, and the following two
+ // characters are the neighbours bitfield in hexadecimal. For example, to draw a pixel up
+ // to the left of each foreground pixel, the value 0x01 can be used:
+
+ // > ?"\^o801hey"
+
+ uint8_t outlineColorChar = str[++n];
+ outlineColor = p0CharToNum(outlineColorChar);
+
+ std::string neighborsHexStr = str.substr(n+1, 2);
+ n+=2;
+ outlineNeighbors = (uint8_t)strtol(neighborsHexStr.c_str(), NULL, 16);
}
}
else if (ch == 7) { // "\a" audio command
@@ -473,6 +490,35 @@ int print(std::string str, int x, int y, uint8_t c) {
}
prevX = x;
prevY = y;
+ if (outlineColor != 0 && outlineNeighbors != 0) {
+ /*
+ 0x01 0x02 0x04
+ 0x08 -- 0x10
+ 0x20 0x40 0x80
+ */
+ int xOffsets[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
+ int yOffsets[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
+
+ for (int i = 0; i < 8; i++) {
+ int xOffset = xOffsets[i];
+ int yOffset = yOffsets[i];
+
+ if (xOffset == 0 && yOffset == 0) {
+ continue;
+ }
+ if (outlineNeighbors & (1 << i)) {
+ _ph_graphics->drawCharacter(
+ ch,
+ x + xOffset,
+ y + yOffset,
+ drawPal[outlineColor & 0x0f],
+ bgColor == 0xff ? 0 : drawPal[bgColor & 0x0f],
+ printMode,
+ forceCharWidth,
+ forceCharHeight);
+ }
+ }
+ }
x += charWidth + _ph_graphics->drawCharacter(
ch,
x,
diff --git a/test/printHelperTests.cpp b/test/printHelperTests.cpp
index 95ac09a..6c69123 100644
--- a/test/printHelperTests.cpp
+++ b/test/printHelperTests.cpp
@@ -849,6 +849,21 @@ TEST_CASE("Print helper functions") {
checkPoints(graphics, expectedPoints);
}
+ SUBCASE("p8scii special control code for outline(\\^o) ") {
+ graphics->cls(2);
+
+ print("\x06""o8ff:", 0, 0, 3);
+
+ std::vector<coloredPoint> expectedPoints = {
+ {0, 0, 8}, {1, 0, 8}, {2, 0, 8},
+ {0, 1, 8}, {1, 1, 3}, {2, 1, 8},
+ {0, 2, 8}, {1, 2, 8}, {2, 2, 8},
+ {0, 3, 8}, {1, 3, 3}, {2, 3, 8},
+ {0, 4, 8}, {1, 4, 8}, {2, 4, 8},
+ };
+
+ checkPoints(graphics, expectedPoints);
+ }
delete stubHost;
delete graphics;