Build Your Own Arcade Controls Forum

Main => Software Forum => Topic started by: evilsidius on July 17, 2017, 06:35:38 pm

Title: Mame 0187 save and load states and pause
Post by: evilsidius on July 17, 2017, 06:35:38 pm
Hello guys, i am new to all this, so sorry if this is a noob question.

Well, for now i use my pc for play. In the future i am thinking to build a arcade. But for now i use my windows 10 with a xbox controller.
I have 3 questions.

1 - What i want is to make the save state and load state more simple using only one button, is that possible? I just want to use position 1. So there is a way to assign one button for save in position 1 and another button to load from position 1?

2 - I want Pause the emulation and save or load and i still want the emulation paused. There is a way?
Let me explain this better, those that use the fusion emulator for mega drive, if you pause emulation and load a state you can notice that the emulation will still be on pause. After you press pause again that the emulation will start on the loaded file. I dont know if i make myself clear. English isnt my first language.

Anyway, hope you can help me, thanks you all.
Title: Re: Mame 0187 save and load states and pause
Post by: headkaze on July 17, 2017, 09:52:16 pm
You could achive what you want using MAME's Lua plugin system.

I created a basic load/save state plugin you can use a guide.

savestate_plugin.zip (http://headsoft.com.au/download/mame/savestate_plugin.zip)
Title: Re: Mame 0187 save and load states and pause
Post by: KenToad on July 17, 2017, 10:07:24 pm
Doesn't MAME support this natively? It seems to me like I have paused emulation, hit the save state button, then when I load state, it remembers that it was paused. I'm thinking of an older version of MAME.
Title: Re: Mame 0187 save and load states and pause
Post by: headkaze on July 17, 2017, 10:08:51 pm
Doesn't MAME support this natively? It seems to me like I have paused emulation, hit the save state button, then when I load state, it remembers that it was paused. I'm thinking of an older version of MAME.

You could be right. I just knocked up a plugin as proof-of-concept.
Title: Re: Mame 0187 save and load states and pause
Post by: evilsidius on July 21, 2017, 09:49:44 pm
Thanks, when i get home at weekend i will try.
About the pause, when i load here the game starts. Maybe ita a option somewhere?
Title: Re: Mame 0187 save and load states and pause
Post by: evilsidius on July 24, 2017, 09:00:42 pm
Doesn't MAME support this natively? It seems to me like I have paused emulation, hit the save state button, then when I load state, it remembers that it was paused. I'm thinking of an older version of MAME.

You could be right. I just knocked up a plugin as proof-of-concept.

Headkaze, your plugin worked. Thanks a lot.
But still, when i pause (P) the emulation and used your plugin to save, automatically the emulation started with the message that save was sucefull in front of the game.

I would like to save and load and the emulation stayed on pause. Or at least didint show any message of save sucefull or load sucefull. There is a option?
Title: Re: Mame 0187 save and load states and pause
Post by: Howard_Casto on July 25, 2017, 04:06:48 pm
Mame, unfortunately, isn't made with the user in mind.  The only reason we got save states at all is the fact that they make it easier for devs to troubleshoot bugs. 
Title: Re: Mame 0187 save and load states and pause
Post by: headkaze on July 25, 2017, 05:13:20 pm
I would like to save and load and the emulation stayed on pause. Or at least didint show any message of save sucefull or load sucefull. There is a option?

Yes, just add an "emu.pause()" statement after loading/saving the state.

Eg.
Code: [Select]
local function savestate_menu_callback(index, event)
if event == "select" then
local menu_item = savestate_menu[index][1]

if menu_item == "Load State" then manager:machine():load("auto")
elseif menu_item == "Save State" then manager:machine():save("auto")
end

emu.pause()
end
return false
end
Title: Re: Mame 0187 save and load states and pause
Post by: Howard_Casto on July 25, 2017, 08:28:13 pm
Isn't emu.pause a toggle?
Title: Re: Mame 0187 save and load states and pause
Post by: headkaze on July 26, 2017, 04:45:04 pm
Isn't emu.pause a toggle?

Nope, as per luaengine.cpp (https://github.com/mamedev/mame/blob/master/src/frontend/mame/luaengine.cpp) source it's:

Code: [Select]
* emu.pause() - pause emulation
 * emu.unpause() - unpause emulation
Title: Re: Mame 0187 save and load states and pause
Post by: Howard_Casto on July 26, 2017, 10:52:32 pm
Well that's great.  Most emulator lua implementations have pause screwed up in some way.  Thanks for teaching me something yet again.  :)
Title: Re: Mame 0187 save and load states and pause
Post by: Fenris891 on August 03, 2024, 12:33:06 pm
Hi Headkaze, Im interested in the same thing and this is the only post I found about this issue. Could you reupload your plugin please?
Title: Re: Mame 0187 save and load states and pause
Post by: PL1 on August 03, 2024, 06:00:50 pm
Could you reupload your plugin please?
It's been a while since he logged in here so here's a backup from archive.org.   :cheers:
https://web.archive.org/web/20220703081902/headsoft.com.au/download/mame/savestate_plugin.zip (https://web.archive.org/web/20220703081902/headsoft.com.au/download/mame/savestate_plugin.zip)


Scott
Title: Re: Mame 0187 save and load states and pause
Post by: Fenris891 on August 04, 2024, 04:46:15 am
Thanks, I really appreciate it! In which MAME folder should I need to extract it? "plugin" subfolder maybe? Because there already are tons of init.lua files in different subfolders so I dunno where to put this one. Noob here  ;D
Title: Re: Mame 0187 save and load states and pause
Post by: PL1 on August 04, 2024, 04:15:20 pm
In which MAME folder should I need to extract it? "plugin" subfolder maybe?
Yes.  Copy the "savestate" folder from the .zip file into the "\mame\plugins\" folder.

To enable the plugin, either:
1. Edit the plugin.ini file so savestate is 1 (enabled) instead of 0. (disabled)
    or
2. Launch MAME, press TAB to bring up the MAME menu system, go into the plugins menu, and switch savestate to ON.

Now that you've enabled the plugin, press Shift-F7 to save the current state or press F7 to restore an already-saved state.

I tested the plugin in MAME0.262 with Asteroids (rev 4) and sometimes it works, but it does not restore the pause status or pause after restoring -- the restore loads and you're off and running.
- If trying to save/restore a state with the plugin causes an error with line 38 or 39, press Enter or ESC to close the error window, press Alt-Enter to restore the display to full screen, and try saving/restoring again close the savestate menu called by pausing, and press Shift-F7 to save or F7 to restore.  The error appears to be frequent but intermittent caused by the savestate menu shown below.   :dizzy:
- IIRC LUA scripting has been updated several times since Headkaze wrote the plugin so not sure if that's causing the errors.

Looking in the init.lua file, the only reference I see to pause is this . . .
Code: [Select]
emu.register_pause(function()
emu.show_menu("SaveState")
end)
. . . which apparently causes the pause function to also bring up the savestate menu.

What I don't see in the script is the "emu.pause()" command that Headkaze mentioned, so you'll need to add it yourself if you want it.
I would like to save and load and the emulation stayed on pause. Or at least didint show any message of save sucefull or load sucefull. There is a option?

Yes, just add an "emu.pause()" statement after loading/saving the state.

Eg.
Code: [Select]
local function savestate_menu_callback(index, event)
if event == "select" then
local menu_item = savestate_menu[index][1]

if menu_item == "Load State" then manager:machine():load("auto")
elseif menu_item == "Save State" then manager:machine():save("auto")
end

emu.pause()
end
return false
end


Scott
EDIT: Did more testing in MAME v0.238 and v0.262.  Errors happen whenever you try to use the savestate menu shown in the attachment to save or restore.  The error doesn't happen if you pause, close that savestate menu, and then save using Shift-F7 or restore using F7.
Title: Re: Mame 0187 save and load states and pause
Post by: Fenris891 on August 05, 2024, 04:57:32 am
Yeah, indeed I get the error you mentioned whenever I try to use the plugin to save/load my state..it gives me line 38 and 39 error, attempt to call sol.running_MACHINE.
I ve  done all what you said, apart for the fact that I have no plugin.ini in my MAME folder. Maybe this is causing the issue?  Plus shift+f7 does nothing...tried to use f5 and f9, my shortcut to save/load normally but then plugin became useless...  :banghead:
My version of MAME is 0.245