mirror of
https://github.com/jfdelnero/HxCFloppyEmulator.git
synced 2026-07-28 04:06:36 +00:00
New Loader : MAME MFI file.
This commit is contained in:
@@ -113,7 +113,8 @@ DISKLOADERPLUGINS = raw_amiga.o raw_iso.o copyqm_loader.o crctable.o adf_loader.
|
||||
sdd_speccydos_loader.o arburg_raw_loader.o scp_loader.o bmp_loader.o northstar_loader.o xml_loader.o flppcm_loader.o stw_loader.o \
|
||||
vfddat_loader.o ana_loader.o atr_loader.o hfev3_loader.o hfev3_trackgen.o heathkit_loader.o sdu_loader.o xml_db_loader.o \
|
||||
streamhfe_loader.o qd_loader.o ipf_loader.o capslibloader.o hxcstream_loader.o hxcstream.o dfi_loader.o a2r_loader.o \
|
||||
micraln_loader.o fdx_loader.o 86f_loader.o logicanalyzer_loader.o apple2_2mg_loader.o dim_x68k_loader.o woz_loader.o
|
||||
micraln_loader.o fdx_loader.o 86f_loader.o logicanalyzer_loader.o apple2_2mg_loader.o dim_x68k_loader.o woz_loader.o \
|
||||
mfi_loader.o
|
||||
|
||||
DISKWRITERPLUGINS = cpcdsk_writer.o mfm_writer.o hfe_writer.o raw_writer.o afi_writer.o exthfe_writer.o imd_writer.o vtr_writer.o ti99v9t9_writer.o \
|
||||
jv3_writer.o dmk_writer.o d88_writer.o msa_writer.o hfe_hddd_a2_writer.o arburg_raw_writer.o sdd_speccydos_writer.o scp_writer.o \
|
||||
@@ -748,6 +749,9 @@ fdx_writer.o : $(BASEDIR)/loaders/fdx_loader/fdx_writer.c $(BASEDIR)/loaders/fdx
|
||||
woz_loader.o : $(BASEDIR)/loaders/woz_loader/woz_loader.c $(BASEDIR)/loaders/woz_loader/woz_loader.h $(BASEDIR)/loaders/woz_loader/woz_format.h
|
||||
$(CC) -o $@ -c $< $(CFLAGS)
|
||||
|
||||
mfi_loader.o : $(BASEDIR)/loaders/mfi_loader/mfi_loader.c $(BASEDIR)/loaders/mfi_loader/mfi_loader.h $(BASEDIR)/loaders/mfi_loader/mfi_loader.h
|
||||
$(CC) -o $@ -c $< $(CFLAGS)
|
||||
|
||||
adf_hd.o : $(BASEDIR)/thirdpartylibs/adflib/Lib/adf_hd.c
|
||||
$(CC) -o $@ -c $< $(CFLAGS)
|
||||
adf_disk.o : $(BASEDIR)/thirdpartylibs/adflib/Lib/adf_disk.c
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
//
|
||||
// Copyright (C) 2006-2024 Jean-François DEL NERO
|
||||
//
|
||||
// This file is part of the HxCFloppyEmulator library
|
||||
//
|
||||
// HxCFloppyEmulator may be used and distributed without restriction provided
|
||||
// that this copyright statement is not removed from the file and that any
|
||||
// derivative work contains the original copyright notice and the associated
|
||||
// disclaimer.
|
||||
//
|
||||
// HxCFloppyEmulator is free software; you can redistribute it
|
||||
// and/or modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// HxCFloppyEmulator is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with HxCFloppyEmulator; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
//
|
||||
*/
|
||||
|
||||
//
|
||||
// MFI file format documentation used :
|
||||
// https://github.com/mamedev/mame/blob/master/src/lib/formats/mfi_dsk.cpp
|
||||
//
|
||||
/*
|
||||
Mess floppy image structure:
|
||||
|
||||
- header with signature, number of cylinders, number of heads. Min
|
||||
track and min head are considered to always be 0. The two top bits
|
||||
of the cylinder count is the resolution: 0=tracks, 1=half tracks,
|
||||
2=quarter tracks.
|
||||
|
||||
- vector of track descriptions, looping on cylinders with the given
|
||||
resolution and sub-lopping on heads, each description composed of:
|
||||
- offset of the track data in bytes from the start of the file
|
||||
- size of the compressed track data in bytes (0 for unformatted)
|
||||
- size of the uncompressed track data in bytes (0 for unformatted)
|
||||
|
||||
- track data
|
||||
|
||||
All values are 32-bits lsb first.
|
||||
|
||||
Track data is zlib-compressed independently for each track using the
|
||||
simple "compress" function.
|
||||
|
||||
Track data consists of a series of 32-bits lsb-first values
|
||||
representing magnetic cells. Bits 0-27 indicate the position,
|
||||
delta-packed (e.g. difference with the previous position, starts at
|
||||
0), and bits 28-31 the types. Type can be:
|
||||
|
||||
- 0, MG_F -> Flux orientation change
|
||||
- 1, MG_N -> Non-magnetized zone (neutral)
|
||||
- 2, MG_D -> Damaged zone, reads as neutral but cannot be changed by writing
|
||||
- 3, MG_E -> End of zone
|
||||
|
||||
Tracks data is aligned so that the index pulse is at the start for soft-
|
||||
sectored disks. For hard-sectored disks, the sector hole for the first
|
||||
sector is at the start and the index hole is half a sector from the end
|
||||
of the track.
|
||||
|
||||
The position is the angular position in units of 1/200,000,000th of
|
||||
a turn. A size in such units, not coincidentally at all, is also
|
||||
the flyover time in nanoseconds for a perfectly stable 300rpm drive.
|
||||
That makes the standard cell size of a MFM 3.5" DD floppy at 2000
|
||||
exactly for instance (2us). Smallest expected cell size is 500 (ED
|
||||
density drives).
|
||||
|
||||
An unformatted track is equivalent to a pair (MG_N, 0), (MG_E,
|
||||
199999999) but is encoded as zero-size.
|
||||
|
||||
The "track splice" information indicates where to start writing
|
||||
if you try to rewrite a physical disk with the data. Some
|
||||
preservation formats encode that information, it is guessed for
|
||||
others. The write track function of fdcs should set it. The
|
||||
representation is the angular position relative to the index, for
|
||||
soft-sectored disks, and the first sector hole for hard-sectored
|
||||
disks.
|
||||
|
||||
The media type is divided in two parts. The first half
|
||||
indicate the physical form factor, i.e. all medias with that
|
||||
form factor can be physically inserted in a reader that handles
|
||||
it. The second half indicates the variants which are usually
|
||||
detectable by the reader, such as density and number of sides.
|
||||
|
||||
TODO: big-endian support
|
||||
*/
|
||||
|
||||
#define CYLINDER_MASK 0x3fffffff
|
||||
#define RESOLUTION_SHIFT 30
|
||||
|
||||
#define TIME_MASK 0x0fffffff
|
||||
#define MG_MASK 0xf0000000
|
||||
#define MG_SHIFT 28
|
||||
|
||||
#define OLD_MG_A (0 << MG_SHIFT)
|
||||
#define OLD_MG_B (1 << MG_SHIFT)
|
||||
#define OLD_MG_N (2 << MG_SHIFT)
|
||||
#define OLD_MG_D (3 << MG_SHIFT)
|
||||
|
||||
#define MG_F (0 << MG_SHIFT) // MG_F -> Flux orientation change
|
||||
#define MG_N (1 << MG_SHIFT) // MG_N -> Non-magnetized zone (neutral)
|
||||
#define MG_D (2 << MG_SHIFT) // MG_D -> Damaged zone, reads as neutral but cannot be changed by writing
|
||||
#define MG_E (3 << MG_SHIFT) // MG_E -> End of zone
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct mfiheader_t_
|
||||
{
|
||||
uint8_t mfi_signature[16]; // "MESSFLOPPYIMAGE" or "MAMEFLOPPYIMAGE"
|
||||
uint32_t cyl_count; //
|
||||
uint32_t head_count; //
|
||||
uint32_t form_factor;
|
||||
uint32_t variant;
|
||||
} mfiheader_t;
|
||||
|
||||
// Track Header information :
|
||||
|
||||
typedef struct mfitrack_t_
|
||||
{
|
||||
uint32_t offset;
|
||||
uint32_t compressed_size;
|
||||
uint32_t uncompressed_size;
|
||||
uint32_t write_splice;
|
||||
} mfitrack_t;
|
||||
|
||||
#pragma pack()
|
||||
@@ -0,0 +1,478 @@
|
||||
/*
|
||||
//
|
||||
// Copyright (C) 2006-2024 Jean-François DEL NERO
|
||||
//
|
||||
// This file is part of the HxCFloppyEmulator library
|
||||
//
|
||||
// HxCFloppyEmulator may be used and distributed without restriction provided
|
||||
// that this copyright statement is not removed from the file and that any
|
||||
// derivative work contains the original copyright notice and the associated
|
||||
// disclaimer.
|
||||
//
|
||||
// HxCFloppyEmulator is free software; you can redistribute it
|
||||
// and/or modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// HxCFloppyEmulator is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with HxCFloppyEmulator; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
//
|
||||
*/
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
//-------------------------------------------------------------------------------//
|
||||
//-------------------------------------------------------------------------------//
|
||||
//-----------H----H--X----X-----CCCCC----22222----0000-----0000------11----------//
|
||||
//----------H----H----X-X-----C--------------2---0----0---0----0--1--1-----------//
|
||||
//---------HHHHHH-----X------C----------22222---0----0---0----0-----1------------//
|
||||
//--------H----H----X--X----C----------2-------0----0---0----0-----1-------------//
|
||||
//-------H----H---X-----X---CCCCC-----222222----0000-----0000----1111------------//
|
||||
//-------------------------------------------------------------------------------//
|
||||
//----------------------------------------------------- http://hxc2001.free.fr --//
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// File : mfi_loader.c
|
||||
// Contains: mfi floppy image loader
|
||||
//
|
||||
// Written by: Jean-François DEL NERO
|
||||
//
|
||||
// Change History (most recent first):
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#include "internal_libhxcfe.h"
|
||||
#include "tracks/track_generator.h"
|
||||
#include "libhxcfe.h"
|
||||
|
||||
#include "tracks/encoding/mfm_encoding.h"
|
||||
|
||||
#include "floppy_loader.h"
|
||||
#include "floppy_utils.h"
|
||||
|
||||
#include "mfi_loader.h"
|
||||
#include "mfi_writer.h"
|
||||
|
||||
#include "mfi_format.h"
|
||||
|
||||
#include "libhxcadaptor.h"
|
||||
#include "tracks/crc.h"
|
||||
|
||||
#include "thirdpartylibs/zlib/zlib.h"
|
||||
#include "thirdpartylibs/zlib/contrib/minizip/unzip.h"
|
||||
|
||||
#define DEFAULT_BITS_PERIOD 1000 // ps -> 1GHz
|
||||
|
||||
#define MFI_DBG 1
|
||||
|
||||
int MFI_libIsValidDiskFile( HXCFE_IMGLDR * imgldr_ctx, HXCFE_IMGLDR_FILEINFOS * imgfile )
|
||||
{
|
||||
mfiheader_t * fileheader;
|
||||
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_DEBUG,"MFI_libIsValidDiskFile");
|
||||
|
||||
if(hxc_checkfileext(imgfile->path,"MFI",SYS_PATH_TYPE))
|
||||
{
|
||||
fileheader = (mfiheader_t*)imgfile->file_header;
|
||||
|
||||
if( memcmp((char*)&fileheader->mfi_signature,"MESSFLOPPYIMAGE",16) && memcmp((char*)&fileheader->mfi_signature,"MAMEFLOPPYIMAGE",16) && ( fileheader->head_count <= 2 ) )
|
||||
{
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_DEBUG,"MFI_libIsValidDiskFile : non MFI file (bad header)!");
|
||||
return HXCFE_BADFILE;
|
||||
}
|
||||
else
|
||||
{
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_DEBUG,"MFI_libIsValidDiskFile : MFI file !");
|
||||
return HXCFE_VALIDFILE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_DEBUG,"MFI_libIsValidDiskFile : non MFI file !");
|
||||
return HXCFE_BADFILE;
|
||||
}
|
||||
}
|
||||
|
||||
static HXCFE_SIDE* decodestream(HXCFE* floppycontext, int track_size,uint32_t * unpacked_data,int track,int side,short * rpm,float timecoef,int phasecorrection,unsigned int revolution ,int bitrate,int filter,int filterpasses, int bmpexport)
|
||||
{
|
||||
HXCFE_SIDE* currentside;
|
||||
unsigned int i,p,offset;
|
||||
|
||||
HXCFE_TRKSTREAM *track_dump;
|
||||
HXCFE_FXSA * fxs;
|
||||
|
||||
uint32_t * trackbuf_dword;
|
||||
uint32_t index_position[16];
|
||||
uint32_t pulses_count;
|
||||
uint32_t r,cumul;
|
||||
char tmp_filename[512];
|
||||
int in_rand_zone;
|
||||
|
||||
currentside = NULL;
|
||||
|
||||
floppycontext->hxc_printf(MSG_DEBUG,"------------------------------------------------");
|
||||
|
||||
floppycontext->hxc_printf(MSG_DEBUG,"Loading MFI track...");
|
||||
|
||||
index_position[0] = 0;
|
||||
|
||||
fxs = hxcfe_initFxStream(floppycontext);
|
||||
if(fxs)
|
||||
{
|
||||
hxcfe_FxStream_setBitrate(fxs,bitrate);
|
||||
|
||||
hxcfe_FxStream_setPhaseCorrectionFactor(fxs,phasecorrection);
|
||||
|
||||
hxcfe_FxStream_setFilterParameters(fxs,filterpasses,filter);
|
||||
|
||||
pulses_count = track_size;
|
||||
|
||||
if( pulses_count )
|
||||
{
|
||||
offset = 0;
|
||||
|
||||
p = 0;
|
||||
|
||||
trackbuf_dword = calloc(1, ((pulses_count*revolution)+1)*sizeof(uint32_t));
|
||||
if(trackbuf_dword)
|
||||
{
|
||||
r = 0;
|
||||
while( r < revolution )
|
||||
{
|
||||
cumul = 0;
|
||||
in_rand_zone = 0;
|
||||
|
||||
for(i=0;i<pulses_count;i++)
|
||||
{
|
||||
uint32_t dat;
|
||||
|
||||
dat = unpacked_data[i];
|
||||
|
||||
switch( dat & 0xF0000000 )
|
||||
{
|
||||
case MG_F:
|
||||
if( !in_rand_zone )
|
||||
trackbuf_dword[p++] = (dat & 0xFFFFFFF);
|
||||
else
|
||||
cumul += (dat & 0xFFFFFFF);
|
||||
break;
|
||||
|
||||
case MG_N:
|
||||
case MG_D:
|
||||
in_rand_zone = 1;
|
||||
break;
|
||||
|
||||
case MG_E:
|
||||
in_rand_zone = 0;
|
||||
// TODO : randomize starting at p and ending p + cumul
|
||||
trackbuf_dword[p++] = cumul + (dat & 0xFFFFFFF);
|
||||
cumul = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
index_position[r] = p;
|
||||
|
||||
r++;
|
||||
}
|
||||
|
||||
hxcfe_FxStream_setResolution(fxs,DEFAULT_BITS_PERIOD);
|
||||
|
||||
track_dump = hxcfe_FxStream_ImportStream(fxs,trackbuf_dword,32, p, HXCFE_STREAMCHANNEL_TYPE_RLEEVT, "data", NULL);
|
||||
if(track_dump)
|
||||
{
|
||||
offset = 0;
|
||||
hxcfe_FxStream_AddIndex(fxs,track_dump,offset,0,FXSTRM_INDEX_MAININDEX);
|
||||
|
||||
for(i=0;i<revolution;i++)
|
||||
{
|
||||
hxcfe_FxStream_AddIndex(fxs,track_dump,index_position[i],0,FXSTRM_INDEX_MAININDEX);
|
||||
}
|
||||
|
||||
hxcfe_FxStream_ChangeSpeed(fxs,track_dump,timecoef);
|
||||
|
||||
fxs->pll.track = track;
|
||||
currentside = hxcfe_FxStream_AnalyzeAndGetTrack(fxs,track_dump);
|
||||
|
||||
if(currentside)
|
||||
{
|
||||
if(rpm)
|
||||
*rpm = (short)( 60 / GetTrackPeriod(floppycontext,currentside) );
|
||||
}
|
||||
|
||||
if( bmpexport )
|
||||
{
|
||||
sprintf(tmp_filename,"track%.2d.%d.bmp",track>>1,track&1);
|
||||
hxcfe_FxStream_ExportToBmp(fxs,track_dump, tmp_filename);
|
||||
}
|
||||
|
||||
if(currentside)
|
||||
{
|
||||
currentside->stream_dump = track_dump;
|
||||
}
|
||||
else
|
||||
{
|
||||
hxcfe_FxStream_FreeStream(fxs,track_dump);
|
||||
}
|
||||
}
|
||||
|
||||
free(trackbuf_dword);
|
||||
}
|
||||
}
|
||||
|
||||
hxcfe_deinitFxStream(fxs);
|
||||
}
|
||||
|
||||
floppycontext->hxc_printf(MSG_DEBUG,"------------------------------------------------");
|
||||
|
||||
return currentside;
|
||||
}
|
||||
|
||||
int MFI_libLoad_DiskFile(HXCFE_IMGLDR * imgldr_ctx,HXCFE_FLOPPY * floppydisk,char * imgfile,void * parameters)
|
||||
{
|
||||
FILE * f = NULL;
|
||||
int ret;
|
||||
short rpm;
|
||||
int i;
|
||||
int tracknumber,sidenumber;
|
||||
HXCFE_CYLINDER* currentcylinder;
|
||||
HXCFE_SIDE * curside;
|
||||
mfiheader_t fileheader;
|
||||
mfitrack_t * track_header_array = NULL;
|
||||
int resolution;
|
||||
unsigned char * packed_data_buf = NULL;
|
||||
uint32_t * unpacked_data_buf = NULL;
|
||||
|
||||
float timecoef;
|
||||
int phasecorrection;
|
||||
int bitrate;
|
||||
int filterpasses,filter;
|
||||
int bmp_export;
|
||||
|
||||
currentcylinder = 0;
|
||||
bmp_export = 0;
|
||||
|
||||
f = NULL;
|
||||
|
||||
ret = HXCFE_NOERROR;
|
||||
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_DEBUG,"MFI_libLoad_DiskFile %s",imgfile);
|
||||
|
||||
phasecorrection = hxcfe_getEnvVarValue( imgldr_ctx->hxcfe, "FLUXSTREAM_PLL_PHASE_CORRECTION_DIVISOR" );
|
||||
filterpasses = hxcfe_getEnvVarValue( imgldr_ctx->hxcfe, "FLUXSTREAM_BITRATE_FILTER_PASSES" );
|
||||
filter = hxcfe_getEnvVarValue( imgldr_ctx->hxcfe, "FLUXSTREAM_BITRATE_FILTER_WINDOW" );
|
||||
bitrate = hxcfe_getEnvVarValue( imgldr_ctx->hxcfe, "STREAMHFELOADER_BITRATE" );
|
||||
|
||||
timecoef=1;
|
||||
if( !strcmp(hxcfe_getEnvVar( imgldr_ctx->hxcfe, "FLUXSTREAM_RPMFIX", NULL),"360TO300RPM") )
|
||||
{
|
||||
timecoef=(float)1.2;
|
||||
}
|
||||
|
||||
if( !strcmp(hxcfe_getEnvVar( imgldr_ctx->hxcfe, "FLUXSTREAM_RPMFIX", NULL),"300TO360RPM") )
|
||||
{
|
||||
timecoef=(float)0.833;
|
||||
}
|
||||
|
||||
f = hxc_fopen(imgfile,"rb");
|
||||
if( f == NULL )
|
||||
{
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_ERROR,"Cannot open %s !",imgfile);
|
||||
return HXCFE_ACCESSERROR;
|
||||
}
|
||||
|
||||
memset( &fileheader,0,sizeof(mfiheader_t));
|
||||
if( hxc_fread( &fileheader, sizeof(mfiheader_t), f ) <= 0 )
|
||||
{
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_ERROR,"Can't read the file header %s !",imgfile);
|
||||
fclose(f);
|
||||
return HXCFE_ACCESSERROR;
|
||||
}
|
||||
|
||||
if( !memcmp((char*)&fileheader.mfi_signature,"MESSFLOPPYIMAGE",16) || !memcmp((char*)&fileheader.mfi_signature,"MAMEFLOPPYIMAGE",16) )
|
||||
{
|
||||
|
||||
#ifdef MFI_DBG
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_DEBUG,"MFI revision : %s",(char*)&fileheader.mfi_signature);
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_DEBUG,"MFI form factor : 0x%.8X",(char*)&fileheader.form_factor);
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_DEBUG,"MFI variants : 0x%.8X",(char*)&fileheader.variant);
|
||||
#endif
|
||||
|
||||
floppydisk->floppySectorPerTrack = -1;
|
||||
floppydisk->floppyiftype = GENERIC_SHUGART_DD_FLOPPYMODE;
|
||||
floppydisk->floppyBitRate = 250 * 1000;
|
||||
|
||||
resolution = fileheader.cyl_count >> RESOLUTION_SHIFT;
|
||||
floppydisk->floppyNumberOfSide = fileheader.head_count;
|
||||
floppydisk->floppyNumberOfTrack = (fileheader.cyl_count & CYLINDER_MASK);
|
||||
rpm = 300;
|
||||
|
||||
#ifdef MFI_DBG
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_DEBUG,"--- Header ---");
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_DEBUG,"Resolution : %d",resolution);
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_DEBUG,"Number Of Side : %d",floppydisk->floppyNumberOfSide);
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_DEBUG,"Number Of Track : %d",floppydisk->floppyNumberOfTrack);
|
||||
#endif
|
||||
|
||||
track_header_array = (mfitrack_t*)calloc(1, sizeof(mfitrack_t)*floppydisk->floppyNumberOfTrack * floppydisk->floppyNumberOfSide);
|
||||
if(!track_header_array)
|
||||
{
|
||||
ret = HXCFE_INTERNALERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if( hxc_fread( track_header_array, sizeof(mfitrack_t)*floppydisk->floppyNumberOfTrack * floppydisk->floppyNumberOfSide, f ) <= 0 )
|
||||
{
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_ERROR,"Can't read the file header %s !",imgfile);
|
||||
ret = HXCFE_ACCESSERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
floppydisk->tracks = (HXCFE_CYLINDER**)malloc(sizeof(HXCFE_CYLINDER*)*floppydisk->floppyNumberOfTrack);
|
||||
if(!floppydisk->tracks)
|
||||
{
|
||||
ret = HXCFE_INTERNALERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
packed_data_buf = NULL;
|
||||
unpacked_data_buf = NULL;
|
||||
|
||||
memset(floppydisk->tracks,0,sizeof(HXCFE_CYLINDER*)*floppydisk->floppyNumberOfTrack);
|
||||
|
||||
for(i=0;i<floppydisk->floppyNumberOfTrack*floppydisk->floppyNumberOfSide;i++)
|
||||
{
|
||||
|
||||
hxcfe_imgCallProgressCallback(imgldr_ctx,i,floppydisk->floppyNumberOfTrack*floppydisk->floppyNumberOfSide );
|
||||
|
||||
#ifdef MFI_DBG
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_DEBUG,"--- Entry %d ---",i);
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_DEBUG,"Offset : 0x%X",track_header_array[i].offset);
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_DEBUG,"Compressed_size : 0x%X",track_header_array[i].compressed_size);
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_DEBUG,"Uncompressed_size : 0x%X",track_header_array[i].uncompressed_size);
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_DEBUG,"Write_splice : 0x%X",track_header_array[i].write_splice);
|
||||
#endif
|
||||
|
||||
if ( floppydisk->floppyNumberOfSide == 1 )
|
||||
{
|
||||
tracknumber = i;
|
||||
sidenumber = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
tracknumber = i>>1;
|
||||
sidenumber = i&1;
|
||||
}
|
||||
|
||||
if(track_header_array[i].compressed_size && track_header_array[i].compressed_size)
|
||||
{
|
||||
long unsigned int destLen;
|
||||
|
||||
packed_data_buf = calloc(1,track_header_array[i].compressed_size + 16);
|
||||
unpacked_data_buf = calloc(1,track_header_array[i].uncompressed_size + 16);
|
||||
if( packed_data_buf && unpacked_data_buf )
|
||||
{
|
||||
destLen = track_header_array[i].uncompressed_size;
|
||||
|
||||
fseek(f,track_header_array[i].offset,SEEK_SET);
|
||||
hxc_fread(packed_data_buf,track_header_array[i].compressed_size,f);
|
||||
|
||||
uncompress((unsigned char *)unpacked_data_buf, &destLen, packed_data_buf, track_header_array[i].compressed_size);
|
||||
|
||||
if(destLen)
|
||||
{
|
||||
curside = decodestream(imgldr_ctx->hxcfe, destLen / sizeof(uint32_t),unpacked_data_buf,tracknumber,sidenumber,&rpm,timecoef,phasecorrection,3,bitrate,filter,filterpasses,bmp_export);
|
||||
|
||||
if(!floppydisk->tracks[tracknumber])
|
||||
{
|
||||
floppydisk->tracks[tracknumber] = allocCylinderEntry(rpm,floppydisk->floppyNumberOfSide);
|
||||
}
|
||||
|
||||
currentcylinder = floppydisk->tracks[tracknumber];
|
||||
|
||||
currentcylinder->sides[sidenumber] = curside;
|
||||
}
|
||||
else
|
||||
{
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_WARNING,"MFI : Track Entry %d : Unpack failure",i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_WARNING,"MFI : Track allocation failure",i);
|
||||
}
|
||||
|
||||
free(packed_data_buf);
|
||||
packed_data_buf = NULL;
|
||||
|
||||
free(unpacked_data_buf);
|
||||
unpacked_data_buf = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
imgldr_ctx->hxcfe->hxc_printf(MSG_WARNING,"MFI : Track Entry %d : Unformatted",i);
|
||||
curside = tg_alloctrack(floppydisk->floppyBitRate,ISOIBM_MFM_ENCODING,rpm,((250000/(rpm/60))/4)*8,2500,-2500,TG_ALLOCTRACK_ALLOCFLAKEYBUFFER|TG_ALLOCTRACK_RANDOMIZEDATABUFFER|TG_ALLOCTRACK_UNFORMATEDBUFFER);
|
||||
|
||||
if(!floppydisk->tracks[tracknumber])
|
||||
{
|
||||
floppydisk->tracks[tracknumber] = allocCylinderEntry(rpm,floppydisk->floppyNumberOfSide);
|
||||
}
|
||||
|
||||
currentcylinder = floppydisk->tracks[tracknumber];
|
||||
|
||||
currentcylinder->sides[sidenumber] = curside;
|
||||
}
|
||||
}
|
||||
|
||||
hxcfe_sanityCheck(imgldr_ctx->hxcfe,floppydisk);
|
||||
}
|
||||
|
||||
hxc_fclose(f);
|
||||
|
||||
free(track_header_array);
|
||||
|
||||
return ret;
|
||||
|
||||
error:
|
||||
if(f)
|
||||
hxc_fclose(f);
|
||||
|
||||
free(track_header_array);
|
||||
free(packed_data_buf);
|
||||
free(unpacked_data_buf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int MFI_libGetPluginInfo(HXCFE_IMGLDR * imgldr_ctx,uint32_t infotype,void * returnvalue)
|
||||
{
|
||||
static const char plug_id[]="MAME_MFI";
|
||||
static const char plug_desc[]="Mame MFI Loader";
|
||||
static const char plug_ext[]="mfi";
|
||||
|
||||
plugins_ptr plug_funcs=
|
||||
{
|
||||
(ISVALIDDISKFILE) MFI_libIsValidDiskFile,
|
||||
(LOADDISKFILE) MFI_libLoad_DiskFile,
|
||||
(WRITEDISKFILE) 0,//MFI_libWrite_DiskFile,
|
||||
(GETPLUGININFOS) MFI_libGetPluginInfo
|
||||
};
|
||||
|
||||
return libGetPluginInfo(
|
||||
imgldr_ctx,
|
||||
infotype,
|
||||
returnvalue,
|
||||
plug_id,
|
||||
plug_desc,
|
||||
&plug_funcs,
|
||||
plug_ext
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
//
|
||||
// Copyright (C) 2006-2024 Jean-François DEL NERO
|
||||
//
|
||||
// This file is part of the HxCFloppyEmulator library
|
||||
//
|
||||
// HxCFloppyEmulator may be used and distributed without restriction provided
|
||||
// that this copyright statement is not removed from the file and that any
|
||||
// derivative work contains the original copyright notice and the associated
|
||||
// disclaimer.
|
||||
//
|
||||
// HxCFloppyEmulator is free software; you can redistribute it
|
||||
// and/or modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// HxCFloppyEmulator is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with HxCFloppyEmulator; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
//
|
||||
*/
|
||||
|
||||
int MFI_libGetPluginInfo(HXCFE_IMGLDR * imgldr_ctx,uint32_t infotype,void * returnvalue);
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
//
|
||||
// Copyright (C) 2006-2024 Jean-François DEL NERO
|
||||
//
|
||||
// This file is part of the HxCFloppyEmulator library
|
||||
//
|
||||
// HxCFloppyEmulator may be used and distributed without restriction provided
|
||||
// that this copyright statement is not removed from the file and that any
|
||||
// derivative work contains the original copyright notice and the associated
|
||||
// disclaimer.
|
||||
//
|
||||
// HxCFloppyEmulator is free software; you can redistribute it
|
||||
// and/or modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// HxCFloppyEmulator is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with HxCFloppyEmulator; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
//
|
||||
*/
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
//-------------------------------------------------------------------------------//
|
||||
//-------------------------------------------------------------------------------//
|
||||
//-----------H----H--X----X-----CCCCC----22222----0000-----0000------11----------//
|
||||
//----------H----H----X-X-----C--------------2---0----0---0----0--1--1-----------//
|
||||
//---------HHHHHH-----X------C----------22222---0----0---0----0-----1------------//
|
||||
//--------H----H----X--X----C----------2-------0----0---0----0-----1-------------//
|
||||
//-------H----H---X-----X---CCCCC-----222222----0000-----0000----1111------------//
|
||||
//-------------------------------------------------------------------------------//
|
||||
//----------------------------------------------------- http://hxc2001.free.fr --//
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// File : mfi_writer.c
|
||||
// Contains: MFI floppy image writer
|
||||
//
|
||||
// Written by: Jean-François DEL NERO
|
||||
//
|
||||
// Change History (most recent first):
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#include "internal_libhxcfe.h"
|
||||
#include "tracks/track_generator.h"
|
||||
#include "libhxcfe.h"
|
||||
#include "86f_loader.h"
|
||||
#include "86f_writer.h"
|
||||
#include "86f_format.h"
|
||||
#include "floppy_utils.h"
|
||||
#include "tracks/sector_extractor.h"
|
||||
#include "libhxcadaptor.h"
|
||||
|
||||
// Main writer function
|
||||
int MFI_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy,char * filename)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
//
|
||||
// Copyright (C) 2006-2024 Jean-François DEL NERO
|
||||
//
|
||||
// This file is part of the HxCFloppyEmulator library
|
||||
//
|
||||
// HxCFloppyEmulator may be used and distributed without restriction provided
|
||||
// that this copyright statement is not removed from the file and that any
|
||||
// derivative work contains the original copyright notice and the associated
|
||||
// disclaimer.
|
||||
//
|
||||
// HxCFloppyEmulator is free software; you can redistribute it
|
||||
// and/or modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// HxCFloppyEmulator is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with HxCFloppyEmulator; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
//
|
||||
*/
|
||||
|
||||
int MFI_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy,char * filename);
|
||||
@@ -137,6 +137,7 @@
|
||||
#include "./loaders/logicanalyzer_loader/logicanalyzer_loader.h"
|
||||
#include "./loaders/dim_x68k_loader/dim_x68k_loader.h"
|
||||
#include "./loaders/woz_loader/woz_loader.h"
|
||||
#include "./loaders/mfi_loader/mfi_loader.h"
|
||||
|
||||
const GETPLUGININFOS staticplugins[]=
|
||||
{
|
||||
@@ -197,6 +198,7 @@ const GETPLUGININFOS staticplugins[]=
|
||||
(GETPLUGININFOS)HDM_libGetPluginInfo,
|
||||
(GETPLUGININFOS)RAW_libGetPluginInfo,
|
||||
(GETPLUGININFOS)snes_smc_libGetPluginInfo,
|
||||
(GETPLUGININFOS)MFI_libGetPluginInfo,
|
||||
//(GETPLUGININFOS)KRZ_libGetPluginInfo,
|
||||
(GETPLUGININFOS)VEGASDSK_libGetPluginInfo,
|
||||
(GETPLUGININFOS)DMK_libGetPluginInfo,
|
||||
|
||||
@@ -88,3 +88,4 @@
|
||||
#define PLUGIN_APPLE2_DO "APPLE2_DO"
|
||||
#define PLUGIN_APPLE2_PO "APPLE2_PO"
|
||||
#define PLUGIN_FDX68_FDX "FDX68_FDX"
|
||||
#define PLUGIN_MAME_MFI "MAME_MFI"
|
||||
|
||||
Reference in New Issue
Block a user