RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    mame 2003 plus doesn't save hi-scores on shutdown

    Scheduled Pinned Locked Moved Help and Support
    mame 2003 plusstar warsshutdown switchhiscoresnvram
    15 Posts 6 Posters 1.5k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      james.milroy
      last edited by

      I've got my Star Wars cabinet just the way I want (well almost!) but just discovered a small problem. If I play the game and register a new hi-score for instance or change dip switch settings in the service menu then the changes and scores are NOT saved if I press my power button for a system shutdown. If however I quit out of the rom using the hotkey combo (esc & enter in my case) then it updates the starwars.hi and .nv files. I can then shutdown either from the button or the emulationstaion menu and the scores and settings will be preserved for next time.

      Is there something I can do to the shutdown script to resolve this? I'm using a Pimoroni PicadeX hat and the power button on that.

      M 1 Reply Last reply Reply Quote 0
      • M
        mahoneyt944 @james.milroy
        last edited by mahoneyt944

        @james-milroy mame2003-plus has an option to save hiscores recursively, meaning every so many seconds the save will occur again and again as you play. This isn't typically an option I would recommend since you will be constantly writing to your device, but it maybe what you're looking for. There's also the potential for issues since hiscore saving is a mod in it's own and this option will test it's behavior frequently.

        Anyways, the option is listed under core options-> system->autosave hiscore-> recursively, this also only applies to .hi files.

        1 Reply Last reply Reply Quote 0
        • B
          barbudreadmon
          last edited by barbudreadmon

          Maybe try running killall -s SIGTERM retroarch before shutting down in your shutdown script ? It will close retroarch gracefully (assuming your retroarch isn't super old, there was a bug about this in the past), allowing the core to properly flush its savefiles (eeprom, nvram, hiscore, ...)

          FBNeo developer - github - forum

          1 Reply Last reply Reply Quote 1
          • windgW
            windg
            last edited by windg

            I don't know if the autosave interval option from Retroarch menu will work with this emulator. Sorry i don't have mame games to test it.

            My English isn't at a good level.

            J 1 Reply Last reply Reply Quote 0
            • J
              james.milroy @windg
              last edited by

              @windg , I've tried setting autosave hiscore to recursive. It didn't work in this instance. I was concerned about using it as @mahoneyt944 quite rightly stated that it would be continuously writing to the microsd card. I'll need to look into @barbudreadmon suggestion to edit the shutdown script, that could be what I'm looking for.

              B 1 Reply Last reply Reply Quote 0
              • B
                barbudreadmon @james.milroy
                last edited by

                @james-milroy did the killall method work ?

                FBNeo developer - github - forum

                J 1 Reply Last reply Reply Quote 0
                • J
                  james.milroy @barbudreadmon
                  last edited by

                  @barbudreadmon , I didn't get a chance to try it! I was messing about with shutdown scripts and power buttons and trashed my setup. I thought I had a backup on my PC but turned out I didn't. Long story short, I've started from scratch a couple of times since to try to get my setup back the way it was. I'm nearly there doing a bit when I get a chance. I'm at the stage now where I can attempt to try your suggestion using killall. Naturally, I've made a backup of my SD card this time just in case of any mishaps. Best of it all was that my setup had been perfect all but for saving hi-scores when shutdown using the button. I could probably have lived with that, but I like to tinker.

                  J 1 Reply Last reply Reply Quote 0
                  • J
                    james.milroy @james.milroy
                    last edited by

                    @barbudreadmon , i've tried killall -s SIGTERM retroarch from the command line using PuTTY and then rebooted using my button and it does save the hi-scores. I now need to figure out how to incorporate this into the shutdown. Problem is I don't know how the Picade HAT performs its shutdown. I know it uses GPIO pins and must be monitored somewhere, but their (Pimoroni) documentation doesn't explain things very clearly. I'm going to try the method @meleu proposed in his thread ensuring ES gracefully finish and save metadata in every system shutdown and see where that takes me.

                    J B 2 Replies Last reply Reply Quote 0
                    • J
                      james.milroy @james.milroy
                      last edited by

                      @barbudreadmon , just tried @meleu proposal as in last post, no joy i'm afraid, it doesn't save the hi-scores in the running emulator when the button is pressed. There's got to be a simpler way to accomplish this using killall -s SIGTERM retroarch I'll keep digging and hopefully find out what script is called when I press the button on my Picade X HAT.

                      1 Reply Last reply Reply Quote 0
                      • B
                        barbudreadmon @james.milroy
                        last edited by

                        @james-milroy said in mame 2003 plus doesn't save hi-scores on shutdown:

                        Pimoroni

                        From what i see at https://github.com/pimoroni/clean-shutdown/issues/17 you can run command before pimonori shutdown by using systemd capabilities, you can find more concrete example of this at https://www.golinuxcloud.com/run-script-with-systemd-before-shutdown-linux/

                        FBNeo developer - github - forum

                        J 1 Reply Last reply Reply Quote 0
                        • J
                          james.milroy @barbudreadmon
                          last edited by

                          @barbudreadmon , I've been tinkering with this and I can using a simple script call the splashscreen.sh script and display the splashscreen again before shutdown when I press my power button, so I can do things before shutting down. I have tried putting killall -s SIGTERM retroarch into the script but it isn't saving the hi-scores suggesting that either the command isn't getting run before the Pi shuts down or I've made a mistake in my script. I'm guessing my lack of Linux knowledge is probably the case here and I'll need a bit more than just killall -s SIGTERM retroarch in there. I'll keep plugging away.

                          J 1 Reply Last reply Reply Quote 0
                          • J
                            james.milroy @james.milroy
                            last edited by

                            @barbudreadmon , been thinking about this one and i've had a breakthrough. The script placed in /lib/systemd/system-shutdown/ executes after the file system has went read only. This explains why calling the splashscreen.sh script works and my killall -s SIGTERM retroarch script doesn't. splashscreen.sh isn't trying to write to the SD card whereas killing the retroarch process does work but it can't write the hi-scores to SD cause the file system is now read only. I believe I have to make a service that will be called after pressing the button, but before the shutdown service starts and makes the file system read-only if that makes sense.

                            B jamrom2J 2 Replies Last reply Reply Quote 0
                            • B
                              barbudreadmon @james.milroy
                              last edited by

                              @james-milroy i think you are on the right track, maybe try asking on that github i linked ?

                              FBNeo developer - github - forum

                              1 Reply Last reply Reply Quote 0
                              • jamrom2J
                                jamrom2 @james.milroy
                                last edited by jamrom2

                                @james-milroy I don't know if that's the problem with Mame.

                                Years ago, which is around the time this version was available, you had to compile Mame with another file that would allow you to save high scores, then you needed a hiscore.dat file that would reference an NVRAM mame would create as the "save file". This was known as "hacking Mame" back then. The Mame Devs didn't like it because the goal of Mame is not just to play the games, but to preserve the ROMs as they were from the factory. They eventually altered Mame to prevent the hack from working.

                                I don't know if this version of Mame was compiled with that option active or if it can be. 2003 was around the time the hack was around, but back then it wasn't by year, it was still numbered. I don't know what version of Mame 2003plus is.

                                If it can be recompiled with the "hack" it should save the hiscores.

                                This vid helps explain what I mean.

                                1 Reply Last reply Reply Quote 0
                                • D
                                  Dodge62
                                  last edited by

                                  I banged my head over this for some time before coming up with a solution.

                                  The problem is that when you hit that power button, an interrupt is sent to the login daemon, telling it to shutdown the system. You can't interrupt that in any way, or replace it with a different operation as far as I can see.

                                  You can create a service with killall -s SIGTERM retroarch in its shutdown operation - but by then it's too late. Systemctl has already killed all user processes - including retroarch.

                                  So what I had to do was actually run retroarch as a service itself. That was systemctl left it for its own shutdown procedure. I'm fairly new services, so I don't claim this is the perfect solution but it works for me.

                                  This is based on "retropie" on a Raspberry Pi. If you're running some other Linux system it may or may not be helpful.

                                  First, we need to prevent retroarch from starting in the normal way. I edited /opt/retropie/configs/all/autostart.sh, commenting out the existing lines and adding in a call to the shell bash:

                                  bash
                                  #/opt/retropie/supplementary/runcommand/runcommand.sh 0 _SYS_ mame-libretro ~/RetroPie/roms/mame-libretro/robotron.zip
                                  #emulationstation #auto
                                  

                                  Next I created a new service by adding a file /etc/systemd/system/killmame.service containing

                                  [Unit]
                                  Description=A service start and stop MAME cleanly
                                  After=console-setup network-online.target multi-user.target
                                  
                                  [Service]
                                  User=pi
                                  ExecStart=/home/pi/bin/start.sh
                                  ExecStop=/home/pi/bin/killmame.sh
                                  Type=simple
                                  StandardInput=tty-force
                                  TTYVHangup=yes
                                  TTYPath=/dev/tty20
                                  TTYReset=yes
                                  SendSIGKILL=no
                                  KillMode=none
                                  
                                  [Install]
                                  WantedBy=multi-user.target
                                  

                                  Notes:

                                  • You'll need to create that as root (eg. sudo nano killmame.service)
                                  • killmame is a bad name for the service. It started off only intending to kill it, but morphed into a complete service - retroarch.service might be a better name
                                  • All the tty stuff is needed or retroarch won't run
                                  • The two scripts in ExecStart and ExecStop need to be created in the next step

                                  Now we create a directory /home/pi/bin and create the two scripts in the (can do this as the pi user):

                                  start.sh:

                                  #!/bin/bash
                                  cd /home/pi
                                  
                                  export TERM=linux
                                  export USER=pi
                                  
                                  chvt 20
                                  
                                  /opt/retropie/supplementary/runcommand/runcommand.sh 0 _SYS_ mame-libretro ~/RetroPie/roms/mame-libretro/robotron.zip &
                                  bash
                                  

                                  The command starting /opt/retropie is what I previously had in my autostart.sh. Obviously it's specific to my game, you will need to change it to whatever you had in your autostart.sh file.

                                  You MUST have the & character at the end, putting the command into background. Otherwise systemctl will kill it in the early steps of shutdown. I'm not sure why.

                                  killmame.sh:

                                  #!/bin/bash
                                  
                                  # echo checking for mame running ... > /home/pi/bin/killmame.log
                                  # ps -deafww | grep libretro | grep robotron >> /home/pi/bin/killmame.log
                                  
                                  killall -s SIGTERM retroarch
                                  
                                  echo shutting down MAME at `date` >> /home/pi/bin/killmame.log
                                  

                                  The commented-out lines 'echo' and 'ps' were for debugging - to see if my game was actually running when it came to being shut down.

                                  Finally we need to register and enable our new service:

                                  sudo systemctl daemon-reload
                                  sudo systemctl start killmame
                                  sudo systemctl enable killmame
                                  

                                  All those should complete without output. If the 'start' fails, you'll need to figure out why before continuing.

                                  If they all work, you can reboot. Your machine should first drop into a shell prompt, but then very soon after retroarch should take over. Hitting the kill switch should now shutdown retroarch cleanly, saving high scores.

                                  The only glitch I've found is that if you use <ESCAPE> to exit retroarch, you'll find lots of key presses on the shell window from your game controls. Usually they're harmless but it's just possible you might accidently issue some fatal commands. Probably removing the invocation of bash from autostart.sh woud solve that, but you might then not be able to get back into a shell after exiting with escape. I generally log in remotely using ssh, so that wouldn't worry me.

                                  I hope this helps someone as I spent hours trawling for a solution without finding one. It was only while explaining to my wife why it was impossible, that it occurred to me to actually run retroarch as a service itself.

                                  If someone is able to tidy this up into a cleaner solution I'd be very grateful.

                                  1 Reply Last reply Reply Quote 0
                                  • First post
                                    Last post

                                  Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                                  Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.