diff options
| author | 2011-08-30 10:58:21 +0000 | |
|---|---|---|
| committer | 2011-08-30 10:58:21 +0000 | |
| commit | f900b44eb05a96128fa00fb6e6710f16b8ba6f9d (patch) | |
| tree | 0d3724cdc2aec485a3b12061e2e44a68b75ccb64 /src/lib | |
| parent | 846463227fd91de58e3f20ae17e39ea1a4c84193 (diff) | |
floppy: Refactor slightly. Name, descrition, etc are now an intrinsic property of converters. [O. Galibert]
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/formats/ami_dsk.c | 23 | ||||
| -rw-r--r-- | src/lib/formats/ami_dsk.h | 7 | ||||
| -rw-r--r-- | src/lib/formats/flopimg.c | 52 | ||||
| -rw-r--r-- | src/lib/formats/flopimg.h | 61 | ||||
| -rw-r--r-- | src/lib/formats/hxcmfm_dsk.c | 23 | ||||
| -rw-r--r-- | src/lib/formats/hxcmfm_dsk.h | 7 | ||||
| -rw-r--r-- | src/lib/formats/st_dsk.c | 3 | ||||
| -rw-r--r-- | src/lib/formats/st_dsk.h | 2 |
8 files changed, 108 insertions, 70 deletions
diff --git a/src/lib/formats/ami_dsk.c b/src/lib/formats/ami_dsk.c index 06669a964f9..b12b561d780 100644 --- a/src/lib/formats/ami_dsk.c +++ b/src/lib/formats/ami_dsk.c @@ -8,11 +8,30 @@ #include "formats/ami_dsk.h" -adf_format::adf_format(const char *name,const char *extensions,const char *description,const char *param_guidelines) : - floppy_image_format_t(name,extensions,description,param_guidelines) +adf_format::adf_format() : floppy_image_format_t() { } +const char *adf_format::name() const +{ + return "adf"; +} + +const char *adf_format::description() const +{ + return "Amiga ADF floppy disk image"; +} + +const char *adf_format::extensions() const +{ + return "adf"; +} + +bool adf_format::supports_save() const +{ + return false; +} + int adf_format::identify(floppy_image *image) { UINT64 size = image->image_size(); diff --git a/src/lib/formats/ami_dsk.h b/src/lib/formats/ami_dsk.h index adad1f0712e..cfe1c71c763 100644 --- a/src/lib/formats/ami_dsk.h +++ b/src/lib/formats/ami_dsk.h @@ -14,11 +14,16 @@ class adf_format : public floppy_image_format_t { public: - adf_format(const char *name,const char *extensions,const char *description,const char *param_guidelines); + adf_format(); virtual int identify(floppy_image *image); virtual bool load(floppy_image *image); + virtual const char *name() const; + virtual const char *description() const; + virtual const char *extensions() const; + virtual bool supports_save() const; + static const desc_e desc[]; }; diff --git a/src/lib/formats/flopimg.c b/src/lib/formats/flopimg.c index 14268e28c58..66150e44295 100644 --- a/src/lib/formats/flopimg.c +++ b/src/lib/formats/flopimg.c @@ -941,16 +941,26 @@ LEGACY_FLOPPY_OPTIONS_END /// New implementation ////////////////////////////////////////////////////////// -floppy_image::floppy_image(void *fp, const struct io_procs *procs,const struct floppy_format_def *formats) +floppy_image::floppy_image(void *fp, const struct io_procs *procs, const floppy_format_type *formats) { m_io.file = fp; m_io.procs = procs; m_io.filler = 0xFF; - m_formats = formats; + m_formats = 0; + for(int i=0; formats[i]; i++) + { + floppy_image_format_t *fif = formats[i](); + if(m_formats) + m_formats->append(fif); + else + m_formats = fif; + } } floppy_image::~floppy_image() { + if(m_formats) + delete m_formats; close(); } @@ -993,41 +1003,47 @@ void floppy_image::set_meta_data(UINT16 tracks, UINT8 sides, UINT16 rpm, UINT16 m_bitrate= bitrate; } -const struct floppy_format_def *floppy_image::identify(int *best) +floppy_image_format_t *floppy_image::identify(int *best) { - const struct floppy_format_def *retVal = NULL; + floppy_image_format_t *retVal = NULL; int best_vote = 0; *best = -1; - for (int i = 0; m_formats[i].type; i++) + int id = 0; + for(floppy_image_format_t *fif = m_formats; fif; fif = fif->next) { - floppy_image_format_t *t = (m_formats[i].type)(m_formats[i].name,m_formats[i].extensions,m_formats[i].description,m_formats[i].param_guidelines); - int vote = t->identify(this); + int vote = fif->identify(this); /* is this option a better one? */ if (vote > best_vote) { best_vote = vote; - *best = i; - retVal = &m_formats[i]; + *best = id; + retVal = fif; } + id++; } return retVal; } -bool floppy_image::load(int num) +floppy_image_format_t::floppy_image_format_t() { - floppy_image_format_t *t = (m_formats[num].type)(m_formats[num].name,m_formats[num].extensions,m_formats[num].description,m_formats[num].param_guidelines); - return t->load(this); + next = 0; } -floppy_image_format_t::floppy_image_format_t(const char *name,const char *extensions,const char *description,const char *param_guidelines) +floppy_image_format_t::~floppy_image_format_t() { - m_name = name; - m_extensions = extensions; - m_description = description; - m_param_guidelines = param_guidelines; } -floppy_image_format_t::~floppy_image_format_t() + +void floppy_image_format_t::append(floppy_image_format_t *_next) +{ + if(next) + next->append(_next); + else + next = _next; +} + +bool floppy_image_format_t::save(floppy_image *) { + return false; } bool floppy_image_format_t::type_no_data(int type) const diff --git a/src/lib/formats/flopimg.h b/src/lib/formats/flopimg.h index 3b9d2f1899b..5a2dff6616c 100644 --- a/src/lib/formats/flopimg.h +++ b/src/lib/formats/flopimg.h @@ -222,11 +222,21 @@ class floppy_image; class floppy_image_format_t { public: - floppy_image_format_t(const char *name,const char *extensions,const char *description,const char *param_guidelines); + floppy_image_format_t(); virtual ~floppy_image_format_t(); virtual int identify(floppy_image *image) = 0; virtual bool load(floppy_image *image) = 0; + virtual bool save(floppy_image *image); + + virtual const char *name() const = 0; + virtual const char *description() const = 0; + virtual const char *extensions() const = 0; + virtual bool supports_save() const = 0; + + floppy_image_format_t *next; + void append(floppy_image_format_t *_next); + protected: // Struct designed for easy track data description // Optional, you can always do things by hand, but useful nevertheless @@ -257,7 +267,7 @@ protected: SECTOR_DATA_O, // Sector data to mfm-encode, odd bits only, which in p1, -1 for the current one per the sector id SECTOR_DATA_E, // Sector data to mfm-encode, even bits only, which in p1, -1 for the current one per the sector id - CRC_CCITT_START, // Start a CCITT CRC calculation, with the usual x^16 + x^12 + x^5 + 1 (11021) polynomial, p1 = crc id, p2 = init value + CRC_CCITT_START, // Start a CCITT CRC calculation, with the usual x^16 + x^12 + x^5 + 1 (11021) polynomial, p1 = crc id CRC_AMIGA_START, // Start an amiga checksum calculation, p1 = crc id CRC_END, // End the checksum, p1 = crc id CRC, // Write a checksum in the apporpriate format, p1 = crc id @@ -279,11 +289,6 @@ protected: void generate_track(const desc_e *desc, UINT8 track, UINT8 head, const desc_s *sect, int sect_count, int track_size, UINT8 *buffer); - const char *m_name; - const char *m_extensions; - const char *m_description; - const char *m_param_guidelines; - private: enum { CRC_NONE, CRC_AMIGA, CRC_CCITT }; enum { MAX_CRC_COUNT = 64 }; @@ -308,45 +313,16 @@ private: void collect_crcs(const desc_e *desc, gen_crc_info *crcs); }; - // a device_type is simply a pointer to its alloc function -typedef floppy_image_format_t *(*floppy_format_type)(const char *name,const char *extensions,const char *description,const char *param_guidelines); +typedef floppy_image_format_t *(*floppy_format_type)(); // this template function creates a stub which constructs a image format template<class _FormatClass> -floppy_image_format_t *floppy_image_format_creator(const char *name,const char *extensions,const char *description,const char *param_guidelines) +floppy_image_format_t *floppy_image_format_creator() { - return new _FormatClass(name, extensions, description, param_guidelines); + return new _FormatClass(); } -struct floppy_format_def -{ - const char *name; - const char *extensions; - const char *description; - const floppy_format_type type; - const char *param_guidelines; -}; - -#define FLOPPY_OPTIONS_NAME(name) floppyoptions_##name - -#define FLOPPY_OPTIONS_START(name) \ - const struct floppy_format_def floppyoptions_##name[] = \ - { \ - -#define FLOPPY_OPTIONS_END0 \ - { NULL, NULL, NULL, NULL, NULL } \ - }; - -#define FLOPPY_OPTIONS_EXTERN(name) \ - extern const struct floppy_format_def floppyoptions_##name[] \ - -#define FLOPPY_OPTION(name, extensions_, description_, type_, ranges_)\ - { #name, extensions_, description_, type_, ranges_ }, \ - -#define FLOPPY_OPTIONS_END \ - FLOPPY_OPTIONS_END0 - // ======================> floppy_image #define MAX_FLOPPY_SIDES 2 @@ -358,7 +334,7 @@ class floppy_image { public: // construction/destruction - floppy_image(void *fp, const struct io_procs *procs,const struct floppy_format_def *formats); + floppy_image(void *fp, const struct io_procs *procs, const floppy_format_type *formats); virtual ~floppy_image(); void image_read(void *buffer, UINT64 offset, size_t length); @@ -369,15 +345,14 @@ public: void set_meta_data(UINT16 tracks, UINT8 sides, UINT16 rpm, UINT16 bitrate); void set_track_size(UINT16 track, UINT8 side, UINT16 size) { m_track_size[(track << 1) + side] = size; } - const struct floppy_format_def *identify(int *best); + floppy_image_format_t *identify(int *best); UINT8* get_buffer(UINT16 track, UINT8 side) { return m_native_data[(track << 1) + side]; } UINT16 get_track_size(UINT16 track, UINT8 side) { return m_track_size[(track << 1) + side]; } - bool load(int num); private: void close_internal(bool close_file); struct io_generic m_io; - const struct floppy_format_def *m_formats; + floppy_image_format_t *m_formats; UINT16 m_tracks; UINT8 m_sides; UINT16 m_rpm; diff --git a/src/lib/formats/hxcmfm_dsk.c b/src/lib/formats/hxcmfm_dsk.c index 9e6e18c5a50..f1b7a2c3195 100644 --- a/src/lib/formats/hxcmfm_dsk.c +++ b/src/lib/formats/hxcmfm_dsk.c @@ -28,11 +28,30 @@ struct MFMTRACKIMG #pragma pack() -mfm_format::mfm_format(const char *name,const char *extensions,const char *description,const char *param_guidelines) : - floppy_image_format_t(name,extensions,description,param_guidelines) +mfm_format::mfm_format() : floppy_image_format_t() { } +const char *mfm_format::name() const +{ + return "mfm"; +} + +const char *mfm_format::description() const +{ + return "HxCFloppyEmulator floppy disk image"; +} + +const char *mfm_format::extensions() const +{ + return "mfm"; +} + +bool mfm_format::supports_save() const +{ + return false; +} + int mfm_format::identify(floppy_image *image) { UINT8 header[7]; diff --git a/src/lib/formats/hxcmfm_dsk.h b/src/lib/formats/hxcmfm_dsk.h index e29c10aca75..1b77c8f6fd9 100644 --- a/src/lib/formats/hxcmfm_dsk.h +++ b/src/lib/formats/hxcmfm_dsk.h @@ -14,10 +14,15 @@ class mfm_format : public floppy_image_format_t { public: - mfm_format(const char *name,const char *extensions,const char *description,const char *param_guidelines); + mfm_format(); virtual int identify(floppy_image *image); virtual bool load(floppy_image *image); + + virtual const char *name() const; + virtual const char *description() const; + virtual const char *extensions() const; + virtual bool supports_save() const; }; extern const floppy_format_type FLOPPY_MFM_FORMAT; diff --git a/src/lib/formats/st_dsk.c b/src/lib/formats/st_dsk.c index 8804583270f..0208116459a 100644 --- a/src/lib/formats/st_dsk.c +++ b/src/lib/formats/st_dsk.c @@ -8,8 +8,7 @@ #include "formats/st_dsk.h" -st_gen_format::st_gen_format(const char *name,const char *extensions,const char *description,const char *param_guidelines) : - floppy_image_format_t(name,extensions,description,param_guidelines) +st_gen_format::st_gen_format() : floppy_image_format_t() { } diff --git a/src/lib/formats/st_dsk.h b/src/lib/formats/st_dsk.h index fe5c03d86f6..01c33dbeddd 100644 --- a/src/lib/formats/st_dsk.h +++ b/src/lib/formats/st_dsk.h @@ -14,7 +14,7 @@ class st_gen_format : public floppy_image_format_t { public: - st_gen_format(const char *name,const char *extensions,const char *description,const char *param_guidelines); + st_gen_format(); static const desc_e desc_fcp_9[]; |
