Previous 15994 Revisions Next

r2133 Saturday 29th March, 2008 at 02:32:27 UTC by Nathan Woods
Removed IODevice.count and related concepts
[src/mess]climess.c configms.c device.c device.h filemngr.c image.c image.h infomess.c mess.c uimess.c
[src/mess/osd/windows]menu.c
[src/mess/osd/winui]devview.c messui.c

src/mess/climess.c
r2132r2133
4343
4444int info_listdevices(core_options *opts, const char *gamename)
4545{
46   int i, id;
46   int i;
4747   machine_config *config;
4848   const device_config *dev;
4949   const struct IODevice *iodev;
r2132r2133
7676
7777            src = iodev->file_extensions;
7878
79            for (id = 0; id < iodev->count; id++)
80            {
81               name = device_instancename(&iodev->devclass, id);
82               shortname = device_briefinstancename(&iodev->devclass, id);
79            name = device_instancename(&iodev->devclass, iodev->index_in_device);
80            shortname = device_briefinstancename(&iodev->devclass, iodev->index_in_device);
8381
84               sprintf(paren_shortname, "(%s)", shortname);
82            sprintf(paren_shortname, "(%s)", shortname);
8583
86               mame_printf_info("%-13s%-12s%-8s   ", driver_name, name, paren_shortname);
87               driver_name = " ";
84            mame_printf_info("%-13s%-12s%-8s   ", driver_name, name, paren_shortname);
85            driver_name = " ";
8886
89               if (id == 0)
90               {
91                  while (src && *src)
92                  {
93                     mame_printf_info(".%-5s", src);
94                     src += strlen(src) + 1;
95                  }
96               }
97               mame_printf_info("\n");
87            while (src && *src)
88            {
89               mame_printf_info(".%-5s", src);
90               src += strlen(src) + 1;
9891            }
92            mame_printf_info("\n");
9993         }
10094         machine_config_free(config);
10195      }
src/mess/configms.c
r2132r2133
2424{
2525   xml_data_node *node;
2626   const struct IODevice *dev;
27   int i;
2827   mess_image *image;
2928   const char *dev_instance;
3029   const char *working_directory;
r2132r2133
4039         {
4140            for (dev = mess_device_first_from_machine(Machine); (image == NULL) && (dev != NULL); dev = mess_device_next(dev))
4241            {
43               for (i = 0; !image && (i < dev->count); i++)
44               {
45                  if (!strcmp(dev_instance, device_instancename(&dev->devclass, i)))
46                     image = image_from_device_and_index(dev, i);
47               }
42               if (!strcmp(dev_instance, device_instancename(&dev->devclass, dev->index_in_device)))
43                  image = image_from_device(dev);
4844            }
4945
5046            if (image != NULL)
r2132r2133
6965{
7066   xml_data_node *node;
7167   const struct IODevice *dev;
72   int i;
7368   mess_image *image;
7469   const char *dev_instance;
7570
r2132r2133
7873   {
7974      for (dev = mess_device_first_from_machine(Machine); dev != NULL; dev = mess_device_next(dev))
8075      {
81         for (i = 0; i < dev->count; i++)
82         {
83            image = image_from_device_and_index(dev, i);
84            dev_instance = device_instancename(&dev->devclass, i);
76         image = image_from_device(dev);
77         dev_instance = device_instancename(&dev->devclass, dev->index_in_device);
8578
86            node = xml_add_child(parentnode, "device", NULL);
87            if (node)
88            {
89               xml_set_attribute(node, "instance", dev_instance);
90               xml_set_attribute(node, "directory", image_working_directory(image));
91            }
79         node = xml_add_child(parentnode, "device", NULL);
80         if (node != NULL)
81         {
82            xml_set_attribute(node, "instance", dev_instance);
83            xml_set_attribute(node, "directory", image_working_directory(image));
9284         }
9385      }
9486   }
src/mess/uimess.c
r2132r2133
2525{
2626   static int ui_toggle_key = 0;
2727
28   int id, toggled = 0;
28   int toggled = 0;
2929   const struct IODevice *dev;
3030
3131   /* traditional MESS interface */
r2132r2133
8282   {
8383      if (dev->display != NULL)
8484      {
85         for (id = 0; id < device_count(dev->type); id++)
86         {
87            mess_image *img = image_from_devtype_and_index(dev->type, id);
88            dev->display(img);
89         }
85         mess_image *img = image_from_device(dev);
86         dev->display(img);
9087      }
9188   }
9289}
r2132r2133
103100{
104101   char *dst = buf;
105102   const struct IODevice *dev;
106   int id;
107103
108104   dst += sprintf(dst, "%s\n\n", Machine->gamedrv->description);
109105
r2132r2133
115111
116112   for (dev = mess_device_first_from_machine(Machine); dev != NULL; dev = mess_device_next(dev))
117113   {
118      for (id = 0; id < dev->count; id++)
114         mess_image *img = image_from_device(dev);
115      const char *name = image_filename(img);
116      if( name )
119117      {
120         mess_image *img = image_from_device_and_index(dev, id);
121         const char *name = image_filename(img);
122         if( name )
123         {
124            const char *base_filename;
125            const char *info;
126            char *base_filename_noextension;
118         const char *base_filename;
119         const char *info;
120         char *base_filename_noextension;
127121
128            base_filename = image_basename(img);
129            base_filename_noextension = strip_extension(base_filename);
122         base_filename = image_basename(img);
123         base_filename_noextension = strip_extension(base_filename);
130124
131            /* display device type and filename */
132            dst += sprintf(dst,"%s: %s\n", image_typename_id(img), base_filename);
125         /* display device type and filename */
126         dst += sprintf(dst,"%s: %s\n", image_typename_id(img), base_filename);
133127
134            /* display long filename, if present and doesn't correspond to name */
135            info = image_longname(img);
136            if (info && (!base_filename_noextension || mame_stricmp(info, base_filename_noextension)))
137               dst += sprintf(dst,"%s\n", info);
128         /* display long filename, if present and doesn't correspond to name */
129         info = image_longname(img);
130         if (info && (!base_filename_noextension || mame_stricmp(info, base_filename_noextension)))
131            dst += sprintf(dst,"%s\n", info);
138132
139            /* display manufacturer, if available */
140            info = image_manufacturer(img);
141            if (info)
142            {
143               dst += sprintf(dst,"%s", info);
144               info = stripspace(image_year(img));
145               if (info && *info)
146                  dst += sprintf(dst,", %s", info);
147               dst += sprintf(dst,"\n");
148            }
149
150            /* display playable information, if available */
151            info = image_playable(img);
152            if (info)
153               dst += sprintf(dst,"%s\n", info);
154
155            if (base_filename_noextension)
156               free(base_filename_noextension);
157         }
158         else
133         /* display manufacturer, if available */
134         info = image_manufacturer(img);
135         if (info)
159136         {
160            dst += sprintf(dst,"%s: ---\n", image_typename_id(img));
137            dst += sprintf(dst,"%s", info);
138            info = stripspace(image_year(img));
139            if (info && *info)
140               dst += sprintf(dst,", %s", info);
141            dst += sprintf(dst,"\n");
161142         }
143
144         /* display playable information, if available */
145         info = image_playable(img);
146         if (info)
147            dst += sprintf(dst,"%s\n", info);
148
149         if (base_filename_noextension)
150            free(base_filename_noextension);
162151      }
152      else
153      {
154         dst += sprintf(dst,"%s: ---\n", image_typename_id(img));
155      }
163156   }
164157   return dst - buf;
165158}
src/mess/mess.c
r2132r2133
109109void devices_init(running_machine *machine)
110110{
111111   const struct IODevice *dev;
112   int id;
113112   int result = INIT_FAIL;
114113   const char *image_name;
115114   mess_image *image;
r2132r2133
129128   /* make sure that any required devices have been allocated */
130129   for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev))
131130   {
132      for (id = 0; id < dev->count; id++)
131      /* identify the image */
132      image = image_from_device(dev);
133
134      /* is an image specified for this image */
135      image_name = mess_get_device_option(&dev->devclass, dev->index_in_device);
136      if ((image_name != NULL) && (image_name[0] != '\0'))
133137      {
134         /* identify the image */
135         image = image_from_device_and_index(dev, id);
138         /* try to load this image */
139         result = image_load(image, image_name);
136140
137         /* is an image specified for this image */
138         image_name = mess_get_device_option(&dev->devclass, id);
139         if ((image_name != NULL) && (image_name[0] != '\0'))
141         /* did the image load fail? */
142         if (result)
140143         {
141            /* try to load this image */
142            result = image_load(image, image_name);
143
144            /* did the image load fail? */
145            if (result)
146            {
147               fatalerror_exitcode(MAMERR_DEVICE, "Device %s load (%s) failed: %s\n",
148                  device_typename(dev->type),
149                  osd_basename((char *) image_name),
150                  image_error(image));
151            }
144            fatalerror_exitcode(MAMERR_DEVICE, "Device %s load (%s) failed: %s\n",
145               device_typename(dev->type),
146               osd_basename((char *) image_name),
147               image_error(image));
152148         }
153         else
149      }
150      else
151      {
152         /* no image... must this device be loaded? */
153         if (dev->must_be_loaded)
154154         {
155            /* no image... must this device be loaded? */
156            if (dev->must_be_loaded)
157            {
158               fatalerror_exitcode(MAMERR_DEVICE, "Driver requires that device %s must have an image to load\n", device_typename(dev->type));
159            }
155            fatalerror_exitcode(MAMERR_DEVICE, "Driver requires that device %s must have an image to load\n", device_typename(dev->type));
160156         }
161157      }
162158   }
src/mess/image.c
r2132r2133
109109int image_init(running_machine *machine)
110110{
111111   int err;
112   int count, indx, j;
112   int count, indx;
113113   UINT32 mask, dev_mask = 0;
114114   const struct IODevice *dev;
115115
r2132r2133
121121   count = 0;
122122   for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev))
123123   {
124      /* check to see if this device type is used multiple times */
125      mask = 1 << dev->type;
126      if (dev_mask & mask)
127         multiple_dev_mask |= mask;
128      else
129         dev_mask |= mask;
124      /* weird check only relevant on the first device */
125      if (dev->index_in_device == 0)
126      {
127         /* check to see if this device type is used multiple times */
128         mask = 1 << dev->type;
129         if (dev_mask & mask)
130            multiple_dev_mask |= mask;
131         else
132            dev_mask |= mask;
133      }
130134
131135      /* increment the count */
132      count += dev->count;
136      count++;
133137   }
134138
135139   /* allocate the array */
r2132r2133
143147   indx = 0;
144148   for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev))
145149   {
146      for (j = 0; j < dev->count; j++)
147      {
148         images[indx + j].mempool = pool_alloc(memory_error);
150      images[indx].mempool = pool_alloc(memory_error);
149151
150         /* setup the device */
151         tagpool_init(&images[indx + j].tagpool);
152         images[indx + j].dev = dev;
152      /* setup the device */
153      tagpool_init(&images[indx].tagpool);
154      images[indx].dev = dev;
153155
154         if (dev->init != NULL)
155         {
156            err = dev->init(&images[indx + j]);
157            if (err != INIT_PASS)
158               return err;
159         }
160
156      if (dev->init != NULL)
157      {
158         err = dev->init(&images[indx]);
159         if (err != INIT_PASS)
160            return err;
161161      }
162      indx += dev->count;
162      indx++;
163163   }
164164
165165   add_exit_callback(machine, image_exit);
r2132r2133
174174
175175static void image_exit(running_machine *machine)
176176{
177   int j, indx;
177   int indx;
178178   mess_image *image;
179179   const struct IODevice *dev;
180180
r2132r2133
186186
187187   for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev))
188188   {
189      for (j = 0; j < dev->count; j++)
190      {
191         /* identify the image */
192         image = &images[indx + j];
189      /* identify the image */
190      image = &images[indx];
193191
194         /* call the exit handler if appropriate */
195         if (dev->exit != NULL)
196            dev->exit(image);
192      /* call the exit handler if appropriate */
193      if (dev->exit != NULL)
194         dev->exit(image);
197195
198         /* free the tagpool */
199         tagpool_exit(&images[indx + j].tagpool);
196      /* free the tagpool */
197      tagpool_exit(&images[indx].tagpool);
200198
201         /* free the working directory */
202         if (image->working_directory != NULL)
203         {
204            free(image->working_directory);
205            image->working_directory = NULL;
206         }
207
208         /* free the memory pool */
209         pool_free(image->mempool);
210         image->mempool = NULL;
199      /* free the working directory */
200      if (image->working_directory != NULL)
201      {
202         free(image->working_directory);
203         image->working_directory = NULL;
211204      }
212      indx += dev->count;
205
206      /* free the memory pool */
207      pool_free(image->mempool);
208      image->mempool = NULL;
209      indx++;
213210   }
214211}
215212
r2132r2133
746743
747744void image_unload_all(int ispreload)
748745{
749   int id;
750746   const struct IODevice *dev;
751747   mess_image *image;
752748
r2132r2133
761757   {
762758      if (dev->load_at_init == ispreload)
763759      {
764         /* all instances */
765         for (id = 0; id < dev->count; id++)
766         {
767            image = image_from_device_and_index(dev, id);
760         image = image_from_device(dev);
768761
769            /* unload this image */
770            image_unload_internal(image, TRUE);
771         }
762         /* unload this image */
763         image_unload_internal(image, TRUE);
772764      }
773765   }
774766}
r2132r2133
1002994
1003995int image_slotexists(mess_image *img)
1004996{
1005   return image_index_in_device(img) < image_device(img)->count;
997   return TRUE;
1006998}
1007999
10081000
r2132r2133
15941586  type/id.
15951587****************************************************************************/
15961588
1597mess_image *image_from_device_and_index(const struct IODevice *device, int id)
1589mess_image *image_from_device(const struct IODevice *device)
15981590{
15991591   int indx;
16001592   mess_image *image = NULL;
16011593   const struct IODevice *dev;
16021594
1603   assert(id < device->count);
16041595   assert(images);
16051596
16061597   indx = 0;
r2132r2133
16081599   {
16091600      if (device == dev)
16101601      {
1611         image = &images[indx + id];
1602         image = &images[indx];
16121603         break;
16131604      }
1614      indx += dev->count;
1605      indx++;
16151606   }
16161607
16171608   assert(image != NULL);
r2132r2133
16251616   int indx;
16261617   mess_image *image = NULL;
16271618   const struct IODevice *dev;
1619   int device_index;
16281620
16291621   indx = 0;
1622   device_index = 0;
16301623   for (dev = mess_device_first_from_machine(Machine); dev != NULL; dev = mess_device_next(dev))
16311624   {
1632      if (dev->tag && !strcmp(dev->tag, devtag))
1625      if (dev->tag && !strcmp(dev->tag, devtag) && (device_index++ == id))
16331626      {
1634         image = &images[indx + id];
1627         image = &images[indx];
16351628         break;
16361629      }
1637      indx += dev->count;
1630      indx++;
16381631   }
16391632
1640   assert(image);
1633   assert(image != NULL);
16411634   return image;
16421635}
16431636
r2132r2133
16481641   int indx;
16491642   mess_image *image = NULL;
16501643   const struct IODevice *dev;
1644   int device_index;
16511645
16521646   assert((multiple_dev_mask & (1 << type)) == 0);
16531647   assert(id < device_count(type));
16541648
16551649   indx = 0;
1650   device_index = 0;
16561651   for (dev = mess_device_first_from_machine(Machine); dev != NULL; dev = mess_device_next(dev))
16571652   {
1658      if (type == dev->type)
1653      if ((type == dev->type) && (device_index++ == id))
16591654      {
1660         image = &images[indx + id];
1655         image = &images[indx];
16611656         break;
16621657      }
1663      indx += dev->count;
1658      indx++;
16641659   }
16651660
16661661   assert(image);
r2132r2133
16781673
16791674int image_index_in_device(mess_image *img)
16801675{
1681   int indx;
1682
16831676   assert(img);
1684   indx = img - image_from_device_and_index(img->dev, 0);
1685
1686   assert(indx >= 0);
1687   assert(indx < img->dev->count);
1688   return indx;
1677   return img->dev->index_in_device;
16891678}
src/mess/infomess.c
r2132r2133
3232   const struct IODevice *iodev;
3333   const char *name;
3434   const char *shortname;
35   int id;
3635
3736   for (dev = device_list_first(config->devicelist, MESS_DEVICE); dev != NULL; dev = device_list_next(dev, MESS_DEVICE))
3837   {
r2132r2133
5251      /* close the XML tag */
5352      fprintf(out, ">\n");
5453
55      for (id = 0; id < iodev->count; id++)
56      {
57         name = device_instancename(&iodev->devclass, id);
58         shortname = device_briefinstancename(&iodev->devclass, id);
54      name = device_instancename(&iodev->devclass, iodev->index_in_device);
55      shortname = device_briefinstancename(&iodev->devclass, iodev->index_in_device);
5956
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      }
57      fprintf(out, "\t\t\t<instance");
58      fprintf(out, " name=\"%s\"", xml_normalize_string(name));
59      fprintf(out, " briefname=\"%s\"", xml_normalize_string(shortname));
60      fprintf(out, "/>\n");
6561
6662      if (iodev->file_extensions)
6763      {
src/mess/image.h
r2132r2133
194194****************************************************************************/
195195
196196int image_index_in_device(mess_image *img);
197mess_image *image_from_device_and_index(const struct IODevice *dev, int id);
197mess_image *image_from_device(const struct IODevice *dev);
198198mess_image *image_from_devtag_and_index(const char *devtag, int id);
199199
200200/* deprecated; as there can be multiple devices of a certain type */
src/mess/device.c
r2132r2133
180180   }
181181
182182   name = device_uiname(dev->type);
183   if (dev->count > 1)
183   if (dev->multiple)
184184   {
185185      /* for the average user counting starts at #1 ;-) */
186186      snprintf(buf, bufsize, "%s #%d", name, id + 1);
r2132r2133
293293   int count_override, int *position)
294294{
295295   mess_device_class mess_devclass;
296   const char *tag;
296   const char *mess_tag;
297   const char *mame_tag;
297298   const char *info_string;
298299   char dynamic_tag[32];
299300   device_config *device;
300301   mess_device_config *mess_device;
301302   const char *file_extensions;
302   int j;
303   int i, j, count;
303304   size_t string_buffer_pos = 0;
304305   int createimage_optcount;
305306
r2132r2133
307308   mess_devclass.get_info = handler;
308309   mess_devclass.gamedrv = gamedrv;
309310
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;
311   /* determine device count */
312   count = mess_device_get_info_int(&mess_devclass, MESS_DEVINFO_INT_COUNT);
322313
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)
314   /* create one MAME device for each of these */
315   for (i = 0; i < count; i++)
326316   {
327      const char *file_extensions_copy = &mess_device->string_buffer[string_buffer_pos];
328
329      /* copy the file extensions over to the buffer */
330      for (j = 0; file_extensions[j] != '\0'; j++)
317      /* determine the tag */
318      mess_tag = mess_device_get_info_string(&mess_devclass, MESS_DEVINFO_STR_DEV_TAG);
319      if (mess_tag != NULL)
331320      {
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');
321         snprintf(dynamic_tag, ARRAY_LENGTH(dynamic_tag), "%s_%d", mess_tag, i);
322         mame_tag = dynamic_tag;
334323      }
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');
324      else
325      {
326         /* create a default tag */
327         snprintf(dynamic_tag, ARRAY_LENGTH(dynamic_tag), "mess_device_%d", *position);
328         mame_tag = dynamic_tag;
329      }
330     
331      /* create a bonafide MAME device */
332      device = device_list_add(listheadptr, MESS_DEVICE, mame_tag);
333      mess_device = (mess_device_config *) device->inline_config;
337334
338      file_extensions = file_extensions_copy;
339   }
335      /* convert file extensions from comma delimited to null delimited */
336      file_extensions = mess_device_get_info_string(&mess_devclass, MESS_DEVINFO_STR_FILE_EXTENSIONS);
337      if (file_extensions != NULL)
338      {
339         const char *file_extensions_copy = &mess_device->string_buffer[string_buffer_pos];
340340
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;
341         /* copy the file extensions over to the buffer */
342         for (j = 0; file_extensions[j] != '\0'; j++)
343         {
344            string_buffer_putc(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos,
345               (file_extensions[j] != ',') ? file_extensions[j] : '\0');
346         }
347         string_buffer_putc(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos, '\0');
348         string_buffer_putc(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos, '\0');
349349
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;
350         file_extensions = file_extensions_copy;
351      }
356352
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);
353      /* populate the legacy MESS device */
354      mess_device->io_device.tag               = mess_tag;
355      mess_device->io_device.devconfig         = device;
356      mess_device->io_device.devclass            = mess_devclass;
357      mess_device->io_device.type               = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_TYPE);
358      mess_device->io_device.position            = *position;
359      mess_device->io_device.index_in_device      = i;
360      mess_device->io_device.file_extensions      = file_extensions;
365361
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;
362      mess_device->io_device.readable            = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_READABLE) ? 1 : 0;
363      mess_device->io_device.writeable         = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_WRITEABLE) ? 1 : 0;
364      mess_device->io_device.creatable         = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_CREATABLE) ? 1 : 0;
365      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;
366      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;
367      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;
368368
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);
369      mess_device->io_device.init               = (device_init_handler) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_INIT);
370      mess_device->io_device.exit               = (device_exit_handler) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_EXIT);
371      mess_device->io_device.load               = (device_load_handler) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_LOAD);
372      mess_device->io_device.create            = (device_create_handler) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE);
373      mess_device->io_device.unload            = (device_unload_handler) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_UNLOAD);
374      mess_device->io_device.imgverify         = (device_verify_handler) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_VERIFY);
375      mess_device->io_device.partialhash         = (device_partialhash_handler) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_PARTIAL_HASH);
376      mess_device->io_device.getdispositions      = (device_getdispositions_handler) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_GET_DISPOSITIONS);
370377
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");
378      mess_device->io_device.display            = (device_display_handler) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_DISPLAY);
379      mess_device->io_device.name               = default_device_name;
376380
377      /* set up each option in the list */
378      for (j = 0; j < createimage_optcount; j++)
381      mess_device->io_device.createimage_optguide   = (const struct OptionGuide *) mess_device_get_info_ptr(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE_OPTGUIDE);
382
383      createimage_optcount = (int) mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_CREATE_OPTCOUNT);
384      if (createimage_optcount > 0)
379385      {
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);
386         if (createimage_optcount > MESS_DEVINFO_CREATE_OPTMAX)
387            fatalerror("MESS_DEVINFO_INT_CREATE_OPTCOUNT: Too many options");
382388
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);
389         /* set up each option in the list */
390         for (j = 0; j < createimage_optcount; j++)
391         {
392            info_string = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_CREATE_OPTNAME + j);
393            mess_device->createimage_options[j].name      = string_buffer_putstr(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos, info_string);
394
395            info_string = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_CREATE_OPTDESC + j);
396            mess_device->createimage_options[j].description   = string_buffer_putstr(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos, info_string);
397           
398            info_string = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_CREATE_OPTEXTS + j);
399            mess_device->createimage_options[j].extensions   = string_buffer_putstr(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos, info_string);
400           
401            mess_device->createimage_options[j].optspec      = mess_device_get_info_ptr(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE_OPTSPEC + j);
402         }
403
404         /* terminate the list */
405         memset(&mess_device->createimage_options[createimage_optcount], 0, sizeof(mess_device->createimage_options[createimage_optcount]));
390406      }
391407
392      /* terminate the list */
393      memset(&mess_device->createimage_options[createimage_optcount], 0, sizeof(mess_device->createimage_options[createimage_optcount]));
394   }
408      (*position)++;
395409
396   *position += mess_device->io_device.count;
410      /* overriding the count? */
411      //if (count_override != 0)
412      //   mess_device->io_device.count = count_override;
397413
398   /* overriding the count? */
399   if (count_override != 0)
400      mess_device->io_device.count = count_override;
414      /* any problems? */
415      assert((mess_device->io_device.type >= 0) && (mess_device->io_device.type < IO_COUNT));
401416
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;
417      /* fill in defaults */
418      if (!mess_device->io_device.getdispositions)
419         mess_device->io_device.getdispositions = default_device_getdispositions;
420   }
409421}
410422
411423
r2132r2133
498510
499511int device_count_tag_from_machine(const running_machine *machine, const char *tag)
500512{
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;
513   int count = 0;
514   const device_config *device;
515
516   for (device = device_list_first(machine->config->devicelist, MESS_DEVICE); device != NULL; device = device_list_next(device, MESS_DEVICE))
517   {
518      const struct IODevice *iodev = mess_device_from_core_device(device);
519      if (!strcmp(tag, iodev->tag))
520      {
521         count++;
522      }
523   }
524   return count;
504525}
505526
506527
r2132r2133
526547/* this function is deprecated */
527548int device_count(iodevice_t type)
528549{
529   const struct IODevice *iodev = device_find_from_machine(Machine, type);
530   return (iodev != NULL) ? iodev->count : 0;
550   int count = 0;
551   const device_config *device;
552
553   for (device = device_list_first(Machine->config->devicelist, MESS_DEVICE); device != NULL; device = device_list_next(device, MESS_DEVICE))
554   {
555      const struct IODevice *iodev = mess_device_from_core_device(device);
556      if (iodev->type == type)
557      {
558         count++;
559      }
560   }
561   return count;
531562}
532563
533564
src/mess/filemngr.c
r2132r2133
638638   const char *name;
639639   ui_menu_item menu_items[40];
640640   const struct IODevice *devices[40];
641   int ids[40];
642641   char names[40][64];
643   int sel, total, arrowize, id;
642   int sel, total, arrowize;
644643   const struct IODevice *dev;
645644   mess_image *image;
646645
r2132r2133
650649   /* Cycle through all devices for this system */
651650   for (dev = mess_device_first_from_machine(Machine); dev != NULL; dev = mess_device_next(dev))
652651   {
653      for (id = 0; id < dev->count; id++)
654      {
655         image = image_from_device_and_index(dev, id);
656         strcpy( names[total], image_typename_id(image) );
657         name = image_filename(image);
652      image = image_from_device(dev);
653      strcpy( names[total], image_typename_id(image) );
654      name = image_filename(image);
658655
659         memset(&menu_items[total], 0, sizeof(menu_items[total]));
660         menu_items[total].text = (names[total]) ? names[total] : "---";
661         menu_items[total].subtext = (name) ? name : "---";
656      memset(&menu_items[total], 0, sizeof(menu_items[total]));
657      menu_items[total].text = (names[total]) ? names[total] : "---";
658      menu_items[total].subtext = (name) ? name : "---";
662659
663         devices[total] = dev;
664         ids[total] = id;
665
666         total++;
667      }
660      devices[total] = dev;
661     
662      total++;
668663   }
669664
670665
671666   /* if the fileselect() mode is active */
672667   if (sel & (2 << SEL_BITS))
673668   {
674      image = image_from_device_and_index(devices[previous_sel & SEL_MASK], ids[previous_sel & SEL_MASK]);
669      image = image_from_device(devices[previous_sel & SEL_MASK]);
675670      sel = fileselect(selected & ~(2 << SEL_BITS), image_filename(image), image_working_directory(image));
676671      if (sel != 0 && sel != -1 && sel!=-2)
677672         return sel | (2 << SEL_BITS);
r2132r2133
684679         previous_sel = previous_sel & SEL_MASK;
685680
686681         /* attempt a filename change */
687         image = image_from_device_and_index(devices[previous_sel], ids[previous_sel]);
682         image = image_from_device(devices[previous_sel]);
688683         if (entered_filename[0])
689684            image_load(image, entered_filename);
690685         else
r2132r2133
721716      {
722717         /* yes */
723718         sel &= SEL_MASK;
724         image = image_from_device_and_index(devices[sel], ids[sel]);
719         image = image_from_device(devices[sel]);
725720         image_load(image, NULL);
726721      }
727722
r2132r2133
751746      /* no, let the osd code have a crack at changing files */
752747      else
753748      {
754         image = image_from_device_and_index(devices[sel], ids[sel]);
749         image = image_from_device(devices[sel]);
755750         os_sel = 0;
756751      }
757752
src/mess/device.h
r2132r2133
244244   const char *tag;
245245   iodevice_t type;
246246   int position;
247   int count;
247   int index_in_device;
248248   const char *file_extensions;
249249
250250   /* open dispositions */
r2132r2133
256256   unsigned int reset_on_load : 1;
257257   unsigned int must_be_loaded : 1;
258258   unsigned int load_at_init : 1;
259   unsigned int multiple : 1;
259260
260261   /* image handling callbacks */
261262   device_init_handler init;
src/mess/osd/windows/menu.c
r2132r2133
13471347   // then set up the actual devices
13481348   for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev))
13491349   {
1350      for (i = 0; i < dev->count; i++)
1351      {
1352         img = image_from_device_and_index(dev, i);
1350      img = image_from_device(dev);
13531351
1354         new_item = ID_DEVICE_0 + (image_absolute_index(img) * DEVOPTION_MAX);
1355         flags_for_exists = MF_STRING;
1352      new_item = ID_DEVICE_0 + (image_absolute_index(img) * DEVOPTION_MAX);
1353      flags_for_exists = MF_STRING;
13561354
1357         if (!image_exists(img))
1358            flags_for_exists |= MF_GRAYED;
1355      if (!image_exists(img))
1356         flags_for_exists |= MF_GRAYED;
13591357
1360         flags_for_writing = flags_for_exists;
1361         if (!image_is_writable(img))
1362            flags_for_writing |= MF_GRAYED;
1358      flags_for_writing = flags_for_exists;
1359      if (!image_is_writable(img))
1360         flags_for_writing |= MF_GRAYED;
13631361
1364         sub_menu = CreateMenu();
1365         append_menu_uistring(sub_menu, MF_STRING,      new_item + DEVOPTION_OPEN,      UI_mount);
1362      sub_menu = CreateMenu();
1363      append_menu_uistring(sub_menu, MF_STRING,      new_item + DEVOPTION_OPEN,      UI_mount);
13661364
1367         if (dev->creatable)
1368            append_menu_uistring(sub_menu, MF_STRING,   new_item + DEVOPTION_CREATE,   UI_create);
1365      if (dev->creatable)
1366         append_menu_uistring(sub_menu, MF_STRING,   new_item + DEVOPTION_CREATE,   UI_create);
13691367
1370         append_menu_uistring(sub_menu, flags_for_exists,   new_item + DEVOPTION_CLOSE,   UI_unmount);
1368      append_menu_uistring(sub_menu, flags_for_exists,   new_item + DEVOPTION_CLOSE,   UI_unmount);
13711369
13721370#if HAS_WAVE
1373         if ((dev->type == IO_CASSETTE) && !strcmp(dev->file_extensions, "wav"))
1374         {
1375            cassette_state state;
1376            state = image_exists(img) ? (cassette_get_state(img) & CASSETTE_MASK_UISTATE) : CASSETTE_STOPPED;
1377            append_menu_uistring(sub_menu, MF_SEPARATOR, 0, -1);
1378            append_menu_uistring(sub_menu, flags_for_exists   | ((state == CASSETTE_STOPPED)   ? MF_CHECKED : 0),   new_item + DEVOPTION_CASSETTE_STOPPAUSE,   UI_pauseorstop);
1379            append_menu_uistring(sub_menu, flags_for_exists   | ((state == CASSETTE_PLAY)      ? MF_CHECKED : 0),   new_item + DEVOPTION_CASSETTE_PLAY,         UI_play);
1380            append_menu_uistring(sub_menu, flags_for_writing   | ((state == CASSETTE_RECORD)   ? MF_CHECKED : 0),   new_item + DEVOPTION_CASSETTE_RECORD,      UI_record);
1371      if ((dev->type == IO_CASSETTE) && !strcmp(dev->file_extensions, "wav"))
1372      {
1373         cassette_state state;
1374         state = image_exists(img) ? (cassette_get_state(img) & CASSETTE_MASK_UISTATE) : CASSETTE_STOPPED;
1375         append_menu_uistring(sub_menu, MF_SEPARATOR, 0, -1);
1376         append_menu_uistring(sub_menu, flags_for_exists   | ((state == CASSETTE_STOPPED)   ? MF_CHECKED : 0),   new_item + DEVOPTION_CASSETTE_STOPPAUSE,   UI_pauseorstop);
1377         append_menu_uistring(sub_menu, flags_for_exists   | ((state == CASSETTE_PLAY)      ? MF_CHECKED : 0),   new_item + DEVOPTION_CASSETTE_PLAY,         UI_play);
1378         append_menu_uistring(sub_menu, flags_for_writing   | ((state == CASSETTE_RECORD)   ? MF_CHECKED : 0),   new_item + DEVOPTION_CASSETTE_RECORD,      UI_record);
13811379#if USE_TAPEDLG
1382            append_menu_uistring(sub_menu, flags_for_exists,                                          new_item + DEVOPTION_CASSETTE_DIALOG,      UI_tapecontrol);
1380         append_menu_uistring(sub_menu, flags_for_exists,                                          new_item + DEVOPTION_CASSETTE_DIALOG,      UI_tapecontrol);
13831381#else
1384            append_menu_uistring(sub_menu, flags_for_exists,                                          new_item + DEVOPTION_CASSETTE_REWIND,      UI_rewind);
1385            append_menu_uistring(sub_menu, flags_for_exists,                                          new_item + DEVOPTION_CASSETTE_FASTFORWARD,   UI_fastforward);
1382         append_menu_uistring(sub_menu, flags_for_exists,                                          new_item + DEVOPTION_CASSETTE_REWIND,      UI_rewind);
1383         append_menu_uistring(sub_menu, flags_for_exists,                                          new_item + DEVOPTION_CASSETTE_FASTFORWARD,   UI_fastforward);
13861384#endif
1387         }
1385      }
13881386#endif /* HAS_WAVE */
1389         s = image_exists(img) ? image_filename(img) : ui_getstring(UI_emptyslot);
1390         flags = MF_POPUP;
1387      s = image_exists(img) ? image_filename(img) : ui_getstring(UI_emptyslot);
1388      flags = MF_POPUP;
13911389
1392         snprintf(buf, sizeof(buf) / sizeof(buf[0]), "%s: %s", image_typename_id(img), s);
1393         append_menu_utf8(device_menu, flags, (UINT_PTR) sub_menu, buf);
1394      }
1390      snprintf(buf, sizeof(buf) / sizeof(buf[0]), "%s: %s", image_typename_id(img), s);
1391      append_menu_utf8(device_menu, flags, (UINT_PTR) sub_menu, buf);
13951392   }
13961393}
13971394
src/mess/osd/winui/messui.c
r2132r2133
378378   machine_config *config;
379379   const device_config *dev;
380380   const struct IODevice *iodev;
381   int i, nPos;
381   int nPos;
382382   char szMessage[256];
383383   LPCSTR pszSoftware;
384384   BOOL bResult = FALSE;
r2132r2133
396396      // confirm any mandatory devices are loaded
397397      if (iodev->must_be_loaded)
398398      {
399         for (i = 0; i < iodev->count; i++)
399         pszSoftware = GetSelectedSoftware(drvindex, &iodev->devclass, iodev->index_in_device);
400         if (!pszSoftware || !*pszSoftware)
400401         {
401            pszSoftware = GetSelectedSoftware(drvindex, &iodev->devclass, i);
402            if (!pszSoftware || !*pszSoftware)
403            {
404               snprintf(szMessage, sizeof(szMessage) / sizeof(szMessage[0]),
405                  "System '%s' requires that device %s must have an image to load\n",
406                  drivers[drvindex]->description,
407                  device_typename(iodev->type));
408               goto done;
409            }
402            snprintf(szMessage, sizeof(szMessage) / sizeof(szMessage[0]),
403               "System '%s' requires that device %s must have an image to load\n",
404               drivers[drvindex]->description,
405               device_typename(iodev->type));
406            goto done;
410407         }
411408      }
412409
413      nPos += iodev->count;
410      nPos++;
414411   }
415412   bResult = TRUE;
416413
r2132r2133
448445   const device_config *dev;
449446   const struct IODevice *iodev = NULL;
450447   const char *s;
451   int i;
452448
453449   // allocate the machine config
454450   config = machine_config_alloc_with_mess_devices(drivers[drvindex]);
r2132r2133
469465   if (nID < 0)
470466   {
471467      // special case; first try to find existing image
472      for (i = 0; i < iodev->count; i++)
468      s = GetSelectedSoftware(drvindex, &iodev->devclass, iodev->index_in_device);
469      if (s && !mame_stricmp(s, pszFilename))
473470      {
474         s = GetSelectedSoftware(drvindex, &iodev->devclass, i);
475         if (s && !mame_stricmp(s, pszFilename))
476         {
477            nID = i;
478            break;
479         }
471         nID = iodev->index_in_device;
480472      }
481473   }
482474
483475   if (nID < 0)
484476   {
485477      // still not found?  locate an empty slot
486      for (i = 0; i < iodev->count; i++)
478      s = GetSelectedSoftware(drvindex, &iodev->devclass, iodev->index_in_device);
479      if (!s || !*s || !mame_stricmp(s, pszFilename))
487480      {
488         s = GetSelectedSoftware(drvindex, &iodev->devclass, i);
489         if (!s || !*s || !mame_stricmp(s, pszFilename))
490         {
491            nID = i;
492            break;
493         }
481         nID = iodev->index_in_device;
494482      }
495483   }
496484
r2132r2133
506494
507495static void MessRemoveImage(int drvindex, mess_device_class devclass, LPCSTR pszFilename)
508496{
509   int i, nPos;
497   int nPos;
510498   machine_config *config;
511499   const device_config *dev;
512500   const struct IODevice *iodev = NULL;
r2132r2133
523511
524512         if (iodev->devclass.get_info == devclass.get_info)
525513            break;
526         nPos += iodev->count;
514         nPos++;
527515      }
528516
529517      if (iodev != NULL)
530518      {
531         for (i = 0; i < iodev->count; i++)
519         if (!mame_stricmp(pszFilename, GetSelectedSoftware(drvindex, &iodev->devclass, iodev->index_in_device)))
532520         {
533            if (!mame_stricmp(pszFilename, GetSelectedSoftware(drvindex, &iodev->devclass, i)))
534            {
535               MessSpecifyImage(drvindex, &devclass, i, NULL);
536               break;
537            }
521            MessSpecifyImage(drvindex, &devclass, iodev->index_in_device, NULL);
538522         }
539523      }
540524
r2132r2133
558542static void MessRefreshPicker(int drvindex)
559543{
560544   HWND hwndSoftware;
561   int i, id;
545   int i;
562546   LVFINDINFO lvfi;
563547   machine_config *config;
564548   const device_config *dev;
r2132r2133
580564   {
581565      iodev = mess_device_from_core_device(dev);
582566
583      for (id = 0; id < iodev->count; id++)
567      pszSoftware = GetSelectedSoftware(drvindex, &iodev->devclass, iodev->index_in_device);
568      if (pszSoftware && *pszSoftware)
584569      {
585         pszSoftware = GetSelectedSoftware(drvindex, &iodev->devclass, id);
586         if (pszSoftware && *pszSoftware)
570         i = SoftwarePicker_LookupIndex(hwndSoftware, pszSoftware);
571         if (i < 0)
587572         {
573            SoftwarePicker_AddFile(hwndSoftware, pszSoftware);
588574            i = SoftwarePicker_LookupIndex(hwndSoftware, pszSoftware);
589            if (i < 0)
590            {
591               SoftwarePicker_AddFile(hwndSoftware, pszSoftware);
592               i = SoftwarePicker_LookupIndex(hwndSoftware, pszSoftware);
593            }
594            if (i >= 0)
595            {
596               memset(&lvfi, 0, sizeof(lvfi));
597               lvfi.flags = LVFI_PARAM;
598               lvfi.lParam = i;
599               i = ListView_FindItem(hwndSoftware, -1, &lvfi);
600               ListView_SetItemState(hwndSoftware, i, LVIS_SELECTED, LVIS_SELECTED);
601            }
602575         }
576         if (i >= 0)
577         {
578            memset(&lvfi, 0, sizeof(lvfi));
579            lvfi.flags = LVFI_PARAM;
580            lvfi.lParam = i;
581            i = ListView_FindItem(hwndSoftware, -1, &lvfi);
582            ListView_SetItemState(hwndSoftware, i, LVIS_SELECTED, LVIS_SELECTED);
583         }
603584      }
604585   }
605586
src/mess/osd/winui/devview.c
r2132r2133
3939struct DevViewEntry
4040{
4141   const struct IODevice *dev;
42   int id;
4342   HWND hwndStatic;
4443   HWND hwndEdit;
4544   HWND hwndBrowseButton;
r2132r2133
126125            hwndDevView,
127126            pDevViewInfo->nGame,
128127            pDevViewInfo->pEntries[i].dev,
129            pDevViewInfo->pEntries[i].id,
128            pDevViewInfo->pEntries[i].dev->index_in_device,
130129            szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
131130
132131         if (!pszSelection)
r2132r2133
151150      pDevViewInfo->pCallbacks->pfnSetSelectedSoftware(hwndDevView,
152151         pDevViewInfo->nGame,
153152         pDevViewInfo->pEntries[nChangedEntry].dev,
154         pDevViewInfo->pEntries[nChangedEntry].id,
153         pDevViewInfo->pEntries[nChangedEntry].dev->index_in_device,
155154         pszFilename);
156155   }
157156}
r2132r2133
190189   const device_config *dev;
191190   const struct IODevice *iodev;
192191   struct DevViewEntry *pEnt;
193   int i, id;
192   int i;
194193   int y, nHeight, nDevCount;
195194   int nStaticPos, nStaticWidth, nEditPos, nEditWidth, nButtonPos, nButtonWidth;
196195   HDC hDc;
r2132r2133
217216   for (dev = device_list_first(pDevViewInfo->config->devicelist, MESS_DEVICE); dev != NULL; dev = device_list_next(dev, MESS_DEVICE))
218217   {
219218      iodev = mess_device_from_core_device(dev);
220      nDevCount += iodev->count;
219      nDevCount += 1;
221220   }
222221
223222   if (nDevCount > 0)
r2132r2133
230229      {
231230         iodev = mess_device_from_core_device(dev);
232231
233         for (id = 0; id < iodev->count; id++)
234         {
235            utf8_s = iodev->name(iodev, id, buf, sizeof(buf) / sizeof(buf[0]));
236            s = tstring_from_utf8(utf8_s);
237            ppszDevices[i] = alloca((_tcslen(s) + 1) * sizeof(TCHAR));
238            _tcscpy(ppszDevices[i], s);
239            free(s);
240            i++;
241         }
232         utf8_s = iodev->name(iodev, iodev->index_in_device, buf, sizeof(buf) / sizeof(buf[0]));
233         s = tstring_from_utf8(utf8_s);
234         ppszDevices[i] = alloca((_tcslen(s) + 1) * sizeof(TCHAR));
235         _tcscpy(ppszDevices[i], s);
236         free(s);
237         i++;
242238      }
243239
244240      // Calculate the requisite size for the device column
r2132r2133
270266      {
271267         iodev = mess_device_from_core_device(dev);
272268
273         for (id = 0; id < iodev->count; id++)
274         {
275            pEnt->dev = iodev;
276            pEnt->id = id;
269         pEnt->dev = iodev;
277270
278            pEnt->hwndStatic = win_create_window_ex_utf8(0, "STATIC", iodev->name(iodev, id, buf, sizeof(buf) / sizeof(buf[0])),
279               WS_VISIBLE | WS_CHILD, nStaticPos, y, nStaticWidth, nHeight,
280               hwndDevView, NULL, NULL, NULL);
271         pEnt->hwndStatic = win_create_window_ex_utf8(0, "STATIC", iodev->name(iodev, iodev->index_in_device, buf, sizeof(buf) / sizeof(buf[0])),
272            WS_VISIBLE | WS_CHILD, nStaticPos, y, nStaticWidth, nHeight,
273            hwndDevView, NULL, NULL, NULL);
281274
282            pEnt->hwndEdit = win_create_window_ex_utf8(0, "EDIT", "",
283               WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL, nEditPos, y, nEditWidth, nHeight,
284               hwndDevView, NULL, NULL, NULL);
275         pEnt->hwndEdit = win_create_window_ex_utf8(0, "EDIT", "",
276            WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL, nEditPos, y, nEditWidth, nHeight,
277            hwndDevView, NULL, NULL, NULL);
285278
286            pEnt->hwndBrowseButton = win_create_window_ex_utf8(0, "BUTTON", "...",
287               WS_VISIBLE | WS_CHILD, nButtonPos, y, nButtonWidth, nHeight,
288               hwndDevView, NULL, NULL, NULL);
279         pEnt->hwndBrowseButton = win_create_window_ex_utf8(0, "BUTTON", "...",
280            WS_VISIBLE | WS_CHILD, nButtonPos, y, nButtonWidth, nHeight,
281            hwndDevView, NULL, NULL, NULL);
289282
290            if (pEnt->hwndStatic)
291            {
292               SendMessage(pEnt->hwndStatic, WM_SETFONT, (WPARAM) pDevViewInfo->hFont, TRUE);
293            }
294            if (pEnt->hwndEdit)
295            {
296               SendMessage(pEnt->hwndEdit, WM_SETFONT, (WPARAM) pDevViewInfo->hFont, TRUE);
297               l = (LONG_PTR) DevView_EditWndProc;
298               l = SetWindowLongPtr(pEnt->hwndEdit, GWLP_WNDPROC, l);
299               pEnt->pfnEditWndProc = (WNDPROC) l;
300               SetWindowLongPtr(pEnt->hwndEdit, GWLP_USERDATA, (LONG_PTR) pEnt);
301            }
302            if (pEnt->hwndBrowseButton)
303            {
304               SetWindowLongPtr(pEnt->hwndBrowseButton, GWLP_USERDATA, (LONG_PTR) pEnt);
305            }
306
307            y += nHeight;
308            pEnt++;
283         if (pEnt->hwndStatic)
284         {
285            SendMessage(pEnt->hwndStatic, WM_SETFONT, (WPARAM) pDevViewInfo->hFont, TRUE);
309286         }
287         if (pEnt->hwndEdit)
288         {
289            SendMessage(pEnt->hwndEdit, WM_SETFONT, (WPARAM) pDevViewInfo->hFont, TRUE);
290            l = (LONG_PTR) DevView_EditWndProc;
291            l = SetWindowLongPtr(pEnt->hwndEdit, GWLP_WNDPROC, l);
292            pEnt->pfnEditWndProc = (WNDPROC) l;
293            SetWindowLongPtr(pEnt->hwndEdit, GWLP_USERDATA, (LONG_PTR) pEnt);
294         }
295         if (pEnt->hwndBrowseButton)
296         {
297            SetWindowLongPtr(pEnt->hwndBrowseButton, GWLP_USERDATA, (LONG_PTR) pEnt);
298         }
299
300         y += nHeight;
301         pEnt++;
310302      }
311303   }
312304

Previous 15994 Revisions Next


© 1998-2018 The MESS Team