Boolean_T isRamDsk(unsigned char drive) { union REGS regs; B_REC buffer; regs.x.ax = 0x4408; /* Not if removable */ regs.h.bl = (unsigned)toupper(drive) - (unsigned char)'@'; intdos(®s, ®s); if (0 == regs.x.ax) return False_; if (AbsDiskRead(toupper(drive) - 'A', 1, 0, &buffer)) return Error_; return (1 == buffer.bsFATs); }
int _cdecl CachedAbsDiskRead(int iDrive, DWORD dwSector, WORD wOffset, WORD wLength, void *pBuf) { int err; DEVICEPARAMS dpCache; DEVICEPARAMS *pdp = &dpCache; WORD wToCopy; if (iDrive != iCachedDrive) { if (iCacheDirty) CachedAbsDiskFlush(); iCachedDrive = -1; /* Assume failure reading the drive parameters */ err = GetDeviceParams(iDrive, pdp); if (err) return err; /* Access denied */ if (pdp->dpBytesPerSec > 1024) return 5; /* Prevent cache overflow */ wCachedSectorSize = pdp->dpBytesPerSec; iCachedDrive = iDrive; /* Flag success: Drive parameters are valid. */ dwCachedSector = NO_SECTOR; // Force reading the new drive } /* Prevent errors */ if (wOffset >= wCachedSectorSize) return 5; while (wLength) { if (dwSector != dwCachedSector) // Don't read twice the same sector { if (iCacheDirty) CachedAbsDiskFlush(); err = AbsDiskRead(iDrive, dwSector, 1, cSectorCache); if (err) return err; dwCachedSector = dwSector; } wToCopy = min(wLength, wCachedSectorSize - wOffset); memcpy(pBuf, cSectorCache+wOffset, wToCopy); dwSector += 1; wOffset = 0; wLength -= wToCopy; (char *)pBuf += wToCopy; } return 0; }