Created
January 18, 2015 15:37
-
-
Save lucab/411b53c061935aaab29c to your computer and use it in GitHub Desktop.
mame-lua presave/postload callbacks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 380a02907ff0e082cc5291b23882de10e9fbae58 | |
Author: Luca Bruno <lucab@debian.org> | |
Date: Sun Jan 18 16:28:09 2015 +0100 | |
save: factor-out presave/postload dispatchers | |
Signed-off-by: Luca Bruno <lucab@debian.org> | |
diff --git a/src/emu/save.c b/src/emu/save.c | |
index d7d8ba5..98c23ca 100644 | |
--- a/src/emu/save.c | |
+++ b/src/emu/save.c | |
@@ -213,6 +213,17 @@ save_error save_manager::check_file(running_machine &machine, emu_file &file, co | |
return validate_header(header, gamename, sig, errormsg, ""); | |
} | |
+//------------------------------------------------- | |
+// dispatch_postload - invoke all registered | |
+// postload callbacks for updates | |
+//------------------------------------------------- | |
+ | |
+ | |
+void save_manager::dispatch_postload() | |
+{ | |
+ for (state_callback *func = m_postload_list.first(); func != NULL; func = func->next()) | |
+ func->m_func(); | |
+} | |
//------------------------------------------------- | |
// read_file - read the data from a file | |
@@ -253,12 +264,22 @@ save_error save_manager::read_file(emu_file &file) | |
} | |
// call the post-load functions | |
- for (state_callback *func = m_postload_list.first(); func != NULL; func = func->next()) | |
- func->m_func(); | |
+ dispatch_postload(); | |
return STATERR_NONE; | |
} | |
+//------------------------------------------------- | |
+// dispatch_presave - invoke all registered | |
+// presave callbacks for updates | |
+//------------------------------------------------- | |
+ | |
+ | |
+void save_manager::dispatch_presave() | |
+{ | |
+ for (state_callback *func = m_presave_list.first(); func != NULL; func = func->next()) | |
+ func->m_func(); | |
+} | |
//------------------------------------------------- | |
// write_file - writes the data to a file | |
@@ -287,8 +308,7 @@ save_error save_manager::write_file(emu_file &file) | |
file.compress(FCOMPRESS_MEDIUM); | |
// call the pre-save functions | |
- for (state_callback *func = m_presave_list.first(); func != NULL; func = func->next()) | |
- func->m_func(); | |
+ dispatch_presave(); | |
// then write all the data | |
for (state_entry *entry = m_entry_list.first(); entry != NULL; entry = entry->next()) | |
diff --git a/src/emu/save.h b/src/emu/save.h | |
index 8fc537e..7e00daf 100644 | |
--- a/src/emu/save.h | |
+++ b/src/emu/save.h | |
@@ -99,6 +99,10 @@ public: | |
void register_presave(save_prepost_delegate func); | |
void register_postload(save_prepost_delegate func); | |
+ // callback dispatching | |
+ void dispatch_presave(); | |
+ void dispatch_postload(); | |
+ | |
// generic memory registration | |
void save_memory(const char *module, const char *tag, UINT32 index, const char *name, void *val, UINT32 valsize, UINT32 valcount = 1); | |
commit a140a43463a90b07a0f0931f43615385318714c8 | |
Author: Luca Bruno <lucab@debian.org> | |
Date: Sat Jan 17 23:32:57 2015 +0100 | |
luaengine: rework state getter/setter for saves | |
Improve state_get_value and state_set_value by using the | |
parent device_state_interface and triggering callbacks for | |
updates. | |
While at it, also remove the hackish friend relationship. | |
Signed-off-by: Luca Bruno <lucab@debian.org> | |
diff --git a/src/emu/distate.h b/src/emu/distate.h | |
index d3679b7..1d16e81 100644 | |
--- a/src/emu/distate.h | |
+++ b/src/emu/distate.h | |
@@ -45,7 +45,6 @@ class device_state_entry | |
{ | |
friend class device_state_interface; | |
friend class simple_list<device_state_entry>; | |
- friend class lua_engine; | |
private: | |
// construction/destruction | |
diff --git a/src/emu/luaengine.c b/src/emu/luaengine.c | |
index f38a738..1f1e9b9 100644 | |
--- a/src/emu/luaengine.c | |
+++ b/src/emu/luaengine.c | |
@@ -456,23 +456,33 @@ luabridge::LuaRef lua_engine::l_dev_get_states(const device_t *d) | |
} | |
//------------------------------------------------- | |
-// state_get_value - return value of a devices state | |
+// state_get_value - return value of a device state entry | |
// -> manager:machine().devices[":maincpu"].state["PC"].value | |
//------------------------------------------------- | |
UINT64 lua_engine::l_state_get_value(const device_state_entry *d) | |
{ | |
- return d->value(); | |
+ device_state_interface *state = d->parent_state(); | |
+ if(state) { | |
+ luaThis->machine().save().dispatch_presave(); | |
+ return state->state_int(d->index()); | |
+ } else { | |
+ return 0; | |
+ } | |
} | |
//------------------------------------------------- | |
-// state_set_value - set value of a devices state | |
+// state_set_value - set value of a device state entry | |
// -> manager:machine().devices[":maincpu"].state["D0"].value = 0x0c00 | |
//------------------------------------------------- | |
void lua_engine::l_state_set_value(device_state_entry *d, UINT64 val) | |
{ | |
- d->set_value(val); | |
+ device_state_interface *state = d->parent_state(); | |
+ if(state) { | |
+ state->set_state_int(d->index(), val); | |
+ luaThis->machine().save().dispatch_presave(); | |
+ } | |
} | |
//------------------------------------------------- | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment