Previous 15994 Revisions Next

r2272 Saturday 5th April, 2008 at 14:54:15 UTC by Nathan Woods
1. Created a core image_device_getinfo() API to allow code (front end or
otherwise) to get information about a device

2. [Windows GUI] Converted some code to use image_device_getinfo()
[src/mess]image.c image.h
[src/mess/osd/winui]devview.c messui.c msuiutil.c optionsms.c optionsms.h propertiesms.c softwarepicker.c

src/mess/image.c
r2271r2272
272272****************************************************************************/
273273
274274/*-------------------------------------------------
275    image_device_getinfo - returns info on a device;
276   can be called by front end code
277-------------------------------------------------*/
278
279image_device_info image_device_getinfo(const device_config *device)
280{
281   const struct IODevice *iodev;
282   const char *s;
283   image_device_info info;
284   int i;
285   
286   memset(&info, 0, sizeof(info));
287
288   iodev = mess_device_from_core_device(device);
289   if (iodev != NULL)
290   {
291      /* retrieve type */
292      info.type = iodev->type;
293
294      /* retrieve flags */
295      info.readable = iodev->readable;
296      info.writeable = iodev->writeable;
297      info.creatable = iodev->creatable;
298      info.must_be_loaded = iodev->must_be_loaded;
299      info.uses_partial_hash = iodev->partialhash != NULL;
300
301      /* retrieve name */
302      s = (*iodev->name)(iodev, iodev->index_in_device, info.name, ARRAY_LENGTH(info.name));
303      if (s != info.name)
304         snprintf(info.name, ARRAY_LENGTH(info.name), "%s", s);
305
306      /* retrieve file extensions */
307      for(i = 0; iodev->file_extensions[i] != '\0'; i += strlen(&iodev->file_extensions[i]) + 1)
308         ;
309      memcpy(info.file_extensions, iodev->file_extensions, i * sizeof(info.file_extensions[0]));
310
311      /* retrieve instance name */
312      s = device_instancename(&iodev->devclass, iodev->index_in_device);
313      snprintf(info.instance_name, ARRAY_LENGTH(info.instance_name), "%s", s);
314
315      /* retrieve brief instance name */
316      s = device_briefinstancename(&iodev->devclass, iodev->index_in_device);
317      snprintf(info.brief_instance_name, ARRAY_LENGTH(info.brief_instance_name), "%s", s);
318   }
319
320   return info;
321}
322
323
324
325/*-------------------------------------------------
275326    image_device_uses_file_extension - checks to
276327   see if a particular devices uses a certain
277328   file extension
src/mess/image.h
r2271r2272
5757   IMAGE_ERROR_UNSPECIFIED
5858} image_error_t;
5959
60typedef struct _image_device_info image_device_info;
61struct _image_device_info
62{
63   iodevice_t type : 8;
64   unsigned int readable : 1;
65   unsigned int writeable : 1;
66   unsigned int creatable : 1;
67   unsigned int must_be_loaded : 1;
68   unsigned int uses_partial_hash : 1;
69   char name[62];
70   char file_extensions[32];
71   char instance_name[32];
72   char brief_instance_name[16];
73};
74
6075struct _images_private;
6176typedef struct _images_private images_private;
6277
r2271r2272
99114
100115/* ----- analysis ----- */
101116
117/* returns info on a device - can be called by front end code */
118image_device_info image_device_getinfo(const device_config *device);
119
102120/* checks to see if a particular devices uses a certain file extension */
103121int image_device_uses_file_extension(const device_config *device, const char *file_extension);
104122
src/mess/osd/winui/optionsms.h
r2271r2272
33
44#include "mame.h"
55#include "image.h"
6#include "device.h"
76#include "options.h"
87
98enum
src/mess/osd/winui/messui.c
r2271r2272
377377{
378378   machine_config *config;
379379   const device_config *dev;
380   const struct IODevice *iodev;
381380   int nPos;
382381   char szMessage[256];
383382   LPCSTR pszSoftware;
r2271r2272
391390   nPos = 0;
392391   for (dev = image_device_first(config); dev != NULL; dev = image_device_next(dev))
393392   {
394      iodev = mess_device_from_core_device(dev);
393      image_device_info info = image_device_getinfo(dev);
395394
396395      // confirm any mandatory devices are loaded
397      if (iodev->must_be_loaded)
396      if (info.must_be_loaded)
398397      {
399398         pszSoftware = GetSelectedSoftware(drvindex, dev);
400399         if (!pszSoftware || !*pszSoftware)
r2271r2272
402401            snprintf(szMessage, sizeof(szMessage) / sizeof(szMessage[0]),
403402               "System '%s' requires that device %s must have an image to load\n",
404403               drivers[drvindex]->description,
405               device_typename(iodev->type));
404               device_typename(info.type));
406405            goto done;
407406         }
408407      }
r2271r2272
523522   LVFINDINFO lvfi;
524523   machine_config *config;
525524   const device_config *dev;
526   const struct IODevice *iodev;
527525   LPCSTR pszSoftware;
528526
529527   hwndSoftware = GetDlgItem(GetMainWindow(), IDC_SWLIST);
r2271r2272
539537
540538   for (dev = image_device_first(config); dev != NULL; dev = image_device_next(dev))
541539   {
542      iodev = mess_device_from_core_device(dev);
543
544540      pszSoftware = GetSelectedSoftware(drvindex, dev);
545541      if (pszSoftware && *pszSoftware)
546542      {
r2271r2272
606602
607603typedef struct
608604{
609   const struct IODevice *dev;
605   const device_config *dev;
610606    const char *ext;
611607} mess_image_type;
612608
r2271r2272
652648      if (!imagetypes[i].dev)
653649         typname = "Compressed images";
654650      else
655         typname = lookupdevice(imagetypes[i].dev->type)->dlgname;
651         typname = lookupdevice(image_device_getinfo(imagetypes[i].dev).type)->dlgname;
656652
657653        strcpy(s, typname);
658654        s += strlen(s);
r2271r2272
736732      /* special case; all non-printer devices */
737733      for (dev = image_device_first(config); dev != NULL; dev = image_device_next(dev))
738734      {
739         const struct IODevice *iodev = mess_device_from_core_device(dev);
735         image_device_info info = image_device_getinfo(dev);
740736
741         if (iodev->type != IO_PRINTER)
737         if (info.type != IO_PRINTER)
742738            SetupImageTypes(config, &types[num_extensions], count - num_extensions, FALSE, dev);
743739      }
744740
745741   }
746742   else
747743   {
748      const struct IODevice *iodev = mess_device_from_core_device(dev);
749      const char *ext = iodev->file_extensions;
744      image_device_info info = image_device_getinfo(dev);
745      const char *ext = info.file_extensions;
750746
751747      if (ext != NULL)
752748      {
r2271r2272
754750         {
755751            if (num_extensions < count)
756752            {
757               types[num_extensions].dev = iodev;
753               types[num_extensions].dev = dev;
758754               types[num_extensions].ext = ext;
759755               num_extensions++;
760756            }
r2271r2272
913909   nIcon = GetMessIcon(drvindex, nType);
914910   if (!nIcon)
915911   {
916      if (nType < 0)
912      if (nType == 0)
917913         nType = IO_BAD;
918914      switch(nType)
919915      {
src/mess/osd/winui/devview.c
r2271r2272
193193   LPTSTR *ppszDevices;
194194   LPTSTR s;
195195   SIZE sz;
196   char buf[128];
197196   LONG_PTR l;
198   const char* utf8_s;
199197
200198   pDevViewInfo = GetDevViewInfo(hwndDevView);
201199
r2271r2272
219217
220218      for (dev = image_device_first(pDevViewInfo->config); dev != NULL; dev = image_device_next(dev))
221219      {
222         const struct IODevice *iodev = mess_device_from_core_device(dev);
220         image_device_info info = image_device_getinfo(dev);
223221
224         utf8_s = iodev->name(iodev, iodev->index_in_device, buf, sizeof(buf) / sizeof(buf[0]));
225         s = tstring_from_utf8(utf8_s);
222         s = tstring_from_utf8(info.name);
226223         ppszDevices[i] = alloca((_tcslen(s) + 1) * sizeof(TCHAR));
227224         _tcscpy(ppszDevices[i], s);
228225         free(s);
r2271r2272
256253
257254      for (dev = image_device_first(pDevViewInfo->config); dev != NULL; dev = image_device_next(dev))
258255      {
259         const struct IODevice *iodev = mess_device_from_core_device(dev);
256         image_device_info info = image_device_getinfo(dev);
260257
261258         pEnt->dev = dev;
262259
263         pEnt->hwndStatic = win_create_window_ex_utf8(0, "STATIC", iodev->name(iodev, iodev->index_in_device, buf, sizeof(buf) / sizeof(buf[0])),
260         pEnt->hwndStatic = win_create_window_ex_utf8(0, "STATIC", info.name,
264261            WS_VISIBLE | WS_CHILD, nStaticPos, y, nStaticWidth, nHeight,
265262            hwndDevView, NULL, NULL, NULL);
266263
src/mess/osd/winui/msuiutil.c
r2271r2272
11#include "driver.h"
22#include "image.h"
3#include "device.h"
43#include "msuiutil.h"
54
65BOOL DriverIsComputer(int driver_index)
r2271r2272
5049
5150   for (device = image_device_first(config); device != NULL; device = image_device_next(device))
5251   {
53      const struct IODevice *iodev = mess_device_from_core_device(device);
54      if (iodev->type == type)
52      if (image_device_getinfo(device).type == type)
5553      {
5654         b = TRUE;
5755         break;
src/mess/osd/winui/softwarepicker.c
r2271r2272
185185
186186   if (device != NULL)
187187   {
188      const struct IODevice *iodev = mess_device_from_core_device(device);
189      type = iodev->type;
188      type = image_device_getinfo(device).type;
190189   }
191190   else
192191   {
193      type = (iodevice_t) -1;
192      type = IO_UNKNOWN;
194193   }
195194   return type;
196195}
src/mess/osd/winui/optionsms.c
r2271r2272
142142
143143void SetSelectedSoftware(int driver_index, const device_config *dev, const char *software)
144144{
145   const struct IODevice *iodev = mess_device_from_core_device(dev);
146   const char *opt_name = device_instancename(&iodev->devclass, iodev->index_in_device);
145   image_device_info info = image_device_getinfo(dev);
146   const char *opt_name = info.instance_name;
147147   core_options *o;
148148
149149   if (LOG_SOFTWARE)
r2271r2272
160160
161161const char *GetSelectedSoftware(int driver_index, const device_config *dev)
162162{
163   const struct IODevice *iodev = mess_device_from_core_device(dev);
164   const char *opt_name = device_instancename(&iodev->devclass, iodev->index_in_device);
163   image_device_info info = image_device_getinfo(dev);
164   const char *opt_name = info.instance_name;
165165   const char *software;
166166   core_options *o;
167167
src/mess/osd/winui/propertiesms.c
r2271r2272
1616
1717#include "driver.h"
1818#include "image.h"
19#include "device.h"
2019#include "screenshot.h"
2120#include "datamap.h"
2221#include "bitmask.h"

Previous 15994 Revisions Next


© 1998-2018 The MESS Team