Well, it's not memory watch, but also a Lua script from Snes9x. Just some sample code:
for i = 1, 60 do
joypad.set(1,{right=true,down=true,A=true})
snes9x.frameadvance()
end
for i = 1, 200 do
joypad.set(1,{})
snes9x.frameadvance()
end
for i = 1, 70 do
joypad.set(1,{L=true})
snes9x.frameadvance()
end
There are some limitations in lsnes making the same code impossible: There is no frame-advance Lua function in lsnes, and setting input is only allowed in the on_input callback. So here is my workaround:
button_by_index = {
[4] = "u", [5] = "d", [6] = "l", [7] = "r",
[8] = "A", [0] = "B", [9] = "X", [1] = "Y",
[3] = "S", [2] = "s",[10] = "L",[11] = "R"
}
button_by_name = {}
for index,name in pairs(button_by_index) do
button_by_name[name] = index
end
function press(keys, player)
if player == nil or player == 1 then padnum = 0 end
if player == 2 then padnum = 4 end
assert(padnum ~= nil, "invalid player")
local a = {[0] = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
for i=1,string.len(keys) do
local index = button_by_name[string.sub(keys,i,i)]
if index ~= nil then
a[index] = 1
end
end
input.seta(padnum, 0, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11])
end
getnextinput = coroutine.create(function()
for i = 1, 60 do
coroutine.yield("rdA")
end
for i = 1, 200 do
coroutine.yield("")
end
for i = 1, 70 do
coroutine.yield("L")
end
end)
function on_input()
local b, keys = coroutine.resume(getnextinput)
if b then
press(keys)
end
end
Some ideas to make it less complicated?