summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author cracyc <cracyc@users.noreply.github.com>2017-10-02 17:28:37 -0500
committer cracyc <cracyc@users.noreply.github.com>2017-10-02 17:28:37 -0500
commit633c37236e3adb9673f79cc62401bbdeb773d78d (patch)
tree0b8e1ade593f5d4dac441d8e21b22678c3001d49
parentde4b85197f1a9011bdfc94b037eb7ed73f3e7dc3 (diff)
plugins/cheat: input sequence cheats [Carl]
-rw-r--r--plugins/cheat/init.lua75
1 files changed, 74 insertions, 1 deletions
diff --git a/plugins/cheat/init.lua b/plugins/cheat/init.lua
index 0ddd8510b54..29d9a214815 100644
--- a/plugins/cheat/init.lua
+++ b/plugins/cheat/init.lua
@@ -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()