plugins/cheat: input sequence cheats [Carl]

This commit is contained in:
cracyc 2017-10-02 17:28:37 -05:00
parent de4b85197f
commit 633c37236e

View File

@ -85,6 +85,7 @@ function cheat.startplugin()
local perodicset = false
local watches = {}
local breaks = {}
local inputs = {}
local function load_cheats()
local filename = emu.romname()
@ -321,6 +322,55 @@ function cheat.startplugin()
end
end
local function input_trans(list)
local xlate = { start = {}, stop = {}, last = 0 }
local function errout(port, field)
cheat.enabled = false
error(port .. field .. " not found")
return
end
for num, entry in ipairs(list) do
if entry.port:sub(1, 1) ~= ":" then
entry.port = ":" .. entry.port
end
local port = manager:machine():ioport().ports[entry.port]
if not port then
errout(entry.port, entry.field)
end
local field = port.fields[entry.field]
if not field then
errout(entry.port, entry.field)
end
if not xlate.start[entry.start] then
xlate.start[entry.start] = {}
end
if not xlate.stop[entry.stop] then
xlate.stop[entry.stop] = {}
end
local start = xlate.start[entry.start]
local stop = xlate.stop[entry.stop]
local ent = { port = port, field = field }
stop[#stop + 1] = ent
start[#start + 1] = ent
if entry.stop > xlate.last then
xlate.last = entry.stop
end
end
return xlate
end
local function input_run(cheat, list)
if not is_oneshot(cheat) then
cheat.enabled = false
error("input_run only allowed in one shot cheats")
return
end
local _, screen = next(manager:machine().screens)
list.begin = screen:frame_number()
inputs[#inputs + 1] = list
end
local function parse_cheat(cheat)
cheat.cheat_env = { draw_text = draw_text,
draw_line = draw_line,
@ -331,7 +381,9 @@ function cheat.startplugin()
ipairs = ipairs,
outputs = manager:machine():outputs(),
time = time,
table =
input_trans = input_trans,
input_run = function(list) input_run(cheat, list) end,
table =
{ insert = table.insert,
remove = table.remove } }
cheat.enabled = false
@ -744,6 +796,27 @@ function cheat.startplugin()
end
end
end
for num, input in pairs(inputs) do
local _, screen = next(manager:machine().screens)
local framenum = screen:frame_number() - input.begin
local enttab = input.start[framenum]
if enttab then
for num, entry in pairs(enttab) do
entry.field:set_value(1)
end
end
enttab = input.stop[framenum]
if enttab then
for num, entry in pairs(enttab) do
entry.field:set_value(0)
end
end
if framenum >= input.last then
table.remove(inputs, num)
end
end
end)
emu.register_frame_done(function()