diff --git a/desmume/src/MMU.h b/desmume/src/MMU.h index d5585a5f4..431fa0dad 100644 --- a/desmume/src/MMU.h +++ b/desmume/src/MMU.h @@ -30,7 +30,9 @@ #include "registers.h" #include "mc.h" #include "bits.h" +#ifdef HAVE_LUA #include "lua-engine.h" +#endif #define ARMCPU_ARM7 1 #define ARMCPU_ARM9 0 @@ -550,7 +552,9 @@ FORCEINLINE u8 _MMU_read08(const int PROCNUM, const MMU_ACCESS_TYPE AT, const u3 if((addr&(~0x3FFF)) == MMU.DTCMRegion) return 0; //dtcm } +#ifdef HAVE_LUA CallRegisteredLuaMemHook(addr, 1, /*FIXME*/ 0, LUAMEMHOOK_READ); +#endif if(PROCNUM==ARMCPU_ARM9) if((addr&(~0x3FFF)) == MMU.DTCMRegion) @@ -575,7 +579,9 @@ FORCEINLINE u16 _MMU_read16(const int PROCNUM, const MMU_ACCESS_TYPE AT, const u if((addr&(~0x3FFF)) == MMU.DTCMRegion) return 0; //dtcm } +#ifdef HAVE_LUA CallRegisteredLuaMemHook(addr, 2, /*FIXME*/ 0, LUAMEMHOOK_READ); +#endif //special handling for execution from arm9, since we spend so much time in there if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_CODE) @@ -613,7 +619,9 @@ FORCEINLINE u32 _MMU_read32(const int PROCNUM, const MMU_ACCESS_TYPE AT, const u if((addr&(~0x3FFF)) == MMU.DTCMRegion) return 0; //dtcm } +#ifdef HAVE_LUA CallRegisteredLuaMemHook(addr, 4, /*FIXME*/ 0, LUAMEMHOOK_READ); +#endif //special handling for execution from arm9, since we spend so much time in there if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_CODE) @@ -670,19 +678,25 @@ FORCEINLINE void _MMU_write08(const int PROCNUM, const MMU_ACCESS_TYPE AT, const if((addr&(~0x3FFF)) == MMU.DTCMRegion) { T1WriteByte(MMU.ARM9_DTCM, addr & 0x3FFF, val); +#ifdef HAVE_LUA CallRegisteredLuaMemHook(addr, 1, val, LUAMEMHOOK_WRITE); +#endif return; } if ( (addr & 0x0F000000) == 0x02000000) { T1WriteByte( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK, val); +#ifdef HAVE_LUA CallRegisteredLuaMemHook(addr, 1, val, LUAMEMHOOK_WRITE); +#endif return; } if(PROCNUM==ARMCPU_ARM9) _MMU_ARM9_write08(addr,val); else _MMU_ARM7_write08(addr,val); +#ifdef HAVE_LUA CallRegisteredLuaMemHook(addr, 1, val, LUAMEMHOOK_WRITE); +#endif } FORCEINLINE void _MMU_write16(const int PROCNUM, const MMU_ACCESS_TYPE AT, const u32 addr, u16 val) @@ -698,19 +712,25 @@ FORCEINLINE void _MMU_write16(const int PROCNUM, const MMU_ACCESS_TYPE AT, const if((addr&(~0x3FFF)) == MMU.DTCMRegion) { T1WriteWord(MMU.ARM9_DTCM, addr & 0x3FFE, val); +#ifdef HAVE_LUA CallRegisteredLuaMemHook(addr, 2, val, LUAMEMHOOK_WRITE); +#endif return; } if ( (addr & 0x0F000000) == 0x02000000) { T1WriteWord( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK16, val); +#ifdef HAVE_LUA CallRegisteredLuaMemHook(addr, 2, val, LUAMEMHOOK_WRITE); +#endif return; } if(PROCNUM==ARMCPU_ARM9) _MMU_ARM9_write16(addr,val); else _MMU_ARM7_write16(addr,val); +#ifdef HAVE_LUA CallRegisteredLuaMemHook(addr, 2, val, LUAMEMHOOK_WRITE); +#endif } FORCEINLINE void _MMU_write32(const int PROCNUM, const MMU_ACCESS_TYPE AT, const u32 addr, u32 val) @@ -726,19 +746,25 @@ FORCEINLINE void _MMU_write32(const int PROCNUM, const MMU_ACCESS_TYPE AT, const if((addr&(~0x3FFF)) == MMU.DTCMRegion) { T1WriteLong(MMU.ARM9_DTCM, addr & 0x3FFC, val); +#ifdef HAVE_LUA CallRegisteredLuaMemHook(addr, 4, val, LUAMEMHOOK_WRITE); +#endif return; } if ( (addr & 0x0F000000) == 0x02000000) { T1WriteLong( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK32, val); +#ifdef HAVE_LUA CallRegisteredLuaMemHook(addr, 4, val, LUAMEMHOOK_WRITE); +#endif return; } if(PROCNUM==ARMCPU_ARM9) _MMU_ARM9_write32(addr,val); else _MMU_ARM7_write32(addr,val); +#ifdef HAVE_LUA CallRegisteredLuaMemHook(addr, 4, val, LUAMEMHOOK_WRITE); +#endif } diff --git a/desmume/src/armcpu.cpp b/desmume/src/armcpu.cpp index c5e224fbd..83f525ec6 100644 --- a/desmume/src/armcpu.cpp +++ b/desmume/src/armcpu.cpp @@ -31,7 +31,9 @@ #include "Disassembler.h" #include "NDSSystem.h" #include "MMU_timing.h" +#ifdef HAVE_LUA #include "lua-engine.h" +#endif template static u32 armcpu_prefetch(); @@ -541,7 +543,9 @@ u32 armcpu_exec() || (TEST_COND(CONDITION(ARMPROC.instruction), CODE(ARMPROC.instruction), ARMPROC.CPSR)) //handles any condition ) { +#ifdef HAVE_LUA CallRegisteredLuaMemHook(ARMPROC.instruct_adr, 4, ARMPROC.instruction, LUAMEMHOOK_EXEC); // should report even if condition=false? +#endif if(PROCNUM==0) { #ifdef DEVELOPER DEBUG_statistics.instructionHits[0].arm[INSTRUCTION_INDEX(ARMPROC.instruction)]++; @@ -568,7 +572,9 @@ u32 armcpu_exec() return MMU_fetchExecuteCycles(cExecute, cFetch); } +#ifdef HAVE_LUA CallRegisteredLuaMemHook(ARMPROC.instruct_adr, 2, ARMPROC.instruction, LUAMEMHOOK_EXEC); +#endif if(PROCNUM==0) { #ifdef DEVELOPER