summaryrefslogtreecommitdiffstatshomepage
path: root/plugins
diff options
context:
space:
mode:
author cracyc <cracyc@users.noreply.github.com>2016-07-14 14:57:47 -0500
committer cracyc <cracyc@users.noreply.github.com>2016-07-14 14:57:47 -0500
commitfa6bd3726529062b4ea003532eab5aa19de081cf (patch)
tree454a8bc1a1699ed229983bb624db13676596a49c /plugins
parent5707b183dd0c203467be2dcaba5bf48b3e1e6cca (diff)
plugins/cheatfind: add operand size to simple cheat and write cheats from cheatfind into simple file (nw)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/boot.lua5
-rw-r--r--plugins/cheat/simple_conv.lua16
-rw-r--r--plugins/cheatfind/init.lua33
3 files changed, 40 insertions, 14 deletions
diff --git a/plugins/boot.lua b/plugins/boot.lua
index 11ee6682bae..2e5b46e679d 100644
--- a/plugins/boot.lua
+++ b/plugins/boot.lua
@@ -2,7 +2,8 @@
-- copyright-holders:Miodrag Milanovic
require('lfs')
-local function env_replace(str)
+-- add helper to lfs for plugins to use
+function lfs.env_replace(str)
local pathsep = package.config:sub(1,1)
local function dorep(val)
ret = os.getenv(val)
@@ -19,7 +20,7 @@ local function env_replace(str)
end
return str
end
-local dir = env_replace(manager:options().entries.pluginspath:value())
+local dir = lfs.env_replace(manager:options().entries.pluginspath:value())
package.path = package.path .. ";" .. dir .. "/?.lua;" .. dir .. "/?/init.lua"
diff --git a/plugins/cheat/simple_conv.lua b/plugins/cheat/simple_conv.lua
index 1fad3d7dfea..bb209d7af86 100644
--- a/plugins/cheat/simple_conv.lua
+++ b/plugins/cheat/simple_conv.lua
@@ -2,17 +2,27 @@ local simple = {}
-- converter for simple cheats
-- simple cheats are single address every frame ram cheats in one file called cheat.simple
--- format: <set name>,<cputag>,<hex offset>,<hex value>,<desc>
+-- format: <set name>,<cputag>,<hex offset>,<b|w|d|q - size>,<hex value>,<desc>
-- only program address space is supported, comments are prepended with ;
+-- size is b - u8, w - u16, d - u32, q - u64
function simple.conv_cheat(romset, data)
local cheats = {}
for line in data:gmatch('([^\n;]+)') do
- local set, cputag, offset, val, name = line:match('([^,]+),([^,]+),([^,]+),([^,]+),(.+)')
+ local set, cputag, offset, size, val, name = line:match('([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),(.+)')
if set == romset then
local cheat = {}
cheat.desc = name
cheat.space = { cpup = { tag = cputag, type = "program" } }
- cheat.script = { run = "cpup:write_u8(0x" .. offset .. ",0x" .. val .. ", true)" }
+ if size == "w" then
+ size "u16"
+ elseif size == "d" then
+ size = "u32"
+ elseif size == "q" then
+ size = "u64"
+ else
+ size = "u8"
+ end
+ cheat.script = { run = "cpup:write_" .. size .. "(0x" .. offset .. ",0x" .. val .. ", true)" }
cheats[#cheats + 1] = cheat
end
end
diff --git a/plugins/cheatfind/init.lua b/plugins/cheatfind/init.lua
index 659ffca33db..05a0c541e90 100644
--- a/plugins/cheatfind/init.lua
+++ b/plugins/cheatfind/init.lua
@@ -581,21 +581,21 @@ function cheatfind.startplugin()
if wid == "h" then
wid = "u16"
form = "%08x %04x"
- xmlcheat = "pw"
+ xmlcheat = "w"
elseif wid == "l" then
wid = "u32"
form = "%08x %08x"
- xmlcheat = "pd"
+ xmlcheat = "d"
elseif wid == "j" then
wid = "u64"
form = "%08x %016x"
- xmlcheat = "pq"
+ xmlcheat = "q"
else
wid = "u8"
form = "%08x %02x"
- xmlcheat = "pb"
+ xmlcheat = "b"
end
- xmlcheat = string.format("<mamecheat version=1>\n<cheat desc=\"%s\">\n<script state=\"run\">\n<action>%s.%s@%X=%X</action>\n</script>\n</cheat>\n</mamecheat>", cheat.desc, dev.tag:sub(2), xmlcheat, match.addr, match.newval)
+
if dev.space.shortname then
cheat.ram = { ram = dev.tag }
@@ -611,15 +611,30 @@ function cheatfind.startplugin()
_G.ce.inject(cheat)
end
elseif match.mode == 2 then
- local filename = string.format("%s/%s_%08X_cheat", manager:machine():options().entries.cheatpath:value():match("([^;]+)"), emu.romname(), match.addr)
+ -- lfs.env_replace is defined in boot.lua
+ local setname = emu.romname()
+ if emu.softname() ~= "" then
+ for name, image in pairs(manager:machine().images) do
+ if image:exists() and image:software_list_name() ~= "" then
+ setname = image:software_list_name() .. "/" .. emu.softname()
+ end
+ end
+ end
+ local cheatpath = lfs.env_replace(manager:machine():options().entries.cheatpath:value()):match("([^;]+)")
+ local filename = string.format("%s/%s_%08X_cheat", cheatpath, setname, match.addr)
local json = require("json")
local file = io.open(filename .. ".json", "w")
if file then
file:write(json.stringify({[1] = cheat}, {indent = true}))
file:close()
- file = io.open(filename .. ".xml", "w")
- file:write(xmlcheat)
- file:close()
+ if not dev.space.shortname then -- no xml or simple for ram_device cheat
+ file = io.open(filename .. ".xml", "w")
+ file:write(string.format("<mamecheat version=1>\n<cheat desc=\"%s\">\n<script state=\"run\">\n<action>%s.pp%s@%X=%X</action>\n</script>\n</cheat>\n</mamecheat>", cheat.desc, dev.tag:sub(2), xmlcheat, match.addr, match.newval))
+ file:close()
+ file = io.open(cheatpath .. "/cheat.simple", "a")
+ file:write(string.format("%s,%s,%X,%s,%X,%s\n", setname, dev.tag, match.addr, xmlcheat, match.newval, cheat.desc))
+ file:close()
+ end
manager:machine():popmessage("Cheat written to " .. filename)
else
manager:machine():popmessage("Unable to write file\nCheck cheatpath dir exists")