diff --git a/src/fceu.cpp b/src/fceu.cpp index 04162109..0513d3b6 100644 --- a/src/fceu.cpp +++ b/src/fceu.cpp @@ -205,6 +205,8 @@ static readfunc *AReadG; static writefunc *BWriteG; static int RWWrap=0; +uint8 IOWriteLog[0x10000]; + //mbg merge 7/18/06 docs //bit0 indicates whether emulation is paused //bit1 indicates whether emulation is in frame step mode diff --git a/src/fceu.h b/src/fceu.h index de9231b8..ac40c9ce 100644 --- a/src/fceu.h +++ b/src/fceu.h @@ -54,6 +54,8 @@ uint8 FCEU_ReadRomByte(uint32 i); extern readfunc ARead[0x10000]; extern writefunc BWrite[0x10000]; +extern uint8 IOWriteLog[0x10000]; + enum GI { GI_RESETM2 =1, GI_POWER =2, diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index e9c16c16..30ee9b2f 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -1206,6 +1206,8 @@ static int rom_gethash(lua_State *L) { else lua_pushstring(L, ""); return 1; } +static int iowrite_readbyte(lua_State *L) { int addr = luaL_checkinteger(L,1); lua_pushinteger(L, (addr >= 0 && addr <= 0xFFFF) ? IOWriteLog[addr] : 0); return 1; } +static int iowrite_readbytesigned(lua_State *L) { int addr = luaL_checkinteger(L,1); lua_pushinteger(L, (addr >= 0 && addr <= 0xFFFF) ? (signed char)IOWriteLog[addr] : 0); return 1; } static int memory_readbyte(lua_State *L) { lua_pushinteger(L, FCEU_CheatGetByte(luaL_checkinteger(L,1))); return 1; } static int memory_writebyte(lua_State *L) { FCEU_CheatSetByte(luaL_checkinteger(L,1), luaL_checkinteger(L,2)); return 0; } static int memory_readbyterange(lua_State *L) { @@ -4699,6 +4701,16 @@ static const struct luaL_reg memorylib [] = { {NULL,NULL} }; +static const struct luaL_reg iowritelib [] = { + + {"readbyte", iowrite_readbyte}, + {"readbytesigned", iowrite_readbytesigned}, + // alternate naming scheme for unsigned + {"readbyteunsigned", iowrite_readbyte}, + + {NULL,NULL} +}; + static const struct luaL_reg joypadlib[] = { {"get", joypad_get}, {"getdown", joypad_getdown}, @@ -4921,6 +4933,7 @@ int FCEU_LoadLuaCode(const char *filename, const char *arg) { luaL_register(L, "emu", emulib); // added for better cross-emulator compatibility luaL_register(L, "FCEU", emulib); // kept for backward compatibility luaL_register(L, "memory", memorylib); + luaL_register(L, "iowrite", iowritelib); luaL_register(L, "rom", romlib); luaL_register(L, "joypad", joypadlib); luaL_register(L, "zapper", zapperlib); diff --git a/src/sound.cpp b/src/sound.cpp index 7a501f23..faf2101b 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -239,6 +239,7 @@ static void SQReload(int x, uint8 V) static DECLFW(Write_PSG) { + IOWriteLog[A] = V; A&=0x1F; switch(A) { @@ -311,6 +312,7 @@ static DECLFW(Write_PSG) static DECLFW(Write_DMCRegs) { + IOWriteLog[A] = V; A&=0xF; switch(A) @@ -342,6 +344,7 @@ static DECLFW(Write_DMCRegs) static DECLFW(StatusWrite) { int x; + IOWriteLog[A] = V; DoSQ1(); DoSQ2(); @@ -1005,6 +1008,7 @@ static void RDoNoise(void) DECLFW(Write_IRQFM) { + IOWriteLog[A] = V; V=(V&0xC0)>>6; fcnt=0; if(V&0x2)