trunk/src/emu/softlist.h
| r20005 | r20006 | |
| 191 | 191 | const char *software_get_clone(emu_options &options, char *swlist, const char *swname); |
| 192 | 192 | UINT32 software_get_support(emu_options &options, char *swlist, const char *swname); |
| 193 | 193 | const char *software_part_get_feature(const software_part *part, const char *feature_name); |
| 194 | void software_name_split(const char *swlist_swname, char **swlist_name, char **swname, char **swpart); |
| 194 | 195 | |
| 195 | 196 | bool load_software_part(emu_options &options, device_image_interface *image, const char *path, software_info **sw_info, software_part **sw_part, char **full_sw_name, char**list_name); |
| 196 | 197 | |
trunk/src/emu/imagedev/floppy.c
| r20005 | r20006 | |
| 5 | 5 | *********************************************************************/ |
| 6 | 6 | |
| 7 | 7 | #include "emu.h" |
| 8 | #include "emuopts.h" |
| 8 | 9 | #include "zippath.h" |
| 9 | 10 | #include "floppy.h" |
| 10 | 11 | #include "formats/imageutl.h" |
| r20005 | r20006 | |
| 233 | 234 | index_resync(); |
| 234 | 235 | } |
| 235 | 236 | |
| 236 | | floppy_image_format_t *floppy_image_device::identify(astring filename) const |
| 237 | floppy_image_format_t *floppy_image_device::identify(astring filename) |
| 237 | 238 | { |
| 238 | | FILE *fd; |
| 239 | | fd = fopen(filename.cstr(), "r"); |
| 240 | | if(!fd) |
| 239 | core_file *fd; |
| 240 | astring revised_path; |
| 241 | |
| 242 | file_error err = zippath_fopen(filename, OPEN_FLAG_READ, fd, revised_path); |
| 243 | if(err) { |
| 244 | seterror(IMAGE_ERROR_INVALIDIMAGE, "Unable to open the image file"); |
| 241 | 245 | return 0; |
| 246 | } |
| 242 | 247 | |
| 243 | 248 | io_generic io; |
| 244 | 249 | io.file = fd; |
| 245 | | io.procs = &stdio_ioprocs_noclose; |
| 250 | io.procs = &corefile_ioprocs_noclose; |
| 246 | 251 | io.filler = 0xff; |
| 247 | 252 | int best = 0; |
| 248 | 253 | floppy_image_format_t *best_format = 0; |
| r20005 | r20006 | |
| 253 | 258 | best_format = format; |
| 254 | 259 | } |
| 255 | 260 | } |
| 256 | | fclose(fd); |
| 261 | core_fclose(fd); |
| 257 | 262 | return best_format; |
| 258 | 263 | } |
| 259 | 264 | |
| r20005 | r20006 | |
| 283 | 288 | image = global_alloc(floppy_image(tracks, sides, form_factor)); |
| 284 | 289 | best_format->load(&io, form_factor, image); |
| 285 | 290 | |
| 291 | if(!is_readonly()) |
| 292 | output_format = best_format; |
| 293 | |
| 286 | 294 | revolution_start_time = motor_always_on ? machine().time() : attotime::never; |
| 287 | 295 | revolution_count = 0; |
| 288 | 296 | |
| r20005 | r20006 | |
| 725 | 733 | } |
| 726 | 734 | } |
| 727 | 735 | |
| 736 | astring ui_menu_control_floppy_image::try_file(astring location, astring name, bool has_crc, UINT32 crc) |
| 737 | { |
| 738 | emu_file fd(machine().options().media_path(), OPEN_FLAG_READ); |
| 739 | file_error filerr; |
| 740 | if(has_crc) |
| 741 | filerr = fd.open(location.cstr(), PATH_SEPARATOR, name.cstr(), crc); |
| 742 | else |
| 743 | filerr = fd.open(location.cstr(), PATH_SEPARATOR, name.cstr()); |
| 744 | if(filerr != FILERR_NONE) |
| 745 | return ""; |
| 746 | return fd.fullpath(); |
| 747 | } |
| 748 | |
| 728 | 749 | void ui_menu_control_floppy_image::hook_load(astring filename, bool softlist) |
| 729 | 750 | { |
| 730 | 751 | input_filename = filename; |
| 752 | if(softlist) { |
| 753 | char *swlist_name, *swname, *swpart; |
| 754 | software_name_split(filename.cstr(), &swlist_name, &swname, &swpart); |
| 755 | software_list *sw_list = software_list_open(machine().options(), swlist_name, FALSE, NULL); |
| 756 | software_info *sw_info = software_list_find(sw_list, swname, NULL); |
| 757 | software_part *sw_part = software_find_part(sw_info, swpart, NULL); |
| 758 | const char *parentname = software_get_clone(machine().options(), swlist_name, sw_info->shortname); |
| 759 | for(const rom_entry *region = sw_part->romdata; region; region = rom_next_region(region)) { |
| 760 | const rom_entry *romp = region + 1; |
| 761 | UINT32 crc = 0; |
| 762 | bool has_crc = hash_collection(ROM_GETHASHDATA(romp)).crc(crc); |
| 763 | |
| 764 | filename = try_file(astring(swlist_name) + PATH_SEPARATOR + astring(swname), ROM_GETNAME(romp), has_crc, crc); |
| 765 | if(filename == "") |
| 766 | filename = try_file(astring(swlist_name) + PATH_SEPARATOR + astring(parentname), ROM_GETNAME(romp), has_crc, crc); |
| 767 | if(filename == "") |
| 768 | filename = try_file(swname, ROM_GETNAME(romp), has_crc, crc); |
| 769 | if(filename == "") |
| 770 | filename = try_file(parentname, ROM_GETNAME(romp), has_crc, crc); |
| 771 | if(filename != "") |
| 772 | goto found; |
| 773 | } |
| 774 | |
| 775 | found: |
| 776 | software_list_close(sw_list); |
| 777 | global_free(swlist_name); |
| 778 | } |
| 779 | |
| 731 | 780 | input_format = static_cast<floppy_image_device *>(image)->identify(filename); |
| 732 | 781 | if(!input_format) { |
| 733 | 782 | popmessage("Error: %s\n", image->error()); |
trunk/src/lib/formats/ioprocs.c
| r20005 | r20006 | |
| 2 | 2 | #include <string.h> |
| 3 | 3 | #include "osdcore.h" |
| 4 | 4 | #include "ioprocs.h" |
| 5 | #include "corefile.h" |
| 5 | 6 | |
| 6 | 7 | |
| 7 | 8 | /********************************************************************* |
| r20005 | r20006 | |
| 58 | 59 | stdio_filesizeproc |
| 59 | 60 | }; |
| 60 | 61 | |
| 62 | /********************************************************************* |
| 63 | ioprocs implementation on corefile |
| 64 | *********************************************************************/ |
| 61 | 65 | |
| 66 | static void corefile_closeproc(void *file) |
| 67 | { |
| 68 | core_fclose((core_file*)file); |
| 69 | } |
| 62 | 70 | |
| 71 | static int corefile_seekproc(void *file, INT64 offset, int whence) |
| 72 | { |
| 73 | return core_fseek((core_file*)file, (long) offset, whence); |
| 74 | } |
| 75 | |
| 76 | static size_t corefile_readproc(void *file, void *buffer, size_t length) |
| 77 | { |
| 78 | return core_fread((core_file*)file, buffer, length); |
| 79 | } |
| 80 | |
| 81 | static size_t corefile_writeproc(void *file, const void *buffer, size_t length) |
| 82 | { |
| 83 | return core_fwrite((core_file*)file, buffer, length); |
| 84 | } |
| 85 | |
| 86 | static UINT64 corefile_filesizeproc(void *file) |
| 87 | { |
| 88 | long l, sz; |
| 89 | l = core_ftell((core_file*)file); |
| 90 | if (core_fseek((core_file*)file, 0, SEEK_END)) |
| 91 | return (size_t) -1; |
| 92 | sz = core_ftell((core_file*)file); |
| 93 | if (core_fseek((core_file*)file, l, SEEK_SET)) |
| 94 | return (size_t) -1; |
| 95 | return (size_t) sz; |
| 96 | } |
| 97 | |
| 98 | const struct io_procs corefile_ioprocs = |
| 99 | { |
| 100 | corefile_closeproc, |
| 101 | corefile_seekproc, |
| 102 | corefile_readproc, |
| 103 | corefile_writeproc, |
| 104 | corefile_filesizeproc |
| 105 | }; |
| 106 | |
| 107 | const struct io_procs corefile_ioprocs_noclose = |
| 108 | { |
| 109 | NULL, |
| 110 | corefile_seekproc, |
| 111 | corefile_readproc, |
| 112 | corefile_writeproc, |
| 113 | corefile_filesizeproc |
| 114 | }; |
| 115 | |
| 116 | |
| 117 | |
| 63 | 118 | /********************************************************************* |
| 64 | 119 | calls for accessing generic IO |
| 65 | 120 | *********************************************************************/ |