Retrode Community Forum

General Category => General Discussion => Topic started by: mistermorcus on 11/Dec/2019 05:23:44 AM

Title: Retrode - Windows Batch Launcher for Steam
Post by: mistermorcus on 11/Dec/2019 05:23:44 AM
This first part of the post may get a little wordy, so anyone looking for the goods should skip the first paragraph.

I had been hoping over the years someone would release something that made the Retrode into a retro game player.  The Seedi Windows beta project kind of did this but it was not compatible with the plugin adapters.  My project started out as something for myself, but I realized other people out there may want something similar.  I wanted to be able to launch the Retrode with any of my available plugins using Steam.  Additionally, I wanted to have my save files from the cartridge to automatically be loaded when I launch an emulator and sync to back to the cartridge.  My life has gotten busier with my daughter just being born, which means that I have less time to play games in my game room, so I am restricted to my living room where my PC running Steam is located and not abandon the family.  But this way, when I do have time I can just take my cartridges and still play them on my consoles, which saves a lot of time when it just works.

First things first:  If you choose to try and make any of these scripts work, please know that I AM NOT RESPONSIBLE FOR LOST DATA.  I would strongly recommend making a backup of anything you decide to test with prior to using any of the scripts here.

It is also important to know that you will have to modify these scripts to work with your setup, I would not consider this a project for a novice. Additionally you will also have to setup the emulators and folder structures on your system.  I tried to simplify it as much as I could but hopefully someone smarter than me could come along with a better solution than my scripts!!

I know most people may not have a use for this since a lot of people are using a Raspberry Pi or something similar to launch emulators these days, but I still use a Windows PC and have more experience scripting as a Windows user.  The batch file that I have attached is written using basic Windows batch file commands that I have gathered from various places. I am definitely not an expert but I was able to cobble this all together to make it work for my situation.

I have modified this a few times but I will describe the general work flow of what this batch file does.

1.   Determines the Drive Letter of the Retrode by the volume name
   a.   This is important because I would not want to check for random drive letters and work in the wrong directories.

2.   Make a New Permanent Save backup with timestamp every time the Retrode is launched.
   a.   This may make your Save directory that you choose a little cluttered, but I decided that making extra copies of precious save data was more important in this case.

3.   Make a Permanent backup of the Rom if it does not already exist

4.   Launch Emulator for the given Rom extension
   a.   This version of my script does not handle Turbografx titles since I do not have a plugin for it, but you could easily add it. I just have not tested it in Mednafen.

5.   Mednafen
   a.   I have two instances on my personal setup for Mednafen since I wanted to have a version that saved the save files to the Retrode, and a version that did not. The reason I needed this was because the Retrode does not currently transfer the saves for GBA games.  In this case I wanted to be able to launch and play GBA games and save the game locally on my PC.  The other plugins will launch and handle the saves just fine, however you have to modify the config file in mednafen to save the SRM file in the same directory as the launched rom file.
   b.   Something else to note, is that when I am done playing a game, I save yet another SRM backup to the save directory. I do this for two reasons
     i.   I want to make sure I have my latest save file backed up
     ii.   If I decided I wanted to play this off of my cartridge, I have a save file to use for it. This save file is in the Save directory and does not have a timestamp on it.

6.   N64 Save Handling
   a.   This is the most complicated aspect of this. The other save files are natively supported in a given format in Mednafen, but that is not the case for the N64!! For Mempack and EEP save files no conversion is necessary, however due to the way Mempack files are available in the Retrode and the way that emulators use them, I have to account for the file names and handle them differently.  SRA and FLA files have to be save swapped in order to use them in an emulator.  The process involves copying the file to your local save directory, save swapping them and then renaming them.
   b.   The other aspect to this was that I needed to find an N64 emulator with high enough compatibility to make this worthwhile, and to also be able to accept command line arguments.  I found the last free version of Mupen64Plus-GUI which has worked really well for me.  The issue however is that the save files that it outputs use the standard Rom naming conventions.  Fortunately this can be overwritten in the ini file.  Provided that you know what all of the Rom names are for a given N64 game, you can change each rom version in the INI file to use your save file name which makes this process much easier.  It would be nice if we had a full list of these filenames that the Retrode produces, but I am not aware of one.
   c.   Since we have to copy the save file to the PC to work in the emaultor, we have to find the most recent save file modified by the emulator.  If however that save file is a mempack file, I found that Mupen64plus-gui saves it as a 128kb file, which will not fit on the retrode. In this case I use a program called Trunc.exe to chop the file down at exactly 32kb which theoretically was just empty space.  If it was an fla or sra file we have to save swap it yet again.  Then the files get copied back to the Retrode.

I converted this batch file to an exe with a Bat to Exe converter and launch it through Steam.  If you use Mednafen the way I do, then I would recommend using a gamepad in Steam to set your controls, since it binds keys to the device that you use making it more difficult to swap controllers. If you use a Steam profile then you can swap gamepads on the fly.  It is also helpful to have a separate profile in the Mupen64Plus-GUI this way since it natively only has support for one profile, and I like to have separate profiles for FPS games. 

I attached my batch file as a txt file just in case antivirus tried to quarantine it, so just rename the extension back to .bat.  I am not sure what the rules are on providing any of the tools or emulators that I am using. They are all free versions so I might be able to link to them if permitted. The saveswap is a python program recommended in another post here in the N64 save topic. Trunc is a program that at this point am not sure where I found it.

I realize this isn’t a full guide since it requires you to learn and setup the command line emulators yourself, but I can hopefully answer some of those questions if this post actually generates any interest.  Just wanting to share something back to the community and would like to see more projects like this in the future.

*EDIT* By happenstance I just tried to launch an n64 game and realized it did not work, but still copied a blank file as a permanent save backup. I have fixed this in the updated version to check for a valid rom extension otherwise it will now exit.  In my case it failed because I had recently updated my Retrode firmware and the file extension changed to the .v64 format and I was using .n64.  This issue would also have happened if the retrode was unable to read your cartridge.
Title: Re: Retrode - Windows Batch Launcher for Steam
Post by: Matthias_H on 13/Dec/2019 01:02:00 PM
Nice! For even more convenience, it would be awesome to have some endless loop running in the background (launched at system start) that watches the Retrode, and everytime a ROM file pops up it launches the emulator...
Title: Re: Retrode - Windows Batch Launcher for Steam
Post by: mistermorcus on 13/Dec/2019 02:42:33 PM
A windows rom scanning service would be fantastic. At first I did try to make that work using Task Scheduler and event triggers to detect certain hardware events from the Retrode itself, which did work, but had side effects that I would have needed to figure out.  For instance, every time the computer restarted the game would automatically start playing.
Title: Re: Retrode - Windows Batch Launcher for Steam
Post by: Matthias_H on 13/Dec/2019 07:11:27 PM
Which is exactly what a console should do, no? :-D