src/emu/romload.c
| r10024 | r10025 | |
| 76 | 76 | |
| 77 | 77 | static void rom_exit(running_machine &machine); |
| 78 | 78 | |
| 79 | /*************************************************************************** |
| 80 | HELPERS (also used by devimage.c) |
| 81 | ***************************************************************************/ |
| 79 | 82 | |
| 83 | file_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 | } |
| 80 | 97 | |
| 98 | return FILERR_NOT_FOUND; |
| 99 | } |
| 100 | |
| 101 | file_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 | |
| 81 | 115 | /*************************************************************************** |
| 82 | 116 | HARD DISK HANDLING |
| 83 | 117 | ***************************************************************************/ |
| r10024 | r10025 | |
| 619 | 653 | crc = (crcbytes[0] << 24) | (crcbytes[1] << 16) | (crcbytes[2] << 8) | crcbytes[3]; |
| 620 | 654 | |
| 621 | 655 | /* 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. */ |
| 623 | 657 | romdata->file = NULL; |
| 624 | 658 | for (drv = romdata->machine->gamedrv; romdata->file == NULL && drv != NULL; drv = driver_get_clone(drv)) |
| 625 | 659 | 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); |
| 633 | 661 | |
| 634 | 662 | /* if the region is load by name, load the ROM from there */ |
| 635 | 663 | if (romdata->file == NULL && regiontag != NULL) |
| 636 | 664 | { |
| 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); |
| 642 | 683 | } |
| 643 | 684 | |
| 644 | 685 | /* update counters */ |
| r10024 | r10025 | |
| 949 | 990 | up the parent and loading by checksum |
| 950 | 991 | -------------------------------------------------*/ |
| 951 | 992 | |
| 952 | | chd_error open_disk_image(const game_driver *gamedrv, const rom_entry *romp, mame_file **image_file, chd_file **image_chd,const char *locationtag) |
| 993 | chd_error open_disk_image(const game_driver *gamedrv, const rom_entry *romp, mame_file **image_file, chd_file **image_chd, const char *locationtag) |
| 953 | 994 | { |
| 954 | 995 | return open_disk_image_options(mame_options(), gamedrv, romp, image_file, image_chd, locationtag); |
| 955 | 996 | } |
| r10024 | r10025 | |
| 961 | 1002 | checksum |
| 962 | 1003 | -------------------------------------------------*/ |
| 963 | 1004 | |
| 964 | | chd_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) |
| 1005 | chd_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) |
| 965 | 1006 | { |
| 966 | 1007 | const game_driver *drv, *searchdrv; |
| 967 | 1008 | const rom_entry *region, *rom; |
| r10024 | r10025 | |
| 975 | 1016 | /* attempt to open the properly named file, scanning up through parent directories */ |
| 976 | 1017 | filerr = FILERR_NOT_FOUND; |
| 977 | 1018 | 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); |
| 982 | 1020 | |
| 983 | 1021 | 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); |
| 988 | 1023 | |
| 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); |
| 994 | 1026 | |
| 995 | 1027 | /* did the file open succeed? */ |
| 996 | 1028 | if (filerr == FILERR_NONE) |
| r10024 | r10025 | |
| 1024 | 1056 | /* attempt to open the properly named file, scanning up through parent directories */ |
| 1025 | 1057 | filerr = FILERR_NOT_FOUND; |
| 1026 | 1058 | 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); |
| 1031 | 1060 | |
| 1032 | 1061 | 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); |
| 1037 | 1063 | |
| 1038 | 1064 | /* did the file open succeed? */ |
| 1039 | 1065 | if (filerr == FILERR_NONE) |
| r10024 | r10025 | |
| 1224 | 1250 | |
| 1225 | 1251 | |
| 1226 | 1252 | /*------------------------------------------------- |
| 1253 | software_get_clone - retrive name string of the |
| 1254 | parent software, if any |
| 1255 | -------------------------------------------------*/ |
| 1256 | |
| 1257 | const 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 | /*------------------------------------------------- |
| 1227 | 1271 | load_software_part_region - load a software part |
| 1228 | 1272 | |
| 1229 | 1273 | This is used by MESS when loading a piece of |
| r10024 | r10025 | |
| 1234 | 1278 | |
| 1235 | 1279 | void load_software_part_region(device_t *device, char *swlist, char *swname, rom_entry *start_region) |
| 1236 | 1280 | { |
| 1237 | | astring locationtag(swlist, PATH_SEPARATOR, swname); |
| 1281 | astring locationtag, breakstr("%"); |
| 1238 | 1282 | rom_load_data *romdata = device->machine->romload_data; |
| 1239 | 1283 | const rom_entry *region; |
| 1240 | 1284 | astring regiontag; |
| 1241 | 1285 | |
| 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 | |
| 1242 | 1313 | /* Make sure we are passed a device */ |
| 1243 | | assert(device!=NULL); |
| 1314 | assert(device != NULL); |
| 1244 | 1315 | |
| 1245 | 1316 | romdata->errorstring.reset(); |
| 1246 | 1317 | |
src/emu/devimage.c
| r10024 | r10025 | |
| 300 | 300 | -------------------------------------------------*/ |
| 301 | 301 | bool legacy_image_device_base::load_software(char *swlist, char *swname, rom_entry *start) |
| 302 | 302 | { |
| 303 | astring locationtag, breakstr("%"); |
| 303 | 304 | const rom_entry *region; |
| 304 | 305 | astring regiontag; |
| 305 | 306 | bool retVal = FALSE; |
| r10024 | r10025 | |
| 320 | 321 | if (has_crc) |
| 321 | 322 | crc = (crcbytes[0] << 24) | (crcbytes[1] << 16) | (crcbytes[2] << 8) | crcbytes[3]; |
| 322 | 323 | |
| 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); |
| 329 | 328 | if (filerr == FILERR_NONE) |
| 330 | 329 | { |
| 331 | 330 | m_file = mame_core_file(m_mame_file); |
| 332 | 331 | retVal = TRUE; |
| 333 | 332 | } |
| 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 | |
| 334 | 382 | break; // load first item for start |
| 335 | 383 | } |
| 336 | 384 | romp++; /* something else; skip */ |