summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--plugins/hiscore/init.lua18
-rw-r--r--src/emu/luaengine.cpp12
-rw-r--r--src/emu/luaengine.h2
-rw-r--r--src/emu/machine.cpp7
-rw-r--r--src/emu/machine.h2
5 files changed, 30 insertions, 11 deletions
diff --git a/plugins/hiscore/init.lua b/plugins/hiscore/init.lua
index 3c8e9a37dbe..63e68c0bb5d 100644
--- a/plugins/hiscore/init.lua
+++ b/plugins/hiscore/init.lua
@@ -127,7 +127,7 @@ function hiscore.startplugin()
function write_scores ( posdata )
- print("write_scores")
+ print("write_scores")
local output = io.open(get_file_name(), "wb");
if not output then
-- attempt to create the directory, and try again
@@ -242,9 +242,8 @@ function hiscore.startplugin()
current_game = ""
mem_check_passed = false
scores_have_been_read = false;
+ last_write_time = -10
print("Starting " .. emu.gamename())
- -- check if we've just soft reset
- -- reset() -- there's no way to reliably save scores after a soft reset currently
current_game = emu.romname()
dat = read_hiscore_dat()
if dat and dat ~= "" then
@@ -254,14 +253,17 @@ function hiscore.startplugin()
print("hiscore.dat parse error");
return;
end
- emu.sethook( tick, "frame" );
- emu.register_stop(function()
- reset()
- end)
- end
+ end
+ emu.sethook( tick, "frame" );
end)
+ emu.register_stop(function()
+ reset()
+ end)
+ emu.register_prestart(function()
+ reset()
+ end)
end
return exports
diff --git a/src/emu/luaengine.cpp b/src/emu/luaengine.cpp
index cd392de3c89..18ae0172bf7 100644
--- a/src/emu/luaengine.cpp
+++ b/src/emu/luaengine.cpp
@@ -1319,6 +1319,11 @@ int lua_engine::register_function(lua_State *L, const char *id)
return 1;
}
+int lua_engine::l_emu_register_prestart(lua_State *L)
+{
+ return register_function(L, "LUA_ON_PRESTART");
+}
+
int lua_engine::l_emu_register_start(lua_State *L)
{
return register_function(L, "LUA_ON_START");
@@ -1344,6 +1349,11 @@ int lua_engine::l_emu_register_frame(lua_State *L)
return register_function(L, "LUA_ON_FRAME");
}
+void lua_engine::on_machine_prestart()
+{
+ execute_function("LUA_ON_PRESTART");
+}
+
void lua_engine::on_machine_start()
{
execute_function("LUA_ON_START");
@@ -1393,6 +1403,7 @@ void lua_engine::update_machine()
void lua_engine::attach_notifiers()
{
+ machine().add_notifier(MACHINE_NOTIFY_RESET, machine_notify_delegate(FUNC(lua_engine::on_machine_prestart), this), true);
machine().add_notifier(MACHINE_NOTIFY_RESET, machine_notify_delegate(FUNC(lua_engine::on_machine_start), this));
machine().add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(lua_engine::on_machine_stop), this));
machine().add_notifier(MACHINE_NOTIFY_PAUSE, machine_notify_delegate(FUNC(lua_engine::on_machine_pause), this));
@@ -1439,6 +1450,7 @@ void lua_engine::initialize()
.addCFunction ("start", l_emu_start )
.addCFunction ("pause", l_emu_pause )
.addCFunction ("unpause", l_emu_unpause )
+ .addCFunction ("register_prestart", l_emu_register_prestart )
.addCFunction ("register_start", l_emu_register_start )
.addCFunction ("register_stop", l_emu_register_stop )
.addCFunction ("register_pause", l_emu_register_pause )
diff --git a/src/emu/luaengine.h b/src/emu/luaengine.h
index 2f0f4ad7a34..b98b9597b56 100644
--- a/src/emu/luaengine.h
+++ b/src/emu/luaengine.h
@@ -83,6 +83,7 @@ private:
void update_machine();
+ void on_machine_prestart();
void on_machine_start();
void on_machine_stop();
void on_machine_pause();
@@ -114,6 +115,7 @@ private:
static int l_emu_pause(lua_State *L);
static int l_emu_unpause(lua_State *L);
static int l_emu_set_hook(lua_State *L);
+ static int l_emu_register_prestart(lua_State *L);
static int l_emu_register_start(lua_State *L);
static int l_emu_register_stop(lua_State *L);
static int l_emu_register_pause(lua_State *L);
diff --git a/src/emu/machine.cpp b/src/emu/machine.cpp
index d76ad49676d..70d1ccc411b 100644
--- a/src/emu/machine.cpp
+++ b/src/emu/machine.cpp
@@ -739,12 +739,15 @@ void running_machine::toggle_pause()
// given type
//-------------------------------------------------
-void running_machine::add_notifier(machine_notification event, machine_notify_delegate callback)
+void running_machine::add_notifier(machine_notification event, machine_notify_delegate callback, bool first)
{
assert_always(m_current_phase == MACHINE_PHASE_INIT, "Can only call add_notifier at init time!");
+ if(first)
+ m_notifier_list[event].push_front(std::make_unique<notifier_callback_item>(callback));
+
// exit notifiers are added to the head, and executed in reverse order
- if (event == MACHINE_NOTIFY_EXIT)
+ else if (event == MACHINE_NOTIFY_EXIT)
m_notifier_list[event].push_front(std::make_unique<notifier_callback_item>(callback));
// all other notifiers are added to the tail, and executed in the order registered
diff --git a/src/emu/machine.h b/src/emu/machine.h
index 1eaee4d6e4a..5e19aefb6c4 100644
--- a/src/emu/machine.h
+++ b/src/emu/machine.h
@@ -214,7 +214,7 @@ public:
void pause();
void resume();
void toggle_pause();
- void add_notifier(machine_notification event, machine_notify_delegate callback);
+ void add_notifier(machine_notification event, machine_notify_delegate callback, bool first = false);
void call_notifiers(machine_notification which);
void add_logerror_callback(logerror_callback callback);
void set_ui_active(bool active) { m_ui_active = active; }