src/emu/diimage.c
| r14121 | r14122 | |
| 649 | 649 | return err; |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | int device_image_interface::reopen_for_write(const char *path) |
| 653 | { |
| 654 | if(m_file) |
| 655 | core_fclose(m_file); |
| 656 | |
| 657 | file_error filerr = FILERR_NOT_FOUND; |
| 658 | image_error_t err = IMAGE_ERROR_FILENOTFOUND; |
| 659 | astring revised_path; |
| 660 | |
| 661 | /* attempt to open the file for writing*/ |
| 662 | filerr = zippath_fopen(path, OPEN_FLAG_READ|OPEN_FLAG_WRITE|OPEN_FLAG_CREATE, m_file, revised_path); |
| 663 | |
| 664 | /* did the open succeed? */ |
| 665 | switch(filerr) |
| 666 | { |
| 667 | case FILERR_NONE: |
| 668 | /* success! */ |
| 669 | m_readonly = 0; |
| 670 | m_created = 1; |
| 671 | err = IMAGE_ERROR_SUCCESS; |
| 672 | break; |
| 673 | |
| 674 | case FILERR_NOT_FOUND: |
| 675 | case FILERR_ACCESS_DENIED: |
| 676 | /* file not found (or otherwise cannot open); continue */ |
| 677 | err = IMAGE_ERROR_FILENOTFOUND; |
| 678 | break; |
| 679 | |
| 680 | case FILERR_OUT_OF_MEMORY: |
| 681 | /* out of memory */ |
| 682 | err = IMAGE_ERROR_OUTOFMEMORY; |
| 683 | break; |
| 684 | |
| 685 | case FILERR_ALREADY_OPEN: |
| 686 | /* this shouldn't happen */ |
| 687 | err = IMAGE_ERROR_ALREADYOPEN; |
| 688 | break; |
| 689 | |
| 690 | case FILERR_FAILURE: |
| 691 | case FILERR_TOO_MANY_FILES: |
| 692 | case FILERR_INVALID_DATA: |
| 693 | default: |
| 694 | /* other errors */ |
| 695 | err = IMAGE_ERROR_INTERNAL; |
| 696 | break; |
| 697 | } |
| 698 | |
| 699 | /* if successful, set the file name */ |
| 700 | if (filerr == FILERR_NONE) |
| 701 | set_image_filename(revised_path); |
| 702 | |
| 703 | return err; |
| 704 | } |
| 705 | |
| 652 | 706 | /*------------------------------------------------- |
| 653 | 707 | determine_open_plan - determines which open |
| 654 | 708 | flags to use, and in what order |
| r14121 | r14122 | |
| 1040 | 1094 | for ui-level image selection |
| 1041 | 1095 | -------------------------------------------------*/ |
| 1042 | 1096 | |
| 1043 | | class ui_menu_control_device_image : public ui_menu { |
| 1044 | | public: |
| 1045 | | ui_menu_control_device_image(running_machine &machine, render_container *container, device_image_interface *image); |
| 1046 | | virtual ~ui_menu_control_device_image(); |
| 1047 | | virtual void populate(); |
| 1048 | | virtual void handle(); |
| 1049 | | |
| 1050 | | private: |
| 1051 | | enum { |
| 1052 | | START_FILE, START_OTHER_PART, START_SOFTLIST, SELECT_PARTLIST, SELECT_ONE_PART, SELECT_OTHER_PART, SELECT_FILE, CREATE_FILE, CREATE_CONFIRM, DO_CREATE, SELECT_SOFTLIST |
| 1053 | | }; |
| 1054 | | int state; |
| 1055 | | |
| 1056 | | device_image_interface *image; |
| 1057 | | astring current_directory; |
| 1058 | | astring current_file; |
| 1059 | | int submenu_result; |
| 1060 | | bool create_confirmed; |
| 1061 | | bool softlist_done; |
| 1062 | | const software_list *swl; |
| 1063 | | const software_info *swi; |
| 1064 | | const software_part *swp; |
| 1065 | | const software_list_config *slc; |
| 1066 | | astring software_info_name; |
| 1067 | | |
| 1068 | | void test_create(bool &can_create, bool &need_confirm); |
| 1069 | | void load_software_part(); |
| 1070 | | }; |
| 1071 | | |
| 1072 | 1097 | ui_menu *device_image_interface::get_selection_menu(running_machine &machine, render_container *container) |
| 1073 | 1098 | { |
| 1074 | 1099 | return auto_alloc_clear(machine, ui_menu_control_device_image(machine, container, this)); |
| r14121 | r14122 | |
| 1128 | 1153 | /* does a file or a directory exist at the path */ |
| 1129 | 1154 | entry = osd_stat(path); |
| 1130 | 1155 | file_type = (entry != NULL) ? entry->type : ENTTYPE_NONE; |
| 1131 | | if (entry != NULL) |
| 1132 | | free(entry); |
| 1133 | 1156 | |
| 1134 | 1157 | switch(file_type) |
| 1135 | 1158 | { |
| r14121 | r14122 | |
| 1165 | 1188 | astring temp_name(swi->shortname); |
| 1166 | 1189 | temp_name.cat(":"); |
| 1167 | 1190 | temp_name.cat(swp->name); |
| 1168 | | image->load(temp_name.cstr()); |
| 1191 | hook_load(temp_name, true); |
| 1169 | 1192 | } |
| 1170 | 1193 | |
| 1194 | void ui_menu_control_device_image::hook_load(astring name, bool softlist) |
| 1195 | { |
| 1196 | image->load(name); |
| 1197 | ui_menu::stack_pop(machine()); |
| 1198 | } |
| 1199 | |
| 1171 | 1200 | void ui_menu_control_device_image::populate() |
| 1172 | 1201 | { |
| 1173 | 1202 | } |
| r14121 | r14122 | |
| 1249 | 1278 | switch(submenu_result) { |
| 1250 | 1279 | case ui_menu_software_parts::T_ENTRY: { |
| 1251 | 1280 | load_software_part(); |
| 1252 | | ui_menu::stack_pop(machine()); |
| 1253 | 1281 | break; |
| 1254 | 1282 | } |
| 1255 | 1283 | |
| r14121 | r14122 | |
| 1273 | 1301 | break; |
| 1274 | 1302 | |
| 1275 | 1303 | case ui_menu_file_selector::R_FILE: |
| 1276 | | image->load(current_file); |
| 1277 | | ui_menu::stack_pop(machine()); |
| 1304 | hook_load(current_file, false); |
| 1278 | 1305 | break; |
| 1279 | 1306 | |
| 1280 | 1307 | case ui_menu_file_selector::R_CREATE: |
| r14121 | r14122 | |
| 1301 | 1328 | ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_confirm_save_as(machine(), container, &create_confirmed))); |
| 1302 | 1329 | state = CREATE_CONFIRM; |
| 1303 | 1330 | } else { |
| 1304 | | astring path; |
| 1305 | | zippath_combine(path, current_directory, current_file); |
| 1306 | | int err = image->create(path, 0, NULL); |
| 1307 | | if (err != 0) |
| 1308 | | popmessage("Error: %s", image->error()); |
| 1309 | | ui_menu::stack_pop(machine()); |
| 1331 | state = DO_CREATE; |
| 1332 | handle(); |
| 1310 | 1333 | } |
| 1311 | 1334 | } else { |
| 1312 | 1335 | state = START_FILE; |
src/emu/uiimage.c
| r14121 | r14122 | |
| 25 | 25 | #include "uiimage.h" |
| 26 | 26 | #include "zippath.h" |
| 27 | 27 | #include "unicode.h" |
| 28 | #include "imagedev/floppy.h" |
| 28 | 29 | #include "imagedev/cassette.h" |
| 29 | 30 | #include "imagedev/bitbngr.h" |
| 30 | 31 | |
| r14121 | r14122 | |
| 521 | 522 | const char *volume_name; |
| 522 | 523 | const char *path = current_directory; |
| 523 | 524 | |
| 524 | | if(path[0]) |
| 525 | | fprintf(stderr, "curdir=%s\n", path); |
| 526 | | |
| 527 | 525 | /* open the directory */ |
| 528 | 526 | err = zippath_opendir(path, &directory); |
| 529 | 527 | if (err != FILERR_NONE) |
| r14121 | r14122 | |
| 877 | 875 | process(0); |
| 878 | 876 | } |
| 879 | 877 | |
| 878 | /*------------------------------------------------- |
| 879 | ui_menu_select_format - floppy image format |
| 880 | selection menu |
| 881 | -------------------------------------------------*/ |
| 882 | |
| 883 | ui_menu_select_format::ui_menu_select_format(running_machine &machine, render_container *container, |
| 884 | floppy_image_format_t **_formats, int _ext_match, int _total_usable, int *_result) |
| 885 | : ui_menu(machine, container) |
| 886 | { |
| 887 | formats = _formats; |
| 888 | ext_match = _ext_match; |
| 889 | total_usable = _total_usable; |
| 890 | result = _result; |
| 891 | } |
| 892 | |
| 893 | void ui_menu_select_format::populate() |
| 894 | { |
| 895 | item_append("Select image format", NULL, MENU_FLAG_DISABLE, NULL); |
| 896 | for(int i=0; i<total_usable; i++) { |
| 897 | const floppy_image_format_t *fmt = formats[i]; |
| 898 | |
| 899 | if(i && i == ext_match) |
| 900 | item_append(MENU_SEPARATOR_ITEM, NULL, 0, NULL); |
| 901 | item_append(fmt->description(), fmt->name(), 0, (void *)i); |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | ui_menu_select_format::~ui_menu_select_format() |
| 906 | { |
| 907 | } |
| 908 | |
| 909 | void ui_menu_select_format::handle() |
| 910 | { |
| 911 | /* process the menu */ |
| 912 | const ui_menu_event *event = process(0); |
| 913 | if (event != NULL && event->iptkey == IPT_UI_SELECT) |
| 914 | { |
| 915 | *result = int(FPTR(event->itemref)); |
| 916 | ui_menu::stack_pop(machine()); |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | /*------------------------------------------------- |
| 921 | ui_menu_select_rw - floppy read/write |
| 922 | selection menu |
| 923 | -------------------------------------------------*/ |
| 924 | |
| 925 | ui_menu_select_rw::ui_menu_select_rw(running_machine &machine, render_container *container, |
| 926 | bool _can_in_place, int *_result) |
| 927 | : ui_menu(machine, container) |
| 928 | { |
| 929 | can_in_place = _can_in_place; |
| 930 | result = _result; |
| 931 | } |
| 932 | |
| 933 | void ui_menu_select_rw::populate() |
| 934 | { |
| 935 | item_append("Select access mode", NULL, MENU_FLAG_DISABLE, NULL); |
| 936 | item_append("Read-only", 0, 0, (void *)READONLY); |
| 937 | if(can_in_place) |
| 938 | item_append("Read-write", 0, 0, (void *)READWRITE); |
| 939 | item_append("Read this image, write to another image", 0, 0, (void *)WRITE_OTHER); |
| 940 | item_append("Read this image, write to diff", 0, 0, (void *)WRITE_DIFF); |
| 941 | } |
| 942 | |
| 943 | ui_menu_select_rw::~ui_menu_select_rw() |
| 944 | { |
| 945 | } |
| 946 | |
| 947 | void ui_menu_select_rw::handle() |
| 948 | { |
| 949 | /* process the menu */ |
| 950 | const ui_menu_event *event = process(0); |
| 951 | if (event != NULL && event->iptkey == IPT_UI_SELECT) |
| 952 | { |
| 953 | *result = int(FPTR(event->itemref)); |
| 954 | ui_menu::stack_pop(machine()); |
| 955 | } |
| 956 | } |
| 957 | |
| 880 | 958 | /*************************************************************************** |
| 881 | 959 | TYPE DEFINITIONS |
| 882 | 960 | ***************************************************************************/ |
src/emu/imagedev/floppy.c
| r14121 | r14122 | |
| 5 | 5 | *********************************************************************/ |
| 6 | 6 | |
| 7 | 7 | #include "emu.h" |
| 8 | #include "zippath.h" |
| 8 | 9 | #include "floppy.h" |
| 9 | 10 | #include "formats/imageutl.h" |
| 11 | #include "uiimage.h" |
| 10 | 12 | |
| 11 | 13 | // device type definition |
| 12 | 14 | const device_type FLOPPY_CONNECTOR = &device_creator<floppy_connector>; |
| 13 | 15 | const device_type FLOPPY_35_DD = &device_creator<floppy_35_dd>; |
| 16 | const device_type FLOPPY_35_DD_NOSD = &device_creator<floppy_35_dd_nosd>; |
| 14 | 17 | const device_type FLOPPY_35_HD = &device_creator<floppy_35_hd>; |
| 15 | 18 | const device_type FLOPPY_35_ED = &device_creator<floppy_35_ed>; |
| 16 | 19 | const device_type FLOPPY_525_DD = &device_creator<floppy_525_dd>; |
| r14121 | r14122 | |
| 115 | 118 | update_names(); |
| 116 | 119 | } |
| 117 | 120 | |
| 121 | floppy_image_format_t *floppy_image_device::get_formats() const |
| 122 | { |
| 123 | return fif_list; |
| 124 | } |
| 125 | |
| 126 | floppy_image_format_t *floppy_image_device::get_load_format() const |
| 127 | { |
| 128 | return input_format; |
| 129 | } |
| 130 | |
| 118 | 131 | void floppy_image_device::device_config_complete() |
| 119 | 132 | { |
| 120 | 133 | update_names(); |
| r14121 | r14122 | |
| 129 | 142 | rev_time = attotime::from_double(60/rpm); |
| 130 | 143 | } |
| 131 | 144 | |
| 145 | void floppy_image_device::setup_write(floppy_image_format_t *_output_format) |
| 146 | { |
| 147 | output_format = _output_format; |
| 148 | commit_image(); |
| 149 | } |
| 132 | 150 | |
| 151 | void floppy_image_device::commit_image() |
| 152 | { |
| 153 | image_dirty = false; |
| 154 | if(!output_format) |
| 155 | return; |
| 156 | io_generic io; |
| 157 | // Do _not_ remove this cast otherwise the pointer will be incorrect when used by the ioprocs. |
| 158 | io.file = (device_image_interface *)this; |
| 159 | io.procs = &image_ioprocs; |
| 160 | io.filler = 0xff; |
| 161 | output_format->save(&io, image); |
| 162 | } |
| 163 | |
| 133 | 164 | //------------------------------------------------- |
| 134 | 165 | // device_start - device-specific startup |
| 135 | 166 | //------------------------------------------------- |
| r14121 | r14122 | |
| 151 | 182 | stp = 1; |
| 152 | 183 | dskchg = 0; |
| 153 | 184 | index_timer = timer_alloc(0); |
| 185 | image_dirty = false; |
| 154 | 186 | } |
| 155 | 187 | |
| 156 | 188 | void floppy_image_device::device_reset() |
| r14121 | r14122 | |
| 165 | 197 | index_resync(); |
| 166 | 198 | } |
| 167 | 199 | |
| 200 | floppy_image_format_t *floppy_image_device::identify(astring filename) const |
| 201 | { |
| 202 | FILE *fd; |
| 203 | fd = fopen(filename.cstr(), "r"); |
| 204 | if(!fd) |
| 205 | return 0; |
| 206 | |
| 207 | io_generic io; |
| 208 | io.file = fd; |
| 209 | io.procs = &stdio_ioprocs_noclose; |
| 210 | io.filler = 0xff; |
| 211 | int best = 0; |
| 212 | floppy_image_format_t *best_format = 0; |
| 213 | for(floppy_image_format_t *format = fif_list; format; format = format->next) { |
| 214 | int score = format->identify(&io, form_factor); |
| 215 | if(score > best) { |
| 216 | best = score; |
| 217 | best_format = format; |
| 218 | } |
| 219 | } |
| 220 | fclose(fd); |
| 221 | return best_format; |
| 222 | } |
| 223 | |
| 168 | 224 | bool floppy_image_device::call_load() |
| 169 | 225 | { |
| 170 | 226 | io_generic io; |
| r14121 | r14122 | |
| 192 | 248 | revolution_count = 0; |
| 193 | 249 | |
| 194 | 250 | index_resync(); |
| 251 | image_dirty = false; |
| 252 | output_format = 0; |
| 195 | 253 | |
| 196 | 254 | if (!cur_load_cb.isnull()) |
| 197 | 255 | return cur_load_cb(this); |
| r14121 | r14122 | |
| 203 | 261 | dskchg = 0; |
| 204 | 262 | |
| 205 | 263 | if (image) { |
| 264 | if(image_dirty) |
| 265 | commit_image(); |
| 206 | 266 | global_free(image); |
| 207 | 267 | image = 0; |
| 208 | 268 | } |
| r14121 | r14122 | |
| 210 | 270 | cur_unload_cb(this); |
| 211 | 271 | } |
| 212 | 272 | |
| 273 | bool floppy_image_device::call_create(int format_type, option_resolution *format_options) |
| 274 | { |
| 275 | image = global_alloc(floppy_image(tracks, sides, form_factor)); |
| 276 | output_format = 0; |
| 277 | return IMAGE_INIT_PASS; |
| 278 | } |
| 279 | |
| 213 | 280 | /* motor on, active low */ |
| 214 | 281 | void floppy_image_device::mon_w(int state) |
| 215 | 282 | { |
| r14121 | r14122 | |
| 227 | 294 | |
| 228 | 295 | /* on -> off */ |
| 229 | 296 | else { |
| 297 | if(image_dirty) |
| 298 | commit_image(); |
| 230 | 299 | revolution_start_time = attotime::never; |
| 231 | 300 | index_timer->adjust(attotime::zero); |
| 232 | 301 | } |
| r14121 | r14122 | |
| 377 | 446 | |
| 378 | 447 | void floppy_image_device::write_flux(attotime start, attotime end, int transition_count, const attotime *transitions) |
| 379 | 448 | { |
| 449 | image_dirty = true; |
| 450 | |
| 380 | 451 | attotime base; |
| 381 | 452 | int start_pos = find_position(base, start); |
| 382 | 453 | int end_pos = find_position(base, end); |
| r14121 | r14122 | |
| 395 | 466 | index = 0; |
| 396 | 467 | image->set_track_size(cyl, ss, 1); |
| 397 | 468 | buf = image->get_buffer(cyl, ss); |
| 398 | | buf[cells++] = floppy_image::MG_N | 200000000; |
| 469 | buf[cells++] = floppy_image::MG_N; |
| 399 | 470 | } |
| 400 | 471 | |
| 401 | 472 | if(index && (buf[index] & floppy_image::TIME_MASK) == start_pos) |
| r14121 | r14122 | |
| 408 | 479 | UINT32 pos = start_pos; |
| 409 | 480 | int ti = 0; |
| 410 | 481 | while(pos != end_pos) { |
| 411 | | if(image->get_track_size(cyl, ss) < cells+10) |
| 482 | if(image->get_track_size(cyl, ss) < cells+10) { |
| 412 | 483 | image->set_track_size(cyl, ss, cells+200); |
| 484 | buf = image->get_buffer(cyl, ss); |
| 485 | } |
| 413 | 486 | UINT32 next_pos; |
| 414 | 487 | if(ti != transition_count) |
| 415 | 488 | next_pos = trans_pos[ti++]; |
| r14121 | r14122 | |
| 530 | 603 | } |
| 531 | 604 | } |
| 532 | 605 | |
| 606 | ui_menu *floppy_image_device::get_selection_menu(running_machine &machine, render_container *container) |
| 607 | { |
| 608 | return auto_alloc_clear(machine, ui_menu_control_floppy_image(machine, container, this)); |
| 609 | } |
| 610 | |
| 611 | ui_menu_control_floppy_image::ui_menu_control_floppy_image(running_machine &machine, render_container *container, device_image_interface *_image) : ui_menu_control_device_image(machine, container, _image) |
| 612 | { |
| 613 | floppy_image_device *fd = static_cast<floppy_image_device *>(image); |
| 614 | const floppy_image_format_t *fif_list = fd->get_formats(); |
| 615 | int fcnt = 0; |
| 616 | for(const floppy_image_format_t *i = fif_list; i; i = i->next) |
| 617 | fcnt++; |
| 618 | |
| 619 | format_array = global_alloc_array(floppy_image_format_t *, fcnt); |
| 620 | input_format = output_format = 0; |
| 621 | input_filename = output_filename = ""; |
| 622 | } |
| 623 | |
| 624 | ui_menu_control_floppy_image::~ui_menu_control_floppy_image() |
| 625 | { |
| 626 | global_free(format_array); |
| 627 | } |
| 628 | |
| 629 | void ui_menu_control_floppy_image::do_load_create() |
| 630 | { |
| 631 | floppy_image_device *fd = static_cast<floppy_image_device *>(image); |
| 632 | if(input_filename == "") { |
| 633 | int err = fd->create(output_filename, 0, NULL); |
| 634 | if (err != 0) { |
| 635 | popmessage("Error: %s", fd->error()); |
| 636 | return; |
| 637 | } |
| 638 | fd->setup_write(output_format); |
| 639 | } else { |
| 640 | int err = fd->load(input_filename); |
| 641 | if(!err && output_filename != "") |
| 642 | err = fd->reopen_for_write(output_filename); |
| 643 | if(err != 0) { |
| 644 | popmessage("Error: %s", fd->error()); |
| 645 | return; |
| 646 | } |
| 647 | if(output_format) |
| 648 | fd->setup_write(output_format); |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | void ui_menu_control_floppy_image::hook_load(astring filename, bool softlist) |
| 653 | { |
| 654 | input_filename = filename; |
| 655 | input_format = static_cast<floppy_image_device *>(image)->identify(filename); |
| 656 | if(!input_format) { |
| 657 | popmessage("Error: %s\n", image->error()); |
| 658 | ui_menu::stack_pop(machine()); |
| 659 | return; |
| 660 | } |
| 661 | |
| 662 | bool can_in_place = input_format->supports_save(); |
| 663 | if(can_in_place) { |
| 664 | file_error filerr = FILERR_NOT_FOUND; |
| 665 | astring tmp_path; |
| 666 | core_file *tmp_file; |
| 667 | /* attempt to open the file for writing but *without* create */ |
| 668 | filerr = zippath_fopen(filename, OPEN_FLAG_READ|OPEN_FLAG_WRITE, tmp_file, tmp_path); |
| 669 | if(!filerr) |
| 670 | core_fclose(tmp_file); |
| 671 | else |
| 672 | can_in_place = false; |
| 673 | } |
| 674 | submenu_result = -1; |
| 675 | ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_select_rw(machine(), container, can_in_place, &submenu_result))); |
| 676 | state = SELECT_RW; |
| 677 | } |
| 678 | |
| 679 | void ui_menu_control_floppy_image::handle() |
| 680 | { |
| 681 | floppy_image_device *fd = static_cast<floppy_image_device *>(image); |
| 682 | switch(state) { |
| 683 | case DO_CREATE: { |
| 684 | floppy_image_format_t *fif_list = fd->get_formats(); |
| 685 | int ext_match = 0, total_usable = 0; |
| 686 | for(floppy_image_format_t *i = fif_list; i; i = i->next) { |
| 687 | if(!i->supports_save()) |
| 688 | continue; |
| 689 | if(i->extension_matches(current_file)) |
| 690 | format_array[total_usable++] = i; |
| 691 | } |
| 692 | ext_match = total_usable; |
| 693 | for(floppy_image_format_t *i = fif_list; i; i = i->next) { |
| 694 | if(!i->supports_save()) |
| 695 | continue; |
| 696 | if(!i->extension_matches(current_file)) |
| 697 | format_array[total_usable++] = i; |
| 698 | } |
| 699 | submenu_result = -1; |
| 700 | ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_select_format(machine(), container, format_array, ext_match, total_usable, &submenu_result))); |
| 701 | |
| 702 | state = SELECT_FORMAT; |
| 703 | break; |
| 704 | } |
| 705 | |
| 706 | case SELECT_FORMAT: |
| 707 | if(submenu_result == -1) { |
| 708 | state = START_FILE; |
| 709 | handle(); |
| 710 | } else { |
| 711 | zippath_combine(output_filename, current_directory, current_file); |
| 712 | output_format = format_array[submenu_result]; |
| 713 | do_load_create(); |
| 714 | ui_menu::stack_pop(machine()); |
| 715 | } |
| 716 | break; |
| 717 | |
| 718 | case SELECT_RW: |
| 719 | switch(submenu_result) { |
| 720 | case ui_menu_select_rw::READONLY: |
| 721 | do_load_create(); |
| 722 | ui_menu::stack_pop(machine()); |
| 723 | break; |
| 724 | |
| 725 | case ui_menu_select_rw::READWRITE: |
| 726 | output_format = input_format; |
| 727 | do_load_create(); |
| 728 | ui_menu::stack_pop(machine()); |
| 729 | break; |
| 730 | |
| 731 | case ui_menu_select_rw::WRITE_DIFF: |
| 732 | popmessage("Sorry, diffs are not supported yet\n"); |
| 733 | ui_menu::stack_pop(machine()); |
| 734 | break; |
| 735 | |
| 736 | case ui_menu_select_rw::WRITE_OTHER: |
| 737 | ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_file_create(machine(), container, image, current_directory, current_file))); |
| 738 | state = CREATE_FILE; |
| 739 | break; |
| 740 | |
| 741 | case -1: |
| 742 | ui_menu::stack_pop(machine()); |
| 743 | break; |
| 744 | } |
| 745 | break; |
| 746 | |
| 747 | default: |
| 748 | ui_menu_control_device_image::handle(); |
| 749 | } |
| 750 | } |
| 751 | |
| 533 | 752 | floppy_35_dd::floppy_35_dd(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : |
| 534 | 753 | floppy_image_device(mconfig, FLOPPY_35_DD, "3.5\" double density floppy drive", tag, owner, clock) |
| 535 | 754 | { |
| r14121 | r14122 | |
| 547 | 766 | set_rpm(300); |
| 548 | 767 | } |
| 549 | 768 | |
| 769 | void floppy_35_dd::handled_variants(UINT32 *variants, int &var_count) const |
| 770 | { |
| 771 | var_count = 0; |
| 772 | variants[var_count++] = floppy_image::SSSD; |
| 773 | variants[var_count++] = floppy_image::SSDD; |
| 774 | variants[var_count++] = floppy_image::DSDD; |
| 775 | } |
| 776 | |
| 777 | floppy_35_dd_nosd::floppy_35_dd_nosd(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : |
| 778 | floppy_image_device(mconfig, FLOPPY_35_DD_NOSD, "3.5\" double density floppy drive", tag, owner, clock) |
| 779 | { |
| 780 | } |
| 781 | |
| 782 | floppy_35_dd_nosd::~floppy_35_dd_nosd() |
| 783 | { |
| 784 | } |
| 785 | |
| 786 | void floppy_35_dd_nosd::setup_characteristics() |
| 787 | { |
| 788 | form_factor = floppy_image::FF_35; |
| 789 | tracks = 84; |
| 790 | sides = 2; |
| 791 | set_rpm(300); |
| 792 | } |
| 793 | |
| 794 | void floppy_35_dd_nosd::handled_variants(UINT32 *variants, int &var_count) const |
| 795 | { |
| 796 | var_count = 0; |
| 797 | variants[var_count++] = floppy_image::SSSD; |
| 798 | variants[var_count++] = floppy_image::SSDD; |
| 799 | } |
| 800 | |
| 550 | 801 | floppy_35_hd::floppy_35_hd(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : |
| 551 | 802 | floppy_image_device(mconfig, FLOPPY_35_HD, "3.5\" high density floppy drive", tag, owner, clock) |
| 552 | 803 | { |
| r14121 | r14122 | |
| 564 | 815 | set_rpm(300); |
| 565 | 816 | } |
| 566 | 817 | |
| 818 | void floppy_35_hd::handled_variants(UINT32 *variants, int &var_count) const |
| 819 | { |
| 820 | var_count = 0; |
| 821 | variants[var_count++] = floppy_image::SSSD; |
| 822 | variants[var_count++] = floppy_image::SSDD; |
| 823 | variants[var_count++] = floppy_image::DSDD; |
| 824 | variants[var_count++] = floppy_image::DSHD; |
| 825 | } |
| 826 | |
| 567 | 827 | floppy_35_ed::floppy_35_ed(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : |
| 568 | 828 | floppy_image_device(mconfig, FLOPPY_35_ED, "3.5\" extended density floppy drive", tag, owner, clock) |
| 569 | 829 | { |
| r14121 | r14122 | |
| 581 | 841 | set_rpm(300); |
| 582 | 842 | } |
| 583 | 843 | |
| 844 | void floppy_35_ed::handled_variants(UINT32 *variants, int &var_count) const |
| 845 | { |
| 846 | var_count = 0; |
| 847 | variants[var_count++] = floppy_image::SSSD; |
| 848 | variants[var_count++] = floppy_image::SSDD; |
| 849 | variants[var_count++] = floppy_image::DSDD; |
| 850 | variants[var_count++] = floppy_image::DSHD; |
| 851 | variants[var_count++] = floppy_image::DSED; |
| 852 | } |
| 584 | 853 | |
| 585 | 854 | floppy_525_dd::floppy_525_dd(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : |
| 586 | 855 | floppy_image_device(mconfig, FLOPPY_525_DD, "5.25\" double density floppy drive", tag, owner, clock) |
| r14121 | r14122 | |
| 598 | 867 | sides = 1; |
| 599 | 868 | set_rpm(300); |
| 600 | 869 | } |
| 870 | |
| 871 | void floppy_525_dd::handled_variants(UINT32 *variants, int &var_count) const |
| 872 | { |
| 873 | var_count = 0; |
| 874 | variants[var_count++] = floppy_image::SSSD; |
| 875 | variants[var_count++] = floppy_image::SSDD; |
| 876 | } |
src/emu/imagedev/floppy.h
| r14121 | r14122 | |
| 32 | 32 | floppy_image_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock); |
| 33 | 33 | virtual ~floppy_image_device(); |
| 34 | 34 | |
| 35 | virtual void handled_variants(UINT32 *variants, int &var_count) const = 0; |
| 36 | |
| 35 | 37 | void set_formats(const floppy_format_type *formats); |
| 38 | floppy_image_format_t *get_formats() const; |
| 39 | floppy_image_format_t *get_load_format() const; |
| 40 | floppy_image_format_t *identify(astring filename) const; |
| 36 | 41 | void set_rpm(float rpm); |
| 37 | 42 | |
| 38 | 43 | // image-level overrides |
| 39 | 44 | virtual bool call_load(); |
| 40 | 45 | virtual void call_unload(); |
| 46 | virtual bool call_create(int format_type, option_resolution *format_options); |
| 41 | 47 | virtual void call_display_info() {} |
| 42 | 48 | virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) { return load_software(swlist, swname, start_entry); } |
| 43 | 49 | |
| r14121 | r14122 | |
| 50 | 56 | virtual bool is_reset_on_load() const { return false; } |
| 51 | 57 | virtual const char *file_extensions() const { return extension_list; } |
| 52 | 58 | virtual const option_guide *create_option_guide() const { return NULL; } |
| 59 | void setup_write(floppy_image_format_t *output_format); |
| 53 | 60 | |
| 54 | 61 | void setup_load_cb(load_cb cb); |
| 55 | 62 | void setup_unload_cb(unload_cb cb); |
| r14121 | r14122 | |
| 79 | 86 | UINT32 get_form_factor() const; |
| 80 | 87 | UINT32 get_variant() const; |
| 81 | 88 | |
| 89 | virtual ui_menu *get_selection_menu(running_machine &machine, class render_container *container); |
| 90 | |
| 82 | 91 | protected: |
| 83 | 92 | // device-level overrides |
| 84 | 93 | virtual void device_config_complete(); |
| r14121 | r14122 | |
| 89 | 98 | virtual void setup_characteristics() = 0; |
| 90 | 99 | |
| 91 | 100 | image_device_format format; |
| 101 | floppy_image_format_t *input_format; |
| 102 | floppy_image_format_t *output_format; |
| 92 | 103 | floppy_image *image; |
| 93 | 104 | char extension_list[256]; |
| 94 | 105 | floppy_image_format_t *fif_list; |
| r14121 | r14122 | |
| 119 | 130 | UINT32 revolution_count; |
| 120 | 131 | int cyl; |
| 121 | 132 | |
| 133 | bool image_dirty; |
| 134 | |
| 122 | 135 | load_cb cur_load_cb; |
| 123 | 136 | unload_cb cur_unload_cb; |
| 124 | 137 | index_pulse_cb cur_index_pulse_cb; |
| r14121 | r14122 | |
| 126 | 139 | UINT32 find_position(attotime &base, attotime when); |
| 127 | 140 | int find_index(UINT32 position, const UINT32 *buf, int buf_size); |
| 128 | 141 | void write_zone(UINT32 *buf, int &cells, int &index, UINT32 spos, UINT32 epos, UINT32 mg); |
| 142 | void commit_image(); |
| 129 | 143 | }; |
| 130 | 144 | |
| 145 | class ui_menu_control_floppy_image : public ui_menu_control_device_image { |
| 146 | public: |
| 147 | ui_menu_control_floppy_image(running_machine &machine, render_container *container, device_image_interface *image); |
| 148 | virtual ~ui_menu_control_floppy_image(); |
| 149 | |
| 150 | virtual void handle(); |
| 151 | |
| 152 | protected: |
| 153 | enum { SELECT_FORMAT = LAST_ID, SELECT_MEDIA, SELECT_RW }; |
| 154 | |
| 155 | floppy_image_format_t **format_array; |
| 156 | floppy_image_format_t *input_format, *output_format; |
| 157 | astring input_filename, output_filename; |
| 158 | |
| 159 | void do_load_create(); |
| 160 | virtual void hook_load(astring filename, bool softlist); |
| 161 | }; |
| 162 | |
| 131 | 163 | class floppy_35_dd : public floppy_image_device { |
| 132 | 164 | public: |
| 133 | 165 | floppy_35_dd(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 134 | 166 | virtual ~floppy_35_dd(); |
| 167 | virtual void handled_variants(UINT32 *variants, int &var_count) const; |
| 135 | 168 | |
| 136 | 169 | protected: |
| 137 | 170 | virtual void setup_characteristics(); |
| 138 | 171 | }; |
| 139 | 172 | |
| 173 | class floppy_35_dd_nosd : public floppy_image_device { |
| 174 | public: |
| 175 | floppy_35_dd_nosd(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 176 | virtual ~floppy_35_dd_nosd(); |
| 177 | virtual void handled_variants(UINT32 *variants, int &var_count) const; |
| 178 | |
| 179 | protected: |
| 180 | virtual void setup_characteristics(); |
| 181 | }; |
| 182 | |
| 140 | 183 | class floppy_35_hd : public floppy_image_device { |
| 141 | 184 | public: |
| 142 | 185 | floppy_35_hd(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 143 | 186 | virtual ~floppy_35_hd(); |
| 187 | virtual void handled_variants(UINT32 *variants, int &var_count) const; |
| 144 | 188 | |
| 145 | 189 | protected: |
| 146 | 190 | virtual void setup_characteristics(); |
| r14121 | r14122 | |
| 150 | 194 | public: |
| 151 | 195 | floppy_35_ed(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 152 | 196 | virtual ~floppy_35_ed(); |
| 197 | virtual void handled_variants(UINT32 *variants, int &var_count) const; |
| 153 | 198 | |
| 154 | 199 | protected: |
| 155 | 200 | virtual void setup_characteristics(); |
| r14121 | r14122 | |
| 159 | 204 | public: |
| 160 | 205 | floppy_525_dd(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 161 | 206 | virtual ~floppy_525_dd(); |
| 207 | virtual void handled_variants(UINT32 *variants, int &var_count) const; |
| 162 | 208 | |
| 163 | 209 | protected: |
| 164 | 210 | virtual void setup_characteristics(); |
| r14121 | r14122 | |
| 186 | 232 | // device type definition |
| 187 | 233 | extern const device_type FLOPPY_CONNECTOR; |
| 188 | 234 | extern const device_type FLOPPY_35_DD; |
| 235 | extern const device_type FLOPPY_35_DD_NOSD; |
| 189 | 236 | extern const device_type FLOPPY_35_HD; |
| 190 | 237 | extern const device_type FLOPPY_35_ED; |
| 191 | 238 | extern const device_type FLOPPY_525_DD; |