summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/mame.c
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2010-01-17 09:26:29 +0000
committer Aaron Giles <aaron@aarongiles.com>2010-01-17 09:26:29 +0000
commitd061ced59276808138b8a62ca99c6530d0b179bf (patch)
treee08630dd72dce81f385643006b35aa9a802e657b /src/emu/mame.c
parent14e2b9acf31db5fbc78a1ece0548130e4d7bed24 (diff)
Created new template class tagged_list which manages a simple list
along with a tagmap. Changed memory regions, input ports, and devices to use this class. For devices, converted typenext and classnext fields into methods which dynamically search for the next item. Changed a number of macros to use the features of the class, removing the need for a bunch of helper functions.
Diffstat (limited to 'src/emu/mame.c')
-rw-r--r--src/emu/mame.c69
1 files changed, 7 insertions, 62 deletions
diff --git a/src/emu/mame.c b/src/emu/mame.c
index f812d21cf62..7c7799db36e 100644
--- a/src/emu/mame.c
+++ b/src/emu/mame.c
@@ -137,10 +137,6 @@ struct _mame_private
void (*saveload_schedule_callback)(running_machine *);
attotime saveload_schedule_time;
- /* list of memory regions, and a map for lookups */
- region_info * regionlist;
- tagmap_t<region_info *> regionmap;
-
/* random number seed */
UINT32 rand_seed;
@@ -769,31 +765,15 @@ region_info::~region_info()
region
-------------------------------------------------*/
-UINT8 *memory_region_alloc(running_machine *machine, const char *name, UINT32 length, UINT32 flags)
+region_info *memory_region_alloc(running_machine *machine, const char *name, UINT32 length, UINT32 flags)
{
- mame_private *mame = machine->mame_data;
- region_info **infoptr, *info;
- tagmap_error tagerr;
-
/* make sure we don't have a region of the same name; also find the end of the list */
- for (infoptr = &mame->regionlist; *infoptr != NULL; infoptr = &(*infoptr)->next)
- if ((*infoptr)->name.cmp(name) == 0)
- fatalerror("memory_region_alloc called with duplicate region name \"%s\"\n", name);
+ region_info *info = machine->regionlist.find(name);
+ if (info != NULL)
+ fatalerror("memory_region_alloc called with duplicate region name \"%s\"\n", name);
/* allocate the region */
- info = auto_alloc(machine, region_info(machine, name, length, flags));
-
- /* attempt to put is in the hash table */
- tagerr = mame->regionmap.add_unique_hash(name, info, FALSE);
- if (tagerr == TMERR_DUPLICATE)
- {
- region_info *match = mame->regionmap.find_hash_only(name);
- fatalerror("Memory region '%s' has same hash as tag '%s'; please change one of them", name, match->name.cstr());
- }
-
- /* hook us into the list */
- *infoptr = info;
- return info->base.u8;
+ return machine->regionlist.append(name, global_alloc(region_info(machine, name, length, flags)));
}
@@ -804,41 +784,7 @@ UINT8 *memory_region_alloc(running_machine *machine, const char *name, UINT32 le
void memory_region_free(running_machine *machine, const char *name)
{
- mame_private *mame = machine->mame_data;
- region_info **infoptr;
-
- /* find the region */
- for (infoptr = &mame->regionlist; *infoptr != NULL; infoptr = &(*infoptr)->next)
- if ((*infoptr)->name.cmp(name) == 0)
- {
- region_info *info = *infoptr;
-
- /* remove us from the list and the map */
- *infoptr = info->next;
- mame->regionmap.remove(info->name);
-
- /* free the region */
- auto_free(machine, info);
- break;
- }
-}
-
-
-/*-------------------------------------------------
- memory_region_info - return a pointer to the
- information struct for a given memory region
--------------------------------------------------*/
-
-region_info *memory_region_info(running_machine *machine, const char *name)
-{
- mame_private *mame = machine->mame_data;
-
- /* NULL tag always fails */
- if (name == NULL)
- return NULL;
-
- /* look up the region and return the base */
- return mame->regionmap.find_hash_only(name);
+ machine->regionlist.remove(name);
}
@@ -886,7 +832,7 @@ UINT32 memory_region_flags(running_machine *machine, const char *name)
const char *memory_region_next(running_machine *machine, const char *name)
{
if (name == NULL)
- return (machine->mame_data->regionlist != NULL) ? machine->mame_data->regionlist->name : NULL;
+ return (machine->regionlist.first() != NULL) ? machine->regionlist.first()->name.cstr() : NULL;
const region_info *region = machine->region(name);
return (region != NULL && region->next != NULL) ? region->next->name.cstr() : NULL;
}
@@ -1348,7 +1294,6 @@ running_machine::running_machine(const game_driver *driver)
{
try
{
- memset(&portlist, 0, sizeof(portlist));
memset(gfx, 0, sizeof(gfx));
memset(&generic, 0, sizeof(generic));