diff options
author | 2016-04-08 22:30:32 -0500 | |
---|---|---|
committer | 2016-04-08 22:30:32 -0500 | |
commit | 74d1fbbdb96399b8f49ff8393b4c9fe2af9e2ff3 (patch) | |
tree | e947a7c169edacfa23daca107bc98de7bd23adca /plugins | |
parent | 7047f18fdf2685819b3d3383bbebfa3f67ec22ae (diff) |
plugins/cheatfind: start adding basic menu (nw)
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/cheat/init.lua | 11 | ||||
-rw-r--r-- | plugins/cheatfind/init.lua | 156 |
2 files changed, 160 insertions, 7 deletions
diff --git a/plugins/cheat/init.lua b/plugins/cheat/init.lua index a096869ce20..72b1ba83e9f 100644 --- a/plugins/cheat/init.lua +++ b/plugins/cheat/init.lua @@ -148,7 +148,8 @@ function cheat.startplugin() draw_box = draw_box, tobcd = tobcd, frombcd = frombcd, - pairs = pairs } + pairs = pairs, + ipairs = ipairs } cheat.enabled = false -- verify scripts are valid first if not cheat.script then @@ -250,7 +251,7 @@ function cheat.startplugin() local function menu_populate() local menu = {} - for num, cheat in pairs(cheats) do + for num, cheat in ipairs(cheats) do menu[num] = {} menu[num][1] = cheat.desc if not cheat.parameter then @@ -415,13 +416,13 @@ function cheat.startplugin() emu.register_start(function() cheats = load_cheats() - for num, cheat in pairs(cheats) do + for num, cheat in ipairs(cheats) do parse_cheat(cheat) end end) emu.register_frame(function() - for num, cheat in pairs(cheats) do + for num, cheat in ipairs(cheats) do if cheat.enabled and cheat.script.run then cheat.script.run() end @@ -430,7 +431,7 @@ function cheat.startplugin() emu.register_frame_done(function() line = 0 - for num, draw in pairs(output) do + for num, draw in ipairs(output) do if draw.type == "text" then if not draw.color then draw.scr:draw_text(draw.x, draw.y, draw.str) diff --git a/plugins/cheatfind/init.lua b/plugins/cheatfind/init.lua index a4334b67aba..582bf86e8aa 100644 --- a/plugins/cheatfind/init.lua +++ b/plugins/cheatfind/init.lua @@ -32,9 +32,12 @@ function cheatfind.startplugin() local ram = {} for tag, device in pairs(manager:machine().devices) do if device:shortname() == "ram" then - ram[tag] = device + ram[tag] = {} + ram[tag].dev = device + ram[tag].size = emu.item(device.items["0/m_size"]:read(0)) end end + return ram end -- save data block @@ -91,8 +94,157 @@ function cheatfind.startplugin() end return ret end - + _G.cf = cheat + + local devtable = {} + local devsel = 1 + local optable = { "+", "-" } + local opsel = 1 + local change = 0 + local matches = {} + local menu_blocks = {} + + local function start() + devtable = {} + menu_blocks = {} + matches = {} + local table = cheat.getspaces() + for tag, list in pairs(table) do + if list.program then + local ram = {} + for num, entry in pairs(list.program.map) do + if entry.writetype == "ram" then + ram[#ram + 1] = { offset = entry.offset, size = entry.endoff - entry.offset } + end + end + if next(ram) then + devtable[#devtable + 1] = { tag = tag, space = list.program, ram = ram } + end + end + end + table = cheat.getram() + for tag, ram in pairs(table) do + devtable[#devtable + 1] = { tag = tag, space = ram.dev, ram = { offset = 0, size = ram.size } } + end + end + + emu.register_start(start) + + local function menu_populate() + local menu = {} + menu[1] = {} + menu[1][1] = "Region" + menu[1][2] = devtable[devsel].tag + if #devtable == 1 then + menu[1][3] = 0 + elseif devsel == 1 then + menu[1][3] = 2 + elseif devsel == #devtable then + menu[1][3] = 1 + else + menu[1][3] = 3 + end + menu[2] = { "Init", "", 0 } + if next(menu_blocks) then + menu[3] = { "---", "", 32 } + menu[4] = {} + menu[4][1] = "Operator" + menu[4][2] = optable[opsel] + if opsel == 1 then + menu[4][3] = 2 + elseif opsel == #optable then + menu[4][3] = 1 + else + menu[4][3] = 3 + end + menu[5] = {} + menu[5][1] = "Change" + menu[5][2] = change + if change == 0 then + menu[5][2] = "Any" + menu[5][3] = 2 + elseif change == 100 then --? + menu[5][3] = 1 + else + menu[5][3] = 3 + end + menu[6] = { "Compare", "", 0 } + menu[7] = { "---", "", 32 } + for num, list in ipairs(matches) do + for num2, match in ipairs(list) do + if #menu > 50 then + break + end + menu[#menu + 1] = { string.format("%x %x %x", match.addr, match.oldval, match.newval), "", 0 } + end + end + end + return menu + end + + local function menu_callback(index, event) + if index == 1 then + if event == "left" then + if devsel ~= 1 then + devsel = devsel - 1 + return true + end + elseif event == "right" then + if devsel ~= #devtable then + devsel = devsel + 1 + return true + end + end + elseif index == 2 then + if event == "select" then + menu_blocks = {} + matches = {} + for num, region in ipairs(devtable[devsel].ram) do + menu_blocks[num] = cheat.save(devtable[devsel].space, region.offset, region.size) + end + return true + end + elseif index == 4 then + if event == "left" then + if opsel ~= 1 then + opsel = opsel - 1 + return true + end + elseif event == "right" then + if opsel ~= #optable then + opsel = opsel + 1 + return true + end + end + elseif index == 5 then + if event == "left" then + if change ~= 0 then + change = change - 1 + return true + end + elseif event == "right" then + if change ~= 100 then + change = change + 1 + return true + end + end + elseif index == 6 then + if event == "select" then + matches = {} + for num, block in ipairs(menu_blocks) do + matches[#matches + 1] = cheat.comp(block, optable[opsel], change) + end + return true + end + elseif index > 7 then + if event == "select" then + -- write out a script? + end + end + return false + end + emu.register_menu(menu_callback, menu_populate, "Cheat Finder") end return exports |