summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
author cracyc <cracyc@users.noreply.github.com>2016-04-08 22:30:32 -0500
committer cracyc <cracyc@users.noreply.github.com>2016-04-08 22:30:32 -0500
commit74d1fbbdb96399b8f49ff8393b4c9fe2af9e2ff3 (patch)
treee947a7c169edacfa23daca107bc98de7bd23adca /src
parent7047f18fdf2685819b3d3383bbebfa3f67ec22ae (diff)
plugins/cheatfind: start adding basic menu (nw)
Diffstat (limited to 'src')
-rw-r--r--src/emu/luaengine.cpp74
-rw-r--r--src/emu/luaengine.h2
2 files changed, 72 insertions, 4 deletions
diff --git a/src/emu/luaengine.cpp b/src/emu/luaengine.cpp
index 640f1bc9874..a5cd130fb81 100644
--- a/src/emu/luaengine.cpp
+++ b/src/emu/luaengine.cpp
@@ -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)
diff --git a/src/emu/luaengine.h b/src/emu/luaengine.h
index 7fefb73d0e3..69247a84cdf 100644
--- a/src/emu/luaengine.h
+++ b/src/emu/luaengine.h
@@ -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);