diff options
author | 2009-08-13 04:55:32 +0000 | |
---|---|---|
committer | 2009-08-13 04:55:32 +0000 | |
commit | 40cc74b98f4b106ef77e6902e298704437ced114 (patch) | |
tree | 8d05ca539e484280c3567960d740bb5cdf641e1e /src/emu/romload.c | |
parent | 259fb90602e9ad68211032f1545d7df2c20d23e1 (diff) |
> -----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
Diffstat (limited to 'src/emu/romload.c')
-rw-r--r-- | src/emu/romload.c | 101 |
1 files changed, 51 insertions, 50 deletions
diff --git a/src/emu/romload.c b/src/emu/romload.c index 49d8330b40d..860b4a9733b 100644 --- a/src/emu/romload.c +++ b/src/emu/romload.c @@ -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,11 +88,11 @@ 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; @@ -111,6 +100,21 @@ chd_file *get_disk_handle(const char *region) /*------------------------------------------------- + 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; } |