Boot using last opened .MRA file or a specific one

https://github.com/MiSTer-devel/Main_MiSTer/wiki

Moderators: Mug UK, Zorro 2, Greenious, spiny, Sorgelig, Moderator Team

angelotax
Retro freak
Retro freak
Posts: 11
Joined: Mon Dec 30, 2019 12:52 pm

Boot using last opened .MRA file or a specific one

Postby angelotax » Thu Jan 02, 2020 4:54 pm

Hi Guys,
I can't really thank this community enough for the incredibile project and passion you all put in it.
Finally, an authentic retrogaming experience is possible without having a hundred hardware systems or real Arcade PCBs at home.
So what i did, is to mod my arcade cab and now it runs on Mister and i couldn't be happier.
The implementation of the .mra files is a godsend in order to simplify the arcade experience, but on the other hand we lost the ability to boot to the last opened Arcade core.
Having a cab that automatically powers on and off at certain hours, that's not ideal, and having the Mister boot at the menu kinda ruins the authenticity of the experience a little bit.
What i'm asking is: there is , or there will / can possibly be, a way to make the Mister auto load a .mra file when it is turned on ?
Even the last loaded .mra file would be absolutely great.

Again thanks for letting me experience this, i'm infinitely grateful.
:cheers:

angelotax
Retro freak
Retro freak
Posts: 11
Joined: Mon Dec 30, 2019 12:52 pm

Re: Boot using last opened .MRA file or a specific one

Postby angelotax » Fri Jan 17, 2020 8:17 am

Hi guys,
I would really like to look into this code and try to implement this.
I would like to make the the .mra files autoboot directly when mister is powered on using the "boot to last core" function that is already inside the mister.ini file and already working perfectly.
This means allowing the "boot to last core" function to not only use the last .rbf files, but also the last .mra files opened to autoboot at mister startup.
Could someone kindly point me to the github page / pages / scripts where the code for "boot to last core" function is located, so i can look into it ?

Thanks
:cheers:
EDIT:
I guess that the extention that the script is looking into is defined by the script bootcore.cpp, is my assumption correct ?
I guess that the script is also looking into lastcore.dat to get the last booted core name.
Is something about .mra recorded there ?

bootcore.cpp

Code: Select all

bool isExactcoreName(char *path)
{
   char *spl = strrchr(path, '.');
   return (spl && !strcmp(spl, ".rbf"));
}

char *getcoreName(char *path)
{
   char *spl = strrchr(path, '.');
   if (spl && !strcmp(spl, ".rbf"))
   {
      *spl = '\0';
   }
   else
   {
      return NULL;
   }
   if ((spl = strrchr(path, '/')) != NULL)
   {
      path = spl + 1;
   }
   if ((spl = strrchr(path, '_')) != NULL)
   {
      *spl = 0;
   }

   return path;
}

char *getcoreExactName(char *path)
{
   char *spl;
   if ((spl = strrchr(path, '/')) != NULL)
   {
      path = spl + 1;
   }

   return path;
}

char *replaceStr(const char *str, const char *oldstr, const char *newstr)
{
   char *result;
   int i, cnt = 0;
   int newstrlen = strlen(newstr);
   int oldstrlen = strlen(oldstr);

   for (i = 0; str[i] != '\0'; i++)
   {
      if (strstr(&str[i], oldstr) == &str[i])
      {
         cnt++;
         i += oldstrlen - 1;
      }
   }

   result = new char[i + cnt * (newstrlen - oldstrlen) + 1];

   i = 0;
   while (*str)
   {
      if (strstr(str, oldstr) == str)
      {
         strcpy(&result[i], newstr);
         i += newstrlen;
         str += oldstrlen;
      }
      else
         result[i++] = *str++;
   }

   result[i] = '\0';
   return result;
}

char* loadLastcore()
{
   char full_path[2100];
   char path[256] = { CONFIG_DIR"/" };
   strcat(path, "lastcore.dat");
   sprintf(full_path, "%s/%s", getRootDir(), path);
   FILE *fd = fopen(full_path, "r");
   if (!fd)
   {      
      return NULL;
   }
   fseek(fd, 0L, SEEK_END);
   long size = ftell(fd);

   fseek(fd, 0L, SEEK_SET);
   char *lastcore = new char[size + 1];

   int ret = fread(lastcore, sizeof(char), size, fd);
   fclose(fd);
   if (ret == size)
   {
      return lastcore;
   }
   delete[] lastcore;
   return NULL;

}

char *findCore(const char *name, char *coreName, int indent)
{
   char *spl;
   DIR *dir;
   struct dirent *entry;

   if (!(dir = opendir(name)))
   {
      return NULL;
   }


   char *indir;
   char* path = new char[256];
   while ((entry = readdir(dir)) != NULL) {
      if (entry->d_type == DT_DIR) {
         if (entry->d_name[0] != '_')
            continue;
         snprintf(path, 256, "%s/%s", name, entry->d_name);
         indir = findCore(path, coreName, indent + 2);
         if (indir != NULL)
         {
            closedir(dir);
            delete[] path;
            return indir;
         }
      }
      else {
         snprintf(path, 256, "%s/%s", name, entry->d_name);
         if (strstr(path, coreName) != NULL) {
            spl = strrchr(path, '.');
            if (spl && !strcmp(spl, ".rbf"))
            {
               closedir(dir);            
               return path;
            }
         }
      }
   }

zakk4223
Retro freak
Retro freak
Posts: 13
Joined: Thu Sep 12, 2019 11:31 pm

Re: Boot using last opened .MRA file or a specific one

Postby zakk4223 » Fri Jan 17, 2020 1:44 pm

Most of it is in bootcore.cpp, but there is a bit in menu.cpp that implements the countdown/delay and loads the RBF when that is done.

Off the top of my head:

You'll need to modify it to also store if the last booted core is an MRA or an RBF, since they are loaded differently. Somewhere in bootcore.cpp you'll also have to modify a function to allow both rbf and mra files to be written as the autoboot core (I believe it filters on *.rbf).

There's a function that searches for the RBF based on what is written to the lastcore config file. It assumes RBF only so that'll need modification to be aware of MRA and RBF. Keep in mind it's perfectly ok for there to be both a core and MRA with the same 'base' name so filter accordingly based on lastcore config.

Once all that is taken care of you need to modify the (two?) places where it loads the RBF to also allow it to load MRAs. One is in bootcore.cpp and is the case where the timeout is set to zero, and the other is in menu.cpp where the timer expires. Look for fpga_load_rbf()

I don't remember what the MRA loading function is called, but you can probably work backwards from romutils.cpp pretty easily.

angelotax
Retro freak
Retro freak
Posts: 11
Joined: Mon Dec 30, 2019 12:52 pm

Re: Boot using last opened .MRA file or a specific one

Postby angelotax » Fri Jan 17, 2020 2:30 pm

Thank you very mutch for the heads up.
I'm not a coder, so i'll try my best to figure and isolate the lines of code and scripts where the function is located, and quote them here.
Hopefully someone will keep looking at this and trow me some hints.

angelotax
Retro freak
Retro freak
Posts: 11
Joined: Mon Dec 30, 2019 12:52 pm

Re: Boot using last opened .MRA file or a specific one

Postby angelotax » Fri Jan 17, 2020 2:50 pm

zakk4223 wrote:You'll need to modify it to also store if the last booted core is an MRA or an RBF, since they are loaded differently. Somewhere in bootcore.cpp you'll also have to modify a function to allow both rbf and mra files to be written as the autoboot core (I believe it filters on *.rbf).


Code: Select all

bool isExactcoreName(char *path)
{
   char *spl = strrchr(path, '.');
   return (spl && !strcmp(spl, ".rbf"));
}

char *getcoreName(char *path)
{
   char *spl = strrchr(path, '.');
   if (spl && !strcmp(spl, ".rbf"))
   {
      *spl = '\0';
   }
   else
   {
   

Could this be it ?
Guess this defines a path that is '.' ?
and returns these variables spl and !strcmp (wich probably are defined somewere and represent the core name)?
and in this case ".rbf" defines/filters the extension that the corename(defined above) has ?
I'm really guessing here.
Hope to get going one litte piece at a time.


Return to “MiSTer”

Who is online

Users browsing this forum: No registered users and 14 guests