src/emu/devimage.c
| r14705 | r14706 | |
| 1 | | /*************************************************************************** |
| 2 | | |
| 3 | | devimage.c |
| 4 | | |
| 5 | | Legacy image device helpers. |
| 6 | | |
| 7 | | **************************************************************************** |
| 8 | | |
| 9 | | Copyright Miodrag Milanovic |
| 10 | | All rights reserved. |
| 11 | | |
| 12 | | Redistribution and use in source and binary forms, with or without |
| 13 | | modification, are permitted provided that the following conditions are |
| 14 | | met: |
| 15 | | |
| 16 | | * Redistributions of source code must retain the above copyright |
| 17 | | notice, this list of conditions and the following disclaimer. |
| 18 | | * Redistributions in binary form must reproduce the above copyright |
| 19 | | notice, this list of conditions and the following disclaimer in |
| 20 | | the documentation and/or other materials provided with the |
| 21 | | distribution. |
| 22 | | * Neither the name 'MAME' nor the names of its contributors may be |
| 23 | | used to endorse or promote products derived from this software |
| 24 | | without specific prior written permission. |
| 25 | | |
| 26 | | THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR |
| 27 | | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 28 | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 29 | | DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, |
| 30 | | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 31 | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 32 | | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 33 | | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 34 | | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 35 | | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 36 | | POSSIBILITY OF SUCH DAMAGE. |
| 37 | | |
| 38 | | ***************************************************************************/ |
| 39 | | |
| 40 | | |
| 41 | | #include "emu.h" |
| 42 | | #include "devlegcy.h" |
| 43 | | |
| 44 | | |
| 45 | | //************************************************************************** |
| 46 | | // LEGACY IMAGE DEVICE CONFIGURATION |
| 47 | | //************************************************************************** |
| 48 | | |
| 49 | | //------------------------------------------------- |
| 50 | | // legacy_device_base - destructor |
| 51 | | //------------------------------------------------- |
| 52 | | |
| 53 | | legacy_image_device_base::~legacy_image_device_base() |
| 54 | | { |
| 55 | | } |
| 56 | | |
| 57 | | //************************************************************************** |
| 58 | | // LIVE LEGACY IMAGE DEVICE |
| 59 | | //************************************************************************** |
| 60 | | |
| 61 | | //------------------------------------------------- |
| 62 | | // legacy_image_device_base - constructor |
| 63 | | //------------------------------------------------- |
| 64 | | |
| 65 | | legacy_image_device_base::legacy_image_device_base(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, UINT32 clock, device_get_config_func get_config) |
| 66 | | : legacy_device_base(mconfig, type, tag, owner, clock, get_config), |
| 67 | | device_image_interface(mconfig, *this) |
| 68 | | { |
| 69 | | } |
| 70 | | |
| 71 | | |
| 72 | | //------------------------------------------------- |
| 73 | | // device_config_complete - update configuration |
| 74 | | // based on completed device setup |
| 75 | | //------------------------------------------------- |
| 76 | | |
| 77 | | void legacy_image_device_base::device_config_complete() |
| 78 | | { |
| 79 | | image_device_format **formatptr; |
| 80 | | image_device_format *format; |
| 81 | | formatptr = &m_formatlist; |
| 82 | | int cnt = 0; |
| 83 | | |
| 84 | | int format_count = get_legacy_int(DEVINFO_INT_IMAGE_CREATE_OPTCOUNT); |
| 85 | | |
| 86 | | for (int i = 0; i < format_count; i++) |
| 87 | | { |
| 88 | | // only add if creatable |
| 89 | | if (get_legacy_string(DEVINFO_PTR_IMAGE_CREATE_OPTSPEC + i)) { |
| 90 | | // allocate a new format |
| 91 | | format = global_alloc_clear(image_device_format); |
| 92 | | |
| 93 | | // populate it |
| 94 | | format->m_index = cnt; |
| 95 | | format->m_name = get_legacy_string(DEVINFO_STR_IMAGE_CREATE_OPTNAME + i); |
| 96 | | format->m_description = get_legacy_string(DEVINFO_STR_IMAGE_CREATE_OPTDESC + i); |
| 97 | | format->m_extensions = get_legacy_string(DEVINFO_STR_IMAGE_CREATE_OPTEXTS + i); |
| 98 | | format->m_optspec = get_legacy_string(DEVINFO_PTR_IMAGE_CREATE_OPTSPEC + i); |
| 99 | | |
| 100 | | // and append it to the list |
| 101 | | *formatptr = format; |
| 102 | | formatptr = &format->m_next; |
| 103 | | cnt++; |
| 104 | | } |
| 105 | | } |
| 106 | | |
| 107 | | update_names(); |
| 108 | | |
| 109 | | // Override in case of hardcoded values |
| 110 | | if (strlen(get_legacy_string(DEVINFO_STR_IMAGE_INSTANCE_NAME))>0) { |
| 111 | | m_instance_name = get_legacy_string(DEVINFO_STR_IMAGE_INSTANCE_NAME); |
| 112 | | } |
| 113 | | if (strlen(get_legacy_string(DEVINFO_STR_IMAGE_BRIEF_INSTANCE_NAME))>0) { |
| 114 | | m_brief_instance_name = get_legacy_string(DEVINFO_STR_IMAGE_BRIEF_INSTANCE_NAME); |
| 115 | | } |
| 116 | | } |
| 117 | | |
| 118 | | |
| 119 | | bool legacy_image_device_base::call_load() |
| 120 | | { |
| 121 | | device_image_load_func func = reinterpret_cast<device_image_load_func>(get_legacy_fct(DEVINFO_FCT_IMAGE_LOAD)); |
| 122 | | if (func) { |
| 123 | | return (*func)(*this); |
| 124 | | } else { |
| 125 | | return FALSE; |
| 126 | | } |
| 127 | | } |
| 128 | | |
| 129 | | bool legacy_image_device_base::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) |
| 130 | | { |
| 131 | | device_image_softlist_load_func func = reinterpret_cast<device_image_softlist_load_func>(get_legacy_fct(DEVINFO_FCT_IMAGE_SOFTLIST_LOAD)); |
| 132 | | if (func) { |
| 133 | | return (*func)(*this,swlist,swname,start_entry); |
| 134 | | } else { |
| 135 | | return FALSE; |
| 136 | | } |
| 137 | | } |
| 138 | | |
| 139 | | bool legacy_image_device_base::call_create(int format_type, option_resolution *format_options) |
| 140 | | { |
| 141 | | device_image_create_func func = reinterpret_cast<device_image_create_func>(get_legacy_fct(DEVINFO_FCT_IMAGE_CREATE)); |
| 142 | | if (func) { |
| 143 | | return (*func)(*this,format_type,format_options); |
| 144 | | } else { |
| 145 | | return FALSE; |
| 146 | | } |
| 147 | | } |
| 148 | | |
| 149 | | void legacy_image_device_base::call_unload() |
| 150 | | { |
| 151 | | device_image_unload_func func = reinterpret_cast<device_image_unload_func>(get_legacy_fct(DEVINFO_FCT_IMAGE_UNLOAD)); |
| 152 | | if (func) (*func)(*this); |
| 153 | | } |
| 154 | | |
| 155 | | void legacy_image_device_base::call_display() |
| 156 | | { |
| 157 | | device_image_display_func func = reinterpret_cast<device_image_display_func>(get_legacy_fct(DEVINFO_FCT_IMAGE_DISPLAY)); |
| 158 | | if (func) (*func)(*this); |
| 159 | | } |
| 160 | | |
| 161 | | void legacy_image_device_base::call_display_info() |
| 162 | | { |
| 163 | | device_image_display_info_func func = reinterpret_cast<device_image_display_info_func>(get_legacy_fct(DEVINFO_FCT_IMAGE_DISPLAY_INFO)); |
| 164 | | if (func) (*func)(*this); |
| 165 | | } |
| 166 | | |
| 167 | | void legacy_image_device_base::call_get_devices() |
| 168 | | { |
| 169 | | device_image_get_devices_func func = reinterpret_cast<device_image_get_devices_func>(get_legacy_fct(DEVINFO_FCT_IMAGE_GET_DEVICES)); |
| 170 | | if (func) (*func)(*this); |
| 171 | | } |
| 172 | | |
| 173 | | device_image_partialhash_func legacy_image_device_base::get_partial_hash() const |
| 174 | | { |
| 175 | | return reinterpret_cast<device_image_partialhash_func>(get_legacy_fct(DEVINFO_FCT_IMAGE_PARTIAL_HASH)); |
| 176 | | } |
src/emu/diimage.h
| r14705 | r14706 | |
| 108 | 108 | |
| 109 | 109 | // device image interface function types |
| 110 | 110 | typedef int (*device_image_load_func)(device_image_interface &image); |
| 111 | | typedef int (*device_image_create_func)(device_image_interface &image, int format_type, option_resolution *format_options); |
| 112 | 111 | typedef void (*device_image_unload_func)(device_image_interface &image); |
| 113 | | typedef void (*device_image_display_func)(device_image_interface &image); |
| 114 | 112 | typedef void (*device_image_partialhash_func)(hash_collection &, const unsigned char *, unsigned long, const char *); |
| 115 | | typedef void (*device_image_get_devices_func)(device_image_interface &device); |
| 116 | | typedef bool (*device_image_softlist_load_func)(device_image_interface &image, char *swlist, char *swname, rom_entry *start_entry); |
| 117 | 113 | typedef void (*device_image_display_info_func)(device_image_interface &image); |
| 118 | 114 | |
| 119 | 115 | //************************************************************************** |
| r14705 | r14706 | |
| 128 | 124 | #define DEVICE_IMAGE_LOAD_NAME(name) device_load_##name |
| 129 | 125 | #define DEVICE_IMAGE_LOAD(name) int DEVICE_IMAGE_LOAD_NAME(name)(device_image_interface &image) |
| 130 | 126 | |
| 131 | | #define DEVICE_IMAGE_CREATE_NAME(name) device_create_##name |
| 132 | | #define DEVICE_IMAGE_CREATE(name) int DEVICE_IMAGE_CREATE_NAME(name)(device_image_interface &image, int create_format, option_resolution *create_args) |
| 133 | | |
| 134 | 127 | #define DEVICE_IMAGE_UNLOAD_NAME(name) device_unload_##name |
| 135 | 128 | #define DEVICE_IMAGE_UNLOAD(name) void DEVICE_IMAGE_UNLOAD_NAME(name)(device_image_interface &image) |
| 136 | 129 | |
| 137 | | #define DEVICE_IMAGE_DISPLAY_NAME(name) device_image_display_func##name |
| 138 | | #define DEVICE_IMAGE_DISPLAY(name) void DEVICE_IMAGE_DISPLAY_NAME(name)(device_image_interface &image) |
| 139 | | |
| 140 | 130 | #define DEVICE_IMAGE_DISPLAY_INFO_NAME(name) device_image_display_info_func##name |
| 141 | 131 | #define DEVICE_IMAGE_DISPLAY_INFO(name) void DEVICE_IMAGE_DISPLAY_INFO_NAME(name)(device_image_interface &image) |
| 142 | 132 | |
| 143 | | #define DEVICE_IMAGE_GET_DEVICES_NAME(name) device_image_get_devices_##name |
| 144 | | #define DEVICE_IMAGE_GET_DEVICES(name) void DEVICE_IMAGE_GET_DEVICES_NAME(name)(device_image_interface &image) |
| 145 | | |
| 146 | | #define DEVICE_IMAGE_SOFTLIST_LOAD_NAME(name) device_softlist_load_##name |
| 147 | | #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) |
| 148 | | |
| 149 | | |
| 150 | | |
| 151 | 133 | // ======================> device_image_interface |
| 152 | 134 | |
| 153 | 135 | // class representing interface-specific live image |
| r14705 | r14706 | |
| 170 | 152 | virtual void call_unload() { } |
| 171 | 153 | virtual void call_display() { } |
| 172 | 154 | virtual void call_display_info() { } |
| 173 | | virtual void call_get_devices() { } |
| 174 | 155 | virtual device_image_partialhash_func get_partial_hash() const { return NULL; } |
| 175 | 156 | virtual iodevice_t image_type() const = 0; |
| 176 | 157 | virtual bool is_readable() const = 0; |
src/emu/devlegcy.h
| r14705 | r14706 | |
| 134 | 134 | |
| 135 | 135 | DEVINFO_STR_CLASS_SPECIFIC = 0x34000, // R/W: device-specific values start here |
| 136 | 136 | DEVINFO_STR_DEVICE_SPECIFIC = 0x38000, // R/W: device-specific values start here |
| 137 | | DEVINFO_STR_LAST = 0x3ffff, |
| 138 | | |
| 139 | | /* --- image device related --- */ |
| 140 | | /* --- the following bits of info are returned as integers --- */ |
| 141 | | DEVINFO_INT_IMAGE_FIRST = DEVINFO_INT_FIRST + 0x7000, |
| 142 | | DEVINFO_INT_IMAGE_TYPE, |
| 143 | | DEVINFO_INT_IMAGE_READABLE, |
| 144 | | DEVINFO_INT_IMAGE_WRITEABLE, |
| 145 | | DEVINFO_INT_IMAGE_CREATABLE, |
| 146 | | DEVINFO_INT_IMAGE_MUST_BE_LOADED, |
| 147 | | DEVINFO_INT_IMAGE_RESET_ON_LOAD, |
| 148 | | DEVINFO_INT_IMAGE_CREATE_OPTCOUNT, |
| 149 | | DEVINFO_INT_IMAGE_LAST = DEVINFO_INT_IMAGE_FIRST + 0x0fff, |
| 150 | | |
| 151 | | /* --- the following bits of info are returned as pointers --- */ |
| 152 | | DEVINFO_PTR_IMAGE_FIRST = DEVINFO_PTR_FIRST + 0x7000, |
| 153 | | DEVINFO_PTR_IMAGE_CREATE_OPTGUIDE, |
| 154 | | DEVINFO_PTR_IMAGE_CREATE_OPTSPEC, |
| 155 | | |
| 156 | | /* --- the following bits of info are returned as pointers to functions --- */ |
| 157 | | DEVINFO_FCT_IMAGE_FIRST = DEVINFO_FCT_FIRST + 0x7000, |
| 158 | | DEVINFO_FCT_IMAGE_LOAD, /* R/O: device_image_load_func */ |
| 159 | | DEVINFO_FCT_IMAGE_CREATE, /* R/O: device_image_create_func */ |
| 160 | | DEVINFO_FCT_IMAGE_UNLOAD, /* R/O: device_image_unload_func */ |
| 161 | | DEVINFO_FCT_IMAGE_DISPLAY, /* R/O: device_image_display_func */ |
| 162 | | DEVINFO_FCT_IMAGE_PARTIAL_HASH, /* R/O: device_image_partialhash_func */ |
| 163 | | DEVINFO_FCT_IMAGE_DISPLAY_INFO, /* R/O: device_image_display_info_func */ |
| 164 | | DEVINFO_FCT_IMAGE_GET_DEVICES, /* R/O: device_image_get_devices_func */ |
| 165 | | DEVINFO_FCT_IMAGE_SOFTLIST_LOAD, /* R/O: device_image_softlist_load_func */ |
| 166 | | DEVINFO_FCT_IMAGE_LAST = DEVINFO_FCT_FIRST + 0x0fff, |
| 167 | | |
| 168 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 169 | | DEVINFO_STR_IMAGE_FIRST = DEVINFO_STR_FIRST + 0x7000, |
| 170 | | DEVINFO_STR_IMAGE_FILE_EXTENSIONS, |
| 171 | | DEVINFO_STR_IMAGE_INSTANCE_NAME, |
| 172 | | DEVINFO_STR_IMAGE_BRIEF_INSTANCE_NAME, |
| 173 | | DEVINFO_STR_IMAGE_CREATE_OPTNAME, |
| 174 | | DEVINFO_STR_IMAGE_CREATE_OPTDESC = DEVINFO_STR_IMAGE_CREATE_OPTNAME + DEVINFO_IMAGE_CREATE_OPTMAX, |
| 175 | | DEVINFO_STR_IMAGE_CREATE_OPTEXTS = DEVINFO_STR_IMAGE_CREATE_OPTDESC + DEVINFO_IMAGE_CREATE_OPTMAX, |
| 176 | | DEVINFO_STR_IMAGE_INTERFACE, |
| 177 | | DEVINFO_STR_IMAGE_LAST = DEVINFO_STR_IMAGE_FIRST + 0x0fff |
| 137 | DEVINFO_STR_LAST = 0x3ffff |
| 178 | 138 | }; |
| 179 | 139 | |
| 180 | 140 | //************************************************************************** |
| r14705 | r14706 | |
| 215 | 175 | // reduced macros that are easier to use, and map to the above two macros |
| 216 | 176 | #define DECLARE_LEGACY_DEVICE(name, basename) _DECLARE_LEGACY_DEVICE(name, basename, basename##_device, legacy_device_base) |
| 217 | 177 | #define DECLARE_LEGACY_SOUND_DEVICE(name, basename) _DECLARE_LEGACY_DEVICE(name, basename, basename##_device, legacy_sound_device_base) |
| 218 | | #define DECLARE_LEGACY_IMAGE_DEVICE(name, basename) _DECLARE_LEGACY_DEVICE(name, basename, basename##_device, legacy_image_device_base) |
| 219 | 178 | |
| 220 | 179 | #define DEFINE_LEGACY_DEVICE(name, basename) _DEFINE_LEGACY_DEVICE(name, basename, basename##_device, legacy_device_base) |
| 221 | 180 | #define DEFINE_LEGACY_SOUND_DEVICE(name, basename) _DEFINE_LEGACY_DEVICE(name, basename, basename##_device, legacy_sound_device_base) |
| 222 | | #define DEFINE_LEGACY_IMAGE_DEVICE(name, basename) _DEFINE_LEGACY_DEVICE(name, basename, basename##_device, legacy_image_device_base) |
| 223 | 181 | |
| 224 | 182 | |
| 225 | 183 | // macros to wrap legacy device functions |
| r14705 | r14706 | |
| 457 | 415 | |
| 458 | 416 | |
| 459 | 417 | |
| 460 | | // ======================> legacy_image_device |
| 461 | | |
| 462 | | // legacy_image_device is a legacy_device_base with a image interface |
| 463 | | class legacy_image_device_base : public legacy_device_base, |
| 464 | | public device_image_interface |
| 465 | | { |
| 466 | | public: |
| 467 | | virtual bool call_load(); |
| 468 | | virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry); |
| 469 | | virtual bool call_create(int format_type, option_resolution *format_options); |
| 470 | | virtual void call_unload(); |
| 471 | | virtual void call_display(); |
| 472 | | virtual void call_display_info(); |
| 473 | | virtual device_image_partialhash_func get_partial_hash() const; |
| 474 | | virtual void call_get_devices(); |
| 475 | | |
| 476 | | virtual iodevice_t image_type() const { return static_cast<iodevice_t>(get_legacy_int(DEVINFO_INT_IMAGE_TYPE)); } |
| 477 | | |
| 478 | | virtual bool is_readable() const { return get_legacy_int(DEVINFO_INT_IMAGE_READABLE)!=0; } |
| 479 | | virtual bool is_writeable() const { return get_legacy_int(DEVINFO_INT_IMAGE_WRITEABLE)!=0; } |
| 480 | | virtual bool is_creatable() const { return get_legacy_int(DEVINFO_INT_IMAGE_CREATABLE)!=0; } |
| 481 | | virtual bool must_be_loaded() const { return get_legacy_int(DEVINFO_INT_IMAGE_MUST_BE_LOADED)!=0; } |
| 482 | | virtual bool is_reset_on_load() const { return get_legacy_int(DEVINFO_INT_IMAGE_RESET_ON_LOAD)!=0; } |
| 483 | | virtual const char *image_interface() const { return get_legacy_string(DEVINFO_STR_IMAGE_INTERFACE); } |
| 484 | | virtual const char *file_extensions() const { return get_legacy_string(DEVINFO_STR_IMAGE_FILE_EXTENSIONS); } |
| 485 | | virtual const option_guide *create_option_guide() const { return reinterpret_cast<const option_guide *>(get_legacy_ptr(DEVINFO_PTR_IMAGE_CREATE_OPTGUIDE)); } |
| 486 | | protected: |
| 487 | | // device overrides |
| 488 | | virtual void device_config_complete(); |
| 489 | | |
| 490 | | // construction/destruction |
| 491 | | legacy_image_device_base(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, UINT32 clock, device_get_config_func get_config); |
| 492 | | ~legacy_image_device_base(); |
| 493 | | }; |
| 494 | | |
| 495 | | |
| 496 | 418 | #endif /* __DEVLEGCY_H__ */ |