summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/uimenu.c
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2011-04-13 20:31:00 +0000
committer Aaron Giles <aaron@aarongiles.com>2011-04-13 20:31:00 +0000
commit00d745ca7752d2f96e842a7f23e157c0d2c40bdf (patch)
tree9b6a3dcda7d0ff05b098fe0823fe4d09f6d0e6b4 /src/emu/uimenu.c
parentf99e1a5da63f996cd07fae98d42c2e5ff389adef (diff)
(Big tangle of changes that all happened as I was looking into the ROM
loader rewrite, which is still in progress....) Replaced mamedriv.c with a new driver list mechanism that is generated by the build tools. The emulator core now expects the presence of a file called src/$(TARGET)/$(SUBTARGET).lst which is just a raw list of driver names, one per line. C and C++ comments are still permitted. This file is parsed by a new build tool makelist which extracts the driver names, sorts them, and generates a file called drivlist.c, which is consumed by the core. [Aaron Giles] Added new osdcore function osd_malloc_array() which is identical to osd_malloc() but obviously hints that the underlying allocation is for an array. Updated all callers to use the appropriate form. Modified the Windows allocator to only use guard pages for array-style allocations, allowing us to enable them once again in debug builds. [Aaron Giles] Created new static class driver_list to wrap accesses to the list of available drivers. Improved speed of driver lookups by relying on the presorting done by makelist. [Aaron Giles] Created helper class driver_enumerator as a helper for iterating through the list of drivers. This class supports basic filtering and iteration, and also serves as a temporary cache of machine_configs. [Aaron Giles] Created cli_frontend object to wrap all the CLI handling code in clifront.c. Updated/simplified all the code to take advantage of the driver_enumerator. [Aaron Giles] Created media_auditor object to wrap all the auditing functions in audit.c. Updated all users to the new interface. Note that the new auditing mechanism is slightly out of sync with the romload code in terms of finding ROMs owned by devices, so it may mis-report some issues until the new ROM loading code is in. [Aaron Giles] Added concept of a per-device searchpath. For most devices, their searchpath is just the short name of the device. For driver_devices, the searchpath is driver[;parent[;bios]]. This searchpath will eventually be used by the rom loader to find ROMs. For now it is used by the media auditor only. [Aaron Giles] Created info_xml_creator object to wrap all the info generation functions in info.c. Converted the file to C++ and cleaned up the input processing code. [Aaron Giles] (not for whatsnew ... Known issues: auditing of CHDs appears busted, and debug builds report unfreed memory if you use the built-in game picker)
Diffstat (limited to 'src/emu/uimenu.c')
-rw-r--r--src/emu/uimenu.c102
1 files changed, 34 insertions, 68 deletions
diff --git a/src/emu/uimenu.c b/src/emu/uimenu.c
index efd14614b1b..91addf9ba55 100644
--- a/src/emu/uimenu.c
+++ b/src/emu/uimenu.c
@@ -208,7 +208,7 @@ struct _select_game_state
UINT8 error;
UINT8 rerandomize;
char search[40];
- const game_driver * matchlist[VISIBLE_GAMES_IN_LIST];
+ int matchlist[VISIBLE_GAMES_IN_LIST];
const game_driver * driverlist[1];
};
@@ -245,6 +245,9 @@ static const char priortext[] = "Return to Prior Menu";
static const char backtext[] = "Return to " CAPSTARTGAMENOUN;
static const char exittext[] = "Exit";
+// temporary hack until this is C++-ified
+static driver_enumerator *drivlist;
+
/***************************************************************************
@@ -299,7 +302,6 @@ static void menu_crosshair_populate(running_machine &machine, ui_menu *menu);
static void menu_quit_game(running_machine &machine, ui_menu *menu, void *parameter, void *state);
static void menu_select_game(running_machine &machine, ui_menu *menu, void *parameter, void *state);
static void menu_select_game_populate(running_machine &machine, ui_menu *menu, select_game_state *menustate);
-static int CLIB_DECL menu_select_game_driver_compare(const void *elem1, const void *elem2);
static void menu_select_game_build_driver_list(ui_menu *menu, select_game_state *menustate);
static void menu_select_game_custom_render(running_machine &machine, ui_menu *menu, void *state, void *selectedref, float top, float bottom, float x, float y, float x2, float y2);
@@ -3426,9 +3428,10 @@ static void menu_select_game(running_machine &machine, ui_menu *menu, void *para
/* if no state, allocate some */
if (state == NULL)
{
- state = ui_menu_alloc_state(menu, sizeof(*menustate) + sizeof(menustate->driverlist) * driver_list_get_count(drivers), NULL);
+ state = ui_menu_alloc_state(menu, sizeof(*menustate) + sizeof(menustate->driverlist) * driver_list::total(), NULL);
if (parameter != NULL)
strcpy(((select_game_state *)state)->search, (const char *)parameter);
+ ((select_game_state *)state)->matchlist[0] = -1;
}
menustate = (select_game_state *)state;
@@ -3459,24 +3462,20 @@ static void menu_select_game(running_machine &machine, ui_menu *menu, void *para
/* anything else is a driver */
else
{
- audit_record *audit;
- int audit_records;
- int audit_result;
-
- /* audit the game first to see if we're going to work */
- audit_records = audit_images(menu->machine().options(), driver, AUDIT_VALIDATE_FAST, &audit);
- audit_result = audit_summary(driver, audit_records, audit, FALSE);
- if (audit_records > 0)
- global_free(audit);
-
- /* if everything looks good, schedule the new driver */
- if (audit_result == CORRECT || audit_result == BEST_AVAILABLE)
+ // audit the game first to see if we're going to work
+ driver_enumerator enumerator(machine.options(), *driver);
+ enumerator.next();
+ media_auditor auditor(enumerator);
+ media_auditor::summary summary = auditor.audit_media(AUDIT_VALIDATE_FAST);
+
+ // if everything looks good, schedule the new driver
+ if (summary == media_auditor::CORRECT || summary == media_auditor::BEST_AVAILABLE)
{
machine.schedule_new_driver(*driver);
ui_menu_stack_reset(machine);
}
- /* otherwise, display an error */
+ // otherwise, display an error
else
{
ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_REF);
@@ -3551,18 +3550,19 @@ static void menu_select_game_populate(running_machine &machine, ui_menu *menu, s
}
/* otherwise, rebuild the match list */
- if (menustate->search[0] != 0 || menustate->matchlist[0] == NULL || menustate->rerandomize)
- driver_list_get_approx_matches(menustate->driverlist, menustate->search, matchcount, menustate->matchlist);
+ assert(drivlist != NULL);
+ if (menustate->search[0] != 0 || menustate->matchlist[0] == -1 || menustate->rerandomize)
+ drivlist->find_approximate_matches(menustate->search, matchcount, menustate->matchlist);
menustate->rerandomize = FALSE;
/* iterate over entries */
for (curitem = 0; curitem < matchcount; curitem++)
{
- const game_driver *driver = menustate->matchlist[curitem];
- if (driver != NULL)
+ int curmatch = menustate->matchlist[curitem];
+ if (curmatch != -1)
{
- const game_driver *cloneof = driver_get_clone(driver);
- ui_menu_item_append(menu, driver->name, driver->description, (cloneof == NULL || (cloneof->flags & GAME_IS_BIOS_ROOT)) ? 0 : MENU_FLAG_INVERT, (void *)driver);
+ int cloneof = drivlist->non_bios_clone(curmatch);
+ ui_menu_item_append(menu, drivlist->driver(curmatch).name, drivlist->driver(curmatch).description, (cloneof == -1) ? 0 : MENU_FLAG_INVERT, (void *)&drivlist->driver(curmatch));
}
}
@@ -3579,41 +3579,17 @@ static void menu_select_game_populate(running_machine &machine, ui_menu *menu, s
/*-------------------------------------------------
- menu_select_game_driver_compare - compare the
- names of two drivers
--------------------------------------------------*/
-
-static int CLIB_DECL menu_select_game_driver_compare(const void *elem1, const void *elem2)
-{
- const game_driver **driver1_ptr = (const game_driver **)elem1;
- const game_driver **driver2_ptr = (const game_driver **)elem2;
- const char *driver1 = (*driver1_ptr)->name;
- const char *driver2 = (*driver2_ptr)->name;
-
- while (*driver1 == *driver2 && *driver1 != 0)
- driver1++, driver2++;
- return *driver1 - *driver2;
-}
-
-
-/*-------------------------------------------------
menu_select_game_build_driver_list - build a
list of available drivers
-------------------------------------------------*/
static void menu_select_game_build_driver_list(ui_menu *menu, select_game_state *menustate)
{
- int driver_count = driver_list_get_count(drivers);
- int drivnum, listnum;
- UINT8 *found;
-
- /* create a sorted copy of the main driver list */
- memcpy((void *)menustate->driverlist, drivers, driver_count * sizeof(menustate->driverlist[0]));
- qsort((void *)menustate->driverlist, driver_count, sizeof(menustate->driverlist[0]), menu_select_game_driver_compare);
-
- /* allocate a temporary array to track which ones we found */
- found = (UINT8 *)ui_menu_pool_alloc(menu, (driver_count + 7) / 8);
- memset(found, 0, (driver_count + 7) / 8);
+ // start with an empty list
+ // hack alert: use new directly here to avoid reporting this one-time static memory as unfreed
+ if (drivlist == NULL)
+ drivlist = new driver_enumerator(menu->machine().options());
+ drivlist->exclude_all();
/* open a path to the ROMs and find them in the array */
file_enumerator path(menu->machine().options().media_path());
@@ -3622,9 +3598,6 @@ static void menu_select_game_build_driver_list(ui_menu *menu, select_game_state
/* iterate while we get new objects */
while ((dir = path.next()) != NULL)
{
- game_driver tempdriver;
- game_driver *tempdriver_ptr;
- const game_driver **found_driver;
char drivername[50];
char *dst = drivername;
const char *src;
@@ -3634,23 +3607,16 @@ static void menu_select_game_build_driver_list(ui_menu *menu, select_game_state
*dst++ = tolower((UINT8)*src);
*dst = 0;
- /* find it in the array */
- tempdriver.name = drivername;
- tempdriver_ptr = &tempdriver;
- found_driver = (const game_driver **)bsearch(&tempdriver_ptr, menustate->driverlist, driver_count, sizeof(*menustate->driverlist), menu_select_game_driver_compare);
-
- /* if found, mark the corresponding entry in the array */
- if (found_driver != NULL)
- {
- int index = found_driver - menustate->driverlist;
- found[index / 8] |= 1 << (index % 8);
- }
+ int drivnum = drivlist->find(drivername);
+ if (drivnum != -1)
+ drivlist->include(drivnum);
}
/* now build the final list */
- for (drivnum = listnum = 0; drivnum < driver_count; drivnum++)
- if (found[drivnum / 8] & (1 << (drivnum % 8)))
- menustate->driverlist[listnum++] = menustate->driverlist[drivnum];
+ drivlist->reset();
+ int listnum = 0;
+ while (drivlist->next())
+ menustate->driverlist[listnum++] = &drivlist->driver();
/* NULL-terminate */
menustate->driverlist[listnum] = NULL;