Previous 15994 Revisions Next

r2295 Sunday 6th April, 2008 at 05:18:56 UTC by Nathan Woods
More device refactoring
[src/mess]device.c device.h image.c image.h

src/mess/image.c
r2294r2295
9292
9393
9494/***************************************************************************
95    INLINE FUNCTIONS
96***************************************************************************/
97
98/*-------------------------------------------------
99    device_get_info_int_offline - return an integer
100   state value from an allocated device; can be
101   called offline
102-------------------------------------------------*/
103
104INLINE INT64 device_get_info_int_offline(const device_config *device, UINT32 state)
105{
106   deviceinfo info;
107
108   assert(device != NULL);
109   assert(device->type != NULL);
110   assert(state >= DEVINFO_INT_FIRST && state <= DEVINFO_INT_LAST);
111
112   /* retrieve the value */
113   info.i = 0;
114   (*device->type)(device, state, &info);
115   return info.i;
116}
117
118
119
120/*-------------------------------------------------
121    device_get_info_fct_offline - return an integer
122   state value from an allocated device; can be
123   called offline
124-------------------------------------------------*/
125
126INLINE genf *device_get_info_fct_offline(const device_config *device, UINT32 state)
127{
128   deviceinfo info;
129
130   assert(device != NULL);
131   assert(device->type != NULL);
132   assert(state >= DEVINFO_FCT_FIRST && state <= DEVINFO_FCT_LAST);
133
134   /* retrieve the value */
135   info.f = 0;
136   (*device->type)(device, state, &info);
137   return info.f;
138}
139
140
141
142/***************************************************************************
95143    CORE IMPLEMENTATION
96144***************************************************************************/
97145
r2294r2295
210258
211259static int is_image_device(const device_config *device)
212260{
213   return (device->type == MESS_DEVICE);
261   return (device->type == MESS_DEVICE)
262      || (device_get_info_int_offline(device, DEVINFO_INT_IMAGE_READABLE) != 0)
263      || (device_get_info_int_offline(device, DEVINFO_INT_IMAGE_WRITEABLE) != 0);
214264}
215265
216266
r2294r2295
285335   
286336   memset(&info, 0, sizeof(info));
287337
338   /* retrieve type */
339   info.type = (iodevice_t) (int) device_get_info_int_offline(device, DEVINFO_INT_IMAGE_TYPE);
340
341   /* retrieve flags */
342   info.readable = device_get_info_int_offline(device, DEVINFO_INT_IMAGE_READABLE) ? 1 : 0;
343   info.writeable = device_get_info_int_offline(device, DEVINFO_INT_IMAGE_WRITEABLE) ? 1 : 0;
344   info.creatable = device_get_info_int_offline(device, DEVINFO_INT_IMAGE_CREATABLE) ? 1 : 0;
345   info.must_be_loaded = device_get_info_int_offline(device, DEVINFO_INT_IMAGE_MUST_BE_LOADED) ? 1 : 0;
346
288347   iodev = mess_device_from_core_device(device);
289348   if (iodev != NULL)
290349   {
291      /* retrieve type */
292      info.type = iodev->type;
293
294      /* retrieve flags */
295      info.readable = iodev->readable;
296      info.writeable = iodev->writeable;
297      info.creatable = iodev->creatable;
298      info.must_be_loaded = iodev->must_be_loaded;
299      info.uses_partial_hash = iodev->partialhash != NULL;
300
301350      /* retrieve name */
302351      s = (*iodev->name)(iodev, iodev->index_in_device, info.name, ARRAY_LENGTH(info.name));
303352      if (s != info.name)
r2294r2295
364413void image_device_compute_hash(char *dest, const device_config *device,
365414   const void *data, size_t length, unsigned int functions)
366415{
367   deviceinfo info;
368416   device_image_partialhash_func partialhash;
369417
370418   /* retrieve the partial hash func */
371   info.f = 0;
372   (*device->type)(device, DEVINFO_FCT_IMAGE_PARTIAL_HASH, &info);
373   partialhash = (device_image_partialhash_func) info.f;
419   partialhash = (device_image_partialhash_func) device_get_info_fct_offline(device, DEVINFO_FCT_IMAGE_PARTIAL_HASH);
374420
375421   /* compute the hash */
376422   if (partialhash != NULL)
src/mess/image.h
r2294r2295
6565   unsigned int writeable : 1;
6666   unsigned int creatable : 1;
6767   unsigned int must_be_loaded : 1;
68   unsigned int uses_partial_hash : 1;
6968   char name[62];
7069   char file_extensions[32];
7170   char instance_name[32];
r2294r2295
7978/* state constants specific for mountable images */
8079enum
8180{
81   /* --- the following bits of info are returned as integers --- */
82   DEVINFO_INT_IMAGE_FIRST = DEVINFO_INT_FIRST + 0x7000,
83   DEVINFO_INT_IMAGE_TYPE,
84   DEVINFO_INT_IMAGE_READABLE,
85   DEVINFO_INT_IMAGE_WRITEABLE,
86   DEVINFO_INT_IMAGE_CREATABLE,
87   DEVINFO_INT_IMAGE_MUST_BE_LOADED,
88   DEVINFO_INT_IMAGE_LAST = DEVINFO_INT_IMAGE_FIRST + 0x0fff,
89
8290   /* --- the following bits of info are returned as pointers to functions --- */
8391   DEVINFO_FCT_IMAGE_FIRST = DEVINFO_FCT_FIRST + 0x7000,
8492   DEVINFO_FCT_IMAGE_LOAD,                              /* R/O: device_load_handler */
r2294r2295
8694   DEVINFO_FCT_IMAGE_UNLOAD,                           /* R/O: device_unload_handler */
8795   DEVINFO_FCT_DISPLAY,                              /* R/O: device_display_func */
8896   DEVINFO_FCT_IMAGE_PARTIAL_HASH,                        /* R/O: device_image_partialhash_func */
89   DEVINFO_FCT_IMAGE_LAST = DEVINFO_FCT_FIRST + 0x0fff
97   DEVINFO_FCT_IMAGE_LAST = DEVINFO_FCT_FIRST + 0x0fff,
98
99   /* --- the following bits of info are returned as NULL-terminated strings --- */
100   DEVINFO_STR_IMAGE_FIRST = DEVINFO_STR_FIRST + 0x7000,
101   DEVINFO_STR_IMAGE_FILE_EXTENSIONS,
102   DEVINFO_STR_IMAGE_LAST = DEVINFO_STR_IMAGE_FIRST + 0x0fff
90103};
91104
92105
src/mess/device.c
r2294r2295
267267      case DEVINFO_INT_INLINE_CONFIG_BYTES:   info->i = sizeof(mess_device_config);         break;
268268      case DEVINFO_INT_TOKEN_BYTES:         info->i = sizeof(mess_device_token);         break;
269269      case DEVINFO_INT_CLASS:               info->i = DEVICE_CLASS_OTHER;               break;
270      case DEVINFO_INT_IMAGE_READABLE:      info->i = mess_device->io_device.readable;      break;
271      case DEVINFO_INT_IMAGE_WRITEABLE:      info->i = mess_device->io_device.writeable;      break;
272      case DEVINFO_INT_IMAGE_CREATABLE:      info->i = mess_device->io_device.creatable;      break;
273      case DEVINFO_INT_IMAGE_MUST_BE_LOADED:   info->i = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_MUST_BE_LOADED); break;
270274
271275      /* --- the following bits of info are returned as pointers to data or functions --- */
272276      case DEVINFO_FCT_SET_INFO:            /* Nothing */                           break;
r2294r2295
415419      mess_device->io_device.file_extensions      = file_extensions;
416420
417421      mess_device->io_device.reset_on_load      = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_RESET_ON_LOAD) ? 1 : 0;
418      mess_device->io_device.must_be_loaded      = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_MUST_BE_LOADED) ? 1 : 0;
419422      mess_device->io_device.load_at_init         = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_LOAD_AT_INIT) ? 1 : 0;
420423
421424      mess_device->io_device.start            = (device_start_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_START);
src/mess/device.h
r2294r2295
230230
231231   /* miscellaneous flags */
232232   unsigned int reset_on_load : 1;
233   unsigned int must_be_loaded : 1;
234233   unsigned int load_at_init : 1;
235234   unsigned int multiple : 1;
236235

Previous 15994 Revisions Next


© 1998-2018 The MESS Team