Added CHD support in softlists [Miodrag Milanovic]

This commit is contained in:
Miodrag Milanovic 2011-01-10 12:42:28 +00:00
parent 8332fea6d4
commit 73fd06883a
5 changed files with 91 additions and 14 deletions

View File

@ -456,7 +456,7 @@ static void audit_one_disk(core_options *options, const rom_entry *rom, const ga
record->exphash = ROM_GETHASHDATA(rom);
/* open the disk */
err = open_disk_image_options(options, gamedrv, rom, &source_file, &source);
err = open_disk_image_options(options, gamedrv, rom, &source_file, &source, NULL);
/* if we failed, report the error */
if (err != CHDERR_NONE)

View File

@ -79,10 +79,16 @@ static DEVICE_IMAGE_LOAD(cdrom)
dev_cdrom_t *cdrom = get_safe_token(&image.device());
chd_error err = (chd_error)0;
chd_file *chd = NULL;
astring tempstring;
err = chd_open_file( image.image_core_file(), CHD_OPEN_READ, NULL, &chd ); /* CDs are never writeable */
if ( err )
goto error;
if (image.software_entry() == NULL)
{
err = chd_open_file( image.image_core_file(), CHD_OPEN_READ, NULL, &chd ); /* CDs are never writeable */
if ( err )
goto error;
} else {
chd = get_disk_handle(image.device().machine, image.device().subtag(tempstring,"cdrom"));
}
/* open the CHD file */
cdrom->cdrom_handle = cdrom_open( chd );
@ -141,7 +147,8 @@ static DEVICE_START(cdrom)
-------------------------------------------------*/
static DEVICE_IMAGE_SOFTLIST_LOAD(cdrom)
{
return image.load_software(swlist, swname, start_entry);
load_software_part_region( &image.device(), swlist, swname, start_entry );
return TRUE;
}
/*-------------------------------------------------

View File

@ -949,9 +949,9 @@ static void process_rom_entries(rom_load_data *romdata, const char *regiontag, c
up the parent and loading by checksum
-------------------------------------------------*/
chd_error open_disk_image(const game_driver *gamedrv, const rom_entry *romp, mame_file **image_file, chd_file **image_chd)
chd_error open_disk_image(const game_driver *gamedrv, const rom_entry *romp, mame_file **image_file, chd_file **image_chd,const char *locationtag)
{
return open_disk_image_options(mame_options(), gamedrv, romp, image_file, image_chd);
return open_disk_image_options(mame_options(), gamedrv, romp, image_file, image_chd, locationtag);
}
@ -961,7 +961,7 @@ chd_error open_disk_image(const game_driver *gamedrv, const rom_entry *romp, mam
checksum
-------------------------------------------------*/
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)
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,const char *locationtag)
{
const game_driver *drv, *searchdrv;
const rom_entry *region, *rom;
@ -986,6 +986,12 @@ chd_error open_disk_image_options(core_options *options, const game_driver *game
filerr = mame_fopen_options(options, SEARCHPATH_IMAGE, fname, OPEN_FLAG_READ, image_file);
}
if (filerr != FILERR_NONE && locationtag!=NULL)
{
astring fname(locationtag, PATH_SEPARATOR, ROM_GETNAME(romp), ".chd");
filerr = mame_fopen_options(options, SEARCHPATH_IMAGE, fname, OPEN_FLAG_READ, image_file);
}
/* did the file open succeed? */
if (filerr == FILERR_NONE)
{
@ -1101,7 +1107,7 @@ done:
for a region
-------------------------------------------------*/
static void process_disk_entries(rom_load_data *romdata, const char *regiontag, const rom_entry *romp)
static void process_disk_entries(rom_load_data *romdata, const char *regiontag, const rom_entry *romp, const char *locationtag)
{
/* loop until we hit the end of this region */
for ( ; !ROMENTRY_ISREGIONEND(romp); romp++)
@ -1122,7 +1128,7 @@ static void process_disk_entries(rom_load_data *romdata, const char *regiontag,
/* first open the source drive */
LOG(("Opening disk image: %s\n", filename.cstr()));
err = open_disk_image(romdata->machine->gamedrv, romp, &chd.origfile, &chd.origchd);
err = open_disk_image(romdata->machine->gamedrv, romp, &chd.origfile, &chd.origchd, locationtag);
if (err != CHDERR_NONE)
{
if (err == CHDERR_FILE_NOT_FOUND)
@ -1283,7 +1289,7 @@ void load_software_part_region(device_t *device, char *swlist, char *swname, rom
if (ROMREGION_ISROMDATA(region))
process_rom_entries(romdata, locationtag, region + 1);
else if (ROMREGION_ISDISKDATA(region))
process_disk_entries(romdata, locationtag, region + 1);
process_disk_entries(romdata, core_strdup(regiontag.cstr()), region + 1, locationtag);
}
/* now go back and post-process all the regions */
@ -1346,7 +1352,7 @@ static void process_region_list(rom_load_data *romdata)
process_rom_entries(romdata, ROMREGION_ISLOADBYNAME(region) ? ROMREGION_GETTAG(region) : NULL, region + 1);
}
else if (ROMREGION_ISDISKDATA(region))
process_disk_entries(romdata, ROMREGION_GETTAG(region), region + 1);
process_disk_entries(romdata, ROMREGION_GETTAG(region), region + 1, NULL);
}
/* now go back and post-process all the regions */

View File

@ -313,10 +313,10 @@ astring &rom_region_name(astring &result, const game_driver *drv, const rom_sour
/* ----- disk handling ----- */
/* open a disk image, searching up the parent and loading by checksum */
chd_error open_disk_image(const game_driver *gamedrv, const rom_entry *romp, mame_file **image_file, chd_file **image_chd);
chd_error open_disk_image(const game_driver *gamedrv, const rom_entry *romp, mame_file **image_file, chd_file **image_chd,const char *locationtag);
/* open a disk image, searching up the parent and loading by checksum */
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);
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,const char *locationtag);
/* return a pointer to the CHD file associated with the given region */
chd_file *get_disk_handle(running_machine *machine, const char *region);

View File

@ -530,6 +530,35 @@ static void start_handler(void *data, const char *tagname, const char **attribut
/* Missing dataarea name or size */
}
}
else if (!strcmp(tagname, "diskarea"))
{
const char *str_name = NULL;
for ( ; attributes[0]; attributes += 2 )
{
if ( !strcmp( attributes[0], "name" ) )
str_name = attributes[1];
}
if ( str_name )
{
if ( swlist->softinfo )
{
char *s = (char *)pool_malloc_lib(swlist->pool, ( strlen( str_name ) + 1 ) * sizeof(char) );
if ( !s )
return;
strcpy( s, str_name );
/* ROM_REGION( length, "name", flags ) */
add_rom_entry( swlist, s, NULL, 0, 1, ROMENTRYTYPE_REGION | ROMREGION_DATATYPEDISK);
}
}
else
{
/* Missing dataarea name or size */
}
}
else if ( !strcmp(tagname, "feature") )
{
const char *str_feature_name = NULL;
@ -662,6 +691,41 @@ static void start_handler(void *data, const char *tagname, const char **attribut
/* Missing name, size, crc, sha1, or offset */
}
}
else
if (!strcmp(tagname, "disk"))
{
const char *str_name = NULL;
const char *str_sha1 = NULL;
const char *str_status = NULL;
for ( ; attributes[0]; attributes += 2 )
{
if ( !strcmp( attributes[0], "name" ) )
str_name = attributes[1];
if ( !strcmp( attributes[0], "sha1" ) )
str_sha1 = attributes[1];
if ( !strcmp( attributes[0], "status" ) )
str_status = attributes[1];
}
if ( swlist->softinfo )
{
if ( str_name && str_sha1 )
{
char *s_name = (char *)pool_malloc_lib(swlist->pool, ( strlen( str_name ) + 1 ) * sizeof(char) );
char *hashdata = (char *)pool_malloc_lib( swlist->pool, sizeof(char) * ( strlen(str_sha1) + 7 + 4 ) );
int baddump = ( str_status && !strcmp(str_status, "baddump") ) ? 1 : 0;
int nodump = ( str_status && !strcmp(str_status, "nodump" ) ) ? 1 : 0;
if ( !s_name || !hashdata )
return;
strcpy( s_name, str_name );
sprintf( hashdata, "s:%s#%s", str_sha1, ( nodump ? NO_DUMP : ( baddump ? BAD_DUMP : "" ) ) );
add_rom_entry( swlist, s_name, hashdata, 0, 0, ROMENTRYTYPE_ROM | DISK_READONLY );
}
}
}
else
unknown_tag(&swlist->state, tagname);
break;