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

📄 dolba.h

📁 DOS下迷你硬盘读写器终于完工了! 可读写绝对扇区
💻 H
字号:
#include "dolba\checkext.h"
#include "dolba\extint13.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 *cmd,
       unsigned int driveNum,
       unsigned long startSector,
       unsigned long sectorToDo,
       char *filename,char *showFileName)
{
int rw=-1;
unsigned int head=0;
unsigned int cylinder=0;
unsigned int sector=0;
unsigned char pBuffer[32256];
unsigned long sectorToDoVar=sectorToDo;
FILE *f;
unsigned int allowedSector=0;
unsigned int doSector=0;
unsigned long sectorWritten=0;
unsigned int x=0,y=0;

long filesize;

char *prompt="";
char *readWrite;

if(strcmp(strupr(cmd),"R")==0) {readWrite="Read"; rw=0;}
if(strcmp(strupr(cmd),"W")==0) {readWrite="Write"; rw=1;}

sprintf(prompt,"%s :\n  Drive %u\n  Starting sector %lu\n  %lu Sectors\nTo :\n  File",readWrite,driveNum,startSector,sectorToDoVar);
if(driveNum>1) driveNum+=126;

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

//printf("%lu,%lu\n",startSector,sectorToDoVarVar);

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

else if(rw==1)
{
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;}
sectorToDoVar=filesize/512;
if(YesNo("Write drive! Are you sure","")!=1) return;
}

if(driveNum<2) goto absolute;

if(checkExt(driveNum)==0)
{

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

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

allowedSector=63-sector+1;

 if(sectorToDoVar<=allowedSector)
    doSector=sectorToDoVar;

   else    doSector= allowedSector;


   //if(sectorToDoVar<63) doSector=sectorToDoVar;
   //else doSector=63;

   printf("Press Esc to stop.\n");

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

   while(sectorWritten<sectorToDoVar)
   {

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


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

  if(rw==0)
  {
  biosdisk(2,driveNum,head,cylinder,sector,doSector,pBuffer);

//extint13(0x42,driveNum,startSector,doSector,pBuffer);
//doFile(2,"ab+",pBuffer,doSector,filename,0);
  fwrite(pBuffer,doSector*512,1,f);
   }

    else if(rw==1)
    {
    //doFile(3,"rb",pBuffer,doSector,filename,sectorWritten);
  fread(pBuffer,doSector*512,1,f);
  biosdisk(3,driveNum,head,cylinder,sector,doSector,pBuffer);
  //extint13(0x43,driveNum,startSector,doSector,pBuffer);

  }

   sectorWritten+= doSector;
  // startSector+=doSector;
   gotoxy(x,y);
   cprintf("%lu%c sectors done.",sectorWritten*100/sectorToDoVar,'%');

  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;}
   doSector=63;
  if(sectorToDoVar-sectorWritten<63) doSector=sectorToDoVar-sectorWritten;
  }

  }


  else
  {

  absolute :
  if(sectorToDoVar<63) doSector=sectorToDoVar;
  else doSector=63;
  printf("Press Esc to stop.\n");

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

   while(sectorWritten<sectorToDoVar)
   {

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


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

   if(rw==0)
  {
  //biosdisk(cmd,driveNum,head,cylinder,sector,doSector,pBuffer);
if(driveNum<2) absread(driveNum,doSector,startSector,pBuffer);
else extint13(0x42,driveNum,startSector,doSector,pBuffer);
//doFile(2,"ab+",pBuffer,doSector,filename,0);
  fwrite(pBuffer,doSector*512,1,f);
   }

    else if(rw==1)
    {
    //doFile(3,"rb",pBuffer,doSector,filename,sectorWritten);
  fread(pBuffer,doSector*512,1,f);
  //biosdisk(cmd,driveNum,head,cylinder,sector,doSector,pBuffer);

  if(driveNum<2) abswrite(driveNum,doSector,startSector,pBuffer);
  else extint13(0x43,driveNum,startSector,doSector,pBuffer);

  }


   sectorWritten+= doSector;
   startSector+=doSector;
   gotoxy(x,y);
   cprintf("%lu%c sectors done.",sectorWritten*100/sectorToDoVar,'%');

 // 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;}
   //doSector=63;
  if(sectorToDoVar-sectorWritten<63) doSector=sectorToDoVar-sectorWritten;

  }
  }

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

⌨️ 快捷键说明

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