home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
64'er
/
64ER_CD.iso
/
utilpc
/
d64util
/
ccopy.c
next >
Wrap
C/C++ Source or Header
|
1994-03-29
|
2KB
|
134 lines
int infile,outfile;
long track[36];
long lseek();
char dir[16384];
long fileread(tr,se,where)
int tr,se;
char *where;
{
long offset;
char buffer[256];
char *p;
long len=0;
int i;
while()
{
offset=track[tr]+se*0x100L;
lseek(infile,offset,0);
read(infile,buffer,256);
p=buffer;
tr=*p++;
se=*p++;
if(tr)
{
for(i=0;i<254;i++) *where++=*p++;
len+=254;
}
else
{
se--;
for(i=0;i<se;i++) *where++=*p++;
len+=se;
return len;
}
}
}
long copy(tr,se,ohand)
int tr,se,ohand;
{
long offset;
char buffer[256];
char *p;
long len=0;
int i;
while()
{
offset=track[tr]+se*0x100L;
lseek(infile,offset,0);
read(infile,buffer,256);
p=buffer;
tr=*p++;
se=*p++;
if(tr)
{
write(ohand,p,254);
len+=254;
}
else
{
se--;
write(ohand,p,se);
len+=se;
return len;
}
}
}
main(argc,argv)
int argc;
char *argv[];
{
int i,j,num;
long v;
long len;
char *p;
char name[20];
char fname[64];
char oname[64];
v=0;i=1;
while(i<18) {track[i++]=v;v+=0x1500L;}
while(i<25) {track[i++]=v;v+=0x1300L;}
while(i<31) {track[i++]=v;v+=0x1200L;}
while(i<36) {track[i++]=v;v+=0x1100L;}
if(argc!=4)
{
puts("Use: CCOPY <imagefile> <file #> <outputname>\n");
return;
}
strcpy(fname,argv[1]);
infile=fopen(fname,"r");
if(!infile)
{
strcat(fname,".d64");
infile=fopen(fname,"r");
if(!infile)
{
printf("Cannot open \"%s\"\n",argv[1]);
return;
}
}
p=argv[2];
num=0;
while(*p>='0' && *p<='9') num+=9*num + (*p++) -'0';
len=fileread(18,0,dir);
i=0;
p=dir+0xfe;
while(i!=num)
{
i++;
p+=32;
if((i&7)==0) p-=2;
if(p-dir>=len) {puts("Illegal file number\n");return;}
}
outfile=fopen(argv[3],"w");
if(!outfile)
{
printf("Cannot open %s for output\n",argv[3]);
fclose(infile);
return;
}
copy(p[1],p[2],outfile);
fclose(outfile);
fclose(infile);
}