src/mess/image.c
| r2149 | r2150 | |
| 30 | 30 | TYPE DEFINITIONS |
| 31 | 31 | ***************************************************************************/ |
| 32 | 32 | |
| 33 | | struct _mess_image |
| 33 | typedef struct _image_slot_data image_slot_data; |
| 34 | struct _image_slot_data |
| 34 | 35 | { |
| 35 | 36 | /* variables that persist across image mounts */ |
| 36 | 37 | tag_pool tagpool; |
| 37 | 38 | object_pool *mempool; |
| 38 | | const struct IODevice *dev; |
| 39 | const device_config *dev; |
| 39 | 40 | |
| 40 | 41 | /* error related info */ |
| 41 | 42 | image_error_t err; |
| r2149 | r2150 | |
| 72 | 73 | struct _images_private |
| 73 | 74 | { |
| 74 | 75 | UINT32 multiple_dev_mask; |
| 75 | | mess_image images[1]; |
| 76 | int slot_count; |
| 77 | image_slot_data slots[1]; |
| 76 | 78 | }; |
| 77 | 79 | |
| 78 | 80 | |
| r2149 | r2150 | |
| 82 | 84 | ***************************************************************************/ |
| 83 | 85 | |
| 84 | 86 | static void image_exit(running_machine *machine); |
| 85 | | static void image_clear(mess_image *image); |
| 86 | | static void image_clear_error(mess_image *image); |
| 87 | static void image_clear(image_slot_data *image); |
| 88 | static void image_clear_error(image_slot_data *image); |
| 87 | 89 | |
| 88 | 90 | |
| 89 | 91 | |
| r2149 | r2150 | |
| 135 | 137 | |
| 136 | 138 | /* allocate the private structure */ |
| 137 | 139 | private_size = sizeof(*machine->images_data) + ((count - 1) |
| 138 | | * sizeof(machine->images_data->images[0])); |
| 140 | * sizeof(machine->images_data->slots[0])); |
| 139 | 141 | machine->images_data = (images_private *) auto_malloc(private_size); |
| 140 | 142 | memset(machine->images_data, '\0', private_size); |
| 141 | 143 | |
| 142 | 144 | /* some setup */ |
| 143 | 145 | machine->images_data->multiple_dev_mask = multiple_dev_mask; |
| 146 | machine->images_data->slot_count = count; |
| 144 | 147 | |
| 145 | 148 | /* initialize the devices */ |
| 146 | 149 | indx = 0; |
| 147 | 150 | for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev)) |
| 148 | 151 | { |
| 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; |
| 150 | 154 | |
| 155 | /* create a memory pool */ |
| 156 | machine->images_data->slots[indx].mempool = pool_alloc(memory_error); |
| 157 | |
| 151 | 158 | /* 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; |
| 154 | 161 | |
| 155 | 162 | if (dev->init != NULL) |
| 156 | 163 | { |
| 157 | | err = dev->init(&machine->images_data->images[indx]); |
| 164 | err = dev->init(machine->images_data->slots[indx].dev); |
| 158 | 165 | if (err != INIT_PASS) |
| 159 | 166 | return err; |
| 160 | 167 | } |
| r2149 | r2150 | |
| 173 | 180 | |
| 174 | 181 | static void image_exit(running_machine *machine) |
| 175 | 182 | { |
| 176 | | int indx; |
| 177 | | mess_image *image; |
| 183 | int indx, i; |
| 184 | image_slot_data *image; |
| 178 | 185 | const struct IODevice *dev; |
| 179 | 186 | |
| 180 | 187 | if (machine->images_data != NULL) |
| 181 | 188 | { |
| 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 | |
| 182 | 195 | /* unload all devices */ |
| 183 | 196 | image_unload_all(FALSE); |
| 184 | 197 | image_unload_all(TRUE); |
| r2149 | r2150 | |
| 188 | 201 | for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev)) |
| 189 | 202 | { |
| 190 | 203 | /* identify the image */ |
| 191 | | image = &machine->images_data->images[indx]; |
| 204 | image = &machine->images_data->slots[indx]; |
| 192 | 205 | |
| 193 | 206 | /* call the exit handler if appropriate */ |
| 194 | 207 | if (dev->exit != NULL) |
| 195 | | dev->exit(image); |
| 208 | dev->exit(image->dev); |
| 196 | 209 | |
| 197 | 210 | /* free the tagpool */ |
| 198 | 211 | tagpool_exit(&image->tagpool); |
| r2149 | r2150 | |
| 210 | 223 | indx++; |
| 211 | 224 | } |
| 212 | 225 | |
| 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 | |
| 213 | 232 | machine->images_data = NULL; |
| 214 | 233 | } |
| 215 | 234 | } |
| r2149 | r2150 | |
| 225 | 244 | an image |
| 226 | 245 | -------------------------------------------------*/ |
| 227 | 246 | |
| 228 | | static image_error_t set_image_filename(mess_image *image, const char *filename, const char *zippath) |
| 247 | static image_error_t set_image_filename(image_slot_data *image, const char *filename, const char *zippath) |
| 229 | 248 | { |
| 230 | 249 | image_error_t err = IMAGE_ERROR_SUCCESS; |
| 231 | 250 | astring *alloc_filename = NULL; |
| r2149 | r2150 | |
| 235 | 254 | int pos; |
| 236 | 255 | |
| 237 | 256 | /* create the directory string */ |
| 238 | | new_dir = filename ? image_strdup(image, filename) : NULL; |
| 257 | new_dir = filename ? image_strdup(image->dev, filename) : NULL; |
| 239 | 258 | for (pos = strlen(new_dir); (pos > 0); pos--) |
| 240 | 259 | { |
| 241 | 260 | if (strchr(":\\/", new_dir[pos - 1])) |
| r2149 | r2150 | |
| 253 | 272 | } |
| 254 | 273 | |
| 255 | 274 | /* copy the string */ |
| 256 | | new_name = image_strdup(image, filename); |
| 275 | new_name = image_strdup(image->dev, filename); |
| 257 | 276 | if (!new_name) |
| 258 | 277 | { |
| 259 | 278 | err = IMAGE_ERROR_OUTOFMEMORY; |
| r2149 | r2150 | |
| 269 | 288 | } |
| 270 | 289 | |
| 271 | 290 | /* 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) |
| 277 | 296 | free(image->working_directory); |
| 278 | 297 | image->name = new_name; |
| 279 | 298 | image->dir = new_dir; |
| r2149 | r2150 | |
| 292 | 311 | image is loaded |
| 293 | 312 | -------------------------------------------------*/ |
| 294 | 313 | |
| 295 | | static int is_loaded(mess_image *image) |
| 314 | static int is_loaded(image_slot_data *image) |
| 296 | 315 | { |
| 297 | | return image->file || image->ptr; |
| 316 | return (image->file != NULL) || (image->ptr != NULL); |
| 298 | 317 | } |
| 299 | 318 | |
| 300 | 319 | |
| r2149 | r2150 | |
| 304 | 323 | specific path |
| 305 | 324 | -------------------------------------------------*/ |
| 306 | 325 | |
| 307 | | static image_error_t load_zip_path(mess_image *image, const char *path) |
| 326 | static image_error_t load_zip_path(image_slot_data *image, const char *path) |
| 308 | 327 | { |
| 309 | 328 | image_error_t err = IMAGE_ERROR_FILENOTFOUND; |
| 310 | 329 | zip_file *zip = NULL; |
| r2149 | r2150 | |
| 365 | 384 | header = zip_file_first_file(zip); |
| 366 | 385 | |
| 367 | 386 | /* if we specified a zip partial path, find it */ |
| 368 | | if (zip_entry) |
| 387 | if (zip_entry != NULL) |
| 369 | 388 | { |
| 370 | | while(header) |
| 389 | while(header != NULL) |
| 371 | 390 | { |
| 372 | 391 | if (!mame_stricmp(header->filename, zip_entry)) |
| 373 | 392 | break; |
| r2149 | r2150 | |
| 376 | 395 | } |
| 377 | 396 | |
| 378 | 397 | /* were we successful? */ |
| 379 | | if (header) |
| 398 | if (header != NULL) |
| 380 | 399 | { |
| 381 | 400 | /* if no zip path was specified, we have to change the name */ |
| 382 | 401 | if (!zip_entry) |
| r2149 | r2150 | |
| 388 | 407 | } |
| 389 | 408 | |
| 390 | 409 | /* allocate space for this zip file */ |
| 391 | | ptr = image_malloc(image, header->uncompressed_length); |
| 410 | ptr = image_malloc(image->dev, header->uncompressed_length); |
| 392 | 411 | if (!ptr) |
| 393 | 412 | { |
| 394 | 413 | err = IMAGE_ERROR_OUTOFMEMORY; |
| r2149 | r2150 | |
| 420 | 439 | specific path |
| 421 | 440 | -------------------------------------------------*/ |
| 422 | 441 | |
| 423 | | static image_error_t load_image_by_path(mess_image *image, const char *software_path, |
| 442 | static image_error_t load_image_by_path(image_slot_data *image, const char *software_path, |
| 424 | 443 | const game_driver *gamedrv, UINT32 open_flags, const char *path) |
| 425 | 444 | { |
| 426 | 445 | file_error filerr = FILERR_NOT_FOUND; |
| r2149 | r2150 | |
| 500 | 519 | flags to use, and in what order |
| 501 | 520 | -------------------------------------------------*/ |
| 502 | 521 | |
| 503 | | static void determine_open_plan(mess_image *image, int is_create, UINT32 *open_plan) |
| 522 | static void determine_open_plan(image_slot_data *image, int is_create, UINT32 *open_plan) |
| 504 | 523 | { |
| 505 | 524 | unsigned int readable, writeable, creatable; |
| 506 | 525 | int i = 0; |
| 526 | const struct IODevice *iodev; |
| 507 | 527 | |
| 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) |
| 509 | 533 | { |
| 510 | | image->dev->getdispositions(image->dev, image_index_in_device(image), |
| 534 | iodev->getdispositions(iodev, image_index_in_device(image->dev), |
| 511 | 535 | &readable, &writeable, &creatable); |
| 512 | 536 | } |
| 513 | 537 | else |
| 514 | 538 | { |
| 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; |
| 518 | 542 | } |
| 519 | 543 | |
| 520 | 544 | /* emit flags */ |
| r2149 | r2150 | |
| 532 | 556 | |
| 533 | 557 | |
| 534 | 558 | /*------------------------------------------------- |
| 559 | find_image_slot - locates the slot for an |
| 560 | image |
| 561 | -------------------------------------------------*/ |
| 562 | |
| 563 | static 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 | /*------------------------------------------------- |
| 535 | 581 | image_load_internal - core image loading |
| 536 | 582 | -------------------------------------------------*/ |
| 537 | 583 | |
| 538 | | static int image_load_internal(running_machine *machine, mess_image *image, const char *path, |
| 584 | static int image_load_internal(const device_config *image, const char *path, |
| 539 | 585 | int is_create, int create_format, option_resolution *create_args) |
| 540 | 586 | { |
| 587 | running_machine *machine = image->machine; |
| 541 | 588 | image_error_t err; |
| 542 | 589 | const char *software_path; |
| 543 | 590 | char *software_path_list = NULL; |
| r2149 | r2150 | |
| 545 | 592 | const game_driver *gamedrv; |
| 546 | 593 | UINT32 open_plan[4]; |
| 547 | 594 | int i; |
| 595 | image_slot_data *slot = find_image_slot(image); |
| 596 | const struct IODevice *iodev = mess_device_from_core_device(image); |
| 548 | 597 | |
| 549 | 598 | /* 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"); |
| 552 | 601 | |
| 553 | 602 | /* we are now loading */ |
| 554 | | image->is_loading = 1; |
| 603 | slot->is_loading = 1; |
| 555 | 604 | |
| 556 | 605 | /* first unload the image */ |
| 557 | 606 | image_unload(image); |
| 558 | 607 | |
| 559 | 608 | /* 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) |
| 562 | 611 | goto done; |
| 563 | 612 | |
| 564 | 613 | /* 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) |
| 566 | 615 | mame_schedule_hard_reset(machine); |
| 567 | 616 | |
| 568 | 617 | /* determine open plan */ |
| 569 | | determine_open_plan(image, is_create, open_plan); |
| 618 | determine_open_plan(slot, is_create, open_plan); |
| 570 | 619 | |
| 571 | 620 | /* 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++) |
| 573 | 622 | { |
| 574 | 623 | software_path = software_path_list; |
| 575 | 624 | do |
| 576 | 625 | { |
| 577 | 626 | gamedrv = machine->gamedrv; |
| 578 | | while(!is_loaded(image) && gamedrv) |
| 627 | while(!is_loaded(slot) && (gamedrv != NULL)) |
| 579 | 628 | { |
| 580 | 629 | /* 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)) |
| 583 | 632 | goto done; |
| 584 | 633 | |
| 585 | 634 | /* move on to the next driver */ |
| r2149 | r2150 | |
| 590 | 639 | if (software_path) |
| 591 | 640 | software_path += strlen(software_path) + 1; |
| 592 | 641 | } |
| 593 | | while(!is_loaded(image) && software_path && *software_path); |
| 642 | while(!is_loaded(slot) && software_path && *software_path); |
| 594 | 643 | } |
| 595 | 644 | |
| 596 | 645 | /* did we fail to find the file? */ |
| 597 | | if (!is_loaded(image)) |
| 646 | if (!is_loaded(slot)) |
| 598 | 647 | { |
| 599 | | image->err = IMAGE_ERROR_FILENOTFOUND; |
| 648 | slot->err = IMAGE_ERROR_FILENOTFOUND; |
| 600 | 649 | goto done; |
| 601 | 650 | } |
| 602 | 651 | |
| 603 | 652 | /* if applicable, call device verify */ |
| 604 | | if (image->dev->imgverify && !image_has_been_created(image)) |
| 653 | if (iodev->imgverify && !image_has_been_created(image)) |
| 605 | 654 | { |
| 606 | 655 | /* access the memory */ |
| 607 | 656 | buffer = image_ptr(image); |
| 608 | 657 | if (!buffer) |
| 609 | 658 | { |
| 610 | | image->err = IMAGE_ERROR_OUTOFMEMORY; |
| 659 | slot->err = IMAGE_ERROR_OUTOFMEMORY; |
| 611 | 660 | goto done; |
| 612 | 661 | } |
| 613 | 662 | |
| 614 | 663 | /* verify the file */ |
| 615 | | err = image->dev->imgverify(buffer, core_fsize(image->file)); |
| 664 | err = iodev->imgverify(buffer, core_fsize(slot->file)); |
| 616 | 665 | if (err) |
| 617 | 666 | { |
| 618 | | image->err = IMAGE_ERROR_INVALIDIMAGE; |
| 667 | slot->err = IMAGE_ERROR_INVALIDIMAGE; |
| 619 | 668 | goto done; |
| 620 | 669 | } |
| 621 | 670 | } |
| 622 | 671 | |
| 623 | 672 | /* 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)) |
| 625 | 674 | { |
| 626 | | err = image->dev->create(image, create_format, create_args); |
| 675 | err = iodev->create(image, create_format, create_args); |
| 627 | 676 | if (err) |
| 628 | 677 | { |
| 629 | | if (!image->err) |
| 630 | | image->err = IMAGE_ERROR_UNSPECIFIED; |
| 678 | if (!slot->err) |
| 679 | slot->err = IMAGE_ERROR_UNSPECIFIED; |
| 631 | 680 | goto done; |
| 632 | 681 | } |
| 633 | 682 | } |
| 634 | | else if (image->dev->load) |
| 683 | else if (iodev->load != NULL) |
| 635 | 684 | { |
| 636 | 685 | /* using device load */ |
| 637 | | err = image->dev->load(image); |
| 686 | err = iodev->load(image); |
| 638 | 687 | if (err) |
| 639 | 688 | { |
| 640 | | if (!image->err) |
| 641 | | image->err = IMAGE_ERROR_UNSPECIFIED; |
| 689 | if (!slot->err) |
| 690 | slot->err = IMAGE_ERROR_UNSPECIFIED; |
| 642 | 691 | goto done; |
| 643 | 692 | } |
| 644 | 693 | } |
| r2149 | r2150 | |
| 648 | 697 | done: |
| 649 | 698 | if (software_path_list) |
| 650 | 699 | 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; |
| 655 | 704 | } |
| 656 | 705 | |
| 657 | 706 | |
| r2149 | r2150 | |
| 662 | 711 | |
| 663 | 712 | int image_load(mess_image *image, const char *path) |
| 664 | 713 | { |
| 665 | | return image_load_internal(Machine, image, path, FALSE, 0, NULL); |
| 714 | return image_load_internal(image, path, FALSE, 0, NULL); |
| 666 | 715 | } |
| 667 | 716 | |
| 668 | 717 | |
| r2149 | r2150 | |
| 673 | 722 | |
| 674 | 723 | int image_create(mess_image *image, const char *path, int create_format, option_resolution *create_args) |
| 675 | 724 | { |
| 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); |
| 677 | 726 | } |
| 678 | 727 | |
| 679 | 728 | |
| r2149 | r2150 | |
| 683 | 732 | to an image |
| 684 | 733 | -------------------------------------------------*/ |
| 685 | 734 | |
| 686 | | static void image_clear(mess_image *image) |
| 735 | static void image_clear(image_slot_data *image) |
| 687 | 736 | { |
| 688 | 737 | if (image->file) |
| 689 | 738 | { |
| r2149 | r2150 | |
| 714 | 763 | images |
| 715 | 764 | -------------------------------------------------*/ |
| 716 | 765 | |
| 717 | | static void image_unload_internal(mess_image *image, int is_final_unload) |
| 766 | static void image_unload_internal(image_slot_data *image, int is_final_unload) |
| 718 | 767 | { |
| 768 | const struct IODevice *iodev; |
| 769 | |
| 719 | 770 | /* is there an actual image loaded? */ |
| 720 | 771 | if (!is_loaded(image)) |
| 721 | 772 | return; |
| 722 | 773 | |
| 723 | 774 | /* 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); |
| 726 | 778 | |
| 727 | 779 | image_clear(image); |
| 728 | 780 | image_clear_error(image); |
| r2149 | r2150 | |
| 736 | 788 | |
| 737 | 789 | void image_unload(mess_image *image) |
| 738 | 790 | { |
| 739 | | image_unload_internal(image, FALSE); |
| 791 | image_slot_data *slot = find_image_slot(image); |
| 792 | image_unload_internal(slot, FALSE); |
| 740 | 793 | } |
| 741 | 794 | |
| 742 | 795 | |
| r2149 | r2150 | |
| 747 | 800 | |
| 748 | 801 | void image_unload_all(int ispreload) |
| 749 | 802 | { |
| 750 | | const struct IODevice *dev; |
| 751 | | mess_image *image; |
| 803 | int i; |
| 804 | image_slot_data *slot; |
| 805 | const struct IODevice *iodev; |
| 752 | 806 | |
| 753 | 807 | if (!ispreload) |
| 754 | 808 | mess_options_extract(Machine); |
| r2149 | r2150 | |
| 757 | 811 | ispreload = ispreload ? 1 : 0; |
| 758 | 812 | |
| 759 | 813 | /* 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++) |
| 761 | 815 | { |
| 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) |
| 763 | 820 | { |
| 764 | | image = image_from_device(dev); |
| 765 | | |
| 766 | 821 | /* unload this image */ |
| 767 | | image_unload_internal(image, TRUE); |
| 822 | image_unload_internal(slot, TRUE); |
| 768 | 823 | } |
| 769 | 824 | } |
| 770 | 825 | } |
| r2149 | r2150 | |
| 780 | 835 | error |
| 781 | 836 | -------------------------------------------------*/ |
| 782 | 837 | |
| 783 | | static void image_clear_error(mess_image *image) |
| 838 | static void image_clear_error(image_slot_data *image) |
| 784 | 839 | { |
| 785 | 840 | image->err = IMAGE_ERROR_SUCCESS; |
| 786 | | if (image->err_message) |
| 841 | if (image->err_message != NULL) |
| 787 | 842 | { |
| 788 | | image_freeptr(image, image->err_message); |
| 843 | image_freeptr(image->dev, image->err_message); |
| 789 | 844 | image->err_message = NULL; |
| 790 | 845 | } |
| 791 | 846 | } |
| r2149 | r2150 | |
| 811 | 866 | "Unspecified error" |
| 812 | 867 | }; |
| 813 | 868 | |
| 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]; |
| 815 | 871 | } |
| 816 | 872 | |
| 817 | 873 | |
| r2149 | r2150 | |
| 822 | 878 | |
| 823 | 879 | void image_seterror(mess_image *image, image_error_t err, const char *message) |
| 824 | 880 | { |
| 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) |
| 828 | 886 | { |
| 829 | | image->err_message = image_strdup(image, message); |
| 887 | slot->err_message = image_strdup(image, message); |
| 830 | 888 | } |
| 831 | 889 | } |
| 832 | 890 | |
| r2149 | r2150 | |
| 846 | 904 | raised if this happens |
| 847 | 905 | ****************************************************************************/ |
| 848 | 906 | |
| 849 | | void *image_alloctag(mess_image *img, const char *tag, size_t size) |
| 907 | void *image_alloctag(mess_image *image, const char *tag, size_t size) |
| 850 | 908 | { |
| 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); |
| 852 | 911 | } |
| 853 | 912 | |
| 854 | 913 | |
| 855 | 914 | |
| 856 | | void *image_lookuptag(mess_image *img, const char *tag) |
| 915 | void *image_lookuptag(mess_image *image, const char *tag) |
| 857 | 916 | { |
| 858 | | return tagpool_lookup(&img->tagpool, tag); |
| 917 | image_slot_data *slot = find_image_slot(image); |
| 918 | return tagpool_lookup(&slot->tagpool, tag); |
| 859 | 919 | } |
| 860 | 920 | |
| 861 | 921 | |
| r2149 | r2150 | |
| 867 | 927 | to be loaded |
| 868 | 928 | ****************************************************************************/ |
| 869 | 929 | |
| 870 | | static int read_hash_config(const char *sysname, mess_image *image) |
| 930 | static int read_hash_config(const char *sysname, image_slot_data *image) |
| 871 | 931 | { |
| 872 | 932 | hash_file *hashfile = NULL; |
| 873 | 933 | const struct hash_info *info = NULL; |
| r2149 | r2150 | |
| 883 | 943 | goto done; |
| 884 | 944 | |
| 885 | 945 | /* 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; |
| 891 | 951 | |
| 892 | 952 | done: |
| 893 | | if (hashfile) |
| 953 | if (hashfile != NULL) |
| 894 | 954 | hashfile_close(hashfile); |
| 895 | 955 | return !hashfile || !info; |
| 896 | 956 | } |
| r2149 | r2150 | |
| 925 | 985 | |
| 926 | 986 | |
| 927 | 987 | |
| 928 | | static int image_checkhash(mess_image *image) |
| 988 | static int image_checkhash(image_slot_data *image) |
| 929 | 989 | { |
| 930 | 990 | const game_driver *drv; |
| 931 | 991 | const struct IODevice *dev; |
| r2149 | r2150 | |
| 939 | 999 | if (!image->hash && !image->writeable && !image->created) |
| 940 | 1000 | { |
| 941 | 1001 | /* initialize key variables */ |
| 942 | | dev = image_device(image); |
| 1002 | dev = mess_device_from_core_device(image->dev); |
| 943 | 1003 | |
| 944 | 1004 | /* do not cause a linear read of 600 megs please */ |
| 945 | 1005 | /* TODO: use SHA/MD5 in the CHD header as the hash */ |
| 946 | 1006 | if (dev->type == IO_CDROM) |
| 947 | 1007 | return FALSE; |
| 948 | 1008 | |
| 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); |
| 950 | 1010 | |
| 951 | | image->hash = image_strdup(image, hash_string); |
| 1011 | image->hash = image_strdup(image->dev, hash_string); |
| 952 | 1012 | |
| 953 | 1013 | /* now read the hash file */ |
| 954 | | drv = Machine->gamedrv; |
| 1014 | drv = image->dev->machine->gamedrv; |
| 955 | 1015 | do |
| 956 | 1016 | { |
| 957 | 1017 | rc = read_hash_config(drv->name, image); |
| 958 | 1018 | drv = mess_next_compatible_driver(drv); |
| 959 | 1019 | } |
| 960 | | while(rc && drv); |
| 1020 | while(rc && (drv != NULL)); |
| 961 | 1021 | } |
| 962 | 1022 | return TRUE; |
| 963 | 1023 | } |
| r2149 | r2150 | |
| 974 | 1034 | image_device |
| 975 | 1035 | -------------------------------------------------*/ |
| 976 | 1036 | |
| 977 | | const struct IODevice *image_device(mess_image *img) |
| 1037 | const struct IODevice *image_device(mess_image *image) |
| 978 | 1038 | { |
| 979 | | return img->dev; |
| 1039 | return mess_device_from_core_device(image); |
| 980 | 1040 | } |
| 981 | 1041 | |
| 982 | 1042 | |
| r2149 | r2150 | |
| 985 | 1045 | image_exists |
| 986 | 1046 | -------------------------------------------------*/ |
| 987 | 1047 | |
| 988 | | int image_exists(mess_image *img) |
| 1048 | int image_exists(mess_image *image) |
| 989 | 1049 | { |
| 990 | | return image_filename(img) != NULL; |
| 1050 | return image_filename(image) != NULL; |
| 991 | 1051 | } |
| 992 | 1052 | |
| 993 | 1053 | |
| r2149 | r2150 | |
| 996 | 1056 | image_slotexists |
| 997 | 1057 | -------------------------------------------------*/ |
| 998 | 1058 | |
| 999 | | int image_slotexists(mess_image *img) |
| 1059 | int image_slotexists(mess_image *image) |
| 1000 | 1060 | { |
| 1001 | 1061 | return TRUE; |
| 1002 | 1062 | } |
| r2149 | r2150 | |
| 1007 | 1067 | image_filename |
| 1008 | 1068 | -------------------------------------------------*/ |
| 1009 | 1069 | |
| 1010 | | const char *image_filename(mess_image *img) |
| 1070 | const char *image_filename(mess_image *image) |
| 1011 | 1071 | { |
| 1012 | | return img->name; |
| 1072 | image_slot_data *slot = find_image_slot(image); |
| 1073 | return slot->name; |
| 1013 | 1074 | } |
| 1014 | 1075 | |
| 1015 | 1076 | |
| r2149 | r2150 | |
| 1018 | 1079 | image_basename |
| 1019 | 1080 | -------------------------------------------------*/ |
| 1020 | 1081 | |
| 1021 | | const char *image_basename(mess_image *img) |
| 1082 | const char *image_basename(mess_image *image) |
| 1022 | 1083 | { |
| 1023 | | return osd_basename((char *) image_filename(img)); |
| 1084 | return osd_basename((char *) image_filename(image)); |
| 1024 | 1085 | } |
| 1025 | 1086 | |
| 1026 | 1087 | |
| r2149 | r2150 | |
| 1029 | 1090 | image_basename_noext |
| 1030 | 1091 | -------------------------------------------------*/ |
| 1031 | 1092 | |
| 1032 | | const char *image_basename_noext(mess_image *img) |
| 1093 | const char *image_basename_noext(mess_image *image) |
| 1033 | 1094 | { |
| 1034 | 1095 | const char *s; |
| 1035 | 1096 | char *ext; |
| 1097 | image_slot_data *slot = find_image_slot(image); |
| 1036 | 1098 | |
| 1037 | | if (!img->basename_noext) |
| 1099 | if (!slot->basename_noext) |
| 1038 | 1100 | { |
| 1039 | | s = image_basename(img); |
| 1101 | s = image_basename(image); |
| 1040 | 1102 | if (s) |
| 1041 | 1103 | { |
| 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, '.'); |
| 1044 | 1106 | if (ext) |
| 1045 | 1107 | *ext = '\0'; |
| 1046 | 1108 | } |
| 1047 | 1109 | } |
| 1048 | | return img->basename_noext; |
| 1110 | return slot->basename_noext; |
| 1049 | 1111 | } |
| 1050 | 1112 | |
| 1051 | 1113 | |
| r2149 | r2150 | |
| 1054 | 1116 | image_filetype |
| 1055 | 1117 | -------------------------------------------------*/ |
| 1056 | 1118 | |
| 1057 | | const char *image_filetype(mess_image *img) |
| 1119 | const char *image_filetype(mess_image *image) |
| 1058 | 1120 | { |
| 1059 | 1121 | const char *s; |
| 1060 | | s = image_filename(img); |
| 1061 | | if (s) |
| 1122 | s = image_filename(image); |
| 1123 | if (s != NULL) |
| 1062 | 1124 | s = strrchr(s, '.'); |
| 1063 | 1125 | return s ? s+1 : NULL; |
| 1064 | 1126 | } |
| r2149 | r2150 | |
| 1071 | 1133 | |
| 1072 | 1134 | const char *image_filedir(mess_image *image) |
| 1073 | 1135 | { |
| 1074 | | return image->dir; |
| 1136 | image_slot_data *slot = find_image_slot(image); |
| 1137 | return slot->dir; |
| 1075 | 1138 | } |
| 1076 | 1139 | |
| 1077 | 1140 | |
| r2149 | r2150 | |
| 1082 | 1145 | |
| 1083 | 1146 | core_file *image_core_file(mess_image *image) |
| 1084 | 1147 | { |
| 1085 | | return image->file; |
| 1148 | image_slot_data *slot = find_image_slot(image); |
| 1149 | return slot->file; |
| 1086 | 1150 | } |
| 1087 | 1151 | |
| 1088 | 1152 | |
| r2149 | r2150 | |
| 1097 | 1161 | int id; |
| 1098 | 1162 | static char buf[64]; |
| 1099 | 1163 | |
| 1100 | | dev = image_device(image); |
| 1164 | dev = mess_device_from_core_device(image); |
| 1101 | 1165 | id = image_index_in_device(image); |
| 1102 | 1166 | return dev->name(dev, id, buf, sizeof(buf) / sizeof(buf[0])); |
| 1103 | 1167 | } |
| r2149 | r2150 | |
| 1108 | 1172 | check_for_file |
| 1109 | 1173 | -------------------------------------------------*/ |
| 1110 | 1174 | |
| 1111 | | static void check_for_file(mess_image *image) |
| 1175 | static void check_for_file(image_slot_data *image) |
| 1112 | 1176 | { |
| 1113 | 1177 | assert_always(image->file != NULL, "Illegal operation on unmounted image"); |
| 1114 | 1178 | } |
| r2149 | r2150 | |
| 1121 | 1185 | |
| 1122 | 1186 | UINT64 image_length(mess_image *image) |
| 1123 | 1187 | { |
| 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); |
| 1126 | 1191 | } |
| 1127 | 1192 | |
| 1128 | 1193 | |
| r2149 | r2150 | |
| 1131 | 1196 | image_hash |
| 1132 | 1197 | -------------------------------------------------*/ |
| 1133 | 1198 | |
| 1134 | | const char *image_hash(mess_image *img) |
| 1199 | const char *image_hash(mess_image *image) |
| 1135 | 1200 | { |
| 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; |
| 1138 | 1204 | } |
| 1139 | 1205 | |
| 1140 | 1206 | |
| r2149 | r2150 | |
| 1143 | 1209 | image_crc |
| 1144 | 1210 | -------------------------------------------------*/ |
| 1145 | 1211 | |
| 1146 | | UINT32 image_crc(mess_image *img) |
| 1212 | UINT32 image_crc(mess_image *image) |
| 1147 | 1213 | { |
| 1148 | 1214 | const char *hash_string; |
| 1149 | 1215 | UINT32 crc = 0; |
| 1150 | 1216 | |
| 1151 | | hash_string = image_hash(img); |
| 1152 | | if (hash_string) |
| 1217 | hash_string = image_hash(image); |
| 1218 | if (hash_string != NULL) |
| 1153 | 1219 | crc = hash_data_extract_crc32(hash_string); |
| 1154 | 1220 | |
| 1155 | 1221 | return crc; |
| r2149 | r2150 | |
| 1161 | 1227 | image_is_writable |
| 1162 | 1228 | -------------------------------------------------*/ |
| 1163 | 1229 | |
| 1164 | | int image_is_writable(mess_image *img) |
| 1230 | int image_is_writable(mess_image *image) |
| 1165 | 1231 | { |
| 1166 | | return img->writeable; |
| 1232 | image_slot_data *slot = find_image_slot(image); |
| 1233 | return slot->writeable; |
| 1167 | 1234 | } |
| 1168 | 1235 | |
| 1169 | 1236 | |
| r2149 | r2150 | |
| 1172 | 1239 | image_has_been_created |
| 1173 | 1240 | -------------------------------------------------*/ |
| 1174 | 1241 | |
| 1175 | | int image_has_been_created(mess_image *img) |
| 1242 | int image_has_been_created(mess_image *image) |
| 1176 | 1243 | { |
| 1177 | | return img->created; |
| 1244 | image_slot_data *slot = find_image_slot(image); |
| 1245 | return slot->created; |
| 1178 | 1246 | } |
| 1179 | 1247 | |
| 1180 | 1248 | |
| r2149 | r2150 | |
| 1183 | 1251 | image_make_readonly |
| 1184 | 1252 | -------------------------------------------------*/ |
| 1185 | 1253 | |
| 1186 | | void image_make_readonly(mess_image *img) |
| 1254 | void image_make_readonly(mess_image *image) |
| 1187 | 1255 | { |
| 1188 | | img->writeable = 0; |
| 1256 | image_slot_data *slot = find_image_slot(image); |
| 1257 | slot->writeable = 0; |
| 1189 | 1258 | } |
| 1190 | 1259 | |
| 1191 | 1260 | |
| r2149 | r2150 | |
| 1196 | 1265 | |
| 1197 | 1266 | UINT32 image_fread(mess_image *image, void *buffer, UINT32 length) |
| 1198 | 1267 | { |
| 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); |
| 1201 | 1271 | } |
| 1202 | 1272 | |
| 1203 | 1273 | |
| r2149 | r2150 | |
| 1208 | 1278 | |
| 1209 | 1279 | UINT32 image_fwrite(mess_image *image, const void *buffer, UINT32 length) |
| 1210 | 1280 | { |
| 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); |
| 1213 | 1284 | } |
| 1214 | 1285 | |
| 1215 | 1286 | |
| r2149 | r2150 | |
| 1220 | 1291 | |
| 1221 | 1292 | int image_fseek(mess_image *image, INT64 offset, int whence) |
| 1222 | 1293 | { |
| 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); |
| 1225 | 1297 | } |
| 1226 | 1298 | |
| 1227 | 1299 | |
| r2149 | r2150 | |
| 1232 | 1304 | |
| 1233 | 1305 | UINT64 image_ftell(mess_image *image) |
| 1234 | 1306 | { |
| 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); |
| 1237 | 1310 | } |
| 1238 | 1311 | |
| 1239 | 1312 | |
| r2149 | r2150 | |
| 1258 | 1331 | |
| 1259 | 1332 | int image_feof(mess_image *image) |
| 1260 | 1333 | { |
| 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); |
| 1263 | 1337 | } |
| 1264 | 1338 | |
| 1265 | 1339 | |
| r2149 | r2150 | |
| 1270 | 1344 | |
| 1271 | 1345 | void *image_ptr(mess_image *image) |
| 1272 | 1346 | { |
| 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); |
| 1275 | 1350 | } |
| 1276 | 1351 | |
| 1277 | 1352 | |
| r2149 | r2150 | |
| 1286 | 1361 | actually exists |
| 1287 | 1362 | -------------------------------------------------*/ |
| 1288 | 1363 | |
| 1289 | | static int try_change_working_directory(mess_image *image, const char *subdir) |
| 1364 | static int try_change_working_directory(image_slot_data *image, const char *subdir) |
| 1290 | 1365 | { |
| 1291 | 1366 | osd_directory *directory; |
| 1292 | 1367 | const osd_directory_entry *entry; |
| r2149 | r2150 | |
| 1340 | 1415 | directory according to a few defaults |
| 1341 | 1416 | -------------------------------------------------*/ |
| 1342 | 1417 | |
| 1343 | | static void setup_working_directory(mess_image *image) |
| 1418 | static void setup_working_directory(image_slot_data *image) |
| 1344 | 1419 | { |
| 1345 | 1420 | char mess_directory[1024]; |
| 1346 | 1421 | const game_driver *gamedrv; |
| r2149 | r2150 | |
| 1371 | 1446 | |
| 1372 | 1447 | const char *image_working_directory(mess_image *image) |
| 1373 | 1448 | { |
| 1449 | image_slot_data *slot = find_image_slot(image); |
| 1450 | |
| 1374 | 1451 | /* 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); |
| 1377 | 1454 | |
| 1378 | | return image->working_directory; |
| 1455 | return slot->working_directory; |
| 1379 | 1456 | } |
| 1380 | 1457 | |
| 1381 | 1458 | |
| r2149 | r2150 | |
| 1387 | 1464 | |
| 1388 | 1465 | void image_set_working_directory(mess_image *image, const char *working_directory) |
| 1389 | 1466 | { |
| 1467 | image_slot_data *slot = find_image_slot(image); |
| 1468 | |
| 1390 | 1469 | 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; |
| 1394 | 1473 | } |
| 1395 | 1474 | |
| 1396 | 1475 | |
| r2149 | r2150 | |
| 1405 | 1484 | |
| 1406 | 1485 | void *image_malloc(mess_image *image, size_t size) |
| 1407 | 1486 | { |
| 1408 | | assert(is_loaded(image) || image->is_loading); |
| 1409 | | return pool_malloc(image->mempool, size); |
| 1487 | return image_realloc(image, NULL, size); |
| 1410 | 1488 | } |
| 1411 | 1489 | |
| 1412 | 1490 | |
| 1413 | 1491 | |
| 1414 | 1492 | void *image_realloc(mess_image *image, void *ptr, size_t size) |
| 1415 | 1493 | { |
| 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); |
| 1418 | 1500 | } |
| 1419 | 1501 | |
| 1420 | 1502 | |
| 1421 | 1503 | |
| 1422 | 1504 | char *image_strdup(mess_image *image, const char *src) |
| 1423 | 1505 | { |
| 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); |
| 1426 | 1512 | } |
| 1427 | 1513 | |
| 1428 | 1514 | |
| r2149 | r2150 | |
| 1430 | 1516 | void image_freeptr(mess_image *image, void *ptr) |
| 1431 | 1517 | { |
| 1432 | 1518 | /* should really do something better here */ |
| 1433 | | pool_realloc(image->mempool, ptr, 0); |
| 1519 | image_realloc(image, ptr, 0); |
| 1434 | 1520 | } |
| 1435 | 1521 | |
| 1436 | 1522 | |
| r2149 | r2150 | |
| 1442 | 1528 | pertaining to that image in the CRC database |
| 1443 | 1529 | ****************************************************************************/ |
| 1444 | 1530 | |
| 1445 | | const char *image_longname(mess_image *img) |
| 1531 | const char *image_longname(mess_image *image) |
| 1446 | 1532 | { |
| 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; |
| 1449 | 1536 | } |
| 1450 | 1537 | |
| 1451 | 1538 | |
| 1452 | 1539 | |
| 1453 | | const char *image_manufacturer(mess_image *img) |
| 1540 | const char *image_manufacturer(mess_image *image) |
| 1454 | 1541 | { |
| 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; |
| 1457 | 1545 | } |
| 1458 | 1546 | |
| 1459 | 1547 | |
| 1460 | 1548 | |
| 1461 | | const char *image_year(mess_image *img) |
| 1549 | const char *image_year(mess_image *image) |
| 1462 | 1550 | { |
| 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; |
| 1465 | 1554 | } |
| 1466 | 1555 | |
| 1467 | 1556 | |
| 1468 | 1557 | |
| 1469 | | const char *image_playable(mess_image *img) |
| 1558 | const char *image_playable(mess_image *image) |
| 1470 | 1559 | { |
| 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; |
| 1473 | 1563 | } |
| 1474 | 1564 | |
| 1475 | 1565 | |
| 1476 | 1566 | |
| 1477 | | const char *image_extrainfo(mess_image *img) |
| 1567 | const char *image_extrainfo(mess_image *image) |
| 1478 | 1568 | { |
| 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; |
| 1481 | 1572 | } |
| 1482 | 1573 | |
| 1483 | 1574 | |
| r2149 | r2150 | |
| 1570 | 1661 | |
| 1571 | 1662 | int image_absolute_index(mess_image *image) |
| 1572 | 1663 | { |
| 1573 | | return image - Machine->images_data->images; |
| 1664 | image_slot_data *slot = find_image_slot(image); |
| 1665 | return slot - Machine->images_data->slots; |
| 1574 | 1666 | } |
| 1575 | 1667 | |
| 1576 | 1668 | |
| 1577 | 1669 | |
| 1578 | 1670 | mess_image *image_from_absolute_index(int absolute_index) |
| 1579 | 1671 | { |
| 1580 | | return &Machine->images_data->images[absolute_index]; |
| 1672 | return Machine->images_data->slots[absolute_index].dev; |
| 1581 | 1673 | } |
| 1582 | 1674 | |
| 1583 | 1675 | |
| r2149 | r2150 | |
| 1592 | 1684 | |
| 1593 | 1685 | mess_image *image_from_device(const struct IODevice *device) |
| 1594 | 1686 | { |
| 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; |
| 1614 | 1688 | } |
| 1615 | 1689 | |
| 1616 | 1690 | |
| r2149 | r2150 | |
| 1628 | 1702 | { |
| 1629 | 1703 | if (dev->tag && !strcmp(dev->tag, devtag) && (device_index++ == id)) |
| 1630 | 1704 | { |
| 1631 | | image = &Machine->images_data->images[indx]; |
| 1705 | image = dev->devconfig; |
| 1632 | 1706 | break; |
| 1633 | 1707 | } |
| 1634 | 1708 | indx++; |
| r2149 | r2150 | |
| 1656 | 1730 | { |
| 1657 | 1731 | if ((type == dev->type) && (device_index++ == id)) |
| 1658 | 1732 | { |
| 1659 | | image = &Machine->images_data->images[indx]; |
| 1733 | image = dev->devconfig; |
| 1660 | 1734 | break; |
| 1661 | 1735 | } |
| 1662 | 1736 | indx++; |
| r2149 | r2150 | |
| 1668 | 1742 | |
| 1669 | 1743 | |
| 1670 | 1744 | |
| 1671 | | iodevice_t image_devtype(mess_image *img) |
| 1745 | iodevice_t image_devtype(mess_image *image) |
| 1672 | 1746 | { |
| 1673 | | return img->dev->type; |
| 1747 | const struct IODevice *iodev = mess_device_from_core_device(image); |
| 1748 | assert(iodev != NULL); |
| 1749 | return iodev->type; |
| 1674 | 1750 | } |
| 1675 | 1751 | |
| 1676 | 1752 | |
| 1677 | 1753 | |
| 1678 | | int image_index_in_device(mess_image *img) |
| 1754 | int image_index_in_device(mess_image *image) |
| 1679 | 1755 | { |
| 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; |
| 1682 | 1759 | } |