mirror of
https://github.com/holub/mame
synced 2025-10-06 09:00:04 +03:00
plugin/cheat: better conversion (nw)
This commit is contained in:
parent
1fcb7dd0e0
commit
4edb50a92a
@ -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 }
|
output[#output + 1] = { type = "box", scr = screen, x1 = x1, x2 = x2, y1 = y1, y2 = y2, bgcolor = bgcolor, linecolor = linecolor }
|
||||||
end
|
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)
|
local function parse_cheat(cheat)
|
||||||
cheat.cheat_env = { draw_text = draw_text,
|
cheat.cheat_env = { draw_text = draw_text,
|
||||||
draw_line = draw_line,
|
draw_line = draw_line,
|
||||||
draw_box = draw_box,
|
draw_box = draw_box,
|
||||||
|
tobcd = tobcd,
|
||||||
|
frombcd = frombcd,
|
||||||
pairs = pairs }
|
pairs = pairs }
|
||||||
cheat.enabled = false
|
cheat.enabled = false
|
||||||
-- verify scripts are valid first
|
-- verify scripts are valid first
|
||||||
|
@ -52,6 +52,7 @@ function xml.conv_cheat(data)
|
|||||||
|
|
||||||
local function convert_memref(cpu, space, width, addr, rw)
|
local function convert_memref(cpu, space, width, addr, rw)
|
||||||
local direct = ""
|
local direct = ""
|
||||||
|
local count
|
||||||
if space == "p" then
|
if space == "p" then
|
||||||
fullspace = "program"
|
fullspace = "program"
|
||||||
elseif space == "d" then
|
elseif space == "d" then
|
||||||
@ -96,6 +97,7 @@ function xml.conv_cheat(data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
data = data:lower()
|
data = data:lower()
|
||||||
|
data = data:gsub("^[(](.-)[)]$", "%1")
|
||||||
data = data:gsub("lt", "<")
|
data = data:gsub("lt", "<")
|
||||||
data = data:gsub("ge", ">=")
|
data = data:gsub("ge", ">=")
|
||||||
data = data:gsub("gt", ">")
|
data = data:gsub("gt", ">")
|
||||||
@ -104,9 +106,13 @@ function xml.conv_cheat(data)
|
|||||||
data = data:gsub("frame", frame)
|
data = data:gsub("frame", frame)
|
||||||
data = data:gsub("band", "&")
|
data = data:gsub("band", "&")
|
||||||
data = data:gsub("bor", "|")
|
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("%f[%w](%x+)%f[%W]", "0x%1")
|
||||||
data = data:gsub("([%w:]-).([pmrodi3])([bwdq])@(0x%x+) *(=*)", convert_memref)
|
data = data:gsub("([%w_:]-).([pmrodi3])([bwdq])@(%w+) *(=*)", convert_memref)
|
||||||
data = data:gsub("([%w:]-).([pmrodi3])([bwdq])@(%b()) *(=*)", convert_memref)
|
repeat
|
||||||
|
data, count = data:gsub("([%w_:]-).([pmrodi3])([bwdq])@(%b()) *(=*)", convert_memref)
|
||||||
|
until count == 0
|
||||||
if write then
|
if write then
|
||||||
data = data .. ")"
|
data = data .. ")"
|
||||||
end
|
end
|
||||||
@ -148,7 +154,7 @@ function xml.conv_cheat(data)
|
|||||||
elseif tag == "action" then
|
elseif tag == "action" then
|
||||||
for count, action in pairs(block) do
|
for count, action in pairs(block) do
|
||||||
if action["condition"] then
|
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
|
for expr in action["text"]:gmatch("([^,]+)") do
|
||||||
str = str .. convert_expr(expr) .. " "
|
str = str .. convert_expr(expr) .. " "
|
||||||
end
|
end
|
||||||
@ -189,6 +195,15 @@ function xml.conv_cheat(data)
|
|||||||
end
|
end
|
||||||
data["cheat"][count]["script"] = scripts
|
data["cheat"][count]["script"] = scripts
|
||||||
elseif tag == "parameter" then
|
elseif tag == "parameter" then
|
||||||
|
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]
|
data["cheat"][count]["parameter"] = block[1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user