diff --git a/README.md b/README.md index 17679d2..265c900 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,13 @@ This is a LUA Plugin for [MAME](https://www.mamedev.org/) that automatically ski ## What does it do? -The plugin temporarily unthrottles the framerate of a game at startup until a certain number of frames has been reached and then returns the framerate back to normal. The plugin also temporarily mutes the audio and blacks out the screen. The faster the computer used, the faster the unthrottled startup time will be. +The plugin temporarily unthrottles the framerate of a game at startup until a certain number of frames has been reached and then returns the framerate back to normal. The plugin also temporarily mutes the audio and blacks out the screen. The faster the computer, the faster the unthrottled startup time will be. ## `galaga` startup example -| Before: ~12 sec startup time | After: ~1 sec startup time | -| ---------------------------- | -------------------------- | -| ![test](media/before.gif) | ![](media/after.gif) | +| Before: ~12 sec startup time | After: ~1 sec startup time | +| ------------------------------------------ | --------------------------------------- | +| ![normal galaga startup](media/before.gif) | ![fast galaga startup](media/after.gif) | ## Installation instructions @@ -23,7 +23,7 @@ The plugin temporarily unthrottles the framerate of a game at startup until a ce - Add `skipstartupframes` to the `plugin` option in `mame.ini` - Run MAME with the command-line option `-plugin skipstartupframes` - ![](media/plugin-options.jpg) + ![MAME plugin toggle menu](media/plugin-menu.jpg) ## 2004 BYOAC Legacy @@ -56,42 +56,41 @@ rallyx,760 `ssf.txt` is an old file that was [created back in 2004](https://forum.arcadecontrols.com/index.php/topic,48674.msg) and was the culmination of work by many members of the [BYOAC forum](https://forum.arcadecontrols.com/) who examined 1000's of games and recorded the correct number of frames to be skipped. The majority of startup frames are most likely still accurate from 2004 but a lot can change in 20+ years. Some rom's might have been changed or redumped, new roms were added to MAME, etc. If you find any startup frames in `ssf.txt` to be inaccurate or missing, you can easily contribute changes to the project: -[CLICK HERE TO EDIT `ssf.txt`](https://github.com/Jakobud/skipstartupframes/edit/main/ssf.txt). Make your edits, commit your changes and then create a pull request. I will examine the change and either approve or reject it. +[CLICK HERE TO EDIT `ssf.txt`](https://github.com/Jakobud/skipstartupframes/edit/main/ssf.txt). Make your edits, commit your changes and then create a pull request into the `develop` branch. I will examine the change and either approve or reject it. ## Debug Mode -In order to facilitate determining accurate startup frames to use in `ssf.txt` the plugin includes an optional "debug mode" that prints out the frame numbers on the screen. Just open `options.cfg` and change `debug` to `true`. +In order to facilitate determining accurate startup frames to use in `ssf.txt` the plugin includes an optional "debug mode" that prints out the frame numbers on the screen. See the **Options section** for more details. -![](media/debug.gif) - -Also included is `debugSpeed` in `options.cfg` that can put the game in slow-motion during debug mode. A value of `1` is normal speed. A low value like `0.25` is slow-motion. +![Skip Startup Frames Debug Mode](media/debug.gif) ## Options -This plugin includes a `options.cfg` with various values to adjust (Restart MAME after making changes) +| In-Game Menu | | +| ----------------------------------------- | ------------------------------------------------------------- | +| ![Mame In-Game Menu](media/game-menu.png) | ![Skip Startup Frames Options](media/plugin-options-menu.png) | -- `blackout` - _boolean_ +- `blackout` - _Yes/No_ - Whether or not to black out the screen while skipping startup frames. - The plugin still renders the startup frames. This option just makes the screen black during the startup. Turn this option off if you want to see the unthrottled startup frames. - - Default: `true` + - Default: `Yes` -- `mute` - _boolean_ +- `mute` - _Yes/No_ - Whether or not to mute the audio while skipping startup frames. - - Default: `true` + - Default: `Yes` -- `parentFallback` - _boolean_ +- `parentFallback` - _Yes/No_ - If a rom is a clone and is not found in `ssf.txt`, fallback to using the parent rom's startup frames from `ssf.txt`. - - Default: `true` + - Default: `Yes` -- `debug` - _boolean_ +- `debug` - _Yes/No_ - Enable debug mode to show frame numbers in game in order to help determine accurate startup frame values to use for roms. - - Default: `false` + - Default: `No` -- `debugSpeed` - _float_ +- `debugSlowMotion` - _Yes/No_ - Used to slowdown game speed/playback while in debug mode. - - `1.0` is normal speed. Lower numbers like `0.25` will make the game run in slow-motion. - - Default: `0.25` + - Default: `No` diff --git a/init.lua b/init.lua index 8a8f214..819d515 100644 --- a/init.lua +++ b/init.lua @@ -8,22 +8,25 @@ local skipstartupframes = json.parse(io.open(plugin_directory .. '/plugin.json') -- Notifiers local startNotifier = nil local stopNotifier = nil +local menuNotifier = nil -function skipstartupframes.startplugin() - local options = {} +local slowMotionRate = 0.3 - -- Default options - local defaultoptions = { - blackout = true, - mute = true, - parentFallback = true, - debug = false, - debugSpeed = 0.25 - } +-- Default options +local defaultoptions = { + blackout = true, + mute = true, + parentFallback = true, + debug = false, + debugSlowMotion = false +} + +-- Load options from options.cfg +local load_options = function() + local options = {} - -- Open options file - local options_path = plugin_directory .. "/options.cfg" - local options_file = io.open(options_path, "r") + -- Open options file for reading + local options_file = io.open(plugin_directory .. "/options.cfg", "r") -- If options file doesn't exist, use default options if options_file == nil then @@ -32,14 +35,33 @@ function skipstartupframes.startplugin() -- Parse options file options = json.parse(options_file:read("*a")) - -- Add any missing options from defaults and fix any wrong types for k,v in pairs(defaultoptions) do + -- Fix incorrect types and add missing options if (options[k] == nil or type(options[k]) ~= type(v)) then options[k] = v end end end + options_file:close() + + return options +end + +-- Save options to options.cfg +local save_options = function(options) + + -- Open options file for reading + local options_file = io.open(plugin_directory .. "/options.cfg", "w") + + local data = json.stringify(options, {indent = true}) + options_file:write(data) + options_file:close() +end + +function skipstartupframes.startplugin() + local options = load_options() + -- Find the frames file local frames_path = plugin_directory .. "/ssf.txt" local frames_file = io.open(frames_path, "r") @@ -70,6 +92,7 @@ function skipstartupframes.startplugin() process_frame() end) + -- Run when MAME begins emulation local start = function() local rom = emu.romname() @@ -120,8 +143,8 @@ function skipstartupframes.startplugin() end -- Slow-Motion Debug Mode - if options.debug and options.debugSpeed ~= 1 then - manager.machine.video.throttle_rate = options.debugSpeed + if options.debug and options.debugSlowMotion then + manager.machine.video.throttle_rate = slowMotionRate end -- Starting frame @@ -153,6 +176,9 @@ function skipstartupframes.startplugin() -- Unmute sound manager.machine.sound.system_mute = false + -- Reset throttle rate + manager.machine.video.throttle_rate = 1 + -- Reset frame processing function to do nothing when frame target is reached process_frame = function() end end @@ -161,38 +187,97 @@ function skipstartupframes.startplugin() return end + -- Run when MAME stops emulation local stop = function() process_frame = function() end end - -- Setup Plugin Options Menu - -- emu.register_menu(menu_callback, menu_populate, _p("plugin-skipstartupframes", "Skip Startup Frames")) + -- Option menu variables + local menuSelection = 3 + local blackoutIndex + local muteIndex + local parentFallbackIndex + local debugIndex + local debugSlowMotionIndex + + -- Option menu creation/population + local menu_populate = function() + local result = {} + + table.insert(result, { 'Skip Startup Frames', '', 'off' }) + table.insert(result, { '---', '', '' }) + + table.insert(result, { _p("plugin-skipstartupframes", "Black out screen during startup"), options.blackout and 'Yes' or 'No', 'lr' }) + blackoutIndex = #result + + table.insert(result, { _p("plugin-skipstartupframes", "Mute audio during startup"), options.mute and 'Yes' or 'No', 'lr' }) + muteIndex = #result + + table.insert(result, { _p("plugin-skipstartupframes", "Fallback to parent rom startup frames"), options.parentFallback and 'Yes' or 'No', 'lr' }) + parentFallbackIndex = #result + + table.insert(result, { _p("plugin-skipstartupframes", "Debug Mode"), options.debug and 'Yes' or 'No', 'lr' }) + debugIndex = #result + + table.insert(result, { _p("plugin-skipstartupframes", "Slow Motion during Debug Mode"), options.debugSlowMotion and 'Yes' or 'No', 'lr' }) + debugSlowMotionIndex = #result + + return result, menuSelection + end + + -- Option menu event callback + local menu_callback = function(index, event) + menuSelection = index - -- local menu_populate = function() + -- Blackout Screen Option + if index == blackoutIndex then + if event == 'left' or event == 'right' then + options.blackout = not options.blackout + save_options(options) + end + return true + + -- Mute Audio Option + elseif index == muteIndex then + if event == 'left' or event == 'right' then + options.mute = not options.mute + save_options(options) + end + return true - -- local mute - -- local blackout - -- local debug + -- Parent ROM Fallback Option + elseif index == parentFallbackIndex then + if event == 'left' or event == 'right' then + options.parentFallback = not options.parentFallback + save_options(options) + end + return true - -- local result = {} - -- table.insert(result, { 'Skip Startup Frames', '', 'off' }) - -- table.insert(result, { '---', '', '' }) - -- -- table.insert(result, { _p("plugin-skipstartupframes", "Mute Sound"), mute, "off" }) - -- -- table.insert(result, { _p("plugin-skipstartupframes", "Black Out Screen"), blackout, "off" }) - -- -- table.insert(result, { _p("plugin-skipstartupframes", "Debug"), debug, "off" }) + -- Debug Mode Option + elseif index == debugIndex then + if event == 'left' or event == 'right' then + options.debug = not options.debug + save_options(options) + end + return true - -- return result - -- end + -- Debug Slow Motion Option + elseif index == debugSlowMotionIndex then + if event == 'left' or event == 'right' then + options.debugSlowMotion = not options.debugSlowMotion + save_options(options) + end + return true - -- local menu_callback = function(index, entry) - -- print(index, entry) - -- end + end + end -- MAME 0.254 and newer compatibility check if emu.add_machine_reset_notifier ~= nil and emu.add_machine_stop_notifier ~= nil then startNotifier = emu.add_machine_reset_notifier(start) stopNotifier = emu.add_machine_stop_notifier(stop) + menuNotifier = emu.register_menu(menu_callback, menu_populate, _p("plugin-skipstartupframes", "Skip Startup Frames")) else -- MAME version not compatible (probably can't even load LUA plugins anyways) diff --git a/media/game-menu.png b/media/game-menu.png new file mode 100644 index 0000000..1e18ab8 Binary files /dev/null and b/media/game-menu.png differ diff --git a/media/plugin-options.jpg b/media/plugin-menu.jpg similarity index 100% rename from media/plugin-options.jpg rename to media/plugin-menu.jpg diff --git a/media/plugin-options-menu.png b/media/plugin-options-menu.png new file mode 100644 index 0000000..1fe8576 Binary files /dev/null and b/media/plugin-options-menu.png differ diff --git a/options.cfg b/options.cfg index d9c509a..071e53f 100644 --- a/options.cfg +++ b/options.cfg @@ -3,5 +3,5 @@ "mute": true, "parentFallback": true, "debug": false, - "debugSpeed": 1 + "debugSlowMotion": false } diff --git a/plugin.json b/plugin.json index d43b626..853e94a 100644 --- a/plugin.json +++ b/plugin.json @@ -1,10 +1,10 @@ { "plugin": { - "name": "skipstartupframes", - "description": "Skip Startup Frames", - "version": "1.0.0", - "author": "Jake Wilson", - "type": "plugin", - "start": "false" + "name": "skipstartupframes", + "description": "Skip Startup Frames", + "version": "1.0.0", + "author": "Jake Wilson", + "type": "plugin", + "start": "false" } }