> -----Original Message-----

> From: Atari Ace [mailto:atari_ace@verizon.net]
> Sent: Monday, August 03, 2009 10:52 PM
> To: submit@mamedev.org
> Cc: atariace@hotmail.com
> Subject: [patch] De-globalize romload.c/validity.c
> 
> Hi mamedev,
> 
> Static and global variables in the core of MAME have slowly been
> replaced with opaque structures latched onto the running machine. This
> patch extends this idiom to two more files, romload.c and validity.c.
> validity.c in fact didn't need any global state (it was used only to
> pass data between function calls), and romload.c already had a struct
> that largely served that purpose.
> 
> ~aa
This commit is contained in:
Aaron Giles 2009-08-13 04:55:32 +00:00
parent 259fb90602
commit 40cc74b98f
16 changed files with 125 additions and 119 deletions

View File

@ -1801,7 +1801,7 @@ static DEVICE_START( ide_controller )
/* set MAME harddisk handle */
config = (const ide_config *)device->inline_config;
ide->handle = get_disk_handle((config->master != NULL) ? config->master : device->tag);
ide->handle = get_disk_handle(device->machine, (config->master != NULL) ? config->master : device->tag);
ide->disk = hard_disk_open(ide->handle);
assert_always(config->slave == NULL, "IDE controller does not yet support slave drives\n");

View File

@ -1327,7 +1327,7 @@ static void init_disc(const device_config *device)
if (config->getdisc != NULL)
ldcore->disc = (*config->getdisc)(device);
else
ldcore->disc = get_disk_handle(device->tag);
ldcore->disc = get_disk_handle(device->machine, device->tag);
/* set default parameters */
ldcore->width = 720;

View File

