int rom_load(const struct RomModule *romp) { const struct RomModule *regionlist[REGION_MAX]; const struct RomModule *region; static struct rom_load_data romdata; int regnum; /* reset the region list */ for (regnum = 0;regnum < REGION_MAX;regnum++) regionlist[regnum] = NULL; /* reset the romdata struct */ memset(&romdata, 0, sizeof(romdata)); romdata.romstotal = count_roms(romp); /* reset the disk list */ memset(disk_handle, 0, sizeof(disk_handle)); /* determine the correct biosset to load based on options.bios string */ system_bios = determine_bios_rom(Machine->gamedrv->bios); /* loop until we hit the end */ for (region = romp, regnum = 0; region; region = rom_next_region(region), regnum++) { int regiontype = ROMREGION_GETTYPE(region); debugload("Processing region %02X (length=%X)\n", regiontype, ROMREGION_GETLENGTH(region)); /* the first entry must be a region */ if (!ROMENTRY_ISREGION(region)) { printf("Error: missing ROM_REGION header\n"); return 1; } /* if sound is disabled and it's a sound-only region, skip it */ if (Machine->sample_rate == 0 && ROMREGION_ISSOUNDONLY(region)) continue; /* allocate memory for the region */ if (new_memory_region(regiontype, ROMREGION_GETLENGTH(region), ROMREGION_GETFLAGS(region))) { printf("Error: unable to allocate memory for region %d\n", regiontype); return 1; } /* remember the base and length */ romdata.regionlength = memory_region_length(regiontype); romdata.regionbase = memory_region(regiontype); debugload("Allocated %X bytes @ %08X\n", romdata.regionlength, (int)romdata.regionbase); /* clear the region if it's requested */ if (ROMREGION_ISERASE(region)) memset(romdata.regionbase, ROMREGION_GETERASEVAL(region), romdata.regionlength); /* or if it's sufficiently small (<= 4MB) */ else if (romdata.regionlength <= 0x400000) memset(romdata.regionbase, 0, romdata.regionlength); #ifdef MAME_DEBUG /* if we're debugging, fill region with random data to catch errors */ else fill_random(romdata.regionbase, romdata.regionlength); #endif /* now process the entries in the region */ if (ROMREGION_ISROMDATA(region)) { if (!process_rom_entries(&romdata, region + 1)) return 1; } else if (ROMREGION_ISDISKDATA(region)) { if (!process_disk_entries(&romdata, region + 1)) return 1; } /* add this region to the list */ if (regiontype < REGION_MAX) regionlist[regiontype] = region; } /* post-process the regions */ for (regnum = 0; regnum < REGION_MAX; regnum++) if (regionlist[regnum]) { debugload("Post-processing region %02X\n", regnum); romdata.regionlength = memory_region_length(regnum); romdata.regionbase = memory_region(regnum); region_post_process(&romdata, regionlist[regnum]); } /* display the results and exit */ return display_rom_load_results(&romdata); }
void rom_init(running_machine *machine, const rom_entry *romp) { const rom_entry *regionlist[REGION_MAX]; const rom_entry *region; static rom_load_data romdata; int regnum; /* if no roms, bail */ if (romp == NULL) return; /* make sure we get called back on the way out */ add_exit_callback(machine, rom_exit); /* reset the region list */ memset((void *)regionlist, 0, sizeof(regionlist)); /* reset the romdata struct */ memset(&romdata, 0, sizeof(romdata)); romdata.romstotal = count_roms(romp); /* reset the disk list */ memset(disk_handle, 0, sizeof(disk_handle)); /* determine the correct biosset to load based on options.bios string */ system_bios = determine_bios_rom(Machine->gamedrv->bios); /* loop until we hit the end */ for (region = romp, regnum = 0; region; region = rom_next_region(region), regnum++) { int regiontype = ROMREGION_GETTYPE(region); debugload("Processing region %02X (length=%X)\n", regiontype, ROMREGION_GETLENGTH(region)); /* the first entry must be a region */ assert(ROMENTRY_ISREGION(region)); /* remember the base and length */ romdata.regionbase = new_memory_region(machine, regiontype, ROMREGION_GETLENGTH(region), ROMREGION_GETFLAGS(region)); romdata.regionlength = ROMREGION_GETLENGTH(region); debugload("Allocated %X bytes @ %08X\n", romdata.regionlength, (int)romdata.regionbase); /* clear the region if it's requested */ if (ROMREGION_ISERASE(region)) memset(romdata.regionbase, ROMREGION_GETERASEVAL(region), romdata.regionlength); /* or if it's sufficiently small (<= 4MB) */ else if (romdata.regionlength <= 0x400000) memset(romdata.regionbase, 0, romdata.regionlength); #ifdef MAME_DEBUG /* if we're debugging, fill region with random data to catch errors */ else fill_random(romdata.regionbase, romdata.regionlength); #endif /* now process the entries in the region */ if (ROMREGION_ISROMDATA(region)) process_rom_entries(&romdata, region + 1); else if (ROMREGION_ISDISKDATA(region)) process_disk_entries(&romdata, region + 1); /* add this region to the list */ if (regiontype < REGION_MAX) regionlist[regiontype] = region; } /* post-process the regions */ for (regnum = 0; regnum < REGION_MAX; regnum++) if (regionlist[regnum]) { debugload("Post-processing region %02X\n", regnum); romdata.regionlength = memory_region_length(regnum); romdata.regionbase = memory_region(regnum); region_post_process(&romdata, regionlist[regnum]); } /* display the results and exit */ total_rom_load_warnings = romdata.warnings; display_rom_load_results(&romdata); }