📄 gm82c765.pp
字号:
#line 229 "f2407_c.h"
ioport unsigned int portFF0F;
ioport unsigned int portFFFF;
#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 "Delay.h"
void Delay50mS(void);
void Delay25mS(void);
void Delay4mS(void);
void Delay50uS(void);
void Delay8uS(void);
void Delay12uS(void);
void Delay24uS(void);
#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 8 "gm82c765.c"
ioport unsigned portE003;
ioport unsigned portE000;
ioport unsigned portE001;
ioport unsigned portE002;
ioport unsigned portC000;
ioport unsigned port8000;
ioport unsigned portA000;
inline int Initial8255()
{
portE003=0x0089;
portE001=0x0070;
}
int InitialGM()
{
char mstreg;
portE001=0x0070;
mstreg=portC000&0xff;
port8000=0x0000;
portA000=0x0000;
return 0;
}
#line 85
int SenseInterrupt(void)
{
char command=0x08;
char result[2];
char mstreg;
if(SendCommandToGM(&command,1)!=0x00)
return -1;
portE001=0x0070;
while(1)
{
mstreg=portC000&0xff;
if(!(mstreg&0x20))
break;
}
if(ReadResultFromGM(result,2)==0x80)
return -1;
MotorOff();
return 0;
}
int SenseDriverStatus(void)
{
char command[2]={0x04,0x00};
char result;
char mstreg;
MotorOn();
if(SendCommandToGM(command,2)!=0x00)
{
MotorOff();
return -1;
}
portE001=0x0070;
Delay4mS();
if(ReadResultFromGM(&result,1)==0x80)
{
MotorOff();
return -1;
}
MotorOff();
return result;
}
void MotorOn()
{
port8000=0x0035;
Delay4mS();
}
void MotorOff()
{
port8000=0x0004;
Delay4mS();
}
int Seek(int newcylinder)
{
char command[3];
command[0]=0x0f;
command[1]=0x04;
command[2]=newcylinder;
MotorOn();
if(SendCommandToGM(command,3)!=0)
{
MotorOff();
return -1;
}
return 0;
}
int WriteData(int cylinder,int head,int sector,int numberofsector,
char *data,int datalength )
{
char command[9];
char result[7];
int i, mstreg=0;
command[0]=0x45;
command[1]=0x00+head*4;
command[2]=cylinder;
command[3]=head;
command[4]=sector;
command[5]=numberofsector;
command[6]=0x09;
command[7]=0x1b;
command[8]=0xff;
MotorOn();
if(SendCommandToGM(command,9)!=0x00)
{
MotorOff();
return -1;
}
portE001=0x0070;
for(i=0;i<datalength;++i)
{
mstreg=portC000&0xff;
if(mstreg==0xb0)
{
portE001=0x0073;
if(i%2)
{
portC000=*(data+i/2);
}
else
{
*(data+i/2)>>=8;
portC000=*(data+i/2);
}
portE001=0x0070;
}
else
{
--i;
}
if(mstreg==0xD0)
break;
}
while(1)
{
mstreg=portC000&0xff;
if(mstreg==0xD0)
break;
}
if(ReadResultFromGM(result,7)!=0)
{
MotorOff();
return -1;
}
MotorOff();
return 0;
}
int ReadData(int cylinder,int head,int sector,int numberofsector,
char *data,int datalength )
{
char command[9];
char result[7];
int i, mstreg=0;
command[0]=0xc6;
command[1]=0x00+head*4;
command[2]=cylinder;
command[3]=head;
command[4]=sector;
command[5]=numberofsector;
command[6]=0x12;
command[7]=0x1b;
command[8]=0xff;
MotorOn();
if(SendCommandToGM(command,9)!=0x00)
{
MotorOff();
return -1;
}
portE001=0x0070;
for(i=0;i<datalength;++i)
{
mstreg=portC000&0xff;
if(mstreg==0xf0)
{
portE001=0x0073;
if(i%2)
{
*(data+i/2)<<=8;
*(data+i/2)+=portC000&0xff;
}
else
{
*(data+i/2)=portC000&0xff;
}
portE001=0x0070;
}
else
{
--i;
}
if((mstreg&0xf0)==0xD0)
break;
}
while(1)
{
mstreg=portC000&0xff;
if((mstreg&0xf0)==0xD0)
break;
}
if(ReadResultFromGM(result,7)!=0)
{
MotorOff();
return -1;
}
MotorOff();
return 0;
}
int Specify()
{
char command[3]={0x0003,0x00df,0x0003};
MotorOn();
if(SendCommandToGM(command,3)!=0)
{
MotorOff();
return -1;
}
MotorOff();
return 0;
}
int Recalibrate()
{
char command[2]={0x0007,0x0000};
MotorOn();
if(SendCommandToGM(command,2)!=0)
{
MotorOff();
return -1;
}
return 0;
}
int ReadID(void)
{
int i;
char command[2]={0x4a,0x00};
char result[7];
char mstreg;
MotorOn();
if(SendCommandToGM(command,2)!=0)
return -1;
portE001=0x0070;
Delay4mS();
while(1)
{
mstreg=portC000&0xff;
if(!(mstreg&0x20))
break;
}
if(ReadResultFromGM(result,7)==0x80)
return -1;
MotorOff();
return 0;
}
int SendCommandToGM(char *command,int comlength)
{
int i;
char mstreg,errCause;
portE001=0x0070;
mstreg=portC000&0x00ff;
if(mstreg&0x0010)
{
return -1;
}
for(i=0;i<comlength;++i)
{
portE001=0x0070;
while(1)
{
mstreg=portC000&0x00ff;
if(mstreg&0x0080)
{
if(mstreg&0x0040)
{
portE001=0x0073;
errCause=portC000&0xff;
return errCause;
}
else
{
break;
}
}
}
portE001=0x0073;
portC000=*(command+i);
}
return 0;
}
int ReadResultFromGM(char *result,int reslength)
{
int i;
char mstreg,errCause;
for(i=0;i<reslength;++i)
{
portE001=0x0070;
while(1)
{
mstreg=portC000&0x00ff;
if(mstreg&0x0080)
{
if(mstreg&0x0040)
{
break;
}
else
{
portE001=0x0073;
errCause=portC000&0xff;
return errCause;
}
}
}
portE001=0x0073;
*(result+i)=portC000&0xff;
}
return 0;
}
interrupt void nothing()
{
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -