Previous 15994 Revisions Next

r2271 Saturday 5th April, 2008 at 14:48:00 UTC by Nathan Woods
Fixed validity warning and simplified some code
[src/mess]device.c device.h

src/mess/device.c
r2270r2271
4848
4949
5050
51struct Devices
51typedef struct _mess_device_type_info mess_device_type_info;
52struct _mess_device_type_info
5253{
5354   iodevice_t type;
5455   const char *name;
r2270r2271
6364
6465/* The List of Devices, with Associated Names - Be careful to ensure that   *
6566 * this list matches the ENUM from device.h, so searches can use IO_COUNT   */
66static const struct Devices device_info_array[] =
67static const mess_device_type_info device_info_array[] =
6768{
6869   { IO_CARTSLOT,   "cartridge",   "cart" }, /*  0 */
6970   { IO_FLOPPY,   "floppydisk",   "flop" }, /*  1 */
r2270r2271
8788    CORE IMPLEMENTATION
8889***************************************************************************/
8990
91static const mess_device_type_info *find_device_type(iodevice_t type)
92{
93   int i;
94   for (i = 0; i < ARRAY_LENGTH(device_info_array); i++)
95   {
96      if (device_info_array[i].type == type)
97         return &device_info_array[i];
98   }
99   return NULL;
100}
101
102
103
90104const char *device_typename(iodevice_t type)
91105{
92   assert(type >= 0);
93   assert(type < IO_COUNT);
94   return device_info_array[type].name;
106   const mess_device_type_info *info = find_device_type(type);
107   return (info != NULL) ? info->name : NULL;
95108}
96109
97110
98111
99112const char *device_brieftypename(iodevice_t type)
100113{
101   assert(type >= 0);
102   assert(type < IO_COUNT);
103   return device_info_array[type].shortname;
114   const mess_device_type_info *info = find_device_type(type);
115   return (info != NULL) ? info->shortname : NULL;
104116}
105117
106118
107119
108int device_typeid(const char *name)
120iodevice_t device_typeid(const char *name)
109121{
110122   int i;
111123   for (i = 0; i < sizeof(device_info_array) / sizeof(device_info_array[0]); i++)
112124   {
113125      if (!mame_stricmp(name, device_info_array[i].name) || !mame_stricmp(name, device_info_array[i].shortname))
114         return i;
126         return device_info_array[i].type;
115127   }
116128   return -1;
117129}
r2270r2271
714726   int error = 0;
715727   int i;
716728
717   if ((sizeof(device_info_array) / sizeof(device_info_array[0])) != IO_COUNT)
718   {
719      mame_printf_error("device_info_array array should match size of IO_* enum\n");
720      error = 1;
721   }
722
723729   /* Check the device struct array */
724730   for (i = 0; i < sizeof(device_info_array) / sizeof(device_info_array[0]); i++)
725731   {
726      if (device_info_array[i].type != i)
727      {
728         mame_printf_error("Device struct array order mismatch\n");
729         error = 1;
730         break;
731      }
732
733732      if (!device_info_array[i].name)
734733      {
735734         mame_printf_error("device_info_array[%d].name appears to be NULL\n", i);
src/mess/device.h
r2270r2271
258258const char *device_uiname(iodevice_t devtype);
259259const char *device_typename(iodevice_t type);
260260const char *device_brieftypename(iodevice_t type);
261int device_typeid(const char *name);
261iodevice_t device_typeid(const char *name);
262262
263263/* device allocation */
264264void mess_devices_setup(machine_config *config, const game_driver *gamedrv);

Previous 15994 Revisions Next


© 1998-2018 The MESS Team