commit 3b32ab804dc433086eb3e3f9815002f89196fd62
Author: Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Mon Jan 19 11:24:04 2026 -0700
Commit: Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Mon Jan 19 11:24:04 2026 -0700
Add basic suppor for inverted color circfill
---
source/graphics.cpp | 68 +++++++++++++++++++++
source/graphics.h | 2 +
test/carts/invert_circfill_static.p8 | 25 ++++++++
.../screenshots/invert_circfill_static_f01.png | Bin 0 -> 1251 bytes
test/endtoendtests.cpp | 17 ++++++
test/graphicstests.cpp | 23 +++++++
6 files changed, 135 insertions(+)
diff --git a/source/graphics.cpp b/source/graphics.cpp
index d03029e..7aa66ec 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -1006,7 +1006,75 @@ void Graphics::circfill(int ox, int oy, int r){
this->circfill(ox, oy, r, _memory->drawState.color);
}
+void Graphics::_invertedCircfill(int ox, int oy, int r, uint8_t col){
+ color(col);
+
+ applyCameraToPoint(&ox, &oy);
+
+ int clipLeft = _memory->drawState.clip_xb;
+ int clipRight = _memory->drawState.clip_xe;
+ int clipTop = _memory->drawState.clip_yb;
+ int clipBottom = _memory->drawState.clip_ye;
+
+ int circleTop = oy - r;
+ int circleBottom = oy + r;
+
+ // Fill rows above the circle
+ for (int row = clipTop; row < circleTop && row < clipBottom; row++) {
+ _private_h_line(clipLeft, clipRight - 1, row);
+ }
+
+ // Fill rows that intersect the circle (left and right of circle)
+ if (r >= 0) {
+ int x = -r, y = 0, err = 2 - 2 * r;
+ int lastY = -1;
+ do {
+ // For each y offset, draw lines outside the circle
+ if (oy + y != lastY) {
+ // Right side of screen (to the right of circle)
+ if (ox + x + 1 < clipRight) {
+ _private_h_line(ox - x + 1, clipRight - 1, oy + y);
+ }
+ // Left side of screen (to the left of circle)
+ if (ox + x - 1 >= clipLeft) {
+ _private_h_line(clipLeft, ox + x - 1, oy + y);
+ }
+ }
+ if (y > 0 && oy - y != lastY) {
+ // Right side of screen (to the right of circle)
+ if (ox + x + 1 < clipRight) {
+ _private_h_line(ox - x + 1, clipRight - 1, oy - y);
+ }
+ // Left side of screen (to the left of circle)
+ if (ox + x - 1 >= clipLeft) {
+ _private_h_line(clipLeft, ox + x - 1, oy - y);
+ }
+ }
+ lastY = oy + y;
+ int savedR = r;
+ r = err;
+ if (r > x)
+ err += ++x * 2 + 1;
+ if (r <= y)
+ err += ++y * 2 + 1;
+ r = savedR;
+ } while (x < 0);
+ }
+
+ // Fill rows below the circle
+ for (int row = circleBottom + 1; row < clipBottom; row++) {
+ _private_h_line(clipLeft, clipRight - 1, row);
+ }
+}
+
void Graphics::circfill(int ox, int oy, int r, uint8_t col){
+ // Check if inverted fill mode is enabled (bit 1 of colorSettingFlag at 0x5f34)
+ bool invertedFill = (_memory->drawState.colorSettingFlag & 0x02) != 0;
+
+ if (invertedFill) {
+ return _invertedCircfill(ox, oy, r, col);
+ }
+
color(col);
applyCameraToPoint(&ox, &oy);
diff --git a/source/graphics.h b/source/graphics.h
index fe8810e..c6136eb 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -60,6 +60,8 @@ class Graphics {
void _private_v_line (int y1, int y2, int x);
int _getRRectCutAmount(int radius, int row);
+ void _invertedCircfill(int ox, int oy, int r, uint8_t col);
+
public:
Graphics(std::string fontdata, PicoRam* memory);
diff --git a/test/carts/invert_circfill_static.p8 b/test/carts/invert_circfill_static.p8
new file mode 100644
index 0000000..5b1a633
--- /dev/null
+++ b/test/carts/invert_circfill_static.p8
@@ -0,0 +1,25 @@
+pico-8 cartridge // http://www.pico-8.com
+version 43
+__lua__
+function _draw()
+
+ cls()
+ poke(0x5f34,0x2)
+
+ -- hold ❎ to skip fill
+ cc = circfill
+ if (btn(❎)) cc = circ
+
+ for z=7,1,-1 do
+ local sx = cos(z/15/4) * 50
+ local sy = sin(z/15/4) * 50
+ cc(64+sx/z,64+sy/z,64/z, 7+z | 0x1800)
+ end
+end
+__gfx__
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
diff --git a/test/carts/screenshots/invert_circfill_static_f01.png b/test/carts/screenshots/invert_circfill_static_f01.png
new file mode 100644
index 0000000..6cf3e48
Binary files /dev/null and b/test/carts/screenshots/invert_circfill_static_f01.png differ
diff --git a/test/endtoendtests.cpp b/test/endtoendtests.cpp
index ec8f197..0c7f517 100644
--- a/test/endtoendtests.cpp
+++ b/test/endtoendtests.cpp
@@ -1088,6 +1088,23 @@ TEST_CASE("Loading and running carts") {
vm->CloseCart();
}
+ // drawing isn't pixel perfect yet, so this test is disabled
+ // SUBCASE("inverted circfill test"){
+ // vm->LoadCart("inverted_circfill_static.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/inverted_circfill_static_f01.png"));
+ // }
+
+ // vm->CloseCart();
+ // }
delete vm;
delete host;
diff --git a/test/graphicstests.cpp b/test/graphicstests.cpp
index 04cc294..ef7548c 100644
--- a/test/graphicstests.cpp
+++ b/test/graphicstests.cpp
@@ -459,6 +459,29 @@ TEST_CASE("graphics class behaves as expected") {
checkPoints(graphics, expectedPoints);
}
+ SUBCASE("circfill({ox}, {oy}, {r}, {c}) with inverted mode fills outside circle") {
+ graphics->cls(8);
+ picoRam.drawState.colorSettingFlag = 0x02; // Enable inverted fill mode
+ graphics->circfill(40, 40, 2, 13);
+ std::vector<coloredPoint> expectedPoints = {
+ // Inside circle should be background color (8)
+ {40, 40, 8},
+ {39, 40, 8},
+ {40, 39, 8},
+ {41, 40, 8},
+ {40, 41, 8},
+ // Outside circle should be filled color (13)
+ {40, 37, 13},
+ {40, 43, 13},
+ {37, 40, 13},
+ {43, 40, 13},
+
+ {0, 0, 13},
+ {127, 127, 13},
+ };
+
+ checkPoints(graphics, expectedPoints);
+ }
SUBCASE("oval({x0}, {x1}, {y0}, {y1}, {c}) draws an ellipse") {
graphics->cls();
graphics->oval(40, 40, 45, 42, 13);