Previous 15994 Revisions Next

r14122 Sunday 22nd January, 2012 at 19:11:12 UTC by Olivier Galibert
floppy: Do specific UI handling [O. Galibert]
[src/emu]diimage.c diimage.h emu.h uiimage.c uiimage.h
[src/emu/imagedev]floppy.c floppy.h
[src/lib/formats]dfi_dsk.c flopimg.c flopimg.h mfi_dsk.c

src/emu/emu.h
r14121r14122
8888#include "ioport.h"
8989#include "output.h"
9090
91// diimage requires uimenu
92#include "uimenu.h"
93
9194// devices and callbacks
9295#include "device.h"
9396#include "distate.h"
src/emu/diimage.c
r14121r14122
649649    return err;
650650}
651651
652int 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
652706/*-------------------------------------------------
653707    determine_open_plan - determines which open
654708    flags to use, and in what order
r14121r14122
10401094    for ui-level image selection
10411095-------------------------------------------------*/
10421096
1043class ui_menu_control_device_image : public ui_menu {
1044public:
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
1050private:
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
10721097ui_menu *device_image_interface::get_selection_menu(running_machine &machine, render_container *container)
10731098{
10741099   return auto_alloc_clear(machine, ui_menu_control_device_image(machine, container, this));
r14121r14122
11281153   /* does a file or a directory exist at the path */
11291154   entry = osd_stat(path);
11301155   file_type = (entry != NULL) ? entry->type : ENTTYPE_NONE;
1131   if (entry != NULL)
1132      free(entry);
11331156
11341157   switch(file_type)
11351158   {
r14121r14122
11651188   astring temp_name(swi->shortname);
11661189   temp_name.cat(":");
11671190   temp_name.cat(swp->name);
1168   image->load(temp_name.cstr());
1191   hook_load(temp_name, true);
11691192}
11701193
1194void ui_menu_control_device_image::hook_load(astring name, bool softlist)
1195{
1196   image->load(name);
1197   ui_menu::stack_pop(machine());
1198}
1199
11711200void ui_menu_control_device_image::populate()
11721201{
11731202}
r14121r14122
12491278      switch(submenu_result) {
12501279      case ui_menu_software_parts::T_ENTRY: {
12511280         load_software_part();
1252         ui_menu::stack_pop(machine());
12531281         break;
12541282      }
12551283
r14121r14122
12731301         break;
12741302
12751303      case ui_menu_file_selector::R_FILE:
1276         image->load(current_file);
1277         ui_menu::stack_pop(machine());
1304         hook_load(current_file, false);
12781305         break;
12791306
12801307      case ui_menu_file_selector::R_CREATE:
r14121r14122
13011328            ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_confirm_save_as(machine(), container, &create_confirmed)));
13021329            state = CREATE_CONFIRM;
13031330         } 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();
13101333         }
13111334      } else {
13121335         state = START_FILE;
src/emu/diimage.h
r14121r14122
182182   virtual const char *file_extensions() const = 0;
183183   virtual const option_guide *create_option_guide() const = 0;
184184
185   virtual class ui_menu *get_selection_menu(running_machine &machine, class render_container *container);
185   virtual ui_menu *get_selection_menu(running_machine &machine, class render_container *container);
186186
187187   const image_device_format *device_get_indexed_creatable_format(int index);
188188   const image_device_format *device_get_named_creatable_format(const char *format_name);
r14121r14122
249249   void unload();
250250   bool create(const char *path, const image_device_format *create_format, option_resolution *create_args);
251251   bool load_software(char *swlist, char *swname, rom_entry *entry);
252   int reopen_for_write(const char *path);
253
252254protected:
253255   bool load_internal(const char *path, bool is_create, int create_format, option_resolution *create_args);
254256   void determine_open_plan(int is_create, UINT32 *open_plan);
r14121r14122
322324   bool m_is_loading;
323325};
324326
327class ui_menu_control_device_image : public ui_menu {
328public:
329   ui_menu_control_device_image(running_machine &machine, render_container *container, device_image_interface *image);
330   virtual ~ui_menu_control_device_image();
331   virtual void populate();
332   virtual void handle();
333     
334protected:
335   enum {
336      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,
337      LAST_ID
338   };
339   int state;
325340
341   device_image_interface *image;
342   astring current_directory;
343   astring current_file;
344   int submenu_result;
345   bool create_confirmed;
346   bool softlist_done;
347   const class software_list *swl;
348   const class software_info *swi;
349   const class software_part *swp;
350   const class software_list_config *slc;
351   astring software_info_name;
352
353   void test_create(bool &can_create, bool &need_confirm);
354   void load_software_part();
355   virtual void hook_load(astring filename, bool softlist);
356};
357
326358#endif   /* __DIIMAGE_H__ */
src/emu/uiimage.c
r14121r14122
2525#include "uiimage.h"
2626#include "zippath.h"
2727#include "unicode.h"
28#include "imagedev/floppy.h"
2829#include "imagedev/cassette.h"
2930#include "imagedev/bitbngr.h"
3031
r14121r14122
521522   const char *volume_name;
522523   const char *path = current_directory;
523524
524   if(path[0])
525      fprintf(stderr, "curdir=%s\n", path);
526
527525   /* open the directory */
528526   err = zippath_opendir(path, &directory);
529527   if (err != FILERR_NONE)
r14121r14122
877875   process(0);
878876}
879877
878/*-------------------------------------------------
879    ui_menu_select_format - floppy image format
880    selection menu
881-------------------------------------------------*/
882
883ui_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
893void 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
905ui_menu_select_format::~ui_menu_select_format()
906{
907}
908
909void 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
925ui_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
933void 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
943ui_menu_select_rw::~ui_menu_select_rw()
944{
945}
946
947void 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
880958/***************************************************************************
881959    TYPE DEFINITIONS
882960***************************************************************************/
src/emu/uiimage.h
r14121r14122
129129   void append_entry_menu_item(const file_selector_entry *entry);
130130};
131131
132class ui_menu_select_format : public ui_menu {
133public:
134   ui_menu_select_format(running_machine &machine, render_container *container,
135                    class floppy_image_format_t **formats, int ext_match, int total_usable, int *result);
136   virtual ~ui_menu_select_format();
137   virtual void populate();
138   virtual void handle();
139
140private:
141   floppy_image_format_t **formats;
142   int ext_match, total_usable;
143   int *result;
144};
145
146class ui_menu_select_rw : public ui_menu {
147public:
148   enum { READONLY, READWRITE, WRITE_OTHER, WRITE_DIFF };
149   ui_menu_select_rw(running_machine &machine, render_container *container,
150                 bool can_in_place, int *result);
151   virtual ~ui_menu_select_rw();
152   virtual void populate();
153   virtual void handle();
154
155private:
156   bool can_in_place;
157   int *result;
158};
159
132160#endif   /* __UIIMAGE_H__ */
src/emu/imagedev/floppy.c
r14121r14122
55*********************************************************************/
66
77#include "emu.h"
8#include "zippath.h"
89#include "floppy.h"
910#include "formats/imageutl.h"
11#include "uiimage.h"
1012
1113// device type definition
1214const device_type FLOPPY_CONNECTOR = &device_creator<floppy_connector>;
1315const device_type FLOPPY_35_DD = &device_creator<floppy_35_dd>;
16const device_type FLOPPY_35_DD_NOSD = &device_creator<floppy_35_dd_nosd>;
1417const device_type FLOPPY_35_HD = &device_creator<floppy_35_hd>;
1518const device_type FLOPPY_35_ED = &device_creator<floppy_35_ed>;
1619const device_type FLOPPY_525_DD = &device_creator<floppy_525_dd>;
r14121r14122
115118   update_names();
116119}
117120
121floppy_image_format_t *floppy_image_device::get_formats() const
122{
123   return fif_list;
124}
125
126floppy_image_format_t *floppy_image_device::get_load_format() const
127{
128   return input_format;
129}
130
118131void floppy_image_device::device_config_complete()
119132{
120133   update_names();
r14121r14122
129142   rev_time = attotime::from_double(60/rpm);
130143}
131144
145void floppy_image_device::setup_write(floppy_image_format_t *_output_format)
146{
147   output_format = _output_format;
148   commit_image();
149}
132150
151void 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
133164//-------------------------------------------------
134165//  device_start - device-specific startup
135166//-------------------------------------------------
r14121r14122
151182   stp = 1;
152183   dskchg = 0;
153184   index_timer = timer_alloc(0);
185   image_dirty = false;
154186}
155187
156188void floppy_image_device::device_reset()
r14121r14122
165197   index_resync();
166198}
167199
200floppy_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
168224bool floppy_image_device::call_load()
169225{
170226   io_generic io;
r14121r14122
192248   revolution_count = 0;
193249
194250   index_resync();
251   image_dirty = false;
252   output_format = 0;
195253
196254   if (!cur_load_cb.isnull())
197255      return cur_load_cb(this);
r14121r14122
203261   dskchg = 0;
204262
205263   if (image) {
264      if(image_dirty)
265         commit_image();
206266      global_free(image);
207267      image = 0;
208268   }
r14121r14122
210270      cur_unload_cb(this);
211271}
212272
273bool 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
213280/* motor on, active low */
214281void floppy_image_device::mon_w(int state)
215282{
r14121r14122
227294
228295   /* on -> off */
229296   else {
297      if(image_dirty)
298         commit_image();
230299      revolution_start_time = attotime::never;
231300      index_timer->adjust(attotime::zero);
232301   }
r14121r14122
377446
378447void floppy_image_device::write_flux(attotime start, attotime end, int transition_count, const attotime *transitions)
379448{
449   image_dirty = true;
450
380451   attotime base;
381452   int start_pos = find_position(base, start);
382453   int end_pos   = find_position(base, end);
r14121r14122
395466      index = 0;
396467      image->set_track_size(cyl, ss, 1);
397468      buf = image->get_buffer(cyl, ss);
398      buf[cells++] = floppy_image::MG_N | 200000000;
469      buf[cells++] = floppy_image::MG_N;
399470   }
400471
401472   if(index && (buf[index] & floppy_image::TIME_MASK) == start_pos)
r14121r14122
408479   UINT32 pos = start_pos;
409480   int ti = 0;
410481   while(pos != end_pos) {
411      if(image->get_track_size(cyl, ss) < cells+10)
482      if(image->get_track_size(cyl, ss) < cells+10) {
412483         image->set_track_size(cyl, ss, cells+200);
484         buf = image->get_buffer(cyl, ss);
485      }
413486      UINT32 next_pos;
414487      if(ti != transition_count)
415488         next_pos = trans_pos[ti++];
r14121r14122
530603   }
531604}
532605
606ui_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
611ui_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
624ui_menu_control_floppy_image::~ui_menu_control_floppy_image()
625{
626   global_free(format_array);
627}
628
629void 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
652void 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
679void 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
533752floppy_35_dd::floppy_35_dd(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
534753   floppy_image_device(mconfig, FLOPPY_35_DD, "3.5\" double density floppy drive", tag, owner, clock)
535754{
r14121r14122
547766   set_rpm(300);
548767}
549768
769void 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
777floppy_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
782floppy_35_dd_nosd::~floppy_35_dd_nosd()
783{
784}
785
786void 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
794void 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
550801floppy_35_hd::floppy_35_hd(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
551802   floppy_image_device(mconfig, FLOPPY_35_HD, "3.5\" high density floppy drive", tag, owner, clock)
552803{
r14121r14122
564815   set_rpm(300);
565816}
566817
818void 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
567827floppy_35_ed::floppy_35_ed(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
568828   floppy_image_device(mconfig, FLOPPY_35_ED, "3.5\" extended density floppy drive", tag, owner, clock)
569829{
r14121r14122
581841   set_rpm(300);
582842}
583843
844void 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}
584853
585854floppy_525_dd::floppy_525_dd(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
586855   floppy_image_device(mconfig, FLOPPY_525_DD, "5.25\" double density floppy drive", tag, owner, clock)
r14121r14122
598867   sides = 1;
599868   set_rpm(300);
600869}
870
871void 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
r14121r14122
3232   floppy_image_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock);
3333   virtual ~floppy_image_device();
3434
35   virtual void handled_variants(UINT32 *variants, int &var_count) const = 0;
36
3537   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;
3641   void set_rpm(float rpm);
3742
3843   // image-level overrides
3944   virtual bool call_load();
4045   virtual void call_unload();
46   virtual bool call_create(int format_type, option_resolution *format_options);
4147   virtual void call_display_info() {}
4248   virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) { return load_software(swlist, swname, start_entry); }
4349
r14121r14122
5056   virtual bool is_reset_on_load() const { return false; }
5157   virtual const char *file_extensions() const { return extension_list; }
5258   virtual const option_guide *create_option_guide() const { return NULL; }
59   void setup_write(floppy_image_format_t *output_format);
5360
5461   void setup_load_cb(load_cb cb);
5562   void setup_unload_cb(unload_cb cb);
r14121r14122
7986   UINT32 get_form_factor() const;
8087   UINT32 get_variant() const;
8188
89   virtual ui_menu *get_selection_menu(running_machine &machine, class render_container *container);
90
8291protected:
8392   // device-level overrides
8493   virtual void device_config_complete();
r14121r14122
8998   virtual void setup_characteristics() = 0;
9099
91100   image_device_format   format;
101   floppy_image_format_t *input_format;
102   floppy_image_format_t *output_format;
92103   floppy_image        *image;
93104   char              extension_list[256];
94105   floppy_image_format_t *fif_list;
r14121r14122
119130   UINT32 revolution_count;
120131   int cyl;
121132
133   bool image_dirty;
134
122135   load_cb cur_load_cb;
123136   unload_cb cur_unload_cb;
124137   index_pulse_cb cur_index_pulse_cb;
r14121r14122
126139   UINT32 find_position(attotime &base, attotime when);
127140   int find_index(UINT32 position, const UINT32 *buf, int buf_size);
128141   void write_zone(UINT32 *buf, int &cells, int &index, UINT32 spos, UINT32 epos, UINT32 mg);
142   void commit_image();
129143};
130144
145class ui_menu_control_floppy_image : public ui_menu_control_device_image {
146public:
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
152protected:
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
131163class floppy_35_dd : public floppy_image_device {
132164public:
133165   floppy_35_dd(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
134166   virtual ~floppy_35_dd();
167   virtual void handled_variants(UINT32 *variants, int &var_count) const;
135168
136169protected:
137170   virtual void setup_characteristics();
138171};
139172
173class floppy_35_dd_nosd : public floppy_image_device {
174public:
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
179protected:
180   virtual void setup_characteristics();
181};
182
140183class floppy_35_hd : public floppy_image_device {
141184public:
142185   floppy_35_hd(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
143186   virtual ~floppy_35_hd();
187   virtual void handled_variants(UINT32 *variants, int &var_count) const;
144188
145189protected:
146190   virtual void setup_characteristics();
r14121r14122
150194public:
151195   floppy_35_ed(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
152196   virtual ~floppy_35_ed();
197   virtual void handled_variants(UINT32 *variants, int &var_count) const;
153198
154199protected:
155200   virtual void setup_characteristics();
r14121r14122
159204public:
160205   floppy_525_dd(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
161206   virtual ~floppy_525_dd();
207   virtual void handled_variants(UINT32 *variants, int &var_count) const;
162208
163209protected:
164210   virtual void setup_characteristics();
r14121r14122
186232// device type definition
187233extern const device_type FLOPPY_CONNECTOR;
188234extern const device_type FLOPPY_35_DD;
235extern const device_type FLOPPY_35_DD_NOSD;
189236extern const device_type FLOPPY_35_HD;
190237extern const device_type FLOPPY_35_ED;
191238extern const device_type FLOPPY_525_DD;
src/lib/formats/flopimg.c
r14121r14122
10081008   }
10091009}
10101010
1011const char *floppy_image::get_variant_name(UINT32 form_factor, UINT32 variant)
1012{
1013   switch(variant) {
1014   case SSSD: return "Single side, single density";
1015   case SSDD: return "Single side, double density";
1016   case DSDD: return "Double side, double density";
1017   case DSHD: return "Double side, high density";
1018   case DSED: return "Double side, extended density";
1019   }
1020   return "Unknown";
1021}
1022
10111023floppy_image_format_t::floppy_image_format_t()
10121024{
10131025   next = 0;
r14121r14122
10301042   return false;
10311043}
10321044
1045bool floppy_image_format_t::extension_matches(const char *file_name) const
1046{
1047   const char *ext = strrchr(file_name, '.');
1048   if(!ext)
1049      return false;
1050   ext++;
1051   int elen = strlen(ext);
1052   const char *rext = extensions();
1053   for(;;) {
1054      const char *next = strchr(rext, ',');
1055      int rlen = next ? next - rext : strlen(rext);
1056      if(rlen == elen && !memcmp(ext, rext, rlen))
1057         return true;
1058      if(next)
1059         rext = next+1;
1060      else
1061         break;         
1062   }
1063   return false;
1064}
1065
10331066bool floppy_image_format_t::type_no_data(int type) const
10341067{
10351068   return type == CRC_CCITT_START ||
r14121r14122
21782211{
21792212   image->get_actual_geometry(track_count, head_count);
21802213
2214   if(!track_count) {
2215      sector_count = 0;
2216      return;
2217   }
2218
21812219   UINT8 bitstream[500000/8];
21822220   UINT8 sectdata[50000];
21832221   desc_xs sectors[256];
r14121r14122
21902228   // 0-10, not near the end like 70+, no special effects on sync
21912229   // like 33
21922230
2193   generate_bitstream_from_track(20, 0, cell_size, bitstream, track_size, image);
2231   generate_bitstream_from_track(track_count > 20 ? 20 : 0, 0, cell_size, bitstream, track_size, image);
21942232   extract_sectors_from_bitstream_mfm_pc(bitstream, track_size, sectors, sectdata, sizeof(sectdata));
21952233
21962234   for(sector_count = 44; sector_count > 0 && !sectors[sector_count].data; sector_count--);
src/lib/formats/flopimg.h
r14121r14122
237237   floppy_image_format_t *next;
238238   void append(floppy_image_format_t *_next);
239239
240   bool extension_matches(const char *file_name) const;
241
240242protected:
241243   // Input for convert_to_edge
242244   enum {
r14121r14122
522524
523525   // Variants
524526   enum {
527      SSSD  = 0x44535353, // "SSSD",
528      SSDD  = 0x44445353, // "DSSD",
525529      DSDD  = 0x44445344, // "DSDD",
526530      DSHD  = 0x44485344, // "DSHD",
527531      DSED  = 0x44455344, // "DSED",
r14121r14122
543547   void get_maximal_geometry(int &tracks, int &heads);
544548   void get_actual_geometry(int &tracks, int &heads);
545549
550   static const char *get_variant_name(UINT32 form_factor, UINT32 variant);
551
546552private:
547553   enum {
548554      MAX_FLOPPY_HEADS = 2,
src/lib/formats/dfi_dsk.c
r14121r14122
2323
2424bool dfi_format::supports_save() const
2525{
26   return true;
26   return false;
2727}
2828
2929int dfi_format::identify(io_generic *io, UINT32 form_factor)
src/lib/formats/mfi_dsk.c
r14121r14122
9595
9696   io_generic_read(io, &h, 0, sizeof(header));
9797   if(memcmp( h.sign, sign, 16 ) == 0 &&
98      h.cyl_count > 0 && h.cyl_count <= 84 &&
99      h.head_count > 0 && h.head_count <= 2 &&
100      h.form_factor == form_factor)
98      h.cyl_count <= 160 &&
99      h.head_count <= 2 &&
100      (!form_factor || h.form_factor == form_factor))
101101      return 100;
102102   return 0;
103103}

Previous 15994 Revisions Next


© 1998-2018 The MESS Team