From 17e04a9b748cc14844b978682d5db1e576d61ca0 Mon Sep 17 00:00:00 2001 From: Fritz Mahnke Date: Sat, 22 Apr 2023 17:49:13 -0400 Subject: [PATCH 1/2] Implement LUA function memory.registerread. --- src/lua-engine.cpp | 3 +-- src/x6502.cpp | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 6aa16a52..23a64641 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -2470,7 +2470,6 @@ static int memory_registerwrite(lua_State *L) { return memory_registerHook(L, MatchHookTypeToCPU(L,LUAMEMHOOK_WRITE), 1); } -FCEU_MAYBE_UNUSED static int memory_registerread(lua_State *L) { return memory_registerHook(L, MatchHookTypeToCPU(L,LUAMEMHOOK_READ), 1); @@ -6137,7 +6136,7 @@ static const struct luaL_reg memorylib [] = { // memory hooks {"registerwrite", memory_registerwrite}, - //{"registerread", memory_registerread}, TODO + {"registerread", memory_registerread}, {"registerexec", memory_registerexec}, // alternate names {"register", memory_registerwrite}, diff --git a/src/x6502.cpp b/src/x6502.cpp index 1948cd46..eba55955 100644 --- a/src/x6502.cpp +++ b/src/x6502.cpp @@ -47,7 +47,11 @@ void (*MapIRQHook)(int a); //normal memory read static INLINE uint8 RdMem(unsigned int A) { - return(_DB=ARead[A](A)); + _DB=ARead[A](A); + #ifdef _S9XLUA_H + CallRegisteredLuaMemHook(A, 1, _DB, LUAMEMHOOK_READ); + #endif + return(_DB); } //normal memory write @@ -61,9 +65,13 @@ static INLINE void WrMem(unsigned int A, uint8 V) static INLINE uint8 RdRAM(unsigned int A) { + _DB=ARead[A](A); + #ifdef _S9XLUA_H + CallRegisteredLuaMemHook(A, 1, _DB, LUAMEMHOOK_READ); + #endif //bbit edited: this was changed so cheat substituion would work - return(_DB=ARead[A](A)); // return(_DB=RAM[A]); + return(_DB); } static INLINE void WrRAM(unsigned int A, uint8 V) @@ -77,7 +85,11 @@ static INLINE void WrRAM(unsigned int A, uint8 V) uint8 X6502_DMR(uint32 A) { ADDCYC(1); - return(X.DB=ARead[A](A)); + _DB=ARead[A](A); + #ifdef _S9XLUA_H + CallRegisteredLuaMemHook(A, 1, _DB, LUAMEMHOOK_READ); + #endif + return(_DB); } void X6502_DMW(uint32 A, uint8 V) From 150372eeca2ad315eb03d18a2175907f920d9352 Mon Sep 17 00:00:00 2001 From: Fritz Mahnke Date: Sat, 22 Apr 2023 22:16:06 -0700 Subject: [PATCH 2/2] Remove some code that was ported to FCEUX from gens, but isn't used. --- src/fceulua.h | 3 --- src/lua-engine.cpp | 46 +++------------------------------------------- 2 files changed, 3 insertions(+), 46 deletions(-) diff --git a/src/fceulua.h b/src/fceulua.h index 08b8a879..2a82d2df 100644 --- a/src/fceulua.h +++ b/src/fceulua.h @@ -21,9 +21,6 @@ enum LuaMemHookType LUAMEMHOOK_WRITE, LUAMEMHOOK_READ, LUAMEMHOOK_EXEC, - LUAMEMHOOK_WRITE_SUB, - LUAMEMHOOK_READ_SUB, - LUAMEMHOOK_EXEC_SUB, LUAMEMHOOK_COUNT }; diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 23a64641..6ca7a4bb 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -26,7 +26,6 @@ #include "debug.h" #include "debugsymboltable.h" #include "sound.h" -#include "drawing.h" #include "state.h" #include "movie.h" #include "driver.h" @@ -319,10 +318,6 @@ static const char* luaMemHookTypeStrings [] = "MEMHOOK_WRITE", "MEMHOOK_READ", "MEMHOOK_EXEC", - - "MEMHOOK_WRITE_SUB", - "MEMHOOK_READ_SUB", - "MEMHOOK_EXEC_SUB", }; //make sure we have the right number of strings @@ -2431,52 +2426,17 @@ static int memory_registerHook(lua_State* L, LuaMemHookType hookType, int defaul return 0; } -LuaMemHookType MatchHookTypeToCPU(lua_State* L, LuaMemHookType hookType) -{ - int cpuID = 0; - - int cpunameIndex = 0; - if(lua_type(L,2) == LUA_TSTRING) - cpunameIndex = 2; - else if(lua_type(L,3) == LUA_TSTRING) - cpunameIndex = 3; - - if(cpunameIndex) - { - const char* cpuName = lua_tostring(L, cpunameIndex); - if(!stricmp(cpuName, "sub")) - cpuID = 1; - lua_remove(L, cpunameIndex); - } - - switch(cpuID) - { - case 0: - return hookType; - - case 1: - switch(hookType) - { - case LUAMEMHOOK_WRITE: return LUAMEMHOOK_WRITE_SUB; - case LUAMEMHOOK_READ: return LUAMEMHOOK_READ_SUB; - case LUAMEMHOOK_EXEC: return LUAMEMHOOK_EXEC_SUB; - default: return hookType; - } - } - return hookType; -} - static int memory_registerwrite(lua_State *L) { - return memory_registerHook(L, MatchHookTypeToCPU(L,LUAMEMHOOK_WRITE), 1); + return memory_registerHook(L, LUAMEMHOOK_WRITE, 1); } static int memory_registerread(lua_State *L) { - return memory_registerHook(L, MatchHookTypeToCPU(L,LUAMEMHOOK_READ), 1); + return memory_registerHook(L, LUAMEMHOOK_READ, 1); } static int memory_registerexec(lua_State *L) { - return memory_registerHook(L, MatchHookTypeToCPU(L,LUAMEMHOOK_EXEC), 1); + return memory_registerHook(L, LUAMEMHOOK_EXEC, 1); } //adelikat: table pulled from GENS. credz nitsuja!