Previous 15994 Revisions Next

r7239 Tuesday 2nd February, 2010 at 13:11:32 UTC by Miodrag Milanović
Made some things simpler and isolated all device add specific code into one function.
[src/mess]image.h mess.c
[src/mess/devices]cartslot.c

src/mess/devices/cartslot.c
r7238r7239
383383/*-------------------------------------------------
384384    DEVICE_GET_IMAGE_DEVICES(cartslot)
385385-------------------------------------------------*/
386static void add_device_with_subdevices(const running_device *_owner, device_type _type, const char *_tag, UINT32 _clock)
387{
388   astring tempstring;
389   device_list *devlist = &_owner->machine->devicelist;
390   const device_config *cfg = new device_config(&_owner->baseconfig(), _type, _tag, _clock);
391   running_device *dev = devlist->append(_owner->subtag(tempstring,_tag), new running_device(*_owner->machine, *cfg));
392   
393   const machine_config_token *tokens = (const machine_config_token *)dev->get_config_ptr(DEVINFO_PTR_MACHINE_CONFIG);
394   machine_config *config;
395   const device_config *config_dev;
396   running_device *new_dev = NULL;
397   if (tokens != NULL)
398   {
399      config = machine_config_alloc(tokens);
400      for (config_dev = config->devicelist.first(); config_dev != NULL; config_dev = config_dev->next)
401      {               
402         device_config *new_cfg = new device_config(cfg, config_dev->type, config_dev->tag, config_dev->clock);
403         new_cfg->static_config = config_dev->static_config;
404         memcpy(
405            new_cfg->inline_config,
406            config_dev->inline_config,
407            new_cfg->get_config_int(DEVINFO_INT_INLINE_CONFIG_BYTES));                       
408         new_dev = devlist->append(dev->subtag(tempstring,config_dev->tag), new running_device(*_owner->machine, *new_cfg));
409         new_dev->owner = dev;
410      }
411      machine_config_free(config);
412   }
413}
386414
387415static DEVICE_GET_IMAGE_DEVICES(cartslot)
388416{
389   const cartslot_pcb_type *pcb_type;
390   astring tempstring;
391
417   const cartslot_pcb_type *pcb_type;   
418   
392419   pcb_type = identify_pcb(device);
393420   if (pcb_type != NULL)
394421   {
395      const device_config *cfg = new device_config(&device->baseconfig(), pcb_type->devtype, TAG_PCB, 0);
396      running_device *dev = devlist->append(device->subtag(tempstring,TAG_PCB), new running_device(*machine, *cfg));
397     
398      const machine_config_token *tokens = (const machine_config_token *)dev->get_config_ptr(DEVINFO_PTR_MACHINE_CONFIG);
399      machine_config *config;
400      const device_config *config_dev;
401      running_device *new_dev = NULL;
402      if (tokens != NULL)
403      {
404         config = machine_config_alloc(tokens);
405         for (config_dev = config->devicelist.first(); config_dev != NULL; config_dev = config_dev->next)
406         {               
407            device_config *new_cfg = new device_config(cfg, config_dev->type, config_dev->tag, config_dev->clock);
408            new_cfg->static_config = config_dev->static_config;
409            memcpy(
410               new_cfg->inline_config,
411               config_dev->inline_config,
412               new_cfg->get_config_int(DEVINFO_INT_INLINE_CONFIG_BYTES));                       
413            new_dev = devlist->append(dev->subtag(tempstring,config_dev->tag), new running_device(*machine, *new_cfg));
414            new_dev->owner = dev;
415         }
416         machine_config_free(config);
417      }
418
422      add_device_with_subdevices(device,pcb_type->devtype,TAG_PCB,0);
419423   }
420424}
421425
src/mess/mess.c
r7238r7239
4141   running_device *image;
4242   image_device_info info;
4343   device_get_image_devices_func get_image_devices;
44   device_list *devlist;
4544
4645   /* initialize natural keyboard support */
4746   inputx_init(machine);
r7238r7239
4948   /* init all devices */
5049   image_init(machine);
5150
52   devlist = &machine->devicelist;
53
5451   /* make sure that any required devices have been allocated */
5552    for (image = machine->devicelist.first(); image != NULL; image = image->next)
5653    {
r7238r7239
7774         /* get image-specific hardware */
7875         get_image_devices = (device_get_image_devices_func) image->get_config_fct(DEVINFO_FCT_GET_IMAGE_DEVICES);
7976         if (get_image_devices != NULL)
80            (*get_image_devices)(image, machine, devlist);
77            (*get_image_devices)(image);
8178      }   
8279   }
8380}
src/mess/image.h
r7238r7239
3636typedef void (*device_display_func)(running_device *image);
3737typedef void (*device_image_partialhash_func)(char *, const unsigned char *, unsigned long, unsigned int);
3838typedef const char *(*device_get_name_func)(running_device *device, char *buffer, size_t buffer_length);
39typedef void (*device_get_image_devices_func)(running_device *device, running_machine *machine, device_list *devlist);
39typedef void (*device_get_image_devices_func)(running_device *device);
4040
4141typedef enum
4242{
r7238r7239
338338#define DEVICE_IMAGE_UNLOAD(name)           void DEVICE_IMAGE_UNLOAD_NAME(name)(running_device *image)
339339
340340#define DEVICE_GET_IMAGE_DEVICES_NAME(name) device_get_image_devices_##name
341#define DEVICE_GET_IMAGE_DEVICES(name)      void DEVICE_GET_IMAGE_DEVICES_NAME(name)(running_device *device, running_machine *machine, device_list *devlist)
341#define DEVICE_GET_IMAGE_DEVICES(name)      void DEVICE_GET_IMAGE_DEVICES_NAME(name)(running_device *device)
342342
343343#endif /* __IMAGE_H__ */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team