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)