Previous 15994 Revisions Next

r2324 Tuesday 8th April, 2008 at 01:44:50 UTC by Nathan Woods
More device refactoring
[src/mess]device.c device.h image.c image.h
[src/mess/osd/winui]softwarepicker.c

src/mess/image.c
r2323r2324
3434   /* variables that persist across image mounts */
3535   object_pool *mempool;
3636   const device_config *dev;
37   image_device_info info;
3738
3839   /* callbacks */
3940   device_image_load_func load;
4041   device_image_create_func create;
4142   device_image_unload_func unload;
43   device_image_verify_func verify;
4244
4345   /* error related info */
4446   image_error_t err;
r2323r2324
213215      slot->mempool = pool_alloc(memory_error);
214216
215217      /* setup the device */
216      machine->images_data->slots[indx].dev = dev;
218      slot->dev = dev;
219      slot->info = image_device_getinfo(machine->config, dev);
217220
218221      /* callbacks */
219222      slot->load = (device_image_load_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_LOAD);
220223      slot->create = (device_image_create_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_CREATE);
221224      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);
222226
223227      indx++;
224228   }
r2323r2324
469473   info.writeable = device_get_info_int_offline(device, DEVINFO_INT_IMAGE_WRITEABLE) ? 1 : 0;
470474   info.creatable = device_get_info_int_offline(device, DEVINFO_INT_IMAGE_CREATABLE) ? 1 : 0;
471475   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;
472478
473479   /* retrieve name */
474480   get_device_name(device, info.name, ARRAY_LENGTH(info.name));
r2323r2324
832838
833839static void determine_open_plan(image_slot_data *image, int is_create, UINT32 *open_plan)
834840{
835   unsigned int readable, writeable, creatable;
836841   int i = 0;
837   const struct IODevice *iodev;
838842
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
847843   /* emit flags */
848   if (!is_create && readable && writeable)
844   if (!is_create && image->info.readable && image->info.writeable)
849845      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)
851847      open_plan[i++] = OPEN_FLAG_WRITE;
852   if (!is_create && readable)
848   if (!is_create && image->info.readable)
853849      open_plan[i++] = OPEN_FLAG_READ;
854   if (writeable && creatable)
850   if (image->info.writeable && image->info.creatable)
855851      open_plan[i++] = OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE;
856852   open_plan[i] = 0;
857853}
r2323r2324
896892   UINT32 open_plan[4];
897893   int i;
898894   image_slot_data *slot = find_image_slot(image);
899   const struct IODevice *iodev = mess_device_from_core_device(image);
900895
901896   /* sanity checks */
902897   assert_always(image != NULL, "image_load(): image is NULL");
r2323r2324
914909      goto done;
915910
916911   /* 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)
918913      mame_schedule_hard_reset(machine);
919914
920915   /* determine open plan */
r2323r2324
953948   }
954949
955950   /* if applicable, call device verify */
956   if (iodev->imgverify && !image_has_been_created(image))
951   if ((slot->verify != NULL) && !image_has_been_created(image))
957952   {
958953      /* access the memory */
959954      buffer = image_ptr(image);
r2323r2324
964959      }
965960
966961      /* verify the file */
967      err = iodev->imgverify(buffer, core_fsize(slot->file));
962      err = (*slot->verify)(buffer, core_fsize(slot->file));
968963      if (err)
969964      {
970965         slot->err = IMAGE_ERROR_INVALIDIMAGE;
r2323r2324
12261221static int image_checkhash(image_slot_data *image)
12271222{
12281223   const game_driver *drv;
1229   const struct IODevice *dev;
12301224   char hash_string[HASH_BUF_SIZE];
1225   device_image_partialhash_func partialhash;
12311226   int rc;
12321227
12331228   /* this call should not be made when the image is not loaded */
r2323r2324
12361231   /* only calculate CRC if it hasn't been calculated, and the open_mode is read only */
12371232   if (!image->hash && !image->writeable && !image->created)
12381233   {
1239      /* initialize key variables */
1240      dev = mess_device_from_core_device(image->dev);
1241
12421234      /* do not cause a linear read of 600 megs please */
12431235      /* TODO: use SHA/MD5 in the CHD header as the hash */
1244      if (dev->type == IO_CDROM)
1236      if (image->info.type == IO_CDROM)
12451237         return FALSE;
12461238
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);
12481241
1242      run_hash(image->dev, partialhash, hash_string, HASH_CRC | HASH_MD5 | HASH_SHA1);
1243
12491244      image->hash = image_strdup(image->dev, hash_string);
12501245
12511246      /* now read the hash file */
src/mess/image.h
r2323r2324
2525typedef int (*device_image_load_func)(const device_config *image);
2626typedef int (*device_image_create_func)(const device_config *image, int format_type, option_resolution *format_options);
2727typedef void (*device_image_unload_func)(const device_config *image);
28typedef int (*device_image_verify_func)(const UINT8 *buf, size_t size);
2829typedef void (*device_display_func)(const device_config *image);
2930typedef void (*device_image_partialhash_func)(char *, const unsigned char *, unsigned long, unsigned int);
3031typedef const char *(*device_get_name_func)(const device_config *device, char *buffer, size_t buffer_length);
r2323r2324
7273   unsigned int writeable : 1;
7374   unsigned int creatable : 1;
7475   unsigned int must_be_loaded : 1;
76   unsigned int reset_on_load : 1;
77   unsigned int has_partial_hash : 1;
7578   char name[62];
7679   char file_extensions[32];
7780   char instance_name[32];
r2323r2324
9295   DEVINFO_INT_IMAGE_WRITEABLE,
9396   DEVINFO_INT_IMAGE_CREATABLE,
9497   DEVINFO_INT_IMAGE_MUST_BE_LOADED,
98   DEVINFO_INT_IMAGE_RESET_ON_LOAD,
9599   DEVINFO_INT_IMAGE_LAST = DEVINFO_INT_IMAGE_FIRST + 0x0fff,
96100
97101   /* --- the following bits of info are returned as pointers to functions --- */
r2323r2324
99103   DEVINFO_FCT_IMAGE_LOAD,                              /* R/O: device_image_load_func */
100104   DEVINFO_FCT_IMAGE_CREATE,                           /* R/O: device_image_create_func */
101105   DEVINFO_FCT_IMAGE_UNLOAD,                           /* R/O: device_image_unload_func */
106   DEVINFO_FCT_IMAGE_VERIFY,                           /* R/O: device_image_verify_func */
102107   DEVINFO_FCT_DISPLAY,                              /* R/O: device_display_func */
103108   DEVINFO_FCT_IMAGE_PARTIAL_HASH,                        /* R/O: device_image_partialhash_func */
104109   DEVINFO_FCT_GET_NAME,                              /* R/O: device_get_name_func */
src/mess/device.c
r2323r2324
234234      case DEVINFO_INT_IMAGE_CREATABLE:      info->i = mess_device->io_device.creatable;      break;
235235      case DEVINFO_INT_IMAGE_TYPE:         info->i = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_TYPE); break;
236236      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;
237238
238239      /* --- the following bits of info are returned as pointers to data or functions --- */
239240      case DEVINFO_FCT_SET_INFO:            /* Nothing */                           break;
r2323r2324
243244      case DEVINFO_FCT_IMAGE_LOAD:         info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_LOAD); break;
244245      case DEVINFO_FCT_IMAGE_CREATE:         info->f   = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE); break;
245246      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;
246248      case DEVINFO_FCT_DISPLAY:            info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_DISPLAY); break;
247249      case DEVINFO_FCT_IMAGE_PARTIAL_HASH:   info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_PARTIAL_HASH); break;
248250      case DEVINFO_FCT_GET_NAME:            info->f = (genf *) DEVICE_GET_NAME_NAME(mess_device);   break;
r2323r2324
370372
371373      mess_device->io_device.start            = (device_start_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_START);
372374      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);
375375
376376      mess_device->io_device.createimage_optguide   = (const struct OptionGuide *) mess_device_get_info_ptr(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE_OPTGUIDE);
377377
src/mess/device.h
r2323r2324
9292
9393struct IODevice;
9494
95typedef int (*device_image_verify_func)(const UINT8 *buf, size_t size);
9695typedef void (*device_getdispositions_func)(int id, unsigned int *readable, unsigned int *writeable, unsigned int *creatable);
9796typedef const char *(*device_getname_func)(const struct IODevice *dev, int id, char *buf, size_t bufsize);
9897
r2323r2324
227226   /* image handling callbacks */
228227   device_start_func start;
229228   device_stop_func stop;
230   int (*imgverify)(const UINT8 *buf, size_t size);
231   device_image_partialhash_func partialhash;
232229
233230   /* image creation options */
234231   const struct OptionGuide *createimage_optguide;
src/mess/osd/winui/softwarepicker.c
r2323r2324
455455
456456   // set up device and CRC, if specified
457457   pInfo->device = device;
458   if ((device != NULL) && (mess_device_from_core_device(device)->partialhash != NULL))
458   if ((device != NULL) && (image_device_getinfo(pPickerInfo->pConfig, device).has_partial_hash != 0))
459459      nCrc = 0;
460460   if (nCrc != 0)
461461      snprintf(pInfo->szHash, sizeof(pInfo->szHash) / sizeof(pInfo->szHash[0]), "c:%08x#", nCrc);

Previous 15994 Revisions Next


© 1998-2018 The MESS Team