Skip to content

Commit

Permalink
use "HXCRAMFILE" api.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfdelnero committed Nov 13, 2023
1 parent b30fad0 commit edb8f85
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 305 deletions.
24 changes: 7 additions & 17 deletions libhxcfe/sources/loaders/hfe_loader/exthfe_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,9 @@ void extaddpad(unsigned char * track,int mfmsize,int tracksize)
}
}

typedef struct RAMFILE_
{
uint8_t * ramfile;
int32_t ramfile_size;
}RAMFILE;

FILE * rfopen(char* fn,char * mode,RAMFILE * rf);
int rfwrite(void * buffer,int size,int mul,FILE * file,RAMFILE * rf);
int rfclose(FILE *f,RAMFILE * rf);

int EXTHFE_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy,char * filename)
{
RAMFILE rf;
HXCRAMFILE rf;
picexttrack * track;

FILE * hxcpicfile;
Expand All @@ -103,7 +93,7 @@ int EXTHFE_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy,char
factor=1;// factor=1-> 50% duty cycle // factor=2-> 25% duty cycle
imgldr_ctx->hxcfe->hxc_printf(MSG_INFO_1,"Write HFE file %s for the standalone emulator.",filename);

hxcpicfile = rfopen(filename,"wb",&rf);
hxcpicfile = hxc_ram_fopen(filename,"wb",&rf);

if(hxcpicfile)
{
Expand Down Expand Up @@ -166,7 +156,7 @@ int EXTHFE_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy,char
else
FILEHEADER->single_step=0xFF;

rfwrite(FILEHEADER,512,1,hxcpicfile,&rf);
hxc_ram_fwrite(FILEHEADER,512,1,hxcpicfile,&rf);

tracklistlen=((((((FILEHEADER->number_of_track)+1)*sizeof(picexttrack))/512)+1));
offsettrack=(unsigned char*) malloc(tracklistlen*512);
Expand Down Expand Up @@ -218,7 +208,7 @@ int EXTHFE_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy,char
i++;
};

rfwrite(offsettrack,512*tracklistlen,1,hxcpicfile,&rf);
hxc_ram_fwrite(offsettrack,512*tracklistlen,1,hxcpicfile,&rf);

i=0;
while(i<(FILEHEADER->number_of_track))
Expand Down Expand Up @@ -327,7 +317,7 @@ int EXTHFE_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy,char
}


rfwrite(mfmtrackfinal,tracksize*2,1,hxcpicfile,&rf);
hxc_ram_fwrite(mfmtrackfinal,tracksize*2,1,hxcpicfile,&rf);

free(mfmtracks0);
free(mfmtracks1);
Expand All @@ -347,12 +337,12 @@ int EXTHFE_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy,char
}
else
{
rfclose(hxcpicfile,&rf);
hxc_ram_fclose(hxcpicfile,&rf);
imgldr_ctx->hxcfe->hxc_printf(MSG_ERROR,"Cannot create %s!",filename);
return -1;
}

rfclose(hxcpicfile,&rf);
hxc_ram_fclose(hxcpicfile,&rf);

imgldr_ctx->hxcfe->hxc_printf(MSG_INFO_1,"%d tracks written to the file",FILEHEADER->number_of_track);

Expand Down
24 changes: 7 additions & 17 deletions libhxcfe/sources/loaders/hfe_loader/hfe_hddd_a2_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,9 @@

extern void addpad(unsigned char * track,int mfmsize,int tracksize);

typedef struct RAMFILE_
{
uint8_t * ramfile;
int32_t ramfile_size;
}RAMFILE;

FILE * rfopen(char* fn,char * mode,RAMFILE * rf);
int rfwrite(void * buffer,int size,int mul,FILE * file,RAMFILE * rf);
int rfclose(FILE *f,RAMFILE * rf);

int HFE_HDDD_A2_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy,char * filename)
{
RAMFILE rf;
HXCRAMFILE rf;
pictrack * track;

FILE * hxcpicfile;
Expand All @@ -79,7 +69,7 @@ int HFE_HDDD_A2_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy
return -1;
}

hxcpicfile=rfopen(filename,"wb",&rf);
hxcpicfile=hxc_ram_fopen(filename,"wb",&rf);

if(hxcpicfile)
{
Expand Down Expand Up @@ -140,7 +130,7 @@ int HFE_HDDD_A2_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy
FILEHEADER->single_step=0x00;
}

rfwrite(FILEHEADER,512,1,hxcpicfile,&rf);
hxc_ram_fwrite(FILEHEADER,512,1,hxcpicfile,&rf);

tracklistlen=((((((FILEHEADER->number_of_track)+1)*sizeof(pictrack))/512)+1));
offsettrack=(unsigned char*) malloc(tracklistlen*512);
Expand Down Expand Up @@ -193,7 +183,7 @@ int HFE_HDDD_A2_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy
i++;
};

rfwrite(offsettrack,512*tracklistlen,1,hxcpicfile,&rf);
hxc_ram_fwrite(offsettrack,512*tracklistlen,1,hxcpicfile,&rf);

i=0;
while(i<(FILEHEADER->number_of_track))
Expand Down Expand Up @@ -279,7 +269,7 @@ int HFE_HDDD_A2_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy
}
}

rfwrite(mfmtrackfinal,tracksize*2,1,hxcpicfile,&rf);
hxc_ram_fwrite(mfmtrackfinal,tracksize*2,1,hxcpicfile,&rf);

free(mfmtracks0);
free(mfmtracks1);
Expand All @@ -298,12 +288,12 @@ int HFE_HDDD_A2_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy
}
else
{
rfclose(hxcpicfile,&rf);
hxc_ram_fclose(hxcpicfile,&rf);
imgldr_ctx->hxcfe->hxc_printf(MSG_ERROR,"Cannot create %s!",filename);
return -1;
}

rfclose(hxcpicfile,&rf);
hxc_ram_fclose(hxcpicfile,&rf);

imgldr_ctx->hxcfe->hxc_printf(MSG_INFO_1,"%d tracks written to the file",FILEHEADER->number_of_track);

Expand Down
42 changes: 7 additions & 35 deletions libhxcfe/sources/loaders/hfe_loader/hfe_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,9 @@ void addpad(unsigned char * track,int mfmsize,int tracksize)
}
}

typedef struct RAMFILE_
{
uint8_t * ramfile;
int32_t ramfile_size;
}RAMFILE;

FILE * rfopen(char* fn,char * mode,RAMFILE * rf)
{
rf->ramfile=0;
rf->ramfile_size=0;
return (FILE *)1;
};

int rfwrite(void * buffer,int size,int mul,FILE * file,RAMFILE * rf)
{
rf->ramfile = realloc(rf->ramfile,rf->ramfile_size+size);
memcpy(&rf->ramfile[rf->ramfile_size],buffer,size);
rf->ramfile_size = rf->ramfile_size + size;
return size;
}

int rfclose(FILE *f,RAMFILE * rf)
{
if(rf->ramfile)
free(rf->ramfile);
return 0;
};

int HFE_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy,char * filename)
{
RAMFILE rf;
HXCRAMFILE rf;
pictrack * track;

FILE * hxcpicfile;
Expand Down Expand Up @@ -130,7 +102,7 @@ int HFE_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy,char *
return HXCFE_BADPARAMETER;
}

hxcpicfile=rfopen(filename,"wb",&rf);
hxcpicfile = hxc_ram_fopen(filename,"wb",&rf);

if(hxcpicfile)
{
Expand Down Expand Up @@ -201,7 +173,7 @@ int HFE_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy,char *
else
FILEHEADER->single_step=0xFF;

rfwrite(FILEHEADER,512,1,hxcpicfile,&rf);
hxc_ram_fwrite(FILEHEADER,512,1,hxcpicfile,&rf);

tracklistlen=((((((FILEHEADER->number_of_track)+1)*sizeof(pictrack))/512)+1));
offsettrack=(unsigned char*) malloc(tracklistlen*512);
Expand Down Expand Up @@ -253,7 +225,7 @@ int HFE_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy,char *
i++;
};

rfwrite(offsettrack,512*tracklistlen,1,hxcpicfile,&rf);
hxc_ram_fwrite(offsettrack,512*tracklistlen,1,hxcpicfile,&rf);

i=0;
while(i<(FILEHEADER->number_of_track))
Expand Down Expand Up @@ -366,7 +338,7 @@ int HFE_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy,char *
}


rfwrite(mfmtrackfinal,tracksize*2,1,hxcpicfile,&rf);
hxc_ram_fwrite(mfmtrackfinal,tracksize*2,1,hxcpicfile,&rf);

free(mfmtracks0);
free(mfmtracks1);
Expand All @@ -387,12 +359,12 @@ int HFE_libWrite_DiskFile(HXCFE_IMGLDR* imgldr_ctx,HXCFE_FLOPPY * floppy,char *
}
else
{
rfclose(hxcpicfile,&rf);
hxc_ram_fclose(hxcpicfile,&rf);
imgldr_ctx->hxcfe->hxc_printf(MSG_ERROR,"Cannot create %s!",filename);
return -1;
}

rfclose(hxcpicfile,&rf);
hxc_ram_fclose(hxcpicfile,&rf);

imgldr_ctx->hxcfe->hxc_printf(MSG_INFO_1,"%d tracks written to the file",FILEHEADER->number_of_track);

Expand Down
Loading

0 comments on commit edb8f85

Please sign in to comment.