src/lib/formats/hxcmfm_dsk.c
| r0 | r12286 | |
| 1 | #include "hxcmfm_dsk.h" |
| 2 | |
| 3 | #define MFM_FORMAT_HEADER "HXCMFM" |
| 4 | |
| 5 | mfm_format::mfm_format(const char *name,const char *extensions,const char *description,const char *param_guidelines) : |
| 6 | floppy_image_format_t(name,extensions,description,param_guidelines) |
| 7 | { |
| 8 | } |
| 9 | |
| 10 | int mfm_format::identify(floppy_image *image) |
| 11 | { |
| 12 | UINT8 header[7]; |
| 13 | |
| 14 | image->image_read(header, 0, 7); |
| 15 | if ( memcmp( header, MFM_FORMAT_HEADER, 6 ) ==0) { |
| 16 | return 100; |
| 17 | } |
| 18 | return 0; |
| 19 | } |
| 20 | |
| 21 | |
| 22 | const floppy_format_type FLOPPY_MFM_FORMAT = &floppy_image_format_creator<mfm_format>; |
| | No newline at end of file |
src/lib/formats/flopimg.c
| r12285 | r12286 | |
| 932 | 932 | |
| 933 | 933 | LEGACY_FLOPPY_OPTIONS_START(default) |
| 934 | 934 | LEGACY_FLOPPY_OPTIONS_END |
| 935 | |
| 936 | |
| 937 | ////////////////////////////////////////////////////////// |
| 938 | /// New implementation |
| 939 | ////////////////////////////////////////////////////////// |
| 940 | |
| 941 | floppy_image::floppy_image(void *fp, const struct io_procs *procs,const struct floppy_format_def *formats) |
| 942 | { |
| 943 | m_io.file = fp; |
| 944 | m_io.procs = procs; |
| 945 | m_io.filler = 0xFF; |
| 946 | m_formats = formats; |
| 947 | } |
| 948 | |
| 949 | floppy_image::~floppy_image() |
| 950 | { |
| 951 | close(); |
| 952 | } |
| 953 | |
| 954 | void floppy_image::image_read(void *buffer, UINT64 offset, size_t length) |
| 955 | { |
| 956 | io_generic_read(&m_io, buffer, offset, length); |
| 957 | } |
| 958 | |
| 959 | void floppy_image::image_write(const void *buffer, UINT64 offset, size_t length) |
| 960 | { |
| 961 | io_generic_write(&m_io, buffer, offset, length); |
| 962 | } |
| 963 | |
| 964 | void floppy_image::image_write_filler(UINT8 filler, UINT64 offset, size_t length) |
| 965 | { |
| 966 | io_generic_write_filler(&m_io, filler, offset, length); |
| 967 | } |
| 968 | |
| 969 | UINT64 floppy_image::image_size() |
| 970 | { |
| 971 | return io_generic_size(&m_io); |
| 972 | } |
| 973 | |
| 974 | void floppy_image::close_internal(bool close_file) |
| 975 | { |
| 976 | if (close_file) |
| 977 | io_generic_close(&m_io); |
| 978 | } |
| 979 | |
| 980 | void floppy_image::close() |
| 981 | { |
| 982 | close_internal(TRUE); |
| 983 | } |
| 984 | |
| 985 | |
| 986 | floppy_image_format_t::floppy_image_format_t(const char *name,const char *extensions,const char *description,const char *param_guidelines) |
| 987 | { |
| 988 | m_name = name; |
| 989 | m_extensions = extensions; |
| 990 | m_description = description; |
| 991 | m_param_guidelines = param_guidelines; |
| 992 | } |
| 993 | floppy_image_format_t::~floppy_image_format_t() |
| 994 | { |
| 995 | } |
| 996 | |
| 997 | int floppy_image_format_t::identify(floppy_image *image) |
| 998 | { |
| 999 | return 0; |
| 1000 | } |
| 1001 | |
| 1002 | const struct floppy_format_def *floppy_image::identify() |
| 1003 | { |
| 1004 | const struct floppy_format_def *retVal = NULL; |
| 1005 | int best_vote = 0; |
| 1006 | |
| 1007 | for (int i = 0; m_formats[i].type; i++) |
| 1008 | { |
| 1009 | 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); |
| 1010 | int vote = t->identify(this); |
| 1011 | /* is this option a better one? */ |
| 1012 | if (vote > best_vote) |
| 1013 | { |
| 1014 | best_vote = vote; |
| 1015 | retVal = &m_formats[i]; |
| 1016 | } |
| 1017 | } |
| 1018 | return retVal; |
| 1019 | } |
src/lib/formats/flopimg.h
| r12285 | r12286 | |
| 213 | 213 | /* misc */ |
| 214 | 214 | const char *floppy_error(floperr_t err); |
| 215 | 215 | |
| 216 | ////////////////////////////////////////////////////////// |
| 217 | /// New implementation |
| 218 | ////////////////////////////////////////////////////////// |
| 219 | |
| 220 | class floppy_image; |
| 221 | |
| 222 | class floppy_image_format_t |
| 223 | { |
| 224 | public: |
| 225 | floppy_image_format_t(const char *name,const char *extensions,const char *description,const char *param_guidelines); |
| 226 | virtual ~floppy_image_format_t(); |
| 227 | |
| 228 | virtual int identify(floppy_image *image); |
| 229 | |
| 230 | protected: |
| 231 | const char *m_name; |
| 232 | const char *m_extensions; |
| 233 | const char *m_description; |
| 234 | const char *m_param_guidelines; |
| 235 | }; |
| 236 | |
| 237 | |
| 238 | // a device_type is simply a pointer to its alloc function |
| 239 | typedef floppy_image_format_t *(*floppy_format_type)(const char *name,const char *extensions,const char *description,const char *param_guidelines); |
| 240 | |
| 241 | // this template function creates a stub which constructs a image format |
| 242 | template<class _FormatClass> |
| 243 | floppy_image_format_t *floppy_image_format_creator(const char *name,const char *extensions,const char *description,const char *param_guidelines) |
| 244 | { |
| 245 | return new _FormatClass(name, extensions, description, param_guidelines); |
| 246 | } |
| 247 | |
| 248 | struct floppy_format_def |
| 249 | { |
| 250 | const char *name; |
| 251 | const char *extensions; |
| 252 | const char *description; |
| 253 | const floppy_format_type type; |
| 254 | const char *param_guidelines; |
| 255 | }; |
| 256 | |
| 257 | #define FLOPPY_OPTIONS_START(name) \ |
| 258 | const struct floppy_format_def floppyoptions_##name[] = \ |
| 259 | { \ |
| 260 | |
| 261 | #define FLOPPY_OPTIONS_END0 \ |
| 262 | { NULL, NULL, NULL, NULL, NULL } \ |
| 263 | }; |
| 264 | |
| 265 | #define FLOPPY_OPTIONS_EXTERN(name) \ |
| 266 | extern const struct floppy_format_def floppyoptions_##name[] \ |
| 267 | |
| 268 | #define FLOPPY_OPTION(name, extensions_, description_, type_, ranges_)\ |
| 269 | { #name, extensions_, description_, type_, ranges_ }, \ |
| 270 | |
| 271 | #define FLOPPY_OPTIONS_END \ |
| 272 | FLOPPY_OPTIONS_END0 |
| 273 | |
| 274 | // ======================> floppy_image |
| 275 | |
| 276 | // class representing floppy image |
| 277 | class floppy_image |
| 278 | { |
| 279 | public: |
| 280 | // construction/destruction |
| 281 | floppy_image(void *fp, const struct io_procs *procs,const struct floppy_format_def *formats); |
| 282 | virtual ~floppy_image(); |
| 283 | |
| 284 | void image_read(void *buffer, UINT64 offset, size_t length); |
| 285 | void image_write(const void *buffer, UINT64 offset, size_t length); |
| 286 | void image_write_filler(UINT8 filler, UINT64 offset, size_t length); |
| 287 | UINT64 image_size(); |
| 288 | void close(); |
| 289 | |
| 290 | const struct floppy_format_def *identify(); |
| 291 | private: |
| 292 | void close_internal(bool close_file); |
| 293 | struct io_generic m_io; |
| 294 | const struct floppy_format_def *m_formats; |
| 295 | }; |
| 296 | |
| 216 | 297 | #endif /* FLOPIMG_H */ |
| 217 | 298 | |
src/mess/tools/floptool/floptool.mak
| r0 | r12286 | |
| 1 | ########################################################################### |
| 2 | # |
| 3 | # floptool.mak |
| 4 | # |
| 5 | # MESS floptool makefile |
| 6 | # |
| 7 | ########################################################################### |
| 8 | |
| 9 | |
| 10 | # floptool executable name |
| 11 | FLOPTOOL = floptool$(EXE) |
| 12 | |
| 13 | # add path to floptool headers |
| 14 | INCPATH += -I$(SRC)/$(TARGET)/tools/floptool |
| 15 | |
| 16 | # floptool directories |
| 17 | FLOPTOOLOBJ = $(MESS_TOOLS)/floptool |
| 18 | |
| 19 | |
| 20 | #------------------------------------------------- |
| 21 | # floptool objects |
| 22 | #------------------------------------------------- |
| 23 | |
| 24 | OBJDIRS += \ |
| 25 | $(FLOPTOOLOBJ) |
| 26 | |
| 27 | FLOPTOOL_OBJS = \ |
| 28 | $(FLOPTOOLOBJ)/main.o \ |
| 29 | |
| 30 | |
| 31 | |
| 32 | #------------------------------------------------- |
| 33 | # rules to build the floptool executable |
| 34 | #------------------------------------------------- |
| 35 | |
| 36 | $(FLOPTOOL): $(FLOPTOOL_OBJS) $(FORMATS_LIB) $(LIBUTIL) $(EXPAT) $(ZLIB) $(LIBOCORE) |
| 37 | @echo Linking $@... |
| 38 | $(LD) $(LDFLAGS) $^ $(LIBS) -o $@ |
src/mess/tools/floptool/main.c
| r0 | r12286 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | main.c |
| 4 | |
| 5 | Floptool command line front end |
| 6 | |
| 7 | 20/07/2011 Initial version by Miodrag Milanovic |
| 8 | |
| 9 | ***************************************************************************/ |
| 10 | |
| 11 | #include <stdio.h> |
| 12 | #include <string.h> |
| 13 | #include <ctype.h> |
| 14 | #include <stdlib.h> |
| 15 | #include <time.h> |
| 16 | #include <assert.h> |
| 17 | |
| 18 | #include "corestr.h" |
| 19 | |
| 20 | #include "formats/flopimg.h" |
| 21 | |
| 22 | static FLOPPY_OPTIONS_START( supported ) |
| 23 | FLOPPY_OPTION( mfm, "mfm", "HxCFloppyEmulator floppy disk image", FLOPPY_MFM_FORMAT, NULL ) |
| 24 | FLOPPY_OPTIONS_END |
| 25 | |
| 26 | static void display_usage(void) |
| 27 | { |
| 28 | fprintf(stderr, "Usage: \n"); |
| 29 | fprintf(stderr, " floptool.exe identify <inputfile>\n"); |
| 30 | } |
| 31 | |
| 32 | static void display_formats(void) |
| 33 | { |
| 34 | int i; |
| 35 | fprintf(stderr, "Supported formats:\n\n"); |
| 36 | for (i = 0; floppyoptions_supported[i].name; i++) { |
| 37 | fprintf(stderr, "%15s - %s\n",floppyoptions_supported[i].name,floppyoptions_supported[i].description); |
| 38 | fprintf(stderr, "%20s [%s]\n","",floppyoptions_supported[i].extensions); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | int CLIB_DECL main(int argc, char *argv[]) |
| 43 | { |
| 44 | FILE *f; |
| 45 | |
| 46 | if (argc > 1) |
| 47 | { |
| 48 | if (!core_stricmp("identify", argv[1])) |
| 49 | { |
| 50 | // convert command |
| 51 | if (argc!=3) { |
| 52 | fprintf(stderr, "Wrong parameter number.\n\n"); |
| 53 | display_usage(); |
| 54 | return -1; |
| 55 | } else { |
| 56 | f = fopen(argv[2], "rb"); |
| 57 | if (!f) { |
| 58 | fprintf(stderr, "File %s not found.\n",argv[2]); |
| 59 | return -1; |
| 60 | } |
| 61 | floppy_image *image = new floppy_image(f, &stdio_ioprocs_noclose, floppyoptions_supported); |
| 62 | const struct floppy_format_def *format = image->identify(); |
| 63 | if (format) { |
| 64 | fprintf(stderr, "File identified as %s\n",format->description); |
| 65 | } else { |
| 66 | fprintf(stderr, "Unable to identified file type\n"); |
| 67 | } |
| 68 | fclose(f); |
| 69 | goto theend; |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | /* Usage */ |
| 75 | fprintf(stderr, "floptool - Generic floppy image manipulation tool for use with MESS\n\n"); |
| 76 | display_usage(); |
| 77 | fprintf(stderr, "\n"); |
| 78 | display_formats(); |
| 79 | fprintf(stderr, "\nExample usage:\n"); |
| 80 | fprintf(stderr, " floptool.exe identify image.dsk\n\n"); |
| 81 | |
| 82 | theend : |
| 83 | return 0; |
| 84 | } |