Merge pull request #643 from fmahnke/mem-reg-read

Implement LUA function memory.registerread
This commit is contained in:
thor2016 2023-05-04 20:55:07 -04:00 committed by GitHub
commit 2265f3effe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 51 deletions

View File

@ -21,9 +21,6 @@ enum LuaMemHookType
LUAMEMHOOK_WRITE,
LUAMEMHOOK_READ,
LUAMEMHOOK_EXEC,
LUAMEMHOOK_WRITE_SUB,
LUAMEMHOOK_READ_SUB,
LUAMEMHOOK_EXEC_SUB,
LUAMEMHOOK_COUNT
};

View File

@ -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,53 +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);
}
FCEU_MAYBE_UNUSED
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!
@ -6137,7 +6096,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},

View File

@ -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)