{$A+,B-,D+,E-,F-,G-,I-,L+,N-,O-,P-,Q-,R-,S-,T-,V+,X+,Y+}
{$M 16384,0,65535}
unit flprdisk;

interface

FUNCTION ReadSector(drive, head, track, sector : Byte; buff: Pointer): Byte;
FUNCTION ReadSectors(drive, head, track, sector, numtoread : Byte; buff: Pointer): Byte;
FUNCTION WriteSector(drive, head, track, sector : Byte; buff: Pointer): Byte;
FUNCTION ResetDrive(drive:byte): Byte;

var
  DriveMotorStatus:Byte Absolute $40:$3F;

implementation

uses
  flprglob;

FUNCTION ReadSector(drive, head, track, sector : Byte; buff: Pointer): Byte; assembler;
{ drive = 0 for drive A:, 1 = B:,   }
{ 80h = first hard drive.           }
ASM
  mov  ax,0201h      { read 1 sector }
  les  bx,[buff]     { es:bx -> buffer }
  mov  ch,[track]
  mov  cl,[sector]
  mov  dh,[head]
  mov  dl,[drive]
  int  13h
  mov  al,ah         { return status result in al }
END;

FUNCTION ReadSectors(drive, head, track, sector, numtoread : Byte; buff: Pointer): Byte; assembler;
{ drive = 0 for drive A:, 1 = B:,   }
{ 80h = first hard drive.           }
ASM
  mov  ah,02h
  mov  al,[numtoread]
  les  bx,[buff]     { es:bx -> buffer }
  mov  ch,[track]
  mov  cl,[sector]
  mov  dh,[head]
  mov  dl,[drive]
  int  13h
  mov  al,ah         { return status result in al }
END;

FUNCTION WriteSector(drive, head, track, sector : Byte; buff: Pointer): Byte; assembler;
{ drive = 0 for drive A:, 1 = B:,
{ 80h = first hard drive. }
ASM
  mov  ax,0301h      { read 1 sector }
  les  bx,[buff]     { es:bx -> buffer }
  mov  ch,[track]
  mov  cl,[sector]
  mov  dh,[head]
  mov  dl,[drive]
  int  13h
  mov  al,ah         { status result in al }
END;

FUNCTION ResetDrive(drive:byte): Byte; assembler;
{ drive = 0 for drive A:, 1 = B:,   }
{ 80h = first hard drive.           }
ASM
  xor  ax,ax
  mov  dl,[drive]
  int  13h
  mov  al,ah         { return status result in al }
END;

end.