@ -695,7 +695,7 @@ static void scsicd_alloc_instance( SCSIInstance *scsiInstance, const char *diskr
/* TODO: get rid of this ifdef MESS section */
our_this->cdrom = mess_cd_get_cdrom_file( devtag_get_device( machine, diskregion ) );
#else
our_this->cdrom = cdrom_open(get_disk_handle( diskregion ));
our_this->cdrom = cdrom_open(get_disk_handle( machine, diskregion ));
if (!our_this->cdrom)
{

View File

@ -237,7 +237,7 @@ static void scsihd_alloc_instance( SCSIInstance *scsiInstance, const char *diskr
/* TODO: get rid of this ifdef MESS section */
our_this->disk = mess_hd_get_hard_disk_file( devtag_get_device( machine, diskregion ) );
#else
our_this->disk = hard_disk_open(get_disk_handle( diskregion ));
our_this->disk = hard_disk_open(get_disk_handle( machine, diskregion ));
if (!our_this->disk)
{

View File

@ -133,6 +133,7 @@ typedef struct _palette_private palette_private;
typedef struct _tilemap_private tilemap_private;
typedef struct _streams_private streams_private;
typedef struct _devices_private devices_private;
typedef struct _romload_private romload_private;
typedef struct _input_port_private input_port_private;
typedef struct _ui_input_private ui_input_private;
typedef struct _cheat_private cheat_private;
@ -182,6 +183,7 @@ struct _running_machine
tilemap_private * tilemap_data; /* internal data from tilemap.c */
streams_private * streams_data; /* internal data from streams.c */
devices_private * devices_data; /* internal data from devices.c */
romload_private * romload_data; /* internal data from romload.c */
input_port_private * input_port_data; /* internal data from inptport.c */
ui_input_private * ui_input_data; /* internal data from uiinput.c */
cheat_private * cheat_data; /* internal data from cheat.c */
@ -223,7 +225,7 @@ struct _mame_system_time
/***************************************************************************
GLOBAL VARAIBLES
GLOBAL VARIABLES
***************************************************************************/
extern const char mame_disclaimer[];

View File

@ -34,8 +34,20 @@
TYPE DEFINITIONS
***************************************************************************/
typedef struct _rom_load_data rom_load_data;
struct _rom_load_data
typedef struct _open_chd open_chd;
struct _open_chd
{
open_chd * next; /* pointer to next in the list */
const char * region; /* disk region we came from */
chd_file * origchd; /* handle to the original CHD */
mame_file * origfile; /* file handle to the original CHD file */
chd_file * diffchd; /* handle to the diff CHD */
mame_file * difffile; /* file handle to the diff CHD file */
};
typedef struct _romload_private rom_load_data;
struct _romload_private
{
running_machine *machine; /* machine object where needed */
int system_bios; /* the system BIOS we wish to load */
@ -49,6 +61,8 @@ struct _rom_load_data
UINT32 romstotalsize; /* total size of ROMs to read */
mame_file * file; /* current file */
open_chd * chd_list; /* disks */
open_chd ** chd_list_tailptr;
UINT8 * regionbase; /* base of current region */
UINT32 regionlength; /* length of current region */
@ -57,31 +71,6 @@ struct _rom_load_data
};
typedef struct _open_chd open_chd;
struct _open_chd
{
open_chd * next; /* pointer to next in the list */
const char * region; /* disk region we came from */
chd_file * origchd; /* handle to the original CHD */
mame_file * origfile; /* file handle to the original CHD file */
chd_file * diffchd; /* handle to the diff CHD */
mame_file * difffile; /* file handle to the diff CHD file */
};
/***************************************************************************
GLOBAL VARIABLES
***************************************************************************/
/* disks */
static open_chd *chd_list;
static open_chd **chd_list_tailptr;
static int total_rom_load_warnings;
/***************************************************************************
FUNCTION PROTOTYPES
***************************************************************************/
@ -99,17 +88,32 @@ static void rom_exit(running_machine *machine);
CHD file associated with the given region
-------------------------------------------------*/
chd_file *get_disk_handle(const char *region)
chd_file *get_disk_handle(running_machine *machine, const char *region)
{
open_chd *curdisk;
for (curdisk = chd_list; curdisk != NULL; curdisk = curdisk->next)
for (curdisk = machine->romload_data->chd_list; curdisk != NULL; curdisk = curdisk->next)
if (strcmp(curdisk->region, region) == 0)
return (curdisk->diffchd != NULL) ? curdisk->diffchd : curdisk->origchd;
return NULL;
}
/*-------------------------------------------------
add_disk_handle - add a disk to the to the
list of CHD files
-------------------------------------------------*/
static void add_disk_handle(running_machine *machine, open_chd *chd)
{
romload_private *romload_data = machine->romload_data;
*romload_data->chd_list_tailptr = auto_alloc(machine, open_chd);
**romload_data->chd_list_tailptr = *chd;
romload_data->chd_list_tailptr = &(*romload_data->chd_list_tailptr)->next;
}
/*-------------------------------------------------
set_disk_handle - set a pointer to the CHD
file associated with the given region
@ -125,9 +129,7 @@ void set_disk_handle(running_machine *machine, const char *region, mame_file *fi
chd.origfile = file;
/* we're okay, add to the list of disks */
*chd_list_tailptr = auto_alloc(machine, open_chd);
**chd_list_tailptr = chd;
chd_list_tailptr = &(*chd_list_tailptr)->next;
add_disk_handle(machine, &chd);
}
@ -1225,9 +1227,7 @@ static void process_disk_entries(rom_load_data *romdata, const char *regiontag,
/* we're okay, add to the list of disks */
LOG(("Assigning to handle %d\n", DISK_GETINDEX(romp)));
*chd_list_tailptr = auto_alloc(romdata->machine, open_chd);
**chd_list_tailptr = chd;
chd_list_tailptr = &(*chd_list_tailptr)->next;
add_disk_handle(romdata->machine, &chd);
}
}
astring_free(filename);
@ -1338,33 +1338,34 @@ static void process_region_list(rom_load_data *romdata)
void rom_init(running_machine *machine)
{
rom_load_data romdata;
rom_load_data *romdata;
/* allocate private data */
machine->romload_data = romdata = auto_alloc_clear(machine, romload_private);
/* make sure we get called back on the way out */
add_exit_callback(machine, rom_exit);
/* reset the romdata struct */
memset(&romdata, 0, sizeof(romdata));
romdata.machine = machine;
romdata.errorstring = astring_alloc();
romdata->machine = machine;
romdata->errorstring = astring_alloc();
/* figure out which BIOS we are using */
determine_bios_rom(&romdata);
determine_bios_rom(romdata);
/* count the total number of ROMs */
count_roms(&romdata);
count_roms(romdata);
/* reset the disk list */
chd_list = NULL;
chd_list_tailptr = &chd_list;
romdata->chd_list = NULL;
romdata->chd_list_tailptr = &machine->romload_data->chd_list;
/* process the ROM entries we were passed */
process_region_list(&romdata);
process_region_list(romdata);
/* display the results and exit */
total_rom_load_warnings = romdata.warnings;
display_rom_load_results(&romdata);
astring_free(romdata.errorstring);
display_rom_load_results(romdata);
astring_free(romdata->errorstring);
}
@ -1385,7 +1386,7 @@ static void rom_exit(running_machine *machine)
}
/* close all hard drives */
for (curchd = chd_list; curchd != NULL; curchd = curchd->next)
for (curchd = machine->romload_data->chd_list; curchd != NULL; curchd = curchd->next)
{
if (curchd->diffchd != NULL)
chd_close(curchd->diffchd);
@ -1404,7 +1405,7 @@ static void rom_exit(running_machine *machine)
warnings we generated
-------------------------------------------------*/
int rom_load_warnings(void)
int rom_load_warnings(running_machine *machine)
{
return total_rom_load_warnings;
return machine->romload_data->warnings;
}

View File

@ -276,7 +276,7 @@ struct _rom_entry
void rom_init(running_machine *machine);
/* return the number of warnings we generated */
int rom_load_warnings(void);
int rom_load_warnings(running_machine *machine);
@ -320,7 +320,7 @@ chd_error open_disk_image(const game_driver *gamedrv, const rom_entry *romp, mam
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);
chd_file *get_disk_handle(running_machine *machine, const char *region);
/* set a pointer to the CHD file associated with the given region */
void set_disk_handle(running_machine *machine, const char *region, mame_file *file, chd_file *chd);

View File

@ -876,11 +876,11 @@ static astring *warnings_string(running_machine *machine, astring *string)
astring_reset(string);
/* if no warnings, nothing to return */
if (rom_load_warnings() == 0 && !(machine->gamedrv->flags & WARNING_FLAGS))
if (rom_load_warnings(machine) == 0 && !(machine->gamedrv->flags & WARNING_FLAGS))
return string;
/* add a warning if any ROMs were loaded with warnings */
if (rom_load_warnings() > 0)
if (rom_load_warnings(machine) > 0)
{
astring_catc(string, "One or more ROMs/CHDs for this game are incorrect. The " GAMENOUN " may not run correctly.\n");
if (machine->gamedrv->flags & WARNING_FLAGS)

View File

@ -85,16 +85,15 @@ struct _quark_table
};
/***************************************************************************
GLOBAL VARIABLES
***************************************************************************/
static quark_table *source_table;
static quark_table *name_table;
static quark_table *description_table;
static quark_table *roms_table;
static quark_table *defstr_table;
typedef struct _quark_tables quark_tables;
struct _quark_tables
{
quark_table *source;
quark_table *name;
quark_table *description;
quark_table *roms;
quark_table *defstr;
};
@ -254,15 +253,15 @@ static quark_table *quark_table_alloc(UINT32 entries, UINT32 hashsize)
string operations
-------------------------------------------------*/
static void quark_tables_create(void)
static void quark_tables_create(quark_tables *tables)
{
int drivnum = driver_list_get_count(drivers), strnum;
/* allocate memory for the quark tables */
source_table = quark_table_alloc(drivnum, QUARK_HASH_SIZE);
name_table = quark_table_alloc(drivnum, QUARK_HASH_SIZE);
description_table = quark_table_alloc(drivnum, QUARK_HASH_SIZE);
roms_table = quark_table_alloc(drivnum, QUARK_HASH_SIZE);
tables->source = quark_table_alloc(drivnum, QUARK_HASH_SIZE);
tables->name = quark_table_alloc(drivnum, QUARK_HASH_SIZE);
tables->description = quark_table_alloc(drivnum, QUARK_HASH_SIZE);
tables->roms = quark_table_alloc(drivnum, QUARK_HASH_SIZE);
/* build the quarks and the hash tables */
for (drivnum = 0; drivers[drivnum]; drivnum++)
@ -270,24 +269,24 @@ static void quark_tables_create(void)
const game_driver *driver = drivers[drivnum];
/* fill in the quark with hashes of the strings */
quark_add(source_table, drivnum, quark_string_crc(driver->source_file));
quark_add(name_table, drivnum, quark_string_crc(driver->name));
quark_add(description_table, drivnum, quark_string_crc(driver->description));
quark_add(tables->source, drivnum, quark_string_crc(driver->source_file));
quark_add(tables->name, drivnum, quark_string_crc(driver->name));
quark_add(tables->description, drivnum, quark_string_crc(driver->description));
/* only track actual driver ROM entries */
if (driver->rom && (driver->flags & GAME_NO_STANDALONE) == 0)
quark_add(roms_table, drivnum, (FPTR)driver->rom);
quark_add(tables->roms, drivnum, (FPTR)driver->rom);
}
/* allocate memory for a quark table of strings */
defstr_table = quark_table_alloc(INPUT_STRING_COUNT, 97);
tables->defstr = quark_table_alloc(INPUT_STRING_COUNT, 97);
/* add all the default strings */
for (strnum = 1; strnum < INPUT_STRING_COUNT; strnum++)
{
const char *string = input_port_string_from_index(strnum);
if (string != NULL)
quark_add(defstr_table, strnum, quark_string_crc(string));
quark_add(tables->defstr, strnum, quark_string_crc(string));
}
}
@ -296,27 +295,27 @@ static void quark_tables_create(void)
quark_tables_free - free allocated tables
-------------------------------------------------*/
static void quark_tables_free(void)
static void quark_tables_free(quark_tables *tables)
{
if (source_table != NULL)
free(source_table);
source_table = NULL;
if (tables->source != NULL)
free(tables->source);
tables->source = NULL;
if (name_table != NULL)
free(name_table);
name_table = NULL;
if (tables->name != NULL)
free(tables->name);
tables->name = NULL;
if (description_table != NULL)
free(description_table);
description_table = NULL;
if (tables->description != NULL)
free(tables->description);
tables->description = NULL;
if (roms_table != NULL)
free(roms_table);
roms_table = NULL;
if (tables->roms != NULL)
free(tables->roms);
tables->roms = NULL;
if (defstr_table != NULL)
free(defstr_table);
defstr_table = NULL;
if (tables->defstr != NULL)
free(tables->defstr);
tables->defstr = NULL;
}
@ -483,9 +482,12 @@ static int validate_inlines(void)
information
-------------------------------------------------*/
static int validate_driver(int drivnum, const machine_config *config)
static int validate_driver(int drivnum, const machine_config *config, const quark_tables *tables)
{
const game_driver *driver = drivers[drivnum];
quark_table *name_table = tables->name;
quark_table *description_table = tables->description;
quark_table *roms_table = tables->roms;
const game_driver *clone_of;
quark_entry *entry;
int error = FALSE, is_clone;
@ -1005,7 +1007,7 @@ static int validate_gfx(int drivnum, const machine_config *config, region_info *
strings
-------------------------------------------------*/
static int get_defstr_index(const char *name, const game_driver *driver, int *error)
static int get_defstr_index(quark_table *defstr_table, const char *name, const game_driver *driver, int *error)
{
UINT32 crc = quark_string_crc(name);
quark_entry *entry;
@ -1144,7 +1146,7 @@ static void validate_analog_input_field(const input_field_config *field, const g
setting
-------------------------------------------------*/
static void validate_dip_settings(const input_field_config *field, const game_driver *driver, int *error)
static void validate_dip_settings(const input_field_config *field, const game_driver *driver, quark_table *defstr_table, int *error)
{
const char *demo_sounds = input_port_string_from_index(INPUT_STRING_Demo_Sounds);
const char *flipscreen = input_port_string_from_index(INPUT_STRING_Flip_Screen);
@ -1155,7 +1157,7 @@ static void validate_dip_settings(const input_field_config *field, const game_dr
/* iterate through the settings */
for (setting = field->settinglist; setting != NULL; setting = setting->next)
{
int strindex = get_defstr_index(setting->name, driver, error);
int strindex = get_defstr_index(defstr_table, setting->name, driver, error);
/* note any coinage strings */
if (strindex >= INPUT_STRING_9C_1C && strindex <= INPUT_STRING_1C_9C)
@ -1185,7 +1187,7 @@ static void validate_dip_settings(const input_field_config *field, const game_dr
/* if we have a neighbor, compare ourselves to him */
if (setting->next != NULL)
{
int next_strindex = get_defstr_index(setting->next->name, driver, error);
int next_strindex = get_defstr_index(defstr_table, setting->next->name, driver, error);
/* check for inverted off/on dispswitch order */
if (strindex == INPUT_STRING_On && next_strindex == INPUT_STRING_Off)
@ -1235,7 +1237,7 @@ static void validate_dip_settings(const input_field_config *field, const game_dr
validate_inputs - validate input configuration
-------------------------------------------------*/
static int validate_inputs(int drivnum, const machine_config *config, const input_port_config **portlistptr)
static int validate_inputs(int drivnum, const machine_config *config, quark_table *defstr_table, const input_port_config **portlistptr)
{
const input_port_config *scanport;
const input_port_config *port;
@ -1289,7 +1291,7 @@ static int validate_inputs(int drivnum, const machine_config *config, const inpu
}
/* verify the settings list */
validate_dip_settings(field, driver, &error);
validate_dip_settings(field, driver, defstr_table, &error);
}
/* look for invalid (0) types which should be mapped to IPT_OTHER */
@ -1324,7 +1326,7 @@ static int validate_inputs(int drivnum, const machine_config *config, const inpu
}
/* look up the string and print an error if default strings are not used */
/*strindex = */get_defstr_index(field->name, driver, &error);
/*strindex = */get_defstr_index(defstr_table, field->name, driver, &error);
}
/* verify conditions on the field */
@ -1593,6 +1595,7 @@ static int validate_devices(int drivnum, const machine_config *config, const inp
int mame_validitychecks(const game_driver *curdriver)
{
quark_tables tables;
osd_ticks_t prep = 0;
osd_ticks_t expansion = 0;
osd_ticks_t driver_checks = 0;
@ -1647,7 +1650,7 @@ int mame_validitychecks(const game_driver *curdriver)
/* prepare by pre-scanning all the drivers and adding their info to hash tables */
prep -= osd_profiling_ticks();
quark_tables_create();
quark_tables_create(&tables);
prep += osd_profiling_ticks();
/* iterate over all drivers */
@ -1671,7 +1674,7 @@ int mame_validitychecks(const game_driver *curdriver)
/* validate the driver entry */
driver_checks -= osd_profiling_ticks();
error = validate_driver(drivnum, config) || error;
error = validate_driver(drivnum, config, &tables) || error;
driver_checks += osd_profiling_ticks();
/* validate the ROM information */
@ -1681,7 +1684,7 @@ int mame_validitychecks(const game_driver *curdriver)
/* validate input ports */
input_checks -= osd_profiling_ticks();
error = validate_inputs(drivnum, config, &portlist) || error;
error = validate_inputs(drivnum, config, tables.defstr, &portlist) || error;
input_checks += osd_profiling_ticks();
/* validate the CPU information */
@ -1741,7 +1744,7 @@ int mame_validitychecks(const game_driver *curdriver)
end_resource_tracking();
exit_resource_tracking();
quark_tables_free();
quark_tables_free(&tables);
return error;
}

View File

@ -141,7 +141,7 @@ static chd_file *get_disc(const device_config *device)
if (image_file == NULL)
fatalerror("No valid image file found!\n");
return get_disk_handle("laserdisc");
return get_disk_handle(device->machine, "laserdisc");
}

View File

@ -455,9 +455,9 @@ static cdrom_toc cde_toc;
static CDE_DMA cde_dma[2];
static void cde_init(void)
static void cde_init(running_machine *machine)
{
cdrom_file *cd = cdrom_open(get_disk_handle("cdrom"));
cdrom_file *cd = cdrom_open(get_disk_handle(machine, "cdrom"));
const cdrom_toc *toc = cdrom_get_toc(cd);
if (cd)
@ -1231,7 +1231,7 @@ static DRIVER_INIT( m2 )
{
unk3 = U64(0xffffffffffffffff);
unk20004 = 0;
cde_init();
cde_init(machine);
}
GAME( 1997, polystar, 0, m2, m2, m2, ROT0, "Konami", "Tobe! Polystars (ver JAA)", GAME_NOT_WORKING | GAME_NO_SOUND )

View File

@ -1011,7 +1011,7 @@ static void atapi_exit(running_machine* machine)
for( i = 0; i < 2; i++ )
{
if( get_disk_handle( diskregions[i] ) != NULL )
if( get_disk_handle( machine, diskregions[i] ) != NULL )
{
SCSIDeleteInstance( available_cdroms[ i ] );
}
@ -1039,7 +1039,7 @@ static void atapi_init(running_machine *machine)
for( i = 0; i < 2; i++ )
{
if( get_disk_handle( diskregions[i] ) != NULL )
if( get_disk_handle( machine, diskregions[i] ) != NULL )
{
SCSIAllocInstance( machine, &SCSIClassCr589, &available_cdroms[ i ], diskregions[i] );
}

View File

@ -423,7 +423,7 @@ static WRITE32_HANDLER(rf5c296_mem_w)
pos++;
} else
v = data;
chd_get_metadata(get_disk_handle("card"), HARD_DISK_KEY_METADATA_TAG, 0, key, 5, 0, 0, 0);
chd_get_metadata(get_disk_handle(space->machine, "card"), HARD_DISK_KEY_METADATA_TAG, 0, key, 5, 0, 0, 0);
k = pos < 5 ? key[pos] : 0;
if(v == k)
locked &= ~(1 << pos);
@ -834,7 +834,7 @@ static DRIVER_INIT( coh3002t )
dip_timer = timer_alloc(machine, dip_timer_fired, NULL );
memset(cis, 0xff, 512);
chd_get_metadata(get_disk_handle("card"), PCMCIA_CIS_METADATA_TAG, 0, cis, 512, 0, 0, 0);
chd_get_metadata(get_disk_handle(machine, "card"), PCMCIA_CIS_METADATA_TAG, 0, cis, 512, 0, 0, 0);
}
static DRIVER_INIT( coh3002t_mp )

View File

@ -102,7 +102,7 @@ void amiga_akiko_init(running_machine* machine)
akiko.cdrom_cmd_start = 0;
akiko.cdrom_cmd_end = 0;
akiko.cdrom_cmd_resp = 0;
akiko.cdrom = cdrom_open(get_disk_handle("cdrom"));
akiko.cdrom = cdrom_open(get_disk_handle(machine, "cdrom"));
akiko.cdrom_toc = NULL;
akiko.dma_timer = timer_alloc(machine, akiko_dma_proc, NULL);
akiko.frame_timer = timer_alloc(machine, akiko_frame_proc, NULL);

View File

@ -946,7 +946,7 @@ static DEVICE_START( naomibd )
case DIMM_BOARD:
v->memory = (UINT8 *)memory_region(device->machine, config->regiontag);
v->gdromchd = get_disk_handle(config->gdromregiontag);
v->gdromchd = get_disk_handle(device->machine, config->gdromregiontag);
v->picdata = (UINT8 *)memory_region(device->machine, config->picregiontag);
load_rom_gdrom(device->machine, v);
break;

View File

@ -261,7 +261,7 @@ void stvcd_reset(running_machine *machine)
#ifdef MESS
cdrom = mess_cd_get_cdrom_file(devtag_get_device( machine, "cdrom" ));
#else
cdrom = cdrom_open(get_disk_handle("cdrom"));
cdrom = cdrom_open(get_disk_handle(machine, "cdrom"));
#endif
if (cdrom)