Previous 15994 Revisions Next

r2291 Sunday 6th April, 2008 at 02:55:07 UTC by Nathan Woods
Yet more device refactoring
[src/mess]messopts.c

src/mess/messopts.c
r2290r2291
6565   for all devices on a driver
6666-------------------------------------------------*/
6767
68static void mess_enumerate_devices(core_options *opts, const game_driver *gamedrv,
69   void (*proc)(core_options *opts, const game_driver *gamedrv, const mess_device_class *devclass, int device_index, int global_index))
68static void mess_enumerate_devices(core_options *opts, const machine_config *config, const game_driver *gamedrv,
69   void (*proc)(core_options *opts, const game_driver *gamedrv, const device_config *device, int global_index))
7070{
71   struct SystemConfigurationParamBlock cfg;
72   device_getinfo_handler handlers[64];
73   int count_overrides[ARRAY_LENGTH(handlers)];
74   int i, j, count, index = 0;
75   mess_device_class devclass;
71   const device_config *device;
72   int index = 0;
7673
77   /* retrieve getinfo handlers */
78   memset(&cfg, 0, sizeof(cfg));
79   memset(handlers, 0, sizeof(handlers));
80   cfg.device_slotcount = sizeof(handlers) / sizeof(handlers[0]);
81   cfg.device_handlers = handlers;
82   cfg.device_countoverrides = count_overrides;
83   if (gamedrv->sysconfig_ctor)
84      gamedrv->sysconfig_ctor(&cfg);
85
86   /* run this on all devices */
87   for (i = 0; handlers[i]; i++)
74   /* loop on each device instance */
75   for (device = image_device_first(config); device != NULL; device = image_device_next(device))
8876   {
89      /* create the device class */
90      memset(&devclass, 0, sizeof(devclass));
91      devclass.gamedrv = gamedrv;
92      devclass.get_info = handlers[i];
93
94      /* how many of this device exist? */
95      count = (int) mess_device_get_info_int(&devclass, MESS_DEVINFO_INT_COUNT);
96
97      /* loop on each device instance */
98      for (j = 0; j < count; j++)
99      {
100         proc(opts, gamedrv, &devclass, j, index++);
101      }
77      proc(opts, gamedrv, device, index++);
10278   }
10379}
10480
r2290r2291
11086-------------------------------------------------*/
11187
11288static void add_device_options_for_device(core_options *opts, const game_driver *gamedrv,
113   const mess_device_class *devclass, int device_index, int global_index)
89   const device_config *device, int global_index)
11490{
91   image_device_info info;
11592   options_entry this_entry[2];
116   const char *dev_name;
117   const char *dev_short_name;
11893   char dev_full_name[128];
11994
12095   /* first device? add the header as to be pretty */
r2290r2291
127102   }
128103
129104   /* retrieve info about the device instance */
130   dev_name = device_instancename(devclass, device_index);
131   dev_short_name = device_briefinstancename(devclass, device_index);
105   info = image_device_getinfo(device);
132106   snprintf(dev_full_name, sizeof(dev_full_name) / sizeof(dev_full_name[0]),
133      "%s;%s", dev_name, dev_short_name);
107      "%s;%s", info.instance_name, info.brief_instance_name);
134108
135109   /* add the option */
136110   memset(this_entry, 0, sizeof(this_entry));
r2290r2291
147121
148122void mess_add_device_options(core_options *opts, const game_driver *driver)
149123{
124   machine_config *config;
125
126   /* create the configuration */
127   config = machine_config_alloc_with_mess_devices(driver);
128
150129   /* enumerate our callback for every device */
151   mess_enumerate_devices(opts, driver, add_device_options_for_device);
130   mess_enumerate_devices(opts, config, driver, add_device_options_for_device);
152131
153132   /* record that we've added device options */
154133   options_set_bool(opts, OPTION_ADDED_DEVICE_OPTIONS, TRUE, OPTION_PRIORITY_CMDLINE);
134
135   /* free the configuration */
136   machine_config_free(config);
155137}
156138
157139
r2290r2291
204186-------------------------------------------------*/
205187
206188static void extract_device_options_for_device(core_options *opts, const game_driver *gamedrv,
207   const mess_device_class *devclass, int device_index, int global_index)
189   const device_config *device, int global_index)
208190{
209   const device_config *image;
210   iodevice_t dev_type;
211   const char *dev_tag;
212   const char *dev_name;
191   image_device_info info;
213192   const char *filename;
214193
215194   assert_always(options_get_bool(opts, OPTION_ADDED_DEVICE_OPTIONS), "extract_device_options_for_device() called without device options");
216195
217   /* identify the correct image */
218   dev_tag = mess_device_get_info_string(devclass, MESS_DEVINFO_STR_DEV_TAG);
219   if (dev_tag != NULL)
220   {
221      image = image_from_devtag_and_index(Machine, dev_tag, device_index);
222   }
223   else
224   {
225      dev_type = (iodevice_t) (int) mess_device_get_info_int(devclass, MESS_DEVINFO_INT_TYPE);
226      image = image_from_devtype_and_index(dev_type, device_index);
227   }
228
229196   /* access the filename */
230   filename = image_filename(image);
197   filename = image_filename(device);
231198
232   /* identify the option name */
233   dev_name = device_instancename(devclass, device_index);
199   /* access other info */
200   info = image_device_getinfo(device);
234201
235202   /* and set the option */
236   options_set_string(opts, dev_name, filename ? filename : "", OPTION_PRIORITY_CMDLINE);
203   options_set_string(opts, info.instance_name, filename ? filename : "", OPTION_PRIORITY_CMDLINE);
237204}
238205
239206
r2290r2291
280247{
281248   /* only extract the device options if we've added them */
282249   if (options_get_bool(mame_options(), OPTION_ADDED_DEVICE_OPTIONS))
283      mess_enumerate_devices(mame_options(), machine->gamedrv, extract_device_options_for_device);
250      mess_enumerate_devices(mame_options(), machine->config, machine->gamedrv, extract_device_options_for_device);
284251
285252   /* write the config, if appropriate */
286253   if (options_get_bool(mame_options(), OPTION_WRITECONFIG))

Previous 15994 Revisions Next


© 1998-2018 The MESS Team