From f947ef06e7a3ca79d7f1150e437f92ecb702de4f Mon Sep 17 00:00:00 2001 From: rainwarrior Date: Tue, 23 Aug 2016 08:46:22 +0000 Subject: [PATCH] lua write callbacks: adding optional third parameter to retrieve the value written, added Sprites.lua script to visualize sprites (requires and demonstrates feature just added) --- trunk/output/luaScripts/Sprites.lua | 45 +++++++++++++++++++++++++++++ trunk/src/lua-engine.cpp | 3 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 trunk/output/luaScripts/Sprites.lua diff --git a/trunk/output/luaScripts/Sprites.lua b/trunk/output/luaScripts/Sprites.lua new file mode 100644 index 00000000..2f309134 --- /dev/null +++ b/trunk/output/luaScripts/Sprites.lua @@ -0,0 +1,45 @@ +-- Simple sprite visualizer +-- Draws a box around all sprites on screen. +-- rainwarrior 8/23/2016 + +sprite_color = "#FF00FF" -- change to customize color + +sprite_height_last = 8 +sprite_height = 8 + +function oam_dma(a,s,v) + local oam = v * 256 + for i=1,64 do + local is = (i-1) * 4 + local x0 = memory.readbyte(oam + is + 3) + local x1 = x0 + 7 + local y0 = memory.readbyte(oam + is + 0) + 1 + local y1 = y0 + (sprite_height_last - 1) + gui.box(x0,y0,x1,y1,"",sprite_color) + end +end + +function ppu_ctrl(a,s,v) + if AND(v,0x20) == 0 then + sprite_height = 8 + else + sprite_height = 16 + end +end + +function frame_end() + -- information about sprite height will be behind by 1 frame + -- (or potentially wrong if changed before the end of the frame) + -- in most games this doesn't change from frame to frame, though + sprite_height_last = sprite_height +end + +-- main + +memory.registerwrite(0x4014,1,oam_dma) +memory.registerwrite(0x2000,1,ppu_ctrl) +emu.registerafter(frame_end) + +while (true) do + emu.frameadvance() +end diff --git a/trunk/src/lua-engine.cpp b/trunk/src/lua-engine.cpp index 469d1644..db9f6ed6 100644 --- a/trunk/src/lua-engine.cpp +++ b/trunk/src/lua-engine.cpp @@ -1976,7 +1976,8 @@ static void CallRegisteredLuaMemHook_LuaMatch(unsigned int address, int size, un //RefreshScriptSpeedStatus(); lua_pushinteger(L, address); lua_pushinteger(L, size); - int errorcode = lua_pcall(L, 2, 0, 0); + lua_pushinteger(L, value); + int errorcode = lua_pcall(L, 3, 0, 0); luaRunning /*info.running*/ = wasRunning; //RefreshScriptSpeedStatus(); if (errorcode)