plugins/cheatfind: fix (nw)

This commit is contained in:
cracyc 2018-01-28 16:46:41 -06:00
parent 98a6abd533
commit 2e3efc5eff
3 changed files with 48 additions and 18 deletions

View File

@ -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

View File

@ -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

View File

@ -400,7 +400,7 @@ T lua_engine::addr_space::direct_mem_read(offs_t address)
for(int i = 0; i < sizeof(T); i++)
{
int addr = space.endianness() == ENDIANNESS_LITTLE ? address + sizeof(T) - 1 - i : address + i;
uint8_t *base = (uint8_t *)space.get_read_ptr(space.address_to_byte(addr & ~lowmask));
uint8_t *base = (uint8_t *)space.get_read_ptr(addr & ~lowmask);
if(!base)
continue;
mem_content <<= 8;
@ -425,7 +425,7 @@ void lua_engine::addr_space::direct_mem_write(offs_t address, T val)
for(int i = 0; i < sizeof(T); i++)
{
int addr = space.endianness() == ENDIANNESS_BIG ? address + sizeof(T) - 1 - i : address + i;
uint8_t *base = (uint8_t *)space.get_read_ptr(space.address_to_byte(addr & ~lowmask));
uint8_t *base = (uint8_t *)space.get_read_ptr(addr & ~lowmask);
if(!base)
continue;
if(space.endianness() == ENDIANNESS_BIG)
@ -1442,6 +1442,7 @@ void lua_engine::initialize()
"write_direct_i64", &addr_space::direct_mem_write<int64_t>,
"write_direct_u64", &addr_space::direct_mem_write<uint64_t>,
"name", sol::property(&addr_space::name),
"shift", sol::property([](addr_space &sp) { return sp.space.addr_shift(); }),
"map", sol::property([this](addr_space &sp) {
address_space &space = sp.space;
sol::table map = sol().create_table();