commit df7bca2d399b935c013c327391aa945f44e16cc4
Author: Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Fri Mar 4 19:16:00 2022 -0700
Commit: Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Fri Mar 4 19:16:00 2022 -0700
implement optional extra args for peek/poke
---
source/picoluaapi.cpp | 24 ++++++++++++++++++---
test/carts/peek_poke_extraargs.p8 | 22 +++++++++++++++++++
test/carts/screenshots/peek_poke_extraargs_f01.png | Bin 0 -> 262 bytes
test/endtoendtests.cpp | 14 ++++++++++++
4 files changed, 57 insertions(+), 3 deletions(-)
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index 5fcd5d1..3838c2d 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -990,21 +990,39 @@ int api_memset(lua_State *L) {
}
int peek(lua_State *L) {
+ int numArgs = lua_gettop(L);
+ int numToReturn = 1;
+
int addr = lua_tonumber(L,1);
- uint8_t val = _vmForLuaApi->vm_peek(addr);
+ if (numArgs > 1) {
+ numToReturn = lua_tonumber(L,2);
+ }
- lua_pushinteger(L, val);
+ for(int i = 0; i < numToReturn; i++) {
+ uint8_t val = _vmForLuaApi->vm_peek(addr + i);
- return 1;
+ lua_pushinteger(L, val);
+ }
+
+ return numToReturn;
}
int poke(lua_State *L) {
+ int numArgs = lua_gettop(L);
+
int dest = lua_tonumber(L,1);
uint8_t val = lua_tonumber(L,2);
_vmForLuaApi->vm_poke(dest, val);
+ if (numArgs > 2) {
+ for(int i = 1; i <= (numArgs - 2); i++) {
+ val = lua_tonumber(L, 2 + i);
+ _vmForLuaApi->vm_poke(dest + i, val);
+ }
+ }
+
return 0;
}
diff --git a/test/carts/peek_poke_extraargs.p8 b/test/carts/peek_poke_extraargs.p8
new file mode 100644
index 0000000..7a19ef5
--- /dev/null
+++ b/test/carts/peek_poke_extraargs.p8
@@ -0,0 +1,22 @@
+pico-8 cartridge // http://www.pico-8.com
+version 35
+__lua__
+function _init()
+ poke(0x5f56,0x80,13)
+end
+
+function _draw()
+ cls()
+ var1,var2,var3=peek(0x5f56,3)
+ print(var1)
+ print(var2)
+ print(var3)
+end
+
+__gfx__
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
diff --git a/test/carts/screenshots/peek_poke_extraargs_f01.png b/test/carts/screenshots/peek_poke_extraargs_f01.png
new file mode 100644
index 0000000..055d3e5
Binary files /dev/null and b/test/carts/screenshots/peek_poke_extraargs_f01.png differ
diff --git a/test/endtoendtests.cpp b/test/endtoendtests.cpp
index 9bcf5ac..f35e229 100644
--- a/test/endtoendtests.cpp
+++ b/test/endtoendtests.cpp
@@ -553,6 +553,20 @@ TEST_CASE("Loading and running carts") {
vm->CloseCart();
}
+ SUBCASE("peek and poke extra args test"){
+ vm->LoadCart("peek_poke_extraargs.p8");
+
+ SUBCASE("No error reported"){
+ CHECK(vm->GetBiosError() == "");
+ }
+ SUBCASE("sceen matches screenshot"){
+ vm->UpdateAndDraw();
+
+ CHECK(verifyScreenshot(vm, host, "carts/screenshots/peek_poke_extraargs_f01.png"));
+ }
+
+ vm->CloseCart();
+ }
delete vm;
delete host;