static void copy_rom_data(romload_private *romdata, const rom_entry *romp) { UINT8 *base = romdata->region->base() + ROM_GETOFFSET(romp); const char *srcrgntag = ROM_GETNAME(romp); UINT32 numbytes = ROM_GETLENGTH(romp); UINT32 srcoffs = (FPTR)ROM_GETHASHDATA(romp); /* srcoffset in place of hashdata */ /* make sure we copy within the region space */ if (ROM_GETOFFSET(romp) + numbytes > romdata->region->bytes()) fatalerror("Error in RomModule definition: COPY out of target memory region space\n"); /* make sure the length was valid */ if (numbytes == 0) fatalerror("Error in RomModule definition: COPY has an invalid length\n"); /* make sure the source was valid */ memory_region *region = romdata->machine().root_device().memregion(srcrgntag); if (region == NULL) fatalerror("Error in RomModule definition: COPY from an invalid region\n"); /* make sure we find within the region space */ if (srcoffs + numbytes > region->bytes()) fatalerror("Error in RomModule definition: COPY out of source memory region space\n"); /* fill the data */ memcpy(base, region->base() + srcoffs, numbytes); }
static void copy_rom_data(rom_load_data *romdata, const rom_entry *romp) { UINT8 *base = romdata->regionbase + ROM_GETOFFSET(romp); int srcregion = ROM_GETFLAGS(romp) >> 24; UINT32 numbytes = ROM_GETLENGTH(romp); UINT32 srcoffs = (UINT32)ROM_GETHASHDATA(romp); /* srcoffset in place of hashdata */ UINT8 *srcbase; /* make sure we copy within the region space */ if (ROM_GETOFFSET(romp) + numbytes > romdata->regionlength) fatalerror("Error in RomModule definition: COPY out of target memory region space\n"); /* make sure the length was valid */ if (numbytes == 0) fatalerror("Error in RomModule definition: COPY has an invalid length\n"); /* make sure the source was valid */ srcbase = memory_region(srcregion); if (!srcbase) fatalerror("Error in RomModule definition: COPY from an invalid region\n"); /* make sure we find within the region space */ if (srcoffs + numbytes > memory_region_length(srcregion)) fatalerror("Error in RomModule definition: COPY out of source memory region space\n"); /* fill the data */ memcpy(base, srcbase + srcoffs, numbytes); }
static void fill_rom_data(romload_private *romdata, const rom_entry *romp) { UINT32 numbytes = ROM_GETLENGTH(romp); UINT8 *base = romdata->region->base() + ROM_GETOFFSET(romp); /* make sure we fill within the region space */ if (ROM_GETOFFSET(romp) + numbytes > romdata->region->bytes()) fatalerror("Error in RomModule definition: FILL out of memory region space\n"); /* make sure the length was valid */ if (numbytes == 0) fatalerror("Error in RomModule definition: FILL has an invalid length\n"); /* fill the data (filling value is stored in place of the hashdata) */ memset(base, (FPTR)ROM_GETHASHDATA(romp) & 0xff, numbytes); }
static int fill_rom_data(struct rom_load_data *romdata, const struct RomModule *romp) { UINT32 numbytes = ROM_GETLENGTH(romp); UINT8 *base = romdata->regionbase + ROM_GETOFFSET(romp); /* make sure we fill within the region space */ if (ROM_GETOFFSET(romp) + numbytes > romdata->regionlength) { printf("Error in RomModule definition: FILL out of memory region space\n"); return 0; } /* make sure the length was valid */ if (numbytes == 0) { printf("Error in RomModule definition: FILL has an invalid length\n"); return 0; } /* fill the data (filling value is stored in place of the hashdata) */ memset(base, (UINT32)ROM_GETHASHDATA(romp) & 0xff, numbytes); return 1; }
void rom_load_manager::fill_rom_data(const rom_entry *romp) { UINT32 numbytes = ROM_GETLENGTH(romp); int skip = ROM_GETSKIPCOUNT(romp); UINT8 *base = m_region->base() + ROM_GETOFFSET(romp); /* make sure we fill within the region space */ if (ROM_GETOFFSET(romp) + numbytes > m_region->bytes()) fatalerror("Error in RomModule definition: FILL out of memory region space\n"); /* make sure the length was valid */ if (numbytes == 0) fatalerror("Error in RomModule definition: FILL has an invalid length\n"); /* fill the data (filling value is stored in place of the hashdata) */ if(skip != 0) { for (int i = 0; i < numbytes; i+= skip + 1) base[i] = (FPTR)ROM_GETHASHDATA(romp) & 0xff; } else memset(base, (FPTR)ROM_GETHASHDATA(romp) & 0xff, numbytes); }
int cartslot_image_device::load_cartridge(const rom_entry *romrgn, const rom_entry *roment, bool load) { const char *region; const char *type; UINT32 flags; offs_t offset, size, read_length, pos = 0, len; UINT8 *ptr; UINT8 clear_val; int datawidth, littleendian, i, j; device_t *cpu; astring regiontag; device().siblingtag(regiontag, ROMREGION_GETTAG(romrgn)); region = regiontag.cstr(); offset = ROM_GETOFFSET(roment); size = ROM_GETLENGTH(roment); flags = ROM_GETFLAGS(roment); ptr = ((UINT8 *) device().machine().root_device().memregion(region)->base()) + offset; if (load) { if (software_entry() == NULL) { /* must this be full size */ if (flags & ROM_FULLSIZE) { if (length() != size) return IMAGE_INIT_FAIL; } /* read the ROM */ pos = read_length = fread(ptr, size); /* reset the ROM to the initial point. */ /* eventually, we could add a flag to allow the ROM to continue instead of restarting whenever a new cart region is present */ fseek(0, SEEK_SET); } else { /* must this be full size */ if (flags & ROM_FULLSIZE) { if (get_software_region_length("rom") != size) return IMAGE_INIT_FAIL; } /* read the ROM */ pos = read_length = get_software_region_length("rom"); memcpy(ptr, get_software_region("rom"), read_length); } /* do we need to mirror the ROM? */ if (flags & ROM_MIRROR) { while(pos < size) { len = MIN(read_length, size - pos); memcpy(ptr + pos, ptr, len); pos += len; } } /* postprocess this region */ type = regiontag.cstr(); littleendian = ROMREGION_ISLITTLEENDIAN(romrgn); datawidth = ROMREGION_GETWIDTH(romrgn) / 8; /* if the region is inverted, do that now */ device_memory_interface *memory; cpu = device().machine().device(type); if (cpu!=NULL && cpu->interface(memory)) { datawidth = cpu->memory().space_config(AS_PROGRAM)->m_databus_width / 8; littleendian = (cpu->memory().space_config()->m_endianness == ENDIANNESS_LITTLE); } /* swap the endianness if we need to */ #ifdef LSB_FIRST if (datawidth > 1 && !littleendian) #else if (datawidth > 1 && littleendian) #endif { for (i = 0; i < size; i += datawidth) { UINT8 temp[8]; memcpy(temp, &ptr[i], datawidth); for (j = datawidth - 1; j >= 0; j--) ptr[i + j] = temp[datawidth - 1 - j]; } } } /* clear out anything that remains */ if (!(flags & ROM_NOCLEAR)) { clear_val = (flags & ROM_FILL_FF) ? 0xFF : 0x00; memset(ptr + pos, clear_val, size - pos); } return IMAGE_INIT_PASS; }
static int read_rom_data(romload_private *romdata, const rom_entry *parent_region, const rom_entry *romp) { int datashift = ROM_GETBITSHIFT(romp); int datamask = ((1 << ROM_GETBITWIDTH(romp)) - 1) << datashift; int numbytes = ROM_GETLENGTH(romp); int groupsize = ROM_GETGROUPSIZE(romp); int skip = ROM_GETSKIPCOUNT(romp); int reversed = ROM_ISREVERSED(romp); int numgroups = (numbytes + groupsize - 1) / groupsize; UINT8 *base = romdata->region->base() + ROM_GETOFFSET(romp); UINT32 tempbufsize; int i; LOG(("Loading ROM data: offs=%X len=%X mask=%02X group=%d skip=%d reverse=%d\n", ROM_GETOFFSET(romp), numbytes, datamask, groupsize, skip, reversed)); /* make sure the length was an even multiple of the group size */ if (numbytes % groupsize != 0) mame_printf_warning("Warning in RomModule definition: %s length not an even multiple of group size\n", ROM_GETNAME(romp)); /* make sure we only fill within the region space */ if (ROM_GETOFFSET(romp) + numgroups * groupsize + (numgroups - 1) * skip > romdata->region->bytes()) fatalerror("Error in RomModule definition: %s out of memory region space\n", ROM_GETNAME(romp)); /* make sure the length was valid */ if (numbytes == 0) fatalerror("Error in RomModule definition: %s has an invalid length\n", ROM_GETNAME(romp)); /* special case for simple loads */ if (datamask == 0xff && (groupsize == 1 || !reversed) && skip == 0) return rom_fread(romdata, base, numbytes, parent_region); /* use a temporary buffer for complex loads */ tempbufsize = MIN(TEMPBUFFER_MAX_SIZE, numbytes); dynamic_buffer tempbuf(tempbufsize); /* chunky reads for complex loads */ skip += groupsize; while (numbytes > 0) { int evengroupcount = (tempbufsize / groupsize) * groupsize; int bytesleft = (numbytes > evengroupcount) ? evengroupcount : numbytes; UINT8 *bufptr = tempbuf; /* read as much as we can */ LOG((" Reading %X bytes into buffer\n", bytesleft)); if (rom_fread(romdata, bufptr, bytesleft, parent_region) != bytesleft) return 0; numbytes -= bytesleft; LOG((" Copying to %p\n", base)); /* unmasked cases */ if (datamask == 0xff) { /* non-grouped data */ if (groupsize == 1) for (i = 0; i < bytesleft; i++, base += skip) *base = *bufptr++; /* grouped data -- non-reversed case */ else if (!reversed) while (bytesleft) { for (i = 0; i < groupsize && bytesleft; i++, bytesleft--) base[i] = *bufptr++; base += skip; } /* grouped data -- reversed case */ else while (bytesleft) { for (i = groupsize - 1; i >= 0 && bytesleft; i--, bytesleft--) base[i] = *bufptr++; base += skip; } } /* masked cases */ else { /* non-grouped data */ if (groupsize == 1) for (i = 0; i < bytesleft; i++, base += skip) *base = (*base & ~datamask) | ((*bufptr++ << datashift) & datamask); /* grouped data -- non-reversed case */ else if (!reversed) while (bytesleft) { for (i = 0; i < groupsize && bytesleft; i++, bytesleft--) base[i] = (base[i] & ~datamask) | ((*bufptr++ << datashift) & datamask); base += skip; } /* grouped data -- reversed case */ else while (bytesleft) { for (i = groupsize - 1; i >= 0 && bytesleft; i--, bytesleft--) base[i] = (base[i] & ~datamask) | ((*bufptr++ << datashift) & datamask); base += skip; } } } LOG((" All done\n")); return ROM_GETLENGTH(romp); }
static void print_game_rom(FILE *out, const game_driver *game, const machine_config *config) { const game_driver *clone_of = driver_get_clone(game); int rom_type; machine_config *pconfig = (clone_of != NULL) ? machine_config_alloc(clone_of->machine_config) : NULL; /* iterate over 3 different ROM "types": BIOS, ROMs, DISKs */ for (rom_type = 0; rom_type < 3; rom_type++) { const rom_source *source; const rom_entry *region; /* iterate over ROM sources: first the game, then any devices */ for (source = rom_first_source(game, config); source != NULL; source = rom_next_source(game, config, source)) for (region = rom_first_region(game, source); region != NULL; region = rom_next_region(region)) { int is_disk = ROMREGION_ISDISKDATA(region); const rom_entry *rom; /* disk regions only work for disks */ if ((is_disk && rom_type != 2) || (!is_disk && rom_type == 2)) continue; /* iterate through ROM entries */ for (rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom)) { int is_bios = ROM_GETBIOSFLAGS(rom); const char *name = ROM_GETNAME(rom); int offset = ROM_GETOFFSET(rom); const rom_entry *parent_rom = NULL; char bios_name[100]; /* BIOS ROMs only apply to bioses */ if ((is_bios && rom_type != 0) || (!is_bios && rom_type == 0)) continue; /* if we have a valid ROM and we are a clone, see if we can find the parent ROM */ if (!ROM_NOGOODDUMP(rom) && clone_of != NULL) { const rom_source *psource; const rom_entry *pregion, *prom; /* scan the clone_of ROM for a matching ROM entry */ for (psource = rom_first_source(clone_of, pconfig); psource != NULL; psource = rom_next_source(clone_of, pconfig, psource)) for (pregion = rom_first_region(clone_of, psource); pregion != NULL; pregion = rom_next_region(pregion)) for (prom = rom_first_file(pregion); prom != NULL; prom = rom_next_file(prom)) if (hash_data_is_equal(ROM_GETHASHDATA(rom), ROM_GETHASHDATA(prom), 0)) { parent_rom = prom; break; } } /* scan for a BIOS name */ bios_name[0] = 0; if (!is_disk && is_bios) { const rom_entry *brom; /* scan backwards through the ROM entries */ for (brom = rom - 1; brom != game->rom; brom--) if (ROMENTRY_ISSYSTEM_BIOS(brom)) { strcpy(bios_name, ROM_GETNAME(brom)); break; } } /* opening tag */ if (!is_disk) fprintf(out, "\t\t<rom"); else fprintf(out, "\t\t<disk"); /* add name, merge, bios, and size tags */ if (name != NULL && name[0] != 0) fprintf(out, " name=\"%s\"", xml_normalize_string(name)); if (parent_rom != NULL) fprintf(out, " merge=\"%s\"", xml_normalize_string(ROM_GETNAME(parent_rom))); if (bios_name[0] != 0) fprintf(out, " bios=\"%s\"", xml_normalize_string(bios_name)); if (!is_disk) fprintf(out, " size=\"%d\"", rom_file_size(rom)); /* dump checksum information only if there is a known dump */ if (!hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP)) { char checksum[HASH_BUF_SIZE]; int hashtype; /* iterate over hash function types and print out their values */ for (hashtype = 0; hashtype < HASH_NUM_FUNCTIONS; hashtype++) if (hash_data_extract_printable_checksum(ROM_GETHASHDATA(rom), 1 << hashtype, checksum)) fprintf(out, " %s=\"%s\"", hash_function_name(1 << hashtype), checksum); } /* append a region name */ fprintf(out, " region=\"%s\"", ROMREGION_GETTAG(region)); /* add nodump/baddump flags */ if (hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP)) fprintf(out, " status=\"nodump\""); if (hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_BAD_DUMP)) fprintf(out, " status=\"baddump\""); /* for non-disk entries, print offset */ if (!is_disk) fprintf(out, " offset=\"%x\"", offset); /* for disk entries, add the disk index */ else fprintf(out, " index=\"%x\"", DISK_GETINDEX(rom)); /* add optional flag */ if ((!is_disk && ROM_ISOPTIONAL(rom)) || (is_disk && DISK_ISOPTIONAL(rom))) fprintf(out, " optional=\"yes\""); fprintf(out, "/>\n"); } } } if (pconfig != NULL) machine_config_free(pconfig); }
void info_xml_creator::output_rom(device_t &device) { // iterate over 3 different ROM "types": BIOS, ROMs, DISKs for (int rom_type = 0; rom_type < 3; rom_type++) for (const rom_entry *region = rom_first_region(device); region != NULL; region = rom_next_region(region)) { bool is_disk = ROMREGION_ISDISKDATA(region); // disk regions only work for disks if ((is_disk && rom_type != 2) || (!is_disk && rom_type == 2)) continue; // iterate through ROM entries for (const rom_entry *rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom)) { bool is_bios = ROM_GETBIOSFLAGS(rom); const char *name = ROM_GETNAME(rom); int offset = ROM_GETOFFSET(rom); const char *merge_name = NULL; char bios_name[100]; // BIOS ROMs only apply to bioses if ((is_bios && rom_type != 0) || (!is_bios && rom_type == 0)) continue; // if we have a valid ROM and we are a clone, see if we can find the parent ROM hash_collection hashes(ROM_GETHASHDATA(rom)); if (!hashes.flag(hash_collection::FLAG_NO_DUMP)) merge_name = get_merge_name(hashes); if (&device != &m_drivlist.config().root_device()) merge_name = NULL; // scan for a BIOS name bios_name[0] = 0; if (!is_disk && is_bios) { // scan backwards through the ROM entries for (const rom_entry *brom = rom - 1; brom != m_drivlist.driver().rom; brom--) if (ROMENTRY_ISSYSTEM_BIOS(brom)) { strcpy(bios_name, ROM_GETNAME(brom)); break; } } astring output; // opening tag if (!is_disk) output.cat("\t\t<rom"); else output.cat("\t\t<disk"); // add name, merge, bios, and size tags */ if (name != NULL && name[0] != 0) output.catprintf(" name=\"%s\"", xml_normalize_string(name)); if (merge_name != NULL) output.catprintf(" merge=\"%s\"", xml_normalize_string(merge_name)); if (bios_name[0] != 0) output.catprintf(" bios=\"%s\"", xml_normalize_string(bios_name)); if (!is_disk) output.catprintf(" size=\"%d\"", rom_file_size(rom)); // dump checksum information only if there is a known dump if (!hashes.flag(hash_collection::FLAG_NO_DUMP)) { // iterate over hash function types and print m_output their values astring tempstr; output.catprintf(" %s", hashes.attribute_string(tempstr)); } else output.cat(" status=\"nodump\""); // append a region name output.catprintf(" region=\"%s\"", ROMREGION_GETTAG(region)); // for non-disk entries, print offset if (!is_disk) output.catprintf(" offset=\"%x\"", offset); // for disk entries, add the disk index else { output.catprintf(" index=\"%x\"", DISK_GETINDEX(rom)); output.catprintf(" writable=\"%s\"", DISK_ISREADONLY(rom) ? "no" : "yes"); } // add optional flag if (ROM_ISOPTIONAL(rom)) output.cat(" optional=\"yes\""); output.cat("/>\n"); fprintf(m_output, "%s", output.cstr()); } } }
static int read_rom_data(struct rom_load_data *romdata, const struct RomModule *romp) { int datashift = ROM_GETBITSHIFT(romp); int datamask = ((1 << ROM_GETBITWIDTH(romp)) - 1) << datashift; int numbytes = ROM_GETLENGTH(romp); int groupsize = ROM_GETGROUPSIZE(romp); int skip = ROM_GETSKIPCOUNT(romp); int reversed = ROM_ISREVERSED(romp); int numgroups = (numbytes + groupsize - 1) / groupsize; UINT8 *base = romdata->regionbase + ROM_GETOFFSET(romp); int i; debugload("Loading ROM data: offs=%X len=%X mask=%02X group=%d skip=%d reverse=%d\n", ROM_GETOFFSET(romp), numbytes, datamask, groupsize, skip, reversed); /* make sure the length was an even multiple of the group size */ if (numbytes % groupsize != 0) { printf("Error in RomModule definition: %s length not an even multiple of group size\n", ROM_GETNAME(romp)); return -1; } /* make sure we only fill within the region space */ if (ROM_GETOFFSET(romp) + numgroups * groupsize + (numgroups - 1) * skip > romdata->regionlength) { printf("Error in RomModule definition: %s out of memory region space\n", ROM_GETNAME(romp)); return -1; } /* make sure the length was valid */ if (numbytes == 0) { printf("Error in RomModule definition: %s has an invalid length\n", ROM_GETNAME(romp)); return -1; } /* special case for simple loads */ if (datamask == 0xff && (groupsize == 1 || !reversed) && skip == 0) return rom_fread(romdata, base, numbytes); /* chunky reads for complex loads */ skip += groupsize; while (numbytes) { int evengroupcount = (sizeof(romdata->tempbuf) / groupsize) * groupsize; int bytesleft = (numbytes > evengroupcount) ? evengroupcount : numbytes; UINT8 *bufptr = romdata->tempbuf; /* read as much as we can */ debugload(" Reading %X bytes into buffer\n", bytesleft); if (rom_fread(romdata, romdata->tempbuf, bytesleft) != bytesleft) return 0; numbytes -= bytesleft; debugload(" Copying to %08X\n", (int)base); /* unmasked cases */ if (datamask == 0xff) { /* non-grouped data */ if (groupsize == 1) for (i = 0; i < bytesleft; i++, base += skip) *base = *bufptr++; /* grouped data -- non-reversed case */ else if (!reversed) while (bytesleft) { for (i = 0; i < groupsize && bytesleft; i++, bytesleft--) base[i] = *bufptr++; base += skip; } /* grouped data -- reversed case */ else while (bytesleft) { for (i = groupsize - 1; i >= 0 && bytesleft; i--, bytesleft--) base[i] = *bufptr++; base += skip; } } /* masked cases */ else { /* non-grouped data */ if (groupsize == 1) for (i = 0; i < bytesleft; i++, base += skip) *base = (*base & ~datamask) | ((*bufptr++ << datashift) & datamask); /* grouped data -- non-reversed case */ else if (!reversed) while (bytesleft) { for (i = 0; i < groupsize && bytesleft; i++, bytesleft--) base[i] = (base[i] & ~datamask) | ((*bufptr++ << datashift) & datamask); base += skip; } /* grouped data -- reversed case */ else while (bytesleft) { for (i = groupsize - 1; i >= 0 && bytesleft; i--, bytesleft--) base[i] = (base[i] & ~datamask) | ((*bufptr++ << datashift) & datamask); base += skip; } } } debugload(" All done\n"); return ROM_GETLENGTH(romp); }
static void print_game_rom(FILE* out, const game_driver* game) { const rom_entry *region, *rom, *chunk; const rom_entry *pregion, *prom, *fprom=NULL; const game_driver *clone_of; if (!game->rom) return; clone_of = driver_get_clone(game); for (region = rom_first_region(game); region; region = rom_next_region(region)) for (rom = rom_first_file(region); rom; rom = rom_next_file(rom)) { int offset, length, in_parent, is_disk, is_bios, found_bios, i; char name[100], bios_name[100]; strcpy(name,ROM_GETNAME(rom)); offset = ROM_GETOFFSET(rom); is_disk = ROMREGION_ISDISKDATA(region); is_bios = ROM_GETBIOSFLAGS(rom); in_parent = 0; length = 0; for (chunk = rom_first_chunk(rom); chunk; chunk = rom_next_chunk(chunk)) length += ROM_GETLENGTH(chunk); if (!ROM_NOGOODDUMP(rom) && clone_of) { fprom=NULL; for (pregion = rom_first_region(clone_of); pregion; pregion = rom_next_region(pregion)) for (prom = rom_first_file(pregion); prom; prom = rom_next_file(prom)) if (hash_data_is_equal(ROM_GETHASHDATA(rom), ROM_GETHASHDATA(prom), 0)) { if (!fprom || !strcmp(ROM_GETNAME(prom), name)) fprom=prom; in_parent = 1; } } found_bios = 0; if(!is_disk && is_bios && game->bios) { const bios_entry *thisbios = game->bios; /* Match against bios short names */ while(!found_bios && !BIOSENTRY_ISEND(thisbios) ) { if((is_bios-1) == thisbios->value) /* Note '-1' */ { strcpy(bios_name,thisbios->_name); found_bios = 1; } thisbios++; } } if (!is_disk) fprintf(out, "\t\t<rom"); else fprintf(out, "\t\t<disk"); if (*name) fprintf(out, " name=\"%s\"", normalize_string(name)); if (in_parent) fprintf(out, " merge=\"%s\"", normalize_string(ROM_GETNAME(fprom))); if (!is_disk && found_bios) fprintf(out, " bios=\"%s\"", normalize_string(bios_name)); if (!is_disk) fprintf(out, " size=\"%d\"", length); /* dump checksum information only if there is a known dump */ if (!hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP)) { for (i=0;i<HASH_NUM_FUNCTIONS;i++) { int func = 1<<i; const char* func_name = hash_function_name(func); char checksum[1000]; if (hash_data_extract_printable_checksum(ROM_GETHASHDATA(rom), func, checksum)) { fprintf(out, " %s=\"%s\"", func_name, checksum); } } } switch (ROMREGION_GETTYPE(region)) { case REGION_CPU1: fprintf(out, " region=\"cpu1\""); break; case REGION_CPU2: fprintf(out, " region=\"cpu2\""); break; case REGION_CPU3: fprintf(out, " region=\"cpu3\""); break; case REGION_CPU4: fprintf(out, " region=\"cpu4\""); break; case REGION_CPU5: fprintf(out, " region=\"cpu5\""); break; case REGION_CPU6: fprintf(out, " region=\"cpu6\""); break; case REGION_CPU7: fprintf(out, " region=\"cpu7\""); break; case REGION_CPU8: fprintf(out, " region=\"cpu8\""); break; case REGION_GFX1: fprintf(out, " region=\"gfx1\""); break; case REGION_GFX2: fprintf(out, " region=\"gfx2\""); break; case REGION_GFX3: fprintf(out, " region=\"gfx3\""); break; case REGION_GFX4: fprintf(out, " region=\"gfx4\""); break; case REGION_GFX5: fprintf(out, " region=\"gfx5\""); break; case REGION_GFX6: fprintf(out, " region=\"gfx6\""); break; case REGION_GFX7: fprintf(out, " region=\"gfx7\""); break; case REGION_GFX8: fprintf(out, " region=\"gfx8\""); break; case REGION_PROMS: fprintf(out, " region=\"proms\""); break; case REGION_SOUND1: fprintf(out, " region=\"sound1\""); break; case REGION_SOUND2: fprintf(out, " region=\"sound2\""); break; case REGION_SOUND3: fprintf(out, " region=\"sound3\""); break; case REGION_SOUND4: fprintf(out, " region=\"sound4\""); break; case REGION_SOUND5: fprintf(out, " region=\"sound5\""); break; case REGION_SOUND6: fprintf(out, " region=\"sound6\""); break; case REGION_SOUND7: fprintf(out, " region=\"sound7\""); break; case REGION_SOUND8: fprintf(out, " region=\"sound8\""); break; case REGION_USER1: fprintf(out, " region=\"user1\""); break; case REGION_USER2: fprintf(out, " region=\"user2\""); break; case REGION_USER3: fprintf(out, " region=\"user3\""); break; case REGION_USER4: fprintf(out, " region=\"user4\""); break; case REGION_USER5: fprintf(out, " region=\"user5\""); break; case REGION_USER6: fprintf(out, " region=\"user6\""); break; case REGION_USER7: fprintf(out, " region=\"user7\""); break; case REGION_USER8: fprintf(out, " region=\"user8\""); break; case REGION_DISKS: fprintf(out, " region=\"disks\""); break; default: fprintf(out, " region=\"0x%x\"", ROMREGION_GETTYPE(region)); } if (hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP)) fprintf(out, " status=\"nodump\""); if (hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_BAD_DUMP)) fprintf(out, " status=\"baddump\""); if (!is_disk) { if (ROMREGION_GETFLAGS(region) & ROMREGION_DISPOSE) fprintf(out, " dispose=\"yes\""); fprintf(out, " offset=\"%x\"", offset); fprintf(out, "/>\n"); } else { fprintf(out, " index=\"%x\"", DISK_GETINDEX(rom)); fprintf(out, "/>\n"); } } }
static int load_cartridge(const rom_entry *romrgn, const rom_entry *roment, mame_file *file) { UINT32 region, flags; offs_t offset, length, read_length, pos = 0, len; UINT8 *ptr; UINT8 clear_val; int type, datawidth, littleendian, i, j; region = ROMREGION_GETTYPE(romrgn); offset = ROM_GETOFFSET(roment); length = ROM_GETLENGTH(roment); flags = ROM_GETFLAGS(roment); ptr = ((UINT8 *) memory_region(region)) + offset; if (file) { /* must this be full size */ if (flags & ROM_FULLSIZE) { if (mame_fsize(file) != length) return INIT_FAIL; } /* read the ROM */ pos = read_length = mame_fread(file, ptr, length); /* do we need to mirror the ROM? */ if (flags & ROM_MIRROR) { while(pos < length) { len = MIN(read_length, length - pos); memcpy(ptr + pos, ptr, len); pos += len; } } /* postprocess this region */ type = ROMREGION_GETTYPE(romrgn); littleendian = ROMREGION_ISLITTLEENDIAN(romrgn); datawidth = ROMREGION_GETWIDTH(romrgn) / 8; /* if the region is inverted, do that now */ if (type >= REGION_CPU1 && type < REGION_CPU1 + MAX_CPU) { int cputype = Machine->drv->cpu[type - REGION_CPU1].cpu_type; if (cputype != 0) { datawidth = cputype_databus_width(cputype, ADDRESS_SPACE_PROGRAM) / 8; littleendian = (cputype_endianness(cputype) == CPU_IS_LE); } } /* swap the endianness if we need to */ #ifdef LSB_FIRST if (datawidth > 1 && !littleendian) #else if (datawidth > 1 && littleendian) #endif { for (i = 0; i < length; i += datawidth) { UINT8 temp[8]; memcpy(temp, &ptr[i], datawidth); for (j = datawidth - 1; j >= 0; j--) ptr[i + j] = temp[datawidth - 1 - j]; } } } /* clear out anything that remains */ if (!(flags & ROM_NOCLEAR)) { clear_val = (flags & ROM_FILL_FF) ? 0xFF : 0x00; memset(ptr + pos, clear_val, length - pos); } return INIT_PASS; }
static int info_listsoftware(core_options *options, const char *gamename) { FILE *out = stdout; int nr_lists = 0; char ** lists = NULL; int list_idx = 0; /* First determine the maximum number of lists we might encounter */ for ( int drvindex = 0; drivers[drvindex] != NULL; drvindex++ ) { if ( mame_strwildcmp( gamename, drivers[drvindex]->name ) == 0 ) { /* allocate the machine config */ machine_config *config = global_alloc(machine_config(drivers[drvindex]->machine_config)); for (const device_config *dev = config->m_devicelist.first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext()) { software_list_config *swlist = (software_list_config *)downcast<const legacy_device_config_base *>(dev)->inline_config(); for ( int i = 0; i < DEVINFO_STR_SWLIST_MAX - DEVINFO_STR_SWLIST_0; i++ ) { if ( swlist->list_name[i] && *swlist->list_name[i] && (swlist->list_type == SOFTWARE_LIST_ORIGINAL_SYSTEM)) nr_lists++; } } /* free the machine config */ global_free(config); } } lists = global_alloc_array( char *, nr_lists ); fprintf( out, "<?xml version=\"1.0\"?>\n" "<!DOCTYPE softwarelist [\n" "<!ELEMENT softwarelists (softwarelist*)>\n" "\t<!ELEMENT softwarelist (software+)>\n" "\t\t<!ATTLIST softwarelist name CDATA #REQUIRED>\n" "\t\t<!ATTLIST softwarelist description CDATA #IMPLIED>\n" "\t\t<!ELEMENT software (description, year?, publisher, part*)>\n" "\t\t\t<!ATTLIST software name CDATA #REQUIRED>\n" "\t\t\t<!ATTLIST software cloneof CDATA #IMPLIED>\n" "\t\t\t<!ATTLIST software supported (yes|partial|no) \"yes\">\n" "\t\t\t<!ELEMENT description (#PCDATA)>\n" "\t\t\t<!ELEMENT year (#PCDATA)>\n" "\t\t\t<!ELEMENT publisher (#PCDATA)>\n" "\t\t\t<!ELEMENT part (dataarea*)>\n" "\t\t\t\t<!ATTLIST part name CDATA #REQUIRED>\n" "\t\t\t\t<!ATTLIST part interface CDATA #REQUIRED>\n" "\t\t\t\t<!ATTLIST part feature CDATA #IMPLIED>\n" "\t\t\t\t<!ELEMENT dataarea (rom*)>\n" "\t\t\t\t\t<!ATTLIST dataarea name CDATA #REQUIRED>\n" "\t\t\t\t\t<!ATTLIST dataarea size CDATA #REQUIRED>\n" "\t\t\t\t\t<!ATTLIST dataarea databits (8|16|32|64) \"8\">\n" "\t\t\t\t\t<!ATTLIST dataarea endian (big|little) \"little\">\n" "\t\t\t\t\t<!ELEMENT rom EMPTY>\n" "\t\t\t\t\t\t<!ATTLIST rom name CDATA #IMPLIED>\n" "\t\t\t\t\t\t<!ATTLIST rom size CDATA #REQUIRED>\n" "\t\t\t\t\t\t<!ATTLIST rom crc CDATA #IMPLIED>\n" "\t\t\t\t\t\t<!ATTLIST rom md5 CDATA #IMPLIED>\n" "\t\t\t\t\t\t<!ATTLIST rom sha1 CDATA #IMPLIED>\n" "\t\t\t\t\t\t<!ATTLIST rom offset CDATA #IMPLIED>\n" "\t\t\t\t\t\t<!ATTLIST rom status (baddump|nodump|good) \"good\">\n" "\t\t\t\t\t\t<!ATTLIST rom loadflag (load16_byte|load16_word|load16_word_swap|load32_byte|load32_word|load32_word_swap|load32_dword|load64_word|load64_word_swap|reload) #IMPLIED>\n" "]>\n\n" "<softwarelists>\n" ); for ( int drvindex = 0; drivers[drvindex] != NULL; drvindex++ ) { if ( mame_strwildcmp( gamename, drivers[drvindex]->name ) == 0 ) { /* allocate the machine config */ machine_config *config = global_alloc(machine_config(drivers[drvindex]->machine_config)); for (const device_config *dev = config->m_devicelist.first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext()) { software_list_config *swlist = (software_list_config *)downcast<const legacy_device_config_base *>(dev)->inline_config(); for ( int i = 0; i < DEVINFO_STR_SWLIST_MAX - DEVINFO_STR_SWLIST_0; i++ ) { if ( swlist->list_name[i] && *swlist->list_name[i] && (swlist->list_type == SOFTWARE_LIST_ORIGINAL_SYSTEM)) { software_list *list = software_list_open( options, swlist->list_name[i], FALSE, NULL ); if ( list ) { /* Verify if we have encountered this list before */ bool seen_before = false; for ( int l = 0; l < list_idx && !seen_before; l++ ) { if ( ! strcmp( swlist->list_name[i], lists[l] ) ) { seen_before = true; } } if ( ! seen_before ) { lists[list_idx] = core_strdup( swlist->list_name[i] ); list_idx++; fprintf(out, "\t<softwarelist name=\"%s\">\n", swlist->list_name[i] ); for ( software_info *swinfo = software_list_find( list, "*", NULL ); swinfo != NULL; swinfo = software_list_find( list, "*", swinfo ) ) { fprintf( out, "\t\t<software name=\"%s\"", swinfo->shortname ); if ( swinfo->parentname != NULL ) fprintf( out, " cloneof=\"%s\"", swinfo->parentname ); if ( swinfo->supported == SOFTWARE_SUPPORTED_PARTIAL ) fprintf( out, " supported=\"partial\"" ); if ( swinfo->supported == SOFTWARE_SUPPORTED_NO ) fprintf( out, " supported=\"no\"" ); fprintf( out, ">\n" ); fprintf( out, "\t\t\t<description>%s</description>\n", xml_normalize_string(swinfo->longname) ); fprintf( out, "\t\t\t<year>%s</year>\n", xml_normalize_string( swinfo->year ) ); fprintf( out, "\t\t\t<publisher>%s</publisher>\n", xml_normalize_string( swinfo->publisher ) ); for ( software_part *part = software_find_part( swinfo, NULL, NULL ); part != NULL; part = software_part_next( part ) ) { fprintf( out, "\t\t\t<part name=\"%s\"", part->name ); if ( part->interface_ ) fprintf( out, " interface=\"%s\"", part->interface_ ); // if ( part->feature ) // fprintf( out, " features=\"%s\"", part->feature ); fprintf( out, ">\n"); /* TODO: display rom region information */ for ( const rom_entry *region = part->romdata; region; region = rom_next_region( region ) ) { fprintf( out, "\t\t\t\t<dataarea name=\"%s\" size=\"%x\">\n", ROMREGION_GETTAG(region), ROMREGION_GETLENGTH(region) ); for ( const rom_entry *rom = rom_first_file( region ); rom && !ROMENTRY_ISREGIONEND(rom); rom++ ) { if ( ROMENTRY_ISFILE(rom) ) { fprintf( out, "\t\t\t\t\t<rom name=\"%s\" size=\"%d\"", xml_normalize_string(ROM_GETNAME(rom)), rom_file_size(rom) ); /* dump checksum information only if there is a known dump */ if (!hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP)) { char checksum[HASH_BUF_SIZE]; int hashtype; /* iterate over hash function types and print out their values */ for (hashtype = 0; hashtype < HASH_NUM_FUNCTIONS; hashtype++) if (hash_data_extract_printable_checksum(ROM_GETHASHDATA(rom), 1 << hashtype, checksum)) fprintf(out, " %s=\"%s\"", hash_function_name(1 << hashtype), checksum); } fprintf( out, " offset=\"%x\"", ROM_GETOFFSET(rom) ); if ( hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_BAD_DUMP) ) fprintf( out, " status=\"baddump\"" ); if ( hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP) ) fprintf( out, " status=\"nodump\"" ); fprintf( out, "/>\n" ); } else if ( ROMENTRY_ISRELOAD(rom) ) { fprintf( out, "\t\t\t\t\t<rom size=\"%d\" offset=\"%x\" loadflag=\"reload\" />\n", ROM_GETLENGTH(rom), ROM_GETOFFSET(rom) ); } } fprintf( out, "\t\t\t\t</dataarea>\n" ); } fprintf( out, "\t\t\t</part>\n" ); } fprintf( out, "\t\t</software>\n" ); } fprintf(out, "\t</softwarelist>\n" ); } software_list_close( list ); } } } } global_free(config); } } fprintf( out, "</softwarelists>\n" ); global_free( lists ); return MAMERR_NONE; }