Removed a couple of unnecessary typedefs from mamecore.h.

Updated romload to use an astring for accumulating errors (I always feared
busting that buffer with some huge romlist).
This commit is contained in:
Aaron Giles 2009-01-02 17:26:37 +00:00
parent 74d7495dbc
commit b7c652b8dd
3 changed files with 49 additions and 44 deletions

View File

@ -60,11 +60,8 @@ typedef UINT32 FPTR;
/* These are forward struct declarations that are used to break /* These are forward struct declarations that are used to break
circular dependencies in the code */ circular dependencies in the code */
typedef struct _running_machine running_machine; typedef struct _running_machine running_machine;
typedef struct _mame_display mame_display;
typedef struct _game_driver game_driver; typedef struct _game_driver game_driver;
typedef struct _machine_config machine_config; typedef struct _machine_config machine_config;
typedef struct _rom_load_data rom_load_data;
typedef struct _osd_create_params osd_create_params;
typedef struct _gfx_element gfx_element; typedef struct _gfx_element gfx_element;
typedef struct _mame_file mame_file; typedef struct _mame_file mame_file;

View File

@ -27,6 +27,25 @@
TYPE DEFINITIONS TYPE DEFINITIONS
***************************************************************************/ ***************************************************************************/
typedef struct _rom_load_data rom_load_data;
struct _rom_load_data
{
int warnings; /* warning count during processing */
int errors; /* error count during processing */
int romsloaded; /* current ROMs loaded count */
int romstotal; /* total number of ROMs to read */
mame_file * file; /* current file */
UINT8 * regionbase; /* base of current region */
UINT32 regionlength; /* length of current region */
astring * errorstring; /* error string */
UINT8 tempbuf[65536]; /* temporary buffer */
};
typedef struct _open_chd open_chd; typedef struct _open_chd open_chd;
struct _open_chd struct _open_chd
{ {
@ -94,6 +113,7 @@ void set_disk_handle(const char *region, mame_file *file, chd_file *chdfile)
} }
/*************************************************************************** /***************************************************************************
ROM LOADING ROM LOADING
***************************************************************************/ ***************************************************************************/
@ -325,7 +345,7 @@ static int determine_bios_rom(rom_load_data *romdata, const rom_entry *romp)
/* 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)
{ {
sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s: invalid bios\n", specbios); astring_catprintf(romdata->errorstring, "%s: invalid bios\n", specbios);
romdata->warnings++; romdata->warnings++;
} }
@ -386,21 +406,21 @@ static void handle_missing_file(rom_load_data *romdata, const rom_entry *romp)
/* optional files are okay */ /* optional files are okay */
if (ROM_ISOPTIONAL(romp)) if (ROM_ISOPTIONAL(romp))
{ {
sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "OPTIONAL %s NOT FOUND\n", ROM_GETNAME(romp)); astring_catprintf(romdata->errorstring, "OPTIONAL %s NOT FOUND\n", ROM_GETNAME(romp));
romdata->warnings++; romdata->warnings++;
} }
/* no good dumps are okay */ /* no good dumps are okay */
else if (ROM_NOGOODDUMP(romp)) else if (ROM_NOGOODDUMP(romp))
{ {
sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s NOT FOUND (NO GOOD DUMP KNOWN)\n", ROM_GETNAME(romp)); astring_catprintf(romdata->errorstring, "%s NOT FOUND (NO GOOD DUMP KNOWN)\n", ROM_GETNAME(romp));
romdata->warnings++; romdata->warnings++;
} }
/* anything else is bad */ /* anything else is bad */
else else
{ {
sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s NOT FOUND\n", ROM_GETNAME(romp)); astring_catprintf(romdata->errorstring, "%s NOT FOUND\n", ROM_GETNAME(romp));
romdata->errors++; romdata->errors++;
} }
} }
@ -422,13 +442,13 @@ static void dump_wrong_and_correct_checksums(rom_load_data* romdata, const char*
found_functions = hash_data_used_functions(hash) & hash_data_used_functions(acthash); found_functions = hash_data_used_functions(hash) & hash_data_used_functions(acthash);
hash_data_print(hash, found_functions, chksum); hash_data_print(hash, found_functions, chksum);
sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], " EXPECTED: %s\n", chksum); astring_catprintf(romdata->errorstring, " EXPECTED: %s\n", chksum);
/* We dump informations only of the functions for which MAME provided /* We dump informations only of the functions for which MAME provided
a correct checksum. Other functions we might have calculated are a correct checksum. Other functions we might have calculated are
useless here */ useless here */
hash_data_print(acthash, found_functions, chksum); hash_data_print(acthash, found_functions, chksum);
sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], " FOUND: %s\n", chksum); astring_catprintf(romdata->errorstring, " FOUND: %s\n", chksum);
/* For debugging purposes, we check if the checksums available in the /* For debugging purposes, we check if the checksums available in the
driver are correctly specified or not. This can be done by checking driver are correctly specified or not. This can be done by checking
@ -445,7 +465,7 @@ static void dump_wrong_and_correct_checksums(rom_load_data* romdata, const char*
for (i = 0; i < HASH_NUM_FUNCTIONS; i++) for (i = 0; i < HASH_NUM_FUNCTIONS; i++)
if (wrong_functions & (1 << i)) if (wrong_functions & (1 << i))
{ {
sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], astring_catprintf(romdata->errorstring,
"\tInvalid %s checksum treated as 0 (check leading zeros)\n", "\tInvalid %s checksum treated as 0 (check leading zeros)\n",
hash_function_name(1 << i)); hash_function_name(1 << i));
@ -476,21 +496,21 @@ static void verify_length_and_hash(rom_load_data *romdata, const char *name, UIN
/* verify length */ /* verify length */
if (explength != actlength) if (explength != actlength)
{ {
sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s WRONG LENGTH (expected: %08x found: %08x)\n", name, explength, actlength); astring_catprintf(romdata->errorstring, "%s WRONG LENGTH (expected: %08x found: %08x)\n", name, explength, actlength);
romdata->warnings++; romdata->warnings++;
} }
/* If there is no good dump known, write it */ /* If there is no good dump known, write it */
if (hash_data_has_info(hash, HASH_INFO_NO_DUMP)) if (hash_data_has_info(hash, HASH_INFO_NO_DUMP))
{ {
sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s NO GOOD DUMP KNOWN\n", name); astring_catprintf(romdata->errorstring, "%s NO GOOD DUMP KNOWN\n", name);
romdata->warnings++; romdata->warnings++;
} }
/* verify checksums */ /* verify checksums */
else if (!hash_data_is_equal(hash, acthash, 0)) else if (!hash_data_is_equal(hash, acthash, 0))
{ {
/* otherwise, it's just bad */ /* otherwise, it's just bad */
sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s WRONG CHECKSUMS:\n", name); astring_catprintf(romdata->errorstring, "%s WRONG CHECKSUMS:\n", name);
dump_wrong_and_correct_checksums(romdata, hash, acthash); dump_wrong_and_correct_checksums(romdata, hash, acthash);
@ -499,7 +519,7 @@ static void verify_length_and_hash(rom_load_data *romdata, const char *name, UIN
/* If it matches, but it is actually a bad dump, write it */ /* If it matches, but it is actually a bad dump, write it */
else if (hash_data_has_info(hash, HASH_INFO_BAD_DUMP)) else if (hash_data_has_info(hash, HASH_INFO_BAD_DUMP))
{ {
sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s ROM NEEDS REDUMP\n",name); astring_catprintf(romdata->errorstring, "%s ROM NEEDS REDUMP\n",name);
romdata->warnings++; romdata->warnings++;
} }
} }
@ -546,15 +566,16 @@ static void display_rom_load_results(running_machine *machine, rom_load_data *ro
} }
/* create the error message and exit fatally */ /* create the error message and exit fatally */
strcat(romdata->errorbuf, "ERROR: required files are missing, the "GAMENOUN" cannot be run."); mame_printf_error("%s", astring_c(romdata->errorstring));
fatalerror_exitcode(machine, MAMERR_MISSING_FILES, "%s", romdata->errorbuf); astring_free(romdata->errorstring);
fatalerror_exitcode(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 */
if (romdata->warnings) if (romdata->warnings)
{ {
strcat(romdata->errorbuf, "WARNING: the "GAMENOUN" might not run correctly."); astring_catc(romdata->errorstring, "WARNING: the "GAMENOUN" might not run correctly.");
mame_printf_warning("%s\n", romdata->errorbuf); mame_printf_warning("%s\n", astring_c(romdata->errorstring));
} }
} }
@ -1117,9 +1138,9 @@ static void process_disk_entries(running_machine *machine, rom_load_data *romdat
if (err != CHDERR_NONE) if (err != CHDERR_NONE)
{ {
if (err == CHDERR_FILE_NOT_FOUND) if (err == CHDERR_FILE_NOT_FOUND)
sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s NOT FOUND\n", astring_c(filename)); astring_catprintf(romdata->errorstring, "%s NOT FOUND\n", astring_c(filename));
else else
sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s CHD ERROR: %s\n", astring_c(filename), chd_error_string(err)); astring_catprintf(romdata->errorstring, "%s CHD ERROR: %s\n", astring_c(filename), chd_error_string(err));
/* if this is NO_DUMP, keep going, though the system may not be able to handle it */ /* if this is NO_DUMP, keep going, though the system may not be able to handle it */
if (hash_data_has_info(ROM_GETHASHDATA(romp), HASH_INFO_NO_DUMP) || DISK_ISOPTIONAL(romp)) if (hash_data_has_info(ROM_GETHASHDATA(romp), HASH_INFO_NO_DUMP) || DISK_ISOPTIONAL(romp))
@ -1138,13 +1159,13 @@ static void process_disk_entries(running_machine *machine, rom_load_data *romdat
/* verify the MD5 */ /* verify the MD5 */
if (!hash_data_is_equal(ROM_GETHASHDATA(romp), acthash, 0)) if (!hash_data_is_equal(ROM_GETHASHDATA(romp), acthash, 0))
{ {
sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s WRONG CHECKSUMS:\n", astring_c(filename)); astring_catprintf(romdata->errorstring, "%s WRONG CHECKSUMS:\n", astring_c(filename));
dump_wrong_and_correct_checksums(romdata, ROM_GETHASHDATA(romp), acthash); dump_wrong_and_correct_checksums(romdata, ROM_GETHASHDATA(romp), acthash);
romdata->warnings++; romdata->warnings++;
} }
else if (hash_data_has_info(ROM_GETHASHDATA(romp), HASH_INFO_BAD_DUMP)) else if (hash_data_has_info(ROM_GETHASHDATA(romp), HASH_INFO_BAD_DUMP))
{ {
sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s CHD NEEDS REDUMP\n", astring_c(filename)); astring_catprintf(romdata->errorstring, "%s CHD NEEDS REDUMP\n", astring_c(filename));
romdata->warnings++; romdata->warnings++;
} }
@ -1155,7 +1176,7 @@ static void process_disk_entries(running_machine *machine, rom_load_data *romdat
err = open_disk_diff(machine->gamedrv, romp, chd.origchd, &chd.difffile, &chd.diffchd); err = open_disk_diff(machine->gamedrv, romp, chd.origchd, &chd.difffile, &chd.diffchd);
if (err != CHDERR_NONE) if (err != CHDERR_NONE)
{ {
sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%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));
romdata->errors++; romdata->errors++;
continue; continue;
} }
@ -1276,13 +1297,14 @@ static void process_region_list(running_machine *machine, rom_load_data *romdata
void rom_init(running_machine *machine) void rom_init(running_machine *machine)
{ {
static rom_load_data romdata; rom_load_data romdata;
/* make sure we get called back on the way out */ /* make sure we get called back on the way out */
add_exit_callback(machine, rom_exit); add_exit_callback(machine, rom_exit);
/* reset the romdata struct */ /* reset the romdata struct */
memset(&romdata, 0, sizeof(romdata)); memset(&romdata, 0, sizeof(romdata));
romdata.errorstring = astring_alloc();
/* determine the correct biosset to load based on OPTION_BIOS string */ /* determine the correct biosset to load based on OPTION_BIOS string */
system_bios = determine_bios_rom(&romdata, machine->gamedrv->rom); system_bios = determine_bios_rom(&romdata, machine->gamedrv->rom);
@ -1299,8 +1321,8 @@ void rom_init(running_machine *machine)
/* 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(machine, &romdata);
astring_free(romdata.errorstring);
} }
@ -1335,6 +1357,11 @@ static void rom_exit(running_machine *machine)
} }
/*-------------------------------------------------
rom_load_warnings - return the number of
warnings we generated
-------------------------------------------------*/
int rom_load_warnings(void) int rom_load_warnings(void)
{ {
return total_rom_load_warnings; return total_rom_load_warnings;

View File

@ -141,25 +141,6 @@ struct _rom_entry
}; };
/* In mamecore.h: typedef struct _rom_load_data rom_load_data; */
struct _rom_load_data
{
int warnings; /* warning count during processing */
int errors; /* error count during processing */
int romsloaded; /* current ROMs loaded count */
int romstotal; /* total number of ROMs to read */
mame_file * file; /* current file */
UINT8 * regionbase; /* base of current region */
UINT32 regionlength; /* length of current region */
char errorbuf[4096]; /* accumulated errors */
UINT8 tempbuf[65536]; /* temporary buffer */
};
/*************************************************************************** /***************************************************************************
MACROS MACROS