//Invoke example
//Before operate(read or write) the drive it should check the status of zip
//{
// while( errno = Packet_Drive_Ready() ) ;
// Packet_Read(i*256,0,buf);
//}
void Zip_Initialize(void)
{
// Port initialization
SET_PCSEL (0xff);
SET_PCDIR (0xff);
SET_PCPUEN(0xff);
SET_PDSEL (0xff);
SET_PDDIR (0xff);
SET_PDPUEN(0xff);
SET_PKSEL (0xfb);
SET_PKDIR (0x7f);
SET_PKPUEN(0xff);
SET_PMSEL (GET_PMSEL | 0x20);
SET_PMDIR (0xff);
SET_PMPUEN(0xff);
// Other initialization
SET_PKDATA(0x7f);
SET_PMDATA(GET_PMDATA | 0x20);
}
//Read the content of registers,Used for test
void Read_Register(void)
{
UWORD i,status,addr;
if ( ptrATAPI->Id == ID_WR ) //If write operation
{
if ( (ptrATAPI->acket_Command[0] = 0x0a) && (ptrATAPI->Buffer_Length == 0) )
ptrATAPI->Buffer_Length=256;
n=ptrATAPI->Buffer_Length;
for (i = 0; i < n; i++)
{
SET_INPUT_MODE();
while ((status = Read_ATA_Reg(STATUS_REG)) & ATA_STATUS_BSY) ;
if (status & ATA_STATUS_ERR)
{
errno = Read_ATA_Reg(ERROR_REG);
return errno;
} //check the status
SET_OUTPUT_MODE();
SET_ADDR(DATA_REG);
for (j = 0; j < 256; j++)
{
//Write_A_Word( buf[i * 256 + j] );
Write_A_Word( *buf++ );
ASSERT_WR();
NEGATE_WR(); //write
}
}
}
else if ( ptrATAPI->Id == ID_RD ) //If read operation
{
if ( (ptrATAPI->acket_Command[0] = 0x08) && (ptrATAPI->Buffer_Length == 0) )
ptrATAPI->Buffer_Length=256;
n=ptrATAPI->Buffer_Length;
for (i = 0; i < n; i++)
{
while ((status = Read_ATA_Reg(STATUS_REG)) & ATA_STATUS_BSY) ;
if (status & ATA_STATUS_ERR)
{
errno = Read_ATA_Reg(ERROR_REG);
return errno;
}
SET_ADDR(DATA_REG);
for (j = 0; j < 256; j++)
{
ASSERT_RD();
*buf++ = Read_A_Word();
//buf[i * 256 + j] = Read_A_Word();
NEGATE_RD();
}
}
}
else if ( ptrATAPI->Id == ID_SET )
{
while ((status = Read_ATA_Reg(STATUS_REG)) & ATA_STATUS_BSY) ;
if (status & ATA_STATUS_ERR)
{
errno = Read_ATA_Reg(ERROR_REG);
return errno;
}
SET_OUTPUT_MODE();
SET_ADDR(DATA_REG);
for (j = 0; j < (UWORD)( ptrATAPI->Buffer_Length / 2 ); j++)
{
Write_A_Word( buf[j] );
ASSERT_WR();
NEGATE_WR();
}
}
else //If other operation
{
while ((status = Read_ATA_Reg(STATUS_REG)) & ATA_STATUS_BSY) ;
if (status & ATA_STATUS_ERR)
{
errno = Read_ATA_Reg(ERROR_REG);
return errno;
}
SET_ADDR(DATA_REG);
for (j = 0; j < (UWORD)( ptrATAPI->Buffer_Length / 2 ); j++)
{
ASSERT_RD();
buf[j] = Read_A_Word();
NEGATE_RD();
}
}
//May be for public use
void e_strcpy(UCHAR *s, UCHAR *d);
void e_strncpy(UCHAR *s, UCHAR *d, UWORD l);
SWORD e_strcmp(UCHAR *s, UCHAR *d);
typedef struct
{
UWORD Bytes_Per_Sector;
UWORD Sectors_Per_Cluster;
UWORD FAT_Number;
UWORD Root_Item_Number;
UWORD Sectors_Per_FAT;
} DISK_PARAMETER;
DISK_PARAMETER Disk_Parameter;
//Store file parameter
UCHAR Para_Buffer[512];
/*****************************************************************************
** Prototype: SWORD Get_Disk_Information(DISK_INFORMATION *ptrInfor); **
** Description: Get the information of the disk **
** Input Parameter:ptrInfor--The information about the disk **
** Return: Error Code **
******************************************************************************/
SWORD Get_Disk_Information(DISK_INFORMATION *ptrInfor)
{
UWORD errno,i;
UCHAR filename[12];
UCHAR *buffer;
//Read the information of index
while( errno = Packet_Drive_Ready() ) ;
if( errno = Packet_Read(0,1,Para_Buffer) ) return errno;
//Point to the head of Para_Buffer
buffer=Para_Buffer;
//Sum the total file number and total song number
ptrInfor->Total_Song_Number = *(buffer+1);
ptrInfor->Total_File_Number = *(buffer+1);
//Locate to file information
buffer+=0x20;
buffer+=0x04;
//Get the file name and length
for( i=0; i< ptrInfor->Total_Song_Number; i++,buffer+=8 )
{
e_strcpy( (UCHAR *)"EWORLD",filename);
filename[6]=i+1+0x30;
e_strcpy( (UCHAR *)".DEC",filename+7);
e_strcpy(filename,ptrInfor->Song_Infor.Song_Name);
ptrInfor->Song_Infor.Song_Length= \
(*(buffer+1))