Previous 15994 Revisions Next

r2114 Wednesday 26th March, 2008 at 01:07:05 UTC by Nathan Woods
MESS devices (of type IODevice) are now "piggy-backed" on MAME's device system.
Removed machine->devices[]. Still much integration work still to be done.
[src/emu]info.c mame.h
[src/mess]climess.c device.c device.h infomess.c mess.c
[src/mess/osd/winui]devview.c messui.c msuiutil.c softwarepicker.c

src/emu/info.c
r2113r2114
868868   /* start tracking resources and allocate the machine and input configs */
869869   begin_resource_tracking();
870870   config = machine_config_alloc(game->machine_config);
871#ifdef MESS
872   mess_devices_setup(config, game);
873#endif /* MESS */
871874   input = input_port_allocate(game->ipt, NULL);
872875
873876   /* print the header and the game name */
src/emu/mame.h
r2113r2114
198198   /* debugger-related information */
199199   int                  debug_mode;         /* was debug mode enabled? */
200200
201   /* MESS-specific information */
202#ifdef MESS
203   struct IODevice *      devices;
204#endif /* MESS */
205
206201   /* internal core information */
207202   mame_private *         mame_data;         /* internal data from mame.c */
208203   palette_private *      palette_data;      /* internal data from palette.c */
src/mess/climess.c
r2113r2114
4343
4444int info_listdevices(core_options *opts, const char *gamename)
4545{
46   int i, dev, id;
47   const struct IODevice *devices;
46   int i, id;
47   machine_config *config;
48   const device_config *dev;
49   const struct IODevice *iodev;
4850   const char *src;
4951   const char *driver_name;
5052   const char *name;
5153   const char *shortname;
5254   char paren_shortname[16];
5355
56   /* since we expand the machine driver, we need to set things up */
57   init_resource_tracking();
58
5459   i = 0;
5560
5661   mame_printf_info(" SYSTEM      DEVICE NAME (brief)   IMAGE FILE EXTENSIONS SUPPORTED    \n");
r2113r2114
6065   {
6166      if (!core_strwildcmp(gamename, drivers[i]->name))
6267      {
63         devices = devices_allocate(drivers[i]);
68         /* allocate the machine config */
69         config = machine_config_alloc_with_mess_devices(drivers[i]);
6470
6571         driver_name = drivers[i]->name;
6672
67         for (dev = 0; devices[dev].type < IO_COUNT; dev++)
73         for (dev = device_list_first(config->devicelist, MESS_DEVICE); dev != NULL; dev = device_list_next(dev, MESS_DEVICE))
6874         {
69            src = devices[dev].file_extensions;
75            iodev = mess_device_from_core_device(dev);
7076
71            for (id = 0; id < devices[dev].count; id++)
77            src = iodev->file_extensions;
78
79            for (id = 0; id < iodev->count; id++)
7280            {
73               name = device_instancename(&devices[dev].devclass, id);
74               shortname = device_briefinstancename(&devices[dev].devclass, id);
81               name = device_instancename(&iodev->devclass, id);
82               shortname = device_briefinstancename(&iodev->devclass, id);
7583
7684               sprintf(paren_shortname, "(%s)", shortname);
7785
r2113r2114
8997               mame_printf_info("\n");
9098            }
9199         }
92         devices_free(devices);
100         machine_config_free(config);
93101      }
94102      i++;
95103   }
104
105   /* clean up our tracked resources */
106   exit_resource_tracking();
107
96108   return 0;
97109}
98110
src/mess/mess.c
r2113r2114
102102
103103
104104/*-------------------------------------------------
105    devices_exit - tear down devices for a specific
106   running_machine
107-------------------------------------------------*/
108
109static void devices_exit(running_machine *machine)
110{
111   devices_free(machine->devices);
112   machine->devices = NULL;
113}
114
115
116
117/*-------------------------------------------------
118105    devices_init - initialize devices for a specific
119106   running_machine
120107-------------------------------------------------*/
r2113r2114
131118   inputx_init(machine);
132119
133120   /* allocate the IODevice struct */
134   machine->devices = (struct IODevice *) devices_allocate(machine->gamedrv);
135   if (!machine->devices)
136      fatalerror_exitcode(MAMERR_DEVICE, "devices_allocate() failed");
137   add_exit_callback(machine, devices_exit);
121   mess_devices_setup((machine_config *) machine->config, machine->gamedrv);
138122
139123   /* initialize RAM code */
140124   ram_init(machine->gamedrv);
src/mess/infomess.c
r2113r2114
2828
2929void print_game_device(FILE *out, const game_driver *game, const machine_config *config)
3030{
31   const struct IODevice* devices;
31   const device_config *dev;
32   const struct IODevice *iodev;
3233   const char *name;
3334   const char *shortname;
34   int id, devindex;
35   int id;
3536
36   devices = devices_allocate(game);
37   if (devices)
37   for (dev = device_list_first(config->devicelist, MESS_DEVICE); dev != NULL; dev = device_list_next(dev, MESS_DEVICE))
3838   {
39      for (devindex = 0; devices[devindex].type < IO_COUNT; devindex++)
40      {
41         /* print out device type */
42         fprintf(out, "\t\t<device type=\"%s\"", xml_normalize_string(device_typename(devices[devindex].type)));
39      iodev = mess_device_from_core_device(dev);
4340
44         /* does this device have a tag? */
45         if (devices[devindex].tag)
46            fprintf(out, " tag=\"%s\"", xml_normalize_string(devices[devindex].tag));
41      /* print out device type */
42      fprintf(out, "\t\t<device type=\"%s\"", xml_normalize_string(device_typename(iodev->type)));
4743
48         /* is this device mandatory? */
49         if (devices[devindex].must_be_loaded)
50            fprintf(out, " mandatory=\"1\"");
44      /* does this device have a tag? */
45      if (iodev->tag)
46         fprintf(out, " tag=\"%s\"", xml_normalize_string(iodev->tag));
5147
52         /* close the XML tag */
53         fprintf(out, ">\n");
48      /* is this device mandatory? */
49      if (iodev->must_be_loaded)
50         fprintf(out, " mandatory=\"1\"");
5451
55         for (id = 0; id < devices[devindex].count; id++)
56         {
57            name = device_instancename(&devices[devindex].devclass, id);
58            shortname = device_briefinstancename(&devices[devindex].devclass, id);
52      /* close the XML tag */
53      fprintf(out, ">\n");
5954
60            fprintf(out, "\t\t\t<instance");
61            fprintf(out, " name=\"%s\"", xml_normalize_string(name));
62            fprintf(out, " briefname=\"%s\"", xml_normalize_string(shortname));
63            fprintf(out, "/>\n");
64         }
55      for (id = 0; id < iodev->count; id++)
56      {
57         name = device_instancename(&iodev->devclass, id);
58         shortname = device_briefinstancename(&iodev->devclass, id);
6559
66         if (devices[devindex].file_extensions)
60         fprintf(out, "\t\t\t<instance");
61         fprintf(out, " name=\"%s\"", xml_normalize_string(name));
62         fprintf(out, " briefname=\"%s\"", xml_normalize_string(shortname));
63         fprintf(out, "/>\n");
64      }
65
66      if (iodev->file_extensions)
67      {
68         const char* ext = iodev->file_extensions;
69         while (*ext)
6770         {
68            const char* ext = devices[devindex].file_extensions;
69            while (*ext)
70            {
71               fprintf(out, "\t\t\t<extension");
72               fprintf(out, " name=\"%s\"", xml_normalize_string(ext));
73               fprintf(out, "/>\n");
74               ext += strlen(ext) + 1;
75            }
71            fprintf(out, "\t\t\t<extension");
72            fprintf(out, " name=\"%s\"", xml_normalize_string(ext));
73            fprintf(out, "/>\n");
74            ext += strlen(ext) + 1;
7675         }
77
78         fprintf(out, "\t\t</device>\n");
7976      }
80      devices_free(devices);
77
78      fprintf(out, "\t\t</device>\n");
8179   }
8280}
8381
src/mess/device.c
r2113r2114
1717
1818
1919/***************************************************************************
20    CONSTANTS
21***************************************************************************/
22
23#define MESS_DEVICE      DEVICE_GET_INFO_NAME(mess_device)
24
25
26
27/***************************************************************************
2028    TYPE DEFINITIONS
2129***************************************************************************/
2230
23struct Devices
31/* this is placed in the inline_config of the MAME device structure */
32typedef struct _mess_device_config mess_device_config;
33struct _mess_device_config
2434{
25   iodevice_t type;
26   const char *name;
27   const char *shortname;
35   struct IODevice io_device;
36   char string_buffer[1024];
37   struct CreateImageOptions createimage_options[MESS_DEVINFO_CREATE_OPTMAX + 1];
2838};
2939
3040
3141
32typedef struct _device_list device_list;
33struct _device_list
42struct Devices
3443{
35   object_pool *pool;
36   struct IODevice devices[1];
44   iodevice_t type;
45   const char *name;
46   const char *shortname;
3747};
3848
3949
r2113r2114
192202
193203
194204/*-------------------------------------------------
195    devices_allocate - allocate devices
205    DEVICE_START(mess_device) - device start
206    callback
196207-------------------------------------------------*/
197208
198const struct IODevice *devices_allocate(const game_driver *gamedrv)
209static DEVICE_START(mess_device)
199210{
200   struct SystemConfigurationParamBlock params;
201   device_getinfo_handler handlers[64];
202   int count_overrides[sizeof(handlers) / sizeof(handlers[0])];
203   int createimage_optcount, count, i, j, position;
204   const char *file_extensions, *info_string;
205   char *converted_file_extensions;
206   object_pool *pool;
207   device_list *devlist;
208   struct IODevice *devices;
211}
209212
210   memset(handlers, 0, sizeof(handlers));
211   memset(count_overrides, 0, sizeof(count_overrides));
212213
213   if (gamedrv->sysconfig_ctor)
214
215/*-------------------------------------------------
216    DEVICE_GET_INFO(mess_device) - device get info
217    callback
218-------------------------------------------------*/
219
220DEVICE_GET_INFO(mess_device)
221{
222   switch (state)
214223   {
215      memset(&params, 0, sizeof(params));
216      params.device_slotcount = sizeof(handlers) / sizeof(handlers[0]);
217      params.device_handlers = handlers;
218      params.device_countoverrides = count_overrides;
219      gamedrv->sysconfig_ctor(&params);
224      /* --- the following bits of info are returned as 64-bit signed integers --- */
225      case DEVINFO_INT_INLINE_CONFIG_BYTES:   info->i = sizeof(mess_device_config);         break;
226      case DEVINFO_INT_TOKEN_BYTES:         info->i = 1;                           break;
227      case DEVINFO_INT_CLASS:               info->i = DEVICE_CLASS_OTHER;               break;
228
229      /* --- the following bits of info are returned as pointers to data or functions --- */
230      case DEVINFO_FCT_SET_INFO:            /* Nothing */                           break;
231      case DEVINFO_FCT_START:               info->start = DEVICE_START_NAME(mess_device);   break;
232      case DEVINFO_FCT_STOP:               /* Nothing */                           break;
233      case DEVINFO_FCT_RESET:               /* Nothing */                           break;
234
235      /* --- the following bits of info are returned as NULL-terminated strings --- */
236      case DEVINFO_STR_NAME:               info->s = "Legacy MESS Device";               break;
237      case DEVINFO_STR_FAMILY:            info->s = "Legacy MESS Device";               break;
238      case DEVINFO_STR_VERSION:            info->s = "1.0";                        break;
239      case DEVINFO_STR_SOURCE_FILE:         info->s = __FILE__;                        break;
240      case DEVINFO_STR_CREDITS:            info->s = "Copyright the MESS Team";         break;
220241   }
242}
221243
222   /* count the amount of handlers that we have available */
223   for (count = 0; handlers[count]; count++)
224      ;
225   count++; /* for our purposes, include the tailing empty device */
226244
227   /* allocate a memory pool to use for these devices */
228   pool = pool_alloc(NULL);
229   if (!pool)
230      goto error;
231245
232   /* allocate the device list */
233   devlist = (device_list *) pool_malloc(pool, sizeof(device_list) + (count - 1) * sizeof(struct IODevice));
234   if (!devlist)
235      goto error;
236   memset(devlist, 0, sizeof(device_list) + (count - 1) * sizeof(struct IODevice));
237   devlist->pool = pool;
238   devices = devlist->devices;
246/*-------------------------------------------------
247    string_buffer_putc
248-------------------------------------------------*/
239249
240   position = 0;
250static void string_buffer_putc(char *buffer, size_t buffer_length, size_t *buffer_pos, char c)
251{
252   size_t pos;
253   
254   /* sanity check */
255   assert_always(*buffer_pos < buffer_length, "Buffer too small");
256   
257   pos = (*buffer_pos)++;
258   buffer[pos] = c;
259}
241260
242   for (i = 0; i < count; i++)
261
262
263/*-------------------------------------------------
264    string_buffer_putstr
265-------------------------------------------------*/
266
267static char *string_buffer_putstr(char *buffer, size_t buffer_length, size_t *buffer_pos, const char *s)
268{
269   char *result = NULL;
270   size_t i = 0;
271
272   if (s != NULL)
243273   {
244      devices[i].type = IO_COUNT;
245
246      if (handlers[i])
274      result = &buffer[*buffer_pos];
275      do
247276      {
248         devices[i].devclass.get_info = handlers[i];
249         devices[i].devclass.gamedrv = gamedrv;
277         string_buffer_putc(buffer, buffer_length, buffer_pos, s[i]);
278      }
279      while(s[i++] != '\0');
280   }
250281
251         /* convert file extensions from comma delimited to null delimited */
252         converted_file_extensions = NULL;
253         file_extensions = mess_device_get_info_string(&devices[i].devclass, MESS_DEVINFO_STR_FILE_EXTENSIONS);
254         if (file_extensions)
255         {
256            converted_file_extensions = pool_malloc(pool, strlen(file_extensions) + 2);
257            if (!converted_file_extensions)
258               goto error;
282   return result;
283}
259284
260            for (j = 0; file_extensions[j]; j++)
261               converted_file_extensions[j] = (file_extensions[j] != ',') ? file_extensions[j] : '\0';
262            converted_file_extensions[j + 0] = '\0';
263            converted_file_extensions[j + 1] = '\0';
264         }
265285
266         info_string = mess_device_get_info_string(&devices[i].devclass, MESS_DEVINFO_STR_DEV_TAG);
267         devices[i].tag               = info_string ? pool_strdup(pool, info_string) : NULL;
268         devices[i].type               = mess_device_get_info_int(&devices[i].devclass, MESS_DEVINFO_INT_TYPE);
269         devices[i].count            = mess_device_get_info_int(&devices[i].devclass, MESS_DEVINFO_INT_COUNT);
270         devices[i].position            = position;
271         devices[i].file_extensions      = converted_file_extensions;
272286
273         devices[i].readable            = mess_device_get_info_int(&devices[i].devclass, MESS_DEVINFO_INT_READABLE) ? 1 : 0;
274         devices[i].writeable         = mess_device_get_info_int(&devices[i].devclass, MESS_DEVINFO_INT_WRITEABLE) ? 1 : 0;
275         devices[i].creatable         = mess_device_get_info_int(&devices[i].devclass, MESS_DEVINFO_INT_CREATABLE) ? 1 : 0;
276         devices[i].reset_on_load      = mess_device_get_info_int(&devices[i].devclass, MESS_DEVINFO_INT_RESET_ON_LOAD) ? 1 : 0;
277         devices[i].must_be_loaded      = mess_device_get_info_int(&devices[i].devclass, MESS_DEVINFO_INT_MUST_BE_LOADED) ? 1 : 0;
278         devices[i].load_at_init         = mess_device_get_info_int(&devices[i].devclass, MESS_DEVINFO_INT_LOAD_AT_INIT) ? 1 : 0;
287/*-------------------------------------------------
288    create_mess_device - allocates a single legacy
289   MESS device
290-------------------------------------------------*/
279291
280         devices[i].init               = (device_init_handler) mess_device_get_info_fct(&devices[i].devclass, MESS_DEVINFO_PTR_INIT);
281         devices[i].exit               = (device_exit_handler) mess_device_get_info_fct(&devices[i].devclass, MESS_DEVINFO_PTR_EXIT);
282         devices[i].load               = (device_load_handler) mess_device_get_info_fct(&devices[i].devclass, MESS_DEVINFO_PTR_LOAD);
283         devices[i].create            = (device_create_handler) mess_device_get_info_fct(&devices[i].devclass, MESS_DEVINFO_PTR_CREATE);
284         devices[i].unload            = (device_unload_handler) mess_device_get_info_fct(&devices[i].devclass, MESS_DEVINFO_PTR_UNLOAD);
285         devices[i].imgverify         = (device_verify_handler) mess_device_get_info_fct(&devices[i].devclass, MESS_DEVINFO_PTR_VERIFY);
286         devices[i].partialhash         = (device_partialhash_handler) mess_device_get_info_fct(&devices[i].devclass, MESS_DEVINFO_PTR_PARTIAL_HASH);
287         devices[i].getdispositions      = (device_getdispositions_handler) mess_device_get_info_fct(&devices[i].devclass, MESS_DEVINFO_PTR_GET_DISPOSITIONS);
292static void create_mess_device(device_config **listheadptr, device_getinfo_handler handler, const game_driver *gamedrv,
293   int count_override, int *position)
294{
295   mess_device_class mess_devclass;
296   const char *tag;
297   const char *info_string;
298   char dynamic_tag[32];
299   device_config *device;
300   mess_device_config *mess_device;
301   const char *file_extensions;
302   int j;
303   size_t string_buffer_pos = 0;
304   int createimage_optcount;
288305
289         devices[i].display            = (device_display_handler) mess_device_get_info_fct(&devices[i].devclass, MESS_DEVINFO_PTR_DISPLAY);
290         devices[i].name               = default_device_name;
306   /* set up MESS's device class */
307   mess_devclass.get_info = handler;
308   mess_devclass.gamedrv = gamedrv;
291309
292         devices[i].createimage_optguide   = (const struct OptionGuide *) mess_device_get_info_ptr(&devices[i].devclass, MESS_DEVINFO_PTR_CREATE_OPTGUIDE);
310   /* determine the tag */
311   tag = mess_device_get_info_string(&mess_devclass, MESS_DEVINFO_STR_DEV_TAG);
312   if (tag == NULL)
313   {
314      /* create a default tag */
315      snprintf(dynamic_tag, ARRAY_LENGTH(dynamic_tag), "mess_device_%d", *position);
316      tag = dynamic_tag;
317   }
318   
319   /* create a bonafide MAME device */
320   device = device_list_add(listheadptr, MESS_DEVICE, tag);
321   mess_device = (mess_device_config *) device->inline_config;
293322
294         createimage_optcount = (int) mess_device_get_info_int(&devices[i].devclass, MESS_DEVINFO_INT_CREATE_OPTCOUNT);
295         if (createimage_optcount > 0)
296         {
297            struct CreateImageOptions *createimage_options;
323   /* convert file extensions from comma delimited to null delimited */
324   file_extensions = mess_device_get_info_string(&mess_devclass, MESS_DEVINFO_STR_FILE_EXTENSIONS);
325   if (file_extensions != NULL)
326   {
327      const char *file_extensions_copy = &mess_device->string_buffer[string_buffer_pos];
298328
299            if (createimage_optcount > MESS_DEVINFO_CREATE_OPTMAX)
300               fatalerror("MESS_DEVINFO_INT_CREATE_OPTCOUNT: Too many options");
329      /* copy the file extensions over to the buffer */
330      for (j = 0; file_extensions[j] != '\0'; j++)
331      {
332         string_buffer_putc(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos,
333            (file_extensions[j] != ',') ? file_extensions[j] : '\0');
334      }
335      string_buffer_putc(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos, '\0');
336      string_buffer_putc(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos, '\0');
301337
302            /* allocate the options */
303            createimage_options = pool_malloc(pool, (createimage_optcount + 1) * sizeof(*createimage_options));
304            if (!createimage_options)
305               goto error;
338      file_extensions = file_extensions_copy;
339   }
306340
307            /* set up each option in the list */
308            for (j = 0; j < createimage_optcount; j++)
309            {
310               info_string = mess_device_get_info_string(&devices[i].devclass, MESS_DEVINFO_STR_CREATE_OPTNAME + j);
311               createimage_options[j].name         = info_string ? pool_strdup(pool, info_string) : NULL;
312               info_string = mess_device_get_info_string(&devices[i].devclass, MESS_DEVINFO_STR_CREATE_OPTDESC + j);
313               createimage_options[j].description   = info_string ? pool_strdup(pool, info_string) : NULL;
314               info_string = mess_device_get_info_string(&devices[i].devclass, MESS_DEVINFO_STR_CREATE_OPTEXTS + j);
315               createimage_options[j].extensions   = info_string ? pool_strdup(pool, info_string) : NULL;
316               createimage_options[j].optspec      = mess_device_get_info_ptr(&devices[i].devclass, MESS_DEVINFO_PTR_CREATE_OPTSPEC + j);
317            }
341   /* populate the legacy MESS device */
342   mess_device->io_device.tag               = device->tag;
343   mess_device->io_device.devconfig         = device;
344   mess_device->io_device.devclass            = mess_devclass;
345   mess_device->io_device.type               = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_TYPE);
346   mess_device->io_device.count            = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_COUNT);
347   mess_device->io_device.position            = *position;
348   mess_device->io_device.file_extensions      = file_extensions;
318349
319            /* terminate the list */
320            memset(&createimage_options[createimage_optcount], 0, sizeof(createimage_options[createimage_optcount]));
350   mess_device->io_device.readable            = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_READABLE) ? 1 : 0;
351   mess_device->io_device.writeable         = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_WRITEABLE) ? 1 : 0;
352   mess_device->io_device.creatable         = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_CREATABLE) ? 1 : 0;
353   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;
354   mess_device->io_device.must_be_loaded      = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_MUST_BE_LOADED) ? 1 : 0;
355   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;
321356
322            /* place this list in the structure */
323            devices[i].createimage_options = createimage_options;
324         }
357   mess_device->io_device.init               = (device_init_handler) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_INIT);
358   mess_device->io_device.exit               = (device_exit_handler) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_EXIT);
359   mess_device->io_device.load               = (device_load_handler) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_LOAD);
360   mess_device->io_device.create            = (device_create_handler) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE);
361   mess_device->io_device.unload            = (device_unload_handler) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_UNLOAD);
362   mess_device->io_device.imgverify         = (device_verify_handler) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_VERIFY);
363   mess_device->io_device.partialhash         = (device_partialhash_handler) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_PARTIAL_HASH);
364   mess_device->io_device.getdispositions      = (device_getdispositions_handler) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_GET_DISPOSITIONS);
325365
326         position += devices[i].count;
366   mess_device->io_device.display            = (device_display_handler) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_DISPLAY);
367   mess_device->io_device.name               = default_device_name;
327368
328         /* overriding the count? */
329         if (count_overrides[i])
330            devices[i].count = count_overrides[i];
369   mess_device->io_device.createimage_optguide   = (const struct OptionGuide *) mess_device_get_info_ptr(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE_OPTGUIDE);
331370
332         /* any problems? */
333         if ((devices[i].type < 0) || (devices[i].type >= IO_COUNT))
334            goto error;
335         if ((devices[i].count < 0) || (devices[i].count > MAX_DEV_INSTANCES))
336            goto error;
371   createimage_optcount = (int) mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_CREATE_OPTCOUNT);
372   if (createimage_optcount > 0)
373   {
374      if (createimage_optcount > MESS_DEVINFO_CREATE_OPTMAX)
375         fatalerror("MESS_DEVINFO_INT_CREATE_OPTCOUNT: Too many options");
337376
338         /* fill in defaults */
339         if (!devices[i].getdispositions)
340            devices[i].getdispositions = default_device_getdispositions;
377      /* set up each option in the list */
378      for (j = 0; j < createimage_optcount; j++)
379      {
380         info_string = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_CREATE_OPTNAME + j);
381         mess_device->createimage_options[j].name      = string_buffer_putstr(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos, info_string);
382
383         info_string = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_CREATE_OPTDESC + j);
384         mess_device->createimage_options[j].description   = string_buffer_putstr(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos, info_string);
385         
386         info_string = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_CREATE_OPTEXTS + j);
387         mess_device->createimage_options[j].extensions   = string_buffer_putstr(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos, info_string);
388         
389         mess_device->createimage_options[j].optspec      = mess_device_get_info_ptr(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE_OPTSPEC + j);
341390      }
391
392      /* terminate the list */
393      memset(&mess_device->createimage_options[createimage_optcount], 0, sizeof(mess_device->createimage_options[createimage_optcount]));
342394   }
343395
344   return devices;
396   *position += mess_device->io_device.count;
345397
346error:
347   if (pool != NULL)
348      pool_free(pool);
349   return NULL;
398   /* overriding the count? */
399   if (count_override != 0)
400      mess_device->io_device.count = count_override;
401
402   /* any problems? */
403   assert((mess_device->io_device.type >= 0) && (mess_device->io_device.type < IO_COUNT));
404   assert ((mess_device->io_device.count >= 0) && (mess_device->io_device.count <= MAX_DEV_INSTANCES));
405
406   /* fill in defaults */
407   if (!mess_device->io_device.getdispositions)
408      mess_device->io_device.getdispositions = default_device_getdispositions;
350409}
351410
352411
353412
354413/*-------------------------------------------------
355    devices_free - free a device list
414    mess_devices_setup - allocate devices
356415-------------------------------------------------*/
357416
358void devices_free(const struct IODevice *devices)
417void mess_devices_setup(machine_config *config, const game_driver *gamedrv)
359418{
360   const UINT8 *devices_b = (const UINT8 *) devices;
361   const UINT8 *devlist_b = devices_b - offsetof(device_list, devices);
362   device_list *devlist = (device_list *) devlist_b;
363   pool_free(devlist->pool);
419   device_getinfo_handler handlers[64];
420   int count_overrides[sizeof(handlers) / sizeof(handlers[0])];
421   int i, position = 0;
422
423   memset(handlers, 0, sizeof(handlers));
424   memset(count_overrides, 0, sizeof(count_overrides));
425
426   /* call the "sysconfig" constructor, if present */
427   if (gamedrv->sysconfig_ctor != NULL)
428   {
429      struct SystemConfigurationParamBlock params;
430
431      memset(&params, 0, sizeof(params));
432      params.device_slotcount = sizeof(handlers) / sizeof(handlers[0]);
433      params.device_handlers = handlers;
434      params.device_countoverrides = count_overrides;
435      gamedrv->sysconfig_ctor(&params);
436   }
437
438   /* loop through all handlers */
439   for (i = 0; handlers[i] != NULL; i++)
440   {
441      create_mess_device(&config->devicelist, handlers[i], gamedrv, count_overrides[i], &position);
442   }
364443}
365444
366445
367446
447/*-------------------------------------------------
448    machine_config_alloc_with_mess_devices -
449   allocate a machine_config with MESS devices
450-------------------------------------------------*/
451
452machine_config *machine_config_alloc_with_mess_devices(const game_driver *gamedrv)
453{
454   machine_config *config = machine_config_alloc(gamedrv->machine_config);
455   mess_devices_setup(config, gamedrv);
456   return config;
457}
458
459
460
368461/*************************************
369462 *
370463 *   Device enumeration
371464 *
372465 *************************************/
373466
374static const struct IODevice *filter_device_array_termination(const struct IODevice *dev)
375{
376   return ((dev != NULL) && (dev->type < IO_COUNT)) ? dev : NULL;
377}
378
379
380
381467const struct IODevice *mess_device_first_from_machine(const running_machine *machine)
382468{
383   return filter_device_array_termination(machine->devices);
469   const device_config *devconfig;
470   devconfig = device_list_first(machine->config->devicelist, MESS_DEVICE);
471   return (devconfig != NULL) ? devconfig->inline_config : NULL;
384472}
385473
386474
387475
388476const struct IODevice *mess_device_next(const struct IODevice *dev)
389477{
390   return filter_device_array_termination(dev + 1);
478   const device_config *devconfig;
479   devconfig = device_list_next(dev->devconfig, MESS_DEVICE);
480   return (devconfig != NULL) ? devconfig->inline_config : NULL;
391481}
392482
393483
r2113r2114
398488 *
399489 *************************************/
400490
401const struct IODevice *device_find_tag(const struct IODevice *devices, const char *tag)
491const struct IODevice *mess_device_from_core_device(const device_config *device)
402492{
403   int i;
404   for (i = 0; devices[i].type != IO_COUNT; i++)
405   {
406      if (devices[i].tag && !strcmp(devices[i].tag, tag))
407         return &devices[i];
408   }
409   return NULL;
493   const mess_device_config *mess_device = (device != NULL) ? (const mess_device_config *) device->inline_config : NULL;
494   return (mess_device != NULL) ? &mess_device->io_device : NULL;
410495}
411496
412497
413498
414int device_count_tag(const struct IODevice *devices, const char *tag)
415{
416   const struct IODevice *dev;
417   dev = device_find_tag(devices, tag);
418   return dev ? dev->count : 0;
419}
420
421
422
423499int device_count_tag_from_machine(const running_machine *machine, const char *tag)
424500{
425   return device_count_tag(machine->devices, tag);
501   const device_config *device = device_list_find_by_tag(machine->config->devicelist, MESS_DEVICE, tag);
502   const struct IODevice *iodev = mess_device_from_core_device(device);
503   return (iodev != NULL) ? iodev->count : 0;
426504}
427505
428506
429507
430508/* this function is deprecated */
431const struct IODevice *device_find(const struct IODevice *devices, iodevice_t type)
509const struct IODevice *device_find_from_machine(const running_machine *machine, iodevice_t type)
432510{
433   int i;
434   for (i = 0; devices[i].type != IO_COUNT; i++)
511   const device_config *device;
512
513   for (device = device_list_first(machine->config->devicelist, MESS_DEVICE); device != NULL; device = device_list_next(device, MESS_DEVICE))
435514   {
436      if (devices[i].type == type)
437         return &devices[i];
515      const struct IODevice *iodev = mess_device_from_core_device(device);
516      if (iodev->type == type)
517      {
518         return iodev;
519      }
438520   }
439521   return NULL;
440522}
r2113r2114
442524
443525
444526/* this function is deprecated */
445const struct IODevice *device_find_from_machine(const running_machine *machine, iodevice_t type)
446{
447   return device_find(machine->devices, type);
448}
449
450
451
452/* this function is deprecated */
453527int device_count(iodevice_t type)
454528{
455529   const struct IODevice *iodev = device_find_from_machine(Machine, type);
src/mess/device.h
r2113r2114
99#ifndef DEVICE_H
1010#define DEVICE_H
1111
12// MAME headers
1213#include "mamecore.h"
14#include "devintrf.h"
15
16// MESS headers
1317#include "osdmess.h"
1418#include "opresolv.h"
1519
20
1621/*************************************
1722 *
1823 *  Device information constants
1924 *
2025 *************************************/
2126
27#define MESS_DEVICE      DEVICE_GET_INFO_NAME(mess_device)
28
2229#define MAX_DEV_INSTANCES   5
2330
2431enum
r2113r2114
97104typedef const char *(*device_getname_handler)(const struct IODevice *dev, int id, char *buf, size_t bufsize);
98105
99106struct _mess_device_class;
107struct _machine_config;
100108
101109union devinfo
102110{
r2113r2114
230238struct IODevice
231239{
232240   mess_device_class devclass;
241   const device_config *devconfig;
233242
234243   /* the basics */
235244   const char *tag;
r2113r2114
268277   const struct CreateImageOptions *createimage_options;
269278};
270279
280/* interoperability with MAME devices */
281DEVICE_GET_INFO(mess_device);
282struct _machine_config *machine_config_alloc_with_mess_devices(const game_driver *gamedrv);
283const struct IODevice *mess_device_from_core_device(const device_config *device);
271284
272285/* device naming */
273286const char *device_uiname(iodevice_t devtype);
r2113r2114
276289int device_typeid(const char *name);
277290
278291/* device allocation */
279const struct IODevice *devices_allocate(const game_driver *gamedrv);
280void devices_free(const struct IODevice *devices);
292void mess_devices_setup(machine_config *config, const game_driver *gamedrv);
281293
282294/* device enumeration */
283295const struct IODevice *mess_device_first_from_machine(const running_machine *machine);
284296const struct IODevice *mess_device_next(const struct IODevice *dev);
285297
286298/* device lookup */
287const struct IODevice *device_find_tag(const struct IODevice *devices, const char *tag);
288int device_count_tag(const struct IODevice *devices, const char *tag);
289299int device_count_tag_from_machine(const running_machine *machine, const char *tag);
290300
291301/* deprecated: device lookup; both of these function assume only one of each type of device */
292const struct IODevice *device_find(const struct IODevice *devices, iodevice_t type);
293302const struct IODevice *device_find_from_machine(const running_machine *machine, iodevice_t type);
294303int device_count(iodevice_t type);
295304
src/mess/osd/winui/messui.c
r2113r2114
375375
376376BOOL MessApproveImageList(HWND hParent, int drvindex)
377377{
378   int i, nPos, devindex;
379   const struct IODevice *devices;
380   const game_driver *pDriver;
378   machine_config *config;
379   const device_config *dev;
380   const struct IODevice *iodev;
381   int i, nPos;
381382   char szMessage[256];
382383   LPCSTR pszSoftware;
383384   BOOL bResult = FALSE;
384385
385386   begin_resource_tracking();
386387
387   pDriver = drivers[drvindex];
388   devices = devices_allocate(pDriver);
388   // allocate the machine config
389   config = machine_config_alloc_with_mess_devices(drivers[drvindex]);
389390
390391   nPos = 0;
391   for (devindex = 0; devices[devindex].type < IO_COUNT; devindex++)
392   for (dev = device_list_first(config->devicelist, MESS_DEVICE); dev != NULL; dev = device_list_next(dev, MESS_DEVICE))
392393   {
394      iodev = mess_device_from_core_device(dev);
395
393396      // confirm any mandatory devices are loaded
394      if (devices[devindex].must_be_loaded)
397      if (iodev->must_be_loaded)
395398      {
396         for (i = 0; i < devices[devindex].count; i++)
399         for (i = 0; i < iodev->count; i++)
397400         {
398            pszSoftware = GetSelectedSoftware(drvindex, &devices[devindex].devclass, i);
401            pszSoftware = GetSelectedSoftware(drvindex, &iodev->devclass, i);
399402            if (!pszSoftware || !*pszSoftware)
400403            {
401404               snprintf(szMessage, sizeof(szMessage) / sizeof(szMessage[0]),
402405                  "System '%s' requires that device %s must have an image to load\n",
403                  pDriver->description,
404                  device_typename(devices[devindex].type));
406                  drivers[drvindex]->description,
407                  device_typename(iodev->type));
405408               goto done;
406409            }
407410         }
408411      }
409412
410      nPos += devices[devindex].count;
413      nPos += iodev->count;
411414   }
412415   bResult = TRUE;
413416
r2113r2114
417420      win_message_box_utf8(hParent, szMessage, MAMEUINAME, MB_OK);
418421   }
419422
420   devices_free(devices);
423   machine_config_free(config);
421424   return bResult;
422425}
423426
r2113r2114
441444// Places the specified image in the specified slot; nID = -1 means don't matter
442445static void MessSpecifyImage(int drvindex, const mess_device_class *devclass, int nID, LPCSTR pszFilename)
443446{
444   const struct IODevice *devices;
445   const struct IODevice *dev;
447   machine_config *config;
448   const device_config *dev;
449   const struct IODevice *iodev = NULL;
446450   const char *s;
447451   int i;
448452
449   devices = devices_allocate(devclass->gamedrv);
453   // allocate the machine config
454   config = machine_config_alloc_with_mess_devices(drivers[drvindex]);
450455
451   for (dev = devices; dev->type < IO_COUNT; dev++)
456   for (dev = device_list_first(config->devicelist, MESS_DEVICE); dev != NULL; dev = device_list_next(dev, MESS_DEVICE))
452457   {
453      if (dev->devclass.get_info == devclass->get_info)
458      iodev = mess_device_from_core_device(dev);
459
460      if (iodev->devclass.get_info == devclass->get_info)
454461         break;
455462   }
456463
r2113r2114
462469   if (nID < 0)
463470   {
464471      // special case; first try to find existing image
465      for (i = 0; i < dev->count; i++)
472      for (i = 0; i < iodev->count; i++)
466473      {
467         s = GetSelectedSoftware(drvindex, &dev->devclass, i);
474         s = GetSelectedSoftware(drvindex, &iodev->devclass, i);
468475         if (s && !mame_stricmp(s, pszFilename))
469476         {
470477            nID = i;
r2113r2114
476483   if (nID < 0)
477484   {
478485      // still not found?  locate an empty slot
479      for (i = 0; i < dev->count; i++)
486      for (i = 0; i < iodev->count; i++)
480487      {
481         s = GetSelectedSoftware(drvindex, &dev->devclass, i);
488         s = GetSelectedSoftware(drvindex, &iodev->devclass, i);
482489         if (!s || !*s || !mame_stricmp(s, pszFilename))
483490         {
484491            nID = i;
r2113r2114
488495   }
489496
490497   if (nID >= 0)
491      InternalSetSelectedSoftware(drvindex, &dev->devclass, nID, pszFilename);
498      InternalSetSelectedSoftware(drvindex, &iodev->devclass, nID, pszFilename);
492499   else if (LOG_SOFTWARE)
493500      dprintf("MessSpecifyImage(): Failed to place image '%s'\n", pszFilename);
494501
495   devices_free(devices);
502   machine_config_free(config);
496503}
497504
498505
r2113r2114
500507static void MessRemoveImage(int drvindex, mess_device_class devclass, LPCSTR pszFilename)
501508{
502509   int i, nPos;
503   const struct IODevice *devices;
504   const struct IODevice *dev;
510   machine_config *config;
511   const device_config *dev;
512   const struct IODevice *iodev = NULL;
505513
506   if (devclass.gamedrv)
514   if (devclass.gamedrv != NULL)
507515   {
508      devices = devices_allocate(devclass.gamedrv);
516      // allocate the machine config
517      config = machine_config_alloc_with_mess_devices(drivers[drvindex]);
509518
510519      nPos = 0;
511      for (dev = devices; dev->type < IO_COUNT; dev++)
520      for (dev = device_list_first(config->devicelist, MESS_DEVICE); dev != NULL; dev = device_list_next(dev, MESS_DEVICE))
512521      {
513         if (dev->devclass.get_info == devclass.get_info)
522         iodev = mess_device_from_core_device(dev);
523
524         if (iodev->devclass.get_info == devclass.get_info)
514525            break;
515         nPos += dev->count;
526         nPos += iodev->count;
516527      }
517528
518      if (dev->type < IO_COUNT)
529      if (iodev != NULL)
519530      {
520         for (i = 0; i < dev->count; i++)
531         for (i = 0; i < iodev->count; i++)
521532         {
522            if (!mame_stricmp(pszFilename, GetSelectedSoftware(drvindex, &dev->devclass, i)))
533            if (!mame_stricmp(pszFilename, GetSelectedSoftware(drvindex, &iodev->devclass, i)))
523534            {
524535               MessSpecifyImage(drvindex, &devclass, i, NULL);
525536               break;
r2113r2114
527538         }
528539      }
529540
530      devices_free(devices);
541      machine_config_free(config);
531542   }
532543}
533544
r2113r2114
549560   HWND hwndSoftware;
550561   int i, id;
551562   LVFINDINFO lvfi;
552   const game_driver *pDriver;
553   const struct IODevice *pDeviceList;
554   const struct IODevice *pDevice;
563   machine_config *config;
564   const device_config *dev;
565   const struct IODevice *iodev;
555566   LPCSTR pszSoftware;
556567
557568   hwndSoftware = GetDlgItem(GetMainWindow(), IDC_SWLIST);
558   pDriver = drivers[drvindex];
559   pDeviceList = devices_allocate(pDriver);
560   if (!pDeviceList)
561      goto done;
562569
570   // allocate the machine config
571   config = machine_config_alloc_with_mess_devices(drivers[drvindex]);
572
563573   s_bIgnoreSoftwarePickerNotifies = TRUE;
564574
565575   // Now clear everything out; this may call back into us but it should not
566576   // be problematic
567577   ListView_SetItemState(hwndSoftware, -1, 0, LVIS_SELECTED);
568578
569   for (pDevice = pDeviceList; pDevice->type < IO_COUNT; pDevice++)
579   for (dev = device_list_first(config->devicelist, MESS_DEVICE); dev != NULL; dev = device_list_next(dev, MESS_DEVICE))
570580   {
571      for (id = 0; id < pDevice->count; id++)
581      iodev = mess_device_from_core_device(dev);
582
583      for (id = 0; id < iodev->count; id++)
572584      {
573         pszSoftware = GetSelectedSoftware(drvindex, &pDevice->devclass, id);
585         pszSoftware = GetSelectedSoftware(drvindex, &iodev->devclass, id);
574586         if (pszSoftware && *pszSoftware)
575587         {
576588            i = SoftwarePicker_LookupIndex(hwndSoftware, pszSoftware);
r2113r2114
591603      }
592604   }
593605
594
595done:
596   devices_free(pDeviceList);
606   machine_config_free(config);
597607   s_bIgnoreSoftwarePickerNotifies = FALSE;
598608}
599609
r2113r2114
747757
748758
749759/* Specify IO_COUNT for type if you want all types */
750static void SetupImageTypes(const struct IODevice *devices, mess_image_type *types, int count, BOOL bZip, int type)
760static void SetupImageTypes(const machine_config *config, mess_image_type *types, int count, BOOL bZip, int type)
751761{
752762    int num_extensions = 0;
753   int devindex;
763   const device_config *dev;
764   const struct IODevice *iodev;
754765
755766   memset(types, 0, sizeof(*types) * count);
756767    count--;
r2113r2114
762773      num_extensions++;
763774    }
764775
765   if (devices != NULL)
776   for (dev = device_list_first(config->devicelist, MESS_DEVICE); dev != NULL; dev = device_list_next(dev, MESS_DEVICE))
766777   {
767      for (devindex = 0; devices[devindex].type < IO_COUNT; devindex++)
778      iodev = mess_device_from_core_device(dev);
779
780      if (iodev->type != IO_PRINTER)
768781      {
769         if (devices[devindex].type != IO_PRINTER)
782         const char *ext = iodev->file_extensions;
783         if (ext != NULL)
770784         {
771            const char *ext = devices[devindex].file_extensions;
772            if (ext)
785            while(*ext != '\0')
773786            {
774               while(*ext)
787               if ((type == IO_COUNT) || (type == iodev->type))
775788               {
776                  if ((type == IO_COUNT) || (type == devices[devindex].type))
789                  if (num_extensions < count)
777790                  {
778                     if (num_extensions < count)
779                     {
780                        types[num_extensions].dev = &devices[devindex];
781                        types[num_extensions].ext = ext;
782                        num_extensions++;
783                     }
791                     types[num_extensions].dev = iodev;
792                     types[num_extensions].ext = ext;
793                     num_extensions++;
784794                  }
785                  ext += strlen(ext) + 1;
786795               }
796               ext += strlen(ext) + 1;
787797            }
788798         }
789799      }
r2113r2114
799809   int drvindex;
800810   HWND hwndList;
801811   char* utf8_filename;
802   const struct IODevice *devices;
812   machine_config *config;
803813
804814   begin_resource_tracking();
805815
806816   hwndList = GetDlgItem(GetMainWindow(), IDC_LIST);
807817   drvindex = Picker_GetSelectedItem(hwndList);
808   devices = devices_allocate(drivers[drvindex]);
809   SetupImageTypes(devices, imagetypes, sizeof(imagetypes) / sizeof(imagetypes[0]), TRUE, iDevice);
810818
819   // allocate the machine config
820   config = machine_config_alloc_with_mess_devices(drivers[drvindex]);
821
822   SetupImageTypes(config, imagetypes, sizeof(imagetypes) / sizeof(imagetypes[0]), TRUE, iDevice);
823
811824   if (CommonFileImageDialog(last_directory, cfd, filename, imagetypes))
812825   {
813826      utf8_filename = utf8_from_tstring(filename);
r2113r2114
818831      free(utf8_filename);
819832   }
820833
821   if (devices != NULL)
822      devices_free(devices);
834   machine_config_free(config);
823835}
824836
825837
r2113r2114
844856   mess_image_type imagetypes[64];
845857   HWND hwndList;
846858   int gamenum;
847   const struct IODevice *devices;
859   machine_config *config;
848860
849861   hwndList = GetDlgItem(GetMainWindow(), IDC_LIST);
850862   gamenum = Picker_GetSelectedItem(hwndList);
851   devices = devices_allocate(drivers[gamenum]);
852   SetupImageTypes(devices, imagetypes, sizeof(imagetypes) / sizeof(imagetypes[0]), TRUE, dev->type);
863
864   // allocate the machine config
865   config = machine_config_alloc_with_mess_devices(drivers[gamenum]);
866
867   SetupImageTypes(config, imagetypes, sizeof(imagetypes) / sizeof(imagetypes[0]), TRUE, dev->type);
853868   bResult = CommonFileImageDialog(last_directory, GetOpenFileName, pszFilename, imagetypes);
854869
855   if (devices != NULL)
856      devices_free(devices);
870   machine_config_free(config);
857871   return bResult;
858872}
859873
r2113r2114
865879   mess_image_type imagetypes[64];
866880   HWND hwndList;
867881   int gamenum;
868   const struct IODevice *devices;
882   machine_config *config;
869883
870884   hwndList = GetDlgItem(GetMainWindow(), IDC_LIST);
871885   gamenum = Picker_GetSelectedItem(hwndList);
872   devices = devices_allocate(drivers[gamenum]);
873   SetupImageTypes(devices, imagetypes, sizeof(imagetypes) / sizeof(imagetypes[0]), TRUE, dev->type);
886
887   // allocate the machine config
888   config = machine_config_alloc_with_mess_devices(drivers[gamenum]);
889
890   SetupImageTypes(config, imagetypes, sizeof(imagetypes) / sizeof(imagetypes[0]), TRUE, dev->type);
874891   bResult = CommonFileImageDialog(last_directory, GetSaveFileName, pszFilename, imagetypes);
875892
876   if (devices != NULL)
877      devices_free(devices);
893   machine_config_free(config);
878894   return bResult;
879895}
880896
src/mess/osd/winui/devview.c
r2113r2114
2929   int nGame;
3030   int nWidth;
3131   BOOL bSurpressFilenameChanged;
32   const struct IODevice *pDevices;
32   machine_config *config;
3333   const struct DevViewCallbacks *pCallbacks;
3434   struct DevViewEntry *pEntries;
3535};
r2113r2114
7676      pDevViewInfo->pEntries = NULL;
7777   }
7878
79   if (pDevViewInfo->pDevices != NULL)
79   if (pDevViewInfo->config != NULL)
8080   {
81      devices_free(pDevViewInfo->pDevices);
82      pDevViewInfo->pDevices = NULL;
81      machine_config_free(pDevViewInfo->config);
82      pDevViewInfo->config = NULL;
8383   }
8484}
8585
r2113r2114
187187BOOL DevView_SetDriver(HWND hwndDevView, int nGame)
188188{
189189   struct DevViewInfo *pDevViewInfo;
190   const game_driver *drv;
191   const struct IODevice *devices;
192   const struct IODevice *dev;
190   const device_config *dev;
191   const struct IODevice *iodev;
193192   struct DevViewEntry *pEnt;
194193   int i, id;
195194   int y, nHeight, nDevCount;
r2113r2114
209208      return TRUE;
210209
211210   DevView_Clear(hwndDevView);
212   drv = drivers[nGame];
213   devices = pDevViewInfo->pDevices = devices_allocate(drv);
214211
215   // Count total amount of devices
212   // allocate the machine config
213   pDevViewInfo->config = machine_config_alloc_with_mess_devices(drivers[nGame]);
214
215   // count total amount of devices
216216   nDevCount = 0;
217   for (dev = devices; dev->type < IO_COUNT; dev++)
218      nDevCount += dev->count;
217   for (dev = device_list_first(pDevViewInfo->config->devicelist, MESS_DEVICE); dev != NULL; dev = device_list_next(dev, MESS_DEVICE))
218   {
219      iodev = mess_device_from_core_device(dev);
220      nDevCount += iodev->count;
221   }
219222
220223   if (nDevCount > 0)
221224   {
222      // Get the names of all of the devices
225      // get the names of all of the devices
223226      ppszDevices = (LPTSTR *) alloca(nDevCount * sizeof(*ppszDevices));
224227      i = 0;
225      for (dev = devices; dev->type < IO_COUNT; dev++)
228
229      for (dev = device_list_first(pDevViewInfo->config->devicelist, MESS_DEVICE); dev != NULL; dev = device_list_next(dev, MESS_DEVICE))
226230      {
227         for (id = 0; id < dev->count; id++)
231         iodev = mess_device_from_core_device(dev);
232
233         for (id = 0; id < iodev->count; id++)
228234         {
229            utf8_s = dev->name(dev, id, buf, sizeof(buf) / sizeof(buf[0]));
235            utf8_s = iodev->name(iodev, id, buf, sizeof(buf) / sizeof(buf[0]));
230236            s = tstring_from_utf8(utf8_s);
231237            ppszDevices[i] = alloca((_tcslen(s) + 1) * sizeof(TCHAR));
232238            _tcscpy(ppszDevices[i], s);
r2113r2114
260266      DevView_GetColumns(hwndDevView, &nStaticPos, &nStaticWidth,
261267         &nEditPos, &nEditWidth, &nButtonPos, &nButtonWidth);
262268
263      for (dev = devices; dev->type < IO_COUNT; dev++)
269      for (dev = device_list_first(pDevViewInfo->config->devicelist, MESS_DEVICE); dev != NULL; dev = device_list_next(dev, MESS_DEVICE))
264270      {
265         for (id = 0; id < dev->count; id++)
271         iodev = mess_device_from_core_device(dev);
272
273         for (id = 0; id < iodev->count; id++)
266274         {
267            pEnt->dev = dev;
275            pEnt->dev = iodev;
268276            pEnt->id = id;
269277
270            pEnt->hwndStatic = win_create_window_ex_utf8(0, "STATIC", dev->name(dev, id, buf, sizeof(buf) / sizeof(buf[0])),
278            pEnt->hwndStatic = win_create_window_ex_utf8(0, "STATIC", iodev->name(iodev, id, buf, sizeof(buf) / sizeof(buf[0])),
271279               WS_VISIBLE | WS_CHILD, nStaticPos, y, nStaticWidth, nHeight,
272280               hwndDevView, NULL, NULL, NULL);
273281
src/mess/osd/winui/msuiutil.c
r2113r2114
4040
4141BOOL DriverHasDevice(const game_driver *gamedrv, iodevice_t type)
4242{
43   BOOL b;
44   const struct IODevice *devices;
43   BOOL b = FALSE;
44   machine_config *config;
45   const device_config *device;
4546
46   devices = devices_allocate(gamedrv);
47   b = device_find(devices, IO_PRINTER) ? TRUE : FALSE;
48   devices_free(devices);
47   // allocate the machine config
48   config = machine_config_alloc_with_mess_devices(gamedrv);
49
50   for (device = device_list_first(config->devicelist, MESS_DEVICE); device != NULL; device = device_list_next(device, MESS_DEVICE))
51   {
52      const struct IODevice *iodev = mess_device_from_core_device(device);
53      if (iodev->type == type)
54      {
55         b = TRUE;
56         break;
57      }
58   }
59
60   machine_config_free(config);
4961   return b;
5062}
5163
src/mess/osd/winui/softwarepicker.c
r2113r2114
6363   struct DirectorySearchInfo *pFirstSearchInfo;
6464   struct DirectorySearchInfo *pLastSearchInfo;
6565   const game_driver *pDriver;
66   machine_config *pConfig;
6667   hash_file *pHashFile;
6768   void (*pfnErrorProc)(const char *message);
6869};
r2113r2114
209210         pPickerInfo->nHashesRealized = 0;
210211      }
211212
213      // is there a machine_config loaded?
214      if (pPickerInfo->pConfig != NULL)
215      {
216         // free the machine_config
217         machine_config_free(pPickerInfo->pConfig);
218         pPickerInfo->pConfig = NULL;
219      }
212220
213221      // change the driver value
214222      pPickerInfo->pDriver = pDriver;
r2113r2114
216224      // if we have a driver, we have to load some stuff
217225      if (pDriver != NULL)
218226      {
227         // get the configuration
228         pPickerInfo->pConfig = machine_config_alloc_with_mess_devices(pDriver);
229
219230         // find a hash file
220231         while((pDriver != NULL) && !pPickerInfo->pHashFile)
221232         {
r2113r2114
399410   struct SoftwarePickerInfo *pPickerInfo;
400411   struct FileInfo **ppNewIndex;
401412   struct FileInfo *pInfo;
402   int nIndex, nSize, devindex;
413   int nIndex, nSize;
403414   LPCSTR pszExtension = NULL, s;
404   const struct IODevice *devices = NULL;
405415   mess_device_class devclass = {0,};
416   const device_config *device;
406417
407418   // first check to see if it is already here
408419   if (SoftwarePicker_LookupIndex(hwndPicker, pszFilename) >= 0)
r2113r2114
413424   // look up the device
414425   if (strrchr(pszFilename, '.'))
415426      pszExtension = strrchr(pszFilename, '.');
416   if (pszExtension && pPickerInfo->pDriver)
427   if ((pszExtension != NULL) && (pPickerInfo->pDriver != NULL))
417428   {
429      // skip the initial '.' in the file extension
418430      pszExtension++;
419431
420      devices = devices_allocate(pPickerInfo->pDriver);
421      if (devices != NULL)
432      for (device = device_list_first(pPickerInfo->pConfig->devicelist, MESS_DEVICE); device != NULL; device = device_list_next(device, MESS_DEVICE))
422433      {
423         for (devindex = 0; devices[devindex].type < IO_COUNT; devindex++)
434         const struct IODevice *iodev = mess_device_from_core_device(device);
435
436         s = iodev->file_extensions;
437         if (s != NULL)
424438         {
425            s = devices[devindex].file_extensions;
426            if (s)
439            while(*s && mame_stricmp(pszExtension, s))
440               s += strlen(s) + 1;
441            if (*s)
427442            {
428               while(*s && mame_stricmp(pszExtension, s))
429                  s += strlen(s) + 1;
430               if (*s)
431               {
432                  devclass = devices[devindex].devclass;
433                  break;
434               }
443               devclass = iodev->devclass;
444               break;
435445            }
436446         }
437         devices_free(devices);
438447      }
439448   }
440449

Previous 15994 Revisions Next


© 1998-2018 The MESS Team