diff --git a/src/emu/audit.c b/src/emu/audit.c index a9baea3fd0d..7b24dd775e6 100644 --- a/src/emu/audit.c +++ b/src/emu/audit.c @@ -120,18 +120,17 @@ int audit_images(core_options *options, const game_driver *gamedrv, UINT32 valid int audit_samples(core_options *options, const game_driver *gamedrv, audit_record **audit) { - machine_config config; + machine_config *config = machine_config_alloc(gamedrv->drv); audit_record *record; int sndnum, sampnum; int records = 0; /* count the number of sample records attached to this driver */ - expand_machine_driver(gamedrv->drv, &config); #if HAS_SAMPLES - for (sndnum = 0; sndnum < ARRAY_LENGTH(config.sound); sndnum++) - if (config.sound[sndnum].type == SOUND_SAMPLES) + for (sndnum = 0; sndnum < ARRAY_LENGTH(config->sound); sndnum++) + if (config->sound[sndnum].type == SOUND_SAMPLES) { - const struct Samplesinterface *intf = (const struct Samplesinterface *)config.sound[sndnum].config; + const struct Samplesinterface *intf = (const struct Samplesinterface *)config->sound[sndnum].config; if (intf->samplenames != NULL) { @@ -145,7 +144,7 @@ int audit_samples(core_options *options, const game_driver *gamedrv, audit_recor /* if no records, just quit now */ if (records == 0) - return records; + goto skip; /* allocate memory for the records */ *audit = malloc_or_die(sizeof(**audit) * records); @@ -153,10 +152,10 @@ int audit_samples(core_options *options, const game_driver *gamedrv, audit_recor record = *audit; /* now iterate over sample entries */ - for (sndnum = 0; sndnum < ARRAY_LENGTH(config.sound); sndnum++) - if (config.sound[sndnum].type == SOUND_SAMPLES) + for (sndnum = 0; sndnum < ARRAY_LENGTH(config->sound); sndnum++) + if (config->sound[sndnum].type == SOUND_SAMPLES) { - const struct Samplesinterface *intf = (const struct Samplesinterface *)config.sound[sndnum].config; + const struct Samplesinterface *intf = (const struct Samplesinterface *)config->sound[sndnum].config; const char *sharedname = NULL; if (intf->samplenames != NULL) @@ -197,6 +196,8 @@ int audit_samples(core_options *options, const game_driver *gamedrv, audit_recor } } +skip: + machine_config_free(config); return records; } diff --git a/src/emu/clifront.c b/src/emu/clifront.c index baeefa5cb4c..fa7f214579d 100644 --- a/src/emu/clifront.c +++ b/src/emu/clifront.c @@ -558,17 +558,14 @@ int cli_info_listsamples(core_options *options, const char *gamename) for (drvindex = 0; drivers[drvindex]; drvindex++) if (mame_strwildcmp(gamename, drivers[drvindex]->name) == 0) { - machine_config drv; + machine_config *config = machine_config_alloc(drivers[drvindex]->drv); int sndnum; - /* expand the machine driver */ - expand_machine_driver(drivers[drvindex]->drv, &drv); - /* find samples interfaces */ - for (sndnum = 0; sndnum < MAX_SOUND && drv.sound[sndnum].type != SOUND_DUMMY; sndnum++) - if (drv.sound[sndnum].type == SOUND_SAMPLES) + for (sndnum = 0; sndnum < MAX_SOUND && config->sound[sndnum].type != SOUND_DUMMY; sndnum++) + if (config->sound[sndnum].type == SOUND_SAMPLES) { - const char *const *samplenames = ((const struct Samplesinterface *)drv.sound[sndnum].config)->samplenames; + const char *const *samplenames = ((const struct Samplesinterface *)config->sound[sndnum].config)->samplenames; int sampnum; /* if the list is legit, walk it and print the sample info */ @@ -578,6 +575,7 @@ int cli_info_listsamples(core_options *options, const char *gamename) } count++; + machine_config_free(config); } /* clean up our tracked resources */ diff --git a/src/emu/driver.c b/src/emu/driver.c index 2677a415f2c..4f92d80443e 100644 --- a/src/emu/driver.c +++ b/src/emu/driver.c @@ -43,26 +43,44 @@ static int penalty_compare(const char *source, const char *target); ***************************************************************************/ /*------------------------------------------------- - expand_machine_driver - construct a machine - driver from the macroized state + machine_config_alloc - allocate a new + machine configuration and populate it using + the supplied constructor -------------------------------------------------*/ -void expand_machine_driver(void (*constructor)(machine_config *), machine_config *output) +machine_config *machine_config_alloc(void (*constructor)(machine_config *)) { - /* initialize the tag on the first screen */ - memset(output, 0, sizeof(*output)); - output->watchdog_time = attotime_zero; - - /* keeping this function allows us to pre-init the driver before constructing it */ - (*constructor)(output); + machine_config *config; + + /* allocate a new configuration object */ + config = malloc_or_die(sizeof(*config)); + if (config == NULL) + return NULL; + memset(config, 0, sizeof(*config)); + + /* call the function to construct the data */ + (*constructor)(config); /* if no screen tagged, tag screen 0 as main */ - if (output->screen[0].tag == NULL && output->screen[0].defstate.format != BITMAP_FORMAT_INVALID) - output->screen[0].tag = "main"; + if (config->screen[0].tag == NULL && config->screen[0].defstate.format != BITMAP_FORMAT_INVALID) + config->screen[0].tag = "main"; /* if no screens, set a dummy refresh for the main screen */ - if (output->screen[0].tag == NULL) - output->screen[0].defstate.refresh = HZ_TO_ATTOSECONDS(60); + if (config->screen[0].tag == NULL) + config->screen[0].defstate.refresh = HZ_TO_ATTOSECONDS(60); + + return config; +} + + +/*------------------------------------------------- + machine_config_free - release memory allocated + for a machine configuration +-------------------------------------------------*/ + +void machine_config_free(machine_config *config) +{ + free(config); } diff --git a/src/emu/driver.h b/src/emu/driver.h index 5bab0ad0bd7..5e5bbb3e0d7 100644 --- a/src/emu/driver.h +++ b/src/emu/driver.h @@ -572,7 +572,8 @@ extern const game_driver driver_empty; FUNCTION PROTOTYPES ***************************************************************************/ -void expand_machine_driver(void (*constructor)(machine_config *), machine_config *output); +machine_config *machine_config_alloc(void (*constructor)(machine_config *)); +void machine_config_free(machine_config *config); cpu_config *driver_add_cpu(machine_config *machine, const char *tag, cpu_type type, int cpuclock); cpu_config *driver_find_cpu(machine_config *machine, const char *tag); diff --git a/src/emu/info.c b/src/emu/info.c index e2e2ca755aa..f3b4cd6f878 100644 --- a/src/emu/info.c +++ b/src/emu/info.c @@ -31,54 +31,53 @@ void print_game_device(FILE* out, const game_driver* game); void print_game_ramoptions(FILE* out, const game_driver* game); #endif /* MESS */ -/* Print a free format string */ -static void print_game_switch(FILE* out, const game_driver* game) +/*------------------------------------------------- + print_game_switches - print the DIP switch + settings for a game +-------------------------------------------------*/ + +static void print_game_switches(FILE *out, const game_driver *game, const input_port_entry *input) { - const input_port_entry* input; - - begin_resource_tracking(); - - input = input_port_allocate(game->ipt, NULL); - + /* iterate over input entries until we run out */ while (input->type != IPT_END) { - if (input->type==IPT_DIPSWITCH_NAME) + /* once we hit a name entry, start outputting */ + if (input->type == IPT_DIPSWITCH_NAME) { int def = input->default_value; - fprintf(out, "\t\t\n", xml_normalize_string(input->name)); - fprintf(out, " name=\"%s\"", xml_normalize_string(input->name)); - ++input; - - fprintf(out, ">\n"); - - while (input->type==IPT_DIPSWITCH_SETTING) + /* loop over settings */ + for (input++; input->type == IPT_DIPSWITCH_SETTING; input++) { - fprintf(out, "\t\t\tname)); + fprintf(out, "\t\t\tname)); if (def == input->default_value) fprintf(out, " default=\"yes\""); - fprintf(out, "/>\n"); - - ++input; } + /* terminate the switch entry */ fprintf(out, "\t\t\n"); } else ++input; } - - end_resource_tracking(); } -static void print_game_input(FILE* out, const game_driver* game) + +/*------------------------------------------------- + print_game_input - print a summary of a game's + input +-------------------------------------------------*/ + +static void print_game_input(FILE *out, const game_driver *game, const input_port_entry *input) { + /* fix me -- this needs to be cleaned up to match the core style */ + enum {cjoy, cdoublejoy, cAD_stick, cdial, ctrackball, cpaddle, clightgun, cpedal, ENDCONTROLTYPES}; - const input_port_entry* input; int nplayer = 0; int nbutton = 0; int ncoin = 0; @@ -103,7 +102,7 @@ enum {cjoy, cdoublejoy, cAD_stick, cdial, ctrackball, cpaddle, clightgun, cpedal for (i=0;iipt, NULL); - while (input->type != IPT_END) { if (nplayer < input->player+1) @@ -127,7 +122,7 @@ enum {cjoy, cdoublejoy, cAD_stick, cdial, ctrackball, cpaddle, clightgun, cpedal case IPT_JOYSTICK_RIGHT: /* if control not defined, start it off as horizontal 2-way */ - if (!control[cjoy].Xway) + if (control[cjoy].Xway == NULL) control[cjoy].Xway = "joy2way"; else if (strcmp(control[cjoy].Xway,"joy2way") == 0) ; @@ -146,12 +141,12 @@ enum {cjoy, cdoublejoy, cAD_stick, cdial, ctrackball, cpaddle, clightgun, cpedal case IPT_JOYSTICK_DOWN: /* if control not defined, start it off as vertical 2-way */ - if (!control[cjoy].Xway) - control[cjoy].Xway= "vjoy2way"; + if (control[cjoy].Xway == NULL) + control[cjoy].Xway = "vjoy2way"; else if (strcmp(control[cjoy].Xway,"vjoy2way") == 0) ; /* if already defined as horiz, make it 4 or 8way */ - else if (strcmp(control[cjoy].Xway,"joy2way")==0) + else if (strcmp(control[cjoy].Xway,"joy2way") == 0) { if (input->way == 4) control[cjoy].Xway = "joy4way"; @@ -167,8 +162,8 @@ enum {cjoy, cdoublejoy, cAD_stick, cdial, ctrackball, cpaddle, clightgun, cpedal case IPT_JOYSTICKLEFT_DOWN: /* if control not defined, start it off as vertical 2way */ - if (!control[cdoublejoy].Xway) - control[cdoublejoy].Xway= "vdoublejoy2way"; + if (control[cdoublejoy].Xway == NULL) + control[cdoublejoy].Xway = "vdoublejoy2way"; else if (strcmp(control[cdoublejoy].Xway,"vdoublejoy2way") == 0) ; /* if already defined as horiz, make it 4 or 8 way */ @@ -188,8 +183,8 @@ enum {cjoy, cdoublejoy, cAD_stick, cdial, ctrackball, cpaddle, clightgun, cpedal case IPT_JOYSTICKLEFT_RIGHT: /* if control not defined, start it off as horiz 2-way */ - if (!control[cdoublejoy].Xway) - control[cdoublejoy].Xway="doublejoy2way"; + if (control[cdoublejoy].Xway == NULL) + control[cdoublejoy].Xway = "doublejoy2way"; else if (strcmp(control[cdoublejoy].Xway,"doublejoy2way") == 0) ; /* if already defined as vertical, make it 4 or 8 way */ @@ -315,24 +310,24 @@ enum {cjoy, cdoublejoy, cAD_stick, cdial, ctrackball, cpaddle, clightgun, cpedal } fprintf(out, "\t\t\n"); - for (i=0;i\n", xml_normalize_string(control[i].Xway) ); + if (control[i].Xway != NULL) + fprintf(out, "\t\t\t\n", xml_normalize_string(control[i].Xway)); if (control[i].analog) { - fprintf(out, "\t\t\t\n"); - - end_resource_tracking(); } -static void print_game_bios(FILE* out, const game_driver* game) + +/*------------------------------------------------- + print_game_bios - print the BIOS set for a + game +-------------------------------------------------*/ + +static void print_game_bios(FILE *out, const game_driver *game) { const rom_entry *rom; - if (game->rom != NULL) - { - for (rom = game->rom; !ROMENTRY_ISEND(rom); rom++) - if (ROMENTRY_ISSYSTEM_BIOS(rom)) - { - const char *name = ROM_GETHASHDATA(rom); - const char *description = name + strlen(name) + 1; + /* skip if no ROMs */ + if (game->rom == NULL) + return; + + /* iterate over ROM entries and look for BIOSes */ + for (rom = game->rom; !ROMENTRY_ISEND(rom); rom++) + if (ROMENTRY_ISSYSTEM_BIOS(rom)) + { + const char *name = ROM_GETHASHDATA(rom); + const char *description = name + strlen(name) + 1; - fprintf(out, "\t\t\n"); - } - } + /* output extracted name and descriptions */ + fprintf(out, "\t\t\n"); + } } -static void print_game_rom(FILE* out, const game_driver* game) + +/*------------------------------------------------- + print_game_rom - print the roms section of + the XML output +-------------------------------------------------*/ + +static void print_game_rom(FILE *out, const game_driver *game) { - const rom_entry *region, *rom, *chunk; - const rom_entry *pregion, *prom, *fprom=NULL; - const game_driver *clone_of; + const game_driver *clone_of = driver_get_clone(game); int rom_type; - if (!game->rom) + /* if no roms, just exit early */ + if (game->rom == NULL) return; - clone_of = driver_get_clone(game); + /* iterate over 3 different ROM "types": BIOS, ROMs, DISKs */ for (rom_type = 0; rom_type < 3; rom_type++) { - for (region = rom_first_region(game); region; region = rom_next_region(region)) - for (rom = rom_first_file(region); rom; rom = rom_next_file(rom)) + const rom_entry *region; + + /* iterate first through regions */ + for (region = rom_first_region(game); region != NULL; region = rom_next_region(region)) + { + int is_disk = ROMREGION_ISDISKDATA(region); + const rom_entry *rom; + + /* disk regions only work for disks */ + if ((is_disk && rom_type != 2) || (!is_disk && rom_type == 2)) + continue; + + /* iterate through ROM entries */ + for (rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom)) { - int offset, length, in_parent, is_disk, is_bios, found_bios, i; - char name[100], bios_name[100]; + int is_bios = ROM_GETBIOSFLAGS(rom); + const char *name = ROM_GETNAME(rom); + int offset = ROM_GETOFFSET(rom); + const rom_entry *parent_rom = NULL; + const rom_entry *chunk; + char bios_name[100]; + int length; + + /* BIOS ROMs only apply to bioses */ + if ((is_bios && rom_type != 0) || (!is_bios && rom_type == 0)) + continue; - strcpy(name,ROM_GETNAME(rom)); - offset = ROM_GETOFFSET(rom); - is_disk = ROMREGION_ISDISKDATA(region); - is_bios = ROM_GETBIOSFLAGS(rom); - - switch (rom_type) - { - case 0: /* rom_type 0 = BIOS */ - if (is_disk || !is_bios) - continue; - break; - case 1: /* rom_type 1 = ROM */ - if (is_disk || is_bios) - continue; - break; - case 2: /* rom_type 1 = DISK */ - if (!is_disk || is_bios) - continue; - break; - } - - in_parent = 0; + /* compute the total length of all chunks */ length = 0; for (chunk = rom_first_chunk(rom); chunk; chunk = rom_next_chunk(chunk)) length += ROM_GETLENGTH(chunk); - if (!ROM_NOGOODDUMP(rom) && clone_of) + /* if we have a valid ROM and we are a clone, see if we can find the parent ROM */ + if (!ROM_NOGOODDUMP(rom) && clone_of != NULL) { - fprom=NULL; - for (pregion = rom_first_region(clone_of); pregion; pregion = rom_next_region(pregion)) - for (prom = rom_first_file(pregion); prom; prom = rom_next_file(prom)) + const rom_entry *pregion, *prom; + + /* scan the clone_of ROM for a matching ROM entry */ + for (pregion = rom_first_region(clone_of); pregion != NULL; pregion = rom_next_region(pregion)) + for (prom = rom_first_file(pregion); prom != NULL; prom = rom_next_file(prom)) if (hash_data_is_equal(ROM_GETHASHDATA(rom), ROM_GETHASHDATA(prom), 0)) { - if (!fprom || !strcmp(ROM_GETNAME(prom), name)) - fprom=prom; - in_parent = 1; + parent_rom = prom; + break; } } - found_bios = 0; - if(!is_disk && is_bios) + /* scan for a BIOS name */ + bios_name[0] = 0; + if (!is_disk && is_bios) { - /* Scan backwards for name */ - for (prom = rom-1; prom != game->rom; prom--) - if (ROMENTRY_ISSYSTEM_BIOS(prom)) + const rom_entry *brom; + + /* scan backwards through the ROM entries */ + for (brom = rom - 1; brom != game->rom; brom--) + if (ROMENTRY_ISSYSTEM_BIOS(brom)) { - strcpy(bios_name, ROM_GETHASHDATA(prom)); - found_bios = 1; + strcpy(bios_name, ROM_GETHASHDATA(brom)); break; } } - + /* opening tag */ if (!is_disk) fprintf(out, "\t\t\n"); - } - } -} - -static void print_game_sampleof(FILE* out, const game_driver* game) -{ -#if (HAS_SAMPLES) - machine_config drv; - int i; - - expand_machine_driver(game->drv, &drv); - - for( i = 0; i < MAX_SOUND && drv.sound[i].type != SOUND_DUMMY; i++ ) - { - const char *const *samplenames = NULL; - if( drv.sound[i].type == SOUND_SAMPLES ) - samplenames = ((const struct Samplesinterface *)drv.sound[i].config)->samplenames; - if (samplenames != 0 && samplenames[0] != 0) { - int k = 0; - if (samplenames[k][0]=='*') - { - /* output sampleof only if different from game name */ - if (strcmp(samplenames[k] + 1, game->name)!=0) - fprintf(out, " sampleof=\"%s\"", xml_normalize_string(samplenames[k] + 1)); - ++k; - } - } - } -#endif -} - -static void print_game_sample(FILE* out, const game_driver* game) -{ -#if (HAS_SAMPLES) - machine_config drv; - int i; - - expand_machine_driver(game->drv, &drv); - - for( i = 0; i < MAX_SOUND && drv.sound[i].type != SOUND_DUMMY; i++ ) - { - const char *const *samplenames = NULL; - if( drv.sound[i].type == SOUND_SAMPLES ) - samplenames = ((const struct Samplesinterface *)drv.sound[i].config)->samplenames; - if (samplenames != 0 && samplenames[0] != 0) { - int k = 0; - if (samplenames[k][0]=='*') - { - ++k; - } - while (samplenames[k] != 0) { - /* check if is not empty */ - if (*samplenames[k]) { - /* check if sample is duplicate */ - int l = 0; - while (l\n", xml_normalize_string(samplenames[k])); + case REGION_CPU1: fprintf(out, " region=\"cpu1\""); break; + case REGION_CPU2: fprintf(out, " region=\"cpu2\""); break; + case REGION_CPU3: fprintf(out, " region=\"cpu3\""); break; + case REGION_CPU4: fprintf(out, " region=\"cpu4\""); break; + case REGION_CPU5: fprintf(out, " region=\"cpu5\""); break; + case REGION_CPU6: fprintf(out, " region=\"cpu6\""); break; + case REGION_CPU7: fprintf(out, " region=\"cpu7\""); break; + case REGION_CPU8: fprintf(out, " region=\"cpu8\""); break; + case REGION_GFX1: fprintf(out, " region=\"gfx1\""); break; + case REGION_GFX2: fprintf(out, " region=\"gfx2\""); break; + case REGION_GFX3: fprintf(out, " region=\"gfx3\""); break; + case REGION_GFX4: fprintf(out, " region=\"gfx4\""); break; + case REGION_GFX5: fprintf(out, " region=\"gfx5\""); break; + case REGION_GFX6: fprintf(out, " region=\"gfx6\""); break; + case REGION_GFX7: fprintf(out, " region=\"gfx7\""); break; + case REGION_GFX8: fprintf(out, " region=\"gfx8\""); break; + case REGION_PROMS: fprintf(out, " region=\"proms\""); break; + case REGION_PLDS: fprintf(out, " region=\"plds\""); break; + case REGION_SOUND1: fprintf(out, " region=\"sound1\""); break; + case REGION_SOUND2: fprintf(out, " region=\"sound2\""); break; + case REGION_SOUND3: fprintf(out, " region=\"sound3\""); break; + case REGION_SOUND4: fprintf(out, " region=\"sound4\""); break; + case REGION_SOUND5: fprintf(out, " region=\"sound5\""); break; + case REGION_SOUND6: fprintf(out, " region=\"sound6\""); break; + case REGION_SOUND7: fprintf(out, " region=\"sound7\""); break; + case REGION_SOUND8: fprintf(out, " region=\"sound8\""); break; + case REGION_USER1: fprintf(out, " region=\"user1\""); break; + case REGION_USER2: fprintf(out, " region=\"user2\""); break; + case REGION_USER3: fprintf(out, " region=\"user3\""); break; + case REGION_USER4: fprintf(out, " region=\"user4\""); break; + case REGION_USER5: fprintf(out, " region=\"user5\""); break; + case REGION_USER6: fprintf(out, " region=\"user6\""); break; + case REGION_USER7: fprintf(out, " region=\"user7\""); break; + case REGION_USER8: fprintf(out, " region=\"user8\""); break; + case REGION_USER9: fprintf(out, " region=\"user9\""); break; + case REGION_USER10: fprintf(out, " region=\"user10\""); break; + case REGION_USER11: fprintf(out, " region=\"user11\""); break; + case REGION_USER12: fprintf(out, " region=\"user12\""); break; + case REGION_USER13: fprintf(out, " region=\"user13\""); break; + case REGION_USER14: fprintf(out, " region=\"user14\""); break; + case REGION_USER15: fprintf(out, " region=\"user15\""); break; + case REGION_USER16: fprintf(out, " region=\"user16\""); break; + case REGION_USER17: fprintf(out, " region=\"user17\""); break; + case REGION_USER18: fprintf(out, " region=\"user18\""); break; + case REGION_USER19: fprintf(out, " region=\"user19\""); break; + case REGION_USER20: fprintf(out, " region=\"user20\""); break; + case REGION_DISKS: fprintf(out, " region=\"disks\""); break; + default: fprintf(out, " region=\"0x%x\"", (int)ROMREGION_GETTYPE(region)); break; } - ++k; + + /* add nodump/baddump flags */ + if (hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP)) + fprintf(out, " status=\"nodump\""); + if (hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_BAD_DUMP)) + fprintf(out, " status=\"baddump\""); + + /* for non-disk entries, print dispose flag and offset */ + if (!is_disk) + { + if (ROMREGION_GETFLAGS(region) & ROMREGION_DISPOSE) + fprintf(out, " dispose=\"yes\""); + fprintf(out, " offset=\"%x\"", offset); + } + + /* for disk entries, add the disk index */ + else + fprintf(out, " index=\"%x\"", DISK_GETINDEX(rom)); + fprintf(out, "/>\n"); } } } +} + + +/*------------------------------------------------- + print_game_sampleof - print the 'sampleof' + attribute, if appropriate +-------------------------------------------------*/ + +static void print_game_sampleof(FILE *out, const game_driver *game, const machine_config *config) +{ +#if (HAS_SAMPLES) + int sndnum; + + for (sndnum = 0; sndnum < ARRAY_LENGTH(config->sound) && config->sound[sndnum].type != SOUND_DUMMY; sndnum++) + if (config->sound[sndnum].type == SOUND_SAMPLES) + { + const char *const *samplenames = ((const struct Samplesinterface *)config->sound[sndnum].config)->samplenames; + if (samplenames != NULL) + { + int sampnum; + + /* iterate over sample names */ + for (sampnum = 0; samplenames[sampnum] != NULL; sampnum++) + { + const char *cursampname = samplenames[sampnum]; + + /* only output sampleof if different from the game name */ + if (cursampname[0] == '*' && strcmp(cursampname + 1, game->name) != 0) + fprintf(out, " sampleof=\"%s\"", xml_normalize_string(cursampname + 1)); + } + } + } #endif } -static void print_game_micro(FILE* out, const game_driver* game) + +/*------------------------------------------------- + print_game_sample - print a list of all + samples referenced by a game_driver +-------------------------------------------------*/ + +static void print_game_sample(FILE *out, const game_driver *game, const machine_config *config) { - machine_config driver; - const cpu_config* cpu; - const sound_config* sound; - int j; +#if (HAS_SAMPLES) + int sndnum; - expand_machine_driver(game->drv, &driver); - cpu = driver.cpu; - sound = driver.sound; + /* iterate over sound chips looking for samples */ + for (sndnum = 0; sndnum < ARRAY_LENGTH(config->sound) && config->sound[sndnum].type != SOUND_DUMMY; sndnum++) + if (config->sound[sndnum].type == SOUND_SAMPLES) + { + const char *const *samplenames = ((const struct Samplesinterface *)config->sound[sndnum].config)->samplenames; + if (samplenames != NULL) + { + int sampnum; + + /* iterate over sample names */ + for (sampnum = 0; samplenames[sampnum] != NULL; sampnum++) + { + const char *cursampname = samplenames[sampnum]; + int dupnum; + + /* ignore the special '*' samplename */ + if (sampnum == 0 && cursampname[0] == '*') + continue; + + /* filter out duplicates */ + for (dupnum = 0; dupnum < sampnum; dupnum++) + if (strcmp(samplenames[dupnum], cursampname) == 0) + break; + if (dupnum < sampnum) + continue; - for(j=0;j\n", xml_normalize_string(cursampname)); + } + } + } +#endif +} + + +/*------------------------------------------------- + print_game_chips - print a list of CPU and + sound chips used by a game +-------------------------------------------------*/ + +static void print_game_chips(FILE *out, const game_driver *game, const machine_config *config) +{ + int chipnum; + + /* iterate over CPUs */ + for (chipnum = 0; chipnum < ARRAY_LENGTH(config->cpu); chipnum++) + if (config->cpu[chipnum].type != CPU_DUMMY) { fprintf(out, "\t\tcpu[chipnum].type))); + fprintf(out, " clock=\"%d\"", config->cpu[chipnum].clock); fprintf(out, "/>\n"); } - } - for(j=0;jsound); chipnum++) + if (config->sound[chipnum].type != SOUND_DUMMY) { fprintf(out, "\t\tsound[chipnum].type))); + if (config->sound[chipnum].clock != 0) + fprintf(out, " clock=\"%d\"", config->sound[chipnum].clock); fprintf(out, "/>\n"); } - } } -static void print_game_display(FILE* out, const game_driver* game) -{ - machine_config driver; - int dx; - int dy; +/*------------------------------------------------- + print_game_display - print a list of all the + displays +-------------------------------------------------*/ + +static void print_game_display(FILE *out, const game_driver *game, const machine_config *config) +{ int scrnum; - expand_machine_driver(game->drv, &driver); - + /* iterate over screens */ for (scrnum = 0; scrnum < MAX_SCREENS; scrnum++) - if (driver.screen[scrnum].tag != NULL) + if (config->screen[scrnum].tag != NULL) { fprintf(out, "\t\tvideo_attributes & VIDEO_TYPE_VECTOR) ? "vector" : "raster"); - fprintf(out, " type=\"%s\"", (driver.video_attributes & VIDEO_TYPE_VECTOR) ? "vector" : "raster" ); - - switch (game->flags & ORIENTATION_MASK) { + /* output the orientation as a string */ + switch (game->flags & ORIENTATION_MASK) + { case ORIENTATION_FLIP_X: fprintf(out, " rotate=\"0\" flipx=\"yes\""); break; @@ -697,65 +720,56 @@ static void print_game_display(FILE* out, const game_driver* game) } /* output width and height only for games that are not vector */ - if (! (driver.video_attributes & VIDEO_TYPE_VECTOR) ) + if (!(config->video_attributes & VIDEO_TYPE_VECTOR)) { - dx = driver.screen[scrnum].defstate.visarea.max_x - driver.screen[scrnum].defstate.visarea.min_x + 1; - dy = driver.screen[scrnum].defstate.visarea.max_y - driver.screen[scrnum].defstate.visarea.min_y + 1; + int dx = config->screen[scrnum].defstate.visarea.max_x - config->screen[scrnum].defstate.visarea.min_x + 1; + int dy = config->screen[scrnum].defstate.visarea.max_y - config->screen[scrnum].defstate.visarea.min_y + 1; fprintf(out, " width=\"%d\"", dx); fprintf(out, " height=\"%d\"", dy); } - fprintf(out, " refresh=\"%f\"", ATTOSECONDS_TO_HZ(driver.screen[scrnum].defstate.refresh)); - + /* output refresh rate */ + fprintf(out, " refresh=\"%f\"", ATTOSECONDS_TO_HZ(config->screen[scrnum].defstate.refresh)); fprintf(out, " />\n"); } } -static void print_game_sound(FILE* out, const game_driver* game) + +/*------------------------------------------------- + print_game_sound - print a list of all the + displays +-------------------------------------------------*/ + +static void print_game_sound(FILE *out, const game_driver *game, const machine_config *config) { - machine_config driver; - const cpu_config* cpu; - const sound_config* sound; + int has_sound = FALSE; + int speakers = 0; + int sndnum; - /* check if the game have sound emulation */ - int has_sound = 0; - int i; + /* see if we have any sound chips to report */ + for (sndnum = 0; sndnum < ARRAY_LENGTH(config->sound); sndnum++) + if (config->sound[sndnum].type != SOUND_DUMMY) + { + has_sound = TRUE; + break; + } - expand_machine_driver(game->drv, &driver); - cpu = driver.cpu; - sound = driver.sound; - - i = 0; - while (i < MAX_SOUND && !has_sound) - { - if (sound[i].type != SOUND_DUMMY) - has_sound = 1; - ++i; - } - - fprintf(out, "\t\tspeaker); speakers++) + if (config->speaker[speakers].tag == NULL) break; - fprintf(out, " channels=\"%d\"", speakers); - } - else - fprintf(out, " channels=\"0\""); - fprintf(out, "/>\n"); + fprintf(out, "\t\t\n", speakers); } -static void print_game_driver(FILE* out, const game_driver* game) + +/*------------------------------------------------- + print_game_driver - print driver status +-------------------------------------------------*/ + +static void print_game_driver(FILE *out, const game_driver *game, const machine_config *config) { - machine_config driver; - - expand_machine_driver(game->drv, &driver); - fprintf(out, "\t\ttotal_colors); fprintf(out, "/>\n"); } -/* Print the MAME info record for a game */ -static void print_game_info(FILE* out, const game_driver* game) -{ - const char *start; - const game_driver *clone_of; - /* No action if not a game */ +/*------------------------------------------------- + print_game_info - print the XML information + for one particular game driver +-------------------------------------------------*/ + +static void print_game_info(FILE *out, const game_driver *game) +{ + const input_port_entry *input; + const game_driver *clone_of; + machine_config *config; + const char *start; + + /* no action if not a game */ if (game->flags & GAME_NO_STANDALONE) return; - fprintf(out, "\t<" XML_TOP); + /* start tracking resources and allocate the machine and input configs */ + begin_resource_tracking(); + config = machine_config_alloc(game->drv); + input = input_port_allocate(game->ipt, NULL); + /* print the header and the game name */ + fprintf(out, "\t<" XML_TOP); fprintf(out, " name=\"%s\"", xml_normalize_string(game->name) ); + /* strip away any path information from the source_file and output it */ start = strrchr(game->source_file, '/'); - if (!start) + if (start == NULL) start = strrchr(game->source_file, '\\'); - if (!start) + if (start == NULL) start = game->source_file - 1; fprintf(out, " sourcefile=\"%s\"", xml_normalize_string(start + 1)); + /* append bios and runnable flags */ if (game->flags & GAME_IS_BIOS_ROOT) fprintf(out, " isbios=\"yes\""); - if (game->flags & GAME_NO_STANDALONE) fprintf(out, " runnable=\"no\""); + /* display clone information */ clone_of = driver_get_clone(game); - if (clone_of && !(clone_of->flags & GAME_IS_BIOS_ROOT)) + if (clone_of != NULL && !(clone_of->flags & GAME_IS_BIOS_ROOT)) fprintf(out, " cloneof=\"%s\"", xml_normalize_string(clone_of->name)); - - if (clone_of) + if (clone_of != NULL) fprintf(out, " romof=\"%s\"", xml_normalize_string(clone_of->name)); - print_game_sampleof(out, game); - + /* display sample information and close the game tag */ + print_game_sampleof(out, game, config); fprintf(out, ">\n"); - if (game->description) + /* output game description */ + if (game->description != NULL) fprintf(out, "\t\t%s\n", xml_normalize_string(game->description)); /* print the year only if is a number */ - if (game->year && strspn(game->year,"0123456789")==strlen(game->year)) - fprintf(out, "\t\t%s\n", xml_normalize_string(game->year) ); + if (game->year != NULL && strspn(game->year, "0123456789") == strlen(game->year)) + fprintf(out, "\t\t%s\n", xml_normalize_string(game->year)); - if (game->manufacturer) + /* print the manufacturer information */ + if (game->manufacturer != NULL) fprintf(out, "\t\t%s\n", xml_normalize_string(game->manufacturer)); + /* now print various additional information */ print_game_bios(out, game); print_game_rom(out, game); - print_game_sample(out, game); - print_game_micro(out, game); - print_game_display(out, game); - print_game_sound(out, game); - print_game_input(out, game); - print_game_switch(out, game); - print_game_driver(out, game); + print_game_sample(out, game, config); + print_game_chips(out, game, config); + print_game_display(out, game, config); + print_game_sound(out, game, config); + print_game_input(out, game, input); + print_game_switches(out, game, input); + print_game_driver(out, game, config); #ifdef MESS print_game_device(out, game); print_game_ramoptions(out, game); #endif + /* close the topmost tag */ fprintf(out, "\t\n"); + + /* release resources */ + end_resource_tracking(); + machine_config_free(config); } -static void print_mame_data(FILE* out, const game_driver* const games[], const char *gamename) -{ - int j; - /* print games */ - for(j=0;games[j];++j) - if (mame_strwildcmp(gamename, games[j]->name) == 0) - print_game_info(out, games[j]); -} +/*------------------------------------------------- + print_mame_xml - print the XML information + for all known games +-------------------------------------------------*/ -/* Print the MAME database in XML format */ -void print_mame_xml(FILE* out, const game_driver* const games[], const char *gamename) +void print_mame_xml(FILE *out, const game_driver *const games[], const char *gamename) { + int drvnum; + fprintf(out, "\n" "name) == 0) + print_game_info(out, games[drvnum]); fprintf(out, "\n"); } diff --git a/src/emu/info.h b/src/emu/info.h index f633e8d0c02..b12259b80d4 100644 --- a/src/emu/info.h +++ b/src/emu/info.h @@ -16,7 +16,13 @@ #include "mamecore.h" -/* Print the MAME database in XML format */ + +/*************************************************************************** + FUNCTION PROTOTYPES +***************************************************************************/ + +/* print the MAME database in XML format */ void print_mame_xml(FILE* out, const game_driver* const games[], const char *gamename); + #endif /* __INFO_H__ */ diff --git a/src/emu/mame.c b/src/emu/mame.c index c4bcc6afd97..4d6f5ddb5e0 100644 --- a/src/emu/mame.c +++ b/src/emu/mame.c @@ -1329,15 +1329,14 @@ void mame_parse_ini_files(core_options *options, const game_driver *driver) { const game_driver *parent = driver_get_clone(driver); const game_driver *gparent = (parent != NULL) ? driver_get_clone(parent) : NULL; + machine_config *config; astring *sourcename; - machine_config drv; - - /* expand the machine driver to look at the info */ - expand_machine_driver(driver->drv, &drv); /* parse "vector.ini" for vector games */ - if (drv.video_attributes & VIDEO_TYPE_VECTOR) + config = machine_config_alloc(driver->drv); + if (config->video_attributes & VIDEO_TYPE_VECTOR) parse_ini_file(options, "vector"); + machine_config_free(config); /* next parse "source/.ini"; if that doesn't exist, try .ini */ sourcename = core_filename_extract_base(astring_alloc(), driver->source_file, TRUE); @@ -1411,11 +1410,8 @@ static running_machine *create_machine(const game_driver *driver) /* initialize the driver-related variables in the machine */ machine->gamedrv = driver; - machine->drv = malloc(sizeof(*machine->drv)); - if (machine->drv == NULL) - goto error; - machine->basename = mame_strdup(machine->gamedrv->name); - expand_machine_driver(machine->gamedrv->drv, (machine_config *)machine->drv); + machine->basename = mame_strdup(driver->name); + machine->drv = machine_config_alloc(driver->drv); /* allocate the driver data */ if (machine->drv->driver_data_size != 0) @@ -1430,7 +1426,7 @@ error: if (machine->driver_data != NULL) free(machine->driver_data); if (machine->drv != NULL) - free((machine_config *)machine->drv); + machine_config_free((machine_config *)machine->drv); if (machine->mame_data != NULL) free(machine->mame_data); if (machine != NULL) @@ -1499,7 +1495,7 @@ static void destroy_machine(running_machine *machine) if (machine->driver_data != NULL) free(machine->driver_data); if (machine->drv != NULL) - free((machine_config *)machine->drv); + machine_config_free((machine_config *)machine->drv); if (machine->mame_data != NULL) free(machine->mame_data); if (machine->basename != NULL) diff --git a/src/emu/validity.c b/src/emu/validity.c index 75329ccb404..133a7d88fe9 100644 --- a/src/emu/validity.c +++ b/src/emu/validity.c @@ -1422,7 +1422,7 @@ int mame_validitychecks(const game_driver *curdriver) { const game_driver *driver = drivers[drivnum]; UINT32 region_length[REGION_MAX]; - machine_config drv; + machine_config *config; /* ASG -- trying this for a while to see if submission failures increase */ #if 1 @@ -1433,43 +1433,45 @@ int mame_validitychecks(const game_driver *curdriver) /* expand the machine driver */ expansion -= osd_profiling_ticks(); - expand_machine_driver(driver->drv, &drv); + config = machine_config_alloc(driver->drv); expansion += osd_profiling_ticks(); /* validate the driver entry */ driver_checks -= osd_profiling_ticks(); - error = validate_driver(drivnum, &drv) || error; + error = validate_driver(drivnum, config) || error; driver_checks += osd_profiling_ticks(); /* validate the ROM information */ rom_checks -= osd_profiling_ticks(); - error = validate_roms(drivnum, &drv, region_length) || error; + error = validate_roms(drivnum, config, region_length) || error; rom_checks += osd_profiling_ticks(); /* validate the CPU information */ cpu_checks -= osd_profiling_ticks(); - error = validate_cpu(drivnum, &drv, region_length) || error; + error = validate_cpu(drivnum, config, region_length) || error; cpu_checks += osd_profiling_ticks(); /* validate the display */ display_checks -= osd_profiling_ticks(); - error = validate_display(drivnum, &drv) || error; + error = validate_display(drivnum, config) || error; display_checks += osd_profiling_ticks(); /* validate the graphics decoding */ gfx_checks -= osd_profiling_ticks(); - error = validate_gfx(drivnum, &drv, region_length) || error; + error = validate_gfx(drivnum, config, region_length) || error; gfx_checks += osd_profiling_ticks(); /* validate input ports */ input_checks -= osd_profiling_ticks(); - error = validate_inputs(drivnum, &drv, &inputports) || error; + error = validate_inputs(drivnum, config, &inputports) || error; input_checks += osd_profiling_ticks(); /* validate sounds and speakers */ sound_checks -= osd_profiling_ticks(); - error = validate_sound(drivnum, &drv) || error; + error = validate_sound(drivnum, config) || error; sound_checks += osd_profiling_ticks(); + + machine_config_free(config); } #ifdef MESS