src/mess/image.c
| r2323 | r2324 | |
| 34 | 34 | /* variables that persist across image mounts */ |
| 35 | 35 | object_pool *mempool; |
| 36 | 36 | const device_config *dev; |
| 37 | image_device_info info; |
| 37 | 38 | |
| 38 | 39 | /* callbacks */ |
| 39 | 40 | device_image_load_func load; |
| 40 | 41 | device_image_create_func create; |
| 41 | 42 | device_image_unload_func unload; |
| 43 | device_image_verify_func verify; |
| 42 | 44 | |
| 43 | 45 | /* error related info */ |
| 44 | 46 | image_error_t err; |
| r2323 | r2324 | |
| 213 | 215 | slot->mempool = pool_alloc(memory_error); |
| 214 | 216 | |
| 215 | 217 | /* setup the device */ |
| 216 | | machine->images_data->slots[indx].dev = dev; |
| 218 | slot->dev = dev; |
| 219 | slot->info = image_device_getinfo(machine->config, dev); |
| 217 | 220 | |
| 218 | 221 | /* callbacks */ |
| 219 | 222 | slot->load = (device_image_load_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_LOAD); |
| 220 | 223 | slot->create = (device_image_create_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_CREATE); |
| 221 | 224 | slot->unload = (device_image_unload_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_UNLOAD); |
| 225 | slot->verify = (device_image_verify_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_VERIFY); |
| 222 | 226 | |
| 223 | 227 | indx++; |
| 224 | 228 | } |
| r2323 | r2324 | |
| 469 | 473 | info.writeable = device_get_info_int_offline(device, DEVINFO_INT_IMAGE_WRITEABLE) ? 1 : 0; |
| 470 | 474 | info.creatable = device_get_info_int_offline(device, DEVINFO_INT_IMAGE_CREATABLE) ? 1 : 0; |
| 471 | 475 | info.must_be_loaded = device_get_info_int_offline(device, DEVINFO_INT_IMAGE_MUST_BE_LOADED) ? 1 : 0; |
| 476 | info.reset_on_load = device_get_info_int_offline(device, DEVINFO_INT_IMAGE_RESET_ON_LOAD) ? 1 : 0; |
| 477 | info.has_partial_hash = device_get_info_fct_offline(device, DEVINFO_FCT_IMAGE_PARTIAL_HASH) ? 1 : 0; |
| 472 | 478 | |
| 473 | 479 | /* retrieve name */ |
| 474 | 480 | get_device_name(device, info.name, ARRAY_LENGTH(info.name)); |
| r2323 | r2324 | |
| 832 | 838 | |
| 833 | 839 | static void determine_open_plan(image_slot_data *image, int is_create, UINT32 *open_plan) |
| 834 | 840 | { |
| 835 | | unsigned int readable, writeable, creatable; |
| 836 | 841 | int i = 0; |
| 837 | | const struct IODevice *iodev; |
| 838 | 842 | |
| 839 | | /* access legacy MESS device */ |
| 840 | | iodev = mess_device_from_core_device(image->dev); |
| 841 | | |
| 842 | | /* determine disposition */ |
| 843 | | readable = iodev->readable; |
| 844 | | writeable = iodev->writeable; |
| 845 | | creatable = iodev->creatable; |
| 846 | | |
| 847 | 843 | /* emit flags */ |
| 848 | | if (!is_create && readable && writeable) |
| 844 | if (!is_create && image->info.readable && image->info.writeable) |
| 849 | 845 | open_plan[i++] = OPEN_FLAG_READ | OPEN_FLAG_WRITE; |
| 850 | | if (!is_create && !readable && writeable) |
| 846 | if (!is_create && !image->info.readable && image->info.writeable) |
| 851 | 847 | open_plan[i++] = OPEN_FLAG_WRITE; |
| 852 | | if (!is_create && readable) |
| 848 | if (!is_create && image->info.readable) |
| 853 | 849 | open_plan[i++] = OPEN_FLAG_READ; |
| 854 | | if (writeable && creatable) |
| 850 | if (image->info.writeable && image->info.creatable) |
| 855 | 851 | open_plan[i++] = OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE; |
| 856 | 852 | open_plan[i] = 0; |
| 857 | 853 | } |
| r2323 | r2324 | |
| 896 | 892 | UINT32 open_plan[4]; |
| 897 | 893 | int i; |
| 898 | 894 | image_slot_data *slot = find_image_slot(image); |
| 899 | | const struct IODevice *iodev = mess_device_from_core_device(image); |
| 900 | 895 | |
| 901 | 896 | /* sanity checks */ |
| 902 | 897 | assert_always(image != NULL, "image_load(): image is NULL"); |
| r2323 | r2324 | |
| 914 | 909 | goto done; |
| 915 | 910 | |
| 916 | 911 | /* do we need to reset the CPU? */ |
| 917 | | if ((attotime_compare(timer_get_time(), attotime_zero) > 0) && iodev->reset_on_load) |
| 912 | if ((attotime_compare(timer_get_time(), attotime_zero) > 0) && slot->info.reset_on_load) |
| 918 | 913 | mame_schedule_hard_reset(machine); |
| 919 | 914 | |
| 920 | 915 | /* determine open plan */ |
| r2323 | r2324 | |
| 953 | 948 | } |
| 954 | 949 | |
| 955 | 950 | /* if applicable, call device verify */ |
| 956 | | if (iodev->imgverify && !image_has_been_created(image)) |
| 951 | if ((slot->verify != NULL) && !image_has_been_created(image)) |
| 957 | 952 | { |
| 958 | 953 | /* access the memory */ |
| 959 | 954 | buffer = image_ptr(image); |
| r2323 | r2324 | |
| 964 | 959 | } |
| 965 | 960 | |
| 966 | 961 | /* verify the file */ |
| 967 | | err = iodev->imgverify(buffer, core_fsize(slot->file)); |
| 962 | err = (*slot->verify)(buffer, core_fsize(slot->file)); |
| 968 | 963 | if (err) |
| 969 | 964 | { |
| 970 | 965 | slot->err = IMAGE_ERROR_INVALIDIMAGE; |
| r2323 | r2324 | |
| 1226 | 1221 | static int image_checkhash(image_slot_data *image) |
| 1227 | 1222 | { |
| 1228 | 1223 | const game_driver *drv; |
| 1229 | | const struct IODevice *dev; |
| 1230 | 1224 | char hash_string[HASH_BUF_SIZE]; |
| 1225 | device_image_partialhash_func partialhash; |
| 1231 | 1226 | int rc; |
| 1232 | 1227 | |
| 1233 | 1228 | /* this call should not be made when the image is not loaded */ |
| r2323 | r2324 | |
| 1236 | 1231 | /* only calculate CRC if it hasn't been calculated, and the open_mode is read only */ |
| 1237 | 1232 | if (!image->hash && !image->writeable && !image->created) |
| 1238 | 1233 | { |
| 1239 | | /* initialize key variables */ |
| 1240 | | dev = mess_device_from_core_device(image->dev); |
| 1241 | | |
| 1242 | 1234 | /* do not cause a linear read of 600 megs please */ |
| 1243 | 1235 | /* TODO: use SHA/MD5 in the CHD header as the hash */ |
| 1244 | | if (dev->type == IO_CDROM) |
| 1236 | if (image->info.type == IO_CDROM) |
| 1245 | 1237 | return FALSE; |
| 1246 | 1238 | |
| 1247 | | run_hash(image->dev, dev->partialhash, hash_string, HASH_CRC | HASH_MD5 | HASH_SHA1); |
| 1239 | /* retrieve the partial hash func */ |
| 1240 | partialhash = (device_image_partialhash_func) device_get_info_fct_offline(image->dev, DEVINFO_FCT_IMAGE_PARTIAL_HASH); |
| 1248 | 1241 | |
| 1242 | run_hash(image->dev, partialhash, hash_string, HASH_CRC | HASH_MD5 | HASH_SHA1); |
| 1243 | |
| 1249 | 1244 | image->hash = image_strdup(image->dev, hash_string); |
| 1250 | 1245 | |
| 1251 | 1246 | /* now read the hash file */ |
src/mess/image.h
| r2323 | r2324 | |
| 25 | 25 | typedef int (*device_image_load_func)(const device_config *image); |
| 26 | 26 | typedef int (*device_image_create_func)(const device_config *image, int format_type, option_resolution *format_options); |
| 27 | 27 | typedef void (*device_image_unload_func)(const device_config *image); |
| 28 | typedef int (*device_image_verify_func)(const UINT8 *buf, size_t size); |
| 28 | 29 | typedef void (*device_display_func)(const device_config *image); |
| 29 | 30 | typedef void (*device_image_partialhash_func)(char *, const unsigned char *, unsigned long, unsigned int); |
| 30 | 31 | typedef const char *(*device_get_name_func)(const device_config *device, char *buffer, size_t buffer_length); |
| r2323 | r2324 | |
| 72 | 73 | unsigned int writeable : 1; |
| 73 | 74 | unsigned int creatable : 1; |
| 74 | 75 | unsigned int must_be_loaded : 1; |
| 76 | unsigned int reset_on_load : 1; |
| 77 | unsigned int has_partial_hash : 1; |
| 75 | 78 | char name[62]; |
| 76 | 79 | char file_extensions[32]; |
| 77 | 80 | char instance_name[32]; |
| r2323 | r2324 | |
| 92 | 95 | DEVINFO_INT_IMAGE_WRITEABLE, |
| 93 | 96 | DEVINFO_INT_IMAGE_CREATABLE, |
| 94 | 97 | DEVINFO_INT_IMAGE_MUST_BE_LOADED, |
| 98 | DEVINFO_INT_IMAGE_RESET_ON_LOAD, |
| 95 | 99 | DEVINFO_INT_IMAGE_LAST = DEVINFO_INT_IMAGE_FIRST + 0x0fff, |
| 96 | 100 | |
| 97 | 101 | /* --- the following bits of info are returned as pointers to functions --- */ |
| r2323 | r2324 | |
| 99 | 103 | DEVINFO_FCT_IMAGE_LOAD, /* R/O: device_image_load_func */ |
| 100 | 104 | DEVINFO_FCT_IMAGE_CREATE, /* R/O: device_image_create_func */ |
| 101 | 105 | DEVINFO_FCT_IMAGE_UNLOAD, /* R/O: device_image_unload_func */ |
| 106 | DEVINFO_FCT_IMAGE_VERIFY, /* R/O: device_image_verify_func */ |
| 102 | 107 | DEVINFO_FCT_DISPLAY, /* R/O: device_display_func */ |
| 103 | 108 | DEVINFO_FCT_IMAGE_PARTIAL_HASH, /* R/O: device_image_partialhash_func */ |
| 104 | 109 | DEVINFO_FCT_GET_NAME, /* R/O: device_get_name_func */ |
src/mess/device.c
| r2323 | r2324 | |
| 234 | 234 | case DEVINFO_INT_IMAGE_CREATABLE: info->i = mess_device->io_device.creatable; break; |
| 235 | 235 | case DEVINFO_INT_IMAGE_TYPE: info->i = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_TYPE); break; |
| 236 | 236 | case DEVINFO_INT_IMAGE_MUST_BE_LOADED: info->i = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_MUST_BE_LOADED); break; |
| 237 | case DEVINFO_INT_IMAGE_RESET_ON_LOAD: info->i = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_RESET_ON_LOAD); break; |
| 237 | 238 | |
| 238 | 239 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 239 | 240 | case DEVINFO_FCT_SET_INFO: /* Nothing */ break; |
| r2323 | r2324 | |
| 243 | 244 | case DEVINFO_FCT_IMAGE_LOAD: info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_LOAD); break; |
| 244 | 245 | case DEVINFO_FCT_IMAGE_CREATE: info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE); break; |
| 245 | 246 | case DEVINFO_FCT_IMAGE_UNLOAD: info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_UNLOAD); break; |
| 247 | case DEVINFO_FCT_IMAGE_VERIFY: info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_VERIFY); break; |
| 246 | 248 | case DEVINFO_FCT_DISPLAY: info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_DISPLAY); break; |
| 247 | 249 | case DEVINFO_FCT_IMAGE_PARTIAL_HASH: info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_PARTIAL_HASH); break; |
| 248 | 250 | case DEVINFO_FCT_GET_NAME: info->f = (genf *) DEVICE_GET_NAME_NAME(mess_device); break; |
| r2323 | r2324 | |
| 370 | 372 | |
| 371 | 373 | mess_device->io_device.start = (device_start_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_START); |
| 372 | 374 | mess_device->io_device.stop = (device_stop_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_STOP); |
| 373 | | mess_device->io_device.imgverify = (device_image_verify_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_VERIFY); |
| 374 | | mess_device->io_device.partialhash = (device_image_partialhash_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_PARTIAL_HASH); |
| 375 | 375 | |
| 376 | 376 | mess_device->io_device.createimage_optguide = (const struct OptionGuide *) mess_device_get_info_ptr(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE_OPTGUIDE); |
| 377 | 377 | |