Previous 15994 Revisions Next

r2319 Monday 7th April, 2008 at 13:15:45 UTC by Nathan Woods
1. Device refactoring

2. [Windows GUI] Cleanups
[src/mess]device.c device.h image.c
[src/mess/osd/windows]menu.c
[src/mess/osd/winui]messui.c

src/mess/image.c
r2318r2319
375375
376376
377377/*-------------------------------------------------
378    get_device_file_extensions - retrieves the file
379   extensions used by a device
380-------------------------------------------------*/
381
382static void get_device_file_extensions(const device_config *device, char *buffer, size_t buffer_len)
383{
384   const char *file_extensions;
385   char *s;
386
387   /* be pedantic - we need room for a string list */
388   assert(buffer_len > 0);
389   buffer_len--;
390
391   /* copy the string */
392   file_extensions = device_get_info_string_offline(device, DEVINFO_STR_IMAGE_FILE_EXTENSIONS);
393   snprintf(buffer, buffer_len, "%s", (file_extensions != NULL) ? file_extensions : "");
394
395   /* convert the comma delimited list to a NUL delimited list */
396   s = buffer;
397   while((s = strchr(s, ',')) != NULL)
398      *(s++) = '\0';
399}
400
401
402
403/*-------------------------------------------------
378404    image_device_getinfo - returns info on a device;
379405   can be called by front end code
380406-------------------------------------------------*/
r2318r2319
384410   const struct IODevice *iodev;
385411   const char *s;
386412   image_device_info info;
387   int i;
388413   
389414   memset(&info, 0, sizeof(info));
390415
r2318r2319
400425   /* retrieve name */
401426   get_device_name(device, info.name, ARRAY_LENGTH(info.name));
402427
428   /* retrieve file extensions */
429   get_device_file_extensions(device, info.file_extensions, ARRAY_LENGTH(info.file_extensions));
430
403431   iodev = mess_device_from_core_device(device);
404432   if (iodev != NULL)
405433   {
406      /* retrieve file extensions */
407      for(i = 0; iodev->file_extensions[i] != '\0'; i += strlen(&iodev->file_extensions[i]) + 1)
408         ;
409      memcpy(info.file_extensions, iodev->file_extensions, i * sizeof(info.file_extensions[0]));
410
411434      /* retrieve instance name */
412435      s = device_instancename(&iodev->devclass, iodev->index_in_device);
413436      snprintf(info.instance_name, ARRAY_LENGTH(info.instance_name), "%s", s);
r2318r2319
431454int image_device_uses_file_extension(const device_config *device, const char *file_extension)
432455{
433456   int result = FALSE;
434   const struct IODevice *iodev;
457   const char *s;
458   char file_extension_list[256];
435459   
436460   /* skip initial period, if present */
437461   if (file_extension[0] == '.')
438462      file_extension++;
439463
440   iodev = mess_device_from_core_device(device);
441   if (iodev != NULL)
464   /* retrieve file extension list */
465   get_device_file_extensions(device, file_extension_list, ARRAY_LENGTH(file_extension_list));
466
467   /* find the extensions */
468   s = file_extension_list;
469   while(!result && (*s != '\0'))
442470   {
443      const char *s = iodev->file_extensions;
444      while(!result && (*s != '\0'))
471      if (!mame_stricmp(s, file_extension))
445472      {
446         if (!mame_stricmp(s, file_extension))
447         {
448            result = TRUE;
449            break;
450         }
451         s += strlen(s) + 1;
473         result = TRUE;
474         break;
452475      }
476      s += strlen(s) + 1;
453477   }
454478   return result;
455479}
src/mess/device.c
r2318r2319
276276      case DEVINFO_INT_IMAGE_READABLE:      info->i = mess_device->io_device.readable;      break;
277277      case DEVINFO_INT_IMAGE_WRITEABLE:      info->i = mess_device->io_device.writeable;      break;
278278      case DEVINFO_INT_IMAGE_CREATABLE:      info->i = mess_device->io_device.creatable;      break;
279      case DEVINFO_INT_IMAGE_TYPE:         info->i = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_TYPE); break;
279280      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;
280281
281282      /* --- the following bits of info are returned as pointers to data or functions --- */
r2318r2319
296297      case DEVINFO_STR_VERSION:            info->s = "1.0";                        break;
297298      case DEVINFO_STR_SOURCE_FILE:         info->s = __FILE__;                        break;
298299      case DEVINFO_STR_CREDITS:            info->s = "Copyright the MESS Team";         break;
300      case DEVINFO_STR_IMAGE_FILE_EXTENSIONS:   info->s = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_FILE_EXTENSIONS); break;
299301   }
300302}
301303
r2318r2319
357359   char dynamic_tag[32];
358360   device_config *device;
359361   mess_device_config *mess_device;
360   const char *file_extensions;
361362   int i, j, count;
362363   size_t string_buffer_pos = 0;
363364   int createimage_optcount;
r2318r2319
398399      info_string = mess_tag;
399400      mess_tag = string_buffer_putstr(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos, info_string);
400401
401      /* convert file extensions from comma delimited to null delimited */
402      file_extensions = mess_device_get_info_string(&mess_devclass, MESS_DEVINFO_STR_FILE_EXTENSIONS);
403      if (file_extensions != NULL)
404      {
405         const char *file_extensions_copy = &mess_device->string_buffer[string_buffer_pos];
406
407         /* copy the file extensions over to the buffer */
408         for (j = 0; file_extensions[j] != '\0'; j++)
409         {
410            string_buffer_putc(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos,
411               (file_extensions[j] != ',') ? file_extensions[j] : '\0');
412         }
413         string_buffer_putc(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos, '\0');
414         string_buffer_putc(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos, '\0');
415
416         file_extensions = file_extensions_copy;
417      }
418
419402      /* populate the legacy MESS device */
420403      mess_device->io_device.tag               = mess_tag;
421404      mess_device->io_device.devconfig         = device;
r2318r2319
423406      mess_device->io_device.type               = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_TYPE);
424407      mess_device->io_device.position            = *position;
425408      mess_device->io_device.index_in_device      = i;
426      mess_device->io_device.file_extensions      = file_extensions;
427409
428410      mess_device->io_device.reset_on_load      = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_RESET_ON_LOAD) ? 1 : 0;
429411      mess_device->io_device.load_at_init         = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_LOAD_AT_INIT) ? 1 : 0;
src/mess/device.h
r2318r2319
216216   iodevice_t type;
217217   int position;
218218   int index_in_device;
219   const char *file_extensions;
220219
221220   /* open dispositions */
222221   unsigned int readable : 1;
src/mess/osd/windows/menu.c
r2318r2319
13531353   // then set up the actual devices
13541354   for (img = image_device_first(machine->config); img != NULL; img = image_device_next(img))
13551355   {
1356      const struct IODevice *dev = mess_device_from_core_device(img);
1356      image_device_info info = image_device_getinfo(img);
13571357
13581358      new_item = ID_DEVICE_0 + (image_absolute_index(img) * DEVOPTION_MAX);
13591359      flags_for_exists = MF_STRING;
r2318r2319
13681368      sub_menu = CreateMenu();
13691369      append_menu_uistring(sub_menu, MF_STRING,      new_item + DEVOPTION_OPEN,      UI_mount);
13701370
1371      if (dev->creatable)
1371      if (info.creatable)
13721372         append_menu_uistring(sub_menu, MF_STRING,   new_item + DEVOPTION_CREATE,   UI_create);
13731373
13741374      append_menu_uistring(sub_menu, flags_for_exists,   new_item + DEVOPTION_CLOSE,   UI_unmount);
13751375
13761376#if HAS_WAVE
1377      if ((dev->type == IO_CASSETTE) && !strcmp(dev->file_extensions, "wav"))
1377      if ((info.type == IO_CASSETTE) && !strcmp(info.file_extensions, "wav"))
13781378      {
13791379         cassette_state state;
13801380         state = image_exists(img) ? (cassette_get_state(img) & CASSETTE_MASK_UISTATE) : CASSETTE_STOPPED;
src/mess/osd/winui/messui.c
r2318r2319
3636
3737#define LOG_SOFTWARE   0
3838
39#ifdef UNUSED_FUNCTION
40static int requested_device_type(char *tchar);
41#endif
42
4339static void SoftwarePicker_OnHeaderContextMenu(POINT pt, int nColumn);
4440
4541static LPCSTR SoftwareTabView_GetTabShortName(int tab);
r2318r2319
8682
8783struct deviceentry
8884{
89   int dev_type;
85   iodevice_t dev_type;
9086   const char *icon_name;
9187   const char *dlgname;
9288};
r2318r2319
172168
173169
174170
175static void AssertValidDevice(int d)
171static const struct deviceentry *lookupdevice(iodevice_t d)
176172{
177   assert((sizeof(s_devices) / sizeof(s_devices[0])) == IO_COUNT);
178   assert(((d >= 0) && (d < IO_COUNT)) || (d == IO_UNKNOWN) || (d == IO_BAD) || (d == IO_ZIP));
179}
180
181
182
183static const struct deviceentry *lookupdevice(int d)
184{
185   assert(d >= 0);
186   assert(d < IO_COUNT);
187   AssertValidDevice(d);
188   return &s_devices[d];
189}
190
191
192
193// ------------------------------------------------------------------------
194#ifdef UNUSED_FUNCTION
195static int requested_device_type(char *tchar)
196{
197   int device = -1;
198173   int i;
199
200    logerror("Requested device is %s\n", tchar);
201
202   if (*tchar == '-')
174   for (i = 0; i < ARRAY_LENGTH(s_devices); i++)
203175   {
204      tchar++;
205
206      for (i = 1; i < IO_COUNT; i++)
207      {
208         if (!mame_stricmp(tchar, device_typename(i)) || !mame_stricmp(tchar, device_brieftypename(i)))
209         {
210            device = i;
211            break;
212         }
213      }
176      if (s_devices[i].dev_type == d)
177         return &s_devices[i];
214178   }
215
216   return device;
179   return NULL;
217180}
218#endif
219181
220182
183
221184// ------------------------------------------------------------------------
222185// UI
223186// ------------------------------------------------------------------------
r2318r2319
895858
896859static int SoftwarePicker_GetItemImage(HWND hwndPicker, int nItem)
897860{
898   int nType;
861   iodevice_t nType;
899862   int nIcon;
900863   int drvindex;
901864   const char *icon_name;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team