foxygit / fake-08-xbox360 Log in
commit 4378a4561805579b24ca665d712d4b523bc4acdd
Author:     jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Tue Feb 9 09:47:29 2021 -0700
Commit:     jtothebell <j.to.the.bell@gmail.com>
CommitDate: Tue Feb 9 09:47:29 2021 -0700

    Implement fillp to set values in memory
---
 source/graphics.cpp    | 12 ++++++++++++
 source/graphics.h      |  2 ++
 source/picoluaapi.cpp  |  7 ++++++-
 test/graphicstests.cpp | 12 ++++++++++++
 4 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/source/graphics.cpp b/source/graphics.cpp
index 0427251..e541ebf 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -935,6 +935,18 @@ void Graphics::rectfill(int x1, int y1, int x2, int y2, uint8_t col) {
 	}
 }

+void Graphics::fillp(fix32 pat) {
+	uint8_t patByte0 = pat.bits() >> 16;
+	uint8_t patByte1 = pat.bits() >> 24;
+
+	uint8_t patTranspByte = pat.bits() >> 15;
+
+	_memory->drawState.fillPattern[0] = patByte0;
+	_memory->drawState.fillPattern[1] = patByte1;
+
+	_memory->drawState.fillPatternTransparencyBit = patTranspByte & 1;
+}
+
 int Graphics::print(std::string str) {
 	int result = this->print(str, _memory->drawState.text_x, _memory->drawState.text_y);

diff --git a/source/graphics.h b/source/graphics.h
index 8086cb7..1366e96 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -143,6 +143,8 @@ class Graphics {
 	void rectfill(int x1, int y1, int x2, int y2);
 	void rectfill(int x1, int y1, int x2, int y2, uint8_t col);

+	void fillp(fix32 pat);
+
 	int print(std::string str);
 	int print(std::string str, int x, int y);
 	int print(std::string str, int x, int y, uint16_t c);
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index 3150de1..44b650c 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -591,7 +591,12 @@ int cursor(lua_State *L) {
 }

 int fillp(lua_State *L) {
-    return noop("fillp");
+    fix32 pat = 0;
+    if (lua_gettop(L) > 0) {
+        pat = lua_tonumber(L, 1);
+    }
+
+    _graphicsForLuaApi->fillp(pat);
 }

 int flip(lua_State *L) {
diff --git a/test/graphicstests.cpp b/test/graphicstests.cpp
index 5771058..58cf551 100644
--- a/test/graphicstests.cpp
+++ b/test/graphicstests.cpp
@@ -1714,6 +1714,18 @@ TEST_CASE("graphics class behaves as expected") {

         checkPoints(graphics, expectedPoints);
     }
+    SUBCASE("fillp(pat) sets values in memory"){
+        //0011001111001100 - checkerboard
+        graphics->fillp(0x33cc);
+
+        CHECK_EQ(picoRam.drawState.fillPattern[0], 0xcc);
+        CHECK_EQ(picoRam.drawState.fillPattern[1], 0x33);
+        CHECK_EQ(picoRam.drawState.fillPatternTransparencyBit, 0);
+
+        CHECK_EQ(picoRam.data[0x5f31], 0xcc);
+        CHECK_EQ(picoRam.data[0x5f32], 0x33);
+        CHECK_EQ(picoRam.data[0x5f33], 0);
+    }


     //general teardown