static int open_rom_file(rom_load_data *romdata, const rom_entry *romp) { mame_file_error filerr = FILERR_NOT_FOUND; const game_driver *drv; ++romdata->romsloaded; /* update status display */ display_loading_rom_message(ROM_GETNAME(romp), romdata); /* Attempt reading up the chain through the parents. It automatically also attempts any kind of load by checksum supported by the archives. */ romdata->file = NULL; for (drv = Machine->gamedrv; !romdata->file && drv; drv = driver_get_clone(drv)) if (drv->name && *drv->name) { UINT8 crcs[4]; char *fname; fname = assemble_3_strings(drv->name, PATH_SEPARATOR, ROM_GETNAME(romp)); if (hash_data_extract_binary_checksum(ROM_GETHASHDATA(romp), HASH_CRC, crcs)) { UINT32 crc = (crcs[0] << 24) | (crcs[1] << 16) | (crcs[2] << 8) | crcs[3]; filerr = mame_fopen_crc(SEARCHPATH_ROM, fname, crc, OPEN_FLAG_READ, &romdata->file); } else filerr = mame_fopen(SEARCHPATH_ROM, fname, OPEN_FLAG_READ, &romdata->file); free(fname); } /* return the result */ return (filerr == FILERR_NONE); }
/*------------------------------------------------- load_software - software image loading -------------------------------------------------*/ bool legacy_image_device_base::load_software(char *swlist, char *swname, rom_entry *start) { const rom_entry *region; astring regiontag; bool retVal = FALSE; for (region = start; region != NULL; region = rom_next_region(region)) { /* loop until we hit the end of this region */ const rom_entry *romp = region + 1; while (!ROMENTRY_ISREGIONEND(romp)) { /* handle files */ if (ROMENTRY_ISFILE(romp)) { UINT32 crc = 0; UINT8 crcbytes[4]; file_error filerr; bool has_crc = hash_data_extract_binary_checksum(ROM_GETHASHDATA(romp), HASH_CRC, crcbytes); if (has_crc) crc = (crcbytes[0] << 24) | (crcbytes[1] << 16) | (crcbytes[2] << 8) | crcbytes[3]; astring fname(swlist, PATH_SEPARATOR, swname, PATH_SEPARATOR, ROM_GETNAME(romp)); if (has_crc) filerr = mame_fopen_crc(libretro_content_directory, fname, crc, OPEN_FLAG_READ, &m_mame_file); else filerr = mame_fopen(libretro_content_directory, fname, OPEN_FLAG_READ, &m_mame_file); if (filerr == FILERR_NONE) { m_file = mame_core_file(m_mame_file); retVal = TRUE; } break; // load first item for start } romp++; /* something else; skip */ } } return retVal; }
static int audit_one_rom(const rom_entry *rom, const game_driver *gamedrv, UINT32 validation, audit_record *record) { const game_driver *drv; const rom_entry *chunk; UINT32 crc = 0; UINT8 crcs[4]; int has_crc; /* fill in the record basics */ record->type = AUDIT_FILE_ROM; record->name = ROM_GETNAME(rom); record->exphash = ROM_GETHASHDATA(rom); /* compute the expected length by summing the chunks */ for (chunk = rom_first_chunk(rom); chunk; chunk = rom_next_chunk(chunk)) record->explength += ROM_GETLENGTH(chunk); /* see if we have a CRC and extract it if so */ has_crc = hash_data_extract_binary_checksum(record->exphash, HASH_CRC, crcs); if (has_crc) crc = (crcs[0] << 24) | (crcs[1] << 16) | (crcs[2] << 8) | crcs[3]; /* find the file and checksum it, getting the file length along the way */ for (drv = gamedrv; drv != NULL; drv = driver_get_clone(drv)) { mame_file_error filerr; mame_file *file; char *fname; /* open the file if we can */ fname = assemble_3_strings(drv->name, PATH_SEPARATOR, ROM_GETNAME(rom)); if (has_crc) filerr = mame_fopen_crc(SEARCHPATH_ROM, fname, crc, OPEN_FLAG_READ, &file); else filerr = mame_fopen(SEARCHPATH_ROM, fname, OPEN_FLAG_READ, &file); free(fname); /* if we got it, extract the hash and length */ if (filerr == FILERR_NONE) { hash_data_copy(record->hash, mame_fhash(file, validation)); record->length = (UINT32)mame_fsize(file); mame_fclose(file); break; } } /* if we failed to find the file, set the appropriate status */ if (drv == NULL) { const game_driver *parent; /* no good dump */ if (hash_data_has_info(record->exphash, HASH_INFO_NO_DUMP)) set_status(record, AUDIT_STATUS_NOT_FOUND, SUBSTATUS_NOT_FOUND_NODUMP); /* optional ROM */ else if (ROM_ISOPTIONAL(rom)) set_status(record, AUDIT_STATUS_NOT_FOUND, SUBSTATUS_NOT_FOUND_OPTIONAL); /* not found and used by parent */ else if (rom_used_by_parent(gamedrv, rom, &parent)) set_status(record, AUDIT_STATUS_NOT_FOUND, (parent->flags & NOT_A_DRIVER) ? SUBSTATUS_NOT_FOUND_BIOS : SUBSTATUS_NOT_FOUND_PARENT); /* just plain old not found */ else set_status(record, AUDIT_STATUS_NOT_FOUND, SUBSTATUS_NOT_FOUND); } /* if we did find the file, do additional verification */ else { /* length mismatch */ if (record->explength != record->length) set_status(record, AUDIT_STATUS_FOUND_INVALID, SUBSTATUS_FOUND_WRONG_LENGTH); /* found but needs a dump */ else if (hash_data_has_info(record->exphash, HASH_INFO_NO_DUMP)) set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_FOUND_NODUMP); /* incorrect hash */ else if (!hash_data_is_equal(record->exphash, record->hash, 0)) set_status(record, AUDIT_STATUS_FOUND_INVALID, SUBSTATUS_FOUND_BAD_CHECKSUM); /* correct hash but needs a redump */ else if (hash_data_has_info(record->exphash, HASH_INFO_BAD_DUMP)) set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_GOOD_NEEDS_REDUMP); /* just plain old good */ else set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_GOOD); } /* return TRUE if we found anything at all */ return (drv != NULL); }