summaryrefslogtreecommitdiffstatshomepage
path: root/plugins
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2023-04-07 06:20:40 +1000
committer Vas Crabb <vas@vastheman.com>2023-04-07 06:20:40 +1000
commitb67b969bf0911d71396c77e42d85ddfe80de6f20 (patch)
tree8d964eac6e0c4c849dc2b9b0b3742154c6c943d4 /plugins
parentc4282fecede9032be78028e8fde737d44bf2b7c6 (diff)
-Improved some Lua APIs:
* Moved several machine lifecycle callbacks to the notifier/subscriber model. The old callback registration model is still available for them for now, but prints a deprecation warning. * Added pre-save/post-load notifications. * Use a single allocated timer rather than one anonymous timer per waiter. Waiters no longer prevent saved states from being loaded. * Clean up outstanding waiters on stop or state load rather than just leaking them. * Started documenting parts of the emulator interface object that should be relatively stable. -imagedev/avivideo.cpp: Fixed an object leak on unload. Also changed some other media image devices to use smart pointers.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/autofire/init.lua6
-rw-r--r--plugins/cheat/init.lua8
-rw-r--r--plugins/cheatfind/init.lua4
-rw-r--r--plugins/console/init.lua10
-rw-r--r--plugins/data/init.lua4
-rw-r--r--plugins/discord/init.lua20
-rw-r--r--plugins/dummy/init.lua18
-rw-r--r--plugins/gdbstub/init.lua18
-rw-r--r--plugins/hiscore/init.lua11
-rw-r--r--plugins/inputmacro/init.lua6
-rw-r--r--plugins/layout/init.lua22
-rw-r--r--plugins/timecode/init.lua6
-rw-r--r--plugins/timer/init.lua11
13 files changed, 88 insertions, 56 deletions
diff --git a/plugins/autofire/init.lua b/plugins/autofire/init.lua
index ab5e7b11f47..35d37e69592 100644
--- a/plugins/autofire/init.lua
+++ b/plugins/autofire/init.lua
@@ -9,6 +9,8 @@ local exports = {
local autofire = exports
+local frame_subscription, stop_subscription
+
function autofire.startplugin()
-- List of autofire buttons, each being a table with keys:
@@ -104,9 +106,9 @@ function autofire.startplugin()
end
end
- emu.register_frame(process_frame)
+ frame_subscription = emu.add_machine_frame_notifier(process_frame)
emu.register_prestart(load_settings)
- emu.register_stop(save_settings)
+ stop_subscription = emu.add_machine_stop_notifier(save_settings)
emu.register_menu(menu_callback, menu_populate, _p('plugin-autofire', 'Autofire'))
end
diff --git a/plugins/cheat/init.lua b/plugins/cheat/init.lua
index f76ffcdf62a..f2418fed7b6 100644
--- a/plugins/cheat/init.lua
+++ b/plugins/cheat/init.lua
@@ -73,6 +73,8 @@ exports.author = { name = "Carl" }
local cheat = exports
+local reset_subscription, stop_subscription, frame_subscription
+
function cheat.set_folder(path)
cheat.path = path
end
@@ -809,7 +811,7 @@ function cheat.startplugin()
return menu_populate()
end, _("Cheat"))
- emu.register_start(function()
+ reset_subscription = emu.add_machine_reset_notifier(function ()
if not stop then
return
end
@@ -832,13 +834,13 @@ function cheat.startplugin()
end
end)
- emu.register_stop(function()
+ stop_subscription = emu.add_machine_stop_notifier(function ()
stop = true
consolelog = nil
save_hotkeys()
end)
- emu.register_frame(function()
+ frame_subscription = emu.add_machine_frame_notifier(function ()
if stop then
return
end
diff --git a/plugins/cheatfind/init.lua b/plugins/cheatfind/init.lua
index d86315d7156..f36b4f5b2d5 100644
--- a/plugins/cheatfind/init.lua
+++ b/plugins/cheatfind/init.lua
@@ -10,6 +10,8 @@ exports.author = { name = "Carl" }
local cheatfind = exports
+local reset_subscription
+
function cheatfind.startplugin()
local cheat = {}
@@ -333,7 +335,7 @@ function cheatfind.startplugin()
end
end
- emu.register_start(start)
+ reset_subscription = emu.add_machine_reset_notifier(start)
local menu_is_showing = false
local tabbed_out = false
diff --git a/plugins/console/init.lua b/plugins/console/init.lua
index 7c04184513d..a9835ae4ad4 100644
--- a/plugins/console/init.lua
+++ b/plugins/console/init.lua
@@ -13,6 +13,8 @@ local history_file = "console_history"
local history_fullpath = nil
+local reset_subscription, stop_subscription
+
function console.startplugin()
local conth = emu.thread()
local ln_started = false
@@ -220,16 +222,18 @@ function console.startplugin()
return table.concat(result, '\001')
end
- emu.register_start(function()
+ reset_subscription = emu.add_machine_reset_notifier(function ()
if not consolebuf and manager.machine.debugger then
consolebuf = manager.machine.debugger.consolelog
lastindex = 0
end
end)
- emu.register_stop(function() consolebuf = nil end)
+ stop_subscription = emu.add_machine_stop_notifier(function ()
+ consolebuf = nil
+ end)
- emu.register_periodic(function()
+ emu.register_periodic(function ()
if stopped then
return
end
diff --git a/plugins/data/init.lua b/plugins/data/init.lua
index eb3ad1ae9b3..0ce3dfa4631 100644
--- a/plugins/data/init.lua
+++ b/plugins/data/init.lua
@@ -15,6 +15,8 @@ local data = exports
local plugindir
+local reset_subscription
+
function data.set_folder(path)
plugindir = path
end
@@ -25,7 +27,7 @@ function data.startplugin()
local cur_set
local cur_list
- emu.register_start(
+ reset_subscription = emu.add_machine_reset_notifier(
function ()
data_scr = {}
for file in lfs.dir(plugindir) do
diff --git a/plugins/discord/init.lua b/plugins/discord/init.lua
index cc7d09582c5..9e077f5d656 100644
--- a/plugins/discord/init.lua
+++ b/plugins/discord/init.lua
@@ -1,14 +1,16 @@
-- license:BSD-3-Clause
-- copyright-holders:Carl
-local exports = {}
-exports.name = "discord"
-exports.version = "0.0.1"
-exports.description = "Discord presence"
-exports.license = "BSD-3-Clause"
-exports.author = { name = "Carl" }
+local exports = {
+ name = "discord",
+ version = "0.0.1",
+ description = "Discord presence",
+ license = "BSD-3-Clause",
+ author = { name = "Carl" } }
local discord = exports
+local reset_subscription, pause_subscription, resume_subscription
+
function discord.startplugin()
local pipe = emu.file("rw")
local json = require("json")
@@ -98,16 +100,16 @@ function discord.startplugin()
end
end
- emu.register_start(function()
+ reset_subscription = emu.add_machine_reset_notifier(function ()
starttime = os.time()
update("Playing")
end)
- emu.register_pause(function()
+ pause_subscription = emu.add_machine_pause_notifier(function ()
update("Paused")
end)
- emu.register_resume(function()
+ resume_subscription = emu.add_machine_resume_notifier(function ()
update("Playing")
end)
end
diff --git a/plugins/dummy/init.lua b/plugins/dummy/init.lua
index 45f6d78d570..54d4f3d7fef 100644
--- a/plugins/dummy/init.lua
+++ b/plugins/dummy/init.lua
@@ -9,21 +9,25 @@ local exports = {
local dummy = exports
+local reset_subscription, stop_subscription
+
function dummy.startplugin()
- emu.register_start(function()
- emu.print_verbose("Starting " .. emu.gamename())
- end)
+ reset_subscription = emu.add_machine_reset_notifier(
+ function ()
+ emu.print_info("Starting " .. emu.gamename())
+ end)
- emu.register_stop(function()
- emu.print_verbose("Exiting " .. emu.gamename())
- end)
+ stop_subscription = emu.add_machine_stop_notifier(
+ function ()
+ emu.print_info("Exiting " .. emu.gamename())
+ end)
local function menu_populate()
return {{ "This is a", "test", "off" }, { "Also a", "test", "" }}
end
local function menu_callback(index, event)
- emu.print_verbose("index: " .. index .. " event: " .. event)
+ emu.print_info("index: " .. index .. " event: " .. event)
return false
end
diff --git a/plugins/gdbstub/init.lua b/plugins/gdbstub/init.lua
index 8a28a68d8cc..1d358518965 100644
--- a/plugins/gdbstub/init.lua
+++ b/plugins/gdbstub/init.lua
@@ -1,11 +1,11 @@
-- license:BSD-3-Clause
-- copyright-holders: Carl
-local exports = {}
-exports.name = "gdbstub"
-exports.version = "0.0.1"
-exports.description = "GDB stub plugin"
-exports.license = "BSD-3-Clause"
-exports.author = { name = "Carl" }
+local exports = {
+ name = "gdbstub",
+ version = "0.0.1",
+ description = "GDB stub plugin",
+ license = "BSD-3-Clause",
+ author = { name = "Carl" } }
local gdbstub = exports
@@ -25,6 +25,8 @@ local regmaps = {
regmaps.i486 = regmaps.i386
regmaps.pentium = regmaps.i386
+local reset_subscription, stop_subscription
+
function gdbstub.startplugin()
local debugger
local debug
@@ -35,7 +37,7 @@ function gdbstub.startplugin()
local consolelast
local running
- emu.register_start(function ()
+ reset_subscription = emu.add_machine_reset_notifier(function ()
debugger = manager.machine.debugger
if not debugger then
print("gdbstub: debugger not enabled")
@@ -56,7 +58,7 @@ function gdbstub.startplugin()
running = false
end)
- emu.register_stop(function()
+ stop_subscription = emu.add_machine_stop_notifier(function ()
consolelog = nil
cpu = nil
debug = nil
diff --git a/plugins/hiscore/init.lua b/plugins/hiscore/init.lua
index 5f93b91bd1a..ae8ebf7568e 100644
--- a/plugins/hiscore/init.lua
+++ b/plugins/hiscore/init.lua
@@ -14,7 +14,8 @@ local exports = {
local hiscore = exports
-local hiscore_plugin_path = ""
+local hiscore_plugin_path
+local reset_subscription, frame_subscription, stop_subscription
function hiscore.set_folder(path)
hiscore_plugin_path = path
@@ -328,7 +329,7 @@ function hiscore.startplugin()
scores_have_been_read = false;
end
- emu.register_start(function()
+ reset_subscription = emu.add_machine_reset_notifier(function ()
found_hiscore_entry = false
mem_check_passed = false
scores_have_been_read = false;
@@ -354,18 +355,18 @@ function hiscore.startplugin()
end
end)
- emu.register_frame(function()
+ frame_subscription = emu.add_machine_frame_notifier(function ()
if found_hiscore_entry then
tick()
end
end)
- emu.register_stop(function()
+ stop_subscription = emu.add_machine_stop_notifier(function ()
reset()
save_config()
end)
- emu.register_prestart(function()
+ emu.register_prestart(function ()
reset()
end)
diff --git a/plugins/inputmacro/init.lua b/plugins/inputmacro/init.lua
index 15156bb159c..9c520f3a503 100644
--- a/plugins/inputmacro/init.lua
+++ b/plugins/inputmacro/init.lua
@@ -10,6 +10,8 @@ local exports = {
local inputmacro = exports
+local frame_subscription, stop_subscription
+
function inputmacro.startplugin()
--[[
Configuration data:
@@ -129,9 +131,9 @@ function inputmacro.startplugin()
return menu:populate()
end
- emu.register_frame(process_frame)
+ frame_subscription = emu.add_machine_frame_notifier(process_frame)
emu.register_prestart(start)
- emu.register_stop(stop)
+ stop_subscription = emu.add_machine_stop_notifier(stop)
emu.register_menu(menu_callback, menu_populate, _p('plugin-inputmacro', 'Input Macros'))
end
diff --git a/plugins/layout/init.lua b/plugins/layout/init.lua
index 861e0a697b3..a7d3f7fb199 100644
--- a/plugins/layout/init.lua
+++ b/plugins/layout/init.lua
@@ -2,15 +2,17 @@
-- copyright-holders:Carl
-- Layout scripts should return a table and a string. The table can have two optional keys reset and frame
-- which have functions for values called on reset and frame draw respectively and the string is a unique name.
-local exports = {}
-exports.name = "layout"
-exports.version = "0.0.1"
-exports.description = "Layout helper plugin"
-exports.license = "BSD-3-Clause"
-exports.author = { name = "Carl" }
+local exports = {
+ name = "layout",
+ version = "0.0.1",
+ description = "Layout helper plugin",
+ license = "BSD-3-Clause",
+ author = { name = "Carl" } }
local layout = exports
+local frame_subscription, stop_subscription
+
function layout.startplugin()
local scripts = {}
local function prepare_layout(file, script)
@@ -45,7 +47,7 @@ function layout.startplugin()
end
emu.register_callback(prepare_layout, "layout")
- emu.register_frame(function()
+ frame_subscription = emu.add_machine_frame_notifier(function ()
if manager.machine.paused then
return
end
@@ -55,14 +57,16 @@ function layout.startplugin()
end
end
end)
- emu.register_start(function()
+ emu.register_prestart(function ()
for num, scr in pairs(scripts) do
if scr.reset then
scr.reset()
end
end
end)
- emu.register_stop(function() scripts = {} end)
+ stop_subscription = emu.add_machine_stop_notifier(function ()
+ scripts = {}
+ end)
end
return exports
diff --git a/plugins/timecode/init.lua b/plugins/timecode/init.lua
index 93435ef2870..1de94c034ba 100644
--- a/plugins/timecode/init.lua
+++ b/plugins/timecode/init.lua
@@ -10,6 +10,8 @@ local exports = {
local timecode = exports
+local frame_subscription, stop_subscription
+
function timecode.startplugin()
local file -- the timecode log file
local write -- whether to record a timecode on the next emulated frame
@@ -338,10 +340,10 @@ function timecode.startplugin()
end
- emu.register_frame(process_frame)
+ frame_subscription = emu.add_machine_frame_notifier(process_frame)
emu.register_frame_done(process_frame_done)
emu.register_prestart(start)
- emu.register_stop(stop)
+ stop_subscription = emu.add_machine_stop_notifier(stop)
emu.register_menu(menu_callback, menu_populate, _p('plugin-timecode', 'Timecode Recorder'))
end
diff --git a/plugins/timer/init.lua b/plugins/timer/init.lua
index 35dbb6431ac..1d67472b3c2 100644
--- a/plugins/timer/init.lua
+++ b/plugins/timer/init.lua
@@ -1,5 +1,6 @@
-- license:BSD-3-Clause
-- copyright-holders:Vas Crabb
+-- TODO: track time properly across soft reset and state load
local exports = {
name = 'timer',
version = '0.0.3',
@@ -9,6 +10,8 @@ local exports = {
local timer = exports
+local reset_subscription, stop_subscription
+
function timer.startplugin()
local total_time = 0
local start_time = 0
@@ -53,8 +56,8 @@ function timer.startplugin()
end
- emu.register_start(
- function()
+ reset_subscription = emu.add_machine_reset_notifier(
+ function ()
if emu.romname() ~= '___empty' then
start_time = os.time()
local persister = require('timer/timer_persist')
@@ -62,8 +65,8 @@ function timer.startplugin()
end
end)
- emu.register_stop(
- function()
+ stop_subscription = emu.add_machine_stop_notifier(
+ function ()
if emu.romname() ~= '___empty' then
local persister = require('timer/timer_persist')
persister:update_totals(start_time)