Previous 15994 Revisions Next

r2150 Saturday 29th March, 2008 at 22:53:04 UTC by Nathan Woods
Changes to the internal representation of MESS images; mess_image is now a
typedef for device_config
[docs]messnew.txt
[src/mess]image.c osdmess.h
[src/mess/devices]cassette.c flopdrv.c mflopimg.c

src/mess/devices/cassette.c
r2149r2150
267267   {
268268      /* creating an image */
269269      create_opts = (const struct CassetteOptions *) mess_device_get_info_ptr(&dev->devclass, MESS_DEVINFO_PTR_CASSETTE_OPTIONS);
270      err = cassette_create(image, &mess_ioprocs, &wavfile_format, create_opts, CASSETTE_FLAG_READWRITE|CASSETTE_FLAG_SAVEONEXIT, &tag->cassette);
270      err = cassette_create((void *) image, &mess_ioprocs, &wavfile_format, create_opts, CASSETTE_FLAG_READWRITE|CASSETTE_FLAG_SAVEONEXIT, &tag->cassette);
271271      if (err)
272272         goto error;
273273   }
r2149r2150
279279         is_writable = image_is_writable(image);
280280         cassette_flags = is_writable ? (CASSETTE_FLAG_READWRITE|CASSETTE_FLAG_SAVEONEXIT) : CASSETTE_FLAG_READONLY;
281281         extension = image_filetype(image);
282         err = cassette_open_choices(image, &mess_ioprocs, extension, formats, cassette_flags, &tag->cassette);
282         err = cassette_open_choices((void *) image, &mess_ioprocs, extension, formats, cassette_flags, &tag->cassette);
283283
284284         /* this is kind of a hack */
285285         if (err && is_writable)
src/mess/devices/flopdrv.c
r2149r2150
4545   pDrive->flags = 0;
4646   pDrive->index_pulse_callback = NULL;
4747   pDrive->ready_state_change_callback = NULL;
48   pDrive->index_timer = timer_alloc(floppy_drive_index_callback, img);
48   pDrive->index_timer = timer_alloc(floppy_drive_index_callback, (void *) img);
4949   pDrive->index = 0;
5050
5151   /* all drives are double-sided 80 track - can be overriden in driver! */
src/mess/devices/mflopimg.c
r2149r2150
287287   {
288288      /* creating an image */
289289      assert(create_format >= 0);
290      err = floppy_create(image, &mess_ioprocs, &floppy_options[create_format], create_args, &flopimg->floppy);
290      err = floppy_create((void *) image, &mess_ioprocs, &floppy_options[create_format], create_args, &flopimg->floppy);
291291      if (err)
292292         goto error;
293293   }
r2149r2150
296296      /* opening an image */
297297      floppy_flags = image_is_writable(image) ? FLOPPY_FLAGS_READWRITE : FLOPPY_FLAGS_READONLY;
298298      extension = image_filetype(image);
299      err = floppy_open_choices(image, &mess_ioprocs, extension, floppy_options, floppy_flags, &flopimg->floppy);
299      err = floppy_open_choices((void *) image, &mess_ioprocs, extension, floppy_options, floppy_flags, &flopimg->floppy);
300300      if (err)
301301         goto error;
302302   }
src/mess/image.c
r2149r2150
3030    TYPE DEFINITIONS
3131***************************************************************************/
3232
33struct _mess_image
33typedef struct _image_slot_data image_slot_data;
34struct _image_slot_data
3435{
3536   /* variables that persist across image mounts */
3637   tag_pool tagpool;
3738   object_pool *mempool;
38   const struct IODevice *dev;
39   const device_config *dev;
3940
4041   /* error related info */
4142   image_error_t err;
r2149r2150
7273struct _images_private
7374{
7475   UINT32 multiple_dev_mask;
75   mess_image images[1];
76   int slot_count;
77   image_slot_data slots[1];
7678};
7779
7880
r2149r2150
8284***************************************************************************/
8385
8486static void image_exit(running_machine *machine);
85static void image_clear(mess_image *image);
86static void image_clear_error(mess_image *image);
87static void image_clear(image_slot_data *image);
88static void image_clear_error(image_slot_data *image);
8789
8890
8991
r2149r2150
135137
136138   /* allocate the private structure */
137139   private_size = sizeof(*machine->images_data) + ((count - 1)
138      * sizeof(machine->images_data->images[0]));
140      * sizeof(machine->images_data->slots[0]));
139141   machine->images_data = (images_private *) auto_malloc(private_size);
140142   memset(machine->images_data, '\0', private_size);
141143
142144   /* some setup */
143145   machine->images_data->multiple_dev_mask = multiple_dev_mask;
146   machine->images_data->slot_count = count;
144147
145148   /* initialize the devices */
146149   indx = 0;
147150   for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev))
148151   {
149      machine->images_data->images[indx].mempool = pool_alloc(memory_error);
152      /* interim change until we use the normal device->start */
153      ((device_config *) dev->devconfig)->machine = machine;
150154
155      /* create a memory pool */
156      machine->images_data->slots[indx].mempool = pool_alloc(memory_error);
157
151158      /* setup the device */
152      tagpool_init(&machine->images_data->images[indx].tagpool);
153      machine->images_data->images[indx].dev = dev;
159      tagpool_init(&machine->images_data->slots[indx].tagpool);
160      machine->images_data->slots[indx].dev = dev->devconfig;
154161
155162      if (dev->init != NULL)
156163      {
157         err = dev->init(&machine->images_data->images[indx]);
164         err = dev->init(machine->images_data->slots[indx].dev);
158165         if (err != INIT_PASS)
159166            return err;
160167      }
r2149r2150
173180
174181static void image_exit(running_machine *machine)
175182{
176   int indx;
177   mess_image *image;
183   int indx, i;
184   image_slot_data *image;
178185   const struct IODevice *dev;
179186
180187   if (machine->images_data != NULL)
181188   {
189      /* interim hack until we use normal device startup/shutdown */
190      for (i = 0; i < machine->images_data->slot_count; i++)
191      {
192         ((device_config *) machine->images_data->slots[i].dev)->machine = machine;
193      }
194
182195      /* unload all devices */
183196      image_unload_all(FALSE);
184197      image_unload_all(TRUE);
r2149r2150
188201      for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev))
189202      {
190203         /* identify the image */
191         image = &machine->images_data->images[indx];
204         image = &machine->images_data->slots[indx];
192205
193206         /* call the exit handler if appropriate */
194207         if (dev->exit != NULL)
195            dev->exit(image);
208            dev->exit(image->dev);
196209
197210         /* free the tagpool */
198211         tagpool_exit(&image->tagpool);
r2149r2150
210223         indx++;
211224      }
212225
226      /* interim hack until we use normal device startup/shutdown */
227      for (i = 0; i < machine->images_data->slot_count; i++)
228      {
229         ((device_config *) machine->images_data->slots[i].dev)->machine = NULL;
230      }
231
213232      machine->images_data = NULL;
214233   }
215234}
r2149r2150
225244   an image
226245-------------------------------------------------*/
227246
228static image_error_t set_image_filename(mess_image *image, const char *filename, const char *zippath)
247static image_error_t set_image_filename(image_slot_data *image, const char *filename, const char *zippath)
229248{
230249   image_error_t err = IMAGE_ERROR_SUCCESS;
231250   astring *alloc_filename = NULL;
r2149r2150
235254   int pos;
236255
237256   /* create the directory string */
238   new_dir = filename ? image_strdup(image, filename) : NULL;
257   new_dir = filename ? image_strdup(image->dev, filename) : NULL;
239258   for (pos = strlen(new_dir); (pos > 0); pos--)
240259   {
241260      if (strchr(":\\/", new_dir[pos - 1]))
r2149r2150
253272   }
254273
255274   /* copy the string */
256   new_name = image_strdup(image, filename);
275   new_name = image_strdup(image->dev, filename);
257276   if (!new_name)
258277   {
259278      err = IMAGE_ERROR_OUTOFMEMORY;
r2149r2150
269288   }
270289
271290   /* set the new name and dir */
272   if (image->name)
273      image_freeptr(image, image->name);
274   if (image->dir)
275      image_freeptr(image, image->dir);
276   if (image->working_directory)
291   if (image->name != NULL)
292      image_freeptr(image->dev, image->name);
293   if (image->dir != NULL)
294      image_freeptr(image->dev, image->dir);
295   if (image->working_directory != NULL)
277296      free(image->working_directory);
278297   image->name = new_name;
279298   image->dir = new_dir;
r2149r2150
292311   image is loaded
293312-------------------------------------------------*/
294313
295static int is_loaded(mess_image *image)
314static int is_loaded(image_slot_data *image)
296315{
297   return image->file || image->ptr;
316   return (image->file != NULL) || (image->ptr != NULL);
298317}
299318
300319
r2149r2150
304323   specific path
305324-------------------------------------------------*/
306325
307static image_error_t load_zip_path(mess_image *image, const char *path)
326static image_error_t load_zip_path(image_slot_data *image, const char *path)
308327{
309328   image_error_t err = IMAGE_ERROR_FILENOTFOUND;
310329   zip_file *zip = NULL;
r2149r2150
365384      header = zip_file_first_file(zip);
366385
367386      /* if we specified a zip partial path, find it */
368      if (zip_entry)
387      if (zip_entry != NULL)
369388      {
370         while(header)
389         while(header != NULL)
371390         {
372391            if (!mame_stricmp(header->filename, zip_entry))
373392               break;
r2149r2150
376395      }
377396
378397      /* were we successful? */
379      if (header)
398      if (header != NULL)
380399      {
381400         /* if no zip path was specified, we have to change the name */
382401         if (!zip_entry)
r2149r2150
388407         }
389408
390409         /* allocate space for this zip file */
391         ptr = image_malloc(image, header->uncompressed_length);
410         ptr = image_malloc(image->dev, header->uncompressed_length);
392411         if (!ptr)
393412         {
394413            err = IMAGE_ERROR_OUTOFMEMORY;
r2149r2150
420439   specific path
421440-------------------------------------------------*/
422441
423static image_error_t load_image_by_path(mess_image *image, const char *software_path,
442static image_error_t load_image_by_path(image_slot_data *image, const char *software_path,
424443   const game_driver *gamedrv, UINT32 open_flags, const char *path)
425444{
426445   file_error filerr = FILERR_NOT_FOUND;
r2149r2150
500519   flags to use, and in what order
501520-------------------------------------------------*/
502521
503static void determine_open_plan(mess_image *image, int is_create, UINT32 *open_plan)
522static void determine_open_plan(image_slot_data *image, int is_create, UINT32 *open_plan)
504523{
505524   unsigned int readable, writeable, creatable;
506525   int i = 0;
526   const struct IODevice *iodev;
507527
508   if (image->dev->getdispositions)
528   /* access legacy MESS device */
529   iodev = mess_device_from_core_device(image->dev);
530
531   /* TODO - getdispositions is silly now that devices don't have counts */
532   if (iodev->getdispositions)
509533   {
510      image->dev->getdispositions(image->dev, image_index_in_device(image),
534      iodev->getdispositions(iodev, image_index_in_device(image->dev),
511535         &readable, &writeable, &creatable);
512536   }
513537   else
514538   {
515      readable = image->dev->readable;
516      writeable = image->dev->writeable;
517      creatable = image->dev->creatable;
539      readable = iodev->readable;
540      writeable = iodev->writeable;
541      creatable = iodev->creatable;
518542   }
519543
520544   /* emit flags */
r2149r2150
532556
533557
534558/*-------------------------------------------------
559    find_image_slot - locates the slot for an
560   image
561-------------------------------------------------*/
562
563static image_slot_data *find_image_slot(const device_config *image)
564{
565   int i;
566   images_private *images_data = image->machine->images_data;
567
568   for (i = 0; i < images_data->slot_count; i++)
569   {
570      if (images_data->slots[i].dev == image)
571      {
572         return &images_data->slots[i];
573      }
574   }
575   return NULL;
576}
577
578
579
580/*-------------------------------------------------
535581    image_load_internal - core image loading
536582-------------------------------------------------*/
537583
538static int image_load_internal(running_machine *machine, mess_image *image, const char *path,
584static int image_load_internal(const device_config *image, const char *path,
539585   int is_create, int create_format, option_resolution *create_args)
540586{
587   running_machine *machine = image->machine;
541588   image_error_t err;
542589   const char *software_path;
543590   char *software_path_list = NULL;
r2149r2150
545592   const game_driver *gamedrv;
546593   UINT32 open_plan[4];
547594   int i;
595   image_slot_data *slot = find_image_slot(image);
596   const struct IODevice *iodev = mess_device_from_core_device(image);
548597
549598   /* sanity checks */
550   assert_always(image, "image_load(): image is NULL");
551   assert_always(path, "image_load(): path is NULL");
599   assert_always(image != NULL, "image_load(): image is NULL");
600   assert_always(path != NULL, "image_load(): path is NULL");
552601
553602   /* we are now loading */
554   image->is_loading = 1;
603   slot->is_loading = 1;
555604
556605   /* first unload the image */
557606   image_unload(image);
558607
559608   /* record the filename */
560   image->err = set_image_filename(image, path, NULL);
561   if (image->err)
609   slot->err = set_image_filename(slot, path, NULL);
610   if (slot->err)
562611      goto done;
563612
564613   /* do we need to reset the CPU? */
565   if ((attotime_compare(timer_get_time(), attotime_zero) > 0) && image->dev->reset_on_load)
614   if ((attotime_compare(timer_get_time(), attotime_zero) > 0) && iodev->reset_on_load)
566615      mame_schedule_hard_reset(machine);
567616
568617   /* determine open plan */
569   determine_open_plan(image, is_create, open_plan);
618   determine_open_plan(slot, is_create, open_plan);
570619
571620   /* attempt to open the file in various ways */
572   for (i = 0; !image->file && open_plan[i]; i++)
621   for (i = 0; !slot->file && open_plan[i]; i++)
573622   {
574623      software_path = software_path_list;
575624      do
576625      {
577626         gamedrv = machine->gamedrv;
578         while(!is_loaded(image) && gamedrv)
627         while(!is_loaded(slot) && (gamedrv != NULL))
579628         {
580629            /* open the file */
581            image->err = load_image_by_path(image, software_path, gamedrv, open_plan[i], path);
582            if (image->err && (image->err != IMAGE_ERROR_FILENOTFOUND))
630            slot->err = load_image_by_path(slot, software_path, gamedrv, open_plan[i], path);
631            if (slot->err && (slot->err != IMAGE_ERROR_FILENOTFOUND))
583632               goto done;
584633
585634            /* move on to the next driver */
r2149r2150
590639         if (software_path)
591640            software_path += strlen(software_path) + 1;
592641      }
593      while(!is_loaded(image) && software_path && *software_path);
642      while(!is_loaded(slot) && software_path && *software_path);
594643   }
595644
596645   /* did we fail to find the file? */
597   if (!is_loaded(image))
646   if (!is_loaded(slot))
598647   {
599      image->err = IMAGE_ERROR_FILENOTFOUND;
648      slot->err = IMAGE_ERROR_FILENOTFOUND;
600649      goto done;
601650   }
602651
603652   /* if applicable, call device verify */
604   if (image->dev->imgverify && !image_has_been_created(image))
653   if (iodev->imgverify && !image_has_been_created(image))
605654   {
606655      /* access the memory */
607656      buffer = image_ptr(image);
608657      if (!buffer)
609658      {
610         image->err = IMAGE_ERROR_OUTOFMEMORY;
659         slot->err = IMAGE_ERROR_OUTOFMEMORY;
611660         goto done;
612661      }
613662
614663      /* verify the file */
615      err = image->dev->imgverify(buffer, core_fsize(image->file));
664      err = iodev->imgverify(buffer, core_fsize(slot->file));
616665      if (err)
617666      {
618         image->err = IMAGE_ERROR_INVALIDIMAGE;
667         slot->err = IMAGE_ERROR_INVALIDIMAGE;
619668         goto done;
620669      }
621670   }
622671
623672   /* call device load or create */
624   if (image_has_been_created(image) && image->dev->create)
673   if (image_has_been_created(image) && (iodev->create != NULL))
625674   {
626      err = image->dev->create(image, create_format, create_args);
675      err = iodev->create(image, create_format, create_args);
627676      if (err)
628677      {
629         if (!image->err)
630            image->err = IMAGE_ERROR_UNSPECIFIED;
678         if (!slot->err)
679            slot->err = IMAGE_ERROR_UNSPECIFIED;
631680         goto done;
632681      }
633682   }
634   else if (image->dev->load)
683   else if (iodev->load != NULL)
635684   {
636685      /* using device load */
637      err = image->dev->load(image);
686      err = iodev->load(image);
638687      if (err)
639688      {
640         if (!image->err)
641            image->err = IMAGE_ERROR_UNSPECIFIED;
689         if (!slot->err)
690            slot->err = IMAGE_ERROR_UNSPECIFIED;
642691         goto done;
643692      }
644693   }
r2149r2150
648697done:
649698   if (software_path_list)
650699      free(software_path_list);
651   if (image->err)
652      image_clear(image);
653   image->is_loading = 1;
654   return image->err ? INIT_FAIL : INIT_PASS;
700   if (slot->err)
701      image_clear(slot);
702   slot->is_loading = 1;
703   return slot->err ? INIT_FAIL : INIT_PASS;
655704}
656705
657706
r2149r2150
662711
663712int image_load(mess_image *image, const char *path)
664713{
665   return image_load_internal(Machine, image, path, FALSE, 0, NULL);
714   return image_load_internal(image, path, FALSE, 0, NULL);
666715}
667716
668717
r2149r2150
673722
674723int image_create(mess_image *image, const char *path, int create_format, option_resolution *create_args)
675724{
676   return image_load_internal(Machine, image, path, TRUE, create_format, create_args);
725   return image_load_internal(image, path, TRUE, create_format, create_args);
677726}
678727
679728
r2149r2150
683732   to an image
684733-------------------------------------------------*/
685734
686static void image_clear(mess_image *image)
735static void image_clear(image_slot_data *image)
687736{
688737   if (image->file)
689738   {
r2149r2150
714763   images
715764-------------------------------------------------*/
716765
717static void image_unload_internal(mess_image *image, int is_final_unload)
766static void image_unload_internal(image_slot_data *image, int is_final_unload)
718767{
768   const struct IODevice *iodev;
769
719770   /* is there an actual image loaded? */
720771   if (!is_loaded(image))
721772      return;
722773
723774   /* call the unload function */
724   if (image->dev->unload)
725      image->dev->unload(image);
775   iodev = mess_device_from_core_device(image->dev);
776   if (iodev->unload != NULL)
777      iodev->unload(image->dev);
726778
727779   image_clear(image);
728780   image_clear_error(image);
r2149r2150
736788
737789void image_unload(mess_image *image)
738790{
739   image_unload_internal(image, FALSE);
791   image_slot_data *slot = find_image_slot(image);
792   image_unload_internal(slot, FALSE);
740793}
741794
742795
r2149r2150
747800
748801void image_unload_all(int ispreload)
749802{
750   const struct IODevice *dev;
751   mess_image *image;
803   int i;
804   image_slot_data *slot;
805   const struct IODevice *iodev;
752806
753807   if (!ispreload)
754808      mess_options_extract(Machine);
r2149r2150
757811   ispreload = ispreload ? 1 : 0;
758812
759813   /* unload all devices with matching preload */
760   for (dev = mess_device_first_from_machine(Machine); dev != NULL; dev = mess_device_next(dev))
814   for (i = 0; i < Machine->images_data->slot_count; i++)
761815   {
762      if (dev->load_at_init == ispreload)
816      slot = &Machine->images_data->slots[i];
817      iodev = mess_device_from_core_device(slot->dev);
818
819      if (iodev->load_at_init == ispreload)
763820      {
764         image = image_from_device(dev);
765
766821         /* unload this image */
767         image_unload_internal(image, TRUE);
822         image_unload_internal(slot, TRUE);
768823      }
769824   }
770825}
r2149r2150
780835   error
781836-------------------------------------------------*/
782837
783static void image_clear_error(mess_image *image)
838static void image_clear_error(image_slot_data *image)
784839{
785840   image->err = IMAGE_ERROR_SUCCESS;
786   if (image->err_message)
841   if (image->err_message != NULL)
787842   {
788      image_freeptr(image, image->err_message);
843      image_freeptr(image->dev, image->err_message);
789844      image->err_message = NULL;
790845   }
791846}
r2149r2150
811866      "Unspecified error"
812867   };
813868
814   return image->err_message ? image->err_message : messages[image->err];
869   image_slot_data *slot = find_image_slot(image);
870   return slot->err_message ? slot->err_message : messages[slot->err];
815871}
816872
817873
r2149r2150
822878
823879void image_seterror(mess_image *image, image_error_t err, const char *message)
824880{
825   image_clear_error(image);
826   image->err = err;
827   if (message)
881   image_slot_data *slot = find_image_slot(image);
882
883   image_clear_error(slot);
884   slot->err = err;
885   if (message != NULL)
828886   {
829      image->err_message = image_strdup(image, message);
887      slot->err_message = image_strdup(image, message);
830888   }
831889}
832890
r2149r2150
846904  raised if this happens
847905****************************************************************************/
848906
849void *image_alloctag(mess_image *img, const char *tag, size_t size)
907void *image_alloctag(mess_image *image, const char *tag, size_t size)
850908{
851   return tagpool_alloc(&img->tagpool, tag, size);
909   image_slot_data *slot = find_image_slot(image);
910   return tagpool_alloc(&slot->tagpool, tag, size);
852911}
853912
854913
855914
856void *image_lookuptag(mess_image *img, const char *tag)
915void *image_lookuptag(mess_image *image, const char *tag)
857916{
858   return tagpool_lookup(&img->tagpool, tag);
917   image_slot_data *slot = find_image_slot(image);
918   return tagpool_lookup(&slot->tagpool, tag);
859919}
860920
861921
r2149r2150
867927  to be loaded
868928****************************************************************************/
869929
870static int read_hash_config(const char *sysname, mess_image *image)
930static int read_hash_config(const char *sysname, image_slot_data *image)
871931{
872932   hash_file *hashfile = NULL;
873933   const struct hash_info *info = NULL;
r2149r2150
883943      goto done;
884944
885945   /* copy the relevant entries */
886   image->longname      = info->longname      ? image_strdup(image, info->longname)      : NULL;
887   image->manufacturer   = info->manufacturer   ? image_strdup(image, info->manufacturer)   : NULL;
888   image->year         = info->year         ? image_strdup(image, info->year)         : NULL;
889   image->playable      = info->playable      ? image_strdup(image, info->playable)      : NULL;
890   image->extrainfo   = info->extrainfo      ? image_strdup(image, info->extrainfo)      : NULL;
946   image->longname      = info->longname      ? image_strdup(image->dev, info->longname)      : NULL;
947   image->manufacturer   = info->manufacturer   ? image_strdup(image->dev, info->manufacturer)   : NULL;
948   image->year         = info->year         ? image_strdup(image->dev, info->year)         : NULL;
949   image->playable      = info->playable      ? image_strdup(image->dev, info->playable)      : NULL;
950   image->extrainfo   = info->extrainfo      ? image_strdup(image->dev, info->extrainfo)      : NULL;
891951
892952done:
893   if (hashfile)
953   if (hashfile != NULL)
894954      hashfile_close(hashfile);
895955   return !hashfile || !info;
896956}
r2149r2150
925985
926986
927987
928static int image_checkhash(mess_image *image)
988static int image_checkhash(image_slot_data *image)
929989{
930990   const game_driver *drv;
931991   const struct IODevice *dev;
r2149r2150
939999   if (!image->hash && !image->writeable && !image->created)
9401000   {
9411001      /* initialize key variables */
942      dev = image_device(image);
1002      dev = mess_device_from_core_device(image->dev);
9431003
9441004      /* do not cause a linear read of 600 megs please */
9451005      /* TODO: use SHA/MD5 in the CHD header as the hash */
9461006      if (dev->type == IO_CDROM)
9471007         return FALSE;
9481008
949      run_hash(image, dev->partialhash, hash_string, HASH_CRC | HASH_MD5 | HASH_SHA1);
1009      run_hash(image->dev, dev->partialhash, hash_string, HASH_CRC | HASH_MD5 | HASH_SHA1);
9501010
951      image->hash = image_strdup(image, hash_string);
1011      image->hash = image_strdup(image->dev, hash_string);
9521012
9531013      /* now read the hash file */
954      drv = Machine->gamedrv;
1014      drv = image->dev->machine->gamedrv;
9551015      do
9561016      {
9571017         rc = read_hash_config(drv->name, image);
9581018         drv = mess_next_compatible_driver(drv);
9591019      }
960      while(rc && drv);
1020      while(rc && (drv != NULL));
9611021   }
9621022   return TRUE;
9631023}
r2149r2150
9741034    image_device
9751035-------------------------------------------------*/
9761036
977const struct IODevice *image_device(mess_image *img)
1037const struct IODevice *image_device(mess_image *image)
9781038{
979   return img->dev;
1039   return mess_device_from_core_device(image);
9801040}
9811041
9821042
r2149r2150
9851045    image_exists
9861046-------------------------------------------------*/
9871047
988int image_exists(mess_image *img)
1048int image_exists(mess_image *image)
9891049{
990   return image_filename(img) != NULL;
1050   return image_filename(image) != NULL;
9911051}
9921052
9931053
r2149r2150
9961056    image_slotexists
9971057-------------------------------------------------*/
9981058
999int image_slotexists(mess_image *img)
1059int image_slotexists(mess_image *image)
10001060{
10011061   return TRUE;
10021062}
r2149r2150
10071067    image_filename
10081068-------------------------------------------------*/
10091069
1010const char *image_filename(mess_image *img)
1070const char *image_filename(mess_image *image)
10111071{
1012   return img->name;
1072   image_slot_data *slot = find_image_slot(image);
1073   return slot->name;
10131074}
10141075
10151076
r2149r2150
10181079    image_basename
10191080-------------------------------------------------*/
10201081
1021const char *image_basename(mess_image *img)
1082const char *image_basename(mess_image *image)
10221083{
1023   return osd_basename((char *) image_filename(img));
1084   return osd_basename((char *) image_filename(image));
10241085}
10251086
10261087
r2149r2150
10291090    image_basename_noext
10301091-------------------------------------------------*/
10311092
1032const char *image_basename_noext(mess_image *img)
1093const char *image_basename_noext(mess_image *image)
10331094{
10341095   const char *s;
10351096   char *ext;
1097   image_slot_data *slot = find_image_slot(image);
10361098
1037   if (!img->basename_noext)
1099   if (!slot->basename_noext)
10381100   {
1039      s = image_basename(img);
1101      s = image_basename(image);
10401102      if (s)
10411103      {
1042         img->basename_noext = image_strdup(img, s);
1043         ext = strrchr(img->basename_noext, '.');
1104         slot->basename_noext = image_strdup(image, s);
1105         ext = strrchr(slot->basename_noext, '.');
10441106         if (ext)
10451107            *ext = '\0';
10461108      }
10471109   }
1048   return img->basename_noext;
1110   return slot->basename_noext;
10491111}
10501112
10511113
r2149r2150
10541116    image_filetype
10551117-------------------------------------------------*/
10561118
1057const char *image_filetype(mess_image *img)
1119const char *image_filetype(mess_image *image)
10581120{
10591121   const char *s;
1060   s = image_filename(img);
1061   if (s)
1122   s = image_filename(image);
1123   if (s != NULL)
10621124      s = strrchr(s, '.');
10631125   return s ? s+1 : NULL;
10641126}
r2149r2150
10711133
10721134const char *image_filedir(mess_image *image)
10731135{
1074   return image->dir;
1136   image_slot_data *slot = find_image_slot(image);
1137   return slot->dir;
10751138}
10761139
10771140
r2149r2150
10821145
10831146core_file *image_core_file(mess_image *image)
10841147{
1085   return image->file;
1148   image_slot_data *slot = find_image_slot(image);
1149   return slot->file;
10861150}
10871151
10881152
r2149r2150
10971161   int id;
10981162   static char buf[64];
10991163
1100   dev = image_device(image);
1164   dev = mess_device_from_core_device(image);
11011165   id = image_index_in_device(image);
11021166   return dev->name(dev, id, buf, sizeof(buf) / sizeof(buf[0]));
11031167}
r2149r2150
11081172    check_for_file
11091173-------------------------------------------------*/
11101174
1111static void check_for_file(mess_image *image)
1175static void check_for_file(image_slot_data *image)
11121176{
11131177   assert_always(image->file != NULL, "Illegal operation on unmounted image");
11141178}
r2149r2150
11211185
11221186UINT64 image_length(mess_image *image)
11231187{
1124   check_for_file(image);
1125   return core_fsize(image->file);
1188   image_slot_data *slot = find_image_slot(image);
1189   check_for_file(slot);
1190   return core_fsize(slot->file);
11261191}
11271192
11281193
r2149r2150
11311196    image_hash
11321197-------------------------------------------------*/
11331198
1134const char *image_hash(mess_image *img)
1199const char *image_hash(mess_image *image)
11351200{
1136   image_checkhash(img);
1137   return img->hash;
1201   image_slot_data *slot = find_image_slot(image);
1202   image_checkhash(slot);
1203   return slot->hash;
11381204}
11391205
11401206
r2149r2150
11431209    image_crc
11441210-------------------------------------------------*/
11451211
1146UINT32 image_crc(mess_image *img)
1212UINT32 image_crc(mess_image *image)
11471213{
11481214   const char *hash_string;
11491215   UINT32 crc = 0;
11501216
1151   hash_string = image_hash(img);
1152   if (hash_string)
1217   hash_string = image_hash(image);
1218   if (hash_string != NULL)
11531219      crc = hash_data_extract_crc32(hash_string);
11541220
11551221   return crc;
r2149r2150
11611227    image_is_writable
11621228-------------------------------------------------*/
11631229
1164int image_is_writable(mess_image *img)
1230int image_is_writable(mess_image *image)
11651231{
1166   return img->writeable;
1232   image_slot_data *slot = find_image_slot(image);
1233   return slot->writeable;
11671234}
11681235
11691236
r2149r2150
11721239    image_has_been_created
11731240-------------------------------------------------*/
11741241
1175int image_has_been_created(mess_image *img)
1242int image_has_been_created(mess_image *image)
11761243{
1177   return img->created;
1244   image_slot_data *slot = find_image_slot(image);
1245   return slot->created;
11781246}
11791247
11801248
r2149r2150
11831251    image_make_readonly
11841252-------------------------------------------------*/
11851253
1186void image_make_readonly(mess_image *img)
1254void image_make_readonly(mess_image *image)
11871255{
1188   img->writeable = 0;
1256   image_slot_data *slot = find_image_slot(image);
1257   slot->writeable = 0;
11891258}
11901259
11911260
r2149r2150
11961265
11971266UINT32 image_fread(mess_image *image, void *buffer, UINT32 length)
11981267{
1199   check_for_file(image);
1200   return core_fread(image->file, buffer, length);
1268   image_slot_data *slot = find_image_slot(image);
1269   check_for_file(slot);
1270   return core_fread(slot->file, buffer, length);
12011271}
12021272
12031273
r2149r2150
12081278
12091279UINT32 image_fwrite(mess_image *image, const void *buffer, UINT32 length)
12101280{
1211   check_for_file(image);
1212   return core_fwrite(image->file, buffer, length);
1281   image_slot_data *slot = find_image_slot(image);
1282   check_for_file(slot);
1283   return core_fwrite(slot->file, buffer, length);
12131284}
12141285
12151286
r2149r2150
12201291
12211292int image_fseek(mess_image *image, INT64 offset, int whence)
12221293{
1223   check_for_file(image);
1224   return core_fseek(image->file, offset, whence);
1294   image_slot_data *slot = find_image_slot(image);
1295   check_for_file(slot);
1296   return core_fseek(slot->file, offset, whence);
12251297}
12261298
12271299
r2149r2150
12321304
12331305UINT64 image_ftell(mess_image *image)
12341306{
1235   check_for_file(image);
1236   return core_ftell(image->file);
1307   image_slot_data *slot = find_image_slot(image);
1308   check_for_file(slot);
1309   return core_ftell(slot->file);
12371310}
12381311
12391312
r2149r2150
12581331
12591332int image_feof(mess_image *image)
12601333{
1261   check_for_file(image);
1262   return core_feof(image->file);
1334   image_slot_data *slot = find_image_slot(image);
1335   check_for_file(slot);
1336   return core_feof(slot->file);
12631337}
12641338
12651339
r2149r2150
12701344
12711345void *image_ptr(mess_image *image)
12721346{
1273   check_for_file(image);
1274   return (void *) core_fbuffer(image->file);
1347   image_slot_data *slot = find_image_slot(image);
1348   check_for_file(slot);
1349   return (void *) core_fbuffer(slot->file);
12751350}
12761351
12771352
r2149r2150
12861361   actually exists
12871362-------------------------------------------------*/
12881363
1289static int try_change_working_directory(mess_image *image, const char *subdir)
1364static int try_change_working_directory(image_slot_data *image, const char *subdir)
12901365{
12911366   osd_directory *directory;
12921367   const osd_directory_entry *entry;
r2149r2150
13401415   directory according to a few defaults
13411416-------------------------------------------------*/
13421417
1343static void setup_working_directory(mess_image *image)
1418static void setup_working_directory(image_slot_data *image)
13441419{
13451420   char mess_directory[1024];
13461421   const game_driver *gamedrv;
r2149r2150
13711446
13721447const char *image_working_directory(mess_image *image)
13731448{
1449   image_slot_data *slot = find_image_slot(image);
1450
13741451   /* check to see if we've never initialized the working directory */
1375   if (image->working_directory == NULL)
1376      setup_working_directory(image);
1452   if (slot->working_directory == NULL)
1453      setup_working_directory(slot);
13771454
1378   return image->working_directory;
1455   return slot->working_directory;
13791456}
13801457
13811458
r2149r2150
13871464
13881465void image_set_working_directory(mess_image *image, const char *working_directory)
13891466{
1467   image_slot_data *slot = find_image_slot(image);
1468
13901469   char *new_working_directory = mame_strdup(working_directory);
1391   if (image->working_directory)
1392      free(image->working_directory);
1393   image->working_directory = new_working_directory;
1470   if (slot->working_directory)
1471      free(slot->working_directory);
1472   slot->working_directory = new_working_directory;
13941473}
13951474
13961475
r2149r2150
14051484
14061485void *image_malloc(mess_image *image, size_t size)
14071486{
1408   assert(is_loaded(image) || image->is_loading);
1409   return pool_malloc(image->mempool, size);
1487   return image_realloc(image, NULL, size);
14101488}
14111489
14121490
14131491
14141492void *image_realloc(mess_image *image, void *ptr, size_t size)
14151493{
1416   assert(is_loaded(image) || image->is_loading);
1417   return pool_realloc(image->mempool, ptr, size);
1494   image_slot_data *slot = find_image_slot(image);
1495
1496   /* sanity checks */
1497   assert(is_loaded(slot) || slot->is_loading);
1498
1499   return pool_realloc(slot->mempool, ptr, size);
14181500}
14191501
14201502
14211503
14221504char *image_strdup(mess_image *image, const char *src)
14231505{
1424   assert(is_loaded(image) || image->is_loading);
1425   return pool_strdup(image->mempool, src);
1506   image_slot_data *slot = find_image_slot(image);
1507
1508   /* sanity checks */
1509   assert(is_loaded(slot) || slot->is_loading);
1510
1511   return pool_strdup(slot->mempool, src);
14261512}
14271513
14281514
r2149r2150
14301516void image_freeptr(mess_image *image, void *ptr)
14311517{
14321518   /* should really do something better here */
1433   pool_realloc(image->mempool, ptr, 0);
1519   image_realloc(image, ptr, 0);
14341520}
14351521
14361522
r2149r2150
14421528  pertaining to that image in the CRC database
14431529****************************************************************************/
14441530
1445const char *image_longname(mess_image *img)
1531const char *image_longname(mess_image *image)
14461532{
1447   image_checkhash(img);
1448   return img->longname;
1533   image_slot_data *slot = find_image_slot(image);
1534   image_checkhash(slot);
1535   return slot->longname;
14491536}
14501537
14511538
14521539
1453const char *image_manufacturer(mess_image *img)
1540const char *image_manufacturer(mess_image *image)
14541541{
1455   image_checkhash(img);
1456   return img->manufacturer;
1542   image_slot_data *slot = find_image_slot(image);
1543   image_checkhash(slot);
1544   return slot->manufacturer;
14571545}
14581546
14591547
14601548
1461const char *image_year(mess_image *img)
1549const char *image_year(mess_image *image)
14621550{
1463   image_checkhash(img);
1464   return img->year;
1551   image_slot_data *slot = find_image_slot(image);
1552   image_checkhash(slot);
1553   return slot->year;
14651554}
14661555
14671556
14681557
1469const char *image_playable(mess_image *img)
1558const char *image_playable(mess_image *image)
14701559{
1471   image_checkhash(img);
1472   return img->playable;
1560   image_slot_data *slot = find_image_slot(image);
1561   image_checkhash(slot);
1562   return slot->playable;
14731563}
14741564
14751565
14761566
1477const char *image_extrainfo(mess_image *img)
1567const char *image_extrainfo(mess_image *image)
14781568{
1479   image_checkhash(img);
1480   return img->extrainfo;
1569   image_slot_data *slot = find_image_slot(image);
1570   image_checkhash(slot);
1571   return slot->extrainfo;
14811572}
14821573
14831574
r2149r2150
15701661
15711662int image_absolute_index(mess_image *image)
15721663{
1573   return image - Machine->images_data->images;
1664   image_slot_data *slot = find_image_slot(image);
1665   return slot - Machine->images_data->slots;
15741666}
15751667
15761668
15771669
15781670mess_image *image_from_absolute_index(int absolute_index)
15791671{
1580   return &Machine->images_data->images[absolute_index];
1672   return Machine->images_data->slots[absolute_index].dev;
15811673}
15821674
15831675
r2149r2150
15921684
15931685mess_image *image_from_device(const struct IODevice *device)
15941686{
1595   int indx;
1596   mess_image *image = NULL;
1597   const struct IODevice *dev;
1598
1599   assert(Machine->images_data->images);
1600
1601   indx = 0;
1602   for (dev = mess_device_first_from_machine(Machine); dev != NULL; dev = mess_device_next(dev))
1603   {
1604      if (device == dev)
1605      {
1606         image = &Machine->images_data->images[indx];
1607         break;
1608      }
1609      indx++;
1610   }
1611
1612   assert(image != NULL);
1613   return image;
1687   return device->devconfig;
16141688}
16151689
16161690
r2149r2150
16281702   {
16291703      if (dev->tag && !strcmp(dev->tag, devtag) && (device_index++ == id))
16301704      {
1631         image = &Machine->images_data->images[indx];
1705         image = dev->devconfig;
16321706         break;
16331707      }
16341708      indx++;
r2149r2150
16561730   {
16571731      if ((type == dev->type) && (device_index++ == id))
16581732      {
1659         image = &Machine->images_data->images[indx];
1733         image = dev->devconfig;
16601734         break;
16611735      }
16621736      indx++;
r2149r2150
16681742
16691743
16701744
1671iodevice_t image_devtype(mess_image *img)
1745iodevice_t image_devtype(mess_image *image)
16721746{
1673   return img->dev->type;
1747   const struct IODevice *iodev = mess_device_from_core_device(image);
1748   assert(iodev != NULL);
1749   return iodev->type;
16741750}
16751751
16761752
16771753
1678int image_index_in_device(mess_image *img)
1754int image_index_in_device(mess_image *image)
16791755{
1680   assert(img);
1681   return img->dev->index_in_device;
1756   const struct IODevice *iodev = mess_device_from_core_device(image);
1757   assert(iodev != NULL);
1758   return iodev->index_in_device;
16821759}
src/mess/osdmess.h
r2149r2150
1212#include "osdcore.h"
1313#include "mamecore.h"
1414#include "options.h"
15#include "devintrf.h"
1516
1617struct _mame_file;
17typedef struct _mess_image mess_image;
18typedef const device_config mess_image;
1819
1920
2021
docs/messnew.txt
r2149r2150
3434
3535Source Changes:
3636----------------
37- MESS device changes:  Piggybacked MESS's device system on MAME's device
38  system.  Removed machine->devices[] array.  [Nate Woods]
37- Major changes to transition MESS's device system onto MAME's device system.
38  [Nate Woods]
3939
4040
4141

Previous 15994 Revisions Next


© 1998-2018 The MESS Team