From b797437b3b3c356e0c39ed6eef44d15468167acf Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 7 Jul 2010 13:25:03 +0000 Subject: [PATCH] Added per-device image softlist loading routine [Miodrag Milanovic] Renamed feof to image_feof (in device_image_interface) in order to compile on FreeBSD [El Barto] --- src/emu/devimage.c | 17 ++++++++++++++--- src/emu/devlegcy.h | 2 ++ src/emu/diimage.h | 7 +++++-- src/emu/softlist.c | 6 ++---- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/emu/devimage.c b/src/emu/devimage.c index 017ae1ccc68..8afe752f044 100644 --- a/src/emu/devimage.c +++ b/src/emu/devimage.c @@ -303,6 +303,7 @@ bool legacy_image_device_base::load_internal(const char *path, bool is_create, i image_error_t err; UINT32 open_plan[4]; int i; + bool softload = FALSE; /* first unload the image */ unload(); @@ -319,7 +320,7 @@ bool legacy_image_device_base::load_internal(const char *path, bool is_create, i goto done; /* Check if there's a software list defined for this device and use that if we're not creating an image */ - if (is_create || !load_software_part( this, path, &m_software_info_ptr, &m_software_part_ptr, &m_full_software_name ) ) + if (is_create || !(softload=load_software_part( this, path, &m_software_info_ptr, &m_software_part_ptr, &m_full_software_name )) ) { /* determine open plan */ determine_open_plan(is_create, open_plan); @@ -333,7 +334,7 @@ bool legacy_image_device_base::load_internal(const char *path, bool is_create, i goto done; } } - + /* Copy some image information when we have been loaded through a software list */ if ( m_software_info_ptr ) { @@ -344,7 +345,7 @@ bool legacy_image_device_base::load_internal(const char *path, bool is_create, i } /* did we fail to find the file? */ - if (!is_loaded()) + if (!is_loaded() && !softload) { err = IMAGE_ERROR_FILENOTFOUND; goto done; @@ -502,6 +503,16 @@ int legacy_image_device_base::call_load() } } +bool legacy_image_device_base::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) +{ + device_image_softlist_load_func func = reinterpret_cast(m_config.get_legacy_config_fct(DEVINFO_FCT_IMAGE_SOFTLIST_LOAD)); + if (func) { + return (*func)(*this,swlist,swname,start_entry); + } else { + return FALSE; + } +} + int legacy_image_device_base::call_create(int format_type, option_resolution *format_options) { device_image_create_func func = reinterpret_cast(m_config.get_legacy_config_fct(DEVINFO_FCT_IMAGE_CREATE)); diff --git a/src/emu/devlegcy.h b/src/emu/devlegcy.h index 7f5288be919..d58d41c6e3b 100644 --- a/src/emu/devlegcy.h +++ b/src/emu/devlegcy.h @@ -159,6 +159,7 @@ enum DEVINFO_FCT_IMAGE_DISPLAY, /* R/O: device_image_display_func */ DEVINFO_FCT_IMAGE_PARTIAL_HASH, /* R/O: device_image_partialhash_func */ DEVINFO_FCT_IMAGE_GET_DEVICES, /* R/O: device_image_get_devices_func */ + DEVINFO_FCT_IMAGE_SOFTLIST_LOAD, /* R/O: device_image_softlist_load_func */ DEVINFO_FCT_IMAGE_LAST = DEVINFO_FCT_FIRST + 0x0fff, /* --- the following bits of info are returned as NULL-terminated strings --- */ @@ -633,6 +634,7 @@ public: virtual bool create(const char *path, const image_device_format *create_format, option_resolution *create_args); virtual int call_load(); + virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); virtual int call_create(int format_type, option_resolution *format_options); virtual void call_unload(); virtual void call_display(); diff --git a/src/emu/diimage.h b/src/emu/diimage.h index cab1a0713af..ef2bd496910 100644 --- a/src/emu/diimage.h +++ b/src/emu/diimage.h @@ -115,7 +115,7 @@ typedef void (*device_image_unload_func)(device_image_interface &image); typedef void (*device_image_display_func)(device_image_interface &image); typedef void (*device_image_partialhash_func)(char *, const unsigned char *, unsigned long, unsigned int); typedef void (*device_image_get_devices_func)(device_image_interface &device); - +typedef bool (*device_image_softlist_load_func)(device_image_interface &image, char *swlist, char *swname, rom_entry *start_entry); //************************************************************************** // MACROS @@ -141,6 +141,8 @@ typedef void (*device_image_get_devices_func)(device_image_interface &device); #define DEVICE_IMAGE_GET_DEVICES_NAME(name) device_image_get_devices_##name #define DEVICE_IMAGE_GET_DEVICES(name) void DEVICE_IMAGE_GET_DEVICES_NAME(name)(device_image_interface &image) +#define DEVICE_IMAGE_SOFTLIST_LOAD_NAME(name) device_softlist_load_##name +#define DEVICE_IMAGE_SOFTLIST_LOAD(name) bool DEVICE_IMAGE_SOFTLIST_LOAD_NAME(name)(device_image_interface &image, char *swlist, char *swname, rom_entry *start_entry) // ======================> device_config_image_interface @@ -200,6 +202,7 @@ public: virtual void unload() = 0; virtual int call_load() = 0; + virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) = 0; virtual int call_create(int format_type, option_resolution *format_options) = 0; virtual void call_unload() = 0; virtual void call_display() = 0; @@ -234,7 +237,7 @@ public: UINT64 ftell() { check_for_file(); return core_ftell(m_file); } int fgetc() { char ch; if (fread(&ch, 1) != 1) ch = '\0'; return ch; } char *fgets(char *buffer, UINT32 length) { check_for_file(); return core_fgets(buffer, length, m_file); } - int feof() { check_for_file(); return core_feof(m_file); } + int image_feof() { check_for_file(); return core_feof(m_file); } void *ptr() {check_for_file(); return (void *) core_fbuffer(m_file); } // configuration access const device_config_image_interface &image_config() const { return m_image_config; } diff --git a/src/emu/softlist.c b/src/emu/softlist.c index f1306f91e25..167d41dcdd3 100644 --- a/src/emu/softlist.c +++ b/src/emu/softlist.c @@ -1087,7 +1087,7 @@ bool load_software_part(device_image_interface *image, const char *path, softwar { /* Load the software part */ try { - load_software_part_region( &image->device(), (char *)swlist_name, (char *)software_info_ptr->shortname, software_part_ptr->romdata ); + result = image->call_softlist_load((char *)swlist_name, (char *)software_info_ptr->shortname, software_part_ptr->romdata ); } catch (emu_fatalerror &fatal) { @@ -1136,9 +1136,7 @@ bool load_software_part(device_image_interface *image, const char *path, softwar /* Tell the world which part we actually loaded */ *full_sw_name = auto_alloc_array( image->device().machine, char, strlen(swlist_name) + strlen(software_info_ptr->shortname) + strlen(software_part_ptr->name) + 3 ); - sprintf( *full_sw_name, "%s:%s:%s", swlist_name, software_info_ptr->shortname, software_part_ptr->name ); - - result = true; + sprintf( *full_sw_name, "%s:%s:%s", swlist_name, software_info_ptr->shortname, software_part_ptr->name ); } /* Close the software list if it's still open */