Previous 15994 Revisions Next

r2204 Wednesday 2nd April, 2008 at 00:15:22 UTC by Nathan Woods
Removed mess_device_first_from_machine(), mess_device_next(), ported the concept
of a display callback to the MAME device architecture, and fixed some
regressions.
[src/emu]devintrf.c
[src/mess]configms.c device.c device.h filemngr.c image.c image.h mess.c uimess.c
[src/mess/machine]apple2.c
[src/mess/osd/windows]menu.c

src/emu/devintrf.c
r2203r2204
203203{
204204   const device_config *curdev;
205205
206   assert(type != NULL);
207
208206   /* scan forward starting with the list head */
209207   for (curdev = listhead; curdev != NULL; curdev = curdev->next)
210208      if (device_matches_type(curdev, type))
r2203r2204
225223   const device_config *curdev;
226224
227225   assert(prevdevice != NULL);
228   assert(type != NULL);
229226
230227   /* scan forward starting with the item after the previous one */
231228   for (curdev = prevdevice->next; curdev != NULL; curdev = curdev->next)
src/mess/configms.c
r2203r2204
2323static void device_dirs_load(int config_type, xml_data_node *parentnode)
2424{
2525   xml_data_node *node;
26   const struct IODevice *dev;
26   const device_config *dev;
27   const struct IODevice *iodev;
2728   const device_config *image;
2829   const char *dev_instance;
2930   const char *working_directory;
r2203r2204
3738
3839         if (dev_instance != NULL)
3940         {
40            for (dev = mess_device_first_from_machine(Machine); (image == NULL) && (dev != NULL); dev = mess_device_next(dev))
41            for (dev = image_device_first(Machine->config); (image == NULL) && (dev != NULL); dev = image_device_next(dev))
4142            {
42               if (!strcmp(dev_instance, device_instancename(&dev->devclass, dev->index_in_device)))
43                  image = image_from_device(dev);
43               iodev = mess_device_from_core_device(dev);
44               if (iodev != NULL)
45               {
46                  if (!strcmp(dev_instance, device_instancename(&iodev->devclass, iodev->index_in_device)))
47                     image = dev;
48               }
4449            }
4550
4651            if (image != NULL)
r2203r2204
7176   /* only care about game-specific data */
7277   if (config_type == CONFIG_TYPE_GAME)
7378   {
74      for (dev = mess_device_first_from_machine(Machine); dev != NULL; dev = mess_device_next(dev))
79      for (image = image_device_first(Machine->config); image != NULL; image = image_device_next(image))
7580      {
76         image = image_from_device(dev);
81         dev = mess_device_from_core_device(image);
7782         dev_instance = device_instancename(&dev->devclass, dev->index_in_device);
7883
7984         node = xml_add_child(parentnode, "device", NULL);
src/mess/uimess.c
r2203r2204
2626   static int ui_toggle_key = 0;
2727
2828   int toggled = 0;
29   const struct IODevice *dev;
29   const device_config *dev;
3030
3131   /* traditional MESS interface */
3232   if (machine->gamedrv->flags & GAME_COMPUTER)
r2203r2204
7878   }
7979
8080   /* run display routine for device */
81   for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev))
81   if (mame_get_phase(machine) == MAME_PHASE_RUNNING)
8282   {
83      if (dev->display != NULL)
83      for (dev = image_device_first(machine->config); dev != NULL; dev = image_device_next(dev))
8484      {
85         const device_config *img = image_from_device(dev);
86         dev->display(img);
85         device_display_func display = (device_display_func) device_get_info_fct(dev, DEVINFO_FCT_DISPLAY);
86         if (display != NULL)
87         {
88            display(dev);
89         }
8790      }
8891   }
8992}
r2203r2204
99102int ui_sprintf_image_info(running_machine *machine, char *buf)
100103{
101104   char *dst = buf;
102   const struct IODevice *dev;
105   const device_config *img;
103106
104107   dst += sprintf(dst, "%s\n\n", machine->gamedrv->description);
105108
r2203r2204
109112      dst += sprintf(dst, "RAM: %s\n\n", ram_string(buf2, mess_ram_size));
110113   }
111114
112   for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev))
115   for (img = image_device_first(machine->config); img != NULL; img = image_device_next(img))
113116   {
114         const device_config *img = image_from_device(dev);
115117      const char *name = image_filename(img);
116118      if( name )
117119      {
src/mess/mess.c
r2203r2204
126126   image_init(machine);
127127
128128   /* make sure that any required devices have been allocated */
129   for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev))
129   for (image = image_device_first(machine->config); image != NULL; image = image_device_next(image))
130130   {
131      /* identify the image */
132      image = image_from_device(dev);
131      /* identify the legacy device */
132      dev = mess_device_from_core_device(image);
133133
134134      /* is an image specified for this image */
135135      image_name = mess_get_device_option(&dev->devclass, dev->index_in_device);
src/mess/image.c
r2203r2204
117117{
118118   int count, indx;
119119   UINT32 mask, dev_mask = 0, multiple_dev_mask = 0;
120   const struct IODevice *dev;
120   const device_config *dev;
121   const struct IODevice *iodev;
121122   size_t private_size;
122123   image_slot_data *slot;
123124
r2203r2204
127128
128129   /* first count all images, and identify multiply defined devices */
129130   count = 0;
130   for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev))
131   for (dev = image_device_first(machine->config); dev != NULL; dev = image_device_next(dev))
131132   {
132      /* weird check only relevant on the first device */
133      if (dev->index_in_device == 0)
133      /* weird check only relevant on the first legacy MESS device */
134      iodev = mess_device_from_core_device(dev);
135      if ((iodev != NULL) && (iodev->index_in_device == 0))
134136      {
135137         /* check to see if this device type is used multiple times */
136         mask = 1 << dev->type;
138         mask = 1 << iodev->type;
137139         if (dev_mask & mask)
138140            multiple_dev_mask |= mask;
139141         else
r2203r2204
156158
157159   /* initialize the devices */
158160   indx = 0;
159   for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev))
161   for (dev = image_device_first(machine->config); dev != NULL; dev = image_device_next(dev))
160162   {
161163      slot = &machine->images_data->slots[indx];
162164
163165      /* interim changes until we use the normal device->start */
164      ((device_config *) dev->devconfig)->machine = machine;
165      ((device_config *) dev->devconfig)->token = (void *) ~0;
166      ((device_config *) dev)->machine = machine;
167      ((device_config *) dev)->token = (void *) ~0;
166168
167169      /* create a memory pool */
168170      machine->images_data->slots[indx].mempool = pool_alloc(memory_error);
169171
170172      /* setup the device */
171      tagpool_init(&machine->images_data->slots[indx].tagpool);
172      machine->images_data->slots[indx].dev = dev->devconfig;
173      tagpool_init(&slot->tagpool);
174      machine->images_data->slots[indx].dev = dev;
173175
174176      /* callbacks */
175177      slot->load = (device_image_load_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_LOAD);
r2203r2204
184186      indx++;
185187
186188      /* interim changes until we use the normal device->start */
187      ((device_config *) dev->devconfig)->token = NULL;
189      ((device_config *) dev)->token = NULL;
188190   }
189191
190192   add_exit_callback(machine, image_exit);
r2203r2204
199201
200202static void image_exit(running_machine *machine)
201203{
202   int indx, i;
203   image_slot_data *image;
204   const struct IODevice *dev;
204   int i;
205   image_slot_data *slot;
205206
206207   if (machine->images_data != NULL)
207208   {
r2203r2204
215216      image_unload_all(FALSE);
216217      image_unload_all(TRUE);
217218
218      indx = 0;
219
220      for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev))
219      for (i = 0; i < machine->images_data->slot_count; i++)
221220      {
222         /* identify the image */
223         image = &machine->images_data->slots[indx];
221         /* identify the image slot */
222         slot = &machine->images_data->slots[i];
224223
225         /* call the stop handler if appropriate */
226         if (dev->stop != NULL)
227            dev->stop(image->dev);
228
229224         /* free the tagpool */
230         tagpool_exit(&image->tagpool);
225         tagpool_exit(&slot->tagpool);
231226
232227         /* free the working directory */
233         if (image->working_directory != NULL)
228         if (slot->working_directory != NULL)
234229         {
235            free(image->working_directory);
236            image->working_directory = NULL;
230            free(slot->working_directory);
231            slot->working_directory = NULL;
237232         }
238233
239234         /* free the memory pool */
240         pool_free(image->mempool);
241         image->mempool = NULL;
242         indx++;
235         pool_free(slot->mempool);
236         slot->mempool = NULL;
243237      }
244238
245239      /* interim hack until we use normal device startup/shutdown */
r2203r2204
265259
266260static int is_image_device(const device_config *device)
267261{
268   return (device->type == MESS_DEVICE)
269      || (device_get_info_fct(device, DEVINFO_FCT_IMAGE_LOAD) != NULL)
270      || (device_get_info_fct(device, DEVINFO_FCT_IMAGE_CREATE) != NULL)
271      || (device_get_info_fct(device, DEVINFO_FCT_IMAGE_UNLOAD) != NULL);
262   return (device->type == MESS_DEVICE);
272263}
273264
274265
r2203r2204
17671758
17681759const device_config *image_from_devtag_and_index(const char *devtag, int id)
17691760{
1770   int indx;
17711761   const device_config *image = NULL;
1772   const struct IODevice *dev;
1773   int device_index;
1762   const device_config *dev;
1763   const struct IODevice *iodev;
17741764
1775   indx = 0;
1776   device_index = 0;
1777   for (dev = mess_device_first_from_machine(Machine); dev != NULL; dev = mess_device_next(dev))
1765   for (dev = image_device_first(Machine->config); dev != NULL; dev = image_device_next(dev))
17781766   {
1779      if (dev->tag && !strcmp(dev->tag, devtag) && (device_index++ == id))
1767      iodev = mess_device_from_core_device(dev);
1768      if ((iodev != NULL) && (iodev->tag != NULL) && !strcmp(iodev->tag, devtag) && (iodev->index_in_device == id))
17801769      {
1781         image = dev->devconfig;
1770         image = dev;
17821771         break;
17831772      }
1784      indx++;
17851773   }
17861774
17871775   assert(image != NULL);
r2203r2204
17921780
17931781const device_config *image_from_devtype_and_index(iodevice_t type, int id)
17941782{
1795   int indx;
17961783   const device_config *image = NULL;
1797   const struct IODevice *dev;
1798   int device_index;
1784   const device_config *dev;
1785   const struct IODevice *iodev;
17991786
18001787   assert((Machine->images_data->multiple_dev_mask & (1 << type)) == 0);
18011788   assert(id < device_count(Machine, type));
18021789
1803   indx = 0;
1804   device_index = 0;
1805   for (dev = mess_device_first_from_machine(Machine); dev != NULL; dev = mess_device_next(dev))
1790   for (dev = image_device_first(Machine->config); dev != NULL; dev = image_device_next(dev))
18061791   {
1807      if ((type == dev->type) && (device_index++ == id))
1792      iodev = mess_device_from_core_device(dev);
1793      if ((iodev != NULL) && (type == iodev->type) && (iodev->index_in_device == id))
18081794      {
1809         image = dev->devconfig;
1795         image = dev;
18101796         break;
18111797      }
1812      indx++;
18131798   }
18141799
18151800   assert(image);
src/mess/image.h
r2203r2204
4747   DEVINFO_FCT_IMAGE_LOAD,                              /* R/O: device_load_handler */
4848   DEVINFO_FCT_IMAGE_CREATE,                           /* R/O: device_create_handler */
4949   DEVINFO_FCT_IMAGE_UNLOAD,                           /* R/O: device_unload_handler */
50   DEVINFO_FCT_DISPLAY,                              /* R/O: device_display_func */
5051   DEVINFO_FCT_IMAGE_LAST = DEVINFO_FCT_FIRST + 0x0fff
5152};
5253
src/mess/device.c
r2203r2204
197197
198198static DEVICE_START(mess_device)
199199{
200   mess_device_config *mess_device = (mess_device_config *) device->inline_config;
201
202   /* if present, invoke the start handler */
203   if (mess_device->io_device.start != NULL)
204      (*mess_device->io_device.start)(device);
200205}
201206
202207
r2203r2204
225230      case DEVINFO_FCT_IMAGE_LOAD:         info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_LOAD); break;
226231      case DEVINFO_FCT_IMAGE_CREATE:         info->f   = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE); break;
227232      case DEVINFO_FCT_IMAGE_UNLOAD:         info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_UNLOAD); break;
233      case DEVINFO_FCT_DISPLAY:            info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_DISPLAY); break;
228234
229235      /* --- the following bits of info are returned as NULL-terminated strings --- */
230236      case DEVINFO_STR_NAME:               info->s = "Legacy MESS Device";               break;
r2203r2204
370376      mess_device->io_device.imgverify         = (device_image_verify_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_VERIFY);
371377      mess_device->io_device.partialhash         = (device_image_partialhash_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_PARTIAL_HASH);
372378
373      mess_device->io_device.display            = (device_display_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_DISPLAY);
374379      mess_device->io_device.name               = default_device_name;
375380
376381      mess_device->io_device.createimage_optguide   = (const struct OptionGuide *) mess_device_get_info_ptr(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE_OPTGUIDE);
r2203r2204
483488
484489/*************************************
485490 *
486 *   Device enumeration
487 *
488 *************************************/
489
490const struct IODevice *mess_device_first_from_machine(const running_machine *machine)
491{
492   const device_config *devconfig;
493   devconfig = device_list_first(machine->config->devicelist, MESS_DEVICE);
494   return (devconfig != NULL) ? devconfig->inline_config : NULL;
495}
496
497
498
499const struct IODevice *mess_device_next(const struct IODevice *dev)
500{
501   const device_config *devconfig;
502   devconfig = device_list_next(dev->devconfig, MESS_DEVICE);
503   return (devconfig != NULL) ? devconfig->inline_config : NULL;
504}
505
506
507
508/*************************************
509 *
510491 *   Device lookup
511492 *
512493 *************************************/
src/mess/filemngr.c
r2203r2204
639639   const struct IODevice *devices[40];
640640   char names[40][64];
641641   int sel, total, arrowize;
642   const struct IODevice *dev;
643642   const device_config *image;
644643
645644   sel = selected - 1;
646645   total = 0;
647646
648647   /* Cycle through all devices for this system */
649   for (dev = mess_device_first_from_machine(Machine); dev != NULL; dev = mess_device_next(dev))
648   for (image = image_device_first(Machine->config); image != NULL; image = image_device_next(image))
650649   {
651      image = image_from_device(dev);
652650      strcpy( names[total], image_typename_id(image) );
653651      name = image_filename(image);
654652
r2203r2204
656654      menu_items[total].text = (names[total]) ? names[total] : "---";
657655      menu_items[total].subtext = (name) ? name : "---";
658656
659      devices[total] = dev;
657      devices[total] = mess_device_from_core_device(image);
660658     
661659      total++;
662660   }
src/mess/device.h
r2203r2204
263263   device_image_partialhash_func partialhash;
264264
265265   /* cosmetic/UI callbacks */
266   void (*display)(const device_config *img);
267266   const char *(*name)(const struct IODevice *dev, int id, char *buf, size_t bufsize);
268267
269268   /* image creation options */
r2203r2204
285284/* device allocation */
286285void mess_devices_setup(machine_config *config, const game_driver *gamedrv);
287286
288/* device enumeration */
289const struct IODevice *mess_device_first_from_machine(const running_machine *machine);
290const struct IODevice *mess_device_next(const struct IODevice *dev);
291
292287/* device lookup */
293288int device_count_tag_from_machine(const running_machine *machine, const char *tag);
294289
src/mess/osd/windows/menu.c
r2203r2204
13451345   remove_menu_items(device_menu);
13461346
13471347   // then set up the actual devices
1348   for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev))
1348   for (img = image_device_first(machine->config); img != NULL; img = image_device_next(img))
13491349   {
1350      img = image_from_device(dev);
1350      dev = mess_device_from_core_device(img);
13511351
13521352      new_item = ID_DEVICE_0 + (image_absolute_index(img) * DEVOPTION_MAX);
13531353      flags_for_exists = MF_STRING;
src/mess/machine/apple2.c
r2203r2204
14251425
14261426static void *apple2_fdc_init(running_machine *machine, int slot, applefdc_t fdc_type)
14271427{
1428   const struct IODevice *dev;
1428   const device_config *dev;
1429   const struct IODevice *iodev;
14291430   applefdc_interface intf;
14301431
14311432   apple2_fdc_has_35 = FALSE;
r2203r2204
14411442   intf.read_data = apple2_fdc_read_data;
14421443   intf.write_data = apple2_fdc_write_data;
14431444
1444   for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev))
1445   for (dev = image_device_first(machine->config); dev != NULL; dev = image_device_next(dev))
14451446   {
1446      if (!strcmp(dev->tag, "sonydriv"))
1447         apple2_fdc_has_35 = 1;
1448      else if (!strcmp(dev->tag, "apple525driv"))
1449         apple2_fdc_has_525 = 1;
1447      iodev = mess_device_from_core_device(dev);
1448      if (iodev != NULL)
1449      {
1450         if (!strcmp(iodev->tag, "sonydriv"))
1451            apple2_fdc_has_35 = 1;
1452         else if (!strcmp(iodev->tag, "apple525driv"))
1453            apple2_fdc_has_525 = 1;
1454      }
14501455   }
14511456
14521457   applefdc_init(&intf);

Previous 15994 Revisions Next


© 1998-2018 The MESS Team