Пример #1
0
void gettracktype(SECTORSEARCH* ss,int track,int side,int * nbsect,int *firstsectid,char * format,int *sectorsize)
{
	int i;
	SECTORCONFIG** sca;
	int nb_sectorfound;

	*sectorsize = 512;
	*firstsectid = 1;
	sprintf(format,"IBM_MFM");
	*nbsect = 0;

	sca = hxcfe_getAllTrackSectors(ss,track,side,ISOIBM_MFM_ENCODING,&nb_sectorfound);
	if(nb_sectorfound)
	{
		*sectorsize = sca[0]->sectorsize;
		*firstsectid = 0xFF;
		*nbsect = nb_sectorfound;
		for(i=0;i<nb_sectorfound;i++)
		{

			sprintf(format,"IBM_MFM");
			if(sca[i]->sector<*firstsectid)
				*firstsectid = sca[i]->sector;
			hxcfe_freeSectorConfig  (ss,sca[i]);
		}
		free(sca);
	}

	sca = hxcfe_getAllTrackSectors(ss,track,side,ISOIBM_FM_ENCODING,&nb_sectorfound);
	if(nb_sectorfound)
	{
		*sectorsize = sca[0]->sectorsize;
		*firstsectid = 0xFF;
		*nbsect = nb_sectorfound;
		for(i=0;i<nb_sectorfound;i++)
		{
			sprintf(format,"IBM_FM");
			if(sca[i]->sector<*firstsectid)
				*firstsectid = sca[i]->sector;
			hxcfe_freeSectorConfig  (ss,sca[i]);
		}
		free(sca);
	}


}
Пример #2
0
int XML_libWrite_DiskFile(HXCFLOPPYEMULATOR* floppycontext,FLOPPY * floppy,char * filename)
{
	int i,j,k,s;
	FILE * xmlfile;
	int fileoffset,nb_sectorfound;
	int nbsect,firstsectid,sectorsize,imagesize;
	char trackformat[32];
	SECTORSEARCH* ss;
	SECTORCONFIG** sca;
	sect_offset ** sorted_sectoffset,**sectoffset;

	floppycontext->hxc_printf(MSG_INFO_1,"Write XML file %s...",filename);

	fileoffset = 0;

	xmlfile=hxc_fopen(filename,"w+");
	if(xmlfile)
	{
		imagesize = hxcfe_getFloppySize(floppycontext,floppy,0);

		ss=hxcfe_initSectorSearch(floppycontext,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<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");

			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,&sectorsize);

			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);

			fprintf(xmlfile,"\t\t<bitrate>%d</bitrate>\n",floppy->floppyBitRate);
			fprintf(xmlfile,"\t\t<pregap>%d</pregap>\n",0);
			fprintf(xmlfile,"\t\t<rpm>%d</rpm>\n",floppy->tracks[0]->floppyRPM);

			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);

					gettracktype(ss,j,i,&nbsect,&firstsectid,(char*)&trackformat,&sectorsize);
					fprintf(xmlfile,"\t\t\t\t<format>%s</format>\n",trackformat);

					sca = hxcfe_getAllTrackISOSectors(ss,j,i,&nb_sectorfound);
					fprintf(xmlfile,"\t\t\t\t<sector_list>\n");

					if(sca && nb_sectorfound)
					{
						sectoffset = malloc(sizeof(sect_offset*) * nb_sectorfound);
						sorted_sectoffset = malloc(sizeof(sect_offset*) * nb_sectorfound);
						if(sorted_sectoffset && sectoffset)
						{
							memset(sectoffset,0,sizeof(sect_offset*) * nb_sectorfound);
							memset(sorted_sectoffset,0,sizeof(sect_offset*) * nb_sectorfound);
							for(s=0;s<nb_sectorfound;s++)
							{
								sorted_sectoffset[s] = malloc(sizeof(sect_offset));
								sorted_sectoffset[s]->ss = sca[s];
								sorted_sectoffset[s]->offset = 0;
							}

							memcpy(sectoffset,sorted_sectoffset,sizeof(sect_offset*) * nb_sectorfound);

							quickSort(sorted_sectoffset, 0, nb_sectorfound - 1);

							for(s=0;s<nb_sectorfound;s++)
							{
								sorted_sectoffset[s]->offset = fileoffset;
								fileoffset += sca[s]->sectorsize;
							}

							free(sorted_sectoffset);

							for(s=0;s<nb_sectorfound;s++)
							{

								fprintf(xmlfile,"\t\t\t\t\t<sector sector_id=\"%d\" sector_size=\"%d\">\n",sca[s]->sector,sca[s]->sectorsize);
								if(sca[s]->fill_byte_used)
								{
									fprintf(xmlfile,"\t\t\t\t\t\t<data_fill>0x%.2X</data_fill>\n",sca[s]->fill_byte);
								}
								else
								{
									if(sca[s]->input_data)
									{
										fprintf(xmlfile,"\t\t\t\t\t\t<sector_data>");
										k=0;
										do
										{
											fprintf(xmlfile,"%.2X",sca[s]->input_data[k]);
											k++;
										}while(k<(int)sca[s]->sectorsize);

										fprintf(xmlfile,"</sector_data>\n");
									}
								}

								if(sca[s]->use_alternate_datamark)
								{
									fprintf(xmlfile,"\t\t\t\t\t\t<datamark>0x%.2X</datamark>\n",sca[s]->alternate_datamark);
								}

								fprintf(xmlfile,"\t\t\t\t\t\t<data_offset>0x%.6X</data_offset>\n",(unsigned int)sectoffset[s]->offset);
								fprintf(xmlfile,"\t\t\t\t\t</sector>\n");

								hxcfe_freeSectorConfig  (ss,sca[s]);
							}

							for(s=0;s<nb_sectorfound;s++)
							{
								free(sectoffset[s]);
							}
							free(sectoffset);
						}

						free(sca);
					}

					fprintf(xmlfile,"\t\t\t\t</sector_list>\n");

					fprintf(xmlfile,"\t\t\t</track>\n");
				}
			}
			hxcfe_deinitSectorSearch(ss);
		}

		fprintf(xmlfile,"\t\t</track_list>\n");
		fprintf(xmlfile,"\t</layout>\n");
		fprintf(xmlfile,"</disk_layout>\n");

		hxc_fclose(xmlfile);
	}

	return 0;
}
int TI99V9T9_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy,char * filename)
{
	int i,j,k;
	FILE * ti99v9t9file;
	int32_t nbsector,imagesize;

	int32_t numberofsector,numberofside,numberoftrack;
	int32_t density = ISOIBM_FM_ENCODING;
	int file_offset;
	int32_t sectorsize = 256;
	unsigned char * diskimage;
	int error = 0;
	HXCFE_SECTORACCESS* ss;
	HXCFE_SECTCFG* sc;

	imgldr_ctx->hxcfe->hxc_printf(MSG_INFO_1,"Write TI99 V9T9 file %s...",filename);

	imagesize=hxcfe_getFloppySize(imgldr_ctx->hxcfe,floppy,&nbsector);

	imgldr_ctx->hxcfe->hxc_printf(MSG_INFO_1,"Disk size : %d Bytes %d Sectors",imagesize,nbsector);

	ss = hxcfe_initSectorAccess(imgldr_ctx->hxcfe, floppy);
	if (ss)
	{
		sc = hxcfe_searchSector(ss, 0, 0, 0, density);
		if (!sc)
		{
			density = ISOIBM_MFM_ENCODING;
			sc = hxcfe_searchSector(ss, 0, 0, 0, density);
			if (!sc)
			{
				imgldr_ctx->hxcfe->hxc_printf(MSG_ERROR, "This disk is neither FM nor MFM.  Exiting.");
				return HXCFE_FILECORRUPTED;
			}
		}

		// sc->input_data should contain the disk geometry

		numberofside = sc->input_data[0x12];
		numberofsector = sc->input_data[0x0c];
		numberoftrack = sc->input_data[0x11];

		if ( (numberofside < 1) && (numberofside > 2))
		{
			imgldr_ctx->hxcfe->hxc_printf(MSG_ERROR, "Image claims it has %i sides, which is clearly wrong.  Exiting.", numberofside);
			return HXCFE_FILECORRUPTED;
		}
 
		if ( (numberoftrack != 40) && (numberoftrack != 80))
		{
			imgldr_ctx->hxcfe->hxc_printf(MSG_ERROR, "Image claims each side has %i tracks, which is clearly wrong.  Exiting.", numberoftrack);
			return HXCFE_FILECORRUPTED;
		}
 
		if ( (numberofsector != 9) && (numberofsector != 16) && (numberofsector != 18) && (numberofsector != 36))
		{
			imgldr_ctx->hxcfe->hxc_printf(MSG_ERROR, "Image claims each track has %i sectors, which is clearly wrong.  Exiting.", numberofsector);
			return HXCFE_FILECORRUPTED;
		}

		if ( (numberofsector * numberoftrack * numberofside) != nbsector )
		{
			imgldr_ctx->hxcfe->hxc_printf(MSG_ERROR, "Disk geometry %i/%i/%i does not match disk length of %i sectors.  Exiting.", numberofside, numberoftrack, numberofsector, nbsector);
			return HXCFE_FILECORRUPTED;
		}


 
		imgldr_ctx->hxcfe->hxc_printf(MSG_INFO_1, "Disk geometry is %i sides, %i tracks per side, %i sectors per track.", numberofside, numberoftrack, numberofsector);

		imagesize = numberofsector * numberoftrack * numberofside * sectorsize;
		diskimage = malloc(imagesize);
		if (!diskimage)
			return HXCFE_INTERNALERROR;
		memset(diskimage, 0xF6, imagesize);

		for(i=0;i<numberofside;i++)
		{
			for(j=0;j<numberoftrack;j++)
			{
				hxcfe_imgCallProgressCallback(imgldr_ctx, j + (i*numberoftrack),numberofside*numberoftrack);

				for(k=0;k<numberofsector;k++)
				{
					sc = hxcfe_searchSector(ss,j,i,k,density);
					if(sc)
					{
						if(sc->use_alternate_data_crc)
							imgldr_ctx->hxcfe->hxc_printf(MSG_ERROR,"Warning : Bad Data CRC : T:%d H:%d S:%d Size :%dB",j,i,k,sc->sectorsize);

						if(sc->sectorsize == sectorsize)
						{
							if(i==0)
								file_offset=(j*numberofsector)*sectorsize + ( k * sectorsize );
							else
								file_offset=(  numberoftrack      *numberofsector*sectorsize) +
												(((numberoftrack-1)-j)*numberofsector*sectorsize) +
												( k * sectorsize );
							memcpy(&diskimage[file_offset], sc->input_data, sectorsize);
						} else {
							error++;
							imgldr_ctx->hxcfe->hxc_printf(MSG_ERROR,"Bad Sector Size : T:%d H:%d S:%d Size :%dB, Should be %dB",j,i,k,sc->sectorsize,sectorsize);
						}

						hxcfe_freeSectorConfig(ss,sc);
					} else {
						imgldr_ctx->hxcfe->hxc_printf(MSG_ERROR,"Sector not found : T:%d H:%d S:%d",j,i,k);
					}
				}
			}
		}

		if(!error)
		{
			ti99v9t9file=hxc_fopen(filename,"wb");
			if(ti99v9t9file)
			{
				fwrite(diskimage,imagesize,1,ti99v9t9file);
				hxc_fclose(ti99v9t9file);
			} else {
				free(diskimage);
				hxcfe_deinitSectorAccess(ss);
				return HXCFE_ACCESSERROR;
			}
		}
	}

	free(diskimage);
	hxcfe_deinitSectorAccess(ss);

	if(!error)
		return HXCFE_NOERROR;
	else
	{
		imgldr_ctx->hxcfe->hxc_printf(MSG_ERROR,"Errors were found in this disk image.");
		return HXCFE_FILECORRUPTED;
	}
}