Previous 15994 Revisions Next

r3036 Wednesday 13th August, 2008 at 00:45:06 UTC by Nathan Woods
Now surfacing creation formats in the new device model
[src/mess]device.c device.h image.c image.h mesvalid.c
[src/mess/devices]mflopimg.c

src/mess/image.c
r3035r3036
3737   const device_config *dev;
3838   image_device_info info;
3939
40   /* creation info */
41   image_device_format *formatlist;
42
4043   /* callbacks */
4144   device_image_load_func load;
4245   device_image_create_func create;
r3035r3036
9194static void image_clear(image_slot_data *image);
9295static void image_clear_error(image_slot_data *image);
9396static void image_unload_internal(image_slot_data *slot);
97static image_slot_data *find_image_slot(const device_config *image);
9498
9599
96100
r3035r3036
185189
186190void image_init(running_machine *machine)
187191{
188   int count, indx;
192   int count, indx, format_count, i;
189193   const device_config *dev;
190194   size_t private_size;
191195   image_slot_data *slot;
196   image_device_format **formatptr;
197   image_device_format *format;
192198
193199   /* sanity checks */
194200   assert(DEVINFO_FCT_IMAGE_FIRST > DEVINFO_FCT_FIRST);
r3035r3036
225231      slot->unload = (device_image_unload_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_UNLOAD);
226232      slot->verify = (device_image_verify_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_VERIFY);
227233
234      /* creation formats */
235      format_count = device_get_info_int(slot->dev, DEVINFO_INT_IMAGE_CREATE_OPTCOUNT);
236      formatptr = &slot->formatlist;
237      for (i = 0; i < format_count; i++)
238      {
239         /* allocate a new format */
240         format = auto_malloc(sizeof(*format));
241         memset(format, 0, sizeof(*format));
242
243         /* populate it */
244         format->name      = auto_strdup(device_get_info_string(slot->dev, DEVINFO_STR_IMAGE_CREATE_OPTNAME + i));
245         format->description   = auto_strdup(device_get_info_string(slot->dev, DEVINFO_STR_IMAGE_CREATE_OPTDESC + i));
246         format->extensions   = auto_strdup(device_get_info_string(slot->dev, DEVINFO_STR_IMAGE_CREATE_OPTEXTS + i));
247         format->optspec      = device_get_info_ptr(slot->dev, DEVINFO_PTR_IMAGE_CREATE_OPTSPEC + i);
248
249         /* and append it to the list */
250         *formatptr = format;
251         formatptr = &format->next;
252      }
253
228254      indx++;
229255   }
230256
r3035r3036
566592
567593
568594/****************************************************************************
595    CREATION FORMATS
596****************************************************************************/
597
598/*-------------------------------------------------
599    image_device_get_creatable_formats - accesses
600   the image formats available for image creation
601-------------------------------------------------*/
602
603const image_device_format *image_device_get_creatable_formats(const device_config *device)
604{
605   image_slot_data *slot = find_image_slot(device);
606   return slot->formatlist;
607}
608
609
610
611/****************************************************************************
569612    IMAGE LOADING
570613****************************************************************************/
571614
src/mess/image.h
r3035r3036
1919
2020
2121/***************************************************************************
22    CONSTANTS
23***************************************************************************/
24
25#define DEVINFO_CREATE_OPTMAX   32
26
27
28
29/***************************************************************************
2230    TYPE DEFINITIONS
2331***************************************************************************/
2432
r3035r3036
8189   char brief_instance_name[16];
8290};
8391
92typedef struct _image_device_format image_device_format;
93struct _image_device_format
94{
95   image_device_format *next;
96   const char *name;
97   const char *description;
98   const char *extensions;
99   const char *optspec;
100};
101
84102struct _images_private;
85103typedef struct _images_private images_private;
86104
r3035r3036
96114   DEVINFO_INT_IMAGE_CREATABLE,
97115   DEVINFO_INT_IMAGE_MUST_BE_LOADED,
98116   DEVINFO_INT_IMAGE_RESET_ON_LOAD,
117   DEVINFO_INT_IMAGE_CREATE_OPTCOUNT,
99118   DEVINFO_INT_IMAGE_LAST = DEVINFO_INT_IMAGE_FIRST + 0x0fff,
100119
120   /* --- the following bits of info are returned as pointers --- */
121   DEVINFO_PTR_IMAGE_FIRST = DEVINFO_PTR_FIRST + 0x7000,
122   DEVINFO_PTR_IMAGE_CREATE_OPTSPEC,
123
101124   /* --- the following bits of info are returned as pointers to functions --- */
102125   DEVINFO_FCT_IMAGE_FIRST = DEVINFO_FCT_FIRST + 0x7000,
103126   DEVINFO_FCT_IMAGE_LOAD,                              /* R/O: device_image_load_func */
r3035r3036
114137   DEVINFO_STR_IMAGE_FILE_EXTENSIONS,
115138   DEVINFO_STR_IMAGE_INSTANCE_NAME,
116139   DEVINFO_STR_IMAGE_BRIEF_INSTANCE_NAME,
140   DEVINFO_STR_IMAGE_CREATE_OPTNAME,
141   DEVINFO_STR_IMAGE_CREATE_OPTDESC = DEVINFO_STR_IMAGE_CREATE_OPTNAME + DEVINFO_CREATE_OPTMAX,
142   DEVINFO_STR_IMAGE_CREATE_OPTEXTS = DEVINFO_STR_IMAGE_CREATE_OPTDESC + DEVINFO_CREATE_OPTMAX,
117143   DEVINFO_STR_IMAGE_LAST = DEVINFO_STR_IMAGE_FIRST + 0x0fff
118144};
119145
r3035r3036
153179void image_device_compute_hash(char *dest, const device_config *device,
154180   const void *data, size_t length, unsigned int functions);
155181
182/* ----- creation formats ----- */
156183
184const image_device_format *image_device_get_creatable_formats(const device_config *device);
157185
186
187
158188/****************************************************************************
159189  Device loading and unloading functions
160190
src/mess/device.c
r3035r3036
3535{
3636   struct IODevice io_device;
3737   char string_buffer[1024];
38   create_image_options createimage_options[MESS_DEVINFO_CREATE_OPTMAX + 1];
38   create_image_options createimage_options[DEVINFO_CREATE_OPTMAX + 1];
3939};
4040
4141
r3035r3036
235235      case DEVINFO_INT_IMAGE_TYPE:         info->i = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_TYPE); break;
236236      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;
237237      case DEVINFO_INT_IMAGE_RESET_ON_LOAD:   info->i = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_RESET_ON_LOAD); break;
238      case DEVINFO_INT_IMAGE_CREATE_OPTCOUNT:   info->i = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_CREATE_OPTCOUNT); break;
238239
239240      /* --- the following bits of info are returned as pointers to data or functions --- */
240241      case DEVINFO_FCT_SET_INFO:            /* Nothing */                           break;
r3035r3036
258259      case DEVINFO_STR_IMAGE_FILE_EXTENSIONS:   info->s = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_FILE_EXTENSIONS); break;
259260      case DEVINFO_STR_IMAGE_INSTANCE_NAME:   info->s = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_NAME + mess_device->io_device.index_in_device); break;
260261      case DEVINFO_STR_IMAGE_BRIEF_INSTANCE_NAME:   info->s = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_SHORT_NAME + mess_device->io_device.index_in_device); break;
262
263      default:
264         if ((state >= DEVINFO_PTR_IMAGE_CREATE_OPTSPEC) && (state < DEVINFO_PTR_IMAGE_CREATE_OPTSPEC + DEVINFO_CREATE_OPTMAX))
265            info->p = mess_device_get_info_ptr(&mess_device->io_device.devclass, state - DEVINFO_PTR_IMAGE_CREATE_OPTSPEC + MESS_DEVINFO_PTR_CREATE_OPTSPEC);
266         else if ((state >= DEVINFO_STR_IMAGE_CREATE_OPTNAME) && (state < DEVINFO_STR_IMAGE_CREATE_OPTNAME + DEVINFO_CREATE_OPTMAX))
267            info->s = mess_device_get_info_ptr(&mess_device->io_device.devclass, state - DEVINFO_STR_IMAGE_CREATE_OPTNAME + MESS_DEVINFO_STR_CREATE_OPTNAME);
268         else if ((state >= DEVINFO_STR_IMAGE_CREATE_OPTDESC) && (state < DEVINFO_STR_IMAGE_CREATE_OPTDESC + DEVINFO_CREATE_OPTMAX))
269            info->s = mess_device_get_info_ptr(&mess_device->io_device.devclass, state - DEVINFO_STR_IMAGE_CREATE_OPTDESC + MESS_DEVINFO_STR_CREATE_OPTDESC);
270         else if ((state >= DEVINFO_STR_IMAGE_CREATE_OPTEXTS) && (state < DEVINFO_STR_IMAGE_CREATE_OPTEXTS + DEVINFO_CREATE_OPTMAX))
271            info->s = mess_device_get_info_ptr(&mess_device->io_device.devclass, state - DEVINFO_STR_IMAGE_CREATE_OPTEXTS + MESS_DEVINFO_STR_CREATE_OPTEXTS);
272         break;
261273   }
262274}
263275
r3035r3036
378390      createimage_optcount = (int) mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_CREATE_OPTCOUNT);
379391      if (createimage_optcount > 0)
380392      {
381         if (createimage_optcount > MESS_DEVINFO_CREATE_OPTMAX)
393         if (createimage_optcount > DEVINFO_CREATE_OPTMAX)
382394            fatalerror("MESS_DEVINFO_INT_CREATE_OPTCOUNT: Too many options");
383395
384396         /* set up each option in the list */
src/mess/device.h
r3035r3036
3131
3232enum
3333{
34   MESS_DEVINFO_CREATE_OPTMAX = 32,
35
3634   /* --- the following bits of info are returned as 64-bit signed integers --- */
3735   MESS_DEVINFO_INT_FIRST = 0x00000,
3836
r3035r3036
6260   MESS_DEVINFO_PTR_GET_DISPOSITIONS,
6361   MESS_DEVINFO_PTR_CREATE_OPTGUIDE,
6462   MESS_DEVINFO_PTR_CREATE_OPTSPEC,
65   MESS_DEVINFO_PTR_VALIDITY_CHECK = MESS_DEVINFO_PTR_CREATE_OPTSPEC + MESS_DEVINFO_CREATE_OPTMAX,   /* R/O: int (*validity_check)(const mess_device_class *devclass) */
63   MESS_DEVINFO_PTR_VALIDITY_CHECK = MESS_DEVINFO_PTR_CREATE_OPTSPEC + DEVINFO_CREATE_OPTMAX,   /* R/O: int (*validity_check)(const mess_device_class *devclass) */
6664
6765   MESS_DEVINFO_PTR_DEV_SPECIFIC = 0x18000,               /* R/W: Device-specific values start here */
6866
r3035r3036
7472   MESS_DEVINFO_STR_FILE_EXTENSIONS,
7573
7674   MESS_DEVINFO_STR_CREATE_OPTNAME,
77   MESS_DEVINFO_STR_CREATE_OPTDESC = MESS_DEVINFO_STR_CREATE_OPTNAME + MESS_DEVINFO_CREATE_OPTMAX,
78   MESS_DEVINFO_STR_CREATE_OPTEXTS = MESS_DEVINFO_STR_CREATE_OPTDESC + MESS_DEVINFO_CREATE_OPTMAX,
75   MESS_DEVINFO_STR_CREATE_OPTDESC = MESS_DEVINFO_STR_CREATE_OPTNAME + DEVINFO_CREATE_OPTMAX,
76   MESS_DEVINFO_STR_CREATE_OPTEXTS = MESS_DEVINFO_STR_CREATE_OPTDESC + DEVINFO_CREATE_OPTMAX,
7977
80   MESS_DEVINFO_STR_NAME = MESS_DEVINFO_STR_CREATE_OPTEXTS + MESS_DEVINFO_CREATE_OPTMAX,
81   MESS_DEVINFO_STR_SHORT_NAME = MESS_DEVINFO_STR_NAME + MESS_DEVINFO_CREATE_OPTMAX,
78   MESS_DEVINFO_STR_NAME = MESS_DEVINFO_STR_CREATE_OPTEXTS + DEVINFO_CREATE_OPTMAX,
79   MESS_DEVINFO_STR_SHORT_NAME = MESS_DEVINFO_STR_NAME + DEVINFO_CREATE_OPTMAX,
8280   MESS_DEVINFO_STR_DESCRIPTION = MESS_DEVINFO_STR_SHORT_NAME + MAX_DEV_INSTANCES,
8381
8482   MESS_DEVINFO_STR_DEV_SPECIFIC = 0x28000,               /* R/W: Device-specific values start here */
src/mess/devices/mflopimg.c
r3035r3036
441441
442442      default:
443443         floppy_options = mess_device_get_info_ptr(devclass, MESS_DEVINFO_PTR_FLOPPY_OPTIONS);
444         if ((state >= MESS_DEVINFO_STR_CREATE_OPTNAME) && (state < MESS_DEVINFO_STR_CREATE_OPTNAME + MESS_DEVINFO_CREATE_OPTMAX))
444         if ((state >= MESS_DEVINFO_STR_CREATE_OPTNAME) && (state < MESS_DEVINFO_STR_CREATE_OPTNAME + DEVINFO_CREATE_OPTMAX))
445445         {
446446            info->s = (void *) floppy_options[state - MESS_DEVINFO_STR_CREATE_OPTNAME].name;
447447         }
448         else if ((state >= MESS_DEVINFO_STR_CREATE_OPTDESC) && (state < MESS_DEVINFO_STR_CREATE_OPTDESC + MESS_DEVINFO_CREATE_OPTMAX))
448         else if ((state >= MESS_DEVINFO_STR_CREATE_OPTDESC) && (state < MESS_DEVINFO_STR_CREATE_OPTDESC + DEVINFO_CREATE_OPTMAX))
449449         {
450450            info->s = (void *) floppy_options[state - MESS_DEVINFO_STR_CREATE_OPTDESC].description;
451451         }
452         else if ((state >= MESS_DEVINFO_STR_CREATE_OPTEXTS) && (state < MESS_DEVINFO_STR_CREATE_OPTEXTS + MESS_DEVINFO_CREATE_OPTMAX))
452         else if ((state >= MESS_DEVINFO_STR_CREATE_OPTEXTS) && (state < MESS_DEVINFO_STR_CREATE_OPTEXTS + DEVINFO_CREATE_OPTMAX))
453453         {
454454            info->s = (void *) floppy_options[state - MESS_DEVINFO_STR_CREATE_OPTEXTS].extensions;
455455         }
456         else if ((state >= MESS_DEVINFO_PTR_CREATE_OPTSPEC) && (state < MESS_DEVINFO_PTR_CREATE_OPTSPEC + MESS_DEVINFO_CREATE_OPTMAX))
456         else if ((state >= MESS_DEVINFO_PTR_CREATE_OPTSPEC) && (state < MESS_DEVINFO_PTR_CREATE_OPTSPEC + DEVINFO_CREATE_OPTMAX))
457457         {
458458            info->p = (void *) floppy_options[state - MESS_DEVINFO_PTR_CREATE_OPTSPEC].param_guidelines;
459459         }
src/mess/mesvalid.c
r3035r3036
141141
142142   /* check creation options */
143143   optcount = mess_device_get_info_int(devclass, MESS_DEVINFO_INT_CREATE_OPTCOUNT);
144   if ((optcount < 0) || (optcount >= MESS_DEVINFO_CREATE_OPTMAX))
144   if ((optcount < 0) || (optcount >= DEVINFO_CREATE_OPTMAX))
145145   {
146146      mame_printf_error("%s: device type '%s' has an invalid creation optcount\n", devclass->gamedrv->name, device_typename(devtype));
147147      error = 1;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team