src/mess/tools/messtest/testmess.c
| r3038 | r3039 | |
| 169 | 169 | static const messtest_command *current_command; |
| 170 | 170 | static int test_flags; |
| 171 | 171 | static int screenshot_num; |
| 172 | | static int format_index; |
| 173 | 172 | static UINT64 runtime_hash; |
| 174 | 173 | static void *wavptr; |
| 175 | 174 | static render_target *target; |
| r3038 | r3039 | |
| 740 | 739 | static void command_image_loadcreate(running_machine *machine) |
| 741 | 740 | { |
| 742 | 741 | const device_config *image; |
| 743 | | int i, format_index = 0; |
| 744 | 742 | const char *filename; |
| 745 | | const char *format; |
| 743 | const char *format_name; |
| 746 | 744 | char buf[128]; |
| 747 | 745 | image_device_info info; |
| 748 | 746 | const char *file_extensions; |
| 749 | 747 | astring *filepath; |
| 750 | 748 | int success; |
| 751 | 749 | const game_driver *gamedrv; |
| 750 | const image_device_format *format = NULL; |
| 752 | 751 | |
| 753 | 752 | /* look up the image slot */ |
| 754 | 753 | image = find_device_by_identity(machine, ¤t_command->u.image_args.device_ident); |
| r3038 | r3039 | |
| 759 | 758 | file_extensions = info.file_extensions; |
| 760 | 759 | |
| 761 | 760 | /* is an image format specified? */ |
| 762 | | format = current_command->u.image_args.format; |
| 763 | | if (format != NULL) |
| 761 | format_name = current_command->u.image_args.format; |
| 762 | if (format_name != NULL) |
| 764 | 763 | { |
| 765 | | const struct IODevice *dev = mess_device_from_core_device(image); |
| 766 | | |
| 767 | 764 | if (current_command->command_type != MESSTEST_COMMAND_IMAGE_CREATE) |
| 768 | 765 | { |
| 769 | 766 | state = STATE_ABORTED; |
| r3038 | r3039 | |
| 771 | 768 | return; |
| 772 | 769 | } |
| 773 | 770 | |
| 774 | | if (!dev->createimage_options) |
| 771 | /* look up the format name */ |
| 772 | format = image_device_get_named_creatable_format(image, format_name); |
| 773 | if (format == NULL) |
| 775 | 774 | { |
| 776 | 775 | state = STATE_ABORTED; |
| 777 | | report_message(MSG_FAILURE, "Cannot specify format for device"); |
| 776 | report_message(MSG_FAILURE, "Unknown device format '%s'", format_name); |
| 778 | 777 | return; |
| 779 | 778 | } |
| 780 | | |
| 781 | | for (i = 0; dev->createimage_options[i].name; i++) |
| 782 | | { |
| 783 | | if (!strcmp(format, dev->createimage_options[i].name)) |
| 784 | | break; |
| 785 | | } |
| 786 | | if (!dev->createimage_options[i].name) |
| 787 | | { |
| 788 | | state = STATE_ABORTED; |
| 789 | | report_message(MSG_FAILURE, "Unknown device '%s'", format); |
| 790 | | return; |
| 791 | | } |
| 792 | | format_index = i; |
| 793 | | file_extensions = dev->createimage_options[i].extensions; |
| 794 | 779 | } |
| 795 | 780 | |
| 796 | 781 | /* figure out the filename */ |
| r3038 | r3039 | |
| 813 | 798 | switch(current_command->command_type) |
| 814 | 799 | { |
| 815 | 800 | case MESSTEST_COMMAND_IMAGE_CREATE: |
| 816 | | success = (image_create(image, astring_c(filepath), format_index, NULL) == INIT_PASS); |
| 801 | success = (image_create(image, astring_c(filepath), format, NULL) == INIT_PASS); |
| 817 | 802 | break; |
| 818 | 803 | |
| 819 | 804 | case MESSTEST_COMMAND_IMAGE_LOAD: |
| r3038 | r3039 | |
| 1337 | 1322 | return; |
| 1338 | 1323 | |
| 1339 | 1324 | /* 'format' attribute */ |
| 1340 | | format_index = 0; |
| 1341 | 1325 | attr_node = xml_get_attribute(node, "format"); |
| 1342 | 1326 | new_command.u.image_args.format = attr_node ? attr_node->value : NULL; |
| 1343 | 1327 | |
src/mess/image.c
| r3038 | r3039 | |
| 38 | 38 | image_device_info info; |
| 39 | 39 | |
| 40 | 40 | /* creation info */ |
| 41 | const option_guide *create_option_guide; |
| 41 | 42 | image_device_format *formatlist; |
| 42 | 43 | |
| 43 | 44 | /* callbacks */ |
| r3038 | r3039 | |
| 231 | 232 | slot->unload = (device_image_unload_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_UNLOAD); |
| 232 | 233 | slot->verify = (device_image_verify_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_VERIFY); |
| 233 | 234 | |
| 235 | /* creation option guide */ |
| 236 | slot->create_option_guide = (const option_guide *) device_get_info_ptr(slot->dev, DEVINFO_PTR_IMAGE_CREATE_OPTGUIDE); |
| 237 | |
| 234 | 238 | /* creation formats */ |
| 235 | 239 | format_count = device_get_info_int(slot->dev, DEVINFO_INT_IMAGE_CREATE_OPTCOUNT); |
| 236 | 240 | formatptr = &slot->formatlist; |
| r3038 | r3039 | |
| 241 | 245 | memset(format, 0, sizeof(*format)); |
| 242 | 246 | |
| 243 | 247 | /* populate it */ |
| 248 | format->index = i; |
| 244 | 249 | format->name = auto_strdup(device_get_info_string(slot->dev, DEVINFO_STR_IMAGE_CREATE_OPTNAME + i)); |
| 245 | 250 | format->description = auto_strdup(device_get_info_string(slot->dev, DEVINFO_STR_IMAGE_CREATE_OPTDESC + i)); |
| 246 | 251 | format->extensions = auto_strdup(device_get_info_string(slot->dev, DEVINFO_STR_IMAGE_CREATE_OPTEXTS + i)); |
| r3038 | r3039 | |
| 596 | 601 | ****************************************************************************/ |
| 597 | 602 | |
| 598 | 603 | /*------------------------------------------------- |
| 604 | image_device_get_creation_option_guide - accesses |
| 605 | the creation option guide |
| 606 | -------------------------------------------------*/ |
| 607 | |
| 608 | const option_guide *image_device_get_creation_option_guide(const device_config *device) |
| 609 | { |
| 610 | image_slot_data *slot = find_image_slot(device); |
| 611 | return slot->create_option_guide; |
| 612 | } |
| 613 | |
| 614 | |
| 615 | |
| 616 | /*------------------------------------------------- |
| 599 | 617 | image_device_get_creatable_formats - accesses |
| 600 | 618 | the image formats available for image creation |
| 601 | 619 | -------------------------------------------------*/ |
| r3038 | r3039 | |
| 608 | 626 | |
| 609 | 627 | |
| 610 | 628 | |
| 629 | /*------------------------------------------------- |
| 630 | image_device_get_indexed_creatable_format - |
| 631 | accesses a specific image format available for |
| 632 | image creation by index |
| 633 | -------------------------------------------------*/ |
| 634 | |
| 635 | const image_device_format *image_device_get_indexed_creatable_format(const device_config *device, int index) |
| 636 | { |
| 637 | const image_device_format *format = image_device_get_creatable_formats(device); |
| 638 | while(index-- && (format != NULL)) |
| 639 | format = format->next; |
| 640 | return format; |
| 641 | } |
| 642 | |
| 643 | |
| 644 | |
| 645 | /*------------------------------------------------- |
| 646 | image_device_get_named_creatable_format - |
| 647 | accesses a specific image format available for |
| 648 | image creation by name |
| 649 | -------------------------------------------------*/ |
| 650 | |
| 651 | const image_device_format *image_device_get_named_creatable_format(const device_config *device, const char *format_name) |
| 652 | { |
| 653 | const image_device_format *format = image_device_get_creatable_formats(device); |
| 654 | while((format != NULL) && strcmp(format->name, format_name)) |
| 655 | format = format->next; |
| 656 | return format; |
| 657 | } |
| 658 | |
| 659 | |
| 660 | |
| 611 | 661 | /**************************************************************************** |
| 612 | 662 | IMAGE LOADING |
| 613 | 663 | ****************************************************************************/ |
| r3038 | r3039 | |
| 1052 | 1102 | image_create - create a MESS image |
| 1053 | 1103 | -------------------------------------------------*/ |
| 1054 | 1104 | |
| 1055 | | int image_create(const device_config *image, const char *path, int create_format, option_resolution *create_args) |
| 1105 | int image_create(const device_config *image, const char *path, const image_device_format *create_format, option_resolution *create_args) |
| 1056 | 1106 | { |
| 1057 | | return image_load_internal(image, path, TRUE, create_format, create_args); |
| 1107 | int format_index = (create_format != NULL) ? create_format->index : -1; |
| 1108 | return image_load_internal(image, path, TRUE, format_index, create_args); |
| 1058 | 1109 | } |
| 1059 | 1110 | |
| 1060 | 1111 | |
src/mess/image.h
| r3038 | r3039 | |
| 93 | 93 | struct _image_device_format |
| 94 | 94 | { |
| 95 | 95 | image_device_format *next; |
| 96 | int index; |
| 96 | 97 | const char *name; |
| 97 | 98 | const char *description; |
| 98 | 99 | const char *extensions; |
| r3038 | r3039 | |
| 119 | 120 | |
| 120 | 121 | /* --- the following bits of info are returned as pointers --- */ |
| 121 | 122 | DEVINFO_PTR_IMAGE_FIRST = DEVINFO_PTR_FIRST + 0x7000, |
| 123 | DEVINFO_PTR_IMAGE_CREATE_OPTGUIDE, |
| 122 | 124 | DEVINFO_PTR_IMAGE_CREATE_OPTSPEC, |
| 123 | 125 | |
| 124 | 126 | /* --- the following bits of info are returned as pointers to functions --- */ |
| r3038 | r3039 | |
| 181 | 183 | |
| 182 | 184 | /* ----- creation formats ----- */ |
| 183 | 185 | |
| 186 | /* accesses the creation option guide */ |
| 187 | const option_guide *image_device_get_creation_option_guide(const device_config *device); |
| 188 | |
| 189 | /* accesses the image formats available for image creation */ |
| 184 | 190 | const image_device_format *image_device_get_creatable_formats(const device_config *device); |
| 185 | 191 | |
| 192 | /* accesses a specific image format available for image creation by index */ |
| 193 | const image_device_format *image_device_get_indexed_creatable_format(const device_config *device, int index); |
| 186 | 194 | |
| 195 | /* accesses a specific image format available for image creation by name */ |
| 196 | const image_device_format *image_device_get_named_creatable_format(const device_config *device, const char *format_name); |
| 187 | 197 | |
| 198 | |
| 199 | |
| 188 | 200 | /**************************************************************************** |
| 189 | 201 | Device loading and unloading functions |
| 190 | 202 | |
| r3038 | r3039 | |
| 195 | 207 | |
| 196 | 208 | /* can be called by front ends */ |
| 197 | 209 | int image_load(const device_config *img, const char *name); |
| 198 | | int image_create(const device_config *img, const char *name, int create_format, option_resolution *create_args); |
| 210 | int image_create(const device_config *img, const char *name, const image_device_format *create_format, option_resolution *create_args); |
| 199 | 211 | void image_unload(const device_config *img); |
| 200 | 212 | |
| 201 | 213 | /* used to retrieve error information during image loading */ |
src/mess/device.c
| r3038 | r3039 | |
| 35 | 35 | { |
| 36 | 36 | struct IODevice io_device; |
| 37 | 37 | char string_buffer[1024]; |
| 38 | | create_image_options createimage_options[DEVINFO_CREATE_OPTMAX + 1]; |
| 39 | 38 | }; |
| 40 | 39 | |
| 41 | 40 | |
| r3038 | r3039 | |
| 237 | 236 | 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 | 237 | case DEVINFO_INT_IMAGE_CREATE_OPTCOUNT: info->i = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_CREATE_OPTCOUNT); break; |
| 239 | 238 | |
| 240 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 239 | /* --- the following bits of info are returned as pointers to data --- */ |
| 240 | case DEVINFO_PTR_IMAGE_CREATE_OPTGUIDE: info->p = mess_device_get_info_ptr(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE_OPTGUIDE); break; |
| 241 | |
| 242 | /* --- the following bits of info are returned as pointers to functions --- */ |
| 241 | 243 | case DEVINFO_FCT_SET_INFO: /* Nothing */ break; |
| 242 | 244 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(mess_device); break; |
| 243 | 245 | case DEVINFO_FCT_STOP: info->stop = DEVICE_STOP_NAME(mess_device); break; |
| r3038 | r3039 | |
| 331 | 333 | char dynamic_tag[32]; |
| 332 | 334 | device_config *device; |
| 333 | 335 | mess_device_config *mess_device; |
| 334 | | int i, j, count; |
| 336 | int i, count; |
| 335 | 337 | size_t string_buffer_pos = 0; |
| 336 | | int createimage_optcount; |
| 337 | 338 | device_getdispositions_func getdispositions; |
| 338 | 339 | unsigned int readable, writeable, creatable; |
| 339 | 340 | |
| r3038 | r3039 | |
| 385 | 386 | mess_device->io_device.start = (device_start_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_START); |
| 386 | 387 | mess_device->io_device.stop = (device_stop_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_STOP); |
| 387 | 388 | |
| 388 | | mess_device->io_device.createimage_optguide = (const option_guide *) mess_device_get_info_ptr(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE_OPTGUIDE); |
| 389 | | |
| 390 | | createimage_optcount = (int) mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_CREATE_OPTCOUNT); |
| 391 | | if (createimage_optcount > 0) |
| 392 | | { |
| 393 | | if (createimage_optcount > DEVINFO_CREATE_OPTMAX) |
| 394 | | fatalerror("MESS_DEVINFO_INT_CREATE_OPTCOUNT: Too many options"); |
| 395 | | |
| 396 | | /* set up each option in the list */ |
| 397 | | for (j = 0; j < createimage_optcount; j++) |
| 398 | | { |
| 399 | | info_string = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_CREATE_OPTNAME + j); |
| 400 | | mess_device->createimage_options[j].name = string_buffer_putstr(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos, info_string); |
| 401 | | |
| 402 | | info_string = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_CREATE_OPTDESC + j); |
| 403 | | mess_device->createimage_options[j].description = string_buffer_putstr(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos, info_string); |
| 404 | | |
| 405 | | info_string = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_CREATE_OPTEXTS + j); |
| 406 | | mess_device->createimage_options[j].extensions = string_buffer_putstr(mess_device->string_buffer, ARRAY_LENGTH(mess_device->string_buffer), &string_buffer_pos, info_string); |
| 407 | | |
| 408 | | mess_device->createimage_options[j].optspec = mess_device_get_info_ptr(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE_OPTSPEC + j); |
| 409 | | } |
| 410 | | |
| 411 | | /* terminate the list */ |
| 412 | | memset(&mess_device->createimage_options[createimage_optcount], 0, sizeof(mess_device->createimage_options[createimage_optcount])); |
| 413 | | |
| 414 | | /* assign the options */ |
| 415 | | mess_device->io_device.createimage_options = mess_device->createimage_options; |
| 416 | | } |
| 417 | | |
| 418 | 389 | /* determine the dispositions */ |
| 419 | 390 | getdispositions = (device_getdispositions_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_GET_DISPOSITIONS); |
| 420 | 391 | if (getdispositions != NULL) |
src/mess/osd/windows/menu.c
| r3038 | r3039 | |
| 578 | 578 | HWND wnd; |
| 579 | 579 | int format_combo_val; |
| 580 | 580 | const device_config *dev; |
| 581 | | const struct IODevice *iodev; |
| 582 | 581 | const option_guide *guide; |
| 583 | 582 | const char *optspec; |
| 584 | 583 | struct file_dialog_params *params; |
| r3038 | r3039 | |
| 596 | 595 | |
| 597 | 596 | // compute our parameters |
| 598 | 597 | dev = params->dev; |
| 599 | | iodev = mess_device_from_core_device(dev); |
| 600 | | guide = iodev->createimage_optguide; |
| 601 | | optspec = iodev->createimage_options[format_combo_val].optspec; |
| 598 | guide = image_device_get_creation_option_guide(dev); |
| 599 | optspec = image_device_get_indexed_creatable_format(dev, format_combo_val)->optspec; |
| 602 | 600 | |
| 603 | 601 | // set the default extension |
| 604 | 602 | CommDlg_OpenSave_SetDefExt(GetParent(dlgwnd), |
| 605 | | iodev->createimage_options[format_combo_val].extensions); |
| 603 | image_device_get_indexed_creatable_format(dev, format_combo_val)->extensions); |
| 606 | 604 | |
| 607 | 605 | // enumerate through all of the child windows |
| 608 | 606 | wnd = NULL; |
| r3038 | r3039 | |
| 652 | 650 | option_resolution *resolution; |
| 653 | 651 | struct storeval_optres_params *params; |
| 654 | 652 | const device_config *dev; |
| 655 | | const struct IODevice *iodev; |
| 656 | 653 | char buf[16]; |
| 657 | 654 | |
| 658 | 655 | params = (struct storeval_optres_params *) storeval_param; |
| 659 | 656 | dev = params->fdparams->dev; |
| 660 | | iodev = mess_device_from_core_device(dev); |
| 661 | 657 | |
| 662 | 658 | // create the resolution, if necessary |
| 663 | 659 | resolution = *(params->fdparams->create_args); |
| 664 | 660 | if (!resolution) |
| 665 | 661 | { |
| 666 | | resolution = option_resolution_create(iodev->createimage_optguide, iodev->createimage_options[*(params->fdparams->create_format)].optspec); |
| 662 | const option_guide *optguide = image_device_get_creation_option_guide(dev); |
| 663 | const image_device_format *format = image_device_get_indexed_creatable_format(dev, *(params->fdparams->create_format)); |
| 664 | |
| 665 | resolution = option_resolution_create(optguide, format->optspec); |
| 667 | 666 | if (!resolution) |
| 668 | 667 | return; |
| 669 | 668 | *(params->fdparams->create_args) = resolution; |
| r3038 | r3039 | |
| 683 | 682 | { |
| 684 | 683 | dialog_box *dialog; |
| 685 | 684 | const option_guide *guide_entry; |
| 686 | | int found, i, pos; |
| 685 | int found, pos; |
| 687 | 686 | char buf[256]; |
| 688 | 687 | struct file_dialog_params *params; |
| 689 | 688 | struct storeval_optres_params *storeval_params; |
| 690 | 689 | static const struct dialog_layout filedialog_layout = { 44, 220 }; |
| 691 | | const struct IODevice *iodev = mess_device_from_core_device(dev); |
| 690 | const image_device_format *format; |
| 692 | 691 | |
| 693 | 692 | // make the filter |
| 694 | 693 | pos = 0; |
| 695 | | for (i = 0; iodev->createimage_options[i].optspec; i++) |
| 694 | for (format = image_device_get_creatable_formats(dev); format != NULL; format = format->next) |
| 696 | 695 | { |
| 697 | | pos += add_filter_entry(filter + pos, filter_len - pos, |
| 698 | | iodev->createimage_options[i].description, |
| 699 | | iodev->createimage_options[i].extensions); |
| 696 | pos += add_filter_entry(filter + pos, filter_len - pos, format->description, format->extensions); |
| 700 | 697 | } |
| 701 | 698 | |
| 702 | 699 | // create the dialog |
| r3038 | r3039 | |
| 717 | 714 | goto error; |
| 718 | 715 | |
| 719 | 716 | // loop through the entries |
| 720 | | for (guide_entry = iodev->createimage_optguide; guide_entry->option_type != OPTIONTYPE_END; guide_entry++) |
| 717 | for (guide_entry = image_device_get_creation_option_guide(dev); guide_entry->option_type != OPTIONTYPE_END; guide_entry++) |
| 721 | 718 | { |
| 722 | 719 | // make sure that this entry is present on at least one option specification |
| 723 | 720 | found = FALSE; |
| 724 | | for (i = 0; iodev->createimage_options[i].optspec; i++) |
| 721 | for (format = image_device_get_creatable_formats(dev); format != NULL; format = format->next) |
| 725 | 722 | { |
| 726 | | if (option_resolution_contains(iodev->createimage_options[i].optspec, guide_entry->parameter)) |
| 723 | if (option_resolution_contains(format->optspec, guide_entry->parameter)) |
| 727 | 724 | { |
| 728 | 725 | found = TRUE; |
| 729 | 726 | break; |
| r3038 | r3039 | |
| 883 | 880 | option_resolution *create_args = NULL; |
| 884 | 881 | image_error_t err; |
| 885 | 882 | image_device_info info; |
| 886 | | const struct IODevice *iodev; |
| 887 | 883 | |
| 888 | 884 | // sanity check |
| 889 | 885 | assert(device != NULL); |
| r3038 | r3039 | |
| 908 | 904 | initial_dir = image_working_directory(device); |
| 909 | 905 | |
| 910 | 906 | // add custom dialog elements, if appropriate |
| 911 | | iodev = mess_device_from_core_device(device); |
| 912 | | if (is_save && (iodev != NULL) |
| 913 | | && (iodev->createimage_optguide != NULL) |
| 914 | | && (iodev->createimage_options[0].optspec != NULL)) |
| 907 | if (is_save |
| 908 | && (image_device_get_creation_option_guide(device) != NULL) |
| 909 | && (image_device_get_creatable_formats(device) != NULL)) |
| 915 | 910 | { |
| 916 | 911 | dialog = build_option_dialog(device, filter, sizeof(filter) / sizeof(filter[0]), &create_format, &create_args); |
| 917 | 912 | if (!dialog) |
| r3038 | r3039 | |
| 930 | 925 | { |
| 931 | 926 | // mount the image |
| 932 | 927 | if (is_save) |
| 933 | | err = image_create(device, filename, create_format, create_args); |
| 928 | err = image_create(device, filename, image_device_get_indexed_creatable_format(device, create_format), create_args); |
| 934 | 929 | else |
| 935 | 930 | err = image_load(device, filename); |
| 936 | 931 | |