From 4edb50a92aeb8129bab5611b2ee27129288377ed Mon Sep 17 00:00:00 2001 From: cracyc Date: Thu, 7 Apr 2016 10:37:44 -0500 Subject: [PATCH] plugin/cheat: better conversion (nw) --- plugins/cheat/init.lua | 24 ++++++++++++++++++++++++ plugins/cheat/xml_conv.lua | 23 +++++++++++++++++++---- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/plugins/cheat/init.lua b/plugins/cheat/init.lua index 459657ea122..705ecca77cb 100644 --- a/plugins/cheat/init.lua +++ b/plugins/cheat/init.lua @@ -120,10 +120,34 @@ function cheat.startplugin() output[#output + 1] = { type = "box", scr = screen, x1 = x1, x2 = x2, y1 = y1, y2 = y2, bgcolor = bgcolor, linecolor = linecolor } end + local function tobcd(val) + local result = 0 + local shift = 0 + while val ~= 0 do + result = result + ((val % 10) << shift) + val = val / 10 + shift = shift + 4 + end + return result + end + + local function frombcd(val) + local result = 0 + local mul = 1 + while val ~= 0 do + result = result + ((val % 16) * mul) + val = val >> 4 + mul = mul * 10 + end + return result + end + local function parse_cheat(cheat) cheat.cheat_env = { draw_text = draw_text, draw_line = draw_line, draw_box = draw_box, + tobcd = tobcd, + frombcd = frombcd, pairs = pairs } cheat.enabled = false -- verify scripts are valid first diff --git a/plugins/cheat/xml_conv.lua b/plugins/cheat/xml_conv.lua index 72bbf635033..c38d590ef14 100644 --- a/plugins/cheat/xml_conv.lua +++ b/plugins/cheat/xml_conv.lua @@ -52,6 +52,7 @@ function xml.conv_cheat(data) local function convert_memref(cpu, space, width, addr, rw) local direct = "" + local count if space == "p" then fullspace = "program" elseif space == "d" then @@ -96,6 +97,7 @@ function xml.conv_cheat(data) end data = data:lower() + data = data:gsub("^[(](.-)[)]$", "%1") data = data:gsub("lt", "<") data = data:gsub("ge", ">=") data = data:gsub("gt", ">") @@ -104,9 +106,13 @@ function xml.conv_cheat(data) data = data:gsub("frame", frame) data = data:gsub("band", "&") data = data:gsub("bor", "|") + data = data:gsub("rshift", ">>") + data = data:gsub("lshift", "<<") data = data:gsub("%f[%w](%x+)%f[%W]", "0x%1") - data = data:gsub("([%w:]-).([pmrodi3])([bwdq])@(0x%x+) *(=*)", convert_memref) - data = data:gsub("([%w:]-).([pmrodi3])([bwdq])@(%b()) *(=*)", convert_memref) + data = data:gsub("([%w_:]-).([pmrodi3])([bwdq])@(%w+) *(=*)", convert_memref) + repeat + data, count = data:gsub("([%w_:]-).([pmrodi3])([bwdq])@(%b()) *(=*)", convert_memref) + until count == 0 if write then data = data .. ")" end @@ -148,7 +154,7 @@ function xml.conv_cheat(data) elseif tag == "action" then for count, action in pairs(block) do if action["condition"] then - str = str .. " if " .. convert_expr(action["condition"]) .. " then " + str = str .. " if (" .. convert_expr(action["condition"]) .. ") then " for expr in action["text"]:gmatch("([^,]+)") do str = str .. convert_expr(expr) .. " " end @@ -189,7 +195,16 @@ function xml.conv_cheat(data) end data["cheat"][count]["script"] = scripts elseif tag == "parameter" then - data["cheat"][count]["parameter"] = block[1] + if block[1]["min"] then + block[1]["min"] = block[1]["min"]:gsub("%$","0x") + end + if block[1]["max"] then + block[1]["max"] = block[1]["max"]:gsub("%$","0x") + end + if block[1]["step"] then + block[1]["step"] = block[1]["step"]:gsub("%$","0x") + end + data["cheat"][count]["parameter"] = block[1] end end if next(spaces) then