From 73fd06883a04f9b0237053bc9865f88f861f6e2d Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Mon, 10 Jan 2011 12:42:28 +0000 Subject: [PATCH] Added CHD support in softlists [Miodrag Milanovic] --- src/emu/audit.c | 2 +- src/emu/imagedev/chd_cd.c | 15 ++++++--- src/emu/romload.c | 20 +++++++----- src/emu/romload.h | 4 +-- src/emu/softlist.c | 64 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 91 insertions(+), 14 deletions(-) diff --git a/src/emu/audit.c b/src/emu/audit.c index adcbffa302b..28a5e4ab868 100644 --- a/src/emu/audit.c +++ b/src/emu/audit.c @@ -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) diff --git a/src/emu/imagedev/chd_cd.c b/src/emu/imagedev/chd_cd.c index 41d22024ce3..2c3962b8804 100644 --- a/src/emu/imagedev/chd_cd.c +++ b/src/emu/imagedev/chd_cd.c @@ -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; } /*------------------------------------------------- diff --git a/src/emu/romload.c b/src/emu/romload.c index 1ec17b0746b..9f30b3fc132 100644 --- a/src/emu/romload.c +++ b/src/emu/romload.c @@ -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 */ diff --git a/src/emu/romload.h b/src/emu/romload.h index 0c66ff7add9..c20eef9a7b3 100644 --- a/src/emu/romload.h +++ b/src/emu/romload.h @@ -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); diff --git a/src/emu/softlist.c b/src/emu/softlist.c index 88890acd323..ec90d8c2654 100644 --- a/src/emu/softlist.c +++ b/src/emu/softlist.c @@ -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;