romload cleanups:

- added running_machine to internal structure, removed as explicit parameter
 - added new function rom_file_size() to compute the size of a ROM
 - removed rom_first_chunk() and rom_next_chunk() which are no longer needed
 - changed progress display to be based on size of ROMs loaded, not number
 - changed temporary load buffer to be dynamically allocated
 - fixed reload logic to handle skipped BIOSes

Also changed rand_memory() to use a fixed seed for consistent behavior.
This commit is contained in:
Aaron Giles 2009-01-02 19:20:55 +00:00
parent b7c652b8dd
commit 84618c3f7a
6 changed files with 252 additions and 203 deletions

View File

@ -329,7 +329,6 @@ int audit_summary(const game_driver *gamedrv, int count, const audit_record *rec
static int audit_one_rom(core_options *options, const rom_entry *rom, const char *regiontag, const game_driver *gamedrv, UINT32 validation, audit_record *record) static int audit_one_rom(core_options *options, const rom_entry *rom, const char *regiontag, const game_driver *gamedrv, UINT32 validation, audit_record *record)
{ {
const game_driver *drv; const game_driver *drv;
const rom_entry *chunk;
UINT32 crc = 0; UINT32 crc = 0;
UINT8 crcs[4]; UINT8 crcs[4];
int has_crc; int has_crc;
@ -339,10 +338,7 @@ static int audit_one_rom(core_options *options, const rom_entry *rom, const char
record->name = ROM_GETNAME(rom); record->name = ROM_GETNAME(rom);
record->exphash = ROM_GETHASHDATA(rom); record->exphash = ROM_GETHASHDATA(rom);
record->length = 0; record->length = 0;
record->explength = rom_file_size(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 */ /* see if we have a CRC and extract it if so */
has_crc = hash_data_extract_binary_checksum(record->exphash, HASH_CRC, crcs); has_crc = hash_data_extract_binary_checksum(record->exphash, HASH_CRC, crcs);

View File

@ -534,7 +534,7 @@ int cli_info_listroms(core_options *options, const char *gamename)
if (mame_strwildcmp(gamename, drivers[drvindex]->name) == 0) if (mame_strwildcmp(gamename, drivers[drvindex]->name) == 0)
{ {
machine_config *config = machine_config_alloc(drivers[drvindex]->machine_config); machine_config *config = machine_config_alloc(drivers[drvindex]->machine_config);
const rom_entry *region, *rom, *chunk; const rom_entry *region, *rom;
const rom_source *source; const rom_source *source;
/* print the header */ /* print the header */
@ -555,11 +555,7 @@ int cli_info_listroms(core_options *options, const char *gamename)
/* accumulate the total length of all chunks */ /* accumulate the total length of all chunks */
if (ROMREGION_ISROMDATA(region)) if (ROMREGION_ISROMDATA(region))
{ length = rom_file_size(rom);
length = 0;
for (chunk = rom_first_chunk(rom); chunk; chunk = rom_next_chunk(chunk))
length += ROM_GETLENGTH(chunk);
}
/* start with the name */ /* start with the name */
mame_printf_info("%-12s ", name); mame_printf_info("%-12s ", name);

View File

@ -386,19 +386,12 @@ static void print_game_rom(FILE *out, const game_driver *game, const machine_con
const char *name = ROM_GETNAME(rom); const char *name = ROM_GETNAME(rom);
int offset = ROM_GETOFFSET(rom); int offset = ROM_GETOFFSET(rom);
const rom_entry *parent_rom = NULL; const rom_entry *parent_rom = NULL;
const rom_entry *chunk;
char bios_name[100]; char bios_name[100];
int length;
/* BIOS ROMs only apply to bioses */ /* BIOS ROMs only apply to bioses */
if ((is_bios && rom_type != 0) || (!is_bios && rom_type == 0)) if ((is_bios && rom_type != 0) || (!is_bios && rom_type == 0))
continue; continue;
/* compute the total length of all chunks */
length = 0;
for (chunk = rom_first_chunk(rom); chunk; chunk = rom_next_chunk(chunk))
length += ROM_GETLENGTH(chunk);
/* if we have a valid ROM and we are a clone, see if we can find the parent ROM */ /* 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) if (!ROM_NOGOODDUMP(rom) && clone_of != NULL)
{ {
@ -443,7 +436,7 @@ static void print_game_rom(FILE *out, const game_driver *game, const machine_con
if (bios_name[0] != 0) if (bios_name[0] != 0)
fprintf(out, " bios=\"%s\"", xml_normalize_string(bios_name)); fprintf(out, " bios=\"%s\"", xml_normalize_string(bios_name));
if (!is_disk) if (!is_disk)
fprintf(out, " size=\"%d\"", length); fprintf(out, " size=\"%d\"", rom_file_size(rom));
/* dump checksum information only if there is a known dump */ /* dump checksum information only if there is a known dump */
if (!hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP)) if (!hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP))

View File

@ -22,6 +22,13 @@
#define LOG(x) do { if (LOG_LOAD) debugload x; } while(0) #define LOG(x) do { if (LOG_LOAD) debugload x; } while(0)
/***************************************************************************
CONSTANTS
***************************************************************************/
#define TEMPBUFFER_MAX_SIZE (1024 * 1024 * 1024)
/*************************************************************************** /***************************************************************************
TYPE DEFINITIONS TYPE DEFINITIONS
@ -30,11 +37,16 @@
typedef struct _rom_load_data rom_load_data; typedef struct _rom_load_data rom_load_data;
struct _rom_load_data struct _rom_load_data
{ {
running_machine *machine; /* machine object where needed */
int system_bios; /* the system BIOS we wish to load */
int warnings; /* warning count during processing */ int warnings; /* warning count during processing */
int errors; /* error count during processing */ int errors; /* error count during processing */
int romsloaded; /* current ROMs loaded count */ int romsloaded; /* current ROMs loaded count */
int romstotal; /* total number of ROMs to read */ int romstotal; /* total number of ROMs to read */
UINT32 romsloadedsize; /* total size of ROMs loaded so far */
UINT32 romstotalsize; /* total size of ROMs to read */
mame_file * file; /* current file */ mame_file * file; /* current file */
@ -42,7 +54,6 @@ struct _rom_load_data
UINT32 regionlength; /* length of current region */ UINT32 regionlength; /* length of current region */
astring * errorstring; /* error string */ astring * errorstring; /* error string */
UINT8 tempbuf[65536]; /* temporary buffer */
}; };
@ -67,9 +78,6 @@ struct _open_chd
static open_chd *chd_list; static open_chd *chd_list;
static open_chd **chd_list_tailptr; static open_chd **chd_list_tailptr;
/* system BIOS */
static int system_bios;
static int total_rom_load_warnings; static int total_rom_load_warnings;
@ -86,6 +94,11 @@ static void rom_exit(running_machine *machine);
HARD DISK HANDLING HARD DISK HANDLING
***************************************************************************/ ***************************************************************************/
/*-------------------------------------------------
get_disk_handle - return a pointer to the
CHD file associated with the given region
-------------------------------------------------*/
chd_file *get_disk_handle(const char *region) chd_file *get_disk_handle(const char *region)
{ {
open_chd *curdisk; open_chd *curdisk;
@ -97,6 +110,11 @@ chd_file *get_disk_handle(const char *region)
} }
/*-------------------------------------------------
set_disk_handle - set a pointer to the CHD
file associated with the given region
-------------------------------------------------*/
void set_disk_handle(const char *region, mame_file *file, chd_file *chdfile) void set_disk_handle(const char *region, mame_file *file, chd_file *chdfile)
{ {
open_chd chd = { 0 }; open_chd chd = { 0 };
@ -241,29 +259,6 @@ const rom_entry *rom_next_file(const rom_entry *romp)
} }
/*-------------------------------------------------
rom_first_chunk - return pointer to first ROM
chunk
-------------------------------------------------*/
const rom_entry *rom_first_chunk(const rom_entry *romp)
{
return (ROMENTRY_ISFILE(romp)) ? romp : NULL;
}
/*-------------------------------------------------
rom_next_chunk - return pointer to next ROM
chunk
-------------------------------------------------*/
const rom_entry *rom_next_chunk(const rom_entry *romp)
{
romp++;
return (ROMENTRY_ISCONTINUE(romp) || ROMENTRY_ISIGNORE(romp)) ? romp : NULL;
}
/*------------------------------------------------- /*-------------------------------------------------
rom_region_name - return the appropriate name rom_region_name - return the appropriate name
for a rom region for a rom region
@ -282,6 +277,34 @@ astring *rom_region_name(astring *result, const game_driver *drv, const rom_sour
} }
/*-------------------------------------------------
rom_file_size - return the expected size of a
file given the ROM description
-------------------------------------------------*/
UINT32 rom_file_size(const rom_entry *romp)
{
UINT32 maxlength = 0;
/* loop until we run out of reloads */
do
{
UINT32 curlength;
/* loop until we run out of continues/ignores */
curlength = ROM_GETLENGTH(romp++);
while (ROMENTRY_ISCONTINUE(romp) || ROMENTRY_ISIGNORE(romp))
curlength += ROM_GETLENGTH(romp++);
/* track the maximum length */
maxlength = MAX(maxlength, curlength);
}
while (ROMENTRY_ISRELOAD(romp));
return maxlength;
}
/*------------------------------------------------- /*-------------------------------------------------
debugload - log data to a file debugload - log data to a file
-------------------------------------------------*/ -------------------------------------------------*/
@ -308,22 +331,23 @@ static void CLIB_DECL ATTR_PRINTF(1,2) debugload(const char *string, ...)
from SystemBios structure and OPTION_BIOS from SystemBios structure and OPTION_BIOS
-------------------------------------------------*/ -------------------------------------------------*/
static int determine_bios_rom(rom_load_data *romdata, const rom_entry *romp) static void determine_bios_rom(rom_load_data *romdata)
{ {
const char *specbios = options_get_string(mame_options(), OPTION_BIOS); const char *specbios = options_get_string(mame_options(), OPTION_BIOS);
const char *defaultname = NULL; const char *defaultname = NULL;
const rom_entry *rom; const rom_entry *rom;
int default_no = 1; int default_no = 1;
int bios_count = 0; int bios_count = 0;
int bios_no = 0;
romdata->system_bios = 0;
/* first determine the default BIOS name */ /* first determine the default BIOS name */
for (rom = romp; !ROMENTRY_ISEND(rom); rom++) for (rom = romdata->machine->gamedrv->rom; !ROMENTRY_ISEND(rom); rom++)
if (ROMENTRY_ISDEFAULT_BIOS(rom)) if (ROMENTRY_ISDEFAULT_BIOS(rom))
defaultname = ROM_GETNAME(rom); defaultname = ROM_GETNAME(rom);
/* look for a BIOS with a matching name */ /* look for a BIOS with a matching name */
for (rom = romp; !ROMENTRY_ISEND(rom); rom++) for (rom = romdata->machine->gamedrv->rom; !ROMENTRY_ISEND(rom); rom++)
if (ROMENTRY_ISSYSTEM_BIOS(rom)) if (ROMENTRY_ISSYSTEM_BIOS(rom))
{ {
const char *biosname = ROM_GETNAME(rom); const char *biosname = ROM_GETNAME(rom);
@ -333,28 +357,27 @@ static int determine_bios_rom(rom_load_data *romdata, const rom_entry *romp)
/* Allow '-bios n' to still be used */ /* Allow '-bios n' to still be used */
sprintf(bios_number, "%d", bios_flags - 1); sprintf(bios_number, "%d", bios_flags - 1);
if (strcmp(bios_number, specbios) == 0 || strcmp(biosname, specbios) == 0) if (strcmp(bios_number, specbios) == 0 || strcmp(biosname, specbios) == 0)
bios_no = bios_flags; romdata->system_bios = bios_flags;
if (defaultname != NULL && strcmp(biosname, defaultname) == 0) if (defaultname != NULL && strcmp(biosname, defaultname) == 0)
default_no = bios_flags; default_no = bios_flags;
bios_count++; bios_count++;
} }
/* if none found, use the default */ /* if none found, use the default */
if (bios_no == 0 && bios_count > 0) if (romdata->system_bios == 0 && bios_count > 0)
{ {
/* if we got neither an empty string nor 'default' then warn the user */ /* if we got neither an empty string nor 'default' then warn the user */
if (specbios[0] != 0 && strcmp(specbios, "default") != 0) if (specbios[0] != 0 && strcmp(specbios, "default") != 0 && romdata != NULL)
{ {
astring_catprintf(romdata->errorstring, "%s: invalid bios\n", specbios); astring_catprintf(romdata->errorstring, "%s: invalid bios\n", specbios);
romdata->warnings++; romdata->warnings++;
} }
/* set to default */ /* set to default */
bios_no = default_no; romdata->system_bios = default_no;
} }
LOG(("Using System BIOS: %d\n", bios_no)); LOG(("Using System BIOS: %d\n", romdata->system_bios));
return bios_no;
} }
@ -363,24 +386,24 @@ static int determine_bios_rom(rom_load_data *romdata, const rom_entry *romp)
that will need to be loaded that will need to be loaded
-------------------------------------------------*/ -------------------------------------------------*/
static int count_roms(running_machine *machine) static void count_roms(rom_load_data *romdata)
{ {
const rom_entry *region, *rom; const rom_entry *region, *rom;
const rom_source *source; const rom_source *source;
int count = 0;
/* start with 0 */
romdata->romstotal = 0;
romdata->romstotalsize = 0;
/* loop over regions, then over files */ /* loop over regions, then over files */
for (source = rom_first_source(machine->gamedrv, machine->config); source != NULL; source = rom_next_source(machine->gamedrv, machine->config, source)) for (source = rom_first_source(romdata->machine->gamedrv, romdata->machine->config); source != NULL; source = rom_next_source(romdata->machine->gamedrv, romdata->machine->config, source))
for (region = rom_first_region(machine->gamedrv, source); region != NULL; region = rom_next_region(region)) for (region = rom_first_region(romdata->machine->gamedrv, source); region != NULL; region = rom_next_region(region))
for (rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom)) for (rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom))
if (ROM_GETBIOSFLAGS(rom) == 0 || ROM_GETBIOSFLAGS(rom) == romdata->system_bios)
{ {
int bios_flags = ROM_GETBIOSFLAGS(rom); romdata->romstotal++;
if (!bios_flags || (bios_flags == system_bios)) /* alternate bios sets */ romdata->romstotalsize += rom_file_size(rom);
count++;
} }
/* return the total count */
return count;
} }
@ -432,7 +455,7 @@ static void handle_missing_file(rom_load_data *romdata, const rom_entry *romp)
correct checksums for a given ROM correct checksums for a given ROM
-------------------------------------------------*/ -------------------------------------------------*/
static void dump_wrong_and_correct_checksums(rom_load_data* romdata, const char* hash, const char* acthash) static void dump_wrong_and_correct_checksums(rom_load_data *romdata, const char *hash, const char *acthash)
{ {
unsigned i; unsigned i;
char chksum[256]; char chksum[256];
@ -480,13 +503,13 @@ static void dump_wrong_and_correct_checksums(rom_load_data* romdata, const char*
and hash signatures of a file and hash signatures of a file
-------------------------------------------------*/ -------------------------------------------------*/
static void verify_length_and_hash(rom_load_data *romdata, const char *name, UINT32 explength, const char* hash) static void verify_length_and_hash(rom_load_data *romdata, const char *name, UINT32 explength, const char *hash)
{ {
UINT32 actlength; UINT32 actlength;
const char* acthash; const char* acthash;
/* we've already complained if there is no file */ /* we've already complained if there is no file */
if (!romdata->file) if (romdata->file == NULL)
return; return;
/* get the length and CRC from the file */ /* get the length and CRC from the file */
@ -530,16 +553,16 @@ static void verify_length_and_hash(rom_load_data *romdata, const char *name, UIN
messages about ROM loading to the user messages about ROM loading to the user
-------------------------------------------------*/ -------------------------------------------------*/
static void display_loading_rom_message(running_machine *machine, const char *name, rom_load_data *romdata) static void display_loading_rom_message(rom_load_data *romdata, const char *name)
{ {
char buffer[200]; char buffer[200];
if (name != NULL) if (name != NULL)
sprintf(buffer, "Loading (%d%%)", 100 * romdata->romsloaded / romdata->romstotal); sprintf(buffer, "Loading (%d%%)", (UINT32)(100 * (UINT64)romdata->romsloadedsize / (UINT64)romdata->romstotalsize));
else else
sprintf(buffer, "Loading Complete"); sprintf(buffer, "Loading Complete");
ui_set_startup_text(machine, buffer, FALSE); ui_set_startup_text(romdata->machine, buffer, FALSE);
} }
@ -548,10 +571,10 @@ static void display_loading_rom_message(running_machine *machine, const char *na
results of ROM loading results of ROM loading
-------------------------------------------------*/ -------------------------------------------------*/
static void display_rom_load_results(running_machine *machine, rom_load_data *romdata) static void display_rom_load_results(rom_load_data *romdata)
{ {
/* final status display */ /* final status display */
display_loading_rom_message(machine, NULL, romdata); display_loading_rom_message(romdata, NULL);
/* if we had errors, they are fatal */ /* if we had errors, they are fatal */
if (romdata->errors != 0) if (romdata->errors != 0)
@ -559,16 +582,16 @@ static void display_rom_load_results(running_machine *machine, rom_load_data *ro
const char *rgntag, *nextrgntag; const char *rgntag, *nextrgntag;
/* clean up any regions */ /* clean up any regions */
for (rgntag = memory_region_next(machine, NULL); rgntag != NULL; rgntag = nextrgntag) for (rgntag = memory_region_next(romdata->machine, NULL); rgntag != NULL; rgntag = nextrgntag)
{ {
nextrgntag = memory_region_next(machine, rgntag); nextrgntag = memory_region_next(romdata->machine, rgntag);
memory_region_free(machine, rgntag); memory_region_free(romdata->machine, rgntag);
} }
/* create the error message and exit fatally */ /* create the error message and exit fatally */
mame_printf_error("%s", astring_c(romdata->errorstring)); mame_printf_error("%s", astring_c(romdata->errorstring));
astring_free(romdata->errorstring); astring_free(romdata->errorstring);
fatalerror_exitcode(machine, MAMERR_MISSING_FILES, "ERROR: required files are missing, the "GAMENOUN" cannot be run."); fatalerror_exitcode(romdata->machine, MAMERR_MISSING_FILES, "ERROR: required files are missing, the "GAMENOUN" cannot be run.");
} }
/* if we had warnings, output them, but continue */ /* if we had warnings, output them, but continue */
@ -585,11 +608,11 @@ static void display_rom_load_results(running_machine *machine, rom_load_data *ro
byte swapping and inverting data as necessary byte swapping and inverting data as necessary
-------------------------------------------------*/ -------------------------------------------------*/
static void region_post_process(running_machine *machine, rom_load_data *romdata, const char *rgntag) static void region_post_process(rom_load_data *romdata, const char *rgntag)
{ {
UINT32 regionlength = memory_region_length(machine, rgntag); UINT32 regionlength = memory_region_length(romdata->machine, rgntag);
UINT32 regionflags = memory_region_flags(machine, rgntag); UINT32 regionflags = memory_region_flags(romdata->machine, rgntag);
UINT8 *regionbase = memory_region(machine, rgntag); UINT8 *regionbase = memory_region(romdata->machine, rgntag);
int littleendian = ((regionflags & ROMREGION_ENDIANMASK) == ROMREGION_LE); int littleendian = ((regionflags & ROMREGION_ENDIANMASK) == ROMREGION_LE);
int datawidth = 1 << ((regionflags & ROMREGION_WIDTHMASK) >> 8); int datawidth = 1 << ((regionflags & ROMREGION_WIDTHMASK) >> 8);
UINT8 *base; UINT8 *base;
@ -629,17 +652,17 @@ static void region_post_process(running_machine *machine, rom_load_data *romdata
up the parent and loading by checksum up the parent and loading by checksum
-------------------------------------------------*/ -------------------------------------------------*/
static int open_rom_file(running_machine *machine, rom_load_data *romdata, const char *regiontag, const rom_entry *romp) static int open_rom_file(rom_load_data *romdata, const char *regiontag, const rom_entry *romp)
{ {
file_error filerr = FILERR_NOT_FOUND; file_error filerr = FILERR_NOT_FOUND;
UINT32 romsize = rom_file_size(romp);
const game_driver *drv; const game_driver *drv;
int has_crc = FALSE; int has_crc = FALSE;
UINT8 crcbytes[4]; UINT8 crcbytes[4];
UINT32 crc = 0; UINT32 crc = 0;
/* update status display */ /* update status display */
++romdata->romsloaded; display_loading_rom_message(romdata, ROM_GETNAME(romp));
display_loading_rom_message(machine, ROM_GETNAME(romp), romdata);
/* extract CRC to use for searching */ /* extract CRC to use for searching */
has_crc = hash_data_extract_binary_checksum(ROM_GETHASHDATA(romp), HASH_CRC, crcbytes); has_crc = hash_data_extract_binary_checksum(ROM_GETHASHDATA(romp), HASH_CRC, crcbytes);
@ -649,7 +672,7 @@ static int open_rom_file(running_machine *machine, rom_load_data *romdata, const
/* attempt reading up the chain through the parents. It automatically also /* attempt reading up the chain through the parents. It automatically also
attempts any kind of load by checksum supported by the archives. */ attempts any kind of load by checksum supported by the archives. */
romdata->file = NULL; romdata->file = NULL;
for (drv = machine->gamedrv; romdata->file == NULL && drv != NULL; drv = driver_get_clone(drv)) for (drv = romdata->machine->gamedrv; romdata->file == NULL && drv != NULL; drv = driver_get_clone(drv))
if (drv->name != NULL && *drv->name != 0) if (drv->name != NULL && *drv->name != 0)
{ {
astring *fname = astring_assemble_3(astring_alloc(), drv->name, PATH_SEPARATOR, ROM_GETNAME(romp)); astring *fname = astring_assemble_3(astring_alloc(), drv->name, PATH_SEPARATOR, ROM_GETNAME(romp));
@ -671,6 +694,10 @@ static int open_rom_file(running_machine *machine, rom_load_data *romdata, const
astring_free(fname); astring_free(fname);
} }
/* update counters */
romdata->romsloaded++;
romdata->romsloadedsize += romsize;
/* return the result */ /* return the result */
return (filerr == FILERR_NONE); return (filerr == FILERR_NONE);
} }
@ -681,15 +708,15 @@ static int open_rom_file(running_machine *machine, rom_load_data *romdata, const
random data for a NULL file random data for a NULL file
-------------------------------------------------*/ -------------------------------------------------*/
static int rom_fread(running_machine *machine, rom_load_data *romdata, UINT8 *buffer, int length) static int rom_fread(rom_load_data *romdata, UINT8 *buffer, int length)
{ {
/* files just pass through */ /* files just pass through */
if (romdata->file) if (romdata->file != NULL)
return mame_fread(romdata->file, buffer, length); return mame_fread(romdata->file, buffer, length);
/* otherwise, fill with randomness */ /* otherwise, fill with randomness */
else else
fill_random(machine, buffer, length); fill_random(romdata->machine, buffer, length);
return length; return length;
} }
@ -700,7 +727,7 @@ static int rom_fread(running_machine *machine, rom_load_data *romdata, UINT8 *bu
entry entry
-------------------------------------------------*/ -------------------------------------------------*/
static int read_rom_data(running_machine *machine, rom_load_data *romdata, const rom_entry *romp) static int read_rom_data(rom_load_data *romdata, const rom_entry *romp)
{ {
int datashift = ROM_GETBITSHIFT(romp); int datashift = ROM_GETBITSHIFT(romp);
int datamask = ((1 << ROM_GETBITWIDTH(romp)) - 1) << datashift; int datamask = ((1 << ROM_GETBITWIDTH(romp)) - 1) << datashift;
@ -710,6 +737,8 @@ static int read_rom_data(running_machine *machine, rom_load_data *romdata, const
int reversed = ROM_ISREVERSED(romp); int reversed = ROM_ISREVERSED(romp);
int numgroups = (numbytes + groupsize - 1) / groupsize; int numgroups = (numbytes + groupsize - 1) / groupsize;
UINT8 *base = romdata->regionbase + ROM_GETOFFSET(romp); UINT8 *base = romdata->regionbase + ROM_GETOFFSET(romp);
UINT32 tempbufsize;
UINT8 *tempbuf;
int i; 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)); 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));
@ -728,20 +757,27 @@ static int read_rom_data(running_machine *machine, rom_load_data *romdata, const
/* special case for simple loads */ /* special case for simple loads */
if (datamask == 0xff && (groupsize == 1 || !reversed) && skip == 0) if (datamask == 0xff && (groupsize == 1 || !reversed) && skip == 0)
return rom_fread(machine, romdata, base, numbytes); return rom_fread(romdata, base, numbytes);
/* use a temporary buffer for complex loads */
tempbufsize = MIN(TEMPBUFFER_MAX_SIZE, numbytes);
tempbuf = malloc_or_die(tempbufsize);
/* chunky reads for complex loads */ /* chunky reads for complex loads */
skip += groupsize; skip += groupsize;
while (numbytes) while (numbytes > 0)
{ {
int evengroupcount = (sizeof(romdata->tempbuf) / groupsize) * groupsize; int evengroupcount = (tempbufsize / groupsize) * groupsize;
int bytesleft = (numbytes > evengroupcount) ? evengroupcount : numbytes; int bytesleft = (numbytes > evengroupcount) ? evengroupcount : numbytes;
UINT8 *bufptr = romdata->tempbuf; UINT8 *bufptr = tempbuf;
/* read as much as we can */ /* read as much as we can */
LOG((" Reading %X bytes into buffer\n", bytesleft)); LOG((" Reading %X bytes into buffer\n", bytesleft));
if (rom_fread(machine, romdata, romdata->tempbuf, bytesleft) != bytesleft) if (rom_fread(romdata, bufptr, bytesleft) != bytesleft)
{
free(tempbuf);
return 0; return 0;
}
numbytes -= bytesleft; numbytes -= bytesleft;
LOG((" Copying to %p\n", base)); LOG((" Copying to %p\n", base));
@ -800,6 +836,8 @@ static int read_rom_data(running_machine *machine, rom_load_data *romdata, const
} }
} }
} }
free(tempbuf);
LOG((" All done\n")); LOG((" All done\n"));
return ROM_GETLENGTH(romp); return ROM_GETLENGTH(romp);
} }
@ -831,7 +869,7 @@ static void fill_rom_data(rom_load_data *romdata, const rom_entry *romp)
copy_rom_data - copy a region of ROM space copy_rom_data - copy a region of ROM space
-------------------------------------------------*/ -------------------------------------------------*/
static void copy_rom_data(running_machine *machine, rom_load_data *romdata, const rom_entry *romp) static void copy_rom_data(rom_load_data *romdata, const rom_entry *romp)
{ {
UINT8 *base = romdata->regionbase + ROM_GETOFFSET(romp); UINT8 *base = romdata->regionbase + ROM_GETOFFSET(romp);
const char *srcrgntag = ROM_GETNAME(romp); const char *srcrgntag = ROM_GETNAME(romp);
@ -848,12 +886,12 @@ static void copy_rom_data(running_machine *machine, rom_load_data *romdata, cons
fatalerror("Error in RomModule definition: COPY has an invalid length\n"); fatalerror("Error in RomModule definition: COPY has an invalid length\n");
/* make sure the source was valid */ /* make sure the source was valid */
srcbase = memory_region(machine, srcrgntag); srcbase = memory_region(romdata->machine, srcrgntag);
if (srcbase == NULL) if (srcbase == NULL)
fatalerror("Error in RomModule definition: COPY from an invalid region\n"); fatalerror("Error in RomModule definition: COPY from an invalid region\n");
/* make sure we find within the region space */ /* make sure we find within the region space */
if (srcoffs + numbytes > memory_region_length(machine, srcrgntag)) if (srcoffs + numbytes > memory_region_length(romdata->machine, srcrgntag))
fatalerror("Error in RomModule definition: COPY out of source memory region space\n"); fatalerror("Error in RomModule definition: COPY out of source memory region space\n");
/* fill the data */ /* fill the data */
@ -866,7 +904,7 @@ static void copy_rom_data(running_machine *machine, rom_load_data *romdata, cons
for a region for a region
-------------------------------------------------*/ -------------------------------------------------*/
static void process_rom_entries(running_machine *machine, rom_load_data *romdata, const char *regiontag, const rom_entry *romp) static void process_rom_entries(rom_load_data *romdata, const char *regiontag, const rom_entry *romp)
{ {
UINT32 lastflags = 0; UINT32 lastflags = 0;
@ -891,20 +929,18 @@ static void process_rom_entries(running_machine *machine, rom_load_data *romdata
/* handle copies */ /* handle copies */
else if (ROMENTRY_ISCOPY(romp)) else if (ROMENTRY_ISCOPY(romp))
copy_rom_data(machine, romdata, romp++); copy_rom_data(romdata, romp++);
/* handle files */ /* handle files */
else if (ROMENTRY_ISFILE(romp)) else if (ROMENTRY_ISFILE(romp))
{ {
int bios_flags = ROM_GETBIOSFLAGS(romp); int irrelevantbios = (ROM_GETBIOSFLAGS(romp) != 0 && ROM_GETBIOSFLAGS(romp) != romdata->system_bios);
if (!bios_flags || (bios_flags == system_bios)) /* alternate bios sets */
{
const rom_entry *baserom = romp; const rom_entry *baserom = romp;
int explength = 0; int explength = 0;
/* open the file */ /* open the file if it is a non-BIOS or matches the current BIOS */
LOG(("Opening ROM file: %s\n", ROM_GETNAME(romp))); LOG(("Opening ROM file: %s\n", ROM_GETNAME(romp)));
if (!open_rom_file(machine, romdata, regiontag, romp)) if (!irrelevantbios && !open_rom_file(romdata, regiontag, romp))
handle_missing_file(romdata, romp); handle_missing_file(romdata, romp);
/* loop until we run out of reloads */ /* loop until we run out of reloads */
@ -925,8 +961,8 @@ static void process_rom_entries(running_machine *machine, rom_load_data *romdata
explength += ROM_GETLENGTH(&modified_romp); explength += ROM_GETLENGTH(&modified_romp);
/* attempt to read using the modified entry */ /* attempt to read using the modified entry */
if (!ROMENTRY_ISIGNORE(&modified_romp)) if (!ROMENTRY_ISIGNORE(&modified_romp) && !irrelevantbios)
readresult = read_rom_data(machine, romdata, &modified_romp); readresult = read_rom_data(romdata, &modified_romp);
} }
while (ROMENTRY_ISCONTINUE(romp) || ROMENTRY_ISIGNORE(romp)); while (ROMENTRY_ISCONTINUE(romp) || ROMENTRY_ISIGNORE(romp));
@ -939,7 +975,7 @@ static void process_rom_entries(running_machine *machine, rom_load_data *romdata
} }
/* reseek to the start and clear the baserom so we don't reverify */ /* reseek to the start and clear the baserom so we don't reverify */
if (romdata->file) if (romdata->file != NULL)
mame_fseek(romdata->file, 0, SEEK_SET); mame_fseek(romdata->file, 0, SEEK_SET);
baserom = NULL; baserom = NULL;
explength = 0; explength = 0;
@ -947,7 +983,7 @@ static void process_rom_entries(running_machine *machine, rom_load_data *romdata
while (ROMENTRY_ISRELOAD(romp)); while (ROMENTRY_ISRELOAD(romp));
/* close the file */ /* close the file */
if (romdata->file) if (romdata->file != NULL)
{ {
LOG(("Closing ROM file\n")); LOG(("Closing ROM file\n"));
mame_fclose(romdata->file); mame_fclose(romdata->file);
@ -955,11 +991,6 @@ static void process_rom_entries(running_machine *machine, rom_load_data *romdata
} }
} }
else else
{
romp++; /* skip over file */
}
}
else
{ {
romp++; /* something else; skip */ romp++; /* something else; skip */
} }
@ -968,7 +999,7 @@ static void process_rom_entries(running_machine *machine, rom_load_data *romdata
/*------------------------------------------------- /*-------------------------------------------------
open_disk_image - open a DISK image, searching open_disk_image - open a disk image, searching
up the parent and loading by checksum up the parent and loading by checksum
-------------------------------------------------*/ -------------------------------------------------*/
@ -979,8 +1010,9 @@ chd_error open_disk_image(const game_driver *gamedrv, const rom_entry *romp, mam
/*------------------------------------------------- /*-------------------------------------------------
open_disk_image_options - open a DISK image, searching open_disk_image_options - open a disk image,
up the parent and loading by checksum searching up the parent and loading by
checksum
-------------------------------------------------*/ -------------------------------------------------*/
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) 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)
@ -1111,7 +1143,7 @@ done:
for a region for a region
-------------------------------------------------*/ -------------------------------------------------*/
static void process_disk_entries(running_machine *machine, rom_load_data *romdata, const char *regiontag, const rom_entry *romp) static void process_disk_entries(rom_load_data *romdata, const char *regiontag, const rom_entry *romp)
{ {
astring *filename = astring_alloc(); astring *filename = astring_alloc();
@ -1134,7 +1166,7 @@ static void process_disk_entries(running_machine *machine, rom_load_data *romdat
/* first open the source drive */ /* first open the source drive */
LOG(("Opening disk image: %s\n", astring_c(filename))); LOG(("Opening disk image: %s\n", astring_c(filename)));
err = open_disk_image(machine->gamedrv, romp, &chd.origfile, &chd.origchd); err = open_disk_image(romdata->machine->gamedrv, romp, &chd.origfile, &chd.origchd);
if (err != CHDERR_NONE) if (err != CHDERR_NONE)
{ {
if (err == CHDERR_FILE_NOT_FOUND) if (err == CHDERR_FILE_NOT_FOUND)
@ -1173,7 +1205,7 @@ static void process_disk_entries(running_machine *machine, rom_load_data *romdat
if (!DISK_ISREADONLY(romp)) if (!DISK_ISREADONLY(romp))
{ {
/* try to open or create the diff */ /* try to open or create the diff */
err = open_disk_diff(machine->gamedrv, romp, chd.origchd, &chd.difffile, &chd.diffchd); err = open_disk_diff(romdata->machine->gamedrv, romp, chd.origchd, &chd.difffile, &chd.diffchd);
if (err != CHDERR_NONE) if (err != CHDERR_NONE)
{ {
astring_catprintf(romdata->errorstring, "%s DIFF CHD ERROR: %s\n", astring_c(filename), chd_error_string(err)); astring_catprintf(romdata->errorstring, "%s DIFF CHD ERROR: %s\n", astring_c(filename), chd_error_string(err));
@ -1232,31 +1264,31 @@ static UINT32 normalize_flags_for_cpu(running_machine *machine, UINT32 startflag
process_region_list - process a region list process_region_list - process a region list
-------------------------------------------------*/ -------------------------------------------------*/
static void process_region_list(running_machine *machine, rom_load_data *romdata) static void process_region_list(rom_load_data *romdata)
{ {
astring *regiontag = astring_alloc(); astring *regiontag = astring_alloc();
const rom_source *source; const rom_source *source;
const rom_entry *region; const rom_entry *region;
/* loop until we hit the end */ /* loop until we hit the end */
for (source = rom_first_source(machine->gamedrv, machine->config); source != NULL; source = rom_next_source(machine->gamedrv, machine->config, source)) for (source = rom_first_source(romdata->machine->gamedrv, romdata->machine->config); source != NULL; source = rom_next_source(romdata->machine->gamedrv, romdata->machine->config, source))
for (region = rom_first_region(machine->gamedrv, source); region != NULL; region = rom_next_region(region)) for (region = rom_first_region(romdata->machine->gamedrv, source); region != NULL; region = rom_next_region(region))
{ {
UINT32 regionlength = ROMREGION_GETLENGTH(region); UINT32 regionlength = ROMREGION_GETLENGTH(region);
UINT32 regionflags = ROMREGION_GETFLAGS(region); UINT32 regionflags = ROMREGION_GETFLAGS(region);
rom_region_name(regiontag, machine->gamedrv, source, region); rom_region_name(regiontag, romdata->machine->gamedrv, source, region);
LOG(("Processing region \"%s\" (length=%X)\n", astring_c(regiontag), regionlength)); LOG(("Processing region \"%s\" (length=%X)\n", astring_c(regiontag), regionlength));
/* the first entry must be a region */ /* the first entry must be a region */
assert(ROMENTRY_ISREGION(region)); assert(ROMENTRY_ISREGION(region));
/* if this is a CPU region, override with the CPU width and endianness */ /* if this is a CPU region, override with the CPU width and endianness */
if (cputag_get_cpu(machine, astring_c(regiontag)) != NULL) if (cputag_get_cpu(romdata->machine, astring_c(regiontag)) != NULL)
regionflags = normalize_flags_for_cpu(machine, regionflags, astring_c(regiontag)); regionflags = normalize_flags_for_cpu(romdata->machine, regionflags, astring_c(regiontag));
/* remember the base and length */ /* remember the base and length */
romdata->regionbase = memory_region_alloc(machine, astring_c(regiontag), regionlength, regionflags); romdata->regionbase = memory_region_alloc(romdata->machine, astring_c(regiontag), regionlength, regionflags);
romdata->regionlength = regionlength; romdata->regionlength = regionlength;
LOG(("Allocated %X bytes @ %p\n", romdata->regionlength, romdata->regionbase)); LOG(("Allocated %X bytes @ %p\n", romdata->regionlength, romdata->regionbase));
@ -1268,31 +1300,31 @@ static void process_region_list(running_machine *machine, rom_load_data *romdata
else if (romdata->regionlength <= 0x400000) else if (romdata->regionlength <= 0x400000)
memset(romdata->regionbase, 0, romdata->regionlength); memset(romdata->regionbase, 0, romdata->regionlength);
#ifdef MAME_DEBUG #ifdef MAME_DEBUG
/* if we're debugging, fill region with random data to catch errors */ /* if we're debugging, fill region with random data to catch errors */
else else
fill_random(machine, romdata->regionbase, romdata->regionlength); fill_random(romdata->machine, romdata->regionbase, romdata->regionlength);
#endif #endif
/* now process the entries in the region */ /* now process the entries in the region */
if (ROMREGION_ISROMDATA(region)) if (ROMREGION_ISROMDATA(region))
process_rom_entries(machine, romdata, ROMREGION_ISLOADBYNAME(region) ? ROMREGION_GETTAG(region) : NULL, region + 1); process_rom_entries(romdata, ROMREGION_ISLOADBYNAME(region) ? ROMREGION_GETTAG(region) : NULL, region + 1);
else if (ROMREGION_ISDISKDATA(region)) else if (ROMREGION_ISDISKDATA(region))
process_disk_entries(machine, romdata, ROMREGION_GETTAG(region), region + 1); process_disk_entries(romdata, ROMREGION_GETTAG(region), region + 1);
} }
/* now go back and post-process all the regions */ /* now go back and post-process all the regions */
for (source = rom_first_source(machine->gamedrv, machine->config); source != NULL; source = rom_next_source(machine->gamedrv, machine->config, source)) for (source = rom_first_source(romdata->machine->gamedrv, romdata->machine->config); source != NULL; source = rom_next_source(romdata->machine->gamedrv, romdata->machine->config, source))
for (region = rom_first_region(machine->gamedrv, source); region != NULL; region = rom_next_region(region)) for (region = rom_first_region(romdata->machine->gamedrv, source); region != NULL; region = rom_next_region(region))
region_post_process(machine, romdata, ROMREGION_GETTAG(region)); region_post_process(romdata, ROMREGION_GETTAG(region));
astring_free(regiontag); astring_free(regiontag);
} }
/*------------------------------------------------- /*-------------------------------------------------
rom_init - new, more flexible ROM rom_init - load the ROMs and open the disk
loading system images associated with the given machine
-------------------------------------------------*/ -------------------------------------------------*/
void rom_init(running_machine *machine) void rom_init(running_machine *machine)
@ -1304,24 +1336,25 @@ void rom_init(running_machine *machine)
/* reset the romdata struct */ /* reset the romdata struct */
memset(&romdata, 0, sizeof(romdata)); memset(&romdata, 0, sizeof(romdata));
romdata.machine = machine;
romdata.errorstring = astring_alloc(); romdata.errorstring = astring_alloc();
/* determine the correct biosset to load based on OPTION_BIOS string */ /* figure out which BIOS we are using */
system_bios = determine_bios_rom(&romdata, machine->gamedrv->rom); determine_bios_rom(&romdata);
/* count the total number of ROMs */ /* count the total number of ROMs */
romdata.romstotal = count_roms(machine); count_roms(&romdata);
/* reset the disk list */ /* reset the disk list */
chd_list = NULL; chd_list = NULL;
chd_list_tailptr = &chd_list; chd_list_tailptr = &chd_list;
/* process the ROM entries we were passed */ /* process the ROM entries we were passed */
process_region_list(machine, &romdata); process_region_list(&romdata);
/* display the results and exit */ /* display the results and exit */
total_rom_load_warnings = romdata.warnings; total_rom_load_warnings = romdata.warnings;
display_rom_load_results(machine, &romdata); display_rom_load_results(&romdata);
astring_free(romdata.errorstring); astring_free(romdata.errorstring);
} }

View File

@ -271,25 +271,61 @@ struct _rom_entry
FUNCTION PROTOTYPES FUNCTION PROTOTYPES
***************************************************************************/ ***************************************************************************/
/* disk handling */
chd_error open_disk_image(const game_driver *gamedrv, const rom_entry *romp, mame_file **image_file, chd_file **image_chd);
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);
chd_file *get_disk_handle(const char *region);
void set_disk_handle(const char *region, mame_file *file, chd_file *chd);
/* ROM processing */ /* ----- ROM processing ----- */
/* load the ROMs and open the disk images associated with the given machine */
void rom_init(running_machine *machine); void rom_init(running_machine *machine);
int rom_load_warnings(void);
const rom_source *rom_first_source(const game_driver *drv, const machine_config *config);
const rom_source *rom_next_source(const game_driver *drv, const machine_config *config, const rom_source *previous);
const rom_entry *rom_first_region(const game_driver *drv, const rom_source *romp);
const rom_entry *rom_next_region(const rom_entry *romp);
const rom_entry *rom_first_file(const rom_entry *romp);
const rom_entry *rom_next_file(const rom_entry *romp);
const rom_entry *rom_first_chunk(const rom_entry *romp);
const rom_entry *rom_next_chunk(const rom_entry *romp);
/* return the number of warnings we generated */
int rom_load_warnings(void);
/* ----- ROM iteration ----- */
/* return pointer to first ROM source */
const rom_source *rom_first_source(const game_driver *drv, const machine_config *config);
/* return pointer to next ROM source */
const rom_source *rom_next_source(const game_driver *drv, const machine_config *config, const rom_source *previous);
/* return pointer to the first ROM region within a source */
const rom_entry *rom_first_region(const game_driver *drv, const rom_source *romp);
/* return pointer to the next ROM region within a source */
const rom_entry *rom_next_region(const rom_entry *romp);
/* return pointer to the first ROM file within a region */
const rom_entry *rom_first_file(const rom_entry *romp);
/* return pointer to the next ROM file within a region */
const rom_entry *rom_next_file(const rom_entry *romp);
/* return TRUE if the given rom_source refers to the game driver itself */
int rom_source_is_gamedrv(const game_driver *drv, const rom_source *source); int rom_source_is_gamedrv(const game_driver *drv, const rom_source *source);
/* return the expected size of a file given the ROM description */
UINT32 rom_file_size(const rom_entry *romp);
/* return the appropriate name for a rom region */
astring *rom_region_name(astring *result, const game_driver *drv, const rom_source *source, const rom_entry *romp); astring *rom_region_name(astring *result, const game_driver *drv, const rom_source *source, const rom_entry *romp);
/* ----- disk handling ----- */
/* open a disk image, searching up the parent and loading by checksum */
chd_error open_disk_image(const game_driver *gamedrv, const rom_entry *romp, mame_file **image_file, chd_file **image_chd);
/* open a disk image, searching up the parent and loading by checksum */
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);
/* return a pointer to the CHD file associated with the given region */
chd_file *get_disk_handle(const char *region);
/* set a pointer to the CHD file associated with the given region */
void set_disk_handle(const char *region, mame_file *file, chd_file *chd);
#endif /* __ROMLOAD_H__ */ #endif /* __ROMLOAD_H__ */

View File

@ -85,18 +85,13 @@ int gregorian_days_in_month(int month, int year)
void rand_memory(void *memory, size_t length) void rand_memory(void *memory, size_t length)
{ {
static UINT32 seed = 0;
UINT8 *bytes = (UINT8 *) memory; UINT8 *bytes = (UINT8 *) memory;
UINT32 currand;
size_t i; size_t i;
currand = rand();
currand <<= 15;
currand ^= rand();
for (i = 0; i < length; i++) for (i = 0; i < length; i++)
{ {
currand = currand * 214013 + 2531011; seed = seed * 214013 + 2531011;
bytes[i] = (UINT8) (currand >> 16); bytes[i] = (UINT8) (seed >> 16);
} }
} }