summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author cracyc <cracyc@users.noreply.github.com>2018-01-28 16:46:41 -0600
committer cracyc <cracyc@users.noreply.github.com>2018-01-28 16:46:41 -0600
commit2e3efc5eff1189f47f81fffff241a7696e9bb189 (patch)
treec75adbb7ee3fd5aff70e8f64eecf3fe5ac5c6bfd
parent98a6abd5335c87943a337e1c53c81eb55952a108 (diff)
plugins/cheatfind: fix (nw)
-rw-r--r--plugins/cheat/cheat_simple.lua8
-rw-r--r--plugins/cheatfind/init.lua53
-rw-r--r--src/frontend/mame/luaengine.cpp5
3 files changed, 48 insertions, 18 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
diff --git a/src/frontend/mame/luaengine.cpp b/src/frontend/mame/luaengine.cpp
index c7a17453350..771ecbe9bdf 100644
--- a/src/frontend/mame/luaengine.cpp
+++ b/src/frontend/mame/luaengine.cpp
@@ -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();