/*
-----------------------------------------------------------------------------------------
ASSIGNMENT NO : 4
Title : Write an ALP/Inline Code for displaying file contents
using root directory and FAT for Floppy Disk.
-----------------------------------------------------------------------------------------
*/
#include<stdio.h>
#include<conio.h>
void main()
{
char name[20],fname[8],ext[3];
char buff[513]="\\0";
char root[512*14],fat[512*9];
int i,j,k;
int flag=0;
unsigned int clust,sector;
int quo,rem;
clrscr();
for(i=0;i<8;i++)
{
fname[i]=\' \';
}
for(i=0;i<3;i++)
{
ext[i]=\' \';
}
printf("\\n\\nEnter the file name .: ");
gets(name);
k=strlen(name);
for(i=0;i<k;i++)
{
if(name[i]==\'.\')
break;
fname[i]=toupper(name[i]);
}
i++;
for(j=0;i<k;i++,j++)
{
ext[j]=toupper(name[i]);
}
_asm{
mov al,0 // total 14 file allocation , Root = 512*14
mov cx,14
mov dx,19
lea bx,root
int 25h
popf
} // root directory is copied in root
k=0;
for(i=0,j=0;i<224;i++)
{
if(strncmp(fname,root+k,8)==0)
{
if(strncmp(ext,root+k+8,3)==0)
{
flag=1;
k=k+26; // the files contents are stored at 26th position in the cluster
_asm{
lea si,root // starting address of root directory
add si,k // address of the strating cluster
mov al,[si]
inc si
mov ah,[si]
mov clust,ax // 16 bit address is stored in cluster
}
break;
}
}
else
{
k=k+32; // the files info. stored is of 32 bits
}
}
if(flag==0)
{
printf("\\n\\tfile is not present:");
getch();
exit(0);
}
else
{
printf("\\n\\nContent of files are .: ");
_asm{
mov al,0
mov cx,9
mov dx,1
lea bx,fat
int 25h
popf
}
while(1)
{
printf("\\n\\nStarting cluster is .: %d",clust);
sector=clust+31;
printf("\\n\\nStarting sector is .: %d",sector);
getch();
_asm{
mov al,0
mov cx,1
mov dx,sector
lea bx,buff
int 25h
popf
}
printf("\\n%s",buff);
getch();
clust=clust*3;
quo=clust/2;
rem=clust%2;
_asm{
lea si,fat
add si,quo
mov al,[si]
inc si
mov ah,[si]
mov clust,ax
}
if(rem==0)
{
clust=clust & 0x0fff;
if(clust==0x0fff)break;
}
else if(rem==1)
{
clust=clust>>4;
if(clust==0x0fff)break;
}
}
}
getch();
}
/*
-----------------------------------------------------------------
END OF THE PROGRAM
-----------------------------------------------------------------
*/