📄 partion2.pp
字号:
#line 3 "gm82c765b.h"
int Recalibrate(void);
int ReadID(void);
int Seek(int newcylinder);
int SenseDriverStatus(void);
int SenseInterrupt(void);
int WriteData(int cylinder,int head,int sector,int numberofsector,
char *data,int datalength );
int ReadData(int cylinder,int head,int sector,int numberofsector,
char *data,int datalength );
#line 3 "partion.h"
typedef struct
{
char Head;
char Sector;
char Cylinder;
}CHS;
typedef struct
{
int SectorBytes;
char SectorsPerCluster;
int ReservedSectors;
char nbrFat;
int RootEntry;
int TotalSectors;
char Media;
int SectorsPerFAT;
int SectorsPerTrack;
int Heads;
long hiddenSectors;
long BigTotalSectors;
}BPB_FAT;
typedef struct
{
char FileName[8];
char ExtendName[3];
char FileAttribute;
char Reserved[10];
int time;
int date;
int firstcluster;
long filesize;
}RootDirectory;
#line 4 "global.h"
extern unsigned char databuffer[1024];
extern unsigned char databuffer1[512];
extern BPB_FAT bpb;
extern int curcylinder;
extern int filecounts;
extern int curFlashPage;
extern int curFlashOffset;
#line 5 "partion2.c"
int ReadFileFromFloppy(int number_of_file)
{
int i,logAddr,clustercount;
unsigned int startcluster;
unsigned int temp;
long filesize;
char cluster[36];
if(number_of_file>filecounts)
return -1;
startcluster=(databuffer1[(number_of_file-1)*16+13]<<8)+(databuffer1[(number_of_file-1)*16+13]>>8);
temp=(databuffer1[(number_of_file-1)*16+15]<<8)+(databuffer1[(number_of_file-1)*16+15]>>8);
filesize=temp<<16;
temp=(databuffer1[(number_of_file-1)*16+14]<<8)+(databuffer1[(number_of_file-1)*16+14]>>8);
filesize+=temp;
WriteFileInFlash(1,databuffer1+(number_of_file-1)*16,32);
while(filesize>0)
{
clustercount=GetClusterChainOfFile(startcluster,cluster);
if(clustercount>=0)
{
for(i=0;i<clustercount;i+=4)
{
if(clustercount<i+4)
{
filesize-=(clustercount-i)*512;
if(filesize<=0)
{
filesize+=(clustercount-i)*512;
logAddr=(startcluster-2)+GetDataLogicBlockAddr();
if(!ReadDataFromFloppy(logAddr,databuffer,(int)filesize))
{
WriteFileInFlash(0,databuffer,(int)filesize);
return 0;
}
else
{
return -1;
}
}
logAddr=(startcluster-2)+GetDataLogicBlockAddr();
if(!ReadDataFromFloppy(logAddr,databuffer,(clustercount-i)*512))
{
WriteFileInFlash(0,databuffer,(clustercount-i)*512);
startcluster=cluster[clustercount-1];
}
else
{
return -1;
}
break;
}
logAddr=(startcluster-2)+GetDataLogicBlockAddr();
if(!ReadDataFromFloppy(logAddr,databuffer,4*512))
{
WriteFileInFlash(0,databuffer,2048);
filesize-=2048;
startcluster=cluster[i+3];
}
else
{
return -1;
}
}
startcluster=cluster[clustercount-1];
}
else
{
return temp;
}
}
return 0;
}
int GetClusterChainOfFile(int startcluster,char *cluster)
{
int clustercount=0;
int maxcluster=0;
int logAddr=0;
int maxcount;
logAddr=(startcluster-2)+GetDataLogicBlockAddr();
maxcount=36-logAddr%36;
logAddr=GetFat1LogicBlockAddr();
while(1)
{
maxcluster+=1024;
if((clustercount?cluster[clustercount-1]:startcluster)>maxcluster)
{
logAddr+=3;
}
else
{
if(!ReadDataFromFloppy(logAddr,databuffer,1536))
{
while(1)
{
cluster[clustercount]=GetNextCluster(clustercount?cluster[clustercount-1]:startcluster,databuffer);
if(cluster[clustercount]==0x0fff)
{
++clustercount;
return clustercount;
}
if(cluster[clustercount]>maxcluster)
{
++clustercount;
logAddr+=3;
break;
}
if(cluster[clustercount]==0)
{
return -2;
}
if((cluster[clustercount]-(clustercount?cluster[clustercount-1]:startcluster))!=1)
{
++clustercount;
return clustercount;
}
++clustercount;
if(clustercount==maxcount)
{
return clustercount;
}
}
}
else
{
return -1;
}
}
}
}
int GetNextCluster(int currentcluster,char *data )
{
int offset=currentcluster%1024;
int nextcluster=0;
switch(offset%4)
{
case 0:
nextcluster=((data[offset*3/4]&0xff00)>>8)+((data[offset*3/4]&0x000f)<<8);
break;
case 1:
nextcluster=((data[offset*3/4]&0x00f0)>>4)+((data[offset*3/4+1]&0xff00)>>4);
break;
case 2:
nextcluster=(data[offset*3/4]&0x00ff)+(data[offset*3/4+1]&0x0f00);
break;
case 3:
nextcluster=((data[offset*3/4]&0xf000)>>12)+((data[offset*3/4]&0x00ff)<<4);
break;
}
return nextcluster;
}
int ListFileInRootDir()
{
int i,j,k;
CHS chsaddr;
filecounts=0;
for(i=GetRootDirLogicBlockAddr();i<GetDataLogicBlockAddr()-4;i+=4)
{
if(!ReadDataFromFloppy(i,databuffer,2048))
{
for(j=0;j<64;++j)
{
if(((databuffer[j*16]&0xff00)!=0xe500)&&(databuffer[j*16+13]!=0))
{
for(k=0;k<16;++k)
databuffer1[filecounts*16+k]=databuffer[j*16+k];
++filecounts;
}
}
}
else
{
return -1;
}
}
return filecounts;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -