Previous 199869 Revisions Next

r34343 Sunday 11th January, 2015 at 09:19:39 UTC by Luca Bruno
luaengine: expose device state entries

This commit exposes device_state_entry to LUA, providing methods
to enumerate available states for a device object, as well as getting
and setting their values.
It is mostly usefull to inspect and manipulate registers content.

Signed-off-by: Luca Bruno <lucab@debian.org>
[src/emu]distate.h luaengine.c luaengine.h

trunk/src/emu/distate.h
r242854r242855
4545{
4646   friend class device_state_interface;
4747   friend class simple_list<device_state_entry>;
48   friend class lua_engine;
4849
4950private:
5051   // construction/destruction
trunk/src/emu/luaengine.c
r242854r242855
436436}
437437
438438//-------------------------------------------------
439//  device_get_state - return table of available state userdata
440//  -> manager:machine().devices[":maincpu"].state
441//-------------------------------------------------
442
443luabridge::LuaRef lua_engine::l_dev_get_states(const device_t *d)
444{
445   device_t *dev = const_cast<device_t *>(d);
446   lua_State *L = luaThis->m_lua_state;
447   luabridge::LuaRef st_table = luabridge::LuaRef::newTable(L);
448   for (const device_state_entry *s = dev->state().state_first(); s != NULL; s = s->next()) {
449      // XXX: refrain from exporting non-visible entries?
450      if (s) {
451         st_table[s->symbol()] = const_cast<device_state_entry *>(s);
452      }
453   }
454
455   return st_table;
456}
457
458//-------------------------------------------------
459//  state_get_value - return value of a devices state
460//  -> manager:machine().devices[":maincpu"].state["PC"].value
461//-------------------------------------------------
462
463UINT64 lua_engine::l_state_get_value(const device_state_entry *d)
464{
465   return d->value();
466}
467
468//-------------------------------------------------
469//  state_set_value - set value of a devices state
470//  -> manager:machine().devices[":maincpu"].state["D0"].value = 0x0c00
471//-------------------------------------------------
472
473void lua_engine::l_state_set_value(device_state_entry *d, UINT64 val)
474{
475   d->set_value(val);
476}
477
478//-------------------------------------------------
439479//  mem_read - templated memory readers for <sign>,<size>
440480//  -> manager:machine().devices[":maincpu"].spaces["program"]:read_i8(0xC000)
441481//-------------------------------------------------
r242854r242855
831871            .addFunction ("shortname", &device_t::shortname)
832872            .addFunction ("tag", &device_t::tag)
833873            .addProperty <luabridge::LuaRef, void> ("spaces", &lua_engine::l_dev_get_memspaces)
874            .addProperty <luabridge::LuaRef, void> ("state", &lua_engine::l_dev_get_states)
834875         .endClass()
835876         .beginClass <lua_addr_space> ("lua_addr_space")
836877            .addCFunction ("read_i8", &lua_addr_space::l_mem_read<INT8>)
r242854r242855
857898            .addFunction ("height", &screen_device::height)
858899            .addFunction ("width", &screen_device::width)
859900         .endClass()
901         .beginClass <device_state_entry> ("dev_space")
902            .addFunction ("name", &device_state_entry::symbol)
903            .addProperty <UINT64, UINT64> ("value", &lua_engine::l_state_get_value, &lua_engine::l_state_set_value)
904            .addFunction ("is_visible", &device_state_entry::visible)
905            .addFunction ("is_divider", &device_state_entry::divider)
906         .endClass()
860907      .endNamespace();
861908
862909   luabridge::push (m_lua_state, machine_manager::instance());
trunk/src/emu/luaengine.h
r242854r242855
104104
105105   // "emu.machine" namespace
106106   static luabridge::LuaRef l_machine_get_devices(const running_machine *r);
107   static luabridge::LuaRef devtree_dfs(device_t *root, luabridge::LuaRef dev_table);
108   static luabridge::LuaRef l_dev_get_states(const device_t *d);
109   static UINT64 l_state_get_value(const device_state_entry *d);
110   static void l_state_set_value(device_state_entry *d, UINT64 v);
107111   static luabridge::LuaRef l_dev_get_memspaces(const device_t *d);
108   static luabridge::LuaRef devtree_dfs(device_t *root, luabridge::LuaRef dev_table);
109112   struct lua_addr_space {
110113      template<typename T> int l_mem_read(lua_State *L);
111114   };


Previous 199869 Revisions Next


© 1997-2024 The MAME Team