Previous 15994 Revisions Next

r2323 Tuesday 8th April, 2008 at 01:15:09 UTC by Nathan Woods
More device refactoring
[src/mess]device.c device.h image.c image.h

src/mess/image.c
r2322r2323
379379   extensions used by a device
380380-------------------------------------------------*/
381381
382static void get_device_file_extensions(const device_config *device, char *buffer, size_t buffer_len)
382static void get_device_file_extensions(const device_config *device,
383   char *buffer, size_t buffer_len)
383384{
384385   const char *file_extensions;
385386   char *s;
r2322r2323
401402
402403
403404/*-------------------------------------------------
405    get_device_instance_name - retrieves the device
406   instance name or brief instance name
407-------------------------------------------------*/
408
409static void get_device_instance_name(const machine_config *config, const device_config *device,
410   char *buffer, size_t buffer_len, iodevice_t type, UINT32 state, const char *(*get_dev_typename)(iodevice_t))
411{
412   const char *result;
413   const device_config *that_device;
414   int count, index;
415
416   /* retrieve info about the device instance */
417   result = device_get_info_string_offline(device, state);
418   if (result != NULL)
419   {
420      /* we got info directly */
421      snprintf(buffer, buffer_len, "%s", result);
422   }
423   else
424   {
425      /* not specified? default to device names based on the device type */
426      result = get_dev_typename(type);
427
428      /* are there multiple devices of the same type */
429      count = 0;
430      index = -1;
431      for (that_device = image_device_first(config); that_device != NULL; that_device = image_device_next(that_device))
432      {
433         if (device == that_device)
434            index = count;
435         if (device_get_info_int_offline(device, DEVINFO_INT_IMAGE_TYPE) == type)
436            count++;
437      }
438
439      /* need to number if there is more than one device */
440      if (that_device != NULL)
441         snprintf(buffer, buffer_len, "%s #%d", result, index + 1);
442      else
443         snprintf(buffer, buffer_len, "%s", result);
444   }
445}
446
447
448
449/*-------------------------------------------------
404450    image_device_getinfo - returns info on a device;
405451   can be called by front end code
406452-------------------------------------------------*/
407453
408454image_device_info image_device_getinfo(const machine_config *config, const device_config *device)
409455{
410   const struct IODevice *iodev;
411   const char *s;
412456   image_device_info info;
413457
414458   /* sanity checks */
r2322r2323
432476   /* retrieve file extensions */
433477   get_device_file_extensions(device, info.file_extensions, ARRAY_LENGTH(info.file_extensions));
434478
435   iodev = mess_device_from_core_device(device);
436   if (iodev != NULL)
437   {
438      /* retrieve instance name */
439      s = device_instancename(&iodev->devclass, iodev->index_in_device);
440      snprintf(info.instance_name, ARRAY_LENGTH(info.instance_name), "%s", s);
479   /* retrieve instance name */
480   get_device_instance_name(config, device, info.instance_name, ARRAY_LENGTH(info.instance_name),
481      info.type, DEVINFO_STR_IMAGE_INSTANCE_NAME, device_typename);
441482
442      /* retrieve brief instance name */
443      s = device_briefinstancename(&iodev->devclass, iodev->index_in_device);
444      snprintf(info.brief_instance_name, ARRAY_LENGTH(info.brief_instance_name), "%s", s);
445   }
483   /* retrieve brief instance name */
484   get_device_instance_name(config, device, info.brief_instance_name, ARRAY_LENGTH(info.brief_instance_name),
485      info.type, DEVINFO_STR_IMAGE_BRIEF_INSTANCE_NAME, device_brieftypename);
446486
447487   return info;
448488}
src/mess/image.h
r2322r2323
107107   /* --- the following bits of info are returned as NULL-terminated strings --- */
108108   DEVINFO_STR_IMAGE_FIRST = DEVINFO_STR_FIRST + 0x7000,
109109   DEVINFO_STR_IMAGE_FILE_EXTENSIONS,
110   DEVINFO_STR_IMAGE_INSTANCE_NAME,
111   DEVINFO_STR_IMAGE_BRIEF_INSTANCE_NAME,
110112   DEVINFO_STR_IMAGE_LAST = DEVINFO_STR_IMAGE_FIRST + 0x0fff
111113};
112114
src/mess/device.c
r2322r2323
130130
131131
132132
133static const char *internal_device_instancename(const mess_device_class *devclass, int id,
134   UINT32 base, const char *(*get_dev_typename)(iodevice_t))
135{
136   iodevice_t type;
137   int count;
138   const char *result;
139   char *s;
140
141   /* retrieve info about the device instance */
142   result = mess_device_get_info_string(devclass, base + id);
143   if (!result)
144   {
145      /* not specified? default to device names based on the device type */
146      type = (iodevice_t) (int) mess_device_get_info_int(devclass, MESS_DEVINFO_INT_TYPE);
147      count = (int) mess_device_get_info_int(devclass, MESS_DEVINFO_INT_COUNT);
148      result = get_dev_typename(type);
149
150      /* need to number if there is more than one device */
151      if (count > 1)
152      {
153         s = device_temp_str();
154         sprintf(s, "%s%d", result, id + 1);
155         result = s;
156      }
157   }
158   return result;
159}
160
161
162
163const char *device_instancename(const mess_device_class *devclass, int id)
164{
165   return internal_device_instancename(devclass, id, MESS_DEVINFO_STR_NAME, device_typename);
166}
167
168
169
170const char *device_briefinstancename(const mess_device_class *devclass, int id)
171{
172   return internal_device_instancename(devclass, id, MESS_DEVINFO_STR_SHORT_NAME, device_brieftypename);
173}
174
175
176
177133/*************************************
178134 *
179135 *   Device structure construction and destruction
r2322r2323
298254      case DEVINFO_STR_SOURCE_FILE:         info->s = __FILE__;                        break;
299255      case DEVINFO_STR_CREDITS:            info->s = "Copyright the MESS Team";         break;
300256      case DEVINFO_STR_IMAGE_FILE_EXTENSIONS:   info->s = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_FILE_EXTENSIONS); break;
257      case DEVINFO_STR_IMAGE_INSTANCE_NAME:   info->s = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_NAME); break;
258      case DEVINFO_STR_IMAGE_BRIEF_INSTANCE_NAME:   info->s = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_SHORT_NAME); break;
301259   }
302260}
303261
src/mess/device.h
r2322r2323
187187   return cpuintrf_temp_str();
188188}
189189
190const char *device_instancename(const mess_device_class *devclass, int id);
191const char *device_briefinstancename(const mess_device_class *devclass, int id);
192190
193191
194
195192/*************************************
196193 *
197194 *  Other

Previous 15994 Revisions Next


© 1998-2018 The MESS Team