mirror of
https://github.com/jfdelnero/HxCFloppyEmulator.git
synced 2026-10-26 22:10:31 +00:00
713 lines
22 KiB
C
713 lines
22 KiB
C
/*
|
|
//
|
|
// Copyright (C) 2006-2026 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
|
|
//
|
|
*/
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <inttypes.h>
|
|
|
|
#include "types.h"
|
|
|
|
#include "internal_libhxcfe.h"
|
|
#include "tracks/track_generator.h"
|
|
#include "libhxcfe.h"
|
|
|
|
#include "xml_loader.h"
|
|
|
|
#include "tracks/sector_extractor.h"
|
|
|
|
#include "libhxcadaptor.h"
|
|
|
|
#include "floppy_utils.h"
|
|
|
|
#include "version.h"
|
|
|
|
#include "misc/env.h"
|
|
|
|
#include "stream_analyzer/fluxStreamAnalyzer.h"
|
|
|
|
void gettracktype(HXCFE_SECTORACCESS* ss,int track,int side,int * nbsect,int *firstsectid,char * format,int * format_id, int *sectorsize)
|
|
{
|
|
int i;
|
|
HXCFE_SECTCFG** sca;
|
|
int32_t nb_sectorfound;
|
|
|
|
*sectorsize = 512;
|
|
*firstsectid = 1;
|
|
sprintf(format,"IBM_MFM");
|
|
*format_id = IBMFORMAT_DD;
|
|
*nbsect = 0;
|
|
|
|
sca = hxcfe_getAllTrackISOSectors(ss,track,side,&nb_sectorfound);
|
|
if(nb_sectorfound)
|
|
{
|
|
*sectorsize = sca[0]->sectorsize;
|
|
*firstsectid = 0xFF;
|
|
*nbsect = nb_sectorfound;
|
|
|
|
if(
|
|
( sca[0]->trackencoding == IBMFORMAT_SD ) ||
|
|
( sca[0]->trackencoding == ISOFORMAT_SD )
|
|
)
|
|
{
|
|
sprintf(format,"IBM_FM");
|
|
*format_id = IBMFORMAT_SD;
|
|
}
|
|
else
|
|
{
|
|
sprintf(format,"IBM_MFM");
|
|
*format_id = IBMFORMAT_DD;
|
|
}
|
|
|
|
for(i=0;i<nb_sectorfound;i++)
|
|
{
|
|
if(sca[i]->sector<*firstsectid)
|
|
*firstsectid = sca[i]->sector;
|
|
hxcfe_freeSectorConfig (ss,sca[i]);
|
|
}
|
|
|
|
free(sca);
|
|
}
|
|
}
|
|
|
|
typedef struct sect_offset_
|
|
{
|
|
HXCFE_SECTCFG* ss;
|
|
uint32_t offset;
|
|
}sect_offset;
|
|
|
|
static void exchange(sect_offset ** table, int a, int b)
|
|
{
|
|
sect_offset * temp;
|
|
temp = table[a];
|
|
table[a] = table[b];
|
|
table[b] = temp;
|
|
}
|
|
|
|
static void quickSort(sect_offset ** table, int start, int end)
|
|
{
|
|
int left = start-1;
|
|
int right = end+1;
|
|
const int pivot = table[start]->ss->sector;
|
|
|
|
if(start >= end)
|
|
return;
|
|
|
|
while(1)
|
|
{
|
|
do right--; while(table[right]->ss->sector > pivot);
|
|
do left++; while(table[left]->ss->sector < pivot);
|
|
|
|
if(left < right)
|
|
exchange(table, left, right);
|
|
else break;
|
|
}
|
|
|
|
quickSort(table, start, right);
|
|
quickSort(table, right+1, end);
|
|
}
|
|
|
|
int XML_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy,char * filename)
|
|
{
|
|
int i,j,k,s,vs;
|
|
FILE * xmlfile;
|
|
int fileoffset;
|
|
int export_mode;
|
|
int32_t nb_sectorfound,nb_validsectorfound;
|
|
int nbsect,firstsectid,sectorsize,imagesize;
|
|
char trackformat[32];
|
|
HXCFE_SECTORACCESS* ss;
|
|
HXCFE_SECTCFG** sca;
|
|
HXCFE_SECTCFG* sectp;
|
|
sect_offset ** sorted_sectoffset,**sectoffset;
|
|
uint32_t crc32;
|
|
int trackformatid;
|
|
int t,size;
|
|
#define HISTOSIZE 32
|
|
unsigned int mini_histo[HISTOSIZE];
|
|
streamconv * strconv;
|
|
|
|
sectoffset = NULL;
|
|
sorted_sectoffset = NULL;
|
|
sca = NULL;
|
|
|
|
imgldr_ctx->hxcfe->hxc_printf(MSG_INFO_1,"Write XML file %s...",filename);
|
|
|
|
fileoffset = 0;
|
|
|
|
export_mode = hxcfe_getEnvVarValue( imgldr_ctx->hxcfe, "XMLEXPORT_MODE" );
|
|
|
|
xmlfile=hxc_fopen(filename,"w+");
|
|
if(xmlfile)
|
|
{
|
|
imagesize = hxcfe_getFloppySize(imgldr_ctx->hxcfe,floppy,0,0);
|
|
|
|
ss=hxcfe_initSectorAccess(imgldr_ctx->hxcfe,floppy);
|
|
if(ss)
|
|
{
|
|
fprintf(xmlfile,"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n");
|
|
fprintf(xmlfile,"<!-- HxC Floppy Emulator Disk Layout -->\n");
|
|
|
|
fprintf(xmlfile,"<disk_layout>\n");
|
|
|
|
fprintf(xmlfile,"\t<libhxcfe_version>v%s,Release_Date:%s,Build_Date:%s</libhxcfe_version>\n",hxcfe_getVersion(imgldr_ctx->hxcfe),STR_DATE, __DATE__ );
|
|
|
|
fprintf(xmlfile,"\t<disk_layout_name>AUTOGENERATEDLAYOUT</disk_layout_name>\n");
|
|
fprintf(xmlfile,"\t<disk_layout_description>Auto Generated Disk Layout</disk_layout_description>\n");
|
|
fprintf(xmlfile,"\t<prefered_file_extension>img</prefered_file_extension>\n");
|
|
fprintf(xmlfile,"\t<interface_mode>GENERIC_SHUGART_DD_FLOPPYMODE</interface_mode>\n");
|
|
|
|
if( hxcfe_floppyGetFlags( imgldr_ctx->hxcfe, floppy ) & HXCFE_FLOPPY_WRPROTECTED_FLAG )
|
|
{
|
|
fprintf(xmlfile,"\t<write_protected>1</write_protected>\n");
|
|
}
|
|
else
|
|
{
|
|
fprintf(xmlfile,"\t<write_protected>0</write_protected>\n");
|
|
}
|
|
|
|
fprintf(xmlfile,"\t<file_size>%d</file_size>\n",imagesize);
|
|
|
|
fprintf(xmlfile,"\t<layout>\n");
|
|
|
|
fprintf(xmlfile,"\t\t<number_of_track>%d</number_of_track>\n",floppy->floppyNumberOfTrack);
|
|
fprintf(xmlfile,"\t\t<number_of_side>%d</number_of_side>\n",floppy->floppyNumberOfSide);
|
|
|
|
gettracktype(ss,0,0,&nbsect,&firstsectid,(char*)&trackformat,&trackformatid,§orsize);
|
|
|
|
fprintf(xmlfile,"\t\t<format>%s</format>\n",trackformat);
|
|
|
|
fprintf(xmlfile,"\t\t<start_sector_id>%d</start_sector_id>\n",firstsectid);
|
|
fprintf(xmlfile,"\t\t<sector_per_track>%d</sector_per_track>\n",nbsect);
|
|
|
|
fprintf(xmlfile,"\t\t<sector_size>%d</sector_size>\n",sectorsize);
|
|
|
|
fprintf(xmlfile,"\t\t<formatvalue>%d</formatvalue>\n",0x00);
|
|
|
|
fprintf(xmlfile,"\t\t<gap3>%d</gap3>\n",0xFF);
|
|
|
|
if(floppy->floppyBitRate!=-1)
|
|
{
|
|
fprintf(xmlfile,"\t\t<bitrate>%d</bitrate>\n",floppy->floppyBitRate);
|
|
}
|
|
else
|
|
{
|
|
fprintf(xmlfile,"\t\t<bitrate>%d</bitrate>\n",(int)((float)(floppy->tracks[0]->sides[0]->tracklen/2) * ( (float)floppy->tracks[0]->floppyRPM / (float)60)));
|
|
}
|
|
|
|
fprintf(xmlfile,"\t\t<pregap>%d</pregap>\n",0);
|
|
fprintf(xmlfile,"\t\t<rpm>%d</rpm>\n",floppy->tracks[0]->floppyRPM);
|
|
|
|
hxcfe_getHash( imgldr_ctx->hxcfe, floppy, -1, -1, -1, (0x1<<ISOIBM_FM_ENCODING) | (0x1<<ISOIBM_MFM_ENCODING), HASH_TYPE_CRC32, HASH_FLAG_DATA | HASH_FLAG_PHYSICALORDER, &crc32, sizeof(crc32) );
|
|
|
|
fprintf(xmlfile,"\t\t<crc32>0x%.8X</crc32>\n",crc32);
|
|
|
|
fprintf(xmlfile,"\t\t<track_list>\n");
|
|
|
|
for(j=0;j<floppy->floppyNumberOfTrack;j++)
|
|
{
|
|
for(i=0;i<floppy->floppyNumberOfSide;i++)
|
|
{
|
|
fprintf(xmlfile,"\t\t\t<track track_number=\"%.2d\" side_number=\"%d\">\n",j,i);
|
|
fprintf(xmlfile,"\t\t\t\t<data_offset>0x%.6X</data_offset>\n",fileoffset);
|
|
|
|
if( export_mode > 0 )
|
|
{
|
|
int cnt;
|
|
unsigned int spacecnt;
|
|
|
|
size = floppy->tracks[j]->sides[i]->tracklen;
|
|
|
|
fprintf(xmlfile,"\t\t\t\t<track_length_cells>%d</track_length_cells>\n",size);
|
|
fprintf(xmlfile,"\t\t\t\t<track_length_us>%.2f</track_length_us>\n",(double)(GetTrackPeriod(imgldr_ctx->hxcfe,floppy->tracks[j]->sides[i])*1000*1000));
|
|
|
|
t = 0;
|
|
cnt = 0;
|
|
memset(mini_histo,0,sizeof(mini_histo));
|
|
spacecnt = 0;
|
|
do
|
|
{
|
|
if( floppy->tracks[j]->sides[i]->databuffer[t>>3] & (0x80>>(t&7)) )
|
|
{
|
|
cnt++;
|
|
if(spacecnt >= HISTOSIZE)
|
|
spacecnt = HISTOSIZE-1;
|
|
|
|
mini_histo[spacecnt]++;
|
|
spacecnt = 0;
|
|
}
|
|
else
|
|
{
|
|
spacecnt++;
|
|
}
|
|
|
|
t++;
|
|
}while( t < size);
|
|
|
|
fprintf(xmlfile,"\t\t\t\t<track_pulses>%d</track_pulses>\n",cnt);
|
|
fprintf(xmlfile,"\t\t\t\t<track_pulses_percent>%.4f</track_pulses_percent>\n",((double)cnt/(double)size) * 100.0);
|
|
|
|
if(cnt)
|
|
{
|
|
fprintf(xmlfile,"\t\t\t\t<track_pulses_histo_percent>");
|
|
fprintf(xmlfile,"%.1f",(((double)mini_histo[0]/cnt)*100.0));
|
|
for(t=1;t<HISTOSIZE;t++)
|
|
{
|
|
fprintf(xmlfile,",%.1f",(((double)mini_histo[t]/(double)cnt)*100.0));
|
|
}
|
|
fprintf(xmlfile,"</track_pulses_histo_percent>\n");
|
|
}
|
|
|
|
if(floppy->tracks[j]->sides[i]->flakybitsbuffer)
|
|
{
|
|
t = 0;
|
|
cnt = 0;
|
|
do
|
|
{
|
|
if( floppy->tracks[j]->sides[i]->flakybitsbuffer[t>>3] & (0x80>>(t&7)) )
|
|
cnt++;
|
|
|
|
t++;
|
|
}while( t < size);
|
|
|
|
fprintf(xmlfile,"\t\t\t\t<track_weakbits_cells>%d</track_weakbits_cells>\n",cnt);
|
|
fprintf(xmlfile,"\t\t\t\t<track_weakbits_percent>%.4f</track_weakbits_percent>\n",((double)cnt/(double)size) * 100.0);
|
|
}
|
|
|
|
if( floppy->tracks[j]->sides[i]->stream_dump )
|
|
{
|
|
strconv = initStreamConvert(imgldr_ctx->hxcfe,floppy->tracks[j]->sides[i], 10000, (10000/1000)*65536,-1,-1,64+1,5000000);
|
|
|
|
if(strconv)
|
|
{
|
|
int indexcnt,roti,i_rot;
|
|
int64_t p_tmp;
|
|
int64_t cumul_t;
|
|
int64_t cumul_r;
|
|
int64_t cumul_rot[256];
|
|
int64_t pulses_cnt_rot[256];
|
|
int64_t pulses_cnt,pulses_cnt_t;
|
|
fprintf(xmlfile,"\t\t\t\t<stream_source>yes</stream_source>\n");
|
|
|
|
roti = 0;
|
|
cumul_t = 0;
|
|
cumul_r = 0;
|
|
indexcnt = 0;
|
|
pulses_cnt = 0;
|
|
pulses_cnt_t = 0;
|
|
memset(cumul_rot,0,sizeof(cumul_rot));
|
|
memset(pulses_cnt_rot,0,sizeof(pulses_cnt_rot));
|
|
while(!strconv->stream_end_event)
|
|
{
|
|
p_tmp = StreamConvert_getNextPulse(strconv);
|
|
pulses_cnt++;
|
|
pulses_cnt_t++;
|
|
cumul_t += p_tmp;
|
|
cumul_r += p_tmp;
|
|
|
|
if(strconv->index_event && indexcnt < 256)
|
|
{
|
|
cumul_rot[roti] = cumul_r;
|
|
pulses_cnt_rot[roti] = pulses_cnt;
|
|
roti++;
|
|
cumul_r = 0;
|
|
pulses_cnt = 0;
|
|
indexcnt++;
|
|
}
|
|
}
|
|
|
|
cumul_rot[roti] = cumul_r;
|
|
pulses_cnt_rot[roti] = pulses_cnt;
|
|
roti++;
|
|
|
|
fprintf(xmlfile,"\t\t\t\t<stream_index_cnt>%d</stream_index_cnt>\n",indexcnt);
|
|
fprintf(xmlfile,"\t\t\t\t<stream_total_duration>%"PRId64"</stream_total_duration>\n",cumul_t);
|
|
fprintf(xmlfile,"\t\t\t\t<stream_total_pulses>%"PRId64"</stream_total_pulses>\n",pulses_cnt_t);
|
|
|
|
fprintf(xmlfile,"\t\t\t\t<stream_interindex_pulses>");
|
|
i_rot = 0;
|
|
fprintf(xmlfile,"%"PRId64,pulses_cnt_rot[i_rot]);
|
|
i_rot++;
|
|
while(i_rot<roti)
|
|
{
|
|
fprintf(xmlfile,",%"PRId64,pulses_cnt_rot[i_rot]);
|
|
i_rot++;
|
|
};
|
|
fprintf(xmlfile,"</stream_interindex_pulses>\n");
|
|
|
|
fprintf(xmlfile,"\t\t\t\t<stream_interindex_duration>");
|
|
i_rot = 0;
|
|
fprintf(xmlfile,"%"PRId64,cumul_rot[i_rot]);
|
|
i_rot++;
|
|
while(i_rot<roti)
|
|
{
|
|
fprintf(xmlfile,",%"PRId64,cumul_rot[i_rot]);
|
|
i_rot++;
|
|
};
|
|
fprintf(xmlfile,"</stream_interindex_duration>\n");
|
|
|
|
deinitStreamConvert(strconv);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
fprintf(xmlfile,"\t\t\t\t<stream_source>no</stream_source>\n");
|
|
}
|
|
}
|
|
|
|
gettracktype(ss,j,i,&nbsect,&firstsectid,(char*)&trackformat,&trackformatid,§orsize);
|
|
fprintf(xmlfile,"\t\t\t\t<format>%s</format>\n",trackformat);
|
|
|
|
nb_sectorfound = 0;
|
|
nb_validsectorfound = 0;
|
|
|
|
sca = hxcfe_getAllTrackISOSectors(ss,j,i,&nb_sectorfound);
|
|
fprintf(xmlfile,"\t\t\t\t<sector_list>\n");
|
|
|
|
if(nb_sectorfound > 128 * 1024)
|
|
nb_sectorfound = 128 * 1024;
|
|
|
|
if(sca && nb_sectorfound)
|
|
{
|
|
sectoffset = calloc( 1, sizeof(sect_offset*) * (int)nb_sectorfound);
|
|
if( !sectoffset )
|
|
goto alloc_error;
|
|
|
|
sorted_sectoffset = calloc( 1, sizeof(sect_offset*) * (int)nb_sectorfound);
|
|
if( !sorted_sectoffset )
|
|
goto alloc_error;
|
|
|
|
if(sorted_sectoffset && sectoffset)
|
|
{
|
|
// Filter and sort the sectors file offsets.
|
|
for(s=0;s<nb_sectorfound;s++)
|
|
{
|
|
if( sca[s]->sectorsize )
|
|
{
|
|
sorted_sectoffset[nb_validsectorfound] = malloc(sizeof(sect_offset));
|
|
if( !sorted_sectoffset[nb_validsectorfound] )
|
|
goto alloc_error;
|
|
|
|
sorted_sectoffset[nb_validsectorfound]->ss = sca[s];
|
|
sorted_sectoffset[nb_validsectorfound]->offset = 0;
|
|
nb_validsectorfound++;
|
|
}
|
|
else
|
|
{
|
|
hxcfe_freeSectorConfig (ss,sca[s]);
|
|
}
|
|
}
|
|
|
|
memcpy(sectoffset,sorted_sectoffset,sizeof(sect_offset*) * (int)nb_validsectorfound);
|
|
|
|
if(nb_validsectorfound)
|
|
quickSort(sorted_sectoffset, 0, nb_validsectorfound - 1);
|
|
|
|
for(s=0;s<nb_validsectorfound;s++)
|
|
{
|
|
sorted_sectoffset[s]->offset = fileoffset;
|
|
fileoffset += sorted_sectoffset[s]->ss->sectorsize;
|
|
}
|
|
|
|
free(sorted_sectoffset);
|
|
sorted_sectoffset = NULL;
|
|
|
|
vs = 0;
|
|
for( s = 0; s < nb_validsectorfound; s++ )
|
|
{
|
|
sectp = sectoffset[s]->ss;
|
|
if( sectp->sectorsize )
|
|
{
|
|
fprintf(xmlfile,"\t\t\t\t\t<sector sector_id=\"%d\" sector_size=\"%d\">\n",sectp->sector,sectp->sectorsize);
|
|
|
|
if( ( trackformatid != IBMFORMAT_SD ) &&
|
|
(
|
|
( sectp->trackencoding == IBMFORMAT_SD ) ||
|
|
( sectp->trackencoding == ISOFORMAT_SD )
|
|
)
|
|
)
|
|
{
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<format>IBM_FM</format>\n");
|
|
}
|
|
else
|
|
{
|
|
if( ( trackformatid != IBMFORMAT_DD ) &&
|
|
(
|
|
( sectp->trackencoding == IBMFORMAT_DD ) ||
|
|
( sectp->trackencoding == ISOFORMAT_DD )
|
|
)
|
|
)
|
|
{
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<format>IBM_MFM</format>\n");
|
|
}
|
|
}
|
|
|
|
if(sectp->fill_byte_used)
|
|
{
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<data_fill>0x%.2X</data_fill>\n",sectp->fill_byte);
|
|
}
|
|
else
|
|
{
|
|
if(sectp->input_data)
|
|
{
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<sector_data>");
|
|
k=0;
|
|
do
|
|
{
|
|
fprintf(xmlfile,"%.2X",sectp->input_data[k]);
|
|
k++;
|
|
}while(k<(int)sectp->sectorsize);
|
|
|
|
fprintf(xmlfile,"</sector_data>\n");
|
|
}
|
|
}
|
|
|
|
if(sectp->head != i || export_mode > 0)
|
|
{
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<side_id>0x%.2X</side_id>\n",sectp->head);
|
|
}
|
|
|
|
if(sectp->cylinder != j || export_mode > 0)
|
|
{
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<track_id>0x%.2X</track_id>\n",sectp->cylinder);
|
|
}
|
|
|
|
if(export_mode > 0)
|
|
{
|
|
if( (sectp->startsectorindex == sectp->startdataindex) && ( sectp->startdataindex != sectp->endsectorindex) )
|
|
{
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<special_status>NO_HEADER</special_status>\n");
|
|
}
|
|
else
|
|
{
|
|
if( (sectp->startsectorindex != sectp->startdataindex) && ( sectp->startdataindex == sectp->endsectorindex) )
|
|
{
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<special_status>NO_DATA</special_status>\n");
|
|
}
|
|
}
|
|
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<start_sector_cell>%d</start_sector_cell>\n",sectp->startsectorindex);
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<start_datasector_cell>%d</start_datasector_cell>\n",sectp->startdataindex);
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<end_sector_cell>%d</end_sector_cell>\n",sectp->endsectorindex);
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<start_sector_us>%.2f</start_sector_us>\n",MeasureTrackTiming(imgldr_ctx->hxcfe,floppy->tracks[j]->sides[i],0,sectp->startsectorindex) * 1000.0 * 1000.0);
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<sector_duration_us>%.2f</sector_duration_us>\n",MeasureTrackTiming(imgldr_ctx->hxcfe,floppy->tracks[j]->sides[i],sectp->startsectorindex,sectp->endsectorindex) * 1000.0 * 1000.0);
|
|
}
|
|
|
|
if(export_mode > 0)
|
|
{
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<addressmark>0x%.2X</addressmark>\n",sectp->alternate_addressmark);
|
|
}
|
|
|
|
if(sectp->use_alternate_datamark || export_mode > 0)
|
|
{
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<datamark>0x%.2X</datamark>\n",sectp->alternate_datamark);
|
|
}
|
|
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<data_offset>0x%.6X</data_offset>\n",(unsigned int)sectoffset[vs]->offset);
|
|
|
|
if(sectp->use_alternate_header_crc || export_mode > 0)
|
|
{
|
|
if(sectp->use_alternate_header_crc & 1)
|
|
{
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<header_crc_status>Bad</header_crc_status>\n");
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<header_crc>0x%.4X</header_crc>\n",(unsigned int)sectp->header_crc);
|
|
}
|
|
else
|
|
{
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<header_crc_status>Valid</header_crc_status>\n");
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<header_crc>0x%.4X</header_crc>\n",(unsigned int)sectp->header_crc);
|
|
}
|
|
}
|
|
|
|
if(sectp->use_alternate_data_crc || export_mode > 0)
|
|
{
|
|
if(sectp->use_alternate_data_crc & 1)
|
|
{
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<data_crc_status>Bad</data_crc_status>\n");
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<data_crc>0x%.4X</data_crc>\n",(unsigned int)sectp->data_crc);
|
|
}
|
|
else
|
|
{
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<data_crc_status>Valid</data_crc_status>\n");
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<data_crc>0x%.4X</data_crc>\n",(unsigned int)sectp->data_crc);
|
|
}
|
|
}
|
|
|
|
if( floppy->tracks[j]->sides[i]->flakybitsbuffer && export_mode > 0)
|
|
{
|
|
int cnt;
|
|
size = floppy->tracks[j]->sides[i]->tracklen;
|
|
|
|
if( sectp->startsectorindex != sectp->endsectorindex )
|
|
{
|
|
t = sectp->startsectorindex;
|
|
cnt = 0;
|
|
do
|
|
{
|
|
if( floppy->tracks[j]->sides[i]->flakybitsbuffer[t>>3] & (0x80>>(t&7)) )
|
|
cnt++;
|
|
|
|
t = (t + 1) % size;
|
|
}while( t != sectp->endsectorindex);
|
|
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<sector_weakbits_cells>%d</sector_weakbits_cells>\n",cnt);
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<sector_weakbits_percent>%.4f</sector_weakbits_percent>\n",((double)cnt/(double)size) * 100.0);
|
|
}
|
|
|
|
if( sectp->startsectorindex != sectp->startdataindex )
|
|
{
|
|
t = sectp->startsectorindex;
|
|
cnt = 0;
|
|
do
|
|
{
|
|
if( floppy->tracks[j]->sides[i]->flakybitsbuffer[t>>3] & (0x80>>(t&7)) )
|
|
cnt++;
|
|
|
|
t = (t + 1) % size;
|
|
}while( t != sectp->startdataindex);
|
|
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<sectorheader_weakbits_cells>%d</sectorheader_weakbits_cells>\n",cnt);
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<sectorheader_weakbits_percent>%.4f</sectorheader_weakbits_percent>\n",((double)cnt/(double)size) * 100.0);
|
|
}
|
|
|
|
if( sectp->startdataindex != sectp->endsectorindex )
|
|
{
|
|
t = sectp->startdataindex;
|
|
cnt = 0;
|
|
do
|
|
{
|
|
if( floppy->tracks[j]->sides[i]->flakybitsbuffer[t>>3] & (0x80>>(t&7)) )
|
|
cnt++;
|
|
|
|
t = (t + 1) % size;
|
|
}while( t != sectp->endsectorindex);
|
|
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<sectordata_weakbits_cells>%d</sectordata_weakbits_cells>\n",cnt);
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<sectordata_weakbits_percent>%.4f</sectordata_weakbits_percent>\n",((double)cnt/(double)size) * 100.0);
|
|
}
|
|
}
|
|
|
|
if(export_mode > 0)
|
|
{
|
|
int cnt = 0;
|
|
int spacecnt = 0;
|
|
int size = floppy->tracks[j]->sides[i]->tracklen;
|
|
|
|
t = sectp->startsectorindex;
|
|
memset(mini_histo,0,sizeof(mini_histo));
|
|
|
|
do
|
|
{
|
|
if( floppy->tracks[j]->sides[i]->databuffer[t>>3] & (0x80>>(t&7)) )
|
|
{
|
|
cnt++;
|
|
if(spacecnt >= HISTOSIZE)
|
|
spacecnt = HISTOSIZE-1;
|
|
|
|
mini_histo[spacecnt]++;
|
|
spacecnt = 0;
|
|
}
|
|
else
|
|
{
|
|
spacecnt++;
|
|
}
|
|
|
|
t = (t + 1) % size;
|
|
}while( t != sectp->endsectorindex);
|
|
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<sector_pulses>%d</sector_pulses>\n",cnt);
|
|
|
|
if(cnt)
|
|
{
|
|
fprintf(xmlfile,"\t\t\t\t\t\t<sector_pulses_histo_percent>");
|
|
fprintf(xmlfile,"%.1f",(((double)mini_histo[0]/cnt)*100.0));
|
|
for(t=1;t<HISTOSIZE;t++)
|
|
{
|
|
fprintf(xmlfile,",%.1f",(((double)mini_histo[t]/(double)cnt)*100.0));
|
|
}
|
|
fprintf(xmlfile,"</sector_pulses_histo_percent>\n");
|
|
}
|
|
}
|
|
|
|
fprintf(xmlfile,"\t\t\t\t\t</sector>\n");
|
|
vs++;
|
|
}
|
|
else
|
|
{
|
|
fprintf(xmlfile,"\t\t\t\t\t<!-- Invalid sector --/>\n");
|
|
}
|
|
|
|
hxcfe_freeSectorConfig (ss,sectp);
|
|
}
|
|
|
|
for(s=0;s<nb_validsectorfound;s++)
|
|
{
|
|
free(sectoffset[s]);
|
|
}
|
|
free(sectoffset);
|
|
sectoffset = NULL;
|
|
}
|
|
|
|
free(sca);
|
|
sca = NULL;
|
|
}
|
|
|
|
fprintf(xmlfile,"\t\t\t\t</sector_list>\n");
|
|
|
|
fprintf(xmlfile,"\t\t\t</track>\n");
|
|
}
|
|
}
|
|
hxcfe_deinitSectorAccess(ss);
|
|
}
|
|
|
|
fprintf(xmlfile,"\t\t</track_list>\n");
|
|
fprintf(xmlfile,"\t</layout>\n");
|
|
fprintf(xmlfile,"</disk_layout>\n");
|
|
|
|
hxc_fclose(xmlfile);
|
|
}
|
|
|
|
return HXCFE_NOERROR;
|
|
|
|
alloc_error:
|
|
if( xmlfile )
|
|
hxc_fclose( xmlfile );
|
|
|
|
if(sorted_sectoffset)
|
|
{
|
|
for(s=0;s<nb_sectorfound;s++)
|
|
{
|
|
free(sorted_sectoffset[s]);
|
|
}
|
|
}
|
|
|
|
free( sectoffset );
|
|
free( sorted_sectoffset );
|
|
free( sca );
|
|
|
|
return HXCFE_INTERNALERROR;
|
|
}
|