mirror of
https://github.com/holub/mame
synced 2025-07-05 09:57:47 +03:00
plugins/cheatfind: start adding basic menu (nw)
This commit is contained in:
parent
7047f18fdf
commit
74d1fbbdb9
@ -148,7 +148,8 @@ function cheat.startplugin()
|
||||
draw_box = draw_box,
|
||||
tobcd = tobcd,
|
||||
frombcd = frombcd,
|
||||
pairs = pairs }
|
||||
pairs = pairs,
|
||||
ipairs = ipairs }
|
||||
cheat.enabled = false
|
||||
-- verify scripts are valid first
|
||||
if not cheat.script then
|
||||
@ -250,7 +251,7 @@ function cheat.startplugin()
|
||||
|
||||
local function menu_populate()
|
||||
local menu = {}
|
||||
for num, cheat in pairs(cheats) do
|
||||
for num, cheat in ipairs(cheats) do
|
||||
menu[num] = {}
|
||||
menu[num][1] = cheat.desc
|
||||
if not cheat.parameter then
|
||||
@ -415,13 +416,13 @@ function cheat.startplugin()
|
||||
|
||||
emu.register_start(function()
|
||||
cheats = load_cheats()
|
||||
for num, cheat in pairs(cheats) do
|
||||
for num, cheat in ipairs(cheats) do
|
||||
parse_cheat(cheat)
|
||||
end
|
||||
end)
|
||||
|
||||
emu.register_frame(function()
|
||||
for num, cheat in pairs(cheats) do
|
||||
for num, cheat in ipairs(cheats) do
|
||||
if cheat.enabled and cheat.script.run then
|
||||
cheat.script.run()
|
||||
end
|
||||
@ -430,7 +431,7 @@ function cheat.startplugin()
|
||||
|
||||
emu.register_frame_done(function()
|
||||
line = 0
|
||||
for num, draw in pairs(output) do
|
||||
for num, draw in ipairs(output) do
|
||||
if draw.type == "text" then
|
||||
if not draw.color then
|
||||
draw.scr:draw_text(draw.x, draw.y, draw.str)
|
||||
|
@ -32,9 +32,12 @@ function cheatfind.startplugin()
|
||||
local ram = {}
|
||||
for tag, device in pairs(manager:machine().devices) do
|
||||
if device:shortname() == "ram" then
|
||||
ram[tag] = device
|
||||
ram[tag] = {}
|
||||
ram[tag].dev = device
|
||||
ram[tag].size = emu.item(device.items["0/m_size"]:read(0))
|
||||
end
|
||||
end
|
||||
return ram
|
||||
end
|
||||
|
||||
-- save data block
|
||||
@ -91,8 +94,157 @@ function cheatfind.startplugin()
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
|
||||
_G.cf = cheat
|
||||
|
||||
local devtable = {}
|
||||
local devsel = 1
|
||||
local optable = { "+", "-" }
|
||||
local opsel = 1
|
||||
local change = 0
|
||||
local matches = {}
|
||||
local menu_blocks = {}
|
||||
|
||||
local function start()
|
||||
devtable = {}
|
||||
menu_blocks = {}
|
||||
matches = {}
|
||||
local table = cheat.getspaces()
|
||||
for tag, list in pairs(table) do
|
||||
if list.program then
|
||||
local ram = {}
|
||||
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 }
|
||||
end
|
||||
end
|
||||
if next(ram) then
|
||||
devtable[#devtable + 1] = { tag = tag, space = list.program, ram = ram }
|
||||
end
|
||||
end
|
||||
end
|
||||
table = cheat.getram()
|
||||
for tag, ram in pairs(table) do
|
||||
devtable[#devtable + 1] = { tag = tag, space = ram.dev, ram = { offset = 0, size = ram.size } }
|
||||
end
|
||||
end
|
||||
|
||||
emu.register_start(start)
|
||||
|
||||
local function menu_populate()
|
||||
local menu = {}
|
||||
menu[1] = {}
|
||||
menu[1][1] = "Region"
|
||||
menu[1][2] = devtable[devsel].tag
|
||||
if #devtable == 1 then
|
||||
menu[1][3] = 0
|
||||
elseif devsel == 1 then
|
||||
menu[1][3] = 2
|
||||
elseif devsel == #devtable then
|
||||
menu[1][3] = 1
|
||||
else
|
||||
menu[1][3] = 3
|
||||
end
|
||||
menu[2] = { "Init", "", 0 }
|
||||
if next(menu_blocks) then
|
||||
menu[3] = { "---", "", 32 }
|
||||
menu[4] = {}
|
||||
menu[4][1] = "Operator"
|
||||
menu[4][2] = optable[opsel]
|
||||
if opsel == 1 then
|
||||
menu[4][3] = 2
|
||||
elseif opsel == #optable then
|
||||
menu[4][3] = 1
|
||||
else
|
||||
menu[4][3] = 3
|
||||
end
|
||||
menu[5] = {}
|
||||
menu[5][1] = "Change"
|
||||
menu[5][2] = change
|
||||
if change == 0 then
|
||||
menu[5][2] = "Any"
|
||||
menu[5][3] = 2
|
||||
elseif change == 100 then --?
|
||||
menu[5][3] = 1
|
||||
else
|
||||
menu[5][3] = 3
|
||||
end
|
||||
menu[6] = { "Compare", "", 0 }
|
||||
menu[7] = { "---", "", 32 }
|
||||
for num, list in ipairs(matches) do
|
||||
for num2, match in ipairs(list) do
|
||||
if #menu > 50 then
|
||||
break
|
||||
end
|
||||
menu[#menu + 1] = { string.format("%x %x %x", match.addr, match.oldval, match.newval), "", 0 }
|
||||
end
|
||||
end
|
||||
end
|
||||
return menu
|
||||
end
|
||||
|
||||
local function menu_callback(index, event)
|
||||
if index == 1 then
|
||||
if event == "left" then
|
||||
if devsel ~= 1 then
|
||||
devsel = devsel - 1
|
||||
return true
|
||||
end
|
||||
elseif event == "right" then
|
||||
if devsel ~= #devtable then
|
||||
devsel = devsel + 1
|
||||
return true
|
||||
end
|
||||
end
|
||||
elseif index == 2 then
|
||||
if event == "select" then
|
||||
menu_blocks = {}
|
||||
matches = {}
|
||||
for num, region in ipairs(devtable[devsel].ram) do
|
||||
menu_blocks[num] = cheat.save(devtable[devsel].space, region.offset, region.size)
|
||||
end
|
||||
return true
|
||||
end
|
||||
elseif index == 4 then
|
||||
if event == "left" then
|
||||
if opsel ~= 1 then
|
||||
opsel = opsel - 1
|
||||
return true
|
||||
end
|
||||
elseif event == "right" then
|
||||
if opsel ~= #optable then
|
||||
opsel = opsel + 1
|
||||
return true
|
||||
end
|
||||
end
|
||||
elseif index == 5 then
|
||||
if event == "left" then
|
||||
if change ~= 0 then
|
||||
change = change - 1
|
||||
return true
|
||||
end
|
||||
elseif event == "right" then
|
||||
if change ~= 100 then
|
||||
change = change + 1
|
||||
return true
|
||||
end
|
||||
end
|
||||
elseif index == 6 then
|
||||
if event == "select" then
|
||||
matches = {}
|
||||
for num, block in ipairs(menu_blocks) do
|
||||
matches[#matches + 1] = cheat.comp(block, optable[opsel], change)
|
||||
end
|
||||
return true
|
||||
end
|
||||
elseif index > 7 then
|
||||
if event == "select" then
|
||||
-- write out a script?
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
emu.register_menu(menu_callback, menu_populate, "Cheat Finder")
|
||||
end
|
||||
|
||||
return exports
|
||||
|
@ -156,8 +156,49 @@ struct Stack <osd_file::error>
|
||||
lua_pushstring(L, strerror.c_str());
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct Stack <map_handler_type>
|
||||
{
|
||||
static void push(lua_State *L, map_handler_type error)
|
||||
{
|
||||
std::string type;
|
||||
switch(error)
|
||||
{
|
||||
case AMH_NONE:
|
||||
type = "none";
|
||||
break;
|
||||
case AMH_RAM:
|
||||
type = "ram";
|
||||
break;
|
||||
case AMH_ROM:
|
||||
type = "rom";
|
||||
break;
|
||||
case AMH_NOP:
|
||||
type = "nop";
|
||||
break;
|
||||
case AMH_UNMAP:
|
||||
type = "unmap";
|
||||
break;
|
||||
case AMH_DEVICE_DELEGATE:
|
||||
type = "delegate";
|
||||
break;
|
||||
case AMH_PORT:
|
||||
type = "port";
|
||||
break;
|
||||
case AMH_BANK:
|
||||
type = "bank";
|
||||
break;
|
||||
case AMH_DEVICE_SUBMAP:
|
||||
type = "submap";
|
||||
break;
|
||||
default:
|
||||
type = "unknown";
|
||||
break;
|
||||
}
|
||||
lua_pushstring(L, type.c_str());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/* mark in error messages for incomplete statements */
|
||||
#define EOFMARK "<eof>"
|
||||
#define marklen (sizeof(EOFMARK)/sizeof(char) - 1)
|
||||
@ -960,7 +1001,7 @@ int lua_engine::lua_addr_space::l_mem_write(lua_State *L)
|
||||
|
||||
UINT8 lua_engine::read_direct_byte(address_space &space, offs_t addr)
|
||||
{
|
||||
UINT8 *base = (UINT8 *)space.get_read_ptr(addr);
|
||||
UINT8 *base = (UINT8 *)space.get_read_ptr(space.address_to_byte(addr));
|
||||
if(base)
|
||||
return base[addr];
|
||||
else
|
||||
@ -1001,7 +1042,7 @@ int lua_engine::lua_addr_space::l_direct_mem_read(lua_State *L)
|
||||
|
||||
void lua_engine::write_direct_byte(address_space &space, offs_t addr, UINT8 byte)
|
||||
{
|
||||
UINT8 *base = (UINT8 *)space.get_read_ptr(addr);
|
||||
UINT8 *base = (UINT8 *)space.get_read_ptr(space.address_to_byte(addr));
|
||||
if(base)
|
||||
base[addr] = byte;
|
||||
}
|
||||
@ -1099,6 +1140,24 @@ int lua_engine::lua_memory_region::l_region_write(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
luabridge::LuaRef lua_engine::l_addr_space_map(const address_space *space)
|
||||
{
|
||||
lua_State *L = luaThis->m_lua_state;
|
||||
luabridge::LuaRef map = luabridge::LuaRef::newTable(L);
|
||||
|
||||
int i = 1;
|
||||
for (address_map_entry &entry : space->map()->m_entrylist)
|
||||
{
|
||||
luabridge::LuaRef mapentry = luabridge::LuaRef::newTable(L);
|
||||
mapentry["offset"] = space->address_to_byte(entry.m_addrstart) & space->bytemask();
|
||||
mapentry["endoff"] = space->address_to_byte(entry.m_addrend) & space->bytemask();
|
||||
mapentry["readtype"] = entry.m_read.m_type;
|
||||
mapentry["writetype"] = entry.m_write.m_type;
|
||||
map[i++] = mapentry;
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
int lua_engine::lua_options_entry::l_entry_value(lua_State *L)
|
||||
{
|
||||
core_options::entry *e = luabridge::Stack<core_options::entry *>::get(L, 1);
|
||||
@ -1691,7 +1750,13 @@ std::vector<lua_engine::menu_item> &lua_engine::menu_populate(std::string &menu)
|
||||
lua_pop(m_lua_state, 1);
|
||||
return menu_list;
|
||||
}
|
||||
lua_pcall(m_lua_state, 0, 1, 0);
|
||||
if(int error = lua_pcall(m_lua_state, 0, 1, 0))
|
||||
{
|
||||
if(error == 2)
|
||||
printf("%s\n", lua_tostring(m_lua_state, -1));
|
||||
lua_pop(m_lua_state, 1);
|
||||
return menu_list;
|
||||
}
|
||||
if(!lua_istable(m_lua_state, -1))
|
||||
{
|
||||
lua_pop(m_lua_state, 1);
|
||||
@ -2149,6 +2214,7 @@ void lua_engine::initialize()
|
||||
.endClass()
|
||||
.deriveClass <address_space, lua_addr_space> ("addr_space")
|
||||
.addFunction("name", &address_space::name)
|
||||
.addProperty <luabridge::LuaRef, void> ("map", &lua_engine::l_addr_space_map)
|
||||
.endClass()
|
||||
.beginClass <render_target> ("target")
|
||||
.addFunction ("width", &render_target::width)
|
||||
|
@ -161,6 +161,8 @@ private:
|
||||
template<typename T> int l_direct_mem_read(lua_State *L);
|
||||
template<typename T> int l_direct_mem_write(lua_State *L);
|
||||
};
|
||||
static luabridge::LuaRef l_addr_space_map(const address_space *as);
|
||||
|
||||
static luabridge::LuaRef l_machine_get_screens(const running_machine *r);
|
||||
struct lua_screen {
|
||||
int l_height(lua_State *L);
|
||||
|
Loading…
Reference in New Issue
Block a user