commit 35f4c804a9ee393eba26a8f60b19b459636d620f
Author: jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Tue Sep 22 22:14:01 2020 -0600
Commit: jtothebell <j.to.the.bell@gmail.com>
CommitDate: Tue Sep 22 22:14:01 2020 -0600
implement cartdata methods
---
source/graphics.cpp | 6 +++++-
source/graphics.h | 1 +
source/picoluaapi.cpp | 21 ++++++++++++++++---
source/vm.cpp | 2 +-
test/carts/cartdatatest.p8 | 27 +++++++++++++++++++++++++
test/carts/screenshots/cartdatatest_f01.png | Bin 0 -> 348 bytes
test/endtoendtests.cpp | 30 ++++++++++++++++++++++++++++
test/vmtests.cpp | 11 ++++++++++
8 files changed, 93 insertions(+), 5 deletions(-)
diff --git a/source/graphics.cpp b/source/graphics.cpp
index 03aa4a1..283006f 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -45,7 +45,7 @@ Graphics::Graphics(std::string fontdata, PicoRam* memory) {
//set default clip
clip();
pal();
- color(6);
+ color();
}
@@ -410,6 +410,10 @@ uint8_t Graphics::pget(int x, int y){
return 0;
}
+void Graphics::color(){
+ color(6);
+}
+
void Graphics::color(uint8_t col){
this->_memory->drawState.color = col;
}
diff --git a/source/graphics.h b/source/graphics.h
index 431e276..c808ea8 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -92,6 +92,7 @@ class Graphics {
void pset(int x, int y, uint8_t col);
uint8_t pget(int x, int y);
+ void color();
void color(uint8_t c);
void line ();
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index cd21e89..531f4fa 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -688,15 +688,30 @@ int reload(lua_State *L) {
//cart data
int cartdata(lua_State *L) {
- return noop("cartdata");
+ const char * str = lua_tolstring(L, 1, nullptr);
+
+ _vmForLuaApi->vm_cartdata(str);
+
+ return 0;
}
int dget(lua_State *L) {
- return noopreturns(L, "dget");
+ int addr = lua_tonumber(L,1);
+
+ int32_t val = _vmForLuaApi->vm_dget(addr);
+
+ lua_pushinteger(L, val);
+
+ return 1;
}
int dset(lua_State *L) {
- return noop("dset");
+ int dest = lua_tonumber(L,1);
+ int val = lua_tonumber(L,2);
+
+ _vmForLuaApi->vm_dset(dest, (int32_t)val);
+
+ return 0;
}
int printh(lua_State *L) {
diff --git a/source/vm.cpp b/source/vm.cpp
index c340e0a..a261583 100644
--- a/source/vm.cpp
+++ b/source/vm.cpp
@@ -100,7 +100,7 @@ bool Vm::loadCart(Cart* cart) {
_memory->Reset();
//set graphics state
- _graphics->color(6);
+ _graphics->color();
_graphics->clip();
_graphics->pal();
diff --git a/test/carts/cartdatatest.p8 b/test/carts/cartdatatest.p8
new file mode 100644
index 0000000..469fe8a
--- /dev/null
+++ b/test/carts/cartdatatest.p8
@@ -0,0 +1,27 @@
+pico-8 cartridge // http://www.pico-8.com
+version 29
+__lua__
+function _init()
+ cartdata("fk08-test")
+ dset(13, 9274)
+ dgetresult = dget(13)
+end
+
+function _draw()
+ cls()
+
+ print(dgetresult)
+end
+__gfx__
+ff000000555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00700700555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00077000555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00077000555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00700700555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+__map__
+0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+__sfx__
+001d00000d0300e0500e0500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
diff --git a/test/carts/screenshots/cartdatatest_f01.png b/test/carts/screenshots/cartdatatest_f01.png
new file mode 100644
index 0000000..fb0a2f7
Binary files /dev/null and b/test/carts/screenshots/cartdatatest_f01.png differ
diff --git a/test/endtoendtests.cpp b/test/endtoendtests.cpp
index 17c56e0..341323c 100644
--- a/test/endtoendtests.cpp
+++ b/test/endtoendtests.cpp
@@ -151,6 +151,36 @@ TEST_CASE("Loading and running carts") {
vm->CloseCart();
}
+ SUBCASE("Memory function test cart"){
+ vm->LoadCart("carts/memorytest.p8");
+
+ SUBCASE("No error reported"){
+ CHECK(vm->GetBiosError() == "");
+ }
+ SUBCASE("sceen matches screenshot")
+ {
+ vm->UpdateAndDraw(0, 0);
+
+ CHECK(verifyScreenshot(vm, "carts/screenshots/memorytest_f01.png"));
+ }
+
+ vm->CloseCart();
+ }
+ SUBCASE("Cart data function test cart"){
+ vm->LoadCart("carts/cartdatatest.p8");
+
+ SUBCASE("No error reported"){
+ CHECK(vm->GetBiosError() == "");
+ }
+ SUBCASE("sceen matches screenshot")
+ {
+ vm->UpdateAndDraw(0, 0);
+
+ CHECK(verifyScreenshot(vm, "carts/screenshots/cartdatatest_f01.png"));
+ }
+
+ vm->CloseCart();
+ }
delete vm;
}
\ No newline at end of file
diff --git a/test/vmtests.cpp b/test/vmtests.cpp
index f64e979..4dc01af 100644
--- a/test/vmtests.cpp
+++ b/test/vmtests.cpp
@@ -373,6 +373,17 @@ TEST_CASE("Vm memory functions") {
CHECK_EQ(memory->spriteSheetData[1], 1);
}
+ SUBCASE("dget before setting cart data key does nothing") {
+ vm->vm_dset(34, 1923);
+
+ CHECK_EQ(vm->vm_dget(34), 0);
+ }
+ SUBCASE("dget after setting cart data key stores value") {
+ vm->vm_cartdata("uniquekey");
+ vm->vm_dset(34, 1923);
+
+ CHECK_EQ(vm->vm_dget(34), 1923);
+ }
delete graphics;