unit flprdisk;

interface

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;
FUNCTION GetDriveStatus(drive:byte):byte;

var
  DriveMotorStatus:Byte Absolute $40:$3F;

implementation

uses
  flprglob;

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
  {numsectors read in al, status in ah, cf=0 if successful}
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 }
  pop     ds
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;

FUNCTION GetDriveStatus(drive:byte): Byte; assembler;
ASM
  mov     ah,1
  int     13h
  { return status result in al }
END;


end.