Previous 15994 Revisions Next

r2191 Tuesday 1st April, 2008 at 01:23:56 UTC by Nathan Woods
Initial work to decouple image.c and device.c
[src/emu]devintrf.h
[src/mess]device.c device.h image.c image.h

src/emu/devintrf.h
r2190r2191
7171
7272   DEVINFO_FCT_DEVICE_SPECIFIC = 0x28000,            /* R/W: device-specific values start here */
7373
74   DEVINFO_FCT_LAST = 0x1ffff,
74   DEVINFO_FCT_LAST = 0x2ffff,
7575
7676   /* --- the following bits of info are returned as NULL-terminated strings --- */
7777   DEVINFO_STR_FIRST = 0x30000,
src/mess/image.c
r2190r2191
3838   object_pool *mempool;
3939   const device_config *dev;
4040
41   /* callbacks */
42   device_image_load_func load;
43   device_image_create_func create;
44   device_image_unload_func unload;
45
4146   /* error related info */
4247   image_error_t err;
4348   char *err_message;
r2190r2191
114119   UINT32 mask, dev_mask = 0, multiple_dev_mask = 0;
115120   const struct IODevice *dev;
116121   size_t private_size;
122   image_slot_data *slot;
117123
124   /* sanity checks */
125   assert(DEVINFO_FCT_IMAGE_FIRST > DEVINFO_FCT_FIRST);
126   assert(DEVINFO_FCT_IMAGE_LAST < DEVINFO_FCT_DEVICE_SPECIFIC);
127
118128   /* first count all images, and identify multiply defined devices */
119129   count = 0;
120130   for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev))
r2190r2191
148158   indx = 0;
149159   for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev))
150160   {
151      /* interim change until we use the normal device->start */
161      slot = &machine->images_data->slots[indx];
162
163      /* interim changes until we use the normal device->start */
152164      ((device_config *) dev->devconfig)->machine = machine;
165      ((device_config *) dev->devconfig)->token = (void *) ~0;
153166
154167      /* create a memory pool */
155168      machine->images_data->slots[indx].mempool = pool_alloc(memory_error);
r2190r2191
158171      tagpool_init(&machine->images_data->slots[indx].tagpool);
159172      machine->images_data->slots[indx].dev = dev->devconfig;
160173
174      /* callbacks */
175      slot->load = (device_image_load_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_LOAD);
176      slot->create = (device_image_create_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_CREATE);
177      slot->unload = (device_image_unload_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_UNLOAD);
178
179      /* invoke start, if present */
161180      if (dev->start != NULL)
162181      {
163         dev->start(machine->images_data->slots[indx].dev);
182         dev->start(slot->dev);
164183      }
165184      indx++;
185
186      /* interim changes until we use the normal device->start */
187      ((device_config *) dev->devconfig)->token = NULL;
166188   }
167189
168190   add_exit_callback(machine, image_exit);
r2190r2191
659681   }
660682
661683   /* call device load or create */
662   if (image_has_been_created(image) && (iodev->create != NULL))
684   if (image_has_been_created(image) && (slot->create != NULL))
663685   {
664      err = iodev->create(image, create_format, create_args);
686      err = slot->create(image, create_format, create_args);
665687      if (err)
666688      {
667689         if (!slot->err)
r2190r2191
669691         goto done;
670692      }
671693   }
672   else if (iodev->load != NULL)
694   else if (slot->load != NULL)
673695   {
674696      /* using device load */
675      err = iodev->load(image);
697      err = slot->load(image);
676698      if (err)
677699      {
678700         if (!slot->err)
r2190r2191
762784
763785   /* call the unload function */
764786   iodev = mess_device_from_core_device(image->dev);
765   if (iodev->unload != NULL)
766      iodev->unload(image->dev);
787   if (image->unload != NULL)
788      image->unload(image->dev);
767789
768790   image_clear(image);
769791   image_clear_error(image);
src/mess/image.h
r2190r2191
66
77****************************************************************************/
88
9#ifndef IMAGE_H
10#define IMAGE_H
9#ifndef __IMAGE_H__
10#define __IMAGE_H__
1111
1212#include <stdlib.h>
13
1314#include "fileio.h"
1415#include "utils.h"
1516#include "opresolv.h"
1617#include "device.h"
1718#include "osdmess.h"
1819
20
21
22/***************************************************************************
23    CONSTANTS
24***************************************************************************/
25
1926typedef enum
2027{
2128   IMAGE_ERROR_SUCCESS,
r2190r2191
3239typedef struct _images_private images_private;
3340
3441
42/* state constants specific for mountable images */
43enum
44{
45   /* --- the following bits of info are returned as pointers to functions --- */
46   DEVINFO_FCT_IMAGE_FIRST      = DEVINFO_FCT_FIRST + 0x7000,
47   DEVINFO_FCT_IMAGE_LOAD,                              /* R/O: device_load_handler */
48   DEVINFO_FCT_IMAGE_CREATE,                           /* R/O: device_create_handler */
49   DEVINFO_FCT_IMAGE_UNLOAD,                           /* R/O: device_unload_handler */
50   DEVINFO_FCT_IMAGE_LAST      = DEVINFO_FCT_FIRST + 0x0fff
51};
3552
53
54
55
3656/****************************************************************************
3757  A const device_config pointer represents one device entry; this could be an instance
3858  of a floppy drive or a printer.  The defining property is that either at
r2190r2191
222242#define DEVICE_IMAGE_UNLOAD_NAME(name)   device_unload_##name
223243#define DEVICE_IMAGE_UNLOAD(name)      void DEVICE_IMAGE_UNLOAD_NAME(name)(const device_config *image)
224244
225#endif /* IMAGE_H */
245#endif /* __IMAGE_H__ */
src/mess/device.c
r2190r2191
209209
210210DEVICE_GET_INFO(mess_device)
211211{
212   mess_device_config *mess_device = (device != NULL) ? (mess_device_config *) device->inline_config : NULL;
213
212214   switch (state)
213215   {
214216      /* --- the following bits of info are returned as 64-bit signed integers --- */
r2190r2191
221223      case DEVINFO_FCT_START:               info->start = DEVICE_START_NAME(mess_device);   break;
222224      case DEVINFO_FCT_STOP:               /* Nothing */                           break;
223225      case DEVINFO_FCT_RESET:               /* Nothing */                           break;
226      case DEVINFO_FCT_IMAGE_LOAD:         info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_LOAD); break;
227      case DEVINFO_FCT_IMAGE_CREATE:         info->f   = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE); break;
228      case DEVINFO_FCT_IMAGE_UNLOAD:         info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_UNLOAD); break;
224229
225230      /* --- the following bits of info are returned as NULL-terminated strings --- */
226231      case DEVINFO_STR_NAME:               info->s = "Legacy MESS Device";               break;
r2190r2191
363368
364369      mess_device->io_device.start            = (device_start_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_START);
365370      mess_device->io_device.stop               = (device_stop_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_STOP);
366      mess_device->io_device.load               = (device_image_load_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_LOAD);
367      mess_device->io_device.create            = (device_image_create_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE);
368      mess_device->io_device.unload            = (device_image_unload_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_UNLOAD);
369371      mess_device->io_device.imgverify         = (device_image_verify_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_VERIFY);
370372      mess_device->io_device.partialhash         = (device_image_partialhash_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_PARTIAL_HASH);
371373
src/mess/device.h
r2190r2191
259259   /* image handling callbacks */
260260   device_start_func start;
261261   device_stop_func stop;
262   device_image_load_func load;
263   device_image_create_func create;
264   device_image_unload_func unload;
265262   int (*imgverify)(const UINT8 *buf, size_t size);
266263   device_image_partialhash_func partialhash;
267264

Previous 15994 Revisions Next


© 1998-2018 The MESS Team