static void process_rom_entries(romload_private *romdata, const char *regiontag, const rom_entry *parent_region, const rom_entry *romp, device_t *device, bool from_list) { UINT32 lastflags = 0; /* loop until we hit the end of this region */ while (!ROMENTRY_ISREGIONEND(romp)) { /* if this is a continue entry, it's invalid */ if (ROMENTRY_ISCONTINUE(romp)) fatalerror("Error in RomModule definition: ROM_CONTINUE not preceded by ROM_LOAD\n"); /* if this is an ignore entry, it's invalid */ if (ROMENTRY_ISIGNORE(romp)) fatalerror("Error in RomModule definition: ROM_IGNORE not preceded by ROM_LOAD\n"); /* if this is a reload entry, it's invalid */ if (ROMENTRY_ISRELOAD(romp)) fatalerror("Error in RomModule definition: ROM_RELOAD not preceded by ROM_LOAD\n"); /* handle fills */ if (ROMENTRY_ISFILL(romp)) fill_rom_data(romdata, romp++); /* handle copies */ else if (ROMENTRY_ISCOPY(romp)) copy_rom_data(romdata, romp++); /* handle files */ else if (ROMENTRY_ISFILE(romp)) { int irrelevantbios = (ROM_GETBIOSFLAGS(romp) != 0 && ROM_GETBIOSFLAGS(romp) != device->system_bios()); const rom_entry *baserom = romp; int explength = 0; /* open the file if it is a non-BIOS or matches the current BIOS */ LOG(("Opening ROM file: %s\n", ROM_GETNAME(romp))); astring tried_file_names; if (!irrelevantbios && !open_rom_file(romdata, regiontag, romp, tried_file_names, from_list)) handle_missing_file(romdata, romp, tried_file_names, CHDERR_NONE); /* loop until we run out of reloads */ do { /* loop until we run out of continues/ignores */ do { rom_entry modified_romp = *romp++; //int readresult; /* handle flag inheritance */ if (!ROM_INHERITSFLAGS(&modified_romp)) lastflags = modified_romp._flags; else modified_romp._flags = (modified_romp._flags & ~ROM_INHERITEDFLAGS) | lastflags; explength += ROM_GETLENGTH(&modified_romp); /* attempt to read using the modified entry */ if (!ROMENTRY_ISIGNORE(&modified_romp) && !irrelevantbios) /*readresult = */read_rom_data(romdata, parent_region, &modified_romp); } while (ROMENTRY_ISCONTINUE(romp) || ROMENTRY_ISIGNORE(romp)); /* if this was the first use of this file, verify the length and CRC */ if (baserom) { LOG(("Verifying length (%X) and checksums\n", explength)); verify_length_and_hash(romdata, ROM_GETNAME(baserom), explength, hash_collection(ROM_GETHASHDATA(baserom))); LOG(("Verify finished\n")); } /* reseek to the start and clear the baserom so we don't reverify */ if (romdata->file != NULL) romdata->file->seek(0, SEEK_SET); baserom = NULL; explength = 0; } while (ROMENTRY_ISRELOAD(romp)); /* close the file */ if (romdata->file != NULL) { LOG(("Closing ROM file\n")); global_free(romdata->file); romdata->file = NULL; } } else { romp++; /* something else; skip */ } } }
void rom_load_manager::process_disk_entries(const char *regiontag, const rom_entry *parent_region, const rom_entry *romp, const char *locationtag) { /* loop until we hit the end of this region */ for ( ; !ROMENTRY_ISREGIONEND(romp); romp++) { /* handle files */ if (ROMENTRY_ISFILE(romp)) { auto chd = std::make_unique<open_chd>(regiontag); hash_collection hashes(ROM_GETHASHDATA(romp)); chd_error err; /* make the filename of the source */ std::string filename = std::string(ROM_GETNAME(romp)).append(".chd"); /* first open the source drive */ LOG(("Opening disk image: %s\n", filename.c_str())); err = chd_error(open_disk_image(machine().options(), &machine().system(), romp, chd->orig_chd(), locationtag)); if (err != CHDERR_NONE) { handle_missing_file(romp, std::string(), err); chd = nullptr; continue; } /* get the header and extract the SHA1 */ hash_collection acthashes; acthashes.add_sha1(chd->orig_chd().sha1()); /* verify the hash */ if (hashes != acthashes) { strcatprintf(m_errorstring, "%s WRONG CHECKSUMS:\n", filename.c_str()); dump_wrong_and_correct_checksums(hashes, acthashes); m_warnings++; } else if (hashes.flag(hash_collection::FLAG_BAD_DUMP)) { strcatprintf(m_errorstring, "%s CHD NEEDS REDUMP\n", filename.c_str()); m_knownbad++; } /* if not read-only, make the diff file */ if (!DISK_ISREADONLY(romp)) { /* try to open or create the diff */ err = open_disk_diff(machine().options(), romp, chd->orig_chd(), chd->diff_chd()); if (err != CHDERR_NONE) { strcatprintf(m_errorstring, "%s DIFF CHD ERROR: %s\n", filename.c_str(), chd_file::error_string(err)); m_errors++; chd = nullptr; continue; } } /* we're okay, add to the list of disks */ LOG(("Assigning to handle %d\n", DISK_GETINDEX(romp))); m_chd_list.push_back(std::move(chd)); } } }
static void process_disk_entries(romload_private *romdata, const char *regiontag, const rom_entry *parent_region, const rom_entry *romp, const char *locationtag) { /* loop until we hit the end of this region */ for ( ; !ROMENTRY_ISREGIONEND(romp); romp++) { /* handle files */ if (ROMENTRY_ISFILE(romp)) { open_chd *chd = global_alloc(open_chd(regiontag)); hash_collection hashes(ROM_GETHASHDATA(romp)); chd_error err; /* make the filename of the source */ astring filename(ROM_GETNAME(romp), ".chd"); /* first open the source drive */ LOG(("Opening disk image: %s\n", filename.cstr())); err = chd_error(open_disk_image(romdata->machine().options(), &romdata->machine().system(), romp, chd->orig_chd(), locationtag)); if (err != CHDERR_NONE) { handle_missing_file(romdata, romp, astring(), err); global_free(chd); continue; } /* get the header and extract the SHA1 */ hash_collection acthashes; acthashes.add_sha1(chd->orig_chd().sha1()); /* verify the hash */ if (hashes != acthashes) { romdata->errorstring.catprintf("%s WRONG CHECKSUMS:\n", filename.cstr()); dump_wrong_and_correct_checksums(romdata, hashes, acthashes); romdata->warnings++; } else if (hashes.flag(hash_collection::FLAG_BAD_DUMP)) { romdata->errorstring.catprintf("%s CHD NEEDS REDUMP\n", filename.cstr()); romdata->knownbad++; } /* if not read-only, make the diff file */ if (!DISK_ISREADONLY(romp)) { /* try to open or create the diff */ err = open_disk_diff(romdata->machine().options(), romp, chd->orig_chd(), chd->diff_chd()); if (err != CHDERR_NONE) { romdata->errorstring.catprintf("%s DIFF CHD ERROR: %s\n", filename.cstr(), chd_file::error_string(err)); romdata->errors++; global_free(chd); continue; } } /* we're okay, add to the list of disks */ LOG(("Assigning to handle %d\n", DISK_GETINDEX(romp))); romdata->machine().romload_data->chd_list.append(*chd); } } }
static int process_rom_entries(struct rom_load_data *romdata, const struct RomModule *romp) { UINT32 lastflags = 0; /* loop until we hit the end of this region */ while (!ROMENTRY_ISREGIONEND(romp)) { /* if this is a continue entry, it's invalid */ if (ROMENTRY_ISCONTINUE(romp)) { printf("Error in RomModule definition: ROM_CONTINUE not preceded by ROM_LOAD\n"); goto fatalerror; } /* if this is a reload entry, it's invalid */ if (ROMENTRY_ISRELOAD(romp)) { printf("Error in RomModule definition: ROM_RELOAD not preceded by ROM_LOAD\n"); goto fatalerror; } /* handle fills */ if (ROMENTRY_ISFILL(romp)) { if (!fill_rom_data(romdata, romp++)) goto fatalerror; } /* handle copies */ else if (ROMENTRY_ISCOPY(romp)) { if (!copy_rom_data(romdata, romp++)) goto fatalerror; } /* handle files */ else if (ROMENTRY_ISFILE(romp)) { if (!ROM_GETBIOSFLAGS(romp) || (ROM_GETBIOSFLAGS(romp) == (system_bios+1))) /* alternate bios sets */ { const struct RomModule *baserom = romp; int explength = 0; /* open the file */ debugload("Opening ROM file: %s\n", ROM_GETNAME(romp)); if (!open_rom_file(romdata, romp)) handle_missing_file(romdata, romp); /* loop until we run out of reloads */ do { /* loop until we run out of continues */ do { struct RomModule modified_romp = *romp++; int readresult; /* handle flag inheritance */ if (!ROM_INHERITSFLAGS(&modified_romp)) lastflags = modified_romp._flags; else modified_romp._flags = (modified_romp._flags & ~ROM_INHERITEDFLAGS) | lastflags; explength += ROM_GETLENGTH(&modified_romp); /* attempt to read using the modified entry */ readresult = read_rom_data(romdata, &modified_romp); if (readresult == -1) goto fatalerror; } while (ROMENTRY_ISCONTINUE(romp)); /* if this was the first use of this file, verify the length and CRC */ if (baserom) { debugload("Verifying length (%X) and checksums\n", explength); verify_length_and_hash(romdata, ROM_GETNAME(baserom), explength, ROM_GETHASHDATA(baserom)); debugload("Verify finished\n"); } /* reseek to the start and clear the baserom so we don't reverify */ if (romdata->file) mame_fseek(romdata->file, 0, SEEK_SET); baserom = NULL; explength = 0; } while (ROMENTRY_ISRELOAD(romp)); /* close the file */ if (romdata->file) { debugload("Closing ROM file\n"); mame_fclose(romdata->file); romdata->file = NULL; } } else { romp++; /* skip over file */ } } } return 1; /* error case */ fatalerror: if (romdata->file) mame_fclose(romdata->file); romdata->file = NULL; return 0; }