diff options
author | 2018-01-28 16:46:41 -0600 | |
---|---|---|
committer | 2018-01-29 16:22:41 +1100 | |
commit | b3f05b309dac0b5d80e5606e6446f2c03abca8ac (patch) | |
tree | 01a6cc8eec39878bfadb768f6cc1fd84306a0002 /plugins | |
parent | d9fd4812a4f5ba989dbc50eece4c72631f7791bc (diff) |
plugins/cheatfind: fix (nw)
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/cheat/cheat_simple.lua | 8 | ||||
-rw-r--r-- | plugins/cheatfind/init.lua | 53 |
2 files changed, 45 insertions, 16 deletions
diff --git a/plugins/cheat/cheat_simple.lua b/plugins/cheat/cheat_simple.lua index 36067b846c6..11c63e6e642 100644 --- a/plugins/cheat/cheat_simple.lua +++ b/plugins/cheat/cheat_simple.lua @@ -279,7 +279,7 @@ function simple.conv_cheat(data) local set, cputag, offset, size, val, desc = line:match('([^,]+),([^,]+),([^,]+),?([^,]*),?([^,]*),(.*)') if set == simple.romset then local cheat - if cputag.sub(1,1) ~= ":" then + if cputag:sub(1,1) ~= ":" then local list, name = set:match('([^/]+)/(.+)') local func = list .. "_" .. cputag if list and desc and codefuncs[func] then @@ -300,12 +300,12 @@ function simple.conv_cheat(data) else size = 8 end - addr = tonumber(addr, 16) + offset = tonumber(offset, 16) val = tonumber(val, 16) if manager:machine().devices[cputag] then - cheat = prepare_ram_cheat(desc, cputag, addr, val, size) + cheat = prepare_ram_cheat(desc, cputag, offset, val, size) else - cheat = prepare_rom_cheat(desc, cputag, addr, val, size) + cheat = prepare_rom_cheat(desc, cputag, offset, val, size) end end if cheat then diff --git a/plugins/cheatfind/init.lua b/plugins/cheatfind/init.lua index 191fc390d54..514e574f87e 100644 --- a/plugins/cheatfind/init.lua +++ b/plugins/cheatfind/init.lua @@ -51,7 +51,10 @@ function cheatfind.startplugin() -- save data block function cheat.save(space, start, size) - local data = { block = "", start = start, size = size, space = space } + local data = { block = "", start = start, size = size, space = space, shift = 0 } + if getmetatable(space).__name:match("addr_space") then + data.shift = space.shift + end if getmetatable(space).__name:match("device_t") then if space:shortname() == "ram" then data.block = emu.item(space.items["0/m_pointer"]):read_block(start, size) @@ -63,14 +66,30 @@ function cheatfind.startplugin() local block = "" local temp = {} local j = 1 - for i = start, start + size do - if j < 65536 then - temp[j] = string.pack("B", space:read_u8(i, true)) - j = j + 1 - else - block = block .. table.concat(temp) .. string.pack("B", space:read_u8(i, true)) - temp = {} - j = 1 + if data.shift >= 0 then -- region or byte wide space + for i = start, start + size, 1 << data.shift do + if j < 65536 then + temp[j] = string.pack("B", space:read_u8(i)) + j = j + 1 + else + block = block .. table.concat(temp) .. string.pack("B", space:read_u8(i)) + temp = {} + j = 1 + end + end + elseif data.shift < 0 then + local s = -data.shift + local read = (s == 1) and space.read_u16 or (s == 2) and space.read_u32 or (s == 3) and space.read_u64 or space.read_u8 + local pack = (s == 1) and "<H" or (s == 2) and "<L" or (s == 3) and "<J" or "B" + for i = start, start + (size >> s) do + if j < 65536 then + temp[j] = string.pack(pack, read(space, i)) + j = j + 1 + else + block = block .. table.concat(temp) .. string.pack(pack, read(space, i)) + temp = {} + j = 1 + end end end block = block .. table.concat(temp) @@ -154,7 +173,12 @@ function cheatfind.startplugin() if oldstat and newstat then local oldc, newc = old, new local comp = false - local addr = olddata.start + i - 1 + local addr = i - 1 + if olddata.shift ~= 0 then + local s = olddata.shift + addr = (s < 0) and addr >> -s or (s > 0) and addr << s + end + addr = addr + olddata.start if not bcd or (check_bcd(old) and check_bcd(new)) then if bcd then oldc = frombcd(old) @@ -275,6 +299,11 @@ function cheatfind.startplugin() 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 } + if list.program.shift > 0 then + ram[#ram].size = ram[#ram].size >> list.program.shift + elseif list.program.shift < 0 then + ram[#ram].size = ram[#ram].size << -list.program.shift + end end end if next(ram) then @@ -396,7 +425,7 @@ function cheatfind.startplugin() file = io.open(cheat_save.path .. "/cheat.simple", "a") file:write(string.format(cheat_save.simple, desc)) file:close() - manager:machine():popmessage(string.format(_("Cheat written to %s and added to cheat.simple"), cheat_save.filename)) + manager:machine():popmessage(string.format(_("Cheat written to %s and added to cheat.simple"), filename)) end written = true elseif not getmetatable(devtable[devcur].space).__name:match("device_t") then @@ -685,7 +714,7 @@ function cheatfind.startplugin() cheat.script.run = "ram:write(" .. match.addr .. "," .. match.newval .. ")" else cheat.space = { cpu = { tag = dev.tag, type = "program" } } - cheat.script.run = "cpu:write_" .. wid .. "(" .. match.addr .. "," .. match.newval .. ", true)" + cheat.script.run = "cpu:write_" .. wid .. "(" .. match.addr .. "," .. match.newval .. ")" end if match.mode == 1 then if not _G.ce then |