用bcb 读磁片磁区

                   读磁片磁区

一、以前的DOS版要读、写、格式化第0轨的第1个磁区,程式大致如下:

char buffer[512];

reg.x.dx=0 ;   /* for drive A *
reg.x.cx=0x0001  /* for boot sector */
reg.x.bx=FP_OFF(buffer);
sreg.es=FP_SEG(buffer);
resg.x.ax=0x0201;   /*  02 for Read, 03 for Write ,05 for Format */
int86x(0x13,&reg,&reg,&sreg);

    那麽在windows 下转换为呼叫 DeviceIoControl 以便格式化、读取、写入该磁轨,DIOC_REGISTERS 这struct 在套上 DOS 下 Int21对HDD或FDD 的各项参数如要格式化是Int21也是有, 但Windows下也另有提供。

l#pragma pack(push, 1)
struct DIOC_REGISTERS {
    DWORD reg_EBX;
    DWORD reg_EDX;
    DWORD reg_ECX;
    DWORD reg_EAX;
    DWORD reg_EDI;
    DWORD reg_ESI;
    DWORD reg_Flags;
};
#pragma pack(pop)

 sDiskImageInfo->hDevice = ::CreateFile(".//vwin32", 0, 0, NULL, 0,
FILE_FLAG_DELETE_ON_CLOSE, NULL);
 if( sDiskImageInfo->hDevice == INVALID_HANDLE_VALUE)
  bRunNext = false;

// Reset Floppy Disk
  reg.reg_EBX = 0;
  reg.reg_EAX = 0x0000;       // IOCTL for block devices
  reg.reg_EDX = sDiskImageInfo->Driver;
  reg.reg_EDI = 0; reg.reg_ESI= 0;
  reg.reg_Flags = 0x0001;     // assume error (carry flag is set)
  dwResult = ::DeviceIoControl( sDiskImageInfo->hDevice,
VWIN32_DIOC_DOS_INT13,
                                &reg, sizeof(DIOC_REGISTERS), &reg,
sizeof(DIOC_REGISTERS), &cb, 0);

// Seek Floppy
      reg.reg_EBX = 0;
      reg.reg_EAX = 0x0C00;       // IOCTL for block devices
      reg.reg_ECX = ( sDiskImageInfo->nC << 8) | sDiskImageInfo->nS;
      reg.reg_EDX = ( sDiskImageInfo->nH << 8) | sDiskImageInfo->Driver;
      reg.reg_EDI = 0;
reg.reg_ESI= 0;
      reg.reg_Flags = 0x0001;     // assume error (carry flag is set)
      dwResult = ::DeviceIoControl( sDiskImageInfo->hDevice,
VWIN32_DIOC_DOS_INT13,
                                   &reg, sizeof(DIOC_REGISTERS), &reg,
sizeof(DIOC_REGISTERS), &cb, 0);

// Read Floppy
R_CreateDiskImageFile:
      reg.reg_EBX = 0;
      reg.reg_EAX = 0x0200 | 0x01;       // IOCTL for block devices
      reg.reg_ECX = ( sDiskImageInfo->nC << 8) | sDiskImageInfo->nS;
      reg.reg_EDX = ( sDiskImageInfo->nH << 8) | sDiskImageInfo->Driver;
      reg.reg_EBX = (DWORD) &m_Buf;
      reg.reg_EDI = 0;
 reg.reg_ESI= 0;
      reg.reg_Flags = 0x0001;     // assume error (carry flag is set)
      dwResult = ::DeviceIoControl( hDevice, VWIN32_DIOC_DOS_INT13,
                                   &reg, sizeof(DIOC_REGISTERS), &reg,
sizeof(DIOC_REGISTERS), &cb, 0);
      if (!dwResult || (reg.reg_Flags & 0x0001))
      {
}
 

  • 0
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论

打赏作者

蝈蝈俊

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值