Previous 15994 Revisions Next

r10025 Thursday 13th January, 2011 at 17:09:45 UTC by Fabio Priuli
Added support for split set to softlist
[src/emu]devimage.c romload.c romload.h

src/emu/romload.c
r10024r10025
7676
7777static void rom_exit(running_machine &machine);
7878
79/***************************************************************************
80    HELPERS (also used by devimage.c)
81 ***************************************************************************/
7982
83file_error common_process_file_options(core_options *options, const char *location, const char *ext, const rom_entry *romp, mame_file **image_file)
84{
85   if (location != NULL)
86   {
87      astring fname(location, PATH_SEPARATOR, ROM_GETNAME(romp));
88      fname.cat(ext);
89      return mame_fopen_options(options, SEARCHPATH_IMAGE, fname, OPEN_FLAG_READ, image_file);
90   }
91   else
92   {
93      astring fname(ROM_GETNAME(romp));
94      fname.cat(ext);
95      return mame_fopen_options(options, SEARCHPATH_IMAGE, fname, OPEN_FLAG_READ, image_file);
96   }
8097
98   return FILERR_NOT_FOUND;
99}
100
101file_error common_process_file(const char *location, bool has_crc, UINT32 crc, const rom_entry *romp, mame_file **image_file)
102{
103   file_error filerr;
104   astring fname(location, PATH_SEPARATOR, ROM_GETNAME(romp));
105
106   if (has_crc)
107      filerr = mame_fopen_crc(SEARCHPATH_ROM, fname, crc, OPEN_FLAG_READ, image_file);
108   else
109      filerr = mame_fopen(SEARCHPATH_ROM, fname, OPEN_FLAG_READ, image_file);
110
111   return filerr;
112}
113
114
81115/***************************************************************************
82116    HARD DISK HANDLING
83117***************************************************************************/
r10024r10025
619653      crc = (crcbytes[0] << 24) | (crcbytes[1] << 16) | (crcbytes[2] << 8) | crcbytes[3];
620654
621655   /* attempt reading up the chain through the parents. It automatically also
622       attempts any kind of load by checksum supported by the archives. */
656     attempts any kind of load by checksum supported by the archives. */
623657   romdata->file = NULL;
624658   for (drv = romdata->machine->gamedrv; romdata->file == NULL && drv != NULL; drv = driver_get_clone(drv))
625659      if (drv->name != NULL && *drv->name != 0)
626      {
627         astring fname(drv->name, PATH_SEPARATOR, ROM_GETNAME(romp));
628         if (has_crc)
629            filerr = mame_fopen_crc(SEARCHPATH_ROM, fname, crc, OPEN_FLAG_READ, &romdata->file);
630         else
631            filerr = mame_fopen(SEARCHPATH_ROM, fname, OPEN_FLAG_READ, &romdata->file);
632      }
660         filerr = common_process_file(drv->name, has_crc, crc, romp, &romdata->file);
633661
634662   /* if the region is load by name, load the ROM from there */
635663   if (romdata->file == NULL && regiontag != NULL)
636664   {
637      astring fname(regiontag, PATH_SEPARATOR, ROM_GETNAME(romp));
638      if (has_crc)
639         filerr = mame_fopen_crc(SEARCHPATH_ROM, fname, crc, OPEN_FLAG_READ, &romdata->file);
640      else
641         filerr = mame_fopen(SEARCHPATH_ROM, fname, OPEN_FLAG_READ, &romdata->file);
665      // check if locationtag actually contains two locations separated by '%'
666      // (i.e. check if we are dealing with a clone in softwarelist)
667      astring tag1(regiontag), tag2;
668      int separator = tag1.chr(0, '%');
669      if (separator != -1)
670      {
671         // we are loading a clone through softlists, split the second location
672         tag2.cpysubstr(tag1, separator + 1, tag1.len() - separator + 1);
673         tag1.del(separator, tag1.len() - separator);
674      }
675
676      if (tag2.chr(0, '%') != -1)
677         fatalerror("More than two regiontags concatenated!\n");
678
679      // try to load from the available location(s)
680      filerr = common_process_file(tag1.cstr(), has_crc, crc, romp, &romdata->file);
681      if ((romdata->file == NULL) && (tag2.cstr() != NULL))
682         filerr = common_process_file(tag2.cstr(), has_crc, crc, romp, &romdata->file);
642683   }
643684
644685   /* update counters */
r10024r10025
949990    up the parent and loading by checksum
950991-------------------------------------------------*/
951992
952chd_error open_disk_image(const game_driver *gamedrv, const rom_entry *romp, mame_file **image_file, chd_file **image_chd,const char *locationtag)
993chd_error open_disk_image(const game_driver *gamedrv, const rom_entry *romp, mame_file **image_file, chd_file **image_chd, const char *locationtag)
953994{
954995   return open_disk_image_options(mame_options(), gamedrv, romp, image_file, image_chd, locationtag);
955996}
r10024r10025
9611002    checksum
9621003-------------------------------------------------*/
9631004
964chd_error open_disk_image_options(core_options *options, const game_driver *gamedrv, const rom_entry *romp, mame_file **image_file, chd_file **image_chd,const char *locationtag)
1005chd_error open_disk_image_options(core_options *options, const game_driver *gamedrv, const rom_entry *romp, mame_file **image_file, chd_file **image_chd, const char *locationtag)
9651006{
9661007   const game_driver *drv, *searchdrv;
9671008   const rom_entry *region, *rom;
r10024r10025
9751016   /* attempt to open the properly named file, scanning up through parent directories */
9761017   filerr = FILERR_NOT_FOUND;
9771018   for (searchdrv = gamedrv; searchdrv != NULL && filerr != FILERR_NONE; searchdrv = driver_get_clone(searchdrv))
978   {
979      astring fname(searchdrv->name, PATH_SEPARATOR, ROM_GETNAME(romp), ".chd");
980      filerr = mame_fopen_options(options, SEARCHPATH_IMAGE, fname, OPEN_FLAG_READ, image_file);
981   }
1019      filerr = common_process_file_options(options, searchdrv->name, ".chd", romp, image_file);
9821020
9831021   if (filerr != FILERR_NONE)
984   {
985      astring fname(ROM_GETNAME(romp), ".chd");
986      filerr = mame_fopen_options(options, SEARCHPATH_IMAGE, fname, OPEN_FLAG_READ, image_file);
987   }
1022      filerr = common_process_file_options(options, NULL, ".chd", romp, image_file);
9881023
989   if (filerr != FILERR_NONE && locationtag!=NULL)
990   {
991      astring fname(locationtag, PATH_SEPARATOR, ROM_GETNAME(romp), ".chd");
992      filerr = mame_fopen_options(options, SEARCHPATH_IMAGE, fname, OPEN_FLAG_READ, image_file);
993   }
1024   if (filerr != FILERR_NONE && locationtag != NULL)
1025      filerr = common_process_file_options(options, locationtag, ".chd", romp, image_file);
9941026
9951027   /* did the file open succeed? */
9961028   if (filerr == FILERR_NONE)
r10024r10025
10241056                     /* attempt to open the properly named file, scanning up through parent directories */
10251057                     filerr = FILERR_NOT_FOUND;
10261058                     for (searchdrv = drv; searchdrv != NULL && filerr != FILERR_NONE; searchdrv = driver_get_clone(searchdrv))
1027                     {
1028                        astring fname(searchdrv->name, PATH_SEPARATOR, ROM_GETNAME(rom), ".chd");
1029                        filerr = mame_fopen_options(options, SEARCHPATH_IMAGE, fname, OPEN_FLAG_READ, image_file);
1030                     }
1059                        filerr = common_process_file_options(options, searchdrv->name, ".chd", rom, image_file);
10311060
10321061                     if (filerr != FILERR_NONE)
1033                     {
1034                        astring fname(ROM_GETNAME(rom), ".chd");
1035                        filerr = mame_fopen_options(options, SEARCHPATH_IMAGE, fname, OPEN_FLAG_READ, image_file);
1036                     }
1062                        filerr = common_process_file_options(options, NULL, ".chd", rom, image_file);
10371063
10381064                     /* did the file open succeed? */
10391065                     if (filerr == FILERR_NONE)
r10024r10025
12241250
12251251
12261252/*-------------------------------------------------
1253    software_get_clone - retrive name string of the
1254    parent software, if any
1255 -------------------------------------------------*/
1256
1257const char *software_get_clone(char *swlist, const char *swname)
1258{
1259   software_list *software_list_ptr = software_list_open(mame_options(), swlist, FALSE, NULL);
1260
1261   if (software_list_ptr)
1262   {
1263      software_info *tmp = software_list_find(software_list_ptr, swname, NULL);
1264      return tmp->parentname;
1265   }
1266
1267   return NULL;
1268}
1269
1270/*-------------------------------------------------
12271271    load_software_part_region - load a software part
12281272
12291273    This is used by MESS when loading a piece of
r10024r10025
12341278
12351279void load_software_part_region(device_t *device, char *swlist, char *swname, rom_entry *start_region)
12361280{
1237   astring locationtag(swlist, PATH_SEPARATOR, swname);
1281   astring locationtag, breakstr("%");
12381282   rom_load_data *romdata = device->machine->romload_data;
12391283   const rom_entry *region;
12401284   astring regiontag;
12411285
1286   // attempt reading up the chain through the parents and create a locationtag astring in the format
1287   // " swlist PATHSEPARATOR clonename % swlist PATHSEPARATOR parentname "
1288   // open_rom_file contains the code to split the two paths and to separately try to load roms from there
1289
1290   software_list *software_list_ptr = software_list_open(mame_options(), swlist, FALSE, NULL);
1291   if (software_list_ptr)
1292   {
1293      for (software_info *swinfo = software_list_find(software_list_ptr, swname, NULL); swinfo != NULL; )
1294      {
1295         if (swinfo != NULL)
1296         {
1297            astring tmp(swlist, PATH_SEPARATOR, swinfo->shortname);
1298            locationtag.cat(tmp);
1299            locationtag.cat(breakstr);
1300            // printf("%s\n", locationtag.cstr());
1301         }
1302         const char *parentname = software_get_clone(swlist, swinfo->shortname);
1303         if (parentname != NULL)
1304            swinfo = software_list_find(software_list_ptr, parentname, NULL);
1305         else
1306            swinfo = NULL;
1307      }
1308      // strip the final '%'
1309      locationtag.del(locationtag.len() - 1, 1);
1310      software_list_close(software_list_ptr);
1311   }
1312
12421313   /* Make sure we are passed a device */
1243   assert(device!=NULL);
1314   assert(device != NULL);
12441315
12451316   romdata->errorstring.reset();
12461317
src/emu/romload.h
r10024r10025
278278int rom_load_warnings(running_machine *machine);
279279
280280
281/* ----- Helpers ----- */
281282
283file_error common_process_file_options(core_options *options, const char *location, const char *ext, const rom_entry *romp, mame_file **image_file);
284file_error common_process_file(const char *location, bool has_crc, UINT32 crc, const rom_entry *romp, mame_file **image_file);
285const char *software_get_clone(char *swlist, const char *swname);
286
282287/* ----- ROM iteration ----- */
283288
284289/* return pointer to first ROM source */
src/emu/devimage.c
r10024r10025
300300-------------------------------------------------*/
301301bool legacy_image_device_base::load_software(char *swlist, char *swname, rom_entry *start)
302302{
303   astring locationtag, breakstr("%");
303304   const rom_entry *region;
304305   astring regiontag;
305306   bool retVal = FALSE;
r10024r10025
320321            if (has_crc)
321322               crc = (crcbytes[0] << 24) | (crcbytes[1] << 16) | (crcbytes[2] << 8) | crcbytes[3];
322323
323            astring fname(swlist, PATH_SEPARATOR, swname, PATH_SEPARATOR, ROM_GETNAME(romp));
324            if (has_crc)
325               filerr = mame_fopen_crc(SEARCHPATH_ROM, fname, crc, OPEN_FLAG_READ, &m_mame_file);
326            else
327               filerr = mame_fopen(SEARCHPATH_ROM, fname, OPEN_FLAG_READ, &m_mame_file);
328
324#if 1
325            astring tmp(swlist, PATH_SEPARATOR, swname);
326            locationtag.cpy(tmp);
327            filerr = common_process_file(locationtag.cstr(), has_crc, crc, romp, &m_mame_file);
329328            if (filerr == FILERR_NONE)
330329            {
331330               m_file = mame_core_file(m_mame_file);
332331               retVal = TRUE;
333332            }
333
334#else
335            // attempt reading up the chain through the parents and create a locationtag astring in the format
336            // " swlist PATHSEPARATOR clonename % swlist PATHSEPARATOR parentname "
337            // below, we have the code to split the two paths and to separately try to load roms from there
338
339            software_list *software_list_ptr = software_list_open(mame_options(), swlist, FALSE, NULL);
340            if (software_list_ptr)
341            {
342               for (software_info *swinfo = software_list_find(software_list_ptr, swname, NULL); swinfo != NULL; )
343               {
344                  if (swinfo != NULL)
345                  {
346                     astring tmp(swlist, PATH_SEPARATOR, swinfo->shortname);
347                     locationtag.cat(tmp);
348                     locationtag.cat(breakstr);
349                     // printf("%s\n", locationtag.cstr());
350                  }
351                  const char *parentname = software_get_clone(swlist, swinfo->shortname);
352                  if (parentname != NULL)
353                     swinfo = software_list_find(software_list_ptr, parentname, NULL);
354                  else
355                     swinfo = NULL;
356               }
357               // strip the final '%'
358               locationtag.del(locationtag.len() - 1, 1);
359               software_list_close(software_list_ptr);
360            }
361
362            // check if locationtag actually contains two locations separated by '%'
363            // (i.e. check if we are dealing with a clone in softwarelist)
364            astring tag1(locationtag), tag2;
365            int separator = tag1.chr(0, '%');
366            if (separator != -1)
367            {
368               // we are loading a clone through softlists, split the second location
369               tag2.cpysubstr(tag1, separator + 1, tag1.len() - separator + 1);
370               tag1.del(separator, tag1.len() - separator);
371            }
372
373            if (tag2.chr(0, '%') != -1)
374               fatalerror("More than two regiontags concatenated!\n");
375
376            // try to load from the available location(s)
377            filerr = common_process_file(tag1.cstr(), has_crc, crc, romp, &m_mame_file);
378            if ((romdata->file == NULL) && (tag2.cstr() != NULL))
379               filerr = common_process_file(tag2.cstr(), has_crc, crc, romp, &m_mame_file);
380#endif
381
334382            break; // load first item for start
335383         }
336384         romp++;   /* something else; skip */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team