Showing posts with label c source code. Show all posts

ALP in line code for displaying boot sector of floppy and boot record of hard disk.

, by Engineer's Vision

ALP in line code for displaying boot sector of floppy and boot record of hard disk.



#include<stdio.h>
#include<conio.h>

void main()
{
    int i;
    char buffer[512],*ptr;
    clrscr();

    asm{
    mov ah,0x1c                          ;function for absolute read disk
    mov al,0                     ;drive number
    mov cx,0x001                 ;number of sectors to read
    mov dx,0                     ;starting sector
    lea bx,buffer                    ;address of buffer
    int 0x0025

    jnc succ                     ;if successful then no carry
       }
    printf("\n Error reading floppy drive ");
    getch();

    succ : ptr = buffer;             ;ptr contains address of buffer
        
    ptr = ptr + 3;
    printf("\n OEM Name & Version is : ");
    for(i=0;i<8;i++,ptr++)
      {
      printf("%c",*ptr);
      }

    ptr = buffer + 0x0b;
    printf("\n Byte/Sector is : %d ",*(int *)ptr);

    ptr = buffer + 0x0d;
    printf("\n Sectors/Allocation unit is : %d ",*(int *)ptr);

    ptr = buffer + 0x10;
    printf("\n Number of FATs are : %d ",*ptr);

    ptr = buffer + 0x11;
    printf("\n Number of root directory entries are : %d ",*(int *)ptr);

    ptr = buffer + 0x13;
    printf("\n Total number of sectors in logical volume are : %d ",*(int *)ptr);

    ptr = buffer + 0x15;
    printf("\n Media descriptor address byte is : %2x ",(unsigned char)*ptr);

    ptr = buffer + 0x16;
    printf("\n Number of sectors/FAT are : %d ",*(int *)ptr);

    ptr = buffer + 0x18;
    printf("\n Sectors/track is : %d ",*(int *)ptr);

    ptr = buffer + 0x1A;
    printf("\n Number of heads are : %d ",*(int *)ptr);

    getch();
}
read more

Program to read file from flopy disk (FAT).

, by Engineer's Vision


Program to read file from flopy disk (FAT).


#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
#include<process.h>

struct dir
{
    char filename[8];
    char ext[3];
    char x1[15];
    int start_cluster;
    char x2[4];
};

void main()
{
    int flag=0,i,j;
    struct dir d[224];
    char arr[512];
    char file[8];
    char ext1[3];
    int logical,physical;

    clrscr();

    printf("\n Enter file name : ");
    scanf("%s",file);
    printf("\n Enter file extension : ");
    scnaf("%s",ext1);

    asm{
    mov al,0
    mov cx,14
    mov dx,19
    lea bx,d
    int 0x25
    }

    for(i=0;i<224;i++)
    {
    for(j=0;j<8;j++)
    {
        if(d[i].filename[j]==' ')
        {
        d[i].filename[j]='\0';
        }
    }
    if(strcmpi(d[i].filename,file)==0)
    {
        printf("\n File name found ");
        d[i].ext[3]='\0';

        if(strcmpi(d[i].ext,ext1)==0)
        {
        printf("\n Extension found ");
        flag=1;
        break;
        }
        else
        {
        printf("\n Extension not found ");
        getch();
        exit(1);
        }
    }
    }

    if(flag==0)
    {
    printf("\n File not found ");
    getch();
    exit(1);
    }

    logical=d[i].start_cluster;
    printf("\n Starting cluster number is : %d ",logical);
    physical=logical+31;

    if(physical<4095)
    {
    asm{
        mov al,0
        mov cx,1
        mov dx,physical
        lea bx,arr
        int 0x25
    }
    }

    printf("\n Contents of file are : \n ");
    printf("%s",arr);
    getch();
}
read more