Previous 15994 Revisions Next

r3039 Friday 15th August, 2008 at 11:33:03 UTC by Nathan Woods
Moved image creation format code to be based on the new device model
[docs]messnew.txt
[src/mess]device.c device.h image.c image.h
[src/mess/osd/windows]menu.c
[src/mess/tools/messtest]testmess.c

src/mess/tools/messtest/testmess.c
r3038r3039
169169static const messtest_command *current_command;
170170static int test_flags;
171171static int screenshot_num;
172static int format_index;
173172static UINT64 runtime_hash;
174173static void *wavptr;
175174static render_target *target;
r3038r3039
740739static void command_image_loadcreate(running_machine *machine)
741740{
742741   const device_config *image;
743   int i, format_index = 0;
744742   const char *filename;
745   const char *format;
743   const char *format_name;
746744   char buf[128];
747745   image_device_info info;
748746   const char *file_extensions;
749747   astring *filepath;
750748   int success;
751749   const game_driver *gamedrv;
750   const image_device_format *format = NULL;
752751
753752   /* look up the image slot */
754753   image = find_device_by_identity(machine, &current_command->u.image_args.device_ident);
r3038r3039
759758   file_extensions = info.file_extensions;
760759
761760   /* is an image format specified? */
762   format = current_command->u.image_args.format;
763   if (format != NULL)
761   format_name = current_command->u.image_args.format;
762   if (format_name != NULL)
764763   {
765      const struct IODevice *dev = mess_device_from_core_device(image);
766
767764      if (current_command->command_type != MESSTEST_COMMAND_IMAGE_CREATE)
768765      {
769766         state = STATE_ABORTED;
r3038r3039
771768         return;
772769      }
773770
774      if (!dev->createimage_options)
771      /* look up the format name */
772      format = image_device_get_named_creatable_format(image, format_name);
773      if (format == NULL)
775774      {
776775         state = STATE_ABORTED;
777         report_message(MSG_FAILURE, "Cannot specify format for device");
776         report_message(MSG_FAILURE, "Unknown device format '%s'", format_name);
778777         return;
779778      }
780
781      for (i = 0; dev->createimage_options[i].name; i++)
782      {
783         if (!strcmp(format, dev->createimage_options[i].name))
784            break;
785      }
786      if (!dev->createimage_options[i].name)
787      {
788         state = STATE_ABORTED;
789         report_message(MSG_FAILURE, "Unknown device '%s'", format);
790         return;
791      }
792      format_index = i;
793      file_extensions = dev->createimage_options[i].extensions;
794779   }
795780
796781   /* figure out the filename */
r3038r3039
813798      switch(current_command->command_type)
814799      {
815800         case MESSTEST_COMMAND_IMAGE_CREATE:
816            success = (image_create(image, astring_c(filepath), format_index, NULL) == INIT_PASS);
801            success = (image_create(image, astring_c(filepath), format, NULL) == INIT_PASS);
817802            break;
818803
819804         case MESSTEST_COMMAND_IMAGE_LOAD:
r3038r3039
13371322      return;
13381323
13391324   /* 'format' attribute */
1340   format_index = 0;
13411325   attr_node = xml_get_attribute(node, "format");
13421326   new_command.u.image_args.format = attr_node ? attr_node->value : NULL;
13431327
src/mess/image.c
r3038r3039
3838   image_device_info info;
3939
4040   /* creation info */
41   const option_guide *create_option_guide;
4142   image_device_format *formatlist;
4243
4344   /* callbacks */
r3038r3039
231232      slot->unload = (device_image_unload_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_UNLOAD);
232233      slot->verify = (device_image_verify_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_VERIFY);
233234
235      /* creation option guide */
236      slot->create_option_guide = (const option_guide *) device_get_info_ptr(slot->dev, DEVINFO_PTR_IMAGE_CREATE_OPTGUIDE);
237
234238      /* creation formats */
235239      format_count = device_get_info_int(slot->dev, DEVINFO_INT_IMAGE_CREATE_OPTCOUNT);
236240      formatptr = &slot->formatlist;
r3038r3039
241245         memset(format, 0, sizeof(*format));
242246
243247         /* populate it */
248         format->index      = i;
244249         format->name      = auto_strdup(device_get_info_string(slot->dev, DEVINFO_STR_IMAGE_CREATE_OPTNAME + i));
245250         format->description   = auto_strdup(device_get_info_string(slot->dev, DEVINFO_STR_IMAGE_CREATE_OPTDESC + i));
246251         format->extensions   = auto_strdup(device_get_info_string(slot->dev, DEVINFO_STR_IMAGE_CREATE_OPTEXTS + i));
r3038r3039
596601****************************************************************************/
597602
598603/*-------------------------------------------------
604    image_device_get_creation_option_guide - accesses
605   the creation option guide
606-------------------------------------------------*/
607
608const option_guide *image_device_get_creation_option_guide(const device_config *device)
609{
610   image_slot_data *slot = find_image_slot(device);
611   return slot->create_option_guide;
612}
613
614
615
616/*-------------------------------------------------
599617    image_device_get_creatable_formats - accesses
600618   the image formats available for image creation
601619-------------------------------------------------*/
r3038r3039
608626
609627
610628
629/*-------------------------------------------------
630    image_device_get_indexed_creatable_format -
631   accesses a specific image format available for
632   image creation by index
633-------------------------------------------------*/
634
635const image_device_format *image_device_get_indexed_creatable_format(const device_config *device, int index)
636{
637   const image_device_format *format = image_device_get_creatable_formats(device);
638   while(index-- && (format != NULL))
639      format = format->next;
640   return format;
641}
642
643
644
645/*-------------------------------------------------
646    image_device_get_named_creatable_format -
647   accesses a specific image format available for
648   image creation by name
649-------------------------------------------------*/
650
651const image_device_format *image_device_get_named_creatable_format(const device_config *device, const char *format_name)
652{
653   const image_device_format *format = image_device_get_creatable_formats(device);
654   while((format != NULL) && strcmp(format->name, format_name))
655      format = format->next;
656   return format;
657}
658
659
660
611661/****************************************************************************
612662    IMAGE LOADING
613663****************************************************************************/
r3038r3039
10521102    image_create - create a MESS image
10531103-------------------------------------------------*/
10541104
1055int image_create(const device_config *image, const char *path, int create_format, option_resolution *create_args)
1105int image_create(const device_config *image, const char *path, const image_device_format *create_format, option_resolution *create_args)
10561106{
1057   return image_load_internal(image, path, TRUE, create_format, create_args);
1107   int format_index = (create_format != NULL) ? create_format->index : -1;
1108   return image_load_internal(image, path, TRUE, format_index, create_args);
10581109}
10591110
10601111
src/mess/image.h
r3038r3039
9393struct _image_device_format
9494{
9595   image_device_format *next;
96   int index;
9697   const char *name;
9798   const char *description;
9899   const char *extensions;
r3038r3039
119120
120121   /* --- the following bits of info are returned as pointers --- */
121122   DEVINFO_PTR_IMAGE_FIRST = DEVINFO_PTR_FIRST + 0x7000,
123   DEVINFO_PTR_IMAGE_CREATE_OPTGUIDE,
122124   DEVINFO_PTR_IMAGE_CREATE_OPTSPEC,
123125
124126   /* --- the following bits of info are returned as pointers to functions --- */
r3038r3039
181183
182184/* ----- creation formats ----- */
183185
186/* accesses the creation option guide */
187const option_guide *image_device_get_creation_option_guide(const device_config *device);
188
189/* accesses the image formats available for image creation */
184190const image_device_format *image_device_get_creatable_formats(const device_config *device);
185191
192/* accesses a specific image format available for image creation by index */
193const image_device_format *image_device_get_indexed_creatable_format(const device_config *device, int index);
186194
195/* accesses a specific image format available for image creation by name */
196const image_device_format *image_device_get_named_creatable_format(const device_config *device, const char *format_name);
187197
198
199
188200/****************************************************************************
189201  Device loading and unloading functions
190202
r3038r3039
195207
196208/* can be called by front ends */
197209int image_load(const device_config *img, const char *name);
198int image_create(const device_config *img, const char *name, int create_format, option_resolution *create_args);
210int image_create(const device_config *img, const char *name, const image_device_format *create_format, option_resolution *create_args);
199211void image_unload(const device_config *img);
200212
201213/* used to retrieve error information during image loading */
src/mess/device.c
r3038r3039
3535{
3636   struct IODevice io_device;
3737   char string_buffer[1024];
38   create_image_options createimage_options[DEVINFO_CREATE_OPTMAX + 1];
3938};
4039
4140
r3038r3039
237236      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;
238237      case DEVINFO_INT_IMAGE_CREATE_OPTCOUNT:   info->i = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_CREATE_OPTCOUNT); break;
239238
240      /* --- the following bits of info are returned as pointers to data or functions --- */
239      /* --- the following bits of info are returned as pointers to data --- */
240      case DEVINFO_PTR_IMAGE_CREATE_OPTGUIDE:   info->p = mess_device_get_info_ptr(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE_OPTGUIDE); break;
241
242      /* --- the following bits of info are returned as pointers to functions --- */
241243      case DEVINFO_FCT_SET_INFO:            /* Nothing */                           break;
242244      case DEVINFO_FCT_START:               info->start = DEVICE_START_NAME(mess_device);   break;
243245      case DEVINFO_FCT_STOP:               info->stop = DEVICE_STOP_NAME(mess_device);      break;
r3038r3039
331333   char dynamic_tag[32];
332334   device_config *device;
333335   mess_device_config *mess_device;
334   int i, j, count;
336   int i, count;
335337   size_t string_buffer_pos = 0;
336   int createimage_optcount;
337338   device_getdispositions_func getdispositions;
338339   unsigned int readable, writeable, creatable;
339340
r3038r3039
385386      mess_device->io_device.start            = (device_start_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_START);
386387      mess_device->io_device.stop               = (device_stop_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_STOP);
387388
388      mess_device->io_device.createimage_optguide   = (const option_guide *) mess_device_get_info_ptr(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE_OPTGUIDE);
389
390      createimage_optcount = (int) mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_CREATE_OPTCOUNT);
391      if (createimage_optcount > 0)
392      {
393         if (createimage_optcount > DEVINFO_CREATE_OPTMAX)
394            fatalerror("MESS_DEVINFO_INT_CREATE_OPTCOUNT: Too many options");
395
396         /* set up each option in the list */
397         for (j = 0; j < createimage_optcount; j++)
398         {
399            info_string = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_CREATE_OPTNAME + j);
400            mess_device->createimage_options[j].name      = string_buffer_putstr(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos, info_string);
401
402            info_string = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_CREATE_OPTDESC + j);
403            mess_device->createimage_options[j].description   = string_buffer_putstr(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos, info_string);
404           
405            info_string = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_CREATE_OPTEXTS + j);
406            mess_device->createimage_options[j].extensions   = string_buffer_putstr(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos, info_string);
407           
408            mess_device->createimage_options[j].optspec      = mess_device_get_info_ptr(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE_OPTSPEC + j);
409         }
410
411         /* terminate the list */
412         memset(&mess_device->createimage_options[createimage_optcount], 0, sizeof(mess_device->createimage_options[createimage_optcount]));
413
414         /* assign the options */
415         mess_device->io_device.createimage_options = mess_device->createimage_options;
416      }
417
418389      /* determine the dispositions */
419390      getdispositions = (device_getdispositions_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_GET_DISPOSITIONS);
420391      if (getdispositions != NULL)
src/mess/device.h
r3038r3039
212212   /* image handling callbacks */
213213   device_start_func start;
214214   device_stop_func stop;
215
216   /* image creation options */
217   const option_guide *createimage_optguide;
218   const create_image_options *createimage_options;
219215};
220216
221217/* interoperability with MAME devices */
src/mess/osd/windows/menu.c
r3038r3039
578578   HWND wnd;
579579   int format_combo_val;
580580   const device_config *dev;
581   const struct IODevice *iodev;
582581   const option_guide *guide;
583582   const char *optspec;
584583   struct file_dialog_params *params;
r3038r3039
596595
597596   // compute our parameters
598597   dev = params->dev;
599   iodev = mess_device_from_core_device(dev);
600   guide = iodev->createimage_optguide;
601   optspec = iodev->createimage_options[format_combo_val].optspec;
598   guide = image_device_get_creation_option_guide(dev);
599   optspec = image_device_get_indexed_creatable_format(dev, format_combo_val)->optspec;
602600
603601   // set the default extension
604602   CommDlg_OpenSave_SetDefExt(GetParent(dlgwnd),
605      iodev->createimage_options[format_combo_val].extensions);
603      image_device_get_indexed_creatable_format(dev, format_combo_val)->extensions);
606604
607605   // enumerate through all of the child windows
608606   wnd = NULL;
r3038r3039
652650   option_resolution *resolution;
653651   struct storeval_optres_params *params;
654652   const device_config *dev;
655   const struct IODevice *iodev;
656653   char buf[16];
657654
658655   params = (struct storeval_optres_params *) storeval_param;
659656   dev = params->fdparams->dev;
660   iodev = mess_device_from_core_device(dev);
661657
662658   // create the resolution, if necessary
663659   resolution = *(params->fdparams->create_args);
664660   if (!resolution)
665661   {
666      resolution = option_resolution_create(iodev->createimage_optguide, iodev->createimage_options[*(params->fdparams->create_format)].optspec);
662      const option_guide *optguide = image_device_get_creation_option_guide(dev);
663      const image_device_format *format = image_device_get_indexed_creatable_format(dev, *(params->fdparams->create_format));
664
665      resolution = option_resolution_create(optguide, format->optspec);
667666      if (!resolution)
668667         return;
669668      *(params->fdparams->create_args) = resolution;
r3038r3039
683682{
684683   dialog_box *dialog;
685684   const option_guide *guide_entry;
686   int found, i, pos;
685   int found, pos;
687686   char buf[256];
688687   struct file_dialog_params *params;
689688   struct storeval_optres_params *storeval_params;
690689   static const struct dialog_layout filedialog_layout = { 44, 220 };
691   const struct IODevice *iodev = mess_device_from_core_device(dev);
690   const image_device_format *format;
692691
693692   // make the filter
694693   pos = 0;
695   for (i = 0; iodev->createimage_options[i].optspec; i++)
694   for (format = image_device_get_creatable_formats(dev); format != NULL; format = format->next)
696695   {
697      pos += add_filter_entry(filter + pos, filter_len - pos,
698         iodev->createimage_options[i].description,
699         iodev->createimage_options[i].extensions);
696      pos += add_filter_entry(filter + pos, filter_len - pos, format->description, format->extensions);
700697   }
701698
702699   // create the dialog
r3038r3039
717714      goto error;
718715
719716   // loop through the entries
720   for (guide_entry = iodev->createimage_optguide; guide_entry->option_type != OPTIONTYPE_END; guide_entry++)
717   for (guide_entry = image_device_get_creation_option_guide(dev); guide_entry->option_type != OPTIONTYPE_END; guide_entry++)
721718   {
722719      // make sure that this entry is present on at least one option specification
723720      found = FALSE;
724      for (i = 0; iodev->createimage_options[i].optspec; i++)
721      for (format = image_device_get_creatable_formats(dev); format != NULL; format = format->next)
725722      {
726         if (option_resolution_contains(iodev->createimage_options[i].optspec, guide_entry->parameter))
723         if (option_resolution_contains(format->optspec, guide_entry->parameter))
727724         {
728725            found = TRUE;
729726            break;
r3038r3039
883880   option_resolution *create_args = NULL;
884881   image_error_t err;
885882   image_device_info info;
886   const struct IODevice *iodev;
887883
888884   // sanity check
889885   assert(device != NULL);
r3038r3039
908904   initial_dir = image_working_directory(device);
909905
910906   // add custom dialog elements, if appropriate
911   iodev = mess_device_from_core_device(device);
912   if (is_save && (iodev != NULL)
913      && (iodev->createimage_optguide != NULL)
914      && (iodev->createimage_options[0].optspec != NULL))
907   if (is_save
908      && (image_device_get_creation_option_guide(device) != NULL)
909      && (image_device_get_creatable_formats(device) != NULL))
915910   {
916911      dialog = build_option_dialog(device, filter, sizeof(filter) / sizeof(filter[0]), &create_format, &create_args);
917912      if (!dialog)
r3038r3039
930925   {
931926      // mount the image
932927      if (is_save)
933         err = image_create(device, filename, create_format, create_args);
928         err = image_create(device, filename, image_device_get_indexed_creatable_format(device, create_format), create_args);
934929      else
935930         err = image_load(device, filename);
936931
docs/messnew.txt
r3038r3039
4646- Natural keyboard support is now implemented completely in the MESS core.
4747  [Nate Woods]
4848
49- Moved image creation format code to be based on the new device model.  [Nate
50  Woods]
4951
5052
53
51540.126
5255
5356New System Drivers Supported (in no particular order):

Previous 15994 Revisions Next


© 1998-2018 The MESS Team