⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dolba.h

📁 都在一个程序里
💻 H
字号:

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

int YesNo(char *s, char *filename)
//char *s,fil;
{
  //getchar();
  char *c="\0";

  printf("%s %s ? (Y/N)",s,filename);
  do {
    //c=getchar();
    //c=toupper(c);
    gets(c);
  } while (*c=='\0');
  if (strcmp(strupr(c),"Y")==0) return 1;
  else
  printf("\nNothing done.\n");
  return 0;
}

void doLBA(char *prompt,unsigned int cmd,
       unsigned int hardDisk,
       unsigned long startSector,
       unsigned long nSectorVar,
       char *filename,char *showFileName)
{
unsigned int head=0;
unsigned int cylinder=0;
unsigned int sector=0;
unsigned char pBuffer[32256];
FILE *f;
unsigned int allowednSector=0;
unsigned int doReadSector=0;
unsigned long sectorWrite=0;
unsigned int x=0,y=0;

unsigned long nSector=nSectorVar;

long filesize;

if(YesNo(prompt,showFileName)!=1) return;

x=wherex();
y=wherey();

//printf("%lu,%lu\n",startSector,nSectorVar);
cylinder=((startSector+nSector-1)/(255*63));
if(cylinder>1022)
{
printf("\n%u out of hard disk's cylinder range(0-1022)\n",cylinder);
return;
}

if(cmd==2)
{
if((f=fopen(filename,"wb"))==NULL)
{
printf("File Error : %s\n",showFileName);
return;
}
//fclose(f);
}

else if(cmd==3)
{
if((f=fopen(filename,"rb"))==NULL)
{printf("File Error : %s\n",showFileName); return;}
filesize=filelength(fileno(f));
//fclose(checkFile);
if((filesize==0) || (filesize % 512)!=0)
{printf("the size of the file is 0 or not an integer in sectors!\n");
return;}
nSector=filesize/512;
if(YesNo("Are you sure","")!=1) return;
}

cylinder=startSector/(255*63);
head=(startSector/63)%255;
sector=startSector%63+1;

allowednSector=63-sector+1;

 if(nSector<=allowednSector)
    doReadSector=nSector;

   else    doReadSector= allowednSector;

   while(sectorWrite<nSector)
   {

   if(bioskey(1)!=0)
   {
   if(bioskey(0)==0x11B)
   {
   printf("\nStopped.\n");
   return;
   }
   }

   if(cylinder>1022)
{printf("\nout of hard disk's cylinder range(0-1022)\n");
return;}

   if(cmd==2)
  {
  biosdisk(cmd,hardDisk,head,cylinder,sector,doReadSector,pBuffer);
//doFile(2,"ab+",pBuffer,doReadSector,filename,0);
  fwrite(pBuffer,doReadSector*512,1,f);
   }

    else if(cmd==3)
    {
    //doFile(3,"rb",pBuffer,doReadSector,filename,sectorWrite);
  fread(pBuffer,doReadSector*512,1,f);
  biosdisk(cmd,hardDisk,head,cylinder,sector,doReadSector,pBuffer);
  }

   sectorWrite+= doReadSector;
   gotoxy(x,y);
   cprintf("%lu%c sectors done.",sectorWrite*100/nSector,'%');

  head++;sector=1;

if (head>254) {cylinder++; head=0; sector=1;}
//if (cylinder>1022)
//{printf("\nout of hard disk's cylinder range(0-1022)\n");
//return;}
   doReadSector=63;
  if(nSector-sectorWrite<63) doReadSector=nSector-sectorWrite;

  }
  fclose(f);
  printf("\nDone.");
  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -