Hello,
As far as I can tell it is currently not possible to read the PPU's OAM via Lua.
Here's a small diff to add ppu.readoam to the Lua engine. While this diff works, I'm not a C++ developer, so the code might be terrible. Feel free to change it if that's the case. :)
--- src/lua-engine.cpp (revision 3365)
+++ src/lua-engine.cpp (working copy)
@@ -1439,6 +1439,13 @@
return 1;
}
+static int ppu_readoam(lua_State *L) {
+ const char *p = reinterpret_cast<const char*>(SPRAM);
+ lua_pushlstring(L, p, 0x100);
+
+ return 1;
+}
+
static inline bool isalphaorunderscore(char c)
{
return isalpha(c) || c == '_';
@@ -5626,6 +5633,7 @@
static const struct luaL_reg ppulib [] = {
{"readbyte", ppu_readbyte},
{"readbyterange", ppu_readbyterange},
+ {"readoam", ppu_readoam},
{NULL,NULL}
};
It might be useful to expose the values of the other PPU registers in Lua, i.e. PPUSCROLL, PPUCTRL, PPUMASK, etc..
You're probably able to read those register values from ram by address.
Thanks for the reply @feos!
From what I can tell, we currently only expose
ppu.readbytein Lua.ppu.readbyteends up callingFFCEUX_PPURead_Default(depending on mapper) which only exposes the pattern tables (< 0x2000), nametables (< 0x3F00), and palettes (< 0x3FFF).The OAM (sprite data) is stored in a separate array
SPRAMwhich is not accessible viappu.readbyte. This is why I'm proposing we addppu.readoamas per the diff above.For the other registers, it appears like they are stored in an instance of
PPUREGScalledppur. As far as I can tell these are not currently accessible in Lua.Edit: Hmm, I just noticed the registers might be readable via
memory.readbyteas this ends up callingGetMemwhich does handle2000-2007. I'll have to try that out.Last edit: cjoudrey 2017-05-28
PPU registers are (depending on the register) either write-only or reading them has some side effect which will probably mess up a game if triggered unexpectedly. If you want to read the PPU's state from Lua, reading 2000-2007 is not the way to do it.
yeah, add new functions if you want to do that and build the values to return with whatever safe logic is required
and please, don't forget readXXXrange functions for all versions or memory reading. Now it's look very strange, that some functions has this variant, and some has not.