floppy: Refactor slightly. Name, descrition, etc are now an intrinsic property of converters. [O. Galibert]

This commit is contained in:
Olivier Galibert 2011-08-30 10:58:21 +00:00
parent 846463227f
commit f900b44eb0
10 changed files with 122 additions and 81 deletions

View File

@ -57,19 +57,21 @@ void floppy_image_device::device_config_complete()
image_device_format **formatptr; image_device_format **formatptr;
image_device_format *format; image_device_format *format;
formatptr = &m_formatlist; formatptr = &m_formatlist;
int cnt = 0;
m_extension_list[0] = '\0'; m_extension_list[0] = '\0';
while (m_formats[cnt].name) m_fif_list = 0;
for(int cnt=0; m_formats[cnt]; cnt++)
{ {
// allocate a new format // allocate a new format
floppy_image_format_t *fif = m_formats[cnt]();
format = global_alloc_clear(image_device_format); format = global_alloc_clear(image_device_format);
format->m_index = cnt; format->m_index = cnt;
format->m_name = m_formats[cnt].name; format->m_name = fif->name();
format->m_description = m_formats[cnt].description; format->m_description = fif->description();
format->m_extensions = m_formats[cnt].extensions; format->m_extensions = fif->extensions();
format->m_optspec = (m_formats[cnt].param_guidelines) ? m_formats[cnt].param_guidelines : ""; format->m_optspec = "";
image_specify_extension( m_extension_list, 256, m_formats[cnt].extensions ); image_specify_extension( m_extension_list, 256, fif->extensions() );
// and append it to the list // and append it to the list
*formatptr = format; *formatptr = format;
formatptr = &format->m_next; formatptr = &format->m_next;
@ -116,10 +118,10 @@ bool floppy_image_device::call_load()
device_image_interface *image = this; device_image_interface *image = this;
int best; int best;
m_image = global_alloc(floppy_image((void *) image, &image_ioprocs, m_formats)); m_image = global_alloc(floppy_image((void *) image, &image_ioprocs, m_formats));
const struct floppy_format_def *format = m_image->identify(&best); floppy_image_format_t *format = m_image->identify(&best);
m_dskchg = 0; m_dskchg = 0;
if (format) { if (format) {
m_image->load(best); format->load(m_image);
if (m_load_func) if (m_load_func)
return m_load_func(*this); return m_load_func(*this);
} else { } else {

View File

@ -18,7 +18,7 @@ struct floppy_interface
{ {
devcb_write_line m_out_idx_cb; /* index */ devcb_write_line m_out_idx_cb; /* index */
const struct floppy_format_def *m_formats; const floppy_format_type *m_formats;
const char * m_interface; const char * m_interface;
device_image_display_info_func m_device_displayinfo; device_image_display_info_func m_device_displayinfo;
device_image_load_func m_load_func; device_image_load_func m_load_func;
@ -76,6 +76,7 @@ protected:
image_device_format m_format; image_device_format m_format;
floppy_image *m_image; floppy_image *m_image;
char m_extension_list[256]; char m_extension_list[256];
floppy_image_format_t *m_fif_list;
/* index pulse timer */ /* index pulse timer */
emu_timer *m_index_timer; emu_timer *m_index_timer;

View File

@ -8,11 +8,30 @@
#include "formats/ami_dsk.h" #include "formats/ami_dsk.h"
adf_format::adf_format(const char *name,const char *extensions,const char *description,const char *param_guidelines) : adf_format::adf_format() : floppy_image_format_t()
floppy_image_format_t(name,extensions,description,param_guidelines)
{ {
} }
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) int adf_format::identify(floppy_image *image)
{ {
UINT64 size = image->image_size(); UINT64 size = image->image_size();

View File

@ -14,11 +14,16 @@
class adf_format : public floppy_image_format_t class adf_format : public floppy_image_format_t
{ {
public: 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 int identify(floppy_image *image);
virtual bool load(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[]; static const desc_e desc[];
}; };

View File

@ -941,16 +941,26 @@ LEGACY_FLOPPY_OPTIONS_END
/// New implementation /// 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.file = fp;
m_io.procs = procs; m_io.procs = procs;
m_io.filler = 0xFF; 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() floppy_image::~floppy_image()
{ {
if(m_formats)
delete m_formats;
close(); close();
} }
@ -993,43 +1003,49 @@ void floppy_image::set_meta_data(UINT16 tracks, UINT8 sides, UINT16 rpm, UINT16
m_bitrate= bitrate; 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; int best_vote = 0;
*best = -1; *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 = fif->identify(this);
int vote = t->identify(this);
/* is this option a better one? */ /* is this option a better one? */
if (vote > best_vote) if (vote > best_vote)
{ {
best_vote = vote; best_vote = vote;
*best = i; *best = id;
retVal = &m_formats[i]; retVal = fif;
} }
id++;
} }
return retVal; 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); next = 0;
return t->load(this);
} }
floppy_image_format_t::floppy_image_format_t(const char *name,const char *extensions,const char *description,const char *param_guidelines)
{
m_name = name;
m_extensions = extensions;
m_description = description;
m_param_guidelines = param_guidelines;
}
floppy_image_format_t::~floppy_image_format_t() 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 bool floppy_image_format_t::type_no_data(int type) const
{ {
return type == CRC_CCITT_START || return type == CRC_CCITT_START ||

View File

@ -222,11 +222,21 @@ class floppy_image;
class floppy_image_format_t class floppy_image_format_t
{ {
public: 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 ~floppy_image_format_t();
virtual int identify(floppy_image *image) = 0; virtual int identify(floppy_image *image) = 0;
virtual bool load(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: protected:
// Struct designed for easy track data description // Struct designed for easy track data description
// Optional, you can always do things by hand, but useful nevertheless // 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_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 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_AMIGA_START, // Start an amiga checksum calculation, p1 = crc id
CRC_END, // End the checksum, p1 = crc id CRC_END, // End the checksum, p1 = crc id
CRC, // Write a checksum in the apporpriate format, 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); 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: private:
enum { CRC_NONE, CRC_AMIGA, CRC_CCITT }; enum { CRC_NONE, CRC_AMIGA, CRC_CCITT };
enum { MAX_CRC_COUNT = 64 }; enum { MAX_CRC_COUNT = 64 };
@ -308,45 +313,16 @@ private:
void collect_crcs(const desc_e *desc, gen_crc_info *crcs); void collect_crcs(const desc_e *desc, gen_crc_info *crcs);
}; };
// a device_type is simply a pointer to its alloc function // 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 // this template function creates a stub which constructs a image format
template<class _FormatClass> 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 // ======================> floppy_image
#define MAX_FLOPPY_SIDES 2 #define MAX_FLOPPY_SIDES 2
@ -358,7 +334,7 @@ class floppy_image
{ {
public: public:
// construction/destruction // 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(); virtual ~floppy_image();
void image_read(void *buffer, UINT64 offset, size_t length); 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_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; } 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]; } 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]; } UINT16 get_track_size(UINT16 track, UINT8 side) { return m_track_size[(track << 1) + side]; }
bool load(int num);
private: private:
void close_internal(bool close_file); void close_internal(bool close_file);
struct io_generic m_io; struct io_generic m_io;
const struct floppy_format_def *m_formats; floppy_image_format_t *m_formats;
UINT16 m_tracks; UINT16 m_tracks;
UINT8 m_sides; UINT8 m_sides;
UINT16 m_rpm; UINT16 m_rpm;

View File

@ -28,11 +28,30 @@ struct MFMTRACKIMG
#pragma pack() #pragma pack()
mfm_format::mfm_format(const char *name,const char *extensions,const char *description,const char *param_guidelines) : mfm_format::mfm_format() : floppy_image_format_t()
floppy_image_format_t(name,extensions,description,param_guidelines)
{ {
} }
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) int mfm_format::identify(floppy_image *image)
{ {
UINT8 header[7]; UINT8 header[7];

View File

@ -14,10 +14,15 @@
class mfm_format : public floppy_image_format_t class mfm_format : public floppy_image_format_t
{ {
public: 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 int identify(floppy_image *image);
virtual bool load(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; extern const floppy_format_type FLOPPY_MFM_FORMAT;

View File

@ -8,8 +8,7 @@
#include "formats/st_dsk.h" #include "formats/st_dsk.h"
st_gen_format::st_gen_format(const char *name,const char *extensions,const char *description,const char *param_guidelines) : st_gen_format::st_gen_format() : floppy_image_format_t()
floppy_image_format_t(name,extensions,description,param_guidelines)
{ {
} }

View File

@ -14,7 +14,7 @@
class st_gen_format : public floppy_image_format_t class st_gen_format : public floppy_image_format_t
{ {
public: 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[]; static const desc_e desc_fcp_9[